]> git.ipfire.org Git - thirdparty/grsecurity-scrape.git/blob - test/grsecurity-3.0-3.13.3-201402132113.patch
Auto commit, 1 new patch{es}.
[thirdparty/grsecurity-scrape.git] / test / grsecurity-3.0-3.13.3-201402132113.patch
1 diff --git a/Documentation/dontdiff b/Documentation/dontdiff
2 index b89a739..e289b9b 100644
3 --- a/Documentation/dontdiff
4 +++ b/Documentation/dontdiff
5 @@ -2,9 +2,11 @@
6 *.aux
7 *.bin
8 *.bz2
9 +*.c.[012]*.*
10 *.cis
11 *.cpio
12 *.csp
13 +*.dbg
14 *.dsp
15 *.dvi
16 *.elf
17 @@ -14,6 +16,7 @@
18 *.gcov
19 *.gen.S
20 *.gif
21 +*.gmo
22 *.grep
23 *.grp
24 *.gz
25 @@ -48,14 +51,17 @@
26 *.tab.h
27 *.tex
28 *.ver
29 +*.vim
30 *.xml
31 *.xz
32 *_MODULES
33 +*_reg_safe.h
34 *_vga16.c
35 *~
36 \#*#
37 *.9
38 -.*
39 +.[^g]*
40 +.gen*
41 .*.d
42 .mm
43 53c700_d.h
44 @@ -69,9 +75,11 @@ Image
45 Module.markers
46 Module.symvers
47 PENDING
48 +PERF*
49 SCCS
50 System.map*
51 TAGS
52 +TRACEEVENT-CFLAGS
53 aconf
54 af_names.h
55 aic7*reg.h*
56 @@ -80,6 +88,7 @@ aic7*seq.h*
57 aicasm
58 aicdb.h*
59 altivec*.c
60 +ashldi3.S
61 asm-offsets.h
62 asm_offsets.h
63 autoconf.h*
64 @@ -92,32 +101,40 @@ bounds.h
65 bsetup
66 btfixupprep
67 build
68 +builtin-policy.h
69 bvmlinux
70 bzImage*
71 capability_names.h
72 capflags.c
73 classlist.h*
74 +clut_vga16.c
75 +common-cmds.h
76 comp*.log
77 compile.h*
78 conf
79 config
80 config-*
81 config_data.h*
82 +config.c
83 config.mak
84 config.mak.autogen
85 +config.tmp
86 conmakehash
87 consolemap_deftbl.c*
88 cpustr.h
89 crc32table.h*
90 cscope.*
91 defkeymap.c
92 +devicetable-offsets.h
93 devlist.h*
94 dnotify_test
95 docproc
96 dslm
97 +dtc-lexer.lex.c
98 elf2ecoff
99 elfconfig.h*
100 evergreen_reg_safe.h
101 +exception_policy.conf
102 fixdep
103 flask.h
104 fore200e_mkfirm
105 @@ -125,12 +142,15 @@ fore200e_pca_fw.c*
106 gconf
107 gconf.glade.h
108 gen-devlist
109 +gen-kdb_cmds.c
110 gen_crc32table
111 gen_init_cpio
112 generated
113 genheaders
114 genksyms
115 *_gray256.c
116 +hash
117 +hid-example
118 hpet_example
119 hugepage-mmap
120 hugepage-shm
121 @@ -145,14 +165,14 @@ int32.c
122 int4.c
123 int8.c
124 kallsyms
125 -kconfig
126 +kern_constants.h
127 keywords.c
128 ksym.c*
129 ksym.h*
130 kxgettext
131 lex.c
132 lex.*.c
133 -linux
134 +lib1funcs.S
135 logo_*.c
136 logo_*_clut224.c
137 logo_*_mono.c
138 @@ -162,14 +182,15 @@ mach-types.h
139 machtypes.h
140 map
141 map_hugetlb
142 -media
143 mconf
144 +mdp
145 miboot*
146 mk_elfconfig
147 mkboot
148 mkbugboot
149 mkcpustr
150 mkdep
151 +mkpiggy
152 mkprep
153 mkregtable
154 mktables
155 @@ -185,6 +206,8 @@ oui.c*
156 page-types
157 parse.c
158 parse.h
159 +parse-events*
160 +pasyms.h
161 patches*
162 pca200e.bin
163 pca200e_ecd.bin2
164 @@ -194,6 +217,7 @@ perf-archive
165 piggyback
166 piggy.gzip
167 piggy.S
168 +pmu-*
169 pnmtologo
170 ppc_defs.h*
171 pss_boot.h
172 @@ -203,7 +227,12 @@ r200_reg_safe.h
173 r300_reg_safe.h
174 r420_reg_safe.h
175 r600_reg_safe.h
176 +randomize_layout_hash.h
177 +randomize_layout_seed.h
178 +realmode.lds
179 +realmode.relocs
180 recordmcount
181 +regdb.c
182 relocs
183 rlim_names.h
184 rn50_reg_safe.h
185 @@ -213,8 +242,12 @@ series
186 setup
187 setup.bin
188 setup.elf
189 +signing_key*
190 +size_overflow_hash.h
191 sImage
192 +slabinfo
193 sm_tbl*
194 +sortextable
195 split-include
196 syscalltab.h
197 tables.c
198 @@ -224,6 +257,7 @@ tftpboot.img
199 timeconst.h
200 times.h*
201 trix_boot.h
202 +user_constants.h
203 utsrelease.h*
204 vdso-syms.lds
205 vdso.lds
206 @@ -235,13 +269,17 @@ vdso32.lds
207 vdso32.so.dbg
208 vdso64.lds
209 vdso64.so.dbg
210 +vdsox32.lds
211 +vdsox32-syms.lds
212 version.h*
213 vmImage
214 vmlinux
215 vmlinux-*
216 vmlinux.aout
217 vmlinux.bin.all
218 +vmlinux.bin.bz2
219 vmlinux.lds
220 +vmlinux.relocs
221 vmlinuz
222 voffset.h
223 vsyscall.lds
224 @@ -249,9 +287,12 @@ vsyscall_32.lds
225 wanxlfw.inc
226 uImage
227 unifdef
228 +utsrelease.h
229 wakeup.bin
230 wakeup.elf
231 wakeup.lds
232 +x509*
233 zImage*
234 zconf.hash.c
235 +zconf.lex.c
236 zoffset.h
237 diff --git a/Documentation/kernel-parameters.txt b/Documentation/kernel-parameters.txt
238 index b9e9bd8..bf49b92 100644
239 --- a/Documentation/kernel-parameters.txt
240 +++ b/Documentation/kernel-parameters.txt
241 @@ -1033,6 +1033,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
242 Format: <unsigned int> such that (rxsize & ~0x1fffc0) == 0.
243 Default: 1024
244
245 + grsec_proc_gid= [GRKERNSEC_PROC_USERGROUP] Chooses GID to
246 + ignore grsecurity's /proc restrictions
247 +
248 +
249 hashdist= [KNL,NUMA] Large hashes allocated during boot
250 are distributed across NUMA nodes. Defaults on
251 for 64-bit NUMA, off otherwise.
252 @@ -2018,6 +2022,10 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
253 noexec=on: enable non-executable mappings (default)
254 noexec=off: disable non-executable mappings
255
256 + nopcid [X86-64]
257 + Disable PCID (Process-Context IDentifier) even if it
258 + is supported by the processor.
259 +
260 nosmap [X86]
261 Disable SMAP (Supervisor Mode Access Prevention)
262 even if it is supported by processor.
263 @@ -2285,6 +2293,25 @@ bytes respectively. Such letter suffixes can also be entirely omitted.
264 the specified number of seconds. This is to be used if
265 your oopses keep scrolling off the screen.
266
267 + pax_nouderef [X86] disables UDEREF. Most likely needed under certain
268 + virtualization environments that don't cope well with the
269 + expand down segment used by UDEREF on X86-32 or the frequent
270 + page table updates on X86-64.
271 +
272 + pax_sanitize_slab=
273 + 0/1 to disable/enable slab object sanitization (enabled by
274 + default).
275 +
276 + pax_softmode= 0/1 to disable/enable PaX softmode on boot already.
277 +
278 + pax_extra_latent_entropy
279 + Enable a very simple form of latent entropy extraction
280 + from the first 4GB of memory as the bootmem allocator
281 + passes the memory pages to the buddy allocator.
282 +
283 + pax_weakuderef [X86-64] enables the weaker but faster form of UDEREF
284 + when the processor supports PCID.
285 +
286 pcbit= [HW,ISDN]
287
288 pcd. [PARIDE]
289 diff --git a/Makefile b/Makefile
290 index 704b508..4a788c4 100644
291 --- a/Makefile
292 +++ b/Makefile
293 @@ -244,8 +244,9 @@ CONFIG_SHELL := $(shell if [ -x "$$BASH" ]; then echo $$BASH; \
294
295 HOSTCC = gcc
296 HOSTCXX = g++
297 -HOSTCFLAGS = -Wall -Wmissing-prototypes -Wstrict-prototypes -O2 -fomit-frame-pointer
298 -HOSTCXXFLAGS = -O2
299 +HOSTCFLAGS = -Wall -W -Wmissing-prototypes -Wstrict-prototypes -Wno-unused-parameter -Wno-missing-field-initializers -O2 -fomit-frame-pointer -fno-delete-null-pointer-checks
300 +HOSTCFLAGS += $(call cc-option, -Wno-empty-body)
301 +HOSTCXXFLAGS = -O2 -Wall -W -fno-delete-null-pointer-checks
302
303 # Decide whether to build built-in, modular, or both.
304 # Normally, just do built-in.
305 @@ -311,9 +312,15 @@ endif
306 # If the user is running make -s (silent mode), suppress echoing of
307 # commands
308
309 +ifneq ($(filter 4.%,$(MAKE_VERSION)),) # make-4
310 +ifneq ($(filter %s ,$(firstword x$(MAKEFLAGS))),)
311 + quiet=silent_
312 +endif
313 +else # make-3.8x
314 ifneq ($(filter s% -s%,$(MAKEFLAGS)),)
315 quiet=silent_
316 endif
317 +endif
318
319 export quiet Q KBUILD_VERBOSE
320
321 @@ -417,8 +424,8 @@ export RCS_TAR_IGNORE := --exclude SCCS --exclude BitKeeper --exclude .svn \
322 # Rules shared between *config targets and build targets
323
324 # Basic helpers built in scripts/
325 -PHONY += scripts_basic
326 -scripts_basic:
327 +PHONY += scripts_basic gcc-plugins
328 +scripts_basic: gcc-plugins
329 $(Q)$(MAKE) $(build)=scripts/basic
330 $(Q)rm -f .tmp_quiet_recordmcount
331
332 @@ -579,6 +586,72 @@ else
333 KBUILD_CFLAGS += -O2
334 endif
335
336 +ifndef DISABLE_PAX_PLUGINS
337 +ifeq ($(call cc-ifversion, -ge, 0408, y), y)
338 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCXX)" "$(HOSTCXX)" "$(CC)")
339 +else
340 +PLUGINCC := $(shell $(CONFIG_SHELL) $(srctree)/scripts/gcc-plugin.sh "$(HOSTCC)" "$(HOSTCXX)" "$(CC)")
341 +endif
342 +ifneq ($(PLUGINCC),)
343 +ifdef CONFIG_PAX_CONSTIFY_PLUGIN
344 +CONSTIFY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/constify_plugin.so -DCONSTIFY_PLUGIN
345 +endif
346 +ifdef CONFIG_PAX_MEMORY_STACKLEAK
347 +STACKLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/stackleak_plugin.so -DSTACKLEAK_PLUGIN
348 +STACKLEAK_PLUGIN_CFLAGS += -fplugin-arg-stackleak_plugin-track-lowest-sp=100
349 +endif
350 +ifdef CONFIG_KALLOCSTAT_PLUGIN
351 +KALLOCSTAT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kallocstat_plugin.so
352 +endif
353 +ifdef CONFIG_PAX_KERNEXEC_PLUGIN
354 +KERNEXEC_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/kernexec_plugin.so
355 +KERNEXEC_PLUGIN_CFLAGS += -fplugin-arg-kernexec_plugin-method=$(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD) -DKERNEXEC_PLUGIN
356 +KERNEXEC_PLUGIN_AFLAGS := -DKERNEXEC_PLUGIN
357 +endif
358 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT
359 +RANDSTRUCT_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/randomize_layout_plugin.so -DRANDSTRUCT_PLUGIN
360 +ifdef CONFIG_GRKERNSEC_RANDSTRUCT_PERFORMANCE
361 +RANDSTRUCT_PLUGIN_CFLAGS += -fplugin-arg-randomize_layout_plugin-performance-mode
362 +endif
363 +endif
364 +ifdef CONFIG_CHECKER_PLUGIN
365 +ifeq ($(call cc-ifversion, -ge, 0406, y), y)
366 +CHECKER_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/checker_plugin.so -DCHECKER_PLUGIN
367 +endif
368 +endif
369 +COLORIZE_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/colorize_plugin.so
370 +ifdef CONFIG_PAX_SIZE_OVERFLOW
371 +SIZE_OVERFLOW_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/size_overflow_plugin.so -DSIZE_OVERFLOW_PLUGIN
372 +endif
373 +ifdef CONFIG_PAX_LATENT_ENTROPY
374 +LATENT_ENTROPY_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/latent_entropy_plugin.so -DLATENT_ENTROPY_PLUGIN
375 +endif
376 +ifdef CONFIG_PAX_MEMORY_STRUCTLEAK
377 +STRUCTLEAK_PLUGIN_CFLAGS := -fplugin=$(objtree)/tools/gcc/structleak_plugin.so -DSTRUCTLEAK_PLUGIN
378 +endif
379 +GCC_PLUGINS_CFLAGS := $(CONSTIFY_PLUGIN_CFLAGS) $(STACKLEAK_PLUGIN_CFLAGS) $(KALLOCSTAT_PLUGIN_CFLAGS)
380 +GCC_PLUGINS_CFLAGS += $(KERNEXEC_PLUGIN_CFLAGS) $(CHECKER_PLUGIN_CFLAGS) $(COLORIZE_PLUGIN_CFLAGS)
381 +GCC_PLUGINS_CFLAGS += $(SIZE_OVERFLOW_PLUGIN_CFLAGS) $(LATENT_ENTROPY_PLUGIN_CFLAGS) $(STRUCTLEAK_PLUGIN_CFLAGS)
382 +GCC_PLUGINS_CFLAGS += $(RANDSTRUCT_PLUGIN_CFLAGS)
383 +GCC_PLUGINS_AFLAGS := $(KERNEXEC_PLUGIN_AFLAGS)
384 +export PLUGINCC GCC_PLUGINS_CFLAGS GCC_PLUGINS_AFLAGS CONSTIFY_PLUGIN
385 +ifeq ($(KBUILD_EXTMOD),)
386 +gcc-plugins:
387 + $(Q)$(MAKE) $(build)=tools/gcc
388 +else
389 +gcc-plugins: ;
390 +endif
391 +else
392 +gcc-plugins:
393 +ifeq ($(call cc-ifversion, -ge, 0405, y), y)
394 + $(error Your gcc installation does not support plugins. If the necessary headers for plugin support are missing, they should be installed. On Debian, apt-get install gcc-<ver>-plugin-dev. If you choose to ignore this error and lessen the improvements provided by this patch, re-run make with the DISABLE_PAX_PLUGINS=y argument.))
395 +else
396 + $(Q)echo "warning, your gcc version does not support plugins, you should upgrade it to gcc 4.5 at least"
397 +endif
398 + $(Q)echo "PAX_MEMORY_STACKLEAK, constification, PAX_LATENT_ENTROPY and other features will be less secure. PAX_SIZE_OVERFLOW will not be active."
399 +endif
400 +endif
401 +
402 include $(srctree)/arch/$(SRCARCH)/Makefile
403
404 ifdef CONFIG_READABLE_ASM
405 @@ -619,7 +692,7 @@ endif
406
407 ifdef CONFIG_DEBUG_INFO
408 KBUILD_CFLAGS += -g
409 -KBUILD_AFLAGS += -gdwarf-2
410 +KBUILD_AFLAGS += -Wa,--gdwarf-2
411 endif
412
413 ifdef CONFIG_DEBUG_INFO_REDUCED
414 @@ -754,7 +827,7 @@ export mod_sign_cmd
415
416
417 ifeq ($(KBUILD_EXTMOD),)
418 -core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/
419 +core-y += kernel/ mm/ fs/ ipc/ security/ crypto/ block/ grsecurity/
420
421 vmlinux-dirs := $(patsubst %/,%,$(filter %/, $(init-y) $(init-m) \
422 $(core-y) $(core-m) $(drivers-y) $(drivers-m) \
423 @@ -803,6 +876,8 @@ endif
424
425 # The actual objects are generated when descending,
426 # make sure no implicit rule kicks in
427 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
428 +$(filter-out $(init-y),$(vmlinux-deps)): KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
429 $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
430
431 # Handle descending into subdirectories listed in $(vmlinux-dirs)
432 @@ -812,7 +887,7 @@ $(sort $(vmlinux-deps)): $(vmlinux-dirs) ;
433 # Error messages still appears in the original language
434
435 PHONY += $(vmlinux-dirs)
436 -$(vmlinux-dirs): prepare scripts
437 +$(vmlinux-dirs): gcc-plugins prepare scripts
438 $(Q)$(MAKE) $(build)=$@
439
440 define filechk_kernel.release
441 @@ -855,10 +930,13 @@ prepare1: prepare2 $(version_h) include/generated/utsrelease.h \
442
443 archprepare: archheaders archscripts prepare1 scripts_basic
444
445 +prepare0: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
446 +prepare0: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
447 prepare0: archprepare FORCE
448 $(Q)$(MAKE) $(build)=.
449
450 # All the preparing..
451 +prepare: KBUILD_CFLAGS := $(filter-out $(GCC_PLUGINS_CFLAGS),$(KBUILD_CFLAGS))
452 prepare: prepare0
453
454 # Generate some files
455 @@ -966,6 +1044,8 @@ all: modules
456 # using awk while concatenating to the final file.
457
458 PHONY += modules
459 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
460 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
461 modules: $(vmlinux-dirs) $(if $(KBUILD_BUILTIN),vmlinux) modules.builtin
462 $(Q)$(AWK) '!x[$$0]++' $(vmlinux-dirs:%=$(objtree)/%/modules.order) > $(objtree)/modules.order
463 @$(kecho) ' Building modules, stage 2.';
464 @@ -981,7 +1061,7 @@ modules.builtin: $(vmlinux-dirs:%=%/modules.builtin)
465
466 # Target to prepare building external modules
467 PHONY += modules_prepare
468 -modules_prepare: prepare scripts
469 +modules_prepare: gcc-plugins prepare scripts
470
471 # Target to install modules
472 PHONY += modules_install
473 @@ -1047,7 +1127,8 @@ MRPROPER_FILES += .config .config.old .version .old_version $(version_h) \
474 Module.symvers tags TAGS cscope* GPATH GTAGS GRTAGS GSYMS \
475 signing_key.priv signing_key.x509 x509.genkey \
476 extra_certificates signing_key.x509.keyid \
477 - signing_key.x509.signer
478 + signing_key.x509.signer tools/gcc/size_overflow_hash.h \
479 + tools/gcc/randomize_layout_seed.h
480
481 # clean - Delete most, but leave enough to build external modules
482 #
483 @@ -1087,6 +1168,7 @@ distclean: mrproper
484 \( -name '*.orig' -o -name '*.rej' -o -name '*~' \
485 -o -name '*.bak' -o -name '#*#' -o -name '.*.orig' \
486 -o -name '.*.rej' \
487 + -o -name '.*.rej' -o -name '*.so' \
488 -o -name '*%' -o -name '.*.cmd' -o -name 'core' \) \
489 -type f -print | xargs rm -f
490
491 @@ -1248,6 +1330,8 @@ PHONY += $(module-dirs) modules
492 $(module-dirs): crmodverdir $(objtree)/Module.symvers
493 $(Q)$(MAKE) $(build)=$(patsubst _module_%,%,$@)
494
495 +modules: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
496 +modules: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
497 modules: $(module-dirs)
498 @$(kecho) ' Building modules, stage 2.';
499 $(Q)$(MAKE) -f $(srctree)/scripts/Makefile.modpost
500 @@ -1387,17 +1471,21 @@ else
501 target-dir = $(if $(KBUILD_EXTMOD),$(dir $<),$(dir $@))
502 endif
503
504 -%.s: %.c prepare scripts FORCE
505 +%.s: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
506 +%.s: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
507 +%.s: %.c gcc-plugins prepare scripts FORCE
508 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
509 %.i: %.c prepare scripts FORCE
510 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
511 -%.o: %.c prepare scripts FORCE
512 +%.o: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
513 +%.o: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
514 +%.o: %.c gcc-plugins prepare scripts FORCE
515 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
516 %.lst: %.c prepare scripts FORCE
517 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
518 -%.s: %.S prepare scripts FORCE
519 +%.s: %.S gcc-plugins prepare scripts FORCE
520 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
521 -%.o: %.S prepare scripts FORCE
522 +%.o: %.S gcc-plugins prepare scripts FORCE
523 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
524 %.symtypes: %.c prepare scripts FORCE
525 $(Q)$(MAKE) $(build)=$(build-dir) $(target-dir)$(notdir $@)
526 @@ -1407,11 +1495,15 @@ endif
527 $(cmd_crmodverdir)
528 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
529 $(build)=$(build-dir)
530 -%/: prepare scripts FORCE
531 +%/: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
532 +%/: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
533 +%/: gcc-plugins prepare scripts FORCE
534 $(cmd_crmodverdir)
535 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
536 $(build)=$(build-dir)
537 -%.ko: prepare scripts FORCE
538 +%.ko: KBUILD_CFLAGS += $(GCC_PLUGINS_CFLAGS)
539 +%.ko: KBUILD_AFLAGS += $(GCC_PLUGINS_AFLAGS)
540 +%.ko: gcc-plugins prepare scripts FORCE
541 $(cmd_crmodverdir)
542 $(Q)$(MAKE) KBUILD_MODULES=$(if $(CONFIG_MODULES),1) \
543 $(build)=$(build-dir) $(@:.ko=.o)
544 diff --git a/arch/alpha/include/asm/atomic.h b/arch/alpha/include/asm/atomic.h
545 index 78b03ef..da28a51 100644
546 --- a/arch/alpha/include/asm/atomic.h
547 +++ b/arch/alpha/include/asm/atomic.h
548 @@ -292,6 +292,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
549 #define atomic_dec(v) atomic_sub(1,(v))
550 #define atomic64_dec(v) atomic64_sub(1,(v))
551
552 +#define atomic64_read_unchecked(v) atomic64_read(v)
553 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
554 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
555 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
556 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
557 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
558 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
559 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
560 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
561 +
562 #define smp_mb__before_atomic_dec() smp_mb()
563 #define smp_mb__after_atomic_dec() smp_mb()
564 #define smp_mb__before_atomic_inc() smp_mb()
565 diff --git a/arch/alpha/include/asm/cache.h b/arch/alpha/include/asm/cache.h
566 index ad368a9..fbe0f25 100644
567 --- a/arch/alpha/include/asm/cache.h
568 +++ b/arch/alpha/include/asm/cache.h
569 @@ -4,19 +4,19 @@
570 #ifndef __ARCH_ALPHA_CACHE_H
571 #define __ARCH_ALPHA_CACHE_H
572
573 +#include <linux/const.h>
574
575 /* Bytes per L1 (data) cache line. */
576 #if defined(CONFIG_ALPHA_GENERIC) || defined(CONFIG_ALPHA_EV6)
577 -# define L1_CACHE_BYTES 64
578 # define L1_CACHE_SHIFT 6
579 #else
580 /* Both EV4 and EV5 are write-through, read-allocate,
581 direct-mapped, physical.
582 */
583 -# define L1_CACHE_BYTES 32
584 # define L1_CACHE_SHIFT 5
585 #endif
586
587 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
588 #define SMP_CACHE_BYTES L1_CACHE_BYTES
589
590 #endif
591 diff --git a/arch/alpha/include/asm/elf.h b/arch/alpha/include/asm/elf.h
592 index 968d999..d36b2df 100644
593 --- a/arch/alpha/include/asm/elf.h
594 +++ b/arch/alpha/include/asm/elf.h
595 @@ -91,6 +91,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
596
597 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x1000000)
598
599 +#ifdef CONFIG_PAX_ASLR
600 +#define PAX_ELF_ET_DYN_BASE (current->personality & ADDR_LIMIT_32BIT ? 0x10000 : 0x120000000UL)
601 +
602 +#define PAX_DELTA_MMAP_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 28)
603 +#define PAX_DELTA_STACK_LEN (current->personality & ADDR_LIMIT_32BIT ? 14 : 19)
604 +#endif
605 +
606 /* $0 is set by ld.so to a pointer to a function which might be
607 registered using atexit. This provides a mean for the dynamic
608 linker to call DT_FINI functions for shared libraries that have
609 diff --git a/arch/alpha/include/asm/pgalloc.h b/arch/alpha/include/asm/pgalloc.h
610 index aab14a0..b4fa3e7 100644
611 --- a/arch/alpha/include/asm/pgalloc.h
612 +++ b/arch/alpha/include/asm/pgalloc.h
613 @@ -29,6 +29,12 @@ pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
614 pgd_set(pgd, pmd);
615 }
616
617 +static inline void
618 +pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
619 +{
620 + pgd_populate(mm, pgd, pmd);
621 +}
622 +
623 extern pgd_t *pgd_alloc(struct mm_struct *mm);
624
625 static inline void
626 diff --git a/arch/alpha/include/asm/pgtable.h b/arch/alpha/include/asm/pgtable.h
627 index d8f9b7e..f6222fa 100644
628 --- a/arch/alpha/include/asm/pgtable.h
629 +++ b/arch/alpha/include/asm/pgtable.h
630 @@ -102,6 +102,17 @@ struct vm_area_struct;
631 #define PAGE_SHARED __pgprot(_PAGE_VALID | __ACCESS_BITS)
632 #define PAGE_COPY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
633 #define PAGE_READONLY __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW)
634 +
635 +#ifdef CONFIG_PAX_PAGEEXEC
636 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOE)
637 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
638 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_VALID | __ACCESS_BITS | _PAGE_FOW | _PAGE_FOE)
639 +#else
640 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
641 +# define PAGE_COPY_NOEXEC PAGE_COPY
642 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
643 +#endif
644 +
645 #define PAGE_KERNEL __pgprot(_PAGE_VALID | _PAGE_ASM | _PAGE_KRE | _PAGE_KWE)
646
647 #define _PAGE_NORMAL(x) __pgprot(_PAGE_VALID | __ACCESS_BITS | (x))
648 diff --git a/arch/alpha/kernel/module.c b/arch/alpha/kernel/module.c
649 index 2fd00b7..cfd5069 100644
650 --- a/arch/alpha/kernel/module.c
651 +++ b/arch/alpha/kernel/module.c
652 @@ -160,7 +160,7 @@ apply_relocate_add(Elf64_Shdr *sechdrs, const char *strtab,
653
654 /* The small sections were sorted to the end of the segment.
655 The following should definitely cover them. */
656 - gp = (u64)me->module_core + me->core_size - 0x8000;
657 + gp = (u64)me->module_core_rw + me->core_size_rw - 0x8000;
658 got = sechdrs[me->arch.gotsecindex].sh_addr;
659
660 for (i = 0; i < n; i++) {
661 diff --git a/arch/alpha/kernel/osf_sys.c b/arch/alpha/kernel/osf_sys.c
662 index 1402fcc..0b1abd2 100644
663 --- a/arch/alpha/kernel/osf_sys.c
664 +++ b/arch/alpha/kernel/osf_sys.c
665 @@ -1298,10 +1298,11 @@ SYSCALL_DEFINE1(old_adjtimex, struct timex32 __user *, txc_p)
666 generic version except that we know how to honor ADDR_LIMIT_32BIT. */
667
668 static unsigned long
669 -arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
670 - unsigned long limit)
671 +arch_get_unmapped_area_1(struct file *filp, unsigned long addr, unsigned long len,
672 + unsigned long limit, unsigned long flags)
673 {
674 struct vm_unmapped_area_info info;
675 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
676
677 info.flags = 0;
678 info.length = len;
679 @@ -1309,6 +1310,7 @@ arch_get_unmapped_area_1(unsigned long addr, unsigned long len,
680 info.high_limit = limit;
681 info.align_mask = 0;
682 info.align_offset = 0;
683 + info.threadstack_offset = offset;
684 return vm_unmapped_area(&info);
685 }
686
687 @@ -1341,20 +1343,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
688 merely specific addresses, but regions of memory -- perhaps
689 this feature should be incorporated into all ports? */
690
691 +#ifdef CONFIG_PAX_RANDMMAP
692 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
693 +#endif
694 +
695 if (addr) {
696 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(addr), len, limit);
697 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(addr), len, limit, flags);
698 if (addr != (unsigned long) -ENOMEM)
699 return addr;
700 }
701
702 /* Next, try allocating at TASK_UNMAPPED_BASE. */
703 - addr = arch_get_unmapped_area_1 (PAGE_ALIGN(TASK_UNMAPPED_BASE),
704 - len, limit);
705 + addr = arch_get_unmapped_area_1 (filp, PAGE_ALIGN(current->mm->mmap_base), len, limit, flags);
706 +
707 if (addr != (unsigned long) -ENOMEM)
708 return addr;
709
710 /* Finally, try allocating in low memory. */
711 - addr = arch_get_unmapped_area_1 (PAGE_SIZE, len, limit);
712 + addr = arch_get_unmapped_area_1 (filp, PAGE_SIZE, len, limit, flags);
713
714 return addr;
715 }
716 diff --git a/arch/alpha/mm/fault.c b/arch/alpha/mm/fault.c
717 index 98838a0..b304fb4 100644
718 --- a/arch/alpha/mm/fault.c
719 +++ b/arch/alpha/mm/fault.c
720 @@ -53,6 +53,124 @@ __load_new_mm_context(struct mm_struct *next_mm)
721 __reload_thread(pcb);
722 }
723
724 +#ifdef CONFIG_PAX_PAGEEXEC
725 +/*
726 + * PaX: decide what to do with offenders (regs->pc = fault address)
727 + *
728 + * returns 1 when task should be killed
729 + * 2 when patched PLT trampoline was detected
730 + * 3 when unpatched PLT trampoline was detected
731 + */
732 +static int pax_handle_fetch_fault(struct pt_regs *regs)
733 +{
734 +
735 +#ifdef CONFIG_PAX_EMUPLT
736 + int err;
737 +
738 + do { /* PaX: patched PLT emulation #1 */
739 + unsigned int ldah, ldq, jmp;
740 +
741 + err = get_user(ldah, (unsigned int *)regs->pc);
742 + err |= get_user(ldq, (unsigned int *)(regs->pc+4));
743 + err |= get_user(jmp, (unsigned int *)(regs->pc+8));
744 +
745 + if (err)
746 + break;
747 +
748 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
749 + (ldq & 0xFFFF0000U) == 0xA77B0000U &&
750 + jmp == 0x6BFB0000U)
751 + {
752 + unsigned long r27, addr;
753 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
754 + unsigned long addrl = ldq | 0xFFFFFFFFFFFF0000UL;
755 +
756 + addr = regs->r27 + ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
757 + err = get_user(r27, (unsigned long *)addr);
758 + if (err)
759 + break;
760 +
761 + regs->r27 = r27;
762 + regs->pc = r27;
763 + return 2;
764 + }
765 + } while (0);
766 +
767 + do { /* PaX: patched PLT emulation #2 */
768 + unsigned int ldah, lda, br;
769 +
770 + err = get_user(ldah, (unsigned int *)regs->pc);
771 + err |= get_user(lda, (unsigned int *)(regs->pc+4));
772 + err |= get_user(br, (unsigned int *)(regs->pc+8));
773 +
774 + if (err)
775 + break;
776 +
777 + if ((ldah & 0xFFFF0000U) == 0x277B0000U &&
778 + (lda & 0xFFFF0000U) == 0xA77B0000U &&
779 + (br & 0xFFE00000U) == 0xC3E00000U)
780 + {
781 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL;
782 + unsigned long addrh = (ldah | 0xFFFFFFFFFFFF0000UL) << 16;
783 + unsigned long addrl = lda | 0xFFFFFFFFFFFF0000UL;
784 +
785 + regs->r27 += ((addrh ^ 0x80000000UL) + 0x80000000UL) + ((addrl ^ 0x8000UL) + 0x8000UL);
786 + regs->pc += 12 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
787 + return 2;
788 + }
789 + } while (0);
790 +
791 + do { /* PaX: unpatched PLT emulation */
792 + unsigned int br;
793 +
794 + err = get_user(br, (unsigned int *)regs->pc);
795 +
796 + if (!err && (br & 0xFFE00000U) == 0xC3800000U) {
797 + unsigned int br2, ldq, nop, jmp;
798 + unsigned long addr = br | 0xFFFFFFFFFFE00000UL, resolver;
799 +
800 + addr = regs->pc + 4 + (((addr ^ 0x00100000UL) + 0x00100000UL) << 2);
801 + err = get_user(br2, (unsigned int *)addr);
802 + err |= get_user(ldq, (unsigned int *)(addr+4));
803 + err |= get_user(nop, (unsigned int *)(addr+8));
804 + err |= get_user(jmp, (unsigned int *)(addr+12));
805 + err |= get_user(resolver, (unsigned long *)(addr+16));
806 +
807 + if (err)
808 + break;
809 +
810 + if (br2 == 0xC3600000U &&
811 + ldq == 0xA77B000CU &&
812 + nop == 0x47FF041FU &&
813 + jmp == 0x6B7B0000U)
814 + {
815 + regs->r28 = regs->pc+4;
816 + regs->r27 = addr+16;
817 + regs->pc = resolver;
818 + return 3;
819 + }
820 + }
821 + } while (0);
822 +#endif
823 +
824 + return 1;
825 +}
826 +
827 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
828 +{
829 + unsigned long i;
830 +
831 + printk(KERN_ERR "PAX: bytes at PC: ");
832 + for (i = 0; i < 5; i++) {
833 + unsigned int c;
834 + if (get_user(c, (unsigned int *)pc+i))
835 + printk(KERN_CONT "???????? ");
836 + else
837 + printk(KERN_CONT "%08x ", c);
838 + }
839 + printk("\n");
840 +}
841 +#endif
842
843 /*
844 * This routine handles page faults. It determines the address,
845 @@ -133,8 +251,29 @@ retry:
846 good_area:
847 si_code = SEGV_ACCERR;
848 if (cause < 0) {
849 - if (!(vma->vm_flags & VM_EXEC))
850 + if (!(vma->vm_flags & VM_EXEC)) {
851 +
852 +#ifdef CONFIG_PAX_PAGEEXEC
853 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->pc)
854 + goto bad_area;
855 +
856 + up_read(&mm->mmap_sem);
857 + switch (pax_handle_fetch_fault(regs)) {
858 +
859 +#ifdef CONFIG_PAX_EMUPLT
860 + case 2:
861 + case 3:
862 + return;
863 +#endif
864 +
865 + }
866 + pax_report_fault(regs, (void *)regs->pc, (void *)rdusp());
867 + do_group_exit(SIGKILL);
868 +#else
869 goto bad_area;
870 +#endif
871 +
872 + }
873 } else if (!cause) {
874 /* Allow reads even for write-only mappings */
875 if (!(vma->vm_flags & (VM_READ | VM_WRITE)))
876 diff --git a/arch/arm/Kconfig b/arch/arm/Kconfig
877 index c1f1a7e..554b0cd 100644
878 --- a/arch/arm/Kconfig
879 +++ b/arch/arm/Kconfig
880 @@ -1828,7 +1828,7 @@ config ALIGNMENT_TRAP
881
882 config UACCESS_WITH_MEMCPY
883 bool "Use kernel mem{cpy,set}() for {copy_to,clear}_user()"
884 - depends on MMU
885 + depends on MMU && !PAX_MEMORY_UDEREF
886 default y if CPU_FEROCEON
887 help
888 Implement faster copy_to_user and clear_user methods for CPU
889 @@ -2100,6 +2100,7 @@ config XIP_PHYS_ADDR
890 config KEXEC
891 bool "Kexec system call (EXPERIMENTAL)"
892 depends on (!SMP || PM_SLEEP_SMP)
893 + depends on !GRKERNSEC_KMEM
894 help
895 kexec is a system call that implements the ability to shutdown your
896 current kernel, and to start another kernel. It is like a reboot
897 diff --git a/arch/arm/include/asm/atomic.h b/arch/arm/include/asm/atomic.h
898 index 62d2cb5..7a13651 100644
899 --- a/arch/arm/include/asm/atomic.h
900 +++ b/arch/arm/include/asm/atomic.h
901 @@ -18,17 +18,35 @@
902 #include <asm/barrier.h>
903 #include <asm/cmpxchg.h>
904
905 +#ifdef CONFIG_GENERIC_ATOMIC64
906 +#include <asm-generic/atomic64.h>
907 +#endif
908 +
909 #define ATOMIC_INIT(i) { (i) }
910
911 #ifdef __KERNEL__
912
913 +#define _ASM_EXTABLE(from, to) \
914 +" .pushsection __ex_table,\"a\"\n"\
915 +" .align 3\n" \
916 +" .long " #from ", " #to"\n" \
917 +" .popsection"
918 +
919 /*
920 * On ARM, ordinary assignment (str instruction) doesn't clear the local
921 * strex/ldrex monitor on some implementations. The reason we can use it for
922 * atomic_set() is the clrex or dummy strex done on every exception return.
923 */
924 #define atomic_read(v) (*(volatile int *)&(v)->counter)
925 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
926 +{
927 + return v->counter;
928 +}
929 #define atomic_set(v,i) (((v)->counter) = (i))
930 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
931 +{
932 + v->counter = i;
933 +}
934
935 #if __LINUX_ARM_ARCH__ >= 6
936
937 @@ -44,6 +62,36 @@ static inline void atomic_add(int i, atomic_t *v)
938
939 prefetchw(&v->counter);
940 __asm__ __volatile__("@ atomic_add\n"
941 +"1: ldrex %1, [%3]\n"
942 +" adds %0, %1, %4\n"
943 +
944 +#ifdef CONFIG_PAX_REFCOUNT
945 +" bvc 3f\n"
946 +"2: bkpt 0xf103\n"
947 +"3:\n"
948 +#endif
949 +
950 +" strex %1, %0, [%3]\n"
951 +" teq %1, #0\n"
952 +" bne 1b"
953 +
954 +#ifdef CONFIG_PAX_REFCOUNT
955 +"\n4:\n"
956 + _ASM_EXTABLE(2b, 4b)
957 +#endif
958 +
959 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
960 + : "r" (&v->counter), "Ir" (i)
961 + : "cc");
962 +}
963 +
964 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
965 +{
966 + unsigned long tmp;
967 + int result;
968 +
969 + prefetchw(&v->counter);
970 + __asm__ __volatile__("@ atomic_add_unchecked\n"
971 "1: ldrex %0, [%3]\n"
972 " add %0, %0, %4\n"
973 " strex %1, %0, [%3]\n"
974 @@ -62,6 +110,42 @@ static inline int atomic_add_return(int i, atomic_t *v)
975 smp_mb();
976
977 __asm__ __volatile__("@ atomic_add_return\n"
978 +"1: ldrex %1, [%3]\n"
979 +" adds %0, %1, %4\n"
980 +
981 +#ifdef CONFIG_PAX_REFCOUNT
982 +" bvc 3f\n"
983 +" mov %0, %1\n"
984 +"2: bkpt 0xf103\n"
985 +"3:\n"
986 +#endif
987 +
988 +" strex %1, %0, [%3]\n"
989 +" teq %1, #0\n"
990 +" bne 1b"
991 +
992 +#ifdef CONFIG_PAX_REFCOUNT
993 +"\n4:\n"
994 + _ASM_EXTABLE(2b, 4b)
995 +#endif
996 +
997 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
998 + : "r" (&v->counter), "Ir" (i)
999 + : "cc");
1000 +
1001 + smp_mb();
1002 +
1003 + return result;
1004 +}
1005 +
1006 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1007 +{
1008 + unsigned long tmp;
1009 + int result;
1010 +
1011 + smp_mb();
1012 +
1013 + __asm__ __volatile__("@ atomic_add_return_unchecked\n"
1014 "1: ldrex %0, [%3]\n"
1015 " add %0, %0, %4\n"
1016 " strex %1, %0, [%3]\n"
1017 @@ -83,6 +167,36 @@ static inline void atomic_sub(int i, atomic_t *v)
1018
1019 prefetchw(&v->counter);
1020 __asm__ __volatile__("@ atomic_sub\n"
1021 +"1: ldrex %1, [%3]\n"
1022 +" subs %0, %1, %4\n"
1023 +
1024 +#ifdef CONFIG_PAX_REFCOUNT
1025 +" bvc 3f\n"
1026 +"2: bkpt 0xf103\n"
1027 +"3:\n"
1028 +#endif
1029 +
1030 +" strex %1, %0, [%3]\n"
1031 +" teq %1, #0\n"
1032 +" bne 1b"
1033 +
1034 +#ifdef CONFIG_PAX_REFCOUNT
1035 +"\n4:\n"
1036 + _ASM_EXTABLE(2b, 4b)
1037 +#endif
1038 +
1039 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1040 + : "r" (&v->counter), "Ir" (i)
1041 + : "cc");
1042 +}
1043 +
1044 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1045 +{
1046 + unsigned long tmp;
1047 + int result;
1048 +
1049 + prefetchw(&v->counter);
1050 + __asm__ __volatile__("@ atomic_sub_unchecked\n"
1051 "1: ldrex %0, [%3]\n"
1052 " sub %0, %0, %4\n"
1053 " strex %1, %0, [%3]\n"
1054 @@ -101,11 +215,25 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1055 smp_mb();
1056
1057 __asm__ __volatile__("@ atomic_sub_return\n"
1058 -"1: ldrex %0, [%3]\n"
1059 -" sub %0, %0, %4\n"
1060 +"1: ldrex %1, [%3]\n"
1061 +" subs %0, %1, %4\n"
1062 +
1063 +#ifdef CONFIG_PAX_REFCOUNT
1064 +" bvc 3f\n"
1065 +" mov %0, %1\n"
1066 +"2: bkpt 0xf103\n"
1067 +"3:\n"
1068 +#endif
1069 +
1070 " strex %1, %0, [%3]\n"
1071 " teq %1, #0\n"
1072 " bne 1b"
1073 +
1074 +#ifdef CONFIG_PAX_REFCOUNT
1075 +"\n4:\n"
1076 + _ASM_EXTABLE(2b, 4b)
1077 +#endif
1078 +
1079 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1080 : "r" (&v->counter), "Ir" (i)
1081 : "cc");
1082 @@ -138,6 +266,28 @@ static inline int atomic_cmpxchg(atomic_t *ptr, int old, int new)
1083 return oldval;
1084 }
1085
1086 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *ptr, int old, int new)
1087 +{
1088 + unsigned long oldval, res;
1089 +
1090 + smp_mb();
1091 +
1092 + do {
1093 + __asm__ __volatile__("@ atomic_cmpxchg_unchecked\n"
1094 + "ldrex %1, [%3]\n"
1095 + "mov %0, #0\n"
1096 + "teq %1, %4\n"
1097 + "strexeq %0, %5, [%3]\n"
1098 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1099 + : "r" (&ptr->counter), "Ir" (old), "r" (new)
1100 + : "cc");
1101 + } while (res);
1102 +
1103 + smp_mb();
1104 +
1105 + return oldval;
1106 +}
1107 +
1108 #else /* ARM_ARCH_6 */
1109
1110 #ifdef CONFIG_SMP
1111 @@ -156,7 +306,17 @@ static inline int atomic_add_return(int i, atomic_t *v)
1112
1113 return val;
1114 }
1115 +
1116 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
1117 +{
1118 + return atomic_add_return(i, v);
1119 +}
1120 +
1121 #define atomic_add(i, v) (void) atomic_add_return(i, v)
1122 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
1123 +{
1124 + (void) atomic_add_return(i, v);
1125 +}
1126
1127 static inline int atomic_sub_return(int i, atomic_t *v)
1128 {
1129 @@ -171,6 +331,10 @@ static inline int atomic_sub_return(int i, atomic_t *v)
1130 return val;
1131 }
1132 #define atomic_sub(i, v) (void) atomic_sub_return(i, v)
1133 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
1134 +{
1135 + (void) atomic_sub_return(i, v);
1136 +}
1137
1138 static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1139 {
1140 @@ -186,9 +350,18 @@ static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
1141 return ret;
1142 }
1143
1144 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
1145 +{
1146 + return atomic_cmpxchg(v, old, new);
1147 +}
1148 +
1149 #endif /* __LINUX_ARM_ARCH__ */
1150
1151 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
1152 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
1153 +{
1154 + return xchg(&v->counter, new);
1155 +}
1156
1157 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1158 {
1159 @@ -201,11 +374,27 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
1160 }
1161
1162 #define atomic_inc(v) atomic_add(1, v)
1163 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
1164 +{
1165 + atomic_add_unchecked(1, v);
1166 +}
1167 #define atomic_dec(v) atomic_sub(1, v)
1168 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
1169 +{
1170 + atomic_sub_unchecked(1, v);
1171 +}
1172
1173 #define atomic_inc_and_test(v) (atomic_add_return(1, v) == 0)
1174 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
1175 +{
1176 + return atomic_add_return_unchecked(1, v) == 0;
1177 +}
1178 #define atomic_dec_and_test(v) (atomic_sub_return(1, v) == 0)
1179 #define atomic_inc_return(v) (atomic_add_return(1, v))
1180 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
1181 +{
1182 + return atomic_add_return_unchecked(1, v);
1183 +}
1184 #define atomic_dec_return(v) (atomic_sub_return(1, v))
1185 #define atomic_sub_and_test(i, v) (atomic_sub_return(i, v) == 0)
1186
1187 @@ -221,6 +410,14 @@ typedef struct {
1188 long long counter;
1189 } atomic64_t;
1190
1191 +#ifdef CONFIG_PAX_REFCOUNT
1192 +typedef struct {
1193 + long long counter;
1194 +} atomic64_unchecked_t;
1195 +#else
1196 +typedef atomic64_t atomic64_unchecked_t;
1197 +#endif
1198 +
1199 #define ATOMIC64_INIT(i) { (i) }
1200
1201 #ifdef CONFIG_ARM_LPAE
1202 @@ -237,6 +434,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1203 return result;
1204 }
1205
1206 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1207 +{
1208 + long long result;
1209 +
1210 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1211 +" ldrd %0, %H0, [%1]"
1212 + : "=&r" (result)
1213 + : "r" (&v->counter), "Qo" (v->counter)
1214 + );
1215 +
1216 + return result;
1217 +}
1218 +
1219 static inline void atomic64_set(atomic64_t *v, long long i)
1220 {
1221 __asm__ __volatile__("@ atomic64_set\n"
1222 @@ -245,6 +455,15 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1223 : "r" (&v->counter), "r" (i)
1224 );
1225 }
1226 +
1227 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1228 +{
1229 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1230 +" strd %2, %H2, [%1]"
1231 + : "=Qo" (v->counter)
1232 + : "r" (&v->counter), "r" (i)
1233 + );
1234 +}
1235 #else
1236 static inline long long atomic64_read(const atomic64_t *v)
1237 {
1238 @@ -259,6 +478,19 @@ static inline long long atomic64_read(const atomic64_t *v)
1239 return result;
1240 }
1241
1242 +static inline long long atomic64_read_unchecked(const atomic64_unchecked_t *v)
1243 +{
1244 + long long result;
1245 +
1246 + __asm__ __volatile__("@ atomic64_read_unchecked\n"
1247 +" ldrexd %0, %H0, [%1]"
1248 + : "=&r" (result)
1249 + : "r" (&v->counter), "Qo" (v->counter)
1250 + );
1251 +
1252 + return result;
1253 +}
1254 +
1255 static inline void atomic64_set(atomic64_t *v, long long i)
1256 {
1257 long long tmp;
1258 @@ -273,6 +505,21 @@ static inline void atomic64_set(atomic64_t *v, long long i)
1259 : "r" (&v->counter), "r" (i)
1260 : "cc");
1261 }
1262 +
1263 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
1264 +{
1265 + long long tmp;
1266 +
1267 + prefetchw(&v->counter);
1268 + __asm__ __volatile__("@ atomic64_set_unchecked\n"
1269 +"1: ldrexd %0, %H0, [%2]\n"
1270 +" strexd %0, %3, %H3, [%2]\n"
1271 +" teq %0, #0\n"
1272 +" bne 1b"
1273 + : "=&r" (tmp), "=Qo" (v->counter)
1274 + : "r" (&v->counter), "r" (i)
1275 + : "cc");
1276 +}
1277 #endif
1278
1279 static inline void atomic64_add(long long i, atomic64_t *v)
1280 @@ -284,6 +531,37 @@ static inline void atomic64_add(long long i, atomic64_t *v)
1281 __asm__ __volatile__("@ atomic64_add\n"
1282 "1: ldrexd %0, %H0, [%3]\n"
1283 " adds %Q0, %Q0, %Q4\n"
1284 +" adcs %R0, %R0, %R4\n"
1285 +
1286 +#ifdef CONFIG_PAX_REFCOUNT
1287 +" bvc 3f\n"
1288 +"2: bkpt 0xf103\n"
1289 +"3:\n"
1290 +#endif
1291 +
1292 +" strexd %1, %0, %H0, [%3]\n"
1293 +" teq %1, #0\n"
1294 +" bne 1b"
1295 +
1296 +#ifdef CONFIG_PAX_REFCOUNT
1297 +"\n4:\n"
1298 + _ASM_EXTABLE(2b, 4b)
1299 +#endif
1300 +
1301 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1302 + : "r" (&v->counter), "r" (i)
1303 + : "cc");
1304 +}
1305 +
1306 +static inline void atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
1307 +{
1308 + long long result;
1309 + unsigned long tmp;
1310 +
1311 + prefetchw(&v->counter);
1312 + __asm__ __volatile__("@ atomic64_add_unchecked\n"
1313 +"1: ldrexd %0, %H0, [%3]\n"
1314 +" adds %Q0, %Q0, %Q4\n"
1315 " adc %R0, %R0, %R4\n"
1316 " strexd %1, %0, %H0, [%3]\n"
1317 " teq %1, #0\n"
1318 @@ -303,6 +581,44 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
1319 __asm__ __volatile__("@ atomic64_add_return\n"
1320 "1: ldrexd %0, %H0, [%3]\n"
1321 " adds %Q0, %Q0, %Q4\n"
1322 +" adcs %R0, %R0, %R4\n"
1323 +
1324 +#ifdef CONFIG_PAX_REFCOUNT
1325 +" bvc 3f\n"
1326 +" mov %0, %1\n"
1327 +" mov %H0, %H1\n"
1328 +"2: bkpt 0xf103\n"
1329 +"3:\n"
1330 +#endif
1331 +
1332 +" strexd %1, %0, %H0, [%3]\n"
1333 +" teq %1, #0\n"
1334 +" bne 1b"
1335 +
1336 +#ifdef CONFIG_PAX_REFCOUNT
1337 +"\n4:\n"
1338 + _ASM_EXTABLE(2b, 4b)
1339 +#endif
1340 +
1341 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1342 + : "r" (&v->counter), "r" (i)
1343 + : "cc");
1344 +
1345 + smp_mb();
1346 +
1347 + return result;
1348 +}
1349 +
1350 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
1351 +{
1352 + long long result;
1353 + unsigned long tmp;
1354 +
1355 + smp_mb();
1356 +
1357 + __asm__ __volatile__("@ atomic64_add_return_unchecked\n"
1358 +"1: ldrexd %0, %H0, [%3]\n"
1359 +" adds %Q0, %Q0, %Q4\n"
1360 " adc %R0, %R0, %R4\n"
1361 " strexd %1, %0, %H0, [%3]\n"
1362 " teq %1, #0\n"
1363 @@ -325,6 +641,37 @@ static inline void atomic64_sub(long long i, atomic64_t *v)
1364 __asm__ __volatile__("@ atomic64_sub\n"
1365 "1: ldrexd %0, %H0, [%3]\n"
1366 " subs %Q0, %Q0, %Q4\n"
1367 +" sbcs %R0, %R0, %R4\n"
1368 +
1369 +#ifdef CONFIG_PAX_REFCOUNT
1370 +" bvc 3f\n"
1371 +"2: bkpt 0xf103\n"
1372 +"3:\n"
1373 +#endif
1374 +
1375 +" strexd %1, %0, %H0, [%3]\n"
1376 +" teq %1, #0\n"
1377 +" bne 1b"
1378 +
1379 +#ifdef CONFIG_PAX_REFCOUNT
1380 +"\n4:\n"
1381 + _ASM_EXTABLE(2b, 4b)
1382 +#endif
1383 +
1384 + : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1385 + : "r" (&v->counter), "r" (i)
1386 + : "cc");
1387 +}
1388 +
1389 +static inline void atomic64_sub_unchecked(long long i, atomic64_unchecked_t *v)
1390 +{
1391 + long long result;
1392 + unsigned long tmp;
1393 +
1394 + prefetchw(&v->counter);
1395 + __asm__ __volatile__("@ atomic64_sub_unchecked\n"
1396 +"1: ldrexd %0, %H0, [%3]\n"
1397 +" subs %Q0, %Q0, %Q4\n"
1398 " sbc %R0, %R0, %R4\n"
1399 " strexd %1, %0, %H0, [%3]\n"
1400 " teq %1, #0\n"
1401 @@ -344,17 +691,28 @@ static inline long long atomic64_sub_return(long long i, atomic64_t *v)
1402 __asm__ __volatile__("@ atomic64_sub_return\n"
1403 "1: ldrexd %0, %H0, [%3]\n"
1404 " subs %Q0, %Q0, %Q4\n"
1405 -" sbc %R0, %R0, %R4\n"
1406 +" sbcs %R0, %R0, %R4\n"
1407 +
1408 +#ifdef CONFIG_PAX_REFCOUNT
1409 +" bvc 3f\n"
1410 +" mov %0, %1\n"
1411 +" mov %H0, %H1\n"
1412 +"2: bkpt 0xf103\n"
1413 +"3:\n"
1414 +#endif
1415 +
1416 " strexd %1, %0, %H0, [%3]\n"
1417 " teq %1, #0\n"
1418 " bne 1b"
1419 +
1420 +#ifdef CONFIG_PAX_REFCOUNT
1421 +"\n4:\n"
1422 + _ASM_EXTABLE(2b, 4b)
1423 +#endif
1424 +
1425 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1426 : "r" (&v->counter), "r" (i)
1427 : "cc");
1428 -
1429 - smp_mb();
1430 -
1431 - return result;
1432 }
1433
1434 static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1435 @@ -382,6 +740,31 @@ static inline long long atomic64_cmpxchg(atomic64_t *ptr, long long old,
1436 return oldval;
1437 }
1438
1439 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *ptr, long long old,
1440 + long long new)
1441 +{
1442 + long long oldval;
1443 + unsigned long res;
1444 +
1445 + smp_mb();
1446 +
1447 + do {
1448 + __asm__ __volatile__("@ atomic64_cmpxchg_unchecked\n"
1449 + "ldrexd %1, %H1, [%3]\n"
1450 + "mov %0, #0\n"
1451 + "teq %1, %4\n"
1452 + "teqeq %H1, %H4\n"
1453 + "strexdeq %0, %5, %H5, [%3]"
1454 + : "=&r" (res), "=&r" (oldval), "+Qo" (ptr->counter)
1455 + : "r" (&ptr->counter), "r" (old), "r" (new)
1456 + : "cc");
1457 + } while (res);
1458 +
1459 + smp_mb();
1460 +
1461 + return oldval;
1462 +}
1463 +
1464 static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1465 {
1466 long long result;
1467 @@ -406,20 +789,34 @@ static inline long long atomic64_xchg(atomic64_t *ptr, long long new)
1468 static inline long long atomic64_dec_if_positive(atomic64_t *v)
1469 {
1470 long long result;
1471 - unsigned long tmp;
1472 + u64 tmp;
1473
1474 smp_mb();
1475
1476 __asm__ __volatile__("@ atomic64_dec_if_positive\n"
1477 -"1: ldrexd %0, %H0, [%3]\n"
1478 -" subs %Q0, %Q0, #1\n"
1479 -" sbc %R0, %R0, #0\n"
1480 +"1: ldrexd %1, %H1, [%3]\n"
1481 +" subs %Q0, %Q1, #1\n"
1482 +" sbcs %R0, %R1, #0\n"
1483 +
1484 +#ifdef CONFIG_PAX_REFCOUNT
1485 +" bvc 3f\n"
1486 +" mov %Q0, %Q1\n"
1487 +" mov %R0, %R1\n"
1488 +"2: bkpt 0xf103\n"
1489 +"3:\n"
1490 +#endif
1491 +
1492 " teq %R0, #0\n"
1493 -" bmi 2f\n"
1494 +" bmi 4f\n"
1495 " strexd %1, %0, %H0, [%3]\n"
1496 " teq %1, #0\n"
1497 " bne 1b\n"
1498 -"2:"
1499 +"4:\n"
1500 +
1501 +#ifdef CONFIG_PAX_REFCOUNT
1502 + _ASM_EXTABLE(2b, 4b)
1503 +#endif
1504 +
1505 : "=&r" (result), "=&r" (tmp), "+Qo" (v->counter)
1506 : "r" (&v->counter)
1507 : "cc");
1508 @@ -442,13 +839,25 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1509 " teq %0, %5\n"
1510 " teqeq %H0, %H5\n"
1511 " moveq %1, #0\n"
1512 -" beq 2f\n"
1513 +" beq 4f\n"
1514 " adds %Q0, %Q0, %Q6\n"
1515 -" adc %R0, %R0, %R6\n"
1516 +" adcs %R0, %R0, %R6\n"
1517 +
1518 +#ifdef CONFIG_PAX_REFCOUNT
1519 +" bvc 3f\n"
1520 +"2: bkpt 0xf103\n"
1521 +"3:\n"
1522 +#endif
1523 +
1524 " strexd %2, %0, %H0, [%4]\n"
1525 " teq %2, #0\n"
1526 " bne 1b\n"
1527 -"2:"
1528 +"4:\n"
1529 +
1530 +#ifdef CONFIG_PAX_REFCOUNT
1531 + _ASM_EXTABLE(2b, 4b)
1532 +#endif
1533 +
1534 : "=&r" (val), "+r" (ret), "=&r" (tmp), "+Qo" (v->counter)
1535 : "r" (&v->counter), "r" (u), "r" (a)
1536 : "cc");
1537 @@ -461,10 +870,13 @@ static inline int atomic64_add_unless(atomic64_t *v, long long a, long long u)
1538
1539 #define atomic64_add_negative(a, v) (atomic64_add_return((a), (v)) < 0)
1540 #define atomic64_inc(v) atomic64_add(1LL, (v))
1541 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1LL, (v))
1542 #define atomic64_inc_return(v) atomic64_add_return(1LL, (v))
1543 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1LL, (v))
1544 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
1545 #define atomic64_sub_and_test(a, v) (atomic64_sub_return((a), (v)) == 0)
1546 #define atomic64_dec(v) atomic64_sub(1LL, (v))
1547 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1LL, (v))
1548 #define atomic64_dec_return(v) atomic64_sub_return(1LL, (v))
1549 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
1550 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
1551 diff --git a/arch/arm/include/asm/cache.h b/arch/arm/include/asm/cache.h
1552 index 75fe66b..ba3dee4 100644
1553 --- a/arch/arm/include/asm/cache.h
1554 +++ b/arch/arm/include/asm/cache.h
1555 @@ -4,8 +4,10 @@
1556 #ifndef __ASMARM_CACHE_H
1557 #define __ASMARM_CACHE_H
1558
1559 +#include <linux/const.h>
1560 +
1561 #define L1_CACHE_SHIFT CONFIG_ARM_L1_CACHE_SHIFT
1562 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
1563 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
1564
1565 /*
1566 * Memory returned by kmalloc() may be used for DMA, so we must make
1567 @@ -24,5 +26,6 @@
1568 #endif
1569
1570 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
1571 +#define __read_only __attribute__ ((__section__(".data..read_only")))
1572
1573 #endif
1574 diff --git a/arch/arm/include/asm/cacheflush.h b/arch/arm/include/asm/cacheflush.h
1575 index ee753f1..c9c30a5 100644
1576 --- a/arch/arm/include/asm/cacheflush.h
1577 +++ b/arch/arm/include/asm/cacheflush.h
1578 @@ -116,7 +116,7 @@ struct cpu_cache_fns {
1579 void (*dma_unmap_area)(const void *, size_t, int);
1580
1581 void (*dma_flush_range)(const void *, const void *);
1582 -};
1583 +} __no_const;
1584
1585 /*
1586 * Select the calling method
1587 diff --git a/arch/arm/include/asm/checksum.h b/arch/arm/include/asm/checksum.h
1588 index 6dcc164..b14d917 100644
1589 --- a/arch/arm/include/asm/checksum.h
1590 +++ b/arch/arm/include/asm/checksum.h
1591 @@ -37,7 +37,19 @@ __wsum
1592 csum_partial_copy_nocheck(const void *src, void *dst, int len, __wsum sum);
1593
1594 __wsum
1595 -csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1596 +__csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr);
1597 +
1598 +static inline __wsum
1599 +csum_partial_copy_from_user(const void __user *src, void *dst, int len, __wsum sum, int *err_ptr)
1600 +{
1601 + __wsum ret;
1602 + pax_open_userland();
1603 + ret = __csum_partial_copy_from_user(src, dst, len, sum, err_ptr);
1604 + pax_close_userland();
1605 + return ret;
1606 +}
1607 +
1608 +
1609
1610 /*
1611 * Fold a partial checksum without adding pseudo headers
1612 diff --git a/arch/arm/include/asm/cmpxchg.h b/arch/arm/include/asm/cmpxchg.h
1613 index df2fbba..63fe3e1 100644
1614 --- a/arch/arm/include/asm/cmpxchg.h
1615 +++ b/arch/arm/include/asm/cmpxchg.h
1616 @@ -102,6 +102,8 @@ static inline unsigned long __xchg(unsigned long x, volatile void *ptr, int size
1617
1618 #define xchg(ptr,x) \
1619 ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1620 +#define xchg_unchecked(ptr,x) \
1621 + ((__typeof__(*(ptr)))__xchg((unsigned long)(x),(ptr),sizeof(*(ptr))))
1622
1623 #include <asm-generic/cmpxchg-local.h>
1624
1625 diff --git a/arch/arm/include/asm/domain.h b/arch/arm/include/asm/domain.h
1626 index 6ddbe44..b5e38b1 100644
1627 --- a/arch/arm/include/asm/domain.h
1628 +++ b/arch/arm/include/asm/domain.h
1629 @@ -48,18 +48,37 @@
1630 * Domain types
1631 */
1632 #define DOMAIN_NOACCESS 0
1633 -#define DOMAIN_CLIENT 1
1634 #ifdef CONFIG_CPU_USE_DOMAINS
1635 +#define DOMAIN_USERCLIENT 1
1636 +#define DOMAIN_KERNELCLIENT 1
1637 #define DOMAIN_MANAGER 3
1638 +#define DOMAIN_VECTORS DOMAIN_USER
1639 #else
1640 +
1641 +#ifdef CONFIG_PAX_KERNEXEC
1642 #define DOMAIN_MANAGER 1
1643 +#define DOMAIN_KERNEXEC 3
1644 +#else
1645 +#define DOMAIN_MANAGER 1
1646 +#endif
1647 +
1648 +#ifdef CONFIG_PAX_MEMORY_UDEREF
1649 +#define DOMAIN_USERCLIENT 0
1650 +#define DOMAIN_UDEREF 1
1651 +#define DOMAIN_VECTORS DOMAIN_KERNEL
1652 +#else
1653 +#define DOMAIN_USERCLIENT 1
1654 +#define DOMAIN_VECTORS DOMAIN_USER
1655 +#endif
1656 +#define DOMAIN_KERNELCLIENT 1
1657 +
1658 #endif
1659
1660 #define domain_val(dom,type) ((type) << (2*(dom)))
1661
1662 #ifndef __ASSEMBLY__
1663
1664 -#ifdef CONFIG_CPU_USE_DOMAINS
1665 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
1666 static inline void set_domain(unsigned val)
1667 {
1668 asm volatile(
1669 @@ -68,15 +87,7 @@ static inline void set_domain(unsigned val)
1670 isb();
1671 }
1672
1673 -#define modify_domain(dom,type) \
1674 - do { \
1675 - struct thread_info *thread = current_thread_info(); \
1676 - unsigned int domain = thread->cpu_domain; \
1677 - domain &= ~domain_val(dom, DOMAIN_MANAGER); \
1678 - thread->cpu_domain = domain | domain_val(dom, type); \
1679 - set_domain(thread->cpu_domain); \
1680 - } while (0)
1681 -
1682 +extern void modify_domain(unsigned int dom, unsigned int type);
1683 #else
1684 static inline void set_domain(unsigned val) { }
1685 static inline void modify_domain(unsigned dom, unsigned type) { }
1686 diff --git a/arch/arm/include/asm/elf.h b/arch/arm/include/asm/elf.h
1687 index f4b46d3..abc9b2b 100644
1688 --- a/arch/arm/include/asm/elf.h
1689 +++ b/arch/arm/include/asm/elf.h
1690 @@ -114,7 +114,14 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1691 the loader. We need to make sure that it is out of the way of the program
1692 that it will "exec", and that there is sufficient room for the brk. */
1693
1694 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
1695 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
1696 +
1697 +#ifdef CONFIG_PAX_ASLR
1698 +#define PAX_ELF_ET_DYN_BASE 0x00008000UL
1699 +
1700 +#define PAX_DELTA_MMAP_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1701 +#define PAX_DELTA_STACK_LEN ((current->personality == PER_LINUX_32BIT) ? 16 : 10)
1702 +#endif
1703
1704 /* When the program starts, a1 contains a pointer to a function to be
1705 registered with atexit, as per the SVR4 ABI. A value of 0 means we
1706 @@ -124,10 +131,6 @@ int dump_task_regs(struct task_struct *t, elf_gregset_t *elfregs);
1707 extern void elf_set_personality(const struct elf32_hdr *);
1708 #define SET_PERSONALITY(ex) elf_set_personality(&(ex))
1709
1710 -struct mm_struct;
1711 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
1712 -#define arch_randomize_brk arch_randomize_brk
1713 -
1714 #ifdef CONFIG_MMU
1715 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
1716 struct linux_binprm;
1717 diff --git a/arch/arm/include/asm/fncpy.h b/arch/arm/include/asm/fncpy.h
1718 index de53547..52b9a28 100644
1719 --- a/arch/arm/include/asm/fncpy.h
1720 +++ b/arch/arm/include/asm/fncpy.h
1721 @@ -81,7 +81,9 @@
1722 BUG_ON((uintptr_t)(dest_buf) & (FNCPY_ALIGN - 1) || \
1723 (__funcp_address & ~(uintptr_t)1 & (FNCPY_ALIGN - 1))); \
1724 \
1725 + pax_open_kernel(); \
1726 memcpy(dest_buf, (void const *)(__funcp_address & ~1), size); \
1727 + pax_close_kernel(); \
1728 flush_icache_range((unsigned long)(dest_buf), \
1729 (unsigned long)(dest_buf) + (size)); \
1730 \
1731 diff --git a/arch/arm/include/asm/futex.h b/arch/arm/include/asm/futex.h
1732 index e42cf59..7b94b8f 100644
1733 --- a/arch/arm/include/asm/futex.h
1734 +++ b/arch/arm/include/asm/futex.h
1735 @@ -50,6 +50,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1736 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1737 return -EFAULT;
1738
1739 + pax_open_userland();
1740 +
1741 smp_mb();
1742 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1743 "1: ldrex %1, [%4]\n"
1744 @@ -65,6 +67,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1745 : "cc", "memory");
1746 smp_mb();
1747
1748 + pax_close_userland();
1749 +
1750 *uval = val;
1751 return ret;
1752 }
1753 @@ -95,6 +99,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1754 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
1755 return -EFAULT;
1756
1757 + pax_open_userland();
1758 +
1759 __asm__ __volatile__("@futex_atomic_cmpxchg_inatomic\n"
1760 "1: " TUSER(ldr) " %1, [%4]\n"
1761 " teq %1, %2\n"
1762 @@ -105,6 +111,8 @@ futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
1763 : "r" (oldval), "r" (newval), "r" (uaddr), "Ir" (-EFAULT)
1764 : "cc", "memory");
1765
1766 + pax_close_userland();
1767 +
1768 *uval = val;
1769 return ret;
1770 }
1771 @@ -127,6 +135,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1772 return -EFAULT;
1773
1774 pagefault_disable(); /* implies preempt_disable() */
1775 + pax_open_userland();
1776
1777 switch (op) {
1778 case FUTEX_OP_SET:
1779 @@ -148,6 +157,7 @@ futex_atomic_op_inuser (int encoded_op, u32 __user *uaddr)
1780 ret = -ENOSYS;
1781 }
1782
1783 + pax_close_userland();
1784 pagefault_enable(); /* subsumes preempt_enable() */
1785
1786 if (!ret) {
1787 diff --git a/arch/arm/include/asm/kmap_types.h b/arch/arm/include/asm/kmap_types.h
1788 index 83eb2f7..ed77159 100644
1789 --- a/arch/arm/include/asm/kmap_types.h
1790 +++ b/arch/arm/include/asm/kmap_types.h
1791 @@ -4,6 +4,6 @@
1792 /*
1793 * This is the "bare minimum". AIO seems to require this.
1794 */
1795 -#define KM_TYPE_NR 16
1796 +#define KM_TYPE_NR 17
1797
1798 #endif
1799 diff --git a/arch/arm/include/asm/mach/dma.h b/arch/arm/include/asm/mach/dma.h
1800 index 9e614a1..3302cca 100644
1801 --- a/arch/arm/include/asm/mach/dma.h
1802 +++ b/arch/arm/include/asm/mach/dma.h
1803 @@ -22,7 +22,7 @@ struct dma_ops {
1804 int (*residue)(unsigned int, dma_t *); /* optional */
1805 int (*setspeed)(unsigned int, dma_t *, int); /* optional */
1806 const char *type;
1807 -};
1808 +} __do_const;
1809
1810 struct dma_struct {
1811 void *addr; /* single DMA address */
1812 diff --git a/arch/arm/include/asm/mach/map.h b/arch/arm/include/asm/mach/map.h
1813 index 2fe141f..192dc01 100644
1814 --- a/arch/arm/include/asm/mach/map.h
1815 +++ b/arch/arm/include/asm/mach/map.h
1816 @@ -27,13 +27,16 @@ struct map_desc {
1817 #define MT_MINICLEAN 6
1818 #define MT_LOW_VECTORS 7
1819 #define MT_HIGH_VECTORS 8
1820 -#define MT_MEMORY 9
1821 +#define MT_MEMORY_RWX 9
1822 #define MT_ROM 10
1823 -#define MT_MEMORY_NONCACHED 11
1824 +#define MT_MEMORY_NONCACHED_RX 11
1825 #define MT_MEMORY_DTCM 12
1826 #define MT_MEMORY_ITCM 13
1827 #define MT_MEMORY_SO 14
1828 #define MT_MEMORY_DMA_READY 15
1829 +#define MT_MEMORY_RW 16
1830 +#define MT_MEMORY_RX 17
1831 +#define MT_MEMORY_NONCACHED_RW 18
1832
1833 #ifdef CONFIG_MMU
1834 extern void iotable_init(struct map_desc *, int);
1835 diff --git a/arch/arm/include/asm/outercache.h b/arch/arm/include/asm/outercache.h
1836 index f94784f..9a09a4a 100644
1837 --- a/arch/arm/include/asm/outercache.h
1838 +++ b/arch/arm/include/asm/outercache.h
1839 @@ -35,7 +35,7 @@ struct outer_cache_fns {
1840 #endif
1841 void (*set_debug)(unsigned long);
1842 void (*resume)(void);
1843 -};
1844 +} __no_const;
1845
1846 extern struct outer_cache_fns outer_cache;
1847
1848 diff --git a/arch/arm/include/asm/page.h b/arch/arm/include/asm/page.h
1849 index 4355f0e..c229913 100644
1850 --- a/arch/arm/include/asm/page.h
1851 +++ b/arch/arm/include/asm/page.h
1852 @@ -114,7 +114,7 @@ struct cpu_user_fns {
1853 void (*cpu_clear_user_highpage)(struct page *page, unsigned long vaddr);
1854 void (*cpu_copy_user_highpage)(struct page *to, struct page *from,
1855 unsigned long vaddr, struct vm_area_struct *vma);
1856 -};
1857 +} __no_const;
1858
1859 #ifdef MULTI_USER
1860 extern struct cpu_user_fns cpu_user;
1861 diff --git a/arch/arm/include/asm/pgalloc.h b/arch/arm/include/asm/pgalloc.h
1862 index 78a7793..e3dc06c 100644
1863 --- a/arch/arm/include/asm/pgalloc.h
1864 +++ b/arch/arm/include/asm/pgalloc.h
1865 @@ -17,6 +17,7 @@
1866 #include <asm/processor.h>
1867 #include <asm/cacheflush.h>
1868 #include <asm/tlbflush.h>
1869 +#include <asm/system_info.h>
1870
1871 #define check_pgt_cache() do { } while (0)
1872
1873 @@ -43,6 +44,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1874 set_pud(pud, __pud(__pa(pmd) | PMD_TYPE_TABLE));
1875 }
1876
1877 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1878 +{
1879 + pud_populate(mm, pud, pmd);
1880 +}
1881 +
1882 #else /* !CONFIG_ARM_LPAE */
1883
1884 /*
1885 @@ -51,6 +57,7 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
1886 #define pmd_alloc_one(mm,addr) ({ BUG(); ((pmd_t *)2); })
1887 #define pmd_free(mm, pmd) do { } while (0)
1888 #define pud_populate(mm,pmd,pte) BUG()
1889 +#define pud_populate_kernel(mm,pmd,pte) BUG()
1890
1891 #endif /* CONFIG_ARM_LPAE */
1892
1893 @@ -128,6 +135,19 @@ static inline void pte_free(struct mm_struct *mm, pgtable_t pte)
1894 __free_page(pte);
1895 }
1896
1897 +static inline void __section_update(pmd_t *pmdp, unsigned long addr, pmdval_t prot)
1898 +{
1899 +#ifdef CONFIG_ARM_LPAE
1900 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1901 +#else
1902 + if (addr & SECTION_SIZE)
1903 + pmdp[1] = __pmd(pmd_val(pmdp[1]) | prot);
1904 + else
1905 + pmdp[0] = __pmd(pmd_val(pmdp[0]) | prot);
1906 +#endif
1907 + flush_pmd_entry(pmdp);
1908 +}
1909 +
1910 static inline void __pmd_populate(pmd_t *pmdp, phys_addr_t pte,
1911 pmdval_t prot)
1912 {
1913 @@ -157,7 +177,7 @@ pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmdp, pte_t *ptep)
1914 static inline void
1915 pmd_populate(struct mm_struct *mm, pmd_t *pmdp, pgtable_t ptep)
1916 {
1917 - __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE);
1918 + __pmd_populate(pmdp, page_to_phys(ptep), _PAGE_USER_TABLE | __supported_pmd_mask);
1919 }
1920 #define pmd_pgtable(pmd) pmd_page(pmd)
1921
1922 diff --git a/arch/arm/include/asm/pgtable-2level-hwdef.h b/arch/arm/include/asm/pgtable-2level-hwdef.h
1923 index 5cfba15..f415e1a 100644
1924 --- a/arch/arm/include/asm/pgtable-2level-hwdef.h
1925 +++ b/arch/arm/include/asm/pgtable-2level-hwdef.h
1926 @@ -20,12 +20,15 @@
1927 #define PMD_TYPE_FAULT (_AT(pmdval_t, 0) << 0)
1928 #define PMD_TYPE_TABLE (_AT(pmdval_t, 1) << 0)
1929 #define PMD_TYPE_SECT (_AT(pmdval_t, 2) << 0)
1930 +#define PMD_PXNTABLE (_AT(pmdval_t, 1) << 2) /* v7 */
1931 #define PMD_BIT4 (_AT(pmdval_t, 1) << 4)
1932 #define PMD_DOMAIN(x) (_AT(pmdval_t, (x)) << 5)
1933 #define PMD_PROTECTION (_AT(pmdval_t, 1) << 9) /* v5 */
1934 +
1935 /*
1936 * - section
1937 */
1938 +#define PMD_SECT_PXN (_AT(pmdval_t, 1) << 0) /* v7 */
1939 #define PMD_SECT_BUFFERABLE (_AT(pmdval_t, 1) << 2)
1940 #define PMD_SECT_CACHEABLE (_AT(pmdval_t, 1) << 3)
1941 #define PMD_SECT_XN (_AT(pmdval_t, 1) << 4) /* v6 */
1942 @@ -37,6 +40,7 @@
1943 #define PMD_SECT_nG (_AT(pmdval_t, 1) << 17) /* v6 */
1944 #define PMD_SECT_SUPER (_AT(pmdval_t, 1) << 18) /* v6 */
1945 #define PMD_SECT_AF (_AT(pmdval_t, 0))
1946 +#define PMD_SECT_RDONLY (_AT(pmdval_t, 0))
1947
1948 #define PMD_SECT_UNCACHED (_AT(pmdval_t, 0))
1949 #define PMD_SECT_BUFFERED (PMD_SECT_BUFFERABLE)
1950 @@ -66,6 +70,7 @@
1951 * - extended small page/tiny page
1952 */
1953 #define PTE_EXT_XN (_AT(pteval_t, 1) << 0) /* v6 */
1954 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 2) /* v7 */
1955 #define PTE_EXT_AP_MASK (_AT(pteval_t, 3) << 4)
1956 #define PTE_EXT_AP0 (_AT(pteval_t, 1) << 4)
1957 #define PTE_EXT_AP1 (_AT(pteval_t, 2) << 4)
1958 diff --git a/arch/arm/include/asm/pgtable-2level.h b/arch/arm/include/asm/pgtable-2level.h
1959 index 86a659a..70e0120 100644
1960 --- a/arch/arm/include/asm/pgtable-2level.h
1961 +++ b/arch/arm/include/asm/pgtable-2level.h
1962 @@ -126,6 +126,9 @@
1963 #define L_PTE_SHARED (_AT(pteval_t, 1) << 10) /* shared(v6), coherent(xsc3) */
1964 #define L_PTE_NONE (_AT(pteval_t, 1) << 11)
1965
1966 +/* Two-level page tables only have PXN in the PGD, not in the PTE. */
1967 +#define L_PTE_PXN (_AT(pteval_t, 0))
1968 +
1969 /*
1970 * These are the memory types, defined to be compatible with
1971 * pre-ARMv6 CPUs cacheable and bufferable bits: XXCB
1972 diff --git a/arch/arm/include/asm/pgtable-3level-hwdef.h b/arch/arm/include/asm/pgtable-3level-hwdef.h
1973 index 626989f..9d67a33 100644
1974 --- a/arch/arm/include/asm/pgtable-3level-hwdef.h
1975 +++ b/arch/arm/include/asm/pgtable-3level-hwdef.h
1976 @@ -75,6 +75,7 @@
1977 #define PTE_EXT_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1978 #define PTE_EXT_AF (_AT(pteval_t, 1) << 10) /* Access Flag */
1979 #define PTE_EXT_NG (_AT(pteval_t, 1) << 11) /* nG */
1980 +#define PTE_EXT_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1981 #define PTE_EXT_XN (_AT(pteval_t, 1) << 54) /* XN */
1982
1983 /*
1984 diff --git a/arch/arm/include/asm/pgtable-3level.h b/arch/arm/include/asm/pgtable-3level.h
1985 index 4f95039..b2dd513 100644
1986 --- a/arch/arm/include/asm/pgtable-3level.h
1987 +++ b/arch/arm/include/asm/pgtable-3level.h
1988 @@ -82,6 +82,7 @@
1989 #define L_PTE_RDONLY (_AT(pteval_t, 1) << 7) /* AP[2] */
1990 #define L_PTE_SHARED (_AT(pteval_t, 3) << 8) /* SH[1:0], inner shareable */
1991 #define L_PTE_YOUNG (_AT(pteval_t, 1) << 10) /* AF */
1992 +#define L_PTE_PXN (_AT(pteval_t, 1) << 53) /* PXN */
1993 #define L_PTE_XN (_AT(pteval_t, 1) << 54) /* XN */
1994 #define L_PTE_DIRTY (_AT(pteval_t, 1) << 55) /* unused */
1995 #define L_PTE_SPECIAL (_AT(pteval_t, 1) << 56) /* unused */
1996 @@ -95,6 +96,7 @@
1997 /*
1998 * To be used in assembly code with the upper page attributes.
1999 */
2000 +#define L_PTE_PXN_HIGH (1 << (53 - 32))
2001 #define L_PTE_XN_HIGH (1 << (54 - 32))
2002 #define L_PTE_DIRTY_HIGH (1 << (55 - 32))
2003
2004 diff --git a/arch/arm/include/asm/pgtable.h b/arch/arm/include/asm/pgtable.h
2005 index 1571d12..b8a9b43 100644
2006 --- a/arch/arm/include/asm/pgtable.h
2007 +++ b/arch/arm/include/asm/pgtable.h
2008 @@ -33,6 +33,9 @@
2009 #include <asm/pgtable-2level.h>
2010 #endif
2011
2012 +#define ktla_ktva(addr) (addr)
2013 +#define ktva_ktla(addr) (addr)
2014 +
2015 /*
2016 * Just any arbitrary offset to the start of the vmalloc VM area: the
2017 * current 8MB value just means that there will be a 8MB "hole" after the
2018 @@ -48,6 +51,9 @@
2019 #define LIBRARY_TEXT_START 0x0c000000
2020
2021 #ifndef __ASSEMBLY__
2022 +extern pteval_t __supported_pte_mask;
2023 +extern pmdval_t __supported_pmd_mask;
2024 +
2025 extern void __pte_error(const char *file, int line, pte_t);
2026 extern void __pmd_error(const char *file, int line, pmd_t);
2027 extern void __pgd_error(const char *file, int line, pgd_t);
2028 @@ -56,6 +62,48 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2029 #define pmd_ERROR(pmd) __pmd_error(__FILE__, __LINE__, pmd)
2030 #define pgd_ERROR(pgd) __pgd_error(__FILE__, __LINE__, pgd)
2031
2032 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
2033 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
2034 +
2035 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2036 +#include <asm/domain.h>
2037 +#include <linux/thread_info.h>
2038 +#include <linux/preempt.h>
2039 +
2040 +static inline int test_domain(int domain, int domaintype)
2041 +{
2042 + return ((current_thread_info()->cpu_domain) & domain_val(domain, 3)) == domain_val(domain, domaintype);
2043 +}
2044 +#endif
2045 +
2046 +#ifdef CONFIG_PAX_KERNEXEC
2047 +static inline unsigned long pax_open_kernel(void) {
2048 +#ifdef CONFIG_ARM_LPAE
2049 + /* TODO */
2050 +#else
2051 + preempt_disable();
2052 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC));
2053 + modify_domain(DOMAIN_KERNEL, DOMAIN_KERNEXEC);
2054 +#endif
2055 + return 0;
2056 +}
2057 +
2058 +static inline unsigned long pax_close_kernel(void) {
2059 +#ifdef CONFIG_ARM_LPAE
2060 + /* TODO */
2061 +#else
2062 + BUG_ON(test_domain(DOMAIN_KERNEL, DOMAIN_MANAGER));
2063 + /* DOMAIN_MANAGER = "client" under KERNEXEC */
2064 + modify_domain(DOMAIN_KERNEL, DOMAIN_MANAGER);
2065 + preempt_enable_no_resched();
2066 +#endif
2067 + return 0;
2068 +}
2069 +#else
2070 +static inline unsigned long pax_open_kernel(void) { return 0; }
2071 +static inline unsigned long pax_close_kernel(void) { return 0; }
2072 +#endif
2073 +
2074 /*
2075 * This is the lowest virtual address we can permit any user space
2076 * mapping to be mapped at. This is particularly important for
2077 @@ -75,8 +123,8 @@ extern void __pgd_error(const char *file, int line, pgd_t);
2078 /*
2079 * The pgprot_* and protection_map entries will be fixed up in runtime
2080 * to include the cachable and bufferable bits based on memory policy,
2081 - * as well as any architecture dependent bits like global/ASID and SMP
2082 - * shared mapping bits.
2083 + * as well as any architecture dependent bits like global/ASID, PXN,
2084 + * and SMP shared mapping bits.
2085 */
2086 #define _L_PTE_DEFAULT L_PTE_PRESENT | L_PTE_YOUNG
2087
2088 @@ -260,7 +308,7 @@ static inline pte_t pte_mkspecial(pte_t pte) { return pte; }
2089 static inline pte_t pte_modify(pte_t pte, pgprot_t newprot)
2090 {
2091 const pteval_t mask = L_PTE_XN | L_PTE_RDONLY | L_PTE_USER |
2092 - L_PTE_NONE | L_PTE_VALID;
2093 + L_PTE_NONE | L_PTE_VALID | __supported_pte_mask;
2094 pte_val(pte) = (pte_val(pte) & ~mask) | (pgprot_val(newprot) & mask);
2095 return pte;
2096 }
2097 diff --git a/arch/arm/include/asm/proc-fns.h b/arch/arm/include/asm/proc-fns.h
2098 index 5324c11..bcae5f0 100644
2099 --- a/arch/arm/include/asm/proc-fns.h
2100 +++ b/arch/arm/include/asm/proc-fns.h
2101 @@ -75,7 +75,7 @@ extern struct processor {
2102 unsigned int suspend_size;
2103 void (*do_suspend)(void *);
2104 void (*do_resume)(void *);
2105 -} processor;
2106 +} __do_const processor;
2107
2108 #ifndef MULTI_CPU
2109 extern void cpu_proc_init(void);
2110 diff --git a/arch/arm/include/asm/psci.h b/arch/arm/include/asm/psci.h
2111 index c4ae171..ea0c0c2 100644
2112 --- a/arch/arm/include/asm/psci.h
2113 +++ b/arch/arm/include/asm/psci.h
2114 @@ -29,7 +29,7 @@ struct psci_operations {
2115 int (*cpu_off)(struct psci_power_state state);
2116 int (*cpu_on)(unsigned long cpuid, unsigned long entry_point);
2117 int (*migrate)(unsigned long cpuid);
2118 -};
2119 +} __no_const;
2120
2121 extern struct psci_operations psci_ops;
2122 extern struct smp_operations psci_smp_ops;
2123 diff --git a/arch/arm/include/asm/smp.h b/arch/arm/include/asm/smp.h
2124 index 22a3b9b..7f214ee 100644
2125 --- a/arch/arm/include/asm/smp.h
2126 +++ b/arch/arm/include/asm/smp.h
2127 @@ -112,7 +112,7 @@ struct smp_operations {
2128 int (*cpu_disable)(unsigned int cpu);
2129 #endif
2130 #endif
2131 -};
2132 +} __no_const;
2133
2134 /*
2135 * set platform specific SMP operations
2136 diff --git a/arch/arm/include/asm/thread_info.h b/arch/arm/include/asm/thread_info.h
2137 index 71a06b2..8bb9ae1 100644
2138 --- a/arch/arm/include/asm/thread_info.h
2139 +++ b/arch/arm/include/asm/thread_info.h
2140 @@ -88,9 +88,9 @@ struct thread_info {
2141 .flags = 0, \
2142 .preempt_count = INIT_PREEMPT_COUNT, \
2143 .addr_limit = KERNEL_DS, \
2144 - .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2145 - domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2146 - domain_val(DOMAIN_IO, DOMAIN_CLIENT), \
2147 + .cpu_domain = domain_val(DOMAIN_USER, DOMAIN_USERCLIENT) | \
2148 + domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT) | \
2149 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT), \
2150 .restart_block = { \
2151 .fn = do_no_restart_syscall, \
2152 }, \
2153 @@ -157,7 +157,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2154 #define TIF_SYSCALL_AUDIT 9
2155 #define TIF_SYSCALL_TRACEPOINT 10
2156 #define TIF_SECCOMP 11 /* seccomp syscall filtering active */
2157 -#define TIF_NOHZ 12 /* in adaptive nohz mode */
2158 +/* within 8 bits of TIF_SYSCALL_TRACE
2159 + * to meet flexible second operand requirements
2160 + */
2161 +#define TIF_GRSEC_SETXID 12
2162 +#define TIF_NOHZ 13 /* in adaptive nohz mode */
2163 #define TIF_USING_IWMMXT 17
2164 #define TIF_MEMDIE 18 /* is terminating due to OOM killer */
2165 #define TIF_RESTORE_SIGMASK 20
2166 @@ -170,10 +174,11 @@ extern int vfp_restore_user_hwstate(struct user_vfp __user *,
2167 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
2168 #define _TIF_SECCOMP (1 << TIF_SECCOMP)
2169 #define _TIF_USING_IWMMXT (1 << TIF_USING_IWMMXT)
2170 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
2171
2172 /* Checks for any syscall work in entry-common.S */
2173 #define _TIF_SYSCALL_WORK (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
2174 - _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP)
2175 + _TIF_SYSCALL_TRACEPOINT | _TIF_SECCOMP | _TIF_GRSEC_SETXID)
2176
2177 /*
2178 * Change these and you break ASM code in entry-common.S
2179 diff --git a/arch/arm/include/asm/uaccess.h b/arch/arm/include/asm/uaccess.h
2180 index 72abdc5..9eba222 100644
2181 --- a/arch/arm/include/asm/uaccess.h
2182 +++ b/arch/arm/include/asm/uaccess.h
2183 @@ -18,6 +18,7 @@
2184 #include <asm/domain.h>
2185 #include <asm/unified.h>
2186 #include <asm/compiler.h>
2187 +#include <asm/pgtable.h>
2188
2189 #if __LINUX_ARM_ARCH__ < 6
2190 #include <asm-generic/uaccess-unaligned.h>
2191 @@ -70,11 +71,38 @@ extern int __put_user_bad(void);
2192 static inline void set_fs(mm_segment_t fs)
2193 {
2194 current_thread_info()->addr_limit = fs;
2195 - modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_CLIENT : DOMAIN_MANAGER);
2196 + modify_domain(DOMAIN_KERNEL, fs ? DOMAIN_KERNELCLIENT : DOMAIN_MANAGER);
2197 }
2198
2199 #define segment_eq(a,b) ((a) == (b))
2200
2201 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
2202 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
2203 +
2204 +static inline void pax_open_userland(void)
2205 +{
2206 +
2207 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2208 + if (segment_eq(get_fs(), USER_DS)) {
2209 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_UDEREF));
2210 + modify_domain(DOMAIN_USER, DOMAIN_UDEREF);
2211 + }
2212 +#endif
2213 +
2214 +}
2215 +
2216 +static inline void pax_close_userland(void)
2217 +{
2218 +
2219 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2220 + if (segment_eq(get_fs(), USER_DS)) {
2221 + BUG_ON(test_domain(DOMAIN_USER, DOMAIN_NOACCESS));
2222 + modify_domain(DOMAIN_USER, DOMAIN_NOACCESS);
2223 + }
2224 +#endif
2225 +
2226 +}
2227 +
2228 #define __addr_ok(addr) ({ \
2229 unsigned long flag; \
2230 __asm__("cmp %2, %0; movlo %0, #0" \
2231 @@ -150,8 +178,12 @@ extern int __get_user_4(void *);
2232
2233 #define get_user(x,p) \
2234 ({ \
2235 + int __e; \
2236 might_fault(); \
2237 - __get_user_check(x,p); \
2238 + pax_open_userland(); \
2239 + __e = __get_user_check(x,p); \
2240 + pax_close_userland(); \
2241 + __e; \
2242 })
2243
2244 extern int __put_user_1(void *, unsigned int);
2245 @@ -195,8 +227,12 @@ extern int __put_user_8(void *, unsigned long long);
2246
2247 #define put_user(x,p) \
2248 ({ \
2249 + int __e; \
2250 might_fault(); \
2251 - __put_user_check(x,p); \
2252 + pax_open_userland(); \
2253 + __e = __put_user_check(x,p); \
2254 + pax_close_userland(); \
2255 + __e; \
2256 })
2257
2258 #else /* CONFIG_MMU */
2259 @@ -237,13 +273,17 @@ static inline void set_fs(mm_segment_t fs)
2260 #define __get_user(x,ptr) \
2261 ({ \
2262 long __gu_err = 0; \
2263 + pax_open_userland(); \
2264 __get_user_err((x),(ptr),__gu_err); \
2265 + pax_close_userland(); \
2266 __gu_err; \
2267 })
2268
2269 #define __get_user_error(x,ptr,err) \
2270 ({ \
2271 + pax_open_userland(); \
2272 __get_user_err((x),(ptr),err); \
2273 + pax_close_userland(); \
2274 (void) 0; \
2275 })
2276
2277 @@ -319,13 +359,17 @@ do { \
2278 #define __put_user(x,ptr) \
2279 ({ \
2280 long __pu_err = 0; \
2281 + pax_open_userland(); \
2282 __put_user_err((x),(ptr),__pu_err); \
2283 + pax_close_userland(); \
2284 __pu_err; \
2285 })
2286
2287 #define __put_user_error(x,ptr,err) \
2288 ({ \
2289 + pax_open_userland(); \
2290 __put_user_err((x),(ptr),err); \
2291 + pax_close_userland(); \
2292 (void) 0; \
2293 })
2294
2295 @@ -425,11 +469,44 @@ do { \
2296
2297
2298 #ifdef CONFIG_MMU
2299 -extern unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n);
2300 -extern unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n);
2301 +extern unsigned long __must_check ___copy_from_user(void *to, const void __user *from, unsigned long n);
2302 +extern unsigned long __must_check ___copy_to_user(void __user *to, const void *from, unsigned long n);
2303 +
2304 +static inline unsigned long __must_check __copy_from_user(void *to, const void __user *from, unsigned long n)
2305 +{
2306 + unsigned long ret;
2307 +
2308 + check_object_size(to, n, false);
2309 + pax_open_userland();
2310 + ret = ___copy_from_user(to, from, n);
2311 + pax_close_userland();
2312 + return ret;
2313 +}
2314 +
2315 +static inline unsigned long __must_check __copy_to_user(void __user *to, const void *from, unsigned long n)
2316 +{
2317 + unsigned long ret;
2318 +
2319 + check_object_size(from, n, true);
2320 + pax_open_userland();
2321 + ret = ___copy_to_user(to, from, n);
2322 + pax_close_userland();
2323 + return ret;
2324 +}
2325 +
2326 extern unsigned long __must_check __copy_to_user_std(void __user *to, const void *from, unsigned long n);
2327 -extern unsigned long __must_check __clear_user(void __user *addr, unsigned long n);
2328 +extern unsigned long __must_check ___clear_user(void __user *addr, unsigned long n);
2329 extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned long n);
2330 +
2331 +static inline unsigned long __must_check __clear_user(void __user *addr, unsigned long n)
2332 +{
2333 + unsigned long ret;
2334 + pax_open_userland();
2335 + ret = ___clear_user(addr, n);
2336 + pax_close_userland();
2337 + return ret;
2338 +}
2339 +
2340 #else
2341 #define __copy_from_user(to,from,n) (memcpy(to, (void __force *)from, n), 0)
2342 #define __copy_to_user(to,from,n) (memcpy((void __force *)to, from, n), 0)
2343 @@ -438,6 +515,9 @@ extern unsigned long __must_check __clear_user_std(void __user *addr, unsigned l
2344
2345 static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
2346 {
2347 + if ((long)n < 0)
2348 + return n;
2349 +
2350 if (access_ok(VERIFY_READ, from, n))
2351 n = __copy_from_user(to, from, n);
2352 else /* security hole - plug it */
2353 @@ -447,6 +527,9 @@ static inline unsigned long __must_check copy_from_user(void *to, const void __u
2354
2355 static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
2356 {
2357 + if ((long)n < 0)
2358 + return n;
2359 +
2360 if (access_ok(VERIFY_WRITE, to, n))
2361 n = __copy_to_user(to, from, n);
2362 return n;
2363 diff --git a/arch/arm/include/uapi/asm/ptrace.h b/arch/arm/include/uapi/asm/ptrace.h
2364 index 5af0ed1..cea83883 100644
2365 --- a/arch/arm/include/uapi/asm/ptrace.h
2366 +++ b/arch/arm/include/uapi/asm/ptrace.h
2367 @@ -92,7 +92,7 @@
2368 * ARMv7 groups of PSR bits
2369 */
2370 #define APSR_MASK 0xf80f0000 /* N, Z, C, V, Q and GE flags */
2371 -#define PSR_ISET_MASK 0x01000010 /* ISA state (J, T) mask */
2372 +#define PSR_ISET_MASK 0x01000020 /* ISA state (J, T) mask */
2373 #define PSR_IT_MASK 0x0600fc00 /* If-Then execution state mask */
2374 #define PSR_ENDIAN_MASK 0x00000200 /* Endianness state mask */
2375
2376 diff --git a/arch/arm/kernel/armksyms.c b/arch/arm/kernel/armksyms.c
2377 index 1f031dd..d9b5e4a 100644
2378 --- a/arch/arm/kernel/armksyms.c
2379 +++ b/arch/arm/kernel/armksyms.c
2380 @@ -53,7 +53,7 @@ EXPORT_SYMBOL(arm_delay_ops);
2381
2382 /* networking */
2383 EXPORT_SYMBOL(csum_partial);
2384 -EXPORT_SYMBOL(csum_partial_copy_from_user);
2385 +EXPORT_SYMBOL(__csum_partial_copy_from_user);
2386 EXPORT_SYMBOL(csum_partial_copy_nocheck);
2387 EXPORT_SYMBOL(__csum_ipv6_magic);
2388
2389 @@ -89,9 +89,9 @@ EXPORT_SYMBOL(__memzero);
2390 #ifdef CONFIG_MMU
2391 EXPORT_SYMBOL(copy_page);
2392
2393 -EXPORT_SYMBOL(__copy_from_user);
2394 -EXPORT_SYMBOL(__copy_to_user);
2395 -EXPORT_SYMBOL(__clear_user);
2396 +EXPORT_SYMBOL(___copy_from_user);
2397 +EXPORT_SYMBOL(___copy_to_user);
2398 +EXPORT_SYMBOL(___clear_user);
2399
2400 EXPORT_SYMBOL(__get_user_1);
2401 EXPORT_SYMBOL(__get_user_2);
2402 diff --git a/arch/arm/kernel/entry-armv.S b/arch/arm/kernel/entry-armv.S
2403 index b3fb8c9..59cfab2 100644
2404 --- a/arch/arm/kernel/entry-armv.S
2405 +++ b/arch/arm/kernel/entry-armv.S
2406 @@ -47,6 +47,87 @@
2407 9997:
2408 .endm
2409
2410 + .macro pax_enter_kernel
2411 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2412 + @ make aligned space for saved DACR
2413 + sub sp, sp, #8
2414 + @ save regs
2415 + stmdb sp!, {r1, r2}
2416 + @ read DACR from cpu_domain into r1
2417 + mov r2, sp
2418 + @ assume 8K pages, since we have to split the immediate in two
2419 + bic r2, r2, #(0x1fc0)
2420 + bic r2, r2, #(0x3f)
2421 + ldr r1, [r2, #TI_CPU_DOMAIN]
2422 + @ store old DACR on stack
2423 + str r1, [sp, #8]
2424 +#ifdef CONFIG_PAX_KERNEXEC
2425 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2426 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2427 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2428 +#endif
2429 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2430 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2431 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2432 +#endif
2433 + @ write r1 to current_thread_info()->cpu_domain
2434 + str r1, [r2, #TI_CPU_DOMAIN]
2435 + @ write r1 to DACR
2436 + mcr p15, 0, r1, c3, c0, 0
2437 + @ instruction sync
2438 + instr_sync
2439 + @ restore regs
2440 + ldmia sp!, {r1, r2}
2441 +#endif
2442 + .endm
2443 +
2444 + .macro pax_open_userland
2445 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2446 + @ save regs
2447 + stmdb sp!, {r0, r1}
2448 + @ read DACR from cpu_domain into r1
2449 + mov r0, sp
2450 + @ assume 8K pages, since we have to split the immediate in two
2451 + bic r0, r0, #(0x1fc0)
2452 + bic r0, r0, #(0x3f)
2453 + ldr r1, [r0, #TI_CPU_DOMAIN]
2454 + @ set current DOMAIN_USER to DOMAIN_CLIENT
2455 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2456 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2457 + @ write r1 to current_thread_info()->cpu_domain
2458 + str r1, [r0, #TI_CPU_DOMAIN]
2459 + @ write r1 to DACR
2460 + mcr p15, 0, r1, c3, c0, 0
2461 + @ instruction sync
2462 + instr_sync
2463 + @ restore regs
2464 + ldmia sp!, {r0, r1}
2465 +#endif
2466 + .endm
2467 +
2468 + .macro pax_close_userland
2469 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2470 + @ save regs
2471 + stmdb sp!, {r0, r1}
2472 + @ read DACR from cpu_domain into r1
2473 + mov r0, sp
2474 + @ assume 8K pages, since we have to split the immediate in two
2475 + bic r0, r0, #(0x1fc0)
2476 + bic r0, r0, #(0x3f)
2477 + ldr r1, [r0, #TI_CPU_DOMAIN]
2478 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2479 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2480 + @ write r1 to current_thread_info()->cpu_domain
2481 + str r1, [r0, #TI_CPU_DOMAIN]
2482 + @ write r1 to DACR
2483 + mcr p15, 0, r1, c3, c0, 0
2484 + @ instruction sync
2485 + instr_sync
2486 + @ restore regs
2487 + ldmia sp!, {r0, r1}
2488 +#endif
2489 + .endm
2490 +
2491 .macro pabt_helper
2492 @ PABORT handler takes pt_regs in r2, fault address in r4 and psr in r5
2493 #ifdef MULTI_PABORT
2494 @@ -89,11 +170,15 @@
2495 * Invalid mode handlers
2496 */
2497 .macro inv_entry, reason
2498 +
2499 + pax_enter_kernel
2500 +
2501 sub sp, sp, #S_FRAME_SIZE
2502 ARM( stmib sp, {r1 - lr} )
2503 THUMB( stmia sp, {r0 - r12} )
2504 THUMB( str sp, [sp, #S_SP] )
2505 THUMB( str lr, [sp, #S_LR] )
2506 +
2507 mov r1, #\reason
2508 .endm
2509
2510 @@ -149,7 +234,11 @@ ENDPROC(__und_invalid)
2511 .macro svc_entry, stack_hole=0
2512 UNWIND(.fnstart )
2513 UNWIND(.save {r0 - pc} )
2514 +
2515 + pax_enter_kernel
2516 +
2517 sub sp, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2518 +
2519 #ifdef CONFIG_THUMB2_KERNEL
2520 SPFIX( str r0, [sp] ) @ temporarily saved
2521 SPFIX( mov r0, sp )
2522 @@ -164,7 +253,12 @@ ENDPROC(__und_invalid)
2523 ldmia r0, {r3 - r5}
2524 add r7, sp, #S_SP - 4 @ here for interlock avoidance
2525 mov r6, #-1 @ "" "" "" ""
2526 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2527 + @ offset sp by 8 as done in pax_enter_kernel
2528 + add r2, sp, #(S_FRAME_SIZE + \stack_hole + 4)
2529 +#else
2530 add r2, sp, #(S_FRAME_SIZE + \stack_hole - 4)
2531 +#endif
2532 SPFIX( addeq r2, r2, #4 )
2533 str r3, [sp, #-4]! @ save the "real" r0 copied
2534 @ from the exception stack
2535 @@ -317,6 +411,9 @@ ENDPROC(__pabt_svc)
2536 .macro usr_entry
2537 UNWIND(.fnstart )
2538 UNWIND(.cantunwind ) @ don't unwind the user space
2539 +
2540 + pax_enter_kernel_user
2541 +
2542 sub sp, sp, #S_FRAME_SIZE
2543 ARM( stmib sp, {r1 - r12} )
2544 THUMB( stmia sp, {r0 - r12} )
2545 @@ -416,7 +513,9 @@ __und_usr:
2546 tst r3, #PSR_T_BIT @ Thumb mode?
2547 bne __und_usr_thumb
2548 sub r4, r2, #4 @ ARM instr at LR - 4
2549 + pax_open_userland
2550 1: ldrt r0, [r4]
2551 + pax_close_userland
2552 ARM_BE8(rev r0, r0) @ little endian instruction
2553
2554 @ r0 = 32-bit ARM instruction which caused the exception
2555 @@ -450,10 +549,14 @@ __und_usr_thumb:
2556 */
2557 .arch armv6t2
2558 #endif
2559 + pax_open_userland
2560 2: ldrht r5, [r4]
2561 + pax_close_userland
2562 cmp r5, #0xe800 @ 32bit instruction if xx != 0
2563 blo __und_usr_fault_16 @ 16bit undefined instruction
2564 + pax_open_userland
2565 3: ldrht r0, [r2]
2566 + pax_close_userland
2567 add r2, r2, #2 @ r2 is PC + 2, make it PC + 4
2568 str r2, [sp, #S_PC] @ it's a 2x16bit instr, update
2569 orr r0, r0, r5, lsl #16
2570 @@ -482,7 +585,8 @@ ENDPROC(__und_usr)
2571 */
2572 .pushsection .fixup, "ax"
2573 .align 2
2574 -4: mov pc, r9
2575 +4: pax_close_userland
2576 + mov pc, r9
2577 .popsection
2578 .pushsection __ex_table,"a"
2579 .long 1b, 4b
2580 @@ -692,7 +796,7 @@ ENTRY(__switch_to)
2581 THUMB( str lr, [ip], #4 )
2582 ldr r4, [r2, #TI_TP_VALUE]
2583 ldr r5, [r2, #TI_TP_VALUE + 4]
2584 -#ifdef CONFIG_CPU_USE_DOMAINS
2585 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2586 ldr r6, [r2, #TI_CPU_DOMAIN]
2587 #endif
2588 switch_tls r1, r4, r5, r3, r7
2589 @@ -701,7 +805,7 @@ ENTRY(__switch_to)
2590 ldr r8, =__stack_chk_guard
2591 ldr r7, [r7, #TSK_STACK_CANARY]
2592 #endif
2593 -#ifdef CONFIG_CPU_USE_DOMAINS
2594 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2595 mcr p15, 0, r6, c3, c0, 0 @ Set domain register
2596 #endif
2597 mov r5, r0
2598 diff --git a/arch/arm/kernel/entry-common.S b/arch/arm/kernel/entry-common.S
2599 index a2dcafd..1048b5a 100644
2600 --- a/arch/arm/kernel/entry-common.S
2601 +++ b/arch/arm/kernel/entry-common.S
2602 @@ -10,18 +10,46 @@
2603
2604 #include <asm/unistd.h>
2605 #include <asm/ftrace.h>
2606 +#include <asm/domain.h>
2607 #include <asm/unwind.h>
2608
2609 +#include "entry-header.S"
2610 +
2611 #ifdef CONFIG_NEED_RET_TO_USER
2612 #include <mach/entry-macro.S>
2613 #else
2614 .macro arch_ret_to_user, tmp1, tmp2
2615 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2616 + @ save regs
2617 + stmdb sp!, {r1, r2}
2618 + @ read DACR from cpu_domain into r1
2619 + mov r2, sp
2620 + @ assume 8K pages, since we have to split the immediate in two
2621 + bic r2, r2, #(0x1fc0)
2622 + bic r2, r2, #(0x3f)
2623 + ldr r1, [r2, #TI_CPU_DOMAIN]
2624 +#ifdef CONFIG_PAX_KERNEXEC
2625 + @ set type of DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2626 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2627 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2628 +#endif
2629 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2630 + @ set current DOMAIN_USER to DOMAIN_UDEREF
2631 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2632 + orr r1, r1, #(domain_val(DOMAIN_USER, DOMAIN_UDEREF))
2633 +#endif
2634 + @ write r1 to current_thread_info()->cpu_domain
2635 + str r1, [r2, #TI_CPU_DOMAIN]
2636 + @ write r1 to DACR
2637 + mcr p15, 0, r1, c3, c0, 0
2638 + @ instruction sync
2639 + instr_sync
2640 + @ restore regs
2641 + ldmia sp!, {r1, r2}
2642 +#endif
2643 .endm
2644 #endif
2645
2646 -#include "entry-header.S"
2647 -
2648 -
2649 .align 5
2650 /*
2651 * This is the fast syscall return path. We do as little as
2652 @@ -411,6 +439,12 @@ ENTRY(vector_swi)
2653 USER( ldr scno, [lr, #-4] ) @ get SWI instruction
2654 #endif
2655
2656 + /*
2657 + * do this here to avoid a performance hit of wrapping the code above
2658 + * that directly dereferences userland to parse the SWI instruction
2659 + */
2660 + pax_enter_kernel_user
2661 +
2662 adr tbl, sys_call_table @ load syscall table pointer
2663
2664 #if defined(CONFIG_OABI_COMPAT)
2665 diff --git a/arch/arm/kernel/entry-header.S b/arch/arm/kernel/entry-header.S
2666 index 39f89fb..d612bd9 100644
2667 --- a/arch/arm/kernel/entry-header.S
2668 +++ b/arch/arm/kernel/entry-header.S
2669 @@ -184,6 +184,60 @@
2670 msr cpsr_c, \rtemp @ switch back to the SVC mode
2671 .endm
2672
2673 + .macro pax_enter_kernel_user
2674 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2675 + @ save regs
2676 + stmdb sp!, {r0, r1}
2677 + @ read DACR from cpu_domain into r1
2678 + mov r0, sp
2679 + @ assume 8K pages, since we have to split the immediate in two
2680 + bic r0, r0, #(0x1fc0)
2681 + bic r0, r0, #(0x3f)
2682 + ldr r1, [r0, #TI_CPU_DOMAIN]
2683 +#ifdef CONFIG_PAX_MEMORY_UDEREF
2684 + @ set current DOMAIN_USER to DOMAIN_NOACCESS
2685 + bic r1, r1, #(domain_val(DOMAIN_USER, 3))
2686 +#endif
2687 +#ifdef CONFIG_PAX_KERNEXEC
2688 + @ set current DOMAIN_KERNEL to DOMAIN_KERNELCLIENT
2689 + bic r1, r1, #(domain_val(DOMAIN_KERNEL, 3))
2690 + orr r1, r1, #(domain_val(DOMAIN_KERNEL, DOMAIN_KERNELCLIENT))
2691 +#endif
2692 + @ write r1 to current_thread_info()->cpu_domain
2693 + str r1, [r0, #TI_CPU_DOMAIN]
2694 + @ write r1 to DACR
2695 + mcr p15, 0, r1, c3, c0, 0
2696 + @ instruction sync
2697 + instr_sync
2698 + @ restore regs
2699 + ldmia sp!, {r0, r1}
2700 +#endif
2701 + .endm
2702 +
2703 + .macro pax_exit_kernel
2704 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
2705 + @ save regs
2706 + stmdb sp!, {r0, r1}
2707 + @ read old DACR from stack into r1
2708 + ldr r1, [sp, #(8 + S_SP)]
2709 + sub r1, r1, #8
2710 + ldr r1, [r1]
2711 +
2712 + @ write r1 to current_thread_info()->cpu_domain
2713 + mov r0, sp
2714 + @ assume 8K pages, since we have to split the immediate in two
2715 + bic r0, r0, #(0x1fc0)
2716 + bic r0, r0, #(0x3f)
2717 + str r1, [r0, #TI_CPU_DOMAIN]
2718 + @ write r1 to DACR
2719 + mcr p15, 0, r1, c3, c0, 0
2720 + @ instruction sync
2721 + instr_sync
2722 + @ restore regs
2723 + ldmia sp!, {r0, r1}
2724 +#endif
2725 + .endm
2726 +
2727 #ifndef CONFIG_THUMB2_KERNEL
2728 .macro svc_exit, rpsr, irq = 0
2729 .if \irq != 0
2730 @@ -203,6 +257,9 @@
2731 blne trace_hardirqs_off
2732 #endif
2733 .endif
2734 +
2735 + pax_exit_kernel
2736 +
2737 msr spsr_cxsf, \rpsr
2738 #if defined(CONFIG_CPU_V6)
2739 ldr r0, [sp]
2740 @@ -266,6 +323,9 @@
2741 blne trace_hardirqs_off
2742 #endif
2743 .endif
2744 +
2745 + pax_exit_kernel
2746 +
2747 ldr lr, [sp, #S_SP] @ top of the stack
2748 ldrd r0, r1, [sp, #S_LR] @ calling lr and pc
2749 clrex @ clear the exclusive monitor
2750 diff --git a/arch/arm/kernel/fiq.c b/arch/arm/kernel/fiq.c
2751 index 918875d..cd5fa27 100644
2752 --- a/arch/arm/kernel/fiq.c
2753 +++ b/arch/arm/kernel/fiq.c
2754 @@ -87,7 +87,10 @@ void set_fiq_handler(void *start, unsigned int length)
2755 void *base = vectors_page;
2756 unsigned offset = FIQ_OFFSET;
2757
2758 + pax_open_kernel();
2759 memcpy(base + offset, start, length);
2760 + pax_close_kernel();
2761 +
2762 if (!cache_is_vipt_nonaliasing())
2763 flush_icache_range((unsigned long)base + offset, offset +
2764 length);
2765 diff --git a/arch/arm/kernel/head.S b/arch/arm/kernel/head.S
2766 index 32f317e..710ae07 100644
2767 --- a/arch/arm/kernel/head.S
2768 +++ b/arch/arm/kernel/head.S
2769 @@ -52,7 +52,9 @@
2770 .equ swapper_pg_dir, KERNEL_RAM_VADDR - PG_DIR_SIZE
2771
2772 .macro pgtbl, rd, phys
2773 - add \rd, \phys, #TEXT_OFFSET - PG_DIR_SIZE
2774 + mov \rd, #TEXT_OFFSET
2775 + sub \rd, #PG_DIR_SIZE
2776 + add \rd, \rd, \phys
2777 .endm
2778
2779 /*
2780 @@ -436,7 +438,7 @@ __enable_mmu:
2781 mov r5, #(domain_val(DOMAIN_USER, DOMAIN_MANAGER) | \
2782 domain_val(DOMAIN_KERNEL, DOMAIN_MANAGER) | \
2783 domain_val(DOMAIN_TABLE, DOMAIN_MANAGER) | \
2784 - domain_val(DOMAIN_IO, DOMAIN_CLIENT))
2785 + domain_val(DOMAIN_IO, DOMAIN_KERNELCLIENT))
2786 mcr p15, 0, r5, c3, c0, 0 @ load domain access register
2787 mcr p15, 0, r4, c2, c0, 0 @ load page table pointer
2788 #endif
2789 diff --git a/arch/arm/kernel/module.c b/arch/arm/kernel/module.c
2790 index 45e4781..8eac93d 100644
2791 --- a/arch/arm/kernel/module.c
2792 +++ b/arch/arm/kernel/module.c
2793 @@ -38,12 +38,39 @@
2794 #endif
2795
2796 #ifdef CONFIG_MMU
2797 -void *module_alloc(unsigned long size)
2798 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
2799 {
2800 + if (!size || PAGE_ALIGN(size) > MODULES_END - MODULES_VADDR)
2801 + return NULL;
2802 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
2803 - GFP_KERNEL, PAGE_KERNEL_EXEC, NUMA_NO_NODE,
2804 + GFP_KERNEL, prot, NUMA_NO_NODE,
2805 __builtin_return_address(0));
2806 }
2807 +
2808 +void *module_alloc(unsigned long size)
2809 +{
2810 +
2811 +#ifdef CONFIG_PAX_KERNEXEC
2812 + return __module_alloc(size, PAGE_KERNEL);
2813 +#else
2814 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2815 +#endif
2816 +
2817 +}
2818 +
2819 +#ifdef CONFIG_PAX_KERNEXEC
2820 +void module_free_exec(struct module *mod, void *module_region)
2821 +{
2822 + module_free(mod, module_region);
2823 +}
2824 +EXPORT_SYMBOL(module_free_exec);
2825 +
2826 +void *module_alloc_exec(unsigned long size)
2827 +{
2828 + return __module_alloc(size, PAGE_KERNEL_EXEC);
2829 +}
2830 +EXPORT_SYMBOL(module_alloc_exec);
2831 +#endif
2832 #endif
2833
2834 int
2835 diff --git a/arch/arm/kernel/patch.c b/arch/arm/kernel/patch.c
2836 index 07314af..c46655c 100644
2837 --- a/arch/arm/kernel/patch.c
2838 +++ b/arch/arm/kernel/patch.c
2839 @@ -18,6 +18,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2840 bool thumb2 = IS_ENABLED(CONFIG_THUMB2_KERNEL);
2841 int size;
2842
2843 + pax_open_kernel();
2844 if (thumb2 && __opcode_is_thumb16(insn)) {
2845 *(u16 *)addr = __opcode_to_mem_thumb16(insn);
2846 size = sizeof(u16);
2847 @@ -39,6 +40,7 @@ void __kprobes __patch_text(void *addr, unsigned int insn)
2848 *(u32 *)addr = insn;
2849 size = sizeof(u32);
2850 }
2851 + pax_close_kernel();
2852
2853 flush_icache_range((uintptr_t)(addr),
2854 (uintptr_t)(addr) + size);
2855 diff --git a/arch/arm/kernel/process.c b/arch/arm/kernel/process.c
2856 index 92f7b15..7048500 100644
2857 --- a/arch/arm/kernel/process.c
2858 +++ b/arch/arm/kernel/process.c
2859 @@ -217,6 +217,7 @@ void machine_power_off(void)
2860
2861 if (pm_power_off)
2862 pm_power_off();
2863 + BUG();
2864 }
2865
2866 /*
2867 @@ -230,7 +231,7 @@ void machine_power_off(void)
2868 * executing pre-reset code, and using RAM that the primary CPU's code wishes
2869 * to use. Implementing such co-ordination would be essentially impossible.
2870 */
2871 -void machine_restart(char *cmd)
2872 +__noreturn void machine_restart(char *cmd)
2873 {
2874 local_irq_disable();
2875 smp_send_stop();
2876 @@ -253,8 +254,8 @@ void __show_regs(struct pt_regs *regs)
2877
2878 show_regs_print_info(KERN_DEFAULT);
2879
2880 - print_symbol("PC is at %s\n", instruction_pointer(regs));
2881 - print_symbol("LR is at %s\n", regs->ARM_lr);
2882 + printk("PC is at %pA\n", (void *)instruction_pointer(regs));
2883 + printk("LR is at %pA\n", (void *)regs->ARM_lr);
2884 printk("pc : [<%08lx>] lr : [<%08lx>] psr: %08lx\n"
2885 "sp : %08lx ip : %08lx fp : %08lx\n",
2886 regs->ARM_pc, regs->ARM_lr, regs->ARM_cpsr,
2887 @@ -425,12 +426,6 @@ unsigned long get_wchan(struct task_struct *p)
2888 return 0;
2889 }
2890
2891 -unsigned long arch_randomize_brk(struct mm_struct *mm)
2892 -{
2893 - unsigned long range_end = mm->brk + 0x02000000;
2894 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
2895 -}
2896 -
2897 #ifdef CONFIG_MMU
2898 #ifdef CONFIG_KUSER_HELPERS
2899 /*
2900 @@ -446,7 +441,7 @@ static struct vm_area_struct gate_vma = {
2901
2902 static int __init gate_vma_init(void)
2903 {
2904 - gate_vma.vm_page_prot = PAGE_READONLY_EXEC;
2905 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
2906 return 0;
2907 }
2908 arch_initcall(gate_vma_init);
2909 @@ -472,41 +467,16 @@ int in_gate_area_no_mm(unsigned long addr)
2910
2911 const char *arch_vma_name(struct vm_area_struct *vma)
2912 {
2913 - return is_gate_vma(vma) ? "[vectors]" :
2914 - (vma->vm_mm && vma->vm_start == vma->vm_mm->context.sigpage) ?
2915 - "[sigpage]" : NULL;
2916 + return is_gate_vma(vma) ? "[vectors]" : NULL;
2917 }
2918
2919 -static struct page *signal_page;
2920 -extern struct page *get_signal_page(void);
2921 -
2922 int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
2923 {
2924 struct mm_struct *mm = current->mm;
2925 - unsigned long addr;
2926 - int ret;
2927 -
2928 - if (!signal_page)
2929 - signal_page = get_signal_page();
2930 - if (!signal_page)
2931 - return -ENOMEM;
2932
2933 down_write(&mm->mmap_sem);
2934 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
2935 - if (IS_ERR_VALUE(addr)) {
2936 - ret = addr;
2937 - goto up_fail;
2938 - }
2939 -
2940 - ret = install_special_mapping(mm, addr, PAGE_SIZE,
2941 - VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC,
2942 - &signal_page);
2943 -
2944 - if (ret == 0)
2945 - mm->context.sigpage = addr;
2946 -
2947 - up_fail:
2948 + mm->context.sigpage = (PAGE_OFFSET + (get_random_int() % 0x3FFEFFE0)) & 0xFFFFFFFC;
2949 up_write(&mm->mmap_sem);
2950 - return ret;
2951 + return 0;
2952 }
2953 #endif
2954 diff --git a/arch/arm/kernel/psci.c b/arch/arm/kernel/psci.c
2955 index 4693188..4596c5e 100644
2956 --- a/arch/arm/kernel/psci.c
2957 +++ b/arch/arm/kernel/psci.c
2958 @@ -24,7 +24,7 @@
2959 #include <asm/opcodes-virt.h>
2960 #include <asm/psci.h>
2961
2962 -struct psci_operations psci_ops;
2963 +struct psci_operations psci_ops __read_only;
2964
2965 static int (*invoke_psci_fn)(u32, u32, u32, u32);
2966
2967 diff --git a/arch/arm/kernel/ptrace.c b/arch/arm/kernel/ptrace.c
2968 index 0dd3b79..e018f64 100644
2969 --- a/arch/arm/kernel/ptrace.c
2970 +++ b/arch/arm/kernel/ptrace.c
2971 @@ -929,10 +929,19 @@ static int tracehook_report_syscall(struct pt_regs *regs,
2972 return current_thread_info()->syscall;
2973 }
2974
2975 +#ifdef CONFIG_GRKERNSEC_SETXID
2976 +extern void gr_delayed_cred_worker(void);
2977 +#endif
2978 +
2979 asmlinkage int syscall_trace_enter(struct pt_regs *regs, int scno)
2980 {
2981 current_thread_info()->syscall = scno;
2982
2983 +#ifdef CONFIG_GRKERNSEC_SETXID
2984 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
2985 + gr_delayed_cred_worker();
2986 +#endif
2987 +
2988 /* Do the secure computing check first; failures should be fast. */
2989 if (secure_computing(scno) == -1)
2990 return -1;
2991 diff --git a/arch/arm/kernel/setup.c b/arch/arm/kernel/setup.c
2992 index 987a7f5..d9d6071 100644
2993 --- a/arch/arm/kernel/setup.c
2994 +++ b/arch/arm/kernel/setup.c
2995 @@ -100,21 +100,23 @@ EXPORT_SYMBOL(system_serial_high);
2996 unsigned int elf_hwcap __read_mostly;
2997 EXPORT_SYMBOL(elf_hwcap);
2998
2999 +pteval_t __supported_pte_mask __read_only;
3000 +pmdval_t __supported_pmd_mask __read_only;
3001
3002 #ifdef MULTI_CPU
3003 -struct processor processor __read_mostly;
3004 +struct processor processor;
3005 #endif
3006 #ifdef MULTI_TLB
3007 -struct cpu_tlb_fns cpu_tlb __read_mostly;
3008 +struct cpu_tlb_fns cpu_tlb __read_only;
3009 #endif
3010 #ifdef MULTI_USER
3011 -struct cpu_user_fns cpu_user __read_mostly;
3012 +struct cpu_user_fns cpu_user __read_only;
3013 #endif
3014 #ifdef MULTI_CACHE
3015 -struct cpu_cache_fns cpu_cache __read_mostly;
3016 +struct cpu_cache_fns cpu_cache __read_only;
3017 #endif
3018 #ifdef CONFIG_OUTER_CACHE
3019 -struct outer_cache_fns outer_cache __read_mostly;
3020 +struct outer_cache_fns outer_cache __read_only;
3021 EXPORT_SYMBOL(outer_cache);
3022 #endif
3023
3024 @@ -247,9 +249,13 @@ static int __get_cpu_architecture(void)
3025 asm("mrc p15, 0, %0, c0, c1, 4"
3026 : "=r" (mmfr0));
3027 if ((mmfr0 & 0x0000000f) >= 0x00000003 ||
3028 - (mmfr0 & 0x000000f0) >= 0x00000030)
3029 + (mmfr0 & 0x000000f0) >= 0x00000030) {
3030 cpu_arch = CPU_ARCH_ARMv7;
3031 - else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3032 + if ((mmfr0 & 0x0000000f) == 0x00000005 || (mmfr0 & 0x0000000f) == 0x00000004) {
3033 + __supported_pte_mask |= L_PTE_PXN;
3034 + __supported_pmd_mask |= PMD_PXNTABLE;
3035 + }
3036 + } else if ((mmfr0 & 0x0000000f) == 0x00000002 ||
3037 (mmfr0 & 0x000000f0) == 0x00000020)
3038 cpu_arch = CPU_ARCH_ARMv6;
3039 else
3040 @@ -573,7 +579,7 @@ static void __init setup_processor(void)
3041 __cpu_architecture = __get_cpu_architecture();
3042
3043 #ifdef MULTI_CPU
3044 - processor = *list->proc;
3045 + memcpy((void *)&processor, list->proc, sizeof processor);
3046 #endif
3047 #ifdef MULTI_TLB
3048 cpu_tlb = *list->tlb;
3049 diff --git a/arch/arm/kernel/signal.c b/arch/arm/kernel/signal.c
3050 index 04d6388..5115238 100644
3051 --- a/arch/arm/kernel/signal.c
3052 +++ b/arch/arm/kernel/signal.c
3053 @@ -23,8 +23,6 @@
3054
3055 extern const unsigned long sigreturn_codes[7];
3056
3057 -static unsigned long signal_return_offset;
3058 -
3059 #ifdef CONFIG_CRUNCH
3060 static int preserve_crunch_context(struct crunch_sigframe __user *frame)
3061 {
3062 @@ -395,8 +393,7 @@ setup_return(struct pt_regs *regs, struct ksignal *ksig,
3063 * except when the MPU has protected the vectors
3064 * page from PL0
3065 */
3066 - retcode = mm->context.sigpage + signal_return_offset +
3067 - (idx << 2) + thumb;
3068 + retcode = mm->context.sigpage + (idx << 2) + thumb;
3069 } else
3070 #endif
3071 {
3072 @@ -600,33 +597,3 @@ do_work_pending(struct pt_regs *regs, unsigned int thread_flags, int syscall)
3073 } while (thread_flags & _TIF_WORK_MASK);
3074 return 0;
3075 }
3076 -
3077 -struct page *get_signal_page(void)
3078 -{
3079 - unsigned long ptr;
3080 - unsigned offset;
3081 - struct page *page;
3082 - void *addr;
3083 -
3084 - page = alloc_pages(GFP_KERNEL, 0);
3085 -
3086 - if (!page)
3087 - return NULL;
3088 -
3089 - addr = page_address(page);
3090 -
3091 - /* Give the signal return code some randomness */
3092 - offset = 0x200 + (get_random_int() & 0x7fc);
3093 - signal_return_offset = offset;
3094 -
3095 - /*
3096 - * Copy signal return handlers into the vector page, and
3097 - * set sigreturn to be a pointer to these.
3098 - */
3099 - memcpy(addr + offset, sigreturn_codes, sizeof(sigreturn_codes));
3100 -
3101 - ptr = (unsigned long)addr + offset;
3102 - flush_icache_range(ptr, ptr + sizeof(sigreturn_codes));
3103 -
3104 - return page;
3105 -}
3106 diff --git a/arch/arm/kernel/smp.c b/arch/arm/kernel/smp.c
3107 index dc894ab..f929a0d 100644
3108 --- a/arch/arm/kernel/smp.c
3109 +++ b/arch/arm/kernel/smp.c
3110 @@ -73,7 +73,7 @@ enum ipi_msg_type {
3111
3112 static DECLARE_COMPLETION(cpu_running);
3113
3114 -static struct smp_operations smp_ops;
3115 +static struct smp_operations smp_ops __read_only;
3116
3117 void __init smp_set_ops(struct smp_operations *ops)
3118 {
3119 diff --git a/arch/arm/kernel/traps.c b/arch/arm/kernel/traps.c
3120 index 4636d56..ce4ec3d 100644
3121 --- a/arch/arm/kernel/traps.c
3122 +++ b/arch/arm/kernel/traps.c
3123 @@ -62,7 +62,7 @@ static void dump_mem(const char *, const char *, unsigned long, unsigned long);
3124 void dump_backtrace_entry(unsigned long where, unsigned long from, unsigned long frame)
3125 {
3126 #ifdef CONFIG_KALLSYMS
3127 - printk("[<%08lx>] (%pS) from [<%08lx>] (%pS)\n", where, (void *)where, from, (void *)from);
3128 + printk("[<%08lx>] (%pA) from [<%08lx>] (%pA)\n", where, (void *)where, from, (void *)from);
3129 #else
3130 printk("Function entered at [<%08lx>] from [<%08lx>]\n", where, from);
3131 #endif
3132 @@ -264,6 +264,8 @@ static arch_spinlock_t die_lock = __ARCH_SPIN_LOCK_UNLOCKED;
3133 static int die_owner = -1;
3134 static unsigned int die_nest_count;
3135
3136 +extern void gr_handle_kernel_exploit(void);
3137 +
3138 static unsigned long oops_begin(void)
3139 {
3140 int cpu;
3141 @@ -306,6 +308,9 @@ static void oops_end(unsigned long flags, struct pt_regs *regs, int signr)
3142 panic("Fatal exception in interrupt");
3143 if (panic_on_oops)
3144 panic("Fatal exception");
3145 +
3146 + gr_handle_kernel_exploit();
3147 +
3148 if (signr)
3149 do_exit(signr);
3150 }
3151 @@ -642,7 +647,9 @@ asmlinkage int arm_syscall(int no, struct pt_regs *regs)
3152 * The user helper at 0xffff0fe0 must be used instead.
3153 * (see entry-armv.S for details)
3154 */
3155 + pax_open_kernel();
3156 *((unsigned int *)0xffff0ff0) = regs->ARM_r0;
3157 + pax_close_kernel();
3158 }
3159 return 0;
3160
3161 @@ -899,7 +906,11 @@ void __init early_trap_init(void *vectors_base)
3162 kuser_init(vectors_base);
3163
3164 flush_icache_range(vectors, vectors + PAGE_SIZE * 2);
3165 - modify_domain(DOMAIN_USER, DOMAIN_CLIENT);
3166 +
3167 +#ifndef CONFIG_PAX_MEMORY_UDEREF
3168 + modify_domain(DOMAIN_USER, DOMAIN_USERCLIENT);
3169 +#endif
3170 +
3171 #else /* ifndef CONFIG_CPU_V7M */
3172 /*
3173 * on V7-M there is no need to copy the vector table to a dedicated
3174 diff --git a/arch/arm/kernel/vmlinux.lds.S b/arch/arm/kernel/vmlinux.lds.S
3175 index 7bcee5c..e2f3249 100644
3176 --- a/arch/arm/kernel/vmlinux.lds.S
3177 +++ b/arch/arm/kernel/vmlinux.lds.S
3178 @@ -8,7 +8,11 @@
3179 #include <asm/thread_info.h>
3180 #include <asm/memory.h>
3181 #include <asm/page.h>
3182 -
3183 +
3184 +#ifdef CONFIG_PAX_KERNEXEC
3185 +#include <asm/pgtable.h>
3186 +#endif
3187 +
3188 #define PROC_INFO \
3189 . = ALIGN(4); \
3190 VMLINUX_SYMBOL(__proc_info_begin) = .; \
3191 @@ -34,7 +38,7 @@
3192 #endif
3193
3194 #if (defined(CONFIG_SMP_ON_UP) && !defined(CONFIG_DEBUG_SPINLOCK)) || \
3195 - defined(CONFIG_GENERIC_BUG)
3196 + defined(CONFIG_GENERIC_BUG) || defined(CONFIG_PAX_REFCOUNT)
3197 #define ARM_EXIT_KEEP(x) x
3198 #define ARM_EXIT_DISCARD(x)
3199 #else
3200 @@ -90,6 +94,11 @@ SECTIONS
3201 _text = .;
3202 HEAD_TEXT
3203 }
3204 +
3205 +#ifdef CONFIG_PAX_KERNEXEC
3206 + . = ALIGN(1<<SECTION_SHIFT);
3207 +#endif
3208 +
3209 .text : { /* Real text segment */
3210 _stext = .; /* Text and read-only data */
3211 __exception_text_start = .;
3212 @@ -112,6 +121,8 @@ SECTIONS
3213 ARM_CPU_KEEP(PROC_INFO)
3214 }
3215
3216 + _etext = .; /* End of text section */
3217 +
3218 RO_DATA(PAGE_SIZE)
3219
3220 . = ALIGN(4);
3221 @@ -142,7 +153,9 @@ SECTIONS
3222
3223 NOTES
3224
3225 - _etext = .; /* End of text and rodata section */
3226 +#ifdef CONFIG_PAX_KERNEXEC
3227 + . = ALIGN(1<<SECTION_SHIFT);
3228 +#endif
3229
3230 #ifndef CONFIG_XIP_KERNEL
3231 . = ALIGN(PAGE_SIZE);
3232 @@ -220,6 +233,11 @@ SECTIONS
3233 . = PAGE_OFFSET + TEXT_OFFSET;
3234 #else
3235 __init_end = .;
3236 +
3237 +#ifdef CONFIG_PAX_KERNEXEC
3238 + . = ALIGN(1<<SECTION_SHIFT);
3239 +#endif
3240 +
3241 . = ALIGN(THREAD_SIZE);
3242 __data_loc = .;
3243 #endif
3244 diff --git a/arch/arm/kvm/arm.c b/arch/arm/kvm/arm.c
3245 index 2a700e0..745b980 100644
3246 --- a/arch/arm/kvm/arm.c
3247 +++ b/arch/arm/kvm/arm.c
3248 @@ -56,7 +56,7 @@ static unsigned long hyp_default_vectors;
3249 static DEFINE_PER_CPU(struct kvm_vcpu *, kvm_arm_running_vcpu);
3250
3251 /* The VMID used in the VTTBR */
3252 -static atomic64_t kvm_vmid_gen = ATOMIC64_INIT(1);
3253 +static atomic64_unchecked_t kvm_vmid_gen = ATOMIC64_INIT(1);
3254 static u8 kvm_next_vmid;
3255 static DEFINE_SPINLOCK(kvm_vmid_lock);
3256
3257 @@ -397,7 +397,7 @@ void force_vm_exit(const cpumask_t *mask)
3258 */
3259 static bool need_new_vmid_gen(struct kvm *kvm)
3260 {
3261 - return unlikely(kvm->arch.vmid_gen != atomic64_read(&kvm_vmid_gen));
3262 + return unlikely(kvm->arch.vmid_gen != atomic64_read_unchecked(&kvm_vmid_gen));
3263 }
3264
3265 /**
3266 @@ -430,7 +430,7 @@ static void update_vttbr(struct kvm *kvm)
3267
3268 /* First user of a new VMID generation? */
3269 if (unlikely(kvm_next_vmid == 0)) {
3270 - atomic64_inc(&kvm_vmid_gen);
3271 + atomic64_inc_unchecked(&kvm_vmid_gen);
3272 kvm_next_vmid = 1;
3273
3274 /*
3275 @@ -447,7 +447,7 @@ static void update_vttbr(struct kvm *kvm)
3276 kvm_call_hyp(__kvm_flush_vm_context);
3277 }
3278
3279 - kvm->arch.vmid_gen = atomic64_read(&kvm_vmid_gen);
3280 + kvm->arch.vmid_gen = atomic64_read_unchecked(&kvm_vmid_gen);
3281 kvm->arch.vmid = kvm_next_vmid;
3282 kvm_next_vmid++;
3283
3284 diff --git a/arch/arm/lib/clear_user.S b/arch/arm/lib/clear_user.S
3285 index 14a0d98..7771a7d 100644
3286 --- a/arch/arm/lib/clear_user.S
3287 +++ b/arch/arm/lib/clear_user.S
3288 @@ -12,14 +12,14 @@
3289
3290 .text
3291
3292 -/* Prototype: int __clear_user(void *addr, size_t sz)
3293 +/* Prototype: int ___clear_user(void *addr, size_t sz)
3294 * Purpose : clear some user memory
3295 * Params : addr - user memory address to clear
3296 * : sz - number of bytes to clear
3297 * Returns : number of bytes NOT cleared
3298 */
3299 ENTRY(__clear_user_std)
3300 -WEAK(__clear_user)
3301 +WEAK(___clear_user)
3302 stmfd sp!, {r1, lr}
3303 mov r2, #0
3304 cmp r1, #4
3305 @@ -44,7 +44,7 @@ WEAK(__clear_user)
3306 USER( strnebt r2, [r0])
3307 mov r0, #0
3308 ldmfd sp!, {r1, pc}
3309 -ENDPROC(__clear_user)
3310 +ENDPROC(___clear_user)
3311 ENDPROC(__clear_user_std)
3312
3313 .pushsection .fixup,"ax"
3314 diff --git a/arch/arm/lib/copy_from_user.S b/arch/arm/lib/copy_from_user.S
3315 index 66a477a..bee61d3 100644
3316 --- a/arch/arm/lib/copy_from_user.S
3317 +++ b/arch/arm/lib/copy_from_user.S
3318 @@ -16,7 +16,7 @@
3319 /*
3320 * Prototype:
3321 *
3322 - * size_t __copy_from_user(void *to, const void *from, size_t n)
3323 + * size_t ___copy_from_user(void *to, const void *from, size_t n)
3324 *
3325 * Purpose:
3326 *
3327 @@ -84,11 +84,11 @@
3328
3329 .text
3330
3331 -ENTRY(__copy_from_user)
3332 +ENTRY(___copy_from_user)
3333
3334 #include "copy_template.S"
3335
3336 -ENDPROC(__copy_from_user)
3337 +ENDPROC(___copy_from_user)
3338
3339 .pushsection .fixup,"ax"
3340 .align 0
3341 diff --git a/arch/arm/lib/copy_page.S b/arch/arm/lib/copy_page.S
3342 index 6ee2f67..d1cce76 100644
3343 --- a/arch/arm/lib/copy_page.S
3344 +++ b/arch/arm/lib/copy_page.S
3345 @@ -10,6 +10,7 @@
3346 * ASM optimised string functions
3347 */
3348 #include <linux/linkage.h>
3349 +#include <linux/const.h>
3350 #include <asm/assembler.h>
3351 #include <asm/asm-offsets.h>
3352 #include <asm/cache.h>
3353 diff --git a/arch/arm/lib/copy_to_user.S b/arch/arm/lib/copy_to_user.S
3354 index d066df6..df28194 100644
3355 --- a/arch/arm/lib/copy_to_user.S
3356 +++ b/arch/arm/lib/copy_to_user.S
3357 @@ -16,7 +16,7 @@
3358 /*
3359 * Prototype:
3360 *
3361 - * size_t __copy_to_user(void *to, const void *from, size_t n)
3362 + * size_t ___copy_to_user(void *to, const void *from, size_t n)
3363 *
3364 * Purpose:
3365 *
3366 @@ -88,11 +88,11 @@
3367 .text
3368
3369 ENTRY(__copy_to_user_std)
3370 -WEAK(__copy_to_user)
3371 +WEAK(___copy_to_user)
3372
3373 #include "copy_template.S"
3374
3375 -ENDPROC(__copy_to_user)
3376 +ENDPROC(___copy_to_user)
3377 ENDPROC(__copy_to_user_std)
3378
3379 .pushsection .fixup,"ax"
3380 diff --git a/arch/arm/lib/csumpartialcopyuser.S b/arch/arm/lib/csumpartialcopyuser.S
3381 index 7d08b43..f7ca7ea 100644
3382 --- a/arch/arm/lib/csumpartialcopyuser.S
3383 +++ b/arch/arm/lib/csumpartialcopyuser.S
3384 @@ -57,8 +57,8 @@
3385 * Returns : r0 = checksum, [[sp, #0], #0] = 0 or -EFAULT
3386 */
3387
3388 -#define FN_ENTRY ENTRY(csum_partial_copy_from_user)
3389 -#define FN_EXIT ENDPROC(csum_partial_copy_from_user)
3390 +#define FN_ENTRY ENTRY(__csum_partial_copy_from_user)
3391 +#define FN_EXIT ENDPROC(__csum_partial_copy_from_user)
3392
3393 #include "csumpartialcopygeneric.S"
3394
3395 diff --git a/arch/arm/lib/delay.c b/arch/arm/lib/delay.c
3396 index 5306de3..aed6d03 100644
3397 --- a/arch/arm/lib/delay.c
3398 +++ b/arch/arm/lib/delay.c
3399 @@ -28,7 +28,7 @@
3400 /*
3401 * Default to the loop-based delay implementation.
3402 */
3403 -struct arm_delay_ops arm_delay_ops = {
3404 +struct arm_delay_ops arm_delay_ops __read_only = {
3405 .delay = __loop_delay,
3406 .const_udelay = __loop_const_udelay,
3407 .udelay = __loop_udelay,
3408 diff --git a/arch/arm/lib/uaccess_with_memcpy.c b/arch/arm/lib/uaccess_with_memcpy.c
3409 index 3e58d71..029817c 100644
3410 --- a/arch/arm/lib/uaccess_with_memcpy.c
3411 +++ b/arch/arm/lib/uaccess_with_memcpy.c
3412 @@ -136,7 +136,7 @@ out:
3413 }
3414
3415 unsigned long
3416 -__copy_to_user(void __user *to, const void *from, unsigned long n)
3417 +___copy_to_user(void __user *to, const void *from, unsigned long n)
3418 {
3419 /*
3420 * This test is stubbed out of the main function above to keep
3421 @@ -190,7 +190,7 @@ out:
3422 return n;
3423 }
3424
3425 -unsigned long __clear_user(void __user *addr, unsigned long n)
3426 +unsigned long ___clear_user(void __user *addr, unsigned long n)
3427 {
3428 /* See rational for this in __copy_to_user() above. */
3429 if (n < 64)
3430 diff --git a/arch/arm/mach-kirkwood/common.c b/arch/arm/mach-kirkwood/common.c
3431 index f3407a5..bd4256f 100644
3432 --- a/arch/arm/mach-kirkwood/common.c
3433 +++ b/arch/arm/mach-kirkwood/common.c
3434 @@ -156,7 +156,16 @@ static void clk_gate_fn_disable(struct clk_hw *hw)
3435 clk_gate_ops.disable(hw);
3436 }
3437
3438 -static struct clk_ops clk_gate_fn_ops;
3439 +static int clk_gate_fn_is_enabled(struct clk_hw *hw)
3440 +{
3441 + return clk_gate_ops.is_enabled(hw);
3442 +}
3443 +
3444 +static struct clk_ops clk_gate_fn_ops = {
3445 + .enable = clk_gate_fn_enable,
3446 + .disable = clk_gate_fn_disable,
3447 + .is_enabled = clk_gate_fn_is_enabled,
3448 +};
3449
3450 static struct clk __init *clk_register_gate_fn(struct device *dev,
3451 const char *name,
3452 @@ -190,14 +199,6 @@ static struct clk __init *clk_register_gate_fn(struct device *dev,
3453 gate_fn->fn_en = fn_en;
3454 gate_fn->fn_dis = fn_dis;
3455
3456 - /* ops is the gate ops, but with our enable/disable functions */
3457 - if (clk_gate_fn_ops.enable != clk_gate_fn_enable ||
3458 - clk_gate_fn_ops.disable != clk_gate_fn_disable) {
3459 - clk_gate_fn_ops = clk_gate_ops;
3460 - clk_gate_fn_ops.enable = clk_gate_fn_enable;
3461 - clk_gate_fn_ops.disable = clk_gate_fn_disable;
3462 - }
3463 -
3464 clk = clk_register(dev, &gate_fn->gate.hw);
3465
3466 if (IS_ERR(clk))
3467 diff --git a/arch/arm/mach-omap2/board-n8x0.c b/arch/arm/mach-omap2/board-n8x0.c
3468 index 827d1500..2885dc6 100644
3469 --- a/arch/arm/mach-omap2/board-n8x0.c
3470 +++ b/arch/arm/mach-omap2/board-n8x0.c
3471 @@ -627,7 +627,7 @@ static int n8x0_menelaus_late_init(struct device *dev)
3472 }
3473 #endif
3474
3475 -static struct menelaus_platform_data n8x0_menelaus_platform_data __initdata = {
3476 +static struct menelaus_platform_data n8x0_menelaus_platform_data __initconst = {
3477 .late_init = n8x0_menelaus_late_init,
3478 };
3479
3480 diff --git a/arch/arm/mach-omap2/gpmc.c b/arch/arm/mach-omap2/gpmc.c
3481 index d24926e..a7645a6 100644
3482 --- a/arch/arm/mach-omap2/gpmc.c
3483 +++ b/arch/arm/mach-omap2/gpmc.c
3484 @@ -148,7 +148,6 @@ struct omap3_gpmc_regs {
3485 };
3486
3487 static struct gpmc_client_irq gpmc_client_irq[GPMC_NR_IRQ];
3488 -static struct irq_chip gpmc_irq_chip;
3489 static int gpmc_irq_start;
3490
3491 static struct resource gpmc_mem_root;
3492 @@ -716,6 +715,18 @@ static void gpmc_irq_noop(struct irq_data *data) { }
3493
3494 static unsigned int gpmc_irq_noop_ret(struct irq_data *data) { return 0; }
3495
3496 +static struct irq_chip gpmc_irq_chip = {
3497 + .name = "gpmc",
3498 + .irq_startup = gpmc_irq_noop_ret,
3499 + .irq_enable = gpmc_irq_enable,
3500 + .irq_disable = gpmc_irq_disable,
3501 + .irq_shutdown = gpmc_irq_noop,
3502 + .irq_ack = gpmc_irq_noop,
3503 + .irq_mask = gpmc_irq_noop,
3504 + .irq_unmask = gpmc_irq_noop,
3505 +
3506 +};
3507 +
3508 static int gpmc_setup_irq(void)
3509 {
3510 int i;
3511 @@ -730,15 +741,6 @@ static int gpmc_setup_irq(void)
3512 return gpmc_irq_start;
3513 }
3514
3515 - gpmc_irq_chip.name = "gpmc";
3516 - gpmc_irq_chip.irq_startup = gpmc_irq_noop_ret;
3517 - gpmc_irq_chip.irq_enable = gpmc_irq_enable;
3518 - gpmc_irq_chip.irq_disable = gpmc_irq_disable;
3519 - gpmc_irq_chip.irq_shutdown = gpmc_irq_noop;
3520 - gpmc_irq_chip.irq_ack = gpmc_irq_noop;
3521 - gpmc_irq_chip.irq_mask = gpmc_irq_noop;
3522 - gpmc_irq_chip.irq_unmask = gpmc_irq_noop;
3523 -
3524 gpmc_client_irq[0].bitmask = GPMC_IRQ_FIFOEVENTENABLE;
3525 gpmc_client_irq[1].bitmask = GPMC_IRQ_COUNT_EVENT;
3526
3527 diff --git a/arch/arm/mach-omap2/omap-mpuss-lowpower.c b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3528 index f991016..145ebeb 100644
3529 --- a/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3530 +++ b/arch/arm/mach-omap2/omap-mpuss-lowpower.c
3531 @@ -84,7 +84,7 @@ struct cpu_pm_ops {
3532 int (*finish_suspend)(unsigned long cpu_state);
3533 void (*resume)(void);
3534 void (*scu_prepare)(unsigned int cpu_id, unsigned int cpu_state);
3535 -};
3536 +} __no_const;
3537
3538 static DEFINE_PER_CPU(struct omap4_cpu_pm_info, omap4_pm_info);
3539 static struct powerdomain *mpuss_pd;
3540 @@ -102,7 +102,7 @@ static void dummy_cpu_resume(void)
3541 static void dummy_scu_prepare(unsigned int cpu_id, unsigned int cpu_state)
3542 {}
3543
3544 -struct cpu_pm_ops omap_pm_ops = {
3545 +static struct cpu_pm_ops omap_pm_ops __read_only = {
3546 .finish_suspend = default_finish_suspend,
3547 .resume = dummy_cpu_resume,
3548 .scu_prepare = dummy_scu_prepare,
3549 diff --git a/arch/arm/mach-omap2/omap-wakeupgen.c b/arch/arm/mach-omap2/omap-wakeupgen.c
3550 index 3664562..72f85c6 100644
3551 --- a/arch/arm/mach-omap2/omap-wakeupgen.c
3552 +++ b/arch/arm/mach-omap2/omap-wakeupgen.c
3553 @@ -343,7 +343,7 @@ static int irq_cpu_hotplug_notify(struct notifier_block *self,
3554 return NOTIFY_OK;
3555 }
3556
3557 -static struct notifier_block __refdata irq_hotplug_notifier = {
3558 +static struct notifier_block irq_hotplug_notifier = {
3559 .notifier_call = irq_cpu_hotplug_notify,
3560 };
3561
3562 diff --git a/arch/arm/mach-omap2/omap_device.c b/arch/arm/mach-omap2/omap_device.c
3563 index e0a398c..a470fa5 100644
3564 --- a/arch/arm/mach-omap2/omap_device.c
3565 +++ b/arch/arm/mach-omap2/omap_device.c
3566 @@ -508,7 +508,7 @@ void omap_device_delete(struct omap_device *od)
3567 struct platform_device __init *omap_device_build(const char *pdev_name,
3568 int pdev_id,
3569 struct omap_hwmod *oh,
3570 - void *pdata, int pdata_len)
3571 + const void *pdata, int pdata_len)
3572 {
3573 struct omap_hwmod *ohs[] = { oh };
3574
3575 @@ -536,7 +536,7 @@ struct platform_device __init *omap_device_build(const char *pdev_name,
3576 struct platform_device __init *omap_device_build_ss(const char *pdev_name,
3577 int pdev_id,
3578 struct omap_hwmod **ohs,
3579 - int oh_cnt, void *pdata,
3580 + int oh_cnt, const void *pdata,
3581 int pdata_len)
3582 {
3583 int ret = -ENOMEM;
3584 diff --git a/arch/arm/mach-omap2/omap_device.h b/arch/arm/mach-omap2/omap_device.h
3585 index 78c02b3..c94109a 100644
3586 --- a/arch/arm/mach-omap2/omap_device.h
3587 +++ b/arch/arm/mach-omap2/omap_device.h
3588 @@ -72,12 +72,12 @@ int omap_device_idle(struct platform_device *pdev);
3589 /* Core code interface */
3590
3591 struct platform_device *omap_device_build(const char *pdev_name, int pdev_id,
3592 - struct omap_hwmod *oh, void *pdata,
3593 + struct omap_hwmod *oh, const void *pdata,
3594 int pdata_len);
3595
3596 struct platform_device *omap_device_build_ss(const char *pdev_name, int pdev_id,
3597 struct omap_hwmod **oh, int oh_cnt,
3598 - void *pdata, int pdata_len);
3599 + const void *pdata, int pdata_len);
3600
3601 struct omap_device *omap_device_alloc(struct platform_device *pdev,
3602 struct omap_hwmod **ohs, int oh_cnt);
3603 diff --git a/arch/arm/mach-omap2/omap_hwmod.c b/arch/arm/mach-omap2/omap_hwmod.c
3604 index 8a1b5e0..5f30074 100644
3605 --- a/arch/arm/mach-omap2/omap_hwmod.c
3606 +++ b/arch/arm/mach-omap2/omap_hwmod.c
3607 @@ -194,10 +194,10 @@ struct omap_hwmod_soc_ops {
3608 int (*init_clkdm)(struct omap_hwmod *oh);
3609 void (*update_context_lost)(struct omap_hwmod *oh);
3610 int (*get_context_lost)(struct omap_hwmod *oh);
3611 -};
3612 +} __no_const;
3613
3614 /* soc_ops: adapts the omap_hwmod code to the currently-booted SoC */
3615 -static struct omap_hwmod_soc_ops soc_ops;
3616 +static struct omap_hwmod_soc_ops soc_ops __read_only;
3617
3618 /* omap_hwmod_list contains all registered struct omap_hwmods */
3619 static LIST_HEAD(omap_hwmod_list);
3620 diff --git a/arch/arm/mach-omap2/powerdomains43xx_data.c b/arch/arm/mach-omap2/powerdomains43xx_data.c
3621 index 95fee54..cfa9cf1 100644
3622 --- a/arch/arm/mach-omap2/powerdomains43xx_data.c
3623 +++ b/arch/arm/mach-omap2/powerdomains43xx_data.c
3624 @@ -10,6 +10,7 @@
3625
3626 #include <linux/kernel.h>
3627 #include <linux/init.h>
3628 +#include <asm/pgtable.h>
3629
3630 #include "powerdomain.h"
3631
3632 @@ -129,7 +130,9 @@ static int am43xx_check_vcvp(void)
3633
3634 void __init am43xx_powerdomains_init(void)
3635 {
3636 - omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3637 + pax_open_kernel();
3638 + *(void **)&omap4_pwrdm_operations.pwrdm_has_voltdm = am43xx_check_vcvp;
3639 + pax_close_kernel();
3640 pwrdm_register_platform_funcs(&omap4_pwrdm_operations);
3641 pwrdm_register_pwrdms(powerdomains_am43xx);
3642 pwrdm_complete_init();
3643 diff --git a/arch/arm/mach-omap2/wd_timer.c b/arch/arm/mach-omap2/wd_timer.c
3644 index d15c7bb..b2d1f0c 100644
3645 --- a/arch/arm/mach-omap2/wd_timer.c
3646 +++ b/arch/arm/mach-omap2/wd_timer.c
3647 @@ -110,7 +110,9 @@ static int __init omap_init_wdt(void)
3648 struct omap_hwmod *oh;
3649 char *oh_name = "wd_timer2";
3650 char *dev_name = "omap_wdt";
3651 - struct omap_wd_timer_platform_data pdata;
3652 + static struct omap_wd_timer_platform_data pdata = {
3653 + .read_reset_sources = prm_read_reset_sources
3654 + };
3655
3656 if (!cpu_class_is_omap2() || of_have_populated_dt())
3657 return 0;
3658 @@ -121,8 +123,6 @@ static int __init omap_init_wdt(void)
3659 return -EINVAL;
3660 }
3661
3662 - pdata.read_reset_sources = prm_read_reset_sources;
3663 -
3664 pdev = omap_device_build(dev_name, id, oh, &pdata,
3665 sizeof(struct omap_wd_timer_platform_data));
3666 WARN(IS_ERR(pdev), "Can't build omap_device for %s:%s.\n",
3667 diff --git a/arch/arm/mach-tegra/cpuidle-tegra20.c b/arch/arm/mach-tegra/cpuidle-tegra20.c
3668 index b82dcae..44ee5b6 100644
3669 --- a/arch/arm/mach-tegra/cpuidle-tegra20.c
3670 +++ b/arch/arm/mach-tegra/cpuidle-tegra20.c
3671 @@ -180,7 +180,7 @@ static int tegra20_idle_lp2_coupled(struct cpuidle_device *dev,
3672 bool entered_lp2 = false;
3673
3674 if (tegra_pending_sgi())
3675 - ACCESS_ONCE(abort_flag) = true;
3676 + ACCESS_ONCE_RW(abort_flag) = true;
3677
3678 cpuidle_coupled_parallel_barrier(dev, &abort_barrier);
3679
3680 diff --git a/arch/arm/mach-ux500/setup.h b/arch/arm/mach-ux500/setup.h
3681 index bdb3564..cebb96f 100644
3682 --- a/arch/arm/mach-ux500/setup.h
3683 +++ b/arch/arm/mach-ux500/setup.h
3684 @@ -39,13 +39,6 @@ extern void ux500_timer_init(void);
3685 .type = MT_DEVICE, \
3686 }
3687
3688 -#define __MEM_DEV_DESC(x, sz) { \
3689 - .virtual = IO_ADDRESS(x), \
3690 - .pfn = __phys_to_pfn(x), \
3691 - .length = sz, \
3692 - .type = MT_MEMORY, \
3693 -}
3694 -
3695 extern struct smp_operations ux500_smp_ops;
3696 extern void ux500_cpu_die(unsigned int cpu);
3697
3698 diff --git a/arch/arm/mm/Kconfig b/arch/arm/mm/Kconfig
3699 index 1f8fed9..14d7823 100644
3700 --- a/arch/arm/mm/Kconfig
3701 +++ b/arch/arm/mm/Kconfig
3702 @@ -446,7 +446,7 @@ config CPU_32v5
3703
3704 config CPU_32v6
3705 bool
3706 - select CPU_USE_DOMAINS if CPU_V6 && MMU
3707 + select CPU_USE_DOMAINS if CPU_V6 && MMU && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3708 select TLS_REG_EMUL if !CPU_32v6K && !MMU
3709
3710 config CPU_32v6K
3711 @@ -601,6 +601,7 @@ config CPU_CP15_MPU
3712
3713 config CPU_USE_DOMAINS
3714 bool
3715 + depends on !ARM_LPAE && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
3716 help
3717 This option enables or disables the use of domain switching
3718 via the set_fs() function.
3719 @@ -800,6 +801,7 @@ config NEED_KUSER_HELPERS
3720 config KUSER_HELPERS
3721 bool "Enable kuser helpers in vector page" if !NEED_KUSER_HELPERS
3722 default y
3723 + depends on !(CPU_V6 || CPU_V6K || CPU_V7) || GRKERNSEC_OLD_ARM_USERLAND
3724 help
3725 Warning: disabling this option may break user programs.
3726
3727 @@ -812,7 +814,7 @@ config KUSER_HELPERS
3728 See Documentation/arm/kernel_user_helpers.txt for details.
3729
3730 However, the fixed address nature of these helpers can be used
3731 - by ROP (return orientated programming) authors when creating
3732 + by ROP (Return Oriented Programming) authors when creating
3733 exploits.
3734
3735 If all of the binaries and libraries which run on your platform
3736 diff --git a/arch/arm/mm/alignment.c b/arch/arm/mm/alignment.c
3737 index 9240364..a2b8cf3 100644
3738 --- a/arch/arm/mm/alignment.c
3739 +++ b/arch/arm/mm/alignment.c
3740 @@ -212,10 +212,12 @@ union offset_union {
3741 #define __get16_unaligned_check(ins,val,addr) \
3742 do { \
3743 unsigned int err = 0, v, a = addr; \
3744 + pax_open_userland(); \
3745 __get8_unaligned_check(ins,v,a,err); \
3746 val = v << ((BE) ? 8 : 0); \
3747 __get8_unaligned_check(ins,v,a,err); \
3748 val |= v << ((BE) ? 0 : 8); \
3749 + pax_close_userland(); \
3750 if (err) \
3751 goto fault; \
3752 } while (0)
3753 @@ -229,6 +231,7 @@ union offset_union {
3754 #define __get32_unaligned_check(ins,val,addr) \
3755 do { \
3756 unsigned int err = 0, v, a = addr; \
3757 + pax_open_userland(); \
3758 __get8_unaligned_check(ins,v,a,err); \
3759 val = v << ((BE) ? 24 : 0); \
3760 __get8_unaligned_check(ins,v,a,err); \
3761 @@ -237,6 +240,7 @@ union offset_union {
3762 val |= v << ((BE) ? 8 : 16); \
3763 __get8_unaligned_check(ins,v,a,err); \
3764 val |= v << ((BE) ? 0 : 24); \
3765 + pax_close_userland(); \
3766 if (err) \
3767 goto fault; \
3768 } while (0)
3769 @@ -250,6 +254,7 @@ union offset_union {
3770 #define __put16_unaligned_check(ins,val,addr) \
3771 do { \
3772 unsigned int err = 0, v = val, a = addr; \
3773 + pax_open_userland(); \
3774 __asm__( FIRST_BYTE_16 \
3775 ARM( "1: "ins" %1, [%2], #1\n" ) \
3776 THUMB( "1: "ins" %1, [%2]\n" ) \
3777 @@ -269,6 +274,7 @@ union offset_union {
3778 " .popsection\n" \
3779 : "=r" (err), "=&r" (v), "=&r" (a) \
3780 : "0" (err), "1" (v), "2" (a)); \
3781 + pax_close_userland(); \
3782 if (err) \
3783 goto fault; \
3784 } while (0)
3785 @@ -282,6 +288,7 @@ union offset_union {
3786 #define __put32_unaligned_check(ins,val,addr) \
3787 do { \
3788 unsigned int err = 0, v = val, a = addr; \
3789 + pax_open_userland(); \
3790 __asm__( FIRST_BYTE_32 \
3791 ARM( "1: "ins" %1, [%2], #1\n" ) \
3792 THUMB( "1: "ins" %1, [%2]\n" ) \
3793 @@ -311,6 +318,7 @@ union offset_union {
3794 " .popsection\n" \
3795 : "=r" (err), "=&r" (v), "=&r" (a) \
3796 : "0" (err), "1" (v), "2" (a)); \
3797 + pax_close_userland(); \
3798 if (err) \
3799 goto fault; \
3800 } while (0)
3801 diff --git a/arch/arm/mm/cache-l2x0.c b/arch/arm/mm/cache-l2x0.c
3802 index 447da6f..77a5057 100644
3803 --- a/arch/arm/mm/cache-l2x0.c
3804 +++ b/arch/arm/mm/cache-l2x0.c
3805 @@ -45,7 +45,7 @@ struct l2x0_of_data {
3806 void (*setup)(const struct device_node *, u32 *, u32 *);
3807 void (*save)(void);
3808 struct outer_cache_fns outer_cache;
3809 -};
3810 +} __do_const;
3811
3812 static bool of_init = false;
3813
3814 diff --git a/arch/arm/mm/context.c b/arch/arm/mm/context.c
3815 index 84e6f77..0b52f31 100644
3816 --- a/arch/arm/mm/context.c
3817 +++ b/arch/arm/mm/context.c
3818 @@ -43,7 +43,7 @@
3819 #define NUM_USER_ASIDS ASID_FIRST_VERSION
3820
3821 static DEFINE_RAW_SPINLOCK(cpu_asid_lock);
3822 -static atomic64_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3823 +static atomic64_unchecked_t asid_generation = ATOMIC64_INIT(ASID_FIRST_VERSION);
3824 static DECLARE_BITMAP(asid_map, NUM_USER_ASIDS);
3825
3826 static DEFINE_PER_CPU(atomic64_t, active_asids);
3827 @@ -180,7 +180,7 @@ static int is_reserved_asid(u64 asid)
3828 static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3829 {
3830 u64 asid = atomic64_read(&mm->context.id);
3831 - u64 generation = atomic64_read(&asid_generation);
3832 + u64 generation = atomic64_read_unchecked(&asid_generation);
3833
3834 if (asid != 0 && is_reserved_asid(asid)) {
3835 /*
3836 @@ -198,7 +198,7 @@ static u64 new_context(struct mm_struct *mm, unsigned int cpu)
3837 */
3838 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3839 if (asid == NUM_USER_ASIDS) {
3840 - generation = atomic64_add_return(ASID_FIRST_VERSION,
3841 + generation = atomic64_add_return_unchecked(ASID_FIRST_VERSION,
3842 &asid_generation);
3843 flush_context(cpu);
3844 asid = find_next_zero_bit(asid_map, NUM_USER_ASIDS, 1);
3845 @@ -227,14 +227,14 @@ void check_and_switch_context(struct mm_struct *mm, struct task_struct *tsk)
3846 cpu_set_reserved_ttbr0();
3847
3848 asid = atomic64_read(&mm->context.id);
3849 - if (!((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS)
3850 + if (!((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS)
3851 && atomic64_xchg(&per_cpu(active_asids, cpu), asid))
3852 goto switch_mm_fastpath;
3853
3854 raw_spin_lock_irqsave(&cpu_asid_lock, flags);
3855 /* Check that our ASID belongs to the current generation. */
3856 asid = atomic64_read(&mm->context.id);
3857 - if ((asid ^ atomic64_read(&asid_generation)) >> ASID_BITS) {
3858 + if ((asid ^ atomic64_read_unchecked(&asid_generation)) >> ASID_BITS) {
3859 asid = new_context(mm, cpu);
3860 atomic64_set(&mm->context.id, asid);
3861 }
3862 diff --git a/arch/arm/mm/fault.c b/arch/arm/mm/fault.c
3863 index eb8830a..5360ce7 100644
3864 --- a/arch/arm/mm/fault.c
3865 +++ b/arch/arm/mm/fault.c
3866 @@ -25,6 +25,7 @@
3867 #include <asm/system_misc.h>
3868 #include <asm/system_info.h>
3869 #include <asm/tlbflush.h>
3870 +#include <asm/sections.h>
3871
3872 #include "fault.h"
3873
3874 @@ -138,6 +139,31 @@ __do_kernel_fault(struct mm_struct *mm, unsigned long addr, unsigned int fsr,
3875 if (fixup_exception(regs))
3876 return;
3877
3878 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3879 + if (addr < TASK_SIZE) {
3880 + if (current->signal->curr_ip)
3881 + 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),
3882 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3883 + else
3884 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3885 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3886 + }
3887 +#endif
3888 +
3889 +#ifdef CONFIG_PAX_KERNEXEC
3890 + if ((fsr & FSR_WRITE) &&
3891 + (((unsigned long)_stext <= addr && addr < init_mm.end_code) ||
3892 + (MODULES_VADDR <= addr && addr < MODULES_END)))
3893 + {
3894 + if (current->signal->curr_ip)
3895 + 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),
3896 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3897 + else
3898 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
3899 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
3900 + }
3901 +#endif
3902 +
3903 /*
3904 * No handler, we'll have to terminate things with extreme prejudice.
3905 */
3906 @@ -174,6 +200,13 @@ __do_user_fault(struct task_struct *tsk, unsigned long addr,
3907 }
3908 #endif
3909
3910 +#ifdef CONFIG_PAX_PAGEEXEC
3911 + if (fsr & FSR_LNX_PF) {
3912 + pax_report_fault(regs, (void *)regs->ARM_pc, (void *)regs->ARM_sp);
3913 + do_group_exit(SIGKILL);
3914 + }
3915 +#endif
3916 +
3917 tsk->thread.address = addr;
3918 tsk->thread.error_code = fsr;
3919 tsk->thread.trap_no = 14;
3920 @@ -401,6 +434,33 @@ do_page_fault(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3921 }
3922 #endif /* CONFIG_MMU */
3923
3924 +#ifdef CONFIG_PAX_PAGEEXEC
3925 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
3926 +{
3927 + long i;
3928 +
3929 + printk(KERN_ERR "PAX: bytes at PC: ");
3930 + for (i = 0; i < 20; i++) {
3931 + unsigned char c;
3932 + if (get_user(c, (__force unsigned char __user *)pc+i))
3933 + printk(KERN_CONT "?? ");
3934 + else
3935 + printk(KERN_CONT "%02x ", c);
3936 + }
3937 + printk("\n");
3938 +
3939 + printk(KERN_ERR "PAX: bytes at SP-4: ");
3940 + for (i = -1; i < 20; i++) {
3941 + unsigned long c;
3942 + if (get_user(c, (__force unsigned long __user *)sp+i))
3943 + printk(KERN_CONT "???????? ");
3944 + else
3945 + printk(KERN_CONT "%08lx ", c);
3946 + }
3947 + printk("\n");
3948 +}
3949 +#endif
3950 +
3951 /*
3952 * First Level Translation Fault Handler
3953 *
3954 @@ -548,9 +608,22 @@ do_DataAbort(unsigned long addr, unsigned int fsr, struct pt_regs *regs)
3955 const struct fsr_info *inf = fsr_info + fsr_fs(fsr);
3956 struct siginfo info;
3957
3958 +#ifdef CONFIG_PAX_MEMORY_UDEREF
3959 + if (addr < TASK_SIZE && is_domain_fault(fsr)) {
3960 + if (current->signal->curr_ip)
3961 + 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),
3962 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3963 + else
3964 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to access userland memory at %08lx\n", current->comm, task_pid_nr(current),
3965 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()), addr);
3966 + goto die;
3967 + }
3968 +#endif
3969 +
3970 if (!inf->fn(addr, fsr & ~FSR_LNX_PF, regs))
3971 return;
3972
3973 +die:
3974 printk(KERN_ALERT "Unhandled fault: %s (0x%03x) at 0x%08lx\n",
3975 inf->name, fsr, addr);
3976
3977 @@ -574,15 +647,98 @@ hook_ifault_code(int nr, int (*fn)(unsigned long, unsigned int, struct pt_regs *
3978 ifsr_info[nr].name = name;
3979 }
3980
3981 +asmlinkage int sys_sigreturn(struct pt_regs *regs);
3982 +asmlinkage int sys_rt_sigreturn(struct pt_regs *regs);
3983 +
3984 asmlinkage void __exception
3985 do_PrefetchAbort(unsigned long addr, unsigned int ifsr, struct pt_regs *regs)
3986 {
3987 const struct fsr_info *inf = ifsr_info + fsr_fs(ifsr);
3988 struct siginfo info;
3989 + unsigned long pc = instruction_pointer(regs);
3990 +
3991 + if (user_mode(regs)) {
3992 + unsigned long sigpage = current->mm->context.sigpage;
3993 +
3994 + if (sigpage <= pc && pc < sigpage + 7*4) {
3995 + if (pc < sigpage + 3*4)
3996 + sys_sigreturn(regs);
3997 + else
3998 + sys_rt_sigreturn(regs);
3999 + return;
4000 + }
4001 + if (pc == 0xffff0f60UL) {
4002 + /*
4003 + * PaX: __kuser_cmpxchg64 emulation
4004 + */
4005 + // TODO
4006 + //regs->ARM_pc = regs->ARM_lr;
4007 + //return;
4008 + }
4009 + if (pc == 0xffff0fa0UL) {
4010 + /*
4011 + * PaX: __kuser_memory_barrier emulation
4012 + */
4013 + // dmb(); implied by the exception
4014 + regs->ARM_pc = regs->ARM_lr;
4015 + return;
4016 + }
4017 + if (pc == 0xffff0fc0UL) {
4018 + /*
4019 + * PaX: __kuser_cmpxchg emulation
4020 + */
4021 + // TODO
4022 + //long new;
4023 + //int op;
4024 +
4025 + //op = FUTEX_OP_SET << 28;
4026 + //new = futex_atomic_op_inuser(op, regs->ARM_r2);
4027 + //regs->ARM_r0 = old != new;
4028 + //regs->ARM_pc = regs->ARM_lr;
4029 + //return;
4030 + }
4031 + if (pc == 0xffff0fe0UL) {
4032 + /*
4033 + * PaX: __kuser_get_tls emulation
4034 + */
4035 + regs->ARM_r0 = current_thread_info()->tp_value[0];
4036 + regs->ARM_pc = regs->ARM_lr;
4037 + return;
4038 + }
4039 + }
4040 +
4041 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4042 + else if (is_domain_fault(ifsr) || is_xn_fault(ifsr)) {
4043 + if (current->signal->curr_ip)
4044 + 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),
4045 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4046 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4047 + else
4048 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to execute %s memory at %08lx\n", current->comm, task_pid_nr(current),
4049 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()),
4050 + pc >= TASK_SIZE ? "non-executable kernel" : "userland", pc);
4051 + goto die;
4052 + }
4053 +#endif
4054 +
4055 +#ifdef CONFIG_PAX_REFCOUNT
4056 + if (fsr_fs(ifsr) == FAULT_CODE_DEBUG) {
4057 + unsigned int bkpt;
4058 +
4059 + if (!probe_kernel_address(pc, bkpt) && cpu_to_le32(bkpt) == 0xe12f1073) {
4060 + current->thread.error_code = ifsr;
4061 + current->thread.trap_no = 0;
4062 + pax_report_refcount_overflow(regs);
4063 + fixup_exception(regs);
4064 + return;
4065 + }
4066 + }
4067 +#endif
4068
4069 if (!inf->fn(addr, ifsr | FSR_LNX_PF, regs))
4070 return;
4071
4072 +die:
4073 printk(KERN_ALERT "Unhandled prefetch abort: %s (0x%03x) at 0x%08lx\n",
4074 inf->name, ifsr, addr);
4075
4076 diff --git a/arch/arm/mm/fault.h b/arch/arm/mm/fault.h
4077 index cf08bdf..772656c 100644
4078 --- a/arch/arm/mm/fault.h
4079 +++ b/arch/arm/mm/fault.h
4080 @@ -3,6 +3,7 @@
4081
4082 /*
4083 * Fault status register encodings. We steal bit 31 for our own purposes.
4084 + * Set when the FSR value is from an instruction fault.
4085 */
4086 #define FSR_LNX_PF (1 << 31)
4087 #define FSR_WRITE (1 << 11)
4088 @@ -22,6 +23,17 @@ static inline int fsr_fs(unsigned int fsr)
4089 }
4090 #endif
4091
4092 +/* valid for LPAE and !LPAE */
4093 +static inline int is_xn_fault(unsigned int fsr)
4094 +{
4095 + return ((fsr_fs(fsr) & 0x3c) == 0xc);
4096 +}
4097 +
4098 +static inline int is_domain_fault(unsigned int fsr)
4099 +{
4100 + return ((fsr_fs(fsr) & 0xD) == 0x9);
4101 +}
4102 +
4103 void do_bad_area(unsigned long addr, unsigned int fsr, struct pt_regs *regs);
4104 unsigned long search_exception_table(unsigned long addr);
4105
4106 diff --git a/arch/arm/mm/init.c b/arch/arm/mm/init.c
4107 index 3e8f106..a0a1fe4 100644
4108 --- a/arch/arm/mm/init.c
4109 +++ b/arch/arm/mm/init.c
4110 @@ -30,6 +30,8 @@
4111 #include <asm/setup.h>
4112 #include <asm/tlb.h>
4113 #include <asm/fixmap.h>
4114 +#include <asm/system_info.h>
4115 +#include <asm/cp15.h>
4116
4117 #include <asm/mach/arch.h>
4118 #include <asm/mach/map.h>
4119 @@ -681,7 +683,46 @@ void free_initmem(void)
4120 {
4121 #ifdef CONFIG_HAVE_TCM
4122 extern char __tcm_start, __tcm_end;
4123 +#endif
4124
4125 +#ifdef CONFIG_PAX_KERNEXEC
4126 + unsigned long addr;
4127 + pgd_t *pgd;
4128 + pud_t *pud;
4129 + pmd_t *pmd;
4130 + int cpu_arch = cpu_architecture();
4131 + unsigned int cr = get_cr();
4132 +
4133 + if (cpu_arch >= CPU_ARCH_ARMv6 && (cr & CR_XP)) {
4134 + /* make pages tables, etc before .text NX */
4135 + for (addr = PAGE_OFFSET; addr < (unsigned long)_stext; addr += SECTION_SIZE) {
4136 + pgd = pgd_offset_k(addr);
4137 + pud = pud_offset(pgd, addr);
4138 + pmd = pmd_offset(pud, addr);
4139 + __section_update(pmd, addr, PMD_SECT_XN);
4140 + }
4141 + /* make init NX */
4142 + for (addr = (unsigned long)__init_begin; addr < (unsigned long)_sdata; addr += SECTION_SIZE) {
4143 + pgd = pgd_offset_k(addr);
4144 + pud = pud_offset(pgd, addr);
4145 + pmd = pmd_offset(pud, addr);
4146 + __section_update(pmd, addr, PMD_SECT_XN);
4147 + }
4148 + /* make kernel code/rodata RX */
4149 + for (addr = (unsigned long)_stext; addr < (unsigned long)__init_begin; addr += SECTION_SIZE) {
4150 + pgd = pgd_offset_k(addr);
4151 + pud = pud_offset(pgd, addr);
4152 + pmd = pmd_offset(pud, addr);
4153 +#ifdef CONFIG_ARM_LPAE
4154 + __section_update(pmd, addr, PMD_SECT_RDONLY);
4155 +#else
4156 + __section_update(pmd, addr, PMD_SECT_APX|PMD_SECT_AP_WRITE);
4157 +#endif
4158 + }
4159 + }
4160 +#endif
4161 +
4162 +#ifdef CONFIG_HAVE_TCM
4163 poison_init_mem(&__tcm_start, &__tcm_end - &__tcm_start);
4164 free_reserved_area(&__tcm_start, &__tcm_end, -1, "TCM link");
4165 #endif
4166 diff --git a/arch/arm/mm/ioremap.c b/arch/arm/mm/ioremap.c
4167 index f123d6e..04bf569 100644
4168 --- a/arch/arm/mm/ioremap.c
4169 +++ b/arch/arm/mm/ioremap.c
4170 @@ -392,9 +392,9 @@ __arm_ioremap_exec(phys_addr_t phys_addr, size_t size, bool cached)
4171 unsigned int mtype;
4172
4173 if (cached)
4174 - mtype = MT_MEMORY;
4175 + mtype = MT_MEMORY_RX;
4176 else
4177 - mtype = MT_MEMORY_NONCACHED;
4178 + mtype = MT_MEMORY_NONCACHED_RX;
4179
4180 return __arm_ioremap_caller(phys_addr, size, mtype,
4181 __builtin_return_address(0));
4182 diff --git a/arch/arm/mm/mmap.c b/arch/arm/mm/mmap.c
4183 index 5e85ed3..b10a7ed 100644
4184 --- a/arch/arm/mm/mmap.c
4185 +++ b/arch/arm/mm/mmap.c
4186 @@ -59,6 +59,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4187 struct vm_area_struct *vma;
4188 int do_align = 0;
4189 int aliasing = cache_is_vipt_aliasing();
4190 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4191 struct vm_unmapped_area_info info;
4192
4193 /*
4194 @@ -81,6 +82,10 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4195 if (len > TASK_SIZE)
4196 return -ENOMEM;
4197
4198 +#ifdef CONFIG_PAX_RANDMMAP
4199 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4200 +#endif
4201 +
4202 if (addr) {
4203 if (do_align)
4204 addr = COLOUR_ALIGN(addr, pgoff);
4205 @@ -88,8 +93,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4206 addr = PAGE_ALIGN(addr);
4207
4208 vma = find_vma(mm, addr);
4209 - if (TASK_SIZE - len >= addr &&
4210 - (!vma || addr + len <= vma->vm_start))
4211 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4212 return addr;
4213 }
4214
4215 @@ -99,6 +103,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
4216 info.high_limit = TASK_SIZE;
4217 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4218 info.align_offset = pgoff << PAGE_SHIFT;
4219 + info.threadstack_offset = offset;
4220 return vm_unmapped_area(&info);
4221 }
4222
4223 @@ -112,6 +117,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4224 unsigned long addr = addr0;
4225 int do_align = 0;
4226 int aliasing = cache_is_vipt_aliasing();
4227 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
4228 struct vm_unmapped_area_info info;
4229
4230 /*
4231 @@ -132,6 +138,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4232 return addr;
4233 }
4234
4235 +#ifdef CONFIG_PAX_RANDMMAP
4236 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4237 +#endif
4238 +
4239 /* requesting a specific address */
4240 if (addr) {
4241 if (do_align)
4242 @@ -139,8 +149,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4243 else
4244 addr = PAGE_ALIGN(addr);
4245 vma = find_vma(mm, addr);
4246 - if (TASK_SIZE - len >= addr &&
4247 - (!vma || addr + len <= vma->vm_start))
4248 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4249 return addr;
4250 }
4251
4252 @@ -150,6 +159,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
4253 info.high_limit = mm->mmap_base;
4254 info.align_mask = do_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
4255 info.align_offset = pgoff << PAGE_SHIFT;
4256 + info.threadstack_offset = offset;
4257 addr = vm_unmapped_area(&info);
4258
4259 /*
4260 @@ -173,6 +183,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4261 {
4262 unsigned long random_factor = 0UL;
4263
4264 +#ifdef CONFIG_PAX_RANDMMAP
4265 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
4266 +#endif
4267 +
4268 /* 8 bits of randomness in 20 address space bits */
4269 if ((current->flags & PF_RANDOMIZE) &&
4270 !(current->personality & ADDR_NO_RANDOMIZE))
4271 @@ -180,9 +194,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
4272
4273 if (mmap_is_legacy()) {
4274 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
4275 +
4276 +#ifdef CONFIG_PAX_RANDMMAP
4277 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4278 + mm->mmap_base += mm->delta_mmap;
4279 +#endif
4280 +
4281 mm->get_unmapped_area = arch_get_unmapped_area;
4282 } else {
4283 mm->mmap_base = mmap_base(random_factor);
4284 +
4285 +#ifdef CONFIG_PAX_RANDMMAP
4286 + if (mm->pax_flags & MF_PAX_RANDMMAP)
4287 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
4288 +#endif
4289 +
4290 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
4291 }
4292 }
4293 diff --git a/arch/arm/mm/mmu.c b/arch/arm/mm/mmu.c
4294 index 580ef2d..2da06ca 100644
4295 --- a/arch/arm/mm/mmu.c
4296 +++ b/arch/arm/mm/mmu.c
4297 @@ -38,6 +38,22 @@
4298 #include "mm.h"
4299 #include "tcm.h"
4300
4301 +#if defined(CONFIG_CPU_USE_DOMAINS) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
4302 +void modify_domain(unsigned int dom, unsigned int type)
4303 +{
4304 + struct thread_info *thread = current_thread_info();
4305 + unsigned int domain = thread->cpu_domain;
4306 + /*
4307 + * DOMAIN_MANAGER might be defined to some other value,
4308 + * use the arch-defined constant
4309 + */
4310 + domain &= ~domain_val(dom, 3);
4311 + thread->cpu_domain = domain | domain_val(dom, type);
4312 + set_domain(thread->cpu_domain);
4313 +}
4314 +EXPORT_SYMBOL(modify_domain);
4315 +#endif
4316 +
4317 /*
4318 * empty_zero_page is a special page that is used for
4319 * zero-initialized data and COW.
4320 @@ -230,10 +246,18 @@ __setup("noalign", noalign_setup);
4321
4322 #endif /* ifdef CONFIG_CPU_CP15 / else */
4323
4324 -#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY|L_PTE_XN
4325 +#define PROT_PTE_DEVICE L_PTE_PRESENT|L_PTE_YOUNG|L_PTE_DIRTY
4326 #define PROT_SECT_DEVICE PMD_TYPE_SECT|PMD_SECT_AP_WRITE
4327
4328 -static struct mem_type mem_types[] = {
4329 +#ifdef CONFIG_PAX_KERNEXEC
4330 +#define L_PTE_KERNEXEC L_PTE_RDONLY
4331 +#define PMD_SECT_KERNEXEC PMD_SECT_RDONLY
4332 +#else
4333 +#define L_PTE_KERNEXEC L_PTE_DIRTY
4334 +#define PMD_SECT_KERNEXEC PMD_SECT_AP_WRITE
4335 +#endif
4336 +
4337 +static struct mem_type mem_types[] __read_only = {
4338 [MT_DEVICE] = { /* Strongly ordered / ARMv6 shared device */
4339 .prot_pte = PROT_PTE_DEVICE | L_PTE_MT_DEV_SHARED |
4340 L_PTE_SHARED,
4341 @@ -262,16 +286,16 @@ static struct mem_type mem_types[] = {
4342 [MT_UNCACHED] = {
4343 .prot_pte = PROT_PTE_DEVICE,
4344 .prot_l1 = PMD_TYPE_TABLE,
4345 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4346 + .prot_sect = PROT_SECT_DEVICE,
4347 .domain = DOMAIN_IO,
4348 },
4349 [MT_CACHECLEAN] = {
4350 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4351 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4352 .domain = DOMAIN_KERNEL,
4353 },
4354 #ifndef CONFIG_ARM_LPAE
4355 [MT_MINICLEAN] = {
4356 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN | PMD_SECT_MINICACHE,
4357 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_MINICACHE | PMD_SECT_RDONLY,
4358 .domain = DOMAIN_KERNEL,
4359 },
4360 #endif
4361 @@ -279,36 +303,54 @@ static struct mem_type mem_types[] = {
4362 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4363 L_PTE_RDONLY,
4364 .prot_l1 = PMD_TYPE_TABLE,
4365 - .domain = DOMAIN_USER,
4366 + .domain = DOMAIN_VECTORS,
4367 },
4368 [MT_HIGH_VECTORS] = {
4369 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4370 L_PTE_USER | L_PTE_RDONLY,
4371 .prot_l1 = PMD_TYPE_TABLE,
4372 - .domain = DOMAIN_USER,
4373 + .domain = DOMAIN_VECTORS,
4374 },
4375 - [MT_MEMORY] = {
4376 + [MT_MEMORY_RWX] = {
4377 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4378 .prot_l1 = PMD_TYPE_TABLE,
4379 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4380 .domain = DOMAIN_KERNEL,
4381 },
4382 + [MT_MEMORY_RW] = {
4383 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4384 + .prot_l1 = PMD_TYPE_TABLE,
4385 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE,
4386 + .domain = DOMAIN_KERNEL,
4387 + },
4388 + [MT_MEMORY_RX] = {
4389 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_KERNEXEC,
4390 + .prot_l1 = PMD_TYPE_TABLE,
4391 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_KERNEXEC,
4392 + .domain = DOMAIN_KERNEL,
4393 + },
4394 [MT_ROM] = {
4395 - .prot_sect = PMD_TYPE_SECT,
4396 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4397 .domain = DOMAIN_KERNEL,
4398 },
4399 - [MT_MEMORY_NONCACHED] = {
4400 + [MT_MEMORY_NONCACHED_RW] = {
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_NONCACHED_RX] = {
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_DTCM] = {
4415 - .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4416 - L_PTE_XN,
4417 + .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY,
4418 .prot_l1 = PMD_TYPE_TABLE,
4419 - .prot_sect = PMD_TYPE_SECT | PMD_SECT_XN,
4420 + .prot_sect = PMD_TYPE_SECT | PMD_SECT_RDONLY,
4421 .domain = DOMAIN_KERNEL,
4422 },
4423 [MT_MEMORY_ITCM] = {
4424 @@ -318,10 +360,10 @@ static struct mem_type mem_types[] = {
4425 },
4426 [MT_MEMORY_SO] = {
4427 .prot_pte = L_PTE_PRESENT | L_PTE_YOUNG | L_PTE_DIRTY |
4428 - L_PTE_MT_UNCACHED | L_PTE_XN,
4429 + L_PTE_MT_UNCACHED,
4430 .prot_l1 = PMD_TYPE_TABLE,
4431 .prot_sect = PMD_TYPE_SECT | PMD_SECT_AP_WRITE | PMD_SECT_S |
4432 - PMD_SECT_UNCACHED | PMD_SECT_XN,
4433 + PMD_SECT_UNCACHED,
4434 .domain = DOMAIN_KERNEL,
4435 },
4436 [MT_MEMORY_DMA_READY] = {
4437 @@ -407,9 +449,35 @@ static void __init build_mem_type_table(void)
4438 * to prevent speculative instruction fetches.
4439 */
4440 mem_types[MT_DEVICE].prot_sect |= PMD_SECT_XN;
4441 + mem_types[MT_DEVICE].prot_pte |= L_PTE_XN;
4442 mem_types[MT_DEVICE_NONSHARED].prot_sect |= PMD_SECT_XN;
4443 + mem_types[MT_DEVICE_NONSHARED].prot_pte |= L_PTE_XN;
4444 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_XN;
4445 + mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_XN;
4446 mem_types[MT_DEVICE_WC].prot_sect |= PMD_SECT_XN;
4447 + mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_XN;
4448 +
4449 + /* Mark other regions on ARMv6+ as execute-never */
4450 +
4451 +#ifdef CONFIG_PAX_KERNEXEC
4452 + mem_types[MT_UNCACHED].prot_sect |= PMD_SECT_XN;
4453 + mem_types[MT_UNCACHED].prot_pte |= L_PTE_XN;
4454 + mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_XN;
4455 + mem_types[MT_CACHECLEAN].prot_pte |= L_PTE_XN;
4456 +#ifndef CONFIG_ARM_LPAE
4457 + mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_XN;
4458 + mem_types[MT_MINICLEAN].prot_pte |= L_PTE_XN;
4459 +#endif
4460 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_XN;
4461 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_XN;
4462 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_XN;
4463 + mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= PMD_SECT_XN;
4464 + mem_types[MT_MEMORY_DTCM].prot_sect |= PMD_SECT_XN;
4465 + mem_types[MT_MEMORY_DTCM].prot_pte |= L_PTE_XN;
4466 +#endif
4467 +
4468 + mem_types[MT_MEMORY_SO].prot_sect |= PMD_SECT_XN;
4469 + mem_types[MT_MEMORY_SO].prot_pte |= L_PTE_XN;
4470 }
4471 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4472 /*
4473 @@ -470,6 +538,9 @@ static void __init build_mem_type_table(void)
4474 * from SVC mode and no access from userspace.
4475 */
4476 mem_types[MT_ROM].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4477 +#ifdef CONFIG_PAX_KERNEXEC
4478 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4479 +#endif
4480 mem_types[MT_MINICLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4481 mem_types[MT_CACHECLEAN].prot_sect |= PMD_SECT_APX|PMD_SECT_AP_WRITE;
4482 #endif
4483 @@ -487,11 +558,17 @@ static void __init build_mem_type_table(void)
4484 mem_types[MT_DEVICE_WC].prot_pte |= L_PTE_SHARED;
4485 mem_types[MT_DEVICE_CACHED].prot_sect |= PMD_SECT_S;
4486 mem_types[MT_DEVICE_CACHED].prot_pte |= L_PTE_SHARED;
4487 - mem_types[MT_MEMORY].prot_sect |= PMD_SECT_S;
4488 - mem_types[MT_MEMORY].prot_pte |= L_PTE_SHARED;
4489 + mem_types[MT_MEMORY_RWX].prot_sect |= PMD_SECT_S;
4490 + mem_types[MT_MEMORY_RWX].prot_pte |= L_PTE_SHARED;
4491 + mem_types[MT_MEMORY_RW].prot_sect |= PMD_SECT_S;
4492 + mem_types[MT_MEMORY_RW].prot_pte |= L_PTE_SHARED;
4493 + mem_types[MT_MEMORY_RX].prot_sect |= PMD_SECT_S;
4494 + mem_types[MT_MEMORY_RX].prot_pte |= L_PTE_SHARED;
4495 mem_types[MT_MEMORY_DMA_READY].prot_pte |= L_PTE_SHARED;
4496 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_S;
4497 - mem_types[MT_MEMORY_NONCACHED].prot_pte |= L_PTE_SHARED;
4498 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_S;
4499 + mem_types[MT_MEMORY_NONCACHED_RW].prot_pte |= L_PTE_SHARED;
4500 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_S;
4501 + mem_types[MT_MEMORY_NONCACHED_RX].prot_pte |= L_PTE_SHARED;
4502 }
4503 }
4504
4505 @@ -502,15 +579,20 @@ static void __init build_mem_type_table(void)
4506 if (cpu_arch >= CPU_ARCH_ARMv6) {
4507 if (cpu_arch >= CPU_ARCH_ARMv7 && (cr & CR_TRE)) {
4508 /* Non-cacheable Normal is XCB = 001 */
4509 - mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4510 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4511 + PMD_SECT_BUFFERED;
4512 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4513 PMD_SECT_BUFFERED;
4514 } else {
4515 /* For both ARMv6 and non-TEX-remapping ARMv7 */
4516 - mem_types[MT_MEMORY_NONCACHED].prot_sect |=
4517 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |=
4518 + PMD_SECT_TEX(1);
4519 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |=
4520 PMD_SECT_TEX(1);
4521 }
4522 } else {
4523 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= PMD_SECT_BUFFERABLE;
4524 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= PMD_SECT_BUFFERABLE;
4525 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= PMD_SECT_BUFFERABLE;
4526 }
4527
4528 #ifdef CONFIG_ARM_LPAE
4529 @@ -526,6 +608,8 @@ static void __init build_mem_type_table(void)
4530 vecs_pgprot |= PTE_EXT_AF;
4531 #endif
4532
4533 + user_pgprot |= __supported_pte_mask;
4534 +
4535 for (i = 0; i < 16; i++) {
4536 pteval_t v = pgprot_val(protection_map[i]);
4537 protection_map[i] = __pgprot(v | user_pgprot);
4538 @@ -543,10 +627,15 @@ static void __init build_mem_type_table(void)
4539
4540 mem_types[MT_LOW_VECTORS].prot_l1 |= ecc_mask;
4541 mem_types[MT_HIGH_VECTORS].prot_l1 |= ecc_mask;
4542 - mem_types[MT_MEMORY].prot_sect |= ecc_mask | cp->pmd;
4543 - mem_types[MT_MEMORY].prot_pte |= kern_pgprot;
4544 + mem_types[MT_MEMORY_RWX].prot_sect |= ecc_mask | cp->pmd;
4545 + mem_types[MT_MEMORY_RWX].prot_pte |= kern_pgprot;
4546 + mem_types[MT_MEMORY_RW].prot_sect |= ecc_mask | cp->pmd;
4547 + mem_types[MT_MEMORY_RW].prot_pte |= kern_pgprot;
4548 + mem_types[MT_MEMORY_RX].prot_sect |= ecc_mask | cp->pmd;
4549 + mem_types[MT_MEMORY_RX].prot_pte |= kern_pgprot;
4550 mem_types[MT_MEMORY_DMA_READY].prot_pte |= kern_pgprot;
4551 - mem_types[MT_MEMORY_NONCACHED].prot_sect |= ecc_mask;
4552 + mem_types[MT_MEMORY_NONCACHED_RW].prot_sect |= ecc_mask;
4553 + mem_types[MT_MEMORY_NONCACHED_RX].prot_sect |= ecc_mask;
4554 mem_types[MT_ROM].prot_sect |= cp->pmd;
4555
4556 switch (cp->pmd) {
4557 @@ -1188,18 +1277,15 @@ void __init arm_mm_memblock_reserve(void)
4558 * called function. This means you can't use any function or debugging
4559 * method which may touch any device, otherwise the kernel _will_ crash.
4560 */
4561 +
4562 +static char vectors[PAGE_SIZE * 2] __read_only __aligned(PAGE_SIZE);
4563 +
4564 static void __init devicemaps_init(const struct machine_desc *mdesc)
4565 {
4566 struct map_desc map;
4567 unsigned long addr;
4568 - void *vectors;
4569
4570 - /*
4571 - * Allocate the vector page early.
4572 - */
4573 - vectors = early_alloc(PAGE_SIZE * 2);
4574 -
4575 - early_trap_init(vectors);
4576 + early_trap_init(&vectors);
4577
4578 for (addr = VMALLOC_START; addr; addr += PMD_SIZE)
4579 pmd_clear(pmd_off_k(addr));
4580 @@ -1239,7 +1325,7 @@ static void __init devicemaps_init(const struct machine_desc *mdesc)
4581 * location (0xffff0000). If we aren't using high-vectors, also
4582 * create a mapping at the low-vectors virtual address.
4583 */
4584 - map.pfn = __phys_to_pfn(virt_to_phys(vectors));
4585 + map.pfn = __phys_to_pfn(virt_to_phys(&vectors));
4586 map.virtual = 0xffff0000;
4587 map.length = PAGE_SIZE;
4588 #ifdef CONFIG_KUSER_HELPERS
4589 @@ -1311,8 +1397,39 @@ static void __init map_lowmem(void)
4590 map.pfn = __phys_to_pfn(start);
4591 map.virtual = __phys_to_virt(start);
4592 map.length = end - start;
4593 - map.type = MT_MEMORY;
4594
4595 +#ifdef CONFIG_PAX_KERNEXEC
4596 + if (map.virtual <= (unsigned long)_stext && ((unsigned long)_end < (map.virtual + map.length))) {
4597 + struct map_desc kernel;
4598 + struct map_desc initmap;
4599 +
4600 + /* when freeing initmem we will make this RW */
4601 + initmap.pfn = __phys_to_pfn(__pa(__init_begin));
4602 + initmap.virtual = (unsigned long)__init_begin;
4603 + initmap.length = _sdata - __init_begin;
4604 + initmap.type = MT_MEMORY_RWX;
4605 + create_mapping(&initmap);
4606 +
4607 + /* when freeing initmem we will make this RX */
4608 + kernel.pfn = __phys_to_pfn(__pa(_stext));
4609 + kernel.virtual = (unsigned long)_stext;
4610 + kernel.length = __init_begin - _stext;
4611 + kernel.type = MT_MEMORY_RWX;
4612 + create_mapping(&kernel);
4613 +
4614 + if (map.virtual < (unsigned long)_stext) {
4615 + map.length = (unsigned long)_stext - map.virtual;
4616 + map.type = MT_MEMORY_RWX;
4617 + create_mapping(&map);
4618 + }
4619 +
4620 + map.pfn = __phys_to_pfn(__pa(_sdata));
4621 + map.virtual = (unsigned long)_sdata;
4622 + map.length = end - __pa(_sdata);
4623 + }
4624 +#endif
4625 +
4626 + map.type = MT_MEMORY_RW;
4627 create_mapping(&map);
4628 }
4629 }
4630 diff --git a/arch/arm/plat-omap/sram.c b/arch/arm/plat-omap/sram.c
4631 index a5bc92d..0bb4730 100644
4632 --- a/arch/arm/plat-omap/sram.c
4633 +++ b/arch/arm/plat-omap/sram.c
4634 @@ -93,6 +93,8 @@ void __init omap_map_sram(unsigned long start, unsigned long size,
4635 * Looks like we need to preserve some bootloader code at the
4636 * beginning of SRAM for jumping to flash for reboot to work...
4637 */
4638 + pax_open_kernel();
4639 memset_io(omap_sram_base + omap_sram_skip, 0,
4640 omap_sram_size - omap_sram_skip);
4641 + pax_close_kernel();
4642 }
4643 diff --git a/arch/arm/plat-samsung/include/plat/dma-ops.h b/arch/arm/plat-samsung/include/plat/dma-ops.h
4644 index ce6d763..cfea917 100644
4645 --- a/arch/arm/plat-samsung/include/plat/dma-ops.h
4646 +++ b/arch/arm/plat-samsung/include/plat/dma-ops.h
4647 @@ -47,7 +47,7 @@ struct samsung_dma_ops {
4648 int (*started)(unsigned ch);
4649 int (*flush)(unsigned ch);
4650 int (*stop)(unsigned ch);
4651 -};
4652 +} __no_const;
4653
4654 extern void *samsung_dmadev_get_ops(void);
4655 extern void *s3c_dma_get_ops(void);
4656 diff --git a/arch/avr32/include/asm/cache.h b/arch/avr32/include/asm/cache.h
4657 index c3a58a1..78fbf54 100644
4658 --- a/arch/avr32/include/asm/cache.h
4659 +++ b/arch/avr32/include/asm/cache.h
4660 @@ -1,8 +1,10 @@
4661 #ifndef __ASM_AVR32_CACHE_H
4662 #define __ASM_AVR32_CACHE_H
4663
4664 +#include <linux/const.h>
4665 +
4666 #define L1_CACHE_SHIFT 5
4667 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4668 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4669
4670 /*
4671 * Memory returned by kmalloc() may be used for DMA, so we must make
4672 diff --git a/arch/avr32/include/asm/elf.h b/arch/avr32/include/asm/elf.h
4673 index d232888..87c8df1 100644
4674 --- a/arch/avr32/include/asm/elf.h
4675 +++ b/arch/avr32/include/asm/elf.h
4676 @@ -84,8 +84,14 @@ typedef struct user_fpu_struct elf_fpregset_t;
4677 the loader. We need to make sure that it is out of the way of the program
4678 that it will "exec", and that there is sufficient room for the brk. */
4679
4680 -#define ELF_ET_DYN_BASE (2 * TASK_SIZE / 3)
4681 +#define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
4682
4683 +#ifdef CONFIG_PAX_ASLR
4684 +#define PAX_ELF_ET_DYN_BASE 0x00001000UL
4685 +
4686 +#define PAX_DELTA_MMAP_LEN 15
4687 +#define PAX_DELTA_STACK_LEN 15
4688 +#endif
4689
4690 /* This yields a mask that user programs can use to figure out what
4691 instruction set this CPU supports. This could be done in user space,
4692 diff --git a/arch/avr32/include/asm/kmap_types.h b/arch/avr32/include/asm/kmap_types.h
4693 index 479330b..53717a8 100644
4694 --- a/arch/avr32/include/asm/kmap_types.h
4695 +++ b/arch/avr32/include/asm/kmap_types.h
4696 @@ -2,9 +2,9 @@
4697 #define __ASM_AVR32_KMAP_TYPES_H
4698
4699 #ifdef CONFIG_DEBUG_HIGHMEM
4700 -# define KM_TYPE_NR 29
4701 +# define KM_TYPE_NR 30
4702 #else
4703 -# define KM_TYPE_NR 14
4704 +# define KM_TYPE_NR 15
4705 #endif
4706
4707 #endif /* __ASM_AVR32_KMAP_TYPES_H */
4708 diff --git a/arch/avr32/mm/fault.c b/arch/avr32/mm/fault.c
4709 index 0eca933..eb78c7b 100644
4710 --- a/arch/avr32/mm/fault.c
4711 +++ b/arch/avr32/mm/fault.c
4712 @@ -41,6 +41,23 @@ static inline int notify_page_fault(struct pt_regs *regs, int trap)
4713
4714 int exception_trace = 1;
4715
4716 +#ifdef CONFIG_PAX_PAGEEXEC
4717 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
4718 +{
4719 + unsigned long i;
4720 +
4721 + printk(KERN_ERR "PAX: bytes at PC: ");
4722 + for (i = 0; i < 20; i++) {
4723 + unsigned char c;
4724 + if (get_user(c, (unsigned char *)pc+i))
4725 + printk(KERN_CONT "???????? ");
4726 + else
4727 + printk(KERN_CONT "%02x ", c);
4728 + }
4729 + printk("\n");
4730 +}
4731 +#endif
4732 +
4733 /*
4734 * This routine handles page faults. It determines the address and the
4735 * problem, and then passes it off to one of the appropriate routines.
4736 @@ -176,6 +193,16 @@ bad_area:
4737 up_read(&mm->mmap_sem);
4738
4739 if (user_mode(regs)) {
4740 +
4741 +#ifdef CONFIG_PAX_PAGEEXEC
4742 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
4743 + if (ecr == ECR_PROTECTION_X || ecr == ECR_TLB_MISS_X) {
4744 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->sp);
4745 + do_group_exit(SIGKILL);
4746 + }
4747 + }
4748 +#endif
4749 +
4750 if (exception_trace && printk_ratelimit())
4751 printk("%s%s[%d]: segfault at %08lx pc %08lx "
4752 "sp %08lx ecr %lu\n",
4753 diff --git a/arch/blackfin/include/asm/cache.h b/arch/blackfin/include/asm/cache.h
4754 index 568885a..f8008df 100644
4755 --- a/arch/blackfin/include/asm/cache.h
4756 +++ b/arch/blackfin/include/asm/cache.h
4757 @@ -7,6 +7,7 @@
4758 #ifndef __ARCH_BLACKFIN_CACHE_H
4759 #define __ARCH_BLACKFIN_CACHE_H
4760
4761 +#include <linux/const.h>
4762 #include <linux/linkage.h> /* for asmlinkage */
4763
4764 /*
4765 @@ -14,7 +15,7 @@
4766 * Blackfin loads 32 bytes for cache
4767 */
4768 #define L1_CACHE_SHIFT 5
4769 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4770 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4771 #define SMP_CACHE_BYTES L1_CACHE_BYTES
4772
4773 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
4774 diff --git a/arch/cris/include/arch-v10/arch/cache.h b/arch/cris/include/arch-v10/arch/cache.h
4775 index aea2718..3639a60 100644
4776 --- a/arch/cris/include/arch-v10/arch/cache.h
4777 +++ b/arch/cris/include/arch-v10/arch/cache.h
4778 @@ -1,8 +1,9 @@
4779 #ifndef _ASM_ARCH_CACHE_H
4780 #define _ASM_ARCH_CACHE_H
4781
4782 +#include <linux/const.h>
4783 /* Etrax 100LX have 32-byte cache-lines. */
4784 -#define L1_CACHE_BYTES 32
4785 #define L1_CACHE_SHIFT 5
4786 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4787
4788 #endif /* _ASM_ARCH_CACHE_H */
4789 diff --git a/arch/cris/include/arch-v32/arch/cache.h b/arch/cris/include/arch-v32/arch/cache.h
4790 index 7caf25d..ee65ac5 100644
4791 --- a/arch/cris/include/arch-v32/arch/cache.h
4792 +++ b/arch/cris/include/arch-v32/arch/cache.h
4793 @@ -1,11 +1,12 @@
4794 #ifndef _ASM_CRIS_ARCH_CACHE_H
4795 #define _ASM_CRIS_ARCH_CACHE_H
4796
4797 +#include <linux/const.h>
4798 #include <arch/hwregs/dma.h>
4799
4800 /* A cache-line is 32 bytes. */
4801 -#define L1_CACHE_BYTES 32
4802 #define L1_CACHE_SHIFT 5
4803 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4804
4805 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
4806
4807 diff --git a/arch/frv/include/asm/atomic.h b/arch/frv/include/asm/atomic.h
4808 index b86329d..6709906 100644
4809 --- a/arch/frv/include/asm/atomic.h
4810 +++ b/arch/frv/include/asm/atomic.h
4811 @@ -186,6 +186,16 @@ static inline void atomic64_dec(atomic64_t *v)
4812 #define atomic64_cmpxchg(v, old, new) (__cmpxchg_64(old, new, &(v)->counter))
4813 #define atomic64_xchg(v, new) (__xchg_64(new, &(v)->counter))
4814
4815 +#define atomic64_read_unchecked(v) atomic64_read(v)
4816 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4817 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4818 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4819 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4820 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4821 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4822 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4823 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4824 +
4825 static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
4826 {
4827 int c, old;
4828 diff --git a/arch/frv/include/asm/cache.h b/arch/frv/include/asm/cache.h
4829 index 2797163..c2a401d 100644
4830 --- a/arch/frv/include/asm/cache.h
4831 +++ b/arch/frv/include/asm/cache.h
4832 @@ -12,10 +12,11 @@
4833 #ifndef __ASM_CACHE_H
4834 #define __ASM_CACHE_H
4835
4836 +#include <linux/const.h>
4837
4838 /* bytes per L1 cache line */
4839 #define L1_CACHE_SHIFT (CONFIG_FRV_L1_CACHE_SHIFT)
4840 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4841 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4842
4843 #define __cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4844 #define ____cacheline_aligned __attribute__((aligned(L1_CACHE_BYTES)))
4845 diff --git a/arch/frv/include/asm/kmap_types.h b/arch/frv/include/asm/kmap_types.h
4846 index 43901f2..0d8b865 100644
4847 --- a/arch/frv/include/asm/kmap_types.h
4848 +++ b/arch/frv/include/asm/kmap_types.h
4849 @@ -2,6 +2,6 @@
4850 #ifndef _ASM_KMAP_TYPES_H
4851 #define _ASM_KMAP_TYPES_H
4852
4853 -#define KM_TYPE_NR 17
4854 +#define KM_TYPE_NR 18
4855
4856 #endif
4857 diff --git a/arch/frv/mm/elf-fdpic.c b/arch/frv/mm/elf-fdpic.c
4858 index 836f147..4cf23f5 100644
4859 --- a/arch/frv/mm/elf-fdpic.c
4860 +++ b/arch/frv/mm/elf-fdpic.c
4861 @@ -61,6 +61,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4862 {
4863 struct vm_area_struct *vma;
4864 struct vm_unmapped_area_info info;
4865 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
4866
4867 if (len > TASK_SIZE)
4868 return -ENOMEM;
4869 @@ -73,8 +74,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4870 if (addr) {
4871 addr = PAGE_ALIGN(addr);
4872 vma = find_vma(current->mm, addr);
4873 - if (TASK_SIZE - len >= addr &&
4874 - (!vma || addr + len <= vma->vm_start))
4875 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
4876 goto success;
4877 }
4878
4879 @@ -85,6 +85,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
4880 info.high_limit = (current->mm->start_stack - 0x00200000);
4881 info.align_mask = 0;
4882 info.align_offset = 0;
4883 + info.threadstack_offset = offset;
4884 addr = vm_unmapped_area(&info);
4885 if (!(addr & ~PAGE_MASK))
4886 goto success;
4887 diff --git a/arch/hexagon/include/asm/cache.h b/arch/hexagon/include/asm/cache.h
4888 index f4ca594..adc72fd6 100644
4889 --- a/arch/hexagon/include/asm/cache.h
4890 +++ b/arch/hexagon/include/asm/cache.h
4891 @@ -21,9 +21,11 @@
4892 #ifndef __ASM_CACHE_H
4893 #define __ASM_CACHE_H
4894
4895 +#include <linux/const.h>
4896 +
4897 /* Bytes per L1 cache line */
4898 -#define L1_CACHE_SHIFT (5)
4899 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4900 +#define L1_CACHE_SHIFT 5
4901 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4902
4903 #define __cacheline_aligned __aligned(L1_CACHE_BYTES)
4904 #define ____cacheline_aligned __aligned(L1_CACHE_BYTES)
4905 diff --git a/arch/ia64/Kconfig b/arch/ia64/Kconfig
4906 index 4e4119b..dd7de0a 100644
4907 --- a/arch/ia64/Kconfig
4908 +++ b/arch/ia64/Kconfig
4909 @@ -554,6 +554,7 @@ source "drivers/sn/Kconfig"
4910 config KEXEC
4911 bool "kexec system call"
4912 depends on !IA64_HP_SIM && (!SMP || HOTPLUG_CPU)
4913 + depends on !GRKERNSEC_KMEM
4914 help
4915 kexec is a system call that implements the ability to shutdown your
4916 current kernel, and to start another kernel. It is like a reboot
4917 diff --git a/arch/ia64/include/asm/atomic.h b/arch/ia64/include/asm/atomic.h
4918 index 6e6fe18..a6ae668 100644
4919 --- a/arch/ia64/include/asm/atomic.h
4920 +++ b/arch/ia64/include/asm/atomic.h
4921 @@ -208,6 +208,16 @@ atomic64_add_negative (__s64 i, atomic64_t *v)
4922 #define atomic64_inc(v) atomic64_add(1, (v))
4923 #define atomic64_dec(v) atomic64_sub(1, (v))
4924
4925 +#define atomic64_read_unchecked(v) atomic64_read(v)
4926 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
4927 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
4928 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
4929 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
4930 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
4931 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
4932 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
4933 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
4934 +
4935 /* Atomic operations are already serializing */
4936 #define smp_mb__before_atomic_dec() barrier()
4937 #define smp_mb__after_atomic_dec() barrier()
4938 diff --git a/arch/ia64/include/asm/cache.h b/arch/ia64/include/asm/cache.h
4939 index 988254a..e1ee885 100644
4940 --- a/arch/ia64/include/asm/cache.h
4941 +++ b/arch/ia64/include/asm/cache.h
4942 @@ -1,6 +1,7 @@
4943 #ifndef _ASM_IA64_CACHE_H
4944 #define _ASM_IA64_CACHE_H
4945
4946 +#include <linux/const.h>
4947
4948 /*
4949 * Copyright (C) 1998-2000 Hewlett-Packard Co
4950 @@ -9,7 +10,7 @@
4951
4952 /* Bytes per L1 (data) cache line. */
4953 #define L1_CACHE_SHIFT CONFIG_IA64_L1_CACHE_SHIFT
4954 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
4955 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
4956
4957 #ifdef CONFIG_SMP
4958 # define SMP_CACHE_SHIFT L1_CACHE_SHIFT
4959 diff --git a/arch/ia64/include/asm/elf.h b/arch/ia64/include/asm/elf.h
4960 index 5a83c5c..4d7f553 100644
4961 --- a/arch/ia64/include/asm/elf.h
4962 +++ b/arch/ia64/include/asm/elf.h
4963 @@ -42,6 +42,13 @@
4964 */
4965 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x800000000UL)
4966
4967 +#ifdef CONFIG_PAX_ASLR
4968 +#define PAX_ELF_ET_DYN_BASE (current->personality == PER_LINUX32 ? 0x08048000UL : 0x4000000000000000UL)
4969 +
4970 +#define PAX_DELTA_MMAP_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4971 +#define PAX_DELTA_STACK_LEN (current->personality == PER_LINUX32 ? 16 : 3*PAGE_SHIFT - 13)
4972 +#endif
4973 +
4974 #define PT_IA_64_UNWIND 0x70000001
4975
4976 /* IA-64 relocations: */
4977 diff --git a/arch/ia64/include/asm/pgalloc.h b/arch/ia64/include/asm/pgalloc.h
4978 index 5767cdf..7462574 100644
4979 --- a/arch/ia64/include/asm/pgalloc.h
4980 +++ b/arch/ia64/include/asm/pgalloc.h
4981 @@ -39,6 +39,12 @@ pgd_populate(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4982 pgd_val(*pgd_entry) = __pa(pud);
4983 }
4984
4985 +static inline void
4986 +pgd_populate_kernel(struct mm_struct *mm, pgd_t * pgd_entry, pud_t * pud)
4987 +{
4988 + pgd_populate(mm, pgd_entry, pud);
4989 +}
4990 +
4991 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
4992 {
4993 return quicklist_alloc(0, GFP_KERNEL, NULL);
4994 @@ -57,6 +63,12 @@ pud_populate(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
4995 pud_val(*pud_entry) = __pa(pmd);
4996 }
4997
4998 +static inline void
4999 +pud_populate_kernel(struct mm_struct *mm, pud_t * pud_entry, pmd_t * pmd)
5000 +{
5001 + pud_populate(mm, pud_entry, pmd);
5002 +}
5003 +
5004 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
5005 {
5006 return quicklist_alloc(0, GFP_KERNEL, NULL);
5007 diff --git a/arch/ia64/include/asm/pgtable.h b/arch/ia64/include/asm/pgtable.h
5008 index 7935115..c0eca6a 100644
5009 --- a/arch/ia64/include/asm/pgtable.h
5010 +++ b/arch/ia64/include/asm/pgtable.h
5011 @@ -12,7 +12,7 @@
5012 * David Mosberger-Tang <davidm@hpl.hp.com>
5013 */
5014
5015 -
5016 +#include <linux/const.h>
5017 #include <asm/mman.h>
5018 #include <asm/page.h>
5019 #include <asm/processor.h>
5020 @@ -142,6 +142,17 @@
5021 #define PAGE_READONLY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5022 #define PAGE_COPY __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5023 #define PAGE_COPY_EXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RX)
5024 +
5025 +#ifdef CONFIG_PAX_PAGEEXEC
5026 +# define PAGE_SHARED_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_RW)
5027 +# define PAGE_READONLY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5028 +# define PAGE_COPY_NOEXEC __pgprot(__ACCESS_BITS | _PAGE_PL_3 | _PAGE_AR_R)
5029 +#else
5030 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
5031 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
5032 +# define PAGE_COPY_NOEXEC PAGE_COPY
5033 +#endif
5034 +
5035 #define PAGE_GATE __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_X_RX)
5036 #define PAGE_KERNEL __pgprot(__DIRTY_BITS | _PAGE_PL_0 | _PAGE_AR_RWX)
5037 #define PAGE_KERNELRX __pgprot(__ACCESS_BITS | _PAGE_PL_0 | _PAGE_AR_RX)
5038 diff --git a/arch/ia64/include/asm/spinlock.h b/arch/ia64/include/asm/spinlock.h
5039 index 45698cd..e8e2dbc 100644
5040 --- a/arch/ia64/include/asm/spinlock.h
5041 +++ b/arch/ia64/include/asm/spinlock.h
5042 @@ -71,7 +71,7 @@ static __always_inline void __ticket_spin_unlock(arch_spinlock_t *lock)
5043 unsigned short *p = (unsigned short *)&lock->lock + 1, tmp;
5044
5045 asm volatile ("ld2.bias %0=[%1]" : "=r"(tmp) : "r"(p));
5046 - ACCESS_ONCE(*p) = (tmp + 2) & ~1;
5047 + ACCESS_ONCE_RW(*p) = (tmp + 2) & ~1;
5048 }
5049
5050 static __always_inline void __ticket_spin_unlock_wait(arch_spinlock_t *lock)
5051 diff --git a/arch/ia64/include/asm/uaccess.h b/arch/ia64/include/asm/uaccess.h
5052 index 449c8c0..18965fb 100644
5053 --- a/arch/ia64/include/asm/uaccess.h
5054 +++ b/arch/ia64/include/asm/uaccess.h
5055 @@ -240,12 +240,24 @@ extern unsigned long __must_check __copy_user (void __user *to, const void __use
5056 static inline unsigned long
5057 __copy_to_user (void __user *to, const void *from, unsigned long count)
5058 {
5059 + if (count > INT_MAX)
5060 + return count;
5061 +
5062 + if (!__builtin_constant_p(count))
5063 + check_object_size(from, count, true);
5064 +
5065 return __copy_user(to, (__force void __user *) from, count);
5066 }
5067
5068 static inline unsigned long
5069 __copy_from_user (void *to, const void __user *from, unsigned long count)
5070 {
5071 + if (count > INT_MAX)
5072 + return count;
5073 +
5074 + if (!__builtin_constant_p(count))
5075 + check_object_size(to, count, false);
5076 +
5077 return __copy_user((__force void __user *) to, from, count);
5078 }
5079
5080 @@ -255,10 +267,13 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5081 ({ \
5082 void __user *__cu_to = (to); \
5083 const void *__cu_from = (from); \
5084 - long __cu_len = (n); \
5085 + unsigned long __cu_len = (n); \
5086 \
5087 - if (__access_ok(__cu_to, __cu_len, get_fs())) \
5088 + if (__cu_len <= INT_MAX && __access_ok(__cu_to, __cu_len, get_fs())) { \
5089 + if (!__builtin_constant_p(n)) \
5090 + check_object_size(__cu_from, __cu_len, true); \
5091 __cu_len = __copy_user(__cu_to, (__force void __user *) __cu_from, __cu_len); \
5092 + } \
5093 __cu_len; \
5094 })
5095
5096 @@ -266,11 +281,14 @@ __copy_from_user (void *to, const void __user *from, unsigned long count)
5097 ({ \
5098 void *__cu_to = (to); \
5099 const void __user *__cu_from = (from); \
5100 - long __cu_len = (n); \
5101 + unsigned long __cu_len = (n); \
5102 \
5103 __chk_user_ptr(__cu_from); \
5104 - if (__access_ok(__cu_from, __cu_len, get_fs())) \
5105 + if (__cu_len <= INT_MAX && __access_ok(__cu_from, __cu_len, get_fs())) { \
5106 + if (!__builtin_constant_p(n)) \
5107 + check_object_size(__cu_to, __cu_len, false); \
5108 __cu_len = __copy_user((__force void __user *) __cu_to, __cu_from, __cu_len); \
5109 + } \
5110 __cu_len; \
5111 })
5112
5113 diff --git a/arch/ia64/kernel/module.c b/arch/ia64/kernel/module.c
5114 index 24603be..948052d 100644
5115 --- a/arch/ia64/kernel/module.c
5116 +++ b/arch/ia64/kernel/module.c
5117 @@ -307,8 +307,7 @@ plt_target (struct plt_entry *plt)
5118 void
5119 module_free (struct module *mod, void *module_region)
5120 {
5121 - if (mod && mod->arch.init_unw_table &&
5122 - module_region == mod->module_init) {
5123 + if (mod && mod->arch.init_unw_table && module_region == mod->module_init_rx) {
5124 unw_remove_unwind_table(mod->arch.init_unw_table);
5125 mod->arch.init_unw_table = NULL;
5126 }
5127 @@ -494,15 +493,39 @@ module_frob_arch_sections (Elf_Ehdr *ehdr, Elf_Shdr *sechdrs, char *secstrings,
5128 }
5129
5130 static inline int
5131 +in_init_rx (const struct module *mod, uint64_t addr)
5132 +{
5133 + return addr - (uint64_t) mod->module_init_rx < mod->init_size_rx;
5134 +}
5135 +
5136 +static inline int
5137 +in_init_rw (const struct module *mod, uint64_t addr)
5138 +{
5139 + return addr - (uint64_t) mod->module_init_rw < mod->init_size_rw;
5140 +}
5141 +
5142 +static inline int
5143 in_init (const struct module *mod, uint64_t addr)
5144 {
5145 - return addr - (uint64_t) mod->module_init < mod->init_size;
5146 + return in_init_rx(mod, addr) || in_init_rw(mod, addr);
5147 +}
5148 +
5149 +static inline int
5150 +in_core_rx (const struct module *mod, uint64_t addr)
5151 +{
5152 + return addr - (uint64_t) mod->module_core_rx < mod->core_size_rx;
5153 +}
5154 +
5155 +static inline int
5156 +in_core_rw (const struct module *mod, uint64_t addr)
5157 +{
5158 + return addr - (uint64_t) mod->module_core_rw < mod->core_size_rw;
5159 }
5160
5161 static inline int
5162 in_core (const struct module *mod, uint64_t addr)
5163 {
5164 - return addr - (uint64_t) mod->module_core < mod->core_size;
5165 + return in_core_rx(mod, addr) || in_core_rw(mod, addr);
5166 }
5167
5168 static inline int
5169 @@ -685,7 +708,14 @@ do_reloc (struct module *mod, uint8_t r_type, Elf64_Sym *sym, uint64_t addend,
5170 break;
5171
5172 case RV_BDREL:
5173 - val -= (uint64_t) (in_init(mod, val) ? mod->module_init : mod->module_core);
5174 + if (in_init_rx(mod, val))
5175 + val -= (uint64_t) mod->module_init_rx;
5176 + else if (in_init_rw(mod, val))
5177 + val -= (uint64_t) mod->module_init_rw;
5178 + else if (in_core_rx(mod, val))
5179 + val -= (uint64_t) mod->module_core_rx;
5180 + else if (in_core_rw(mod, val))
5181 + val -= (uint64_t) mod->module_core_rw;
5182 break;
5183
5184 case RV_LTV:
5185 @@ -820,15 +850,15 @@ apply_relocate_add (Elf64_Shdr *sechdrs, const char *strtab, unsigned int symind
5186 * addresses have been selected...
5187 */
5188 uint64_t gp;
5189 - if (mod->core_size > MAX_LTOFF)
5190 + if (mod->core_size_rx + mod->core_size_rw > MAX_LTOFF)
5191 /*
5192 * This takes advantage of fact that SHF_ARCH_SMALL gets allocated
5193 * at the end of the module.
5194 */
5195 - gp = mod->core_size - MAX_LTOFF / 2;
5196 + gp = mod->core_size_rx + mod->core_size_rw - MAX_LTOFF / 2;
5197 else
5198 - gp = mod->core_size / 2;
5199 - gp = (uint64_t) mod->module_core + ((gp + 7) & -8);
5200 + gp = (mod->core_size_rx + mod->core_size_rw) / 2;
5201 + gp = (uint64_t) mod->module_core_rx + ((gp + 7) & -8);
5202 mod->arch.gp = gp;
5203 DEBUGP("%s: placing gp at 0x%lx\n", __func__, gp);
5204 }
5205 diff --git a/arch/ia64/kernel/palinfo.c b/arch/ia64/kernel/palinfo.c
5206 index ab33328..f39506c 100644
5207 --- a/arch/ia64/kernel/palinfo.c
5208 +++ b/arch/ia64/kernel/palinfo.c
5209 @@ -980,7 +980,7 @@ static int palinfo_cpu_callback(struct notifier_block *nfb,
5210 return NOTIFY_OK;
5211 }
5212
5213 -static struct notifier_block __refdata palinfo_cpu_notifier =
5214 +static struct notifier_block palinfo_cpu_notifier =
5215 {
5216 .notifier_call = palinfo_cpu_callback,
5217 .priority = 0,
5218 diff --git a/arch/ia64/kernel/sys_ia64.c b/arch/ia64/kernel/sys_ia64.c
5219 index 41e33f8..65180b2a 100644
5220 --- a/arch/ia64/kernel/sys_ia64.c
5221 +++ b/arch/ia64/kernel/sys_ia64.c
5222 @@ -28,6 +28,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5223 unsigned long align_mask = 0;
5224 struct mm_struct *mm = current->mm;
5225 struct vm_unmapped_area_info info;
5226 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
5227
5228 if (len > RGN_MAP_LIMIT)
5229 return -ENOMEM;
5230 @@ -43,6 +44,13 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5231 if (REGION_NUMBER(addr) == RGN_HPAGE)
5232 addr = 0;
5233 #endif
5234 +
5235 +#ifdef CONFIG_PAX_RANDMMAP
5236 + if (mm->pax_flags & MF_PAX_RANDMMAP)
5237 + addr = mm->free_area_cache;
5238 + else
5239 +#endif
5240 +
5241 if (!addr)
5242 addr = TASK_UNMAPPED_BASE;
5243
5244 @@ -61,6 +69,7 @@ arch_get_unmapped_area (struct file *filp, unsigned long addr, unsigned long len
5245 info.high_limit = TASK_SIZE;
5246 info.align_mask = align_mask;
5247 info.align_offset = 0;
5248 + info.threadstack_offset = offset;
5249 return vm_unmapped_area(&info);
5250 }
5251
5252 diff --git a/arch/ia64/kernel/vmlinux.lds.S b/arch/ia64/kernel/vmlinux.lds.S
5253 index 0ccb28f..8992469 100644
5254 --- a/arch/ia64/kernel/vmlinux.lds.S
5255 +++ b/arch/ia64/kernel/vmlinux.lds.S
5256 @@ -198,7 +198,7 @@ SECTIONS {
5257 /* Per-cpu data: */
5258 . = ALIGN(PERCPU_PAGE_SIZE);
5259 PERCPU_VADDR(SMP_CACHE_BYTES, PERCPU_ADDR, :percpu)
5260 - __phys_per_cpu_start = __per_cpu_load;
5261 + __phys_per_cpu_start = per_cpu_load;
5262 /*
5263 * ensure percpu data fits
5264 * into percpu page size
5265 diff --git a/arch/ia64/mm/fault.c b/arch/ia64/mm/fault.c
5266 index 7225dad..2a7c8256 100644
5267 --- a/arch/ia64/mm/fault.c
5268 +++ b/arch/ia64/mm/fault.c
5269 @@ -72,6 +72,23 @@ mapped_kernel_page_is_present (unsigned long address)
5270 return pte_present(pte);
5271 }
5272
5273 +#ifdef CONFIG_PAX_PAGEEXEC
5274 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
5275 +{
5276 + unsigned long i;
5277 +
5278 + printk(KERN_ERR "PAX: bytes at PC: ");
5279 + for (i = 0; i < 8; i++) {
5280 + unsigned int c;
5281 + if (get_user(c, (unsigned int *)pc+i))
5282 + printk(KERN_CONT "???????? ");
5283 + else
5284 + printk(KERN_CONT "%08x ", c);
5285 + }
5286 + printk("\n");
5287 +}
5288 +#endif
5289 +
5290 # define VM_READ_BIT 0
5291 # define VM_WRITE_BIT 1
5292 # define VM_EXEC_BIT 2
5293 @@ -151,8 +168,21 @@ retry:
5294 if (((isr >> IA64_ISR_R_BIT) & 1UL) && (!(vma->vm_flags & (VM_READ | VM_WRITE))))
5295 goto bad_area;
5296
5297 - if ((vma->vm_flags & mask) != mask)
5298 + if ((vma->vm_flags & mask) != mask) {
5299 +
5300 +#ifdef CONFIG_PAX_PAGEEXEC
5301 + if (!(vma->vm_flags & VM_EXEC) && (mask & VM_EXEC)) {
5302 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || address != regs->cr_iip)
5303 + goto bad_area;
5304 +
5305 + up_read(&mm->mmap_sem);
5306 + pax_report_fault(regs, (void *)regs->cr_iip, (void *)regs->r12);
5307 + do_group_exit(SIGKILL);
5308 + }
5309 +#endif
5310 +
5311 goto bad_area;
5312 + }
5313
5314 /*
5315 * If for any reason at all we couldn't handle the fault, make
5316 diff --git a/arch/ia64/mm/hugetlbpage.c b/arch/ia64/mm/hugetlbpage.c
5317 index 68232db..6ca80af 100644
5318 --- a/arch/ia64/mm/hugetlbpage.c
5319 +++ b/arch/ia64/mm/hugetlbpage.c
5320 @@ -154,6 +154,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5321 unsigned long pgoff, unsigned long flags)
5322 {
5323 struct vm_unmapped_area_info info;
5324 + unsigned long offset = gr_rand_threadstack_offset(current->mm, file, flags);
5325
5326 if (len > RGN_MAP_LIMIT)
5327 return -ENOMEM;
5328 @@ -177,6 +178,7 @@ unsigned long hugetlb_get_unmapped_area(struct file *file, unsigned long addr, u
5329 info.high_limit = HPAGE_REGION_BASE + RGN_MAP_LIMIT;
5330 info.align_mask = PAGE_MASK & (HPAGE_SIZE - 1);
5331 info.align_offset = 0;
5332 + info.threadstack_offset = offset;
5333 return vm_unmapped_area(&info);
5334 }
5335
5336 diff --git a/arch/ia64/mm/init.c b/arch/ia64/mm/init.c
5337 index 88504ab..cbb6c9f 100644
5338 --- a/arch/ia64/mm/init.c
5339 +++ b/arch/ia64/mm/init.c
5340 @@ -120,6 +120,19 @@ ia64_init_addr_space (void)
5341 vma->vm_start = current->thread.rbs_bot & PAGE_MASK;
5342 vma->vm_end = vma->vm_start + PAGE_SIZE;
5343 vma->vm_flags = VM_DATA_DEFAULT_FLAGS|VM_GROWSUP|VM_ACCOUNT;
5344 +
5345 +#ifdef CONFIG_PAX_PAGEEXEC
5346 + if (current->mm->pax_flags & MF_PAX_PAGEEXEC) {
5347 + vma->vm_flags &= ~VM_EXEC;
5348 +
5349 +#ifdef CONFIG_PAX_MPROTECT
5350 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
5351 + vma->vm_flags &= ~VM_MAYEXEC;
5352 +#endif
5353 +
5354 + }
5355 +#endif
5356 +
5357 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
5358 down_write(&current->mm->mmap_sem);
5359 if (insert_vm_struct(current->mm, vma)) {
5360 diff --git a/arch/m32r/include/asm/cache.h b/arch/m32r/include/asm/cache.h
5361 index 40b3ee9..8c2c112 100644
5362 --- a/arch/m32r/include/asm/cache.h
5363 +++ b/arch/m32r/include/asm/cache.h
5364 @@ -1,8 +1,10 @@
5365 #ifndef _ASM_M32R_CACHE_H
5366 #define _ASM_M32R_CACHE_H
5367
5368 +#include <linux/const.h>
5369 +
5370 /* L1 cache line size */
5371 #define L1_CACHE_SHIFT 4
5372 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5373 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5374
5375 #endif /* _ASM_M32R_CACHE_H */
5376 diff --git a/arch/m32r/lib/usercopy.c b/arch/m32r/lib/usercopy.c
5377 index 82abd15..d95ae5d 100644
5378 --- a/arch/m32r/lib/usercopy.c
5379 +++ b/arch/m32r/lib/usercopy.c
5380 @@ -14,6 +14,9 @@
5381 unsigned long
5382 __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5383 {
5384 + if ((long)n < 0)
5385 + return n;
5386 +
5387 prefetch(from);
5388 if (access_ok(VERIFY_WRITE, to, n))
5389 __copy_user(to,from,n);
5390 @@ -23,6 +26,9 @@ __generic_copy_to_user(void __user *to, const void *from, unsigned long n)
5391 unsigned long
5392 __generic_copy_from_user(void *to, const void __user *from, unsigned long n)
5393 {
5394 + if ((long)n < 0)
5395 + return n;
5396 +
5397 prefetchw(to);
5398 if (access_ok(VERIFY_READ, from, n))
5399 __copy_user_zeroing(to,from,n);
5400 diff --git a/arch/m68k/include/asm/cache.h b/arch/m68k/include/asm/cache.h
5401 index 0395c51..5f26031 100644
5402 --- a/arch/m68k/include/asm/cache.h
5403 +++ b/arch/m68k/include/asm/cache.h
5404 @@ -4,9 +4,11 @@
5405 #ifndef __ARCH_M68K_CACHE_H
5406 #define __ARCH_M68K_CACHE_H
5407
5408 +#include <linux/const.h>
5409 +
5410 /* bytes per L1 cache line */
5411 #define L1_CACHE_SHIFT 4
5412 -#define L1_CACHE_BYTES (1<< L1_CACHE_SHIFT)
5413 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5414
5415 #define ARCH_DMA_MINALIGN L1_CACHE_BYTES
5416
5417 diff --git a/arch/metag/mm/hugetlbpage.c b/arch/metag/mm/hugetlbpage.c
5418 index 0424315..defcca9 100644
5419 --- a/arch/metag/mm/hugetlbpage.c
5420 +++ b/arch/metag/mm/hugetlbpage.c
5421 @@ -205,6 +205,7 @@ hugetlb_get_unmapped_area_new_pmd(unsigned long len)
5422 info.high_limit = TASK_SIZE;
5423 info.align_mask = PAGE_MASK & HUGEPT_MASK;
5424 info.align_offset = 0;
5425 + info.threadstack_offset = 0;
5426 return vm_unmapped_area(&info);
5427 }
5428
5429 diff --git a/arch/microblaze/include/asm/cache.h b/arch/microblaze/include/asm/cache.h
5430 index 4efe96a..60e8699 100644
5431 --- a/arch/microblaze/include/asm/cache.h
5432 +++ b/arch/microblaze/include/asm/cache.h
5433 @@ -13,11 +13,12 @@
5434 #ifndef _ASM_MICROBLAZE_CACHE_H
5435 #define _ASM_MICROBLAZE_CACHE_H
5436
5437 +#include <linux/const.h>
5438 #include <asm/registers.h>
5439
5440 #define L1_CACHE_SHIFT 5
5441 /* word-granular cache in microblaze */
5442 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
5443 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
5444
5445 #define SMP_CACHE_BYTES L1_CACHE_BYTES
5446
5447 diff --git a/arch/mips/Kconfig b/arch/mips/Kconfig
5448 index 650de39..6982b02 100644
5449 --- a/arch/mips/Kconfig
5450 +++ b/arch/mips/Kconfig
5451 @@ -2268,6 +2268,7 @@ source "kernel/Kconfig.preempt"
5452
5453 config KEXEC
5454 bool "Kexec system call"
5455 + depends on !GRKERNSEC_KMEM
5456 help
5457 kexec is a system call that implements the ability to shutdown your
5458 current kernel, and to start another kernel. It is like a reboot
5459 diff --git a/arch/mips/include/asm/atomic.h b/arch/mips/include/asm/atomic.h
5460 index 7eed2f2..c4e385d 100644
5461 --- a/arch/mips/include/asm/atomic.h
5462 +++ b/arch/mips/include/asm/atomic.h
5463 @@ -21,15 +21,39 @@
5464 #include <asm/cmpxchg.h>
5465 #include <asm/war.h>
5466
5467 +#ifdef CONFIG_GENERIC_ATOMIC64
5468 +#include <asm-generic/atomic64.h>
5469 +#endif
5470 +
5471 #define ATOMIC_INIT(i) { (i) }
5472
5473 +#ifdef CONFIG_64BIT
5474 +#define _ASM_EXTABLE(from, to) \
5475 +" .section __ex_table,\"a\"\n" \
5476 +" .dword " #from ", " #to"\n" \
5477 +" .previous\n"
5478 +#else
5479 +#define _ASM_EXTABLE(from, to) \
5480 +" .section __ex_table,\"a\"\n" \
5481 +" .word " #from ", " #to"\n" \
5482 +" .previous\n"
5483 +#endif
5484 +
5485 /*
5486 * atomic_read - read atomic variable
5487 * @v: pointer of type atomic_t
5488 *
5489 * Atomically reads the value of @v.
5490 */
5491 -#define atomic_read(v) (*(volatile int *)&(v)->counter)
5492 +static inline int atomic_read(const atomic_t *v)
5493 +{
5494 + return (*(volatile const int *) &v->counter);
5495 +}
5496 +
5497 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
5498 +{
5499 + return (*(volatile const int *) &v->counter);
5500 +}
5501
5502 /*
5503 * atomic_set - set atomic variable
5504 @@ -38,7 +62,15 @@
5505 *
5506 * Atomically sets the value of @v to @i.
5507 */
5508 -#define atomic_set(v, i) ((v)->counter = (i))
5509 +static inline void atomic_set(atomic_t *v, int i)
5510 +{
5511 + v->counter = i;
5512 +}
5513 +
5514 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
5515 +{
5516 + v->counter = i;
5517 +}
5518
5519 /*
5520 * atomic_add - add integer to atomic variable
5521 @@ -47,7 +79,67 @@
5522 *
5523 * Atomically adds @i to @v.
5524 */
5525 -static __inline__ void atomic_add(int i, atomic_t * v)
5526 +static __inline__ void atomic_add(int i, atomic_t *v)
5527 +{
5528 + int temp;
5529 +
5530 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5531 + __asm__ __volatile__(
5532 + " .set mips3 \n"
5533 + "1: ll %0, %1 # atomic_add \n"
5534 +#ifdef CONFIG_PAX_REFCOUNT
5535 + /* Exception on overflow. */
5536 + "2: add %0, %2 \n"
5537 +#else
5538 + " addu %0, %2 \n"
5539 +#endif
5540 + " sc %0, %1 \n"
5541 + " beqzl %0, 1b \n"
5542 +#ifdef CONFIG_PAX_REFCOUNT
5543 + "3: \n"
5544 + _ASM_EXTABLE(2b, 3b)
5545 +#endif
5546 + " .set mips0 \n"
5547 + : "=&r" (temp), "+m" (v->counter)
5548 + : "Ir" (i));
5549 + } else if (kernel_uses_llsc) {
5550 + __asm__ __volatile__(
5551 + " .set mips3 \n"
5552 + "1: ll %0, %1 # atomic_add \n"
5553 +#ifdef CONFIG_PAX_REFCOUNT
5554 + /* Exception on overflow. */
5555 + "2: add %0, %2 \n"
5556 +#else
5557 + " addu %0, %2 \n"
5558 +#endif
5559 + " sc %0, %1 \n"
5560 + " beqz %0, 1b \n"
5561 +#ifdef CONFIG_PAX_REFCOUNT
5562 + "3: \n"
5563 + _ASM_EXTABLE(2b, 3b)
5564 +#endif
5565 + " .set mips0 \n"
5566 + : "=&r" (temp), "+m" (v->counter)
5567 + : "Ir" (i));
5568 + } else {
5569 + unsigned long flags;
5570 +
5571 + raw_local_irq_save(flags);
5572 + __asm__ __volatile__(
5573 +#ifdef CONFIG_PAX_REFCOUNT
5574 + /* Exception on overflow. */
5575 + "1: add %0, %1 \n"
5576 + "2: \n"
5577 + _ASM_EXTABLE(1b, 2b)
5578 +#else
5579 + " addu %0, %1 \n"
5580 +#endif
5581 + : "+r" (v->counter) : "Ir" (i));
5582 + raw_local_irq_restore(flags);
5583 + }
5584 +}
5585 +
5586 +static __inline__ void atomic_add_unchecked(int i, atomic_unchecked_t *v)
5587 {
5588 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5589 int temp;
5590 @@ -90,7 +182,67 @@ static __inline__ void atomic_add(int i, atomic_t * v)
5591 *
5592 * Atomically subtracts @i from @v.
5593 */
5594 -static __inline__ void atomic_sub(int i, atomic_t * v)
5595 +static __inline__ void atomic_sub(int i, atomic_t *v)
5596 +{
5597 + int temp;
5598 +
5599 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5600 + __asm__ __volatile__(
5601 + " .set mips3 \n"
5602 + "1: ll %0, %1 # atomic64_sub \n"
5603 +#ifdef CONFIG_PAX_REFCOUNT
5604 + /* Exception on overflow. */
5605 + "2: sub %0, %2 \n"
5606 +#else
5607 + " subu %0, %2 \n"
5608 +#endif
5609 + " sc %0, %1 \n"
5610 + " beqzl %0, 1b \n"
5611 +#ifdef CONFIG_PAX_REFCOUNT
5612 + "3: \n"
5613 + _ASM_EXTABLE(2b, 3b)
5614 +#endif
5615 + " .set mips0 \n"
5616 + : "=&r" (temp), "+m" (v->counter)
5617 + : "Ir" (i));
5618 + } else if (kernel_uses_llsc) {
5619 + __asm__ __volatile__(
5620 + " .set mips3 \n"
5621 + "1: ll %0, %1 # atomic64_sub \n"
5622 +#ifdef CONFIG_PAX_REFCOUNT
5623 + /* Exception on overflow. */
5624 + "2: sub %0, %2 \n"
5625 +#else
5626 + " subu %0, %2 \n"
5627 +#endif
5628 + " sc %0, %1 \n"
5629 + " beqz %0, 1b \n"
5630 +#ifdef CONFIG_PAX_REFCOUNT
5631 + "3: \n"
5632 + _ASM_EXTABLE(2b, 3b)
5633 +#endif
5634 + " .set mips0 \n"
5635 + : "=&r" (temp), "+m" (v->counter)
5636 + : "Ir" (i));
5637 + } else {
5638 + unsigned long flags;
5639 +
5640 + raw_local_irq_save(flags);
5641 + __asm__ __volatile__(
5642 +#ifdef CONFIG_PAX_REFCOUNT
5643 + /* Exception on overflow. */
5644 + "1: sub %0, %1 \n"
5645 + "2: \n"
5646 + _ASM_EXTABLE(1b, 2b)
5647 +#else
5648 + " subu %0, %1 \n"
5649 +#endif
5650 + : "+r" (v->counter) : "Ir" (i));
5651 + raw_local_irq_restore(flags);
5652 + }
5653 +}
5654 +
5655 +static __inline__ void atomic_sub_unchecked(long i, atomic_unchecked_t *v)
5656 {
5657 if (kernel_uses_llsc && R10000_LLSC_WAR) {
5658 int temp;
5659 @@ -129,7 +281,93 @@ static __inline__ void atomic_sub(int i, atomic_t * v)
5660 /*
5661 * Same as above, but return the result value
5662 */
5663 -static __inline__ int atomic_add_return(int i, atomic_t * v)
5664 +static __inline__ int atomic_add_return(int i, atomic_t *v)
5665 +{
5666 + int result;
5667 + int temp;
5668 +
5669 + smp_mb__before_llsc();
5670 +
5671 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5672 + __asm__ __volatile__(
5673 + " .set mips3 \n"
5674 + "1: ll %1, %2 # atomic_add_return \n"
5675 +#ifdef CONFIG_PAX_REFCOUNT
5676 + "2: add %0, %1, %3 \n"
5677 +#else
5678 + " addu %0, %1, %3 \n"
5679 +#endif
5680 + " sc %0, %2 \n"
5681 + " beqzl %0, 1b \n"
5682 +#ifdef CONFIG_PAX_REFCOUNT
5683 + " b 4f \n"
5684 + " .set noreorder \n"
5685 + "3: b 5f \n"
5686 + " move %0, %1 \n"
5687 + " .set reorder \n"
5688 + _ASM_EXTABLE(2b, 3b)
5689 +#endif
5690 + "4: addu %0, %1, %3 \n"
5691 +#ifdef CONFIG_PAX_REFCOUNT
5692 + "5: \n"
5693 +#endif
5694 + " .set mips0 \n"
5695 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5696 + : "Ir" (i));
5697 + } else if (kernel_uses_llsc) {
5698 + __asm__ __volatile__(
5699 + " .set mips3 \n"
5700 + "1: ll %1, %2 # atomic_add_return \n"
5701 +#ifdef CONFIG_PAX_REFCOUNT
5702 + "2: add %0, %1, %3 \n"
5703 +#else
5704 + " addu %0, %1, %3 \n"
5705 +#endif
5706 + " sc %0, %2 \n"
5707 + " bnez %0, 4f \n"
5708 + " b 1b \n"
5709 +#ifdef CONFIG_PAX_REFCOUNT
5710 + " .set noreorder \n"
5711 + "3: b 5f \n"
5712 + " move %0, %1 \n"
5713 + " .set reorder \n"
5714 + _ASM_EXTABLE(2b, 3b)
5715 +#endif
5716 + "4: addu %0, %1, %3 \n"
5717 +#ifdef CONFIG_PAX_REFCOUNT
5718 + "5: \n"
5719 +#endif
5720 + " .set mips0 \n"
5721 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5722 + : "Ir" (i));
5723 + } else {
5724 + unsigned long flags;
5725 +
5726 + raw_local_irq_save(flags);
5727 + __asm__ __volatile__(
5728 + " lw %0, %1 \n"
5729 +#ifdef CONFIG_PAX_REFCOUNT
5730 + /* Exception on overflow. */
5731 + "1: add %0, %2 \n"
5732 +#else
5733 + " addu %0, %2 \n"
5734 +#endif
5735 + " sw %0, %1 \n"
5736 +#ifdef CONFIG_PAX_REFCOUNT
5737 + /* Note: Dest reg is not modified on overflow */
5738 + "2: \n"
5739 + _ASM_EXTABLE(1b, 2b)
5740 +#endif
5741 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5742 + raw_local_irq_restore(flags);
5743 + }
5744 +
5745 + smp_llsc_mb();
5746 +
5747 + return result;
5748 +}
5749 +
5750 +static __inline__ int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
5751 {
5752 int result;
5753
5754 @@ -178,7 +416,93 @@ static __inline__ int atomic_add_return(int i, atomic_t * v)
5755 return result;
5756 }
5757
5758 -static __inline__ int atomic_sub_return(int i, atomic_t * v)
5759 +static __inline__ int atomic_sub_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_sub_return \n"
5770 +#ifdef CONFIG_PAX_REFCOUNT
5771 + "2: sub %0, %1, %3 \n"
5772 +#else
5773 + " subu %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: subu %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), "m" (v->counter)
5792 + : "memory");
5793 + } else if (kernel_uses_llsc) {
5794 + __asm__ __volatile__(
5795 + " .set mips3 \n"
5796 + "1: ll %1, %2 # atomic_sub_return \n"
5797 +#ifdef CONFIG_PAX_REFCOUNT
5798 + "2: sub %0, %1, %3 \n"
5799 +#else
5800 + " subu %0, %1, %3 \n"
5801 +#endif
5802 + " sc %0, %2 \n"
5803 + " bnez %0, 4f \n"
5804 + " b 1b \n"
5805 +#ifdef CONFIG_PAX_REFCOUNT
5806 + " .set noreorder \n"
5807 + "3: b 5f \n"
5808 + " move %0, %1 \n"
5809 + " .set reorder \n"
5810 + _ASM_EXTABLE(2b, 3b)
5811 +#endif
5812 + "4: subu %0, %1, %3 \n"
5813 +#ifdef CONFIG_PAX_REFCOUNT
5814 + "5: \n"
5815 +#endif
5816 + " .set mips0 \n"
5817 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
5818 + : "Ir" (i));
5819 + } else {
5820 + unsigned long flags;
5821 +
5822 + raw_local_irq_save(flags);
5823 + __asm__ __volatile__(
5824 + " lw %0, %1 \n"
5825 +#ifdef CONFIG_PAX_REFCOUNT
5826 + /* Exception on overflow. */
5827 + "1: sub %0, %2 \n"
5828 +#else
5829 + " subu %0, %2 \n"
5830 +#endif
5831 + " sw %0, %1 \n"
5832 +#ifdef CONFIG_PAX_REFCOUNT
5833 + /* Note: Dest reg is not modified on overflow */
5834 + "2: \n"
5835 + _ASM_EXTABLE(1b, 2b)
5836 +#endif
5837 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
5838 + raw_local_irq_restore(flags);
5839 + }
5840 +
5841 + smp_llsc_mb();
5842 +
5843 + return result;
5844 +}
5845 +static __inline__ int atomic_sub_return_unchecked(int i, atomic_unchecked_t *v)
5846 {
5847 int result;
5848
5849 @@ -238,7 +562,7 @@ static __inline__ int atomic_sub_return(int i, atomic_t * v)
5850 * Atomically test @v and subtract @i if @v is greater or equal than @i.
5851 * The function returns the old value of @v minus @i.
5852 */
5853 -static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5854 +static __inline__ int atomic_sub_if_positive(int i, atomic_t *v)
5855 {
5856 int result;
5857
5858 @@ -295,8 +619,26 @@ static __inline__ int atomic_sub_if_positive(int i, atomic_t * v)
5859 return result;
5860 }
5861
5862 -#define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
5863 -#define atomic_xchg(v, new) (xchg(&((v)->counter), (new)))
5864 +static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
5865 +{
5866 + return cmpxchg(&v->counter, old, new);
5867 +}
5868 +
5869 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old,
5870 + int new)
5871 +{
5872 + return cmpxchg(&(v->counter), old, new);
5873 +}
5874 +
5875 +static inline int atomic_xchg(atomic_t *v, int new)
5876 +{
5877 + return xchg(&v->counter, new);
5878 +}
5879 +
5880 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
5881 +{
5882 + return xchg(&(v->counter), new);
5883 +}
5884
5885 /**
5886 * __atomic_add_unless - add unless the number is a given value
5887 @@ -324,6 +666,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5888
5889 #define atomic_dec_return(v) atomic_sub_return(1, (v))
5890 #define atomic_inc_return(v) atomic_add_return(1, (v))
5891 +static __inline__ int atomic_inc_return_unchecked(atomic_unchecked_t *v)
5892 +{
5893 + return atomic_add_return_unchecked(1, v);
5894 +}
5895
5896 /*
5897 * atomic_sub_and_test - subtract value from variable and test result
5898 @@ -345,6 +691,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5899 * other cases.
5900 */
5901 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
5902 +static __inline__ int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
5903 +{
5904 + return atomic_add_return_unchecked(1, v) == 0;
5905 +}
5906
5907 /*
5908 * atomic_dec_and_test - decrement by 1 and test
5909 @@ -369,6 +719,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5910 * Atomically increments @v by 1.
5911 */
5912 #define atomic_inc(v) atomic_add(1, (v))
5913 +static __inline__ void atomic_inc_unchecked(atomic_unchecked_t *v)
5914 +{
5915 + atomic_add_unchecked(1, v);
5916 +}
5917
5918 /*
5919 * atomic_dec - decrement and test
5920 @@ -377,6 +731,10 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5921 * Atomically decrements @v by 1.
5922 */
5923 #define atomic_dec(v) atomic_sub(1, (v))
5924 +static __inline__ void atomic_dec_unchecked(atomic_unchecked_t *v)
5925 +{
5926 + atomic_sub_unchecked(1, v);
5927 +}
5928
5929 /*
5930 * atomic_add_negative - add and test if negative
5931 @@ -398,14 +756,30 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5932 * @v: pointer of type atomic64_t
5933 *
5934 */
5935 -#define atomic64_read(v) (*(volatile long *)&(v)->counter)
5936 +static inline long atomic64_read(const atomic64_t *v)
5937 +{
5938 + return (*(volatile const long *) &v->counter);
5939 +}
5940 +
5941 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
5942 +{
5943 + return (*(volatile const long *) &v->counter);
5944 +}
5945
5946 /*
5947 * atomic64_set - set atomic variable
5948 * @v: pointer of type atomic64_t
5949 * @i: required value
5950 */
5951 -#define atomic64_set(v, i) ((v)->counter = (i))
5952 +static inline void atomic64_set(atomic64_t *v, long i)
5953 +{
5954 + v->counter = i;
5955 +}
5956 +
5957 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
5958 +{
5959 + v->counter = i;
5960 +}
5961
5962 /*
5963 * atomic64_add - add integer to atomic variable
5964 @@ -414,7 +788,66 @@ static __inline__ int __atomic_add_unless(atomic_t *v, int a, int u)
5965 *
5966 * Atomically adds @i to @v.
5967 */
5968 -static __inline__ void atomic64_add(long i, atomic64_t * v)
5969 +static __inline__ void atomic64_add(long i, atomic64_t *v)
5970 +{
5971 + long temp;
5972 +
5973 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
5974 + __asm__ __volatile__(
5975 + " .set mips3 \n"
5976 + "1: lld %0, %1 # atomic64_add \n"
5977 +#ifdef CONFIG_PAX_REFCOUNT
5978 + /* Exception on overflow. */
5979 + "2: dadd %0, %2 \n"
5980 +#else
5981 + " daddu %0, %2 \n"
5982 +#endif
5983 + " scd %0, %1 \n"
5984 + " beqzl %0, 1b \n"
5985 +#ifdef CONFIG_PAX_REFCOUNT
5986 + "3: \n"
5987 + _ASM_EXTABLE(2b, 3b)
5988 +#endif
5989 + " .set mips0 \n"
5990 + : "=&r" (temp), "+m" (v->counter)
5991 + : "Ir" (i));
5992 + } else if (kernel_uses_llsc) {
5993 + __asm__ __volatile__(
5994 + " .set mips3 \n"
5995 + "1: lld %0, %1 # atomic64_add \n"
5996 +#ifdef CONFIG_PAX_REFCOUNT
5997 + /* Exception on overflow. */
5998 + "2: dadd %0, %2 \n"
5999 +#else
6000 + " daddu %0, %2 \n"
6001 +#endif
6002 + " scd %0, %1 \n"
6003 + " beqz %0, 1b \n"
6004 +#ifdef CONFIG_PAX_REFCOUNT
6005 + "3: \n"
6006 + _ASM_EXTABLE(2b, 3b)
6007 +#endif
6008 + " .set mips0 \n"
6009 + : "=&r" (temp), "+m" (v->counter)
6010 + : "Ir" (i));
6011 + } else {
6012 + unsigned long flags;
6013 +
6014 + raw_local_irq_save(flags);
6015 + __asm__ __volatile__(
6016 +#ifdef CONFIG_PAX_REFCOUNT
6017 + /* Exception on overflow. */
6018 + "1: dadd %0, %1 \n"
6019 + "2: \n"
6020 + _ASM_EXTABLE(1b, 2b)
6021 +#else
6022 + " daddu %0, %1 \n"
6023 +#endif
6024 + : "+r" (v->counter) : "Ir" (i));
6025 + raw_local_irq_restore(flags);
6026 + }
6027 +}
6028 +static __inline__ void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
6029 {
6030 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6031 long temp;
6032 @@ -457,7 +890,67 @@ static __inline__ void atomic64_add(long i, atomic64_t * v)
6033 *
6034 * Atomically subtracts @i from @v.
6035 */
6036 -static __inline__ void atomic64_sub(long i, atomic64_t * v)
6037 +static __inline__ void atomic64_sub(long i, atomic64_t *v)
6038 +{
6039 + long temp;
6040 +
6041 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6042 + __asm__ __volatile__(
6043 + " .set mips3 \n"
6044 + "1: lld %0, %1 # atomic64_sub \n"
6045 +#ifdef CONFIG_PAX_REFCOUNT
6046 + /* Exception on overflow. */
6047 + "2: dsub %0, %2 \n"
6048 +#else
6049 + " dsubu %0, %2 \n"
6050 +#endif
6051 + " scd %0, %1 \n"
6052 + " beqzl %0, 1b \n"
6053 +#ifdef CONFIG_PAX_REFCOUNT
6054 + "3: \n"
6055 + _ASM_EXTABLE(2b, 3b)
6056 +#endif
6057 + " .set mips0 \n"
6058 + : "=&r" (temp), "+m" (v->counter)
6059 + : "Ir" (i));
6060 + } else if (kernel_uses_llsc) {
6061 + __asm__ __volatile__(
6062 + " .set mips3 \n"
6063 + "1: lld %0, %1 # atomic64_sub \n"
6064 +#ifdef CONFIG_PAX_REFCOUNT
6065 + /* Exception on overflow. */
6066 + "2: dsub %0, %2 \n"
6067 +#else
6068 + " dsubu %0, %2 \n"
6069 +#endif
6070 + " scd %0, %1 \n"
6071 + " beqz %0, 1b \n"
6072 +#ifdef CONFIG_PAX_REFCOUNT
6073 + "3: \n"
6074 + _ASM_EXTABLE(2b, 3b)
6075 +#endif
6076 + " .set mips0 \n"
6077 + : "=&r" (temp), "+m" (v->counter)
6078 + : "Ir" (i));
6079 + } else {
6080 + unsigned long flags;
6081 +
6082 + raw_local_irq_save(flags);
6083 + __asm__ __volatile__(
6084 +#ifdef CONFIG_PAX_REFCOUNT
6085 + /* Exception on overflow. */
6086 + "1: dsub %0, %1 \n"
6087 + "2: \n"
6088 + _ASM_EXTABLE(1b, 2b)
6089 +#else
6090 + " dsubu %0, %1 \n"
6091 +#endif
6092 + : "+r" (v->counter) : "Ir" (i));
6093 + raw_local_irq_restore(flags);
6094 + }
6095 +}
6096 +
6097 +static __inline__ void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
6098 {
6099 if (kernel_uses_llsc && R10000_LLSC_WAR) {
6100 long temp;
6101 @@ -496,7 +989,93 @@ static __inline__ void atomic64_sub(long i, atomic64_t * v)
6102 /*
6103 * Same as above, but return the result value
6104 */
6105 -static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6106 +static __inline__ long atomic64_add_return(long i, atomic64_t *v)
6107 +{
6108 + long result;
6109 + long temp;
6110 +
6111 + smp_mb__before_llsc();
6112 +
6113 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6114 + __asm__ __volatile__(
6115 + " .set mips3 \n"
6116 + "1: lld %1, %2 # atomic64_add_return \n"
6117 +#ifdef CONFIG_PAX_REFCOUNT
6118 + "2: dadd %0, %1, %3 \n"
6119 +#else
6120 + " daddu %0, %1, %3 \n"
6121 +#endif
6122 + " scd %0, %2 \n"
6123 + " beqzl %0, 1b \n"
6124 +#ifdef CONFIG_PAX_REFCOUNT
6125 + " b 4f \n"
6126 + " .set noreorder \n"
6127 + "3: b 5f \n"
6128 + " move %0, %1 \n"
6129 + " .set reorder \n"
6130 + _ASM_EXTABLE(2b, 3b)
6131 +#endif
6132 + "4: daddu %0, %1, %3 \n"
6133 +#ifdef CONFIG_PAX_REFCOUNT
6134 + "5: \n"
6135 +#endif
6136 + " .set mips0 \n"
6137 + : "=&r" (result), "=&r" (temp), "+m" (v->counter)
6138 + : "Ir" (i));
6139 + } else if (kernel_uses_llsc) {
6140 + __asm__ __volatile__(
6141 + " .set mips3 \n"
6142 + "1: lld %1, %2 # atomic64_add_return \n"
6143 +#ifdef CONFIG_PAX_REFCOUNT
6144 + "2: dadd %0, %1, %3 \n"
6145 +#else
6146 + " daddu %0, %1, %3 \n"
6147 +#endif
6148 + " scd %0, %2 \n"
6149 + " bnez %0, 4f \n"
6150 + " b 1b \n"
6151 +#ifdef CONFIG_PAX_REFCOUNT
6152 + " .set noreorder \n"
6153 + "3: b 5f \n"
6154 + " move %0, %1 \n"
6155 + " .set reorder \n"
6156 + _ASM_EXTABLE(2b, 3b)
6157 +#endif
6158 + "4: daddu %0, %1, %3 \n"
6159 +#ifdef CONFIG_PAX_REFCOUNT
6160 + "5: \n"
6161 +#endif
6162 + " .set mips0 \n"
6163 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6164 + : "Ir" (i), "m" (v->counter)
6165 + : "memory");
6166 + } else {
6167 + unsigned long flags;
6168 +
6169 + raw_local_irq_save(flags);
6170 + __asm__ __volatile__(
6171 + " ld %0, %1 \n"
6172 +#ifdef CONFIG_PAX_REFCOUNT
6173 + /* Exception on overflow. */
6174 + "1: dadd %0, %2 \n"
6175 +#else
6176 + " daddu %0, %2 \n"
6177 +#endif
6178 + " sd %0, %1 \n"
6179 +#ifdef CONFIG_PAX_REFCOUNT
6180 + /* Note: Dest reg is not modified on overflow */
6181 + "2: \n"
6182 + _ASM_EXTABLE(1b, 2b)
6183 +#endif
6184 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6185 + raw_local_irq_restore(flags);
6186 + }
6187 +
6188 + smp_llsc_mb();
6189 +
6190 + return result;
6191 +}
6192 +static __inline__ long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
6193 {
6194 long result;
6195
6196 @@ -546,7 +1125,97 @@ static __inline__ long atomic64_add_return(long i, atomic64_t * v)
6197 return result;
6198 }
6199
6200 -static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6201 +static __inline__ long atomic64_sub_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 + long temp;
6210 +
6211 + __asm__ __volatile__(
6212 + " .set mips3 \n"
6213 + "1: lld %1, %2 # atomic64_sub_return \n"
6214 +#ifdef CONFIG_PAX_REFCOUNT
6215 + "2: dsub %0, %1, %3 \n"
6216 +#else
6217 + " dsubu %0, %1, %3 \n"
6218 +#endif
6219 + " scd %0, %2 \n"
6220 + " beqzl %0, 1b \n"
6221 +#ifdef CONFIG_PAX_REFCOUNT
6222 + " b 4f \n"
6223 + " .set noreorder \n"
6224 + "3: b 5f \n"
6225 + " move %0, %1 \n"
6226 + " .set reorder \n"
6227 + _ASM_EXTABLE(2b, 3b)
6228 +#endif
6229 + "4: dsubu %0, %1, %3 \n"
6230 +#ifdef CONFIG_PAX_REFCOUNT
6231 + "5: \n"
6232 +#endif
6233 + " .set mips0 \n"
6234 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6235 + : "Ir" (i), "m" (v->counter)
6236 + : "memory");
6237 + } else if (kernel_uses_llsc) {
6238 + __asm__ __volatile__(
6239 + " .set mips3 \n"
6240 + "1: lld %1, %2 # atomic64_sub_return \n"
6241 +#ifdef CONFIG_PAX_REFCOUNT
6242 + "2: dsub %0, %1, %3 \n"
6243 +#else
6244 + " dsubu %0, %1, %3 \n"
6245 +#endif
6246 + " scd %0, %2 \n"
6247 + " bnez %0, 4f \n"
6248 + " b 1b \n"
6249 +#ifdef CONFIG_PAX_REFCOUNT
6250 + " .set noreorder \n"
6251 + "3: b 5f \n"
6252 + " move %0, %1 \n"
6253 + " .set reorder \n"
6254 + _ASM_EXTABLE(2b, 3b)
6255 +#endif
6256 + "4: dsubu %0, %1, %3 \n"
6257 +#ifdef CONFIG_PAX_REFCOUNT
6258 + "5: \n"
6259 +#endif
6260 + " .set mips0 \n"
6261 + : "=&r" (result), "=&r" (temp), "=m" (v->counter)
6262 + : "Ir" (i), "m" (v->counter)
6263 + : "memory");
6264 + } else {
6265 + unsigned long flags;
6266 +
6267 + raw_local_irq_save(flags);
6268 + __asm__ __volatile__(
6269 + " ld %0, %1 \n"
6270 +#ifdef CONFIG_PAX_REFCOUNT
6271 + /* Exception on overflow. */
6272 + "1: dsub %0, %2 \n"
6273 +#else
6274 + " dsubu %0, %2 \n"
6275 +#endif
6276 + " sd %0, %1 \n"
6277 +#ifdef CONFIG_PAX_REFCOUNT
6278 + /* Note: Dest reg is not modified on overflow */
6279 + "2: \n"
6280 + _ASM_EXTABLE(1b, 2b)
6281 +#endif
6282 + : "=&r" (result), "+m" (v->counter) : "Ir" (i));
6283 + raw_local_irq_restore(flags);
6284 + }
6285 +
6286 + smp_llsc_mb();
6287 +
6288 + return result;
6289 +}
6290 +
6291 +static __inline__ long atomic64_sub_return_unchecked(long i, atomic64_unchecked_t *v)
6292 {
6293 long result;
6294
6295 @@ -605,7 +1274,7 @@ static __inline__ long atomic64_sub_return(long i, atomic64_t * v)
6296 * Atomically test @v and subtract @i if @v is greater or equal than @i.
6297 * The function returns the old value of @v minus @i.
6298 */
6299 -static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6300 +static __inline__ long atomic64_sub_if_positive(long i, atomic64_t *v)
6301 {
6302 long result;
6303
6304 @@ -662,9 +1331,26 @@ static __inline__ long atomic64_sub_if_positive(long i, atomic64_t * v)
6305 return result;
6306 }
6307
6308 -#define atomic64_cmpxchg(v, o, n) \
6309 - ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
6310 -#define atomic64_xchg(v, new) (xchg(&((v)->counter), (new)))
6311 +static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
6312 +{
6313 + return cmpxchg(&v->counter, old, new);
6314 +}
6315 +
6316 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old,
6317 + long new)
6318 +{
6319 + return cmpxchg(&(v->counter), old, new);
6320 +}
6321 +
6322 +static inline long atomic64_xchg(atomic64_t *v, long new)
6323 +{
6324 + return xchg(&v->counter, new);
6325 +}
6326 +
6327 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
6328 +{
6329 + return xchg(&(v->counter), new);
6330 +}
6331
6332 /**
6333 * atomic64_add_unless - add unless the number is a given value
6334 @@ -694,6 +1380,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6335
6336 #define atomic64_dec_return(v) atomic64_sub_return(1, (v))
6337 #define atomic64_inc_return(v) atomic64_add_return(1, (v))
6338 +#define atomic64_inc_return_unchecked(v) atomic64_add_return_unchecked(1, (v))
6339
6340 /*
6341 * atomic64_sub_and_test - subtract value from variable and test result
6342 @@ -715,6 +1402,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6343 * other cases.
6344 */
6345 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
6346 +#define atomic64_inc_and_test_unchecked(v) atomic64_add_return_unchecked(1, (v)) == 0)
6347
6348 /*
6349 * atomic64_dec_and_test - decrement by 1 and test
6350 @@ -739,6 +1427,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6351 * Atomically increments @v by 1.
6352 */
6353 #define atomic64_inc(v) atomic64_add(1, (v))
6354 +#define atomic64_inc_unchecked(v) atomic64_add_unchecked(1, (v))
6355
6356 /*
6357 * atomic64_dec - decrement and test
6358 @@ -747,6 +1436,7 @@ static __inline__ int atomic64_add_unless(atomic64_t *v, long a, long u)
6359 * Atomically decrements @v by 1.
6360 */
6361 #define atomic64_dec(v) atomic64_sub(1, (v))
6362 +#define atomic64_dec_unchecked(v) atomic64_sub_unchecked(1, (v))
6363
6364 /*
6365 * atomic64_add_negative - add and test if negative
6366 diff --git a/arch/mips/include/asm/cache.h b/arch/mips/include/asm/cache.h
6367 index b4db69f..8f3b093 100644
6368 --- a/arch/mips/include/asm/cache.h
6369 +++ b/arch/mips/include/asm/cache.h
6370 @@ -9,10 +9,11 @@
6371 #ifndef _ASM_CACHE_H
6372 #define _ASM_CACHE_H
6373
6374 +#include <linux/const.h>
6375 #include <kmalloc.h>
6376
6377 #define L1_CACHE_SHIFT CONFIG_MIPS_L1_CACHE_SHIFT
6378 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
6379 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
6380
6381 #define SMP_CACHE_SHIFT L1_CACHE_SHIFT
6382 #define SMP_CACHE_BYTES L1_CACHE_BYTES
6383 diff --git a/arch/mips/include/asm/elf.h b/arch/mips/include/asm/elf.h
6384 index a66359e..d3d474a 100644
6385 --- a/arch/mips/include/asm/elf.h
6386 +++ b/arch/mips/include/asm/elf.h
6387 @@ -373,13 +373,16 @@ extern const char *__elf_platform;
6388 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
6389 #endif
6390
6391 +#ifdef CONFIG_PAX_ASLR
6392 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6393 +
6394 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6395 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6396 +#endif
6397 +
6398 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
6399 struct linux_binprm;
6400 extern int arch_setup_additional_pages(struct linux_binprm *bprm,
6401 int uses_interp);
6402
6403 -struct mm_struct;
6404 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
6405 -#define arch_randomize_brk arch_randomize_brk
6406 -
6407 #endif /* _ASM_ELF_H */
6408 diff --git a/arch/mips/include/asm/exec.h b/arch/mips/include/asm/exec.h
6409 index c1f6afa..38cc6e9 100644
6410 --- a/arch/mips/include/asm/exec.h
6411 +++ b/arch/mips/include/asm/exec.h
6412 @@ -12,6 +12,6 @@
6413 #ifndef _ASM_EXEC_H
6414 #define _ASM_EXEC_H
6415
6416 -extern unsigned long arch_align_stack(unsigned long sp);
6417 +#define arch_align_stack(x) ((x) & ~0xfUL)
6418
6419 #endif /* _ASM_EXEC_H */
6420 diff --git a/arch/mips/include/asm/local.h b/arch/mips/include/asm/local.h
6421 index d44622c..64990d2 100644
6422 --- a/arch/mips/include/asm/local.h
6423 +++ b/arch/mips/include/asm/local.h
6424 @@ -12,15 +12,25 @@ typedef struct
6425 atomic_long_t a;
6426 } local_t;
6427
6428 +typedef struct {
6429 + atomic_long_unchecked_t a;
6430 +} local_unchecked_t;
6431 +
6432 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
6433
6434 #define local_read(l) atomic_long_read(&(l)->a)
6435 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
6436 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
6437 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
6438
6439 #define local_add(i, l) atomic_long_add((i), (&(l)->a))
6440 +#define local_add_unchecked(i, l) atomic_long_add_unchecked((i), (&(l)->a))
6441 #define local_sub(i, l) atomic_long_sub((i), (&(l)->a))
6442 +#define local_sub_unchecked(i, l) atomic_long_sub_unchecked((i), (&(l)->a))
6443 #define local_inc(l) atomic_long_inc(&(l)->a)
6444 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
6445 #define local_dec(l) atomic_long_dec(&(l)->a)
6446 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
6447
6448 /*
6449 * Same as above, but return the result value
6450 @@ -70,6 +80,51 @@ static __inline__ long local_add_return(long i, local_t * l)
6451 return result;
6452 }
6453
6454 +static __inline__ long local_add_return_unchecked(long i, local_unchecked_t * l)
6455 +{
6456 + unsigned long result;
6457 +
6458 + if (kernel_uses_llsc && R10000_LLSC_WAR) {
6459 + unsigned long temp;
6460 +
6461 + __asm__ __volatile__(
6462 + " .set mips3 \n"
6463 + "1:" __LL "%1, %2 # local_add_return \n"
6464 + " addu %0, %1, %3 \n"
6465 + __SC "%0, %2 \n"
6466 + " beqzl %0, 1b \n"
6467 + " addu %0, %1, %3 \n"
6468 + " .set mips0 \n"
6469 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6470 + : "Ir" (i), "m" (l->a.counter)
6471 + : "memory");
6472 + } else if (kernel_uses_llsc) {
6473 + unsigned long temp;
6474 +
6475 + __asm__ __volatile__(
6476 + " .set mips3 \n"
6477 + "1:" __LL "%1, %2 # local_add_return \n"
6478 + " addu %0, %1, %3 \n"
6479 + __SC "%0, %2 \n"
6480 + " beqz %0, 1b \n"
6481 + " addu %0, %1, %3 \n"
6482 + " .set mips0 \n"
6483 + : "=&r" (result), "=&r" (temp), "=m" (l->a.counter)
6484 + : "Ir" (i), "m" (l->a.counter)
6485 + : "memory");
6486 + } else {
6487 + unsigned long flags;
6488 +
6489 + local_irq_save(flags);
6490 + result = l->a.counter;
6491 + result += i;
6492 + l->a.counter = result;
6493 + local_irq_restore(flags);
6494 + }
6495 +
6496 + return result;
6497 +}
6498 +
6499 static __inline__ long local_sub_return(long i, local_t * l)
6500 {
6501 unsigned long result;
6502 @@ -117,6 +172,8 @@ static __inline__ long local_sub_return(long i, local_t * l)
6503
6504 #define local_cmpxchg(l, o, n) \
6505 ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6506 +#define local_cmpxchg_unchecked(l, o, n) \
6507 + ((long)cmpxchg_local(&((l)->a.counter), (o), (n)))
6508 #define local_xchg(l, n) (atomic_long_xchg((&(l)->a), (n)))
6509
6510 /**
6511 diff --git a/arch/mips/include/asm/page.h b/arch/mips/include/asm/page.h
6512 index f6be474..12ad554 100644
6513 --- a/arch/mips/include/asm/page.h
6514 +++ b/arch/mips/include/asm/page.h
6515 @@ -95,7 +95,7 @@ extern void copy_user_highpage(struct page *to, struct page *from,
6516 #ifdef CONFIG_CPU_MIPS32
6517 typedef struct { unsigned long pte_low, pte_high; } pte_t;
6518 #define pte_val(x) ((x).pte_low | ((unsigned long long)(x).pte_high << 32))
6519 - #define __pte(x) ({ pte_t __pte = {(x), ((unsigned long long)(x)) >> 32}; __pte; })
6520 + #define __pte(x) ({ pte_t __pte = {(x), (x) >> 32}; __pte; })
6521 #else
6522 typedef struct { unsigned long long pte; } pte_t;
6523 #define pte_val(x) ((x).pte)
6524 diff --git a/arch/mips/include/asm/pgalloc.h b/arch/mips/include/asm/pgalloc.h
6525 index b336037..5b874cc 100644
6526 --- a/arch/mips/include/asm/pgalloc.h
6527 +++ b/arch/mips/include/asm/pgalloc.h
6528 @@ -37,6 +37,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6529 {
6530 set_pud(pud, __pud((unsigned long)pmd));
6531 }
6532 +
6533 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
6534 +{
6535 + pud_populate(mm, pud, pmd);
6536 +}
6537 #endif
6538
6539 /*
6540 diff --git a/arch/mips/include/asm/smtc_proc.h b/arch/mips/include/asm/smtc_proc.h
6541 index 25da651..ae2a259 100644
6542 --- a/arch/mips/include/asm/smtc_proc.h
6543 +++ b/arch/mips/include/asm/smtc_proc.h
6544 @@ -18,6 +18,6 @@ extern struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6545
6546 /* Count of number of recoveries of "stolen" FPU access rights on 34K */
6547
6548 -extern atomic_t smtc_fpu_recoveries;
6549 +extern atomic_unchecked_t smtc_fpu_recoveries;
6550
6551 #endif /* __ASM_SMTC_PROC_H */
6552 diff --git a/arch/mips/include/asm/thread_info.h b/arch/mips/include/asm/thread_info.h
6553 index 4f58ef6..5e7081b 100644
6554 --- a/arch/mips/include/asm/thread_info.h
6555 +++ b/arch/mips/include/asm/thread_info.h
6556 @@ -115,6 +115,8 @@ static inline struct thread_info *current_thread_info(void)
6557 #define TIF_FPUBOUND 24 /* thread bound to FPU-full CPU set */
6558 #define TIF_LOAD_WATCH 25 /* If set, load watch registers */
6559 #define TIF_SYSCALL_TRACEPOINT 26 /* syscall tracepoint instrumentation */
6560 +/* li takes a 32bit immediate */
6561 +#define TIF_GRSEC_SETXID 29 /* update credentials on syscall entry/exit */
6562 #define TIF_SYSCALL_TRACE 31 /* syscall trace active */
6563
6564 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
6565 @@ -132,13 +134,14 @@ static inline struct thread_info *current_thread_info(void)
6566 #define _TIF_FPUBOUND (1<<TIF_FPUBOUND)
6567 #define _TIF_LOAD_WATCH (1<<TIF_LOAD_WATCH)
6568 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
6569 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
6570
6571 #define _TIF_WORK_SYSCALL_ENTRY (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6572 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6573 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6574
6575 /* work to do in syscall_trace_leave() */
6576 #define _TIF_WORK_SYSCALL_EXIT (_TIF_NOHZ | _TIF_SYSCALL_TRACE | \
6577 - _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT)
6578 + _TIF_SYSCALL_AUDIT | _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6579
6580 /* work to do on interrupt/exception return */
6581 #define _TIF_WORK_MASK \
6582 @@ -146,7 +149,7 @@ static inline struct thread_info *current_thread_info(void)
6583 /* work to do on any return to u-space */
6584 #define _TIF_ALLWORK_MASK (_TIF_NOHZ | _TIF_WORK_MASK | \
6585 _TIF_WORK_SYSCALL_EXIT | \
6586 - _TIF_SYSCALL_TRACEPOINT)
6587 + _TIF_SYSCALL_TRACEPOINT | _TIF_GRSEC_SETXID)
6588
6589 /*
6590 * We stash processor id into a COP0 register to retrieve it fast
6591 diff --git a/arch/mips/kernel/binfmt_elfn32.c b/arch/mips/kernel/binfmt_elfn32.c
6592 index 1188e00..41cf144 100644
6593 --- a/arch/mips/kernel/binfmt_elfn32.c
6594 +++ b/arch/mips/kernel/binfmt_elfn32.c
6595 @@ -50,6 +50,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6596 #undef ELF_ET_DYN_BASE
6597 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6598
6599 +#ifdef CONFIG_PAX_ASLR
6600 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6601 +
6602 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6603 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6604 +#endif
6605 +
6606 #include <asm/processor.h>
6607 #include <linux/module.h>
6608 #include <linux/elfcore.h>
6609 diff --git a/arch/mips/kernel/binfmt_elfo32.c b/arch/mips/kernel/binfmt_elfo32.c
6610 index 202e581..689ca79 100644
6611 --- a/arch/mips/kernel/binfmt_elfo32.c
6612 +++ b/arch/mips/kernel/binfmt_elfo32.c
6613 @@ -56,6 +56,13 @@ typedef elf_fpreg_t elf_fpregset_t[ELF_NFPREG];
6614 #undef ELF_ET_DYN_BASE
6615 #define ELF_ET_DYN_BASE (TASK32_SIZE / 3 * 2)
6616
6617 +#ifdef CONFIG_PAX_ASLR
6618 +#define PAX_ELF_ET_DYN_BASE (TASK_IS_32BIT_ADDR ? 0x00400000UL : 0x00400000UL)
6619 +
6620 +#define PAX_DELTA_MMAP_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6621 +#define PAX_DELTA_STACK_LEN (TASK_IS_32BIT_ADDR ? 27-PAGE_SHIFT : 36-PAGE_SHIFT)
6622 +#endif
6623 +
6624 #include <asm/processor.h>
6625
6626 /*
6627 diff --git a/arch/mips/kernel/irq.c b/arch/mips/kernel/irq.c
6628 index d1fea7a..45602ea 100644
6629 --- a/arch/mips/kernel/irq.c
6630 +++ b/arch/mips/kernel/irq.c
6631 @@ -77,17 +77,17 @@ void ack_bad_irq(unsigned int irq)
6632 printk("unexpected IRQ # %d\n", irq);
6633 }
6634
6635 -atomic_t irq_err_count;
6636 +atomic_unchecked_t irq_err_count;
6637
6638 int arch_show_interrupts(struct seq_file *p, int prec)
6639 {
6640 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
6641 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
6642 return 0;
6643 }
6644
6645 asmlinkage void spurious_interrupt(void)
6646 {
6647 - atomic_inc(&irq_err_count);
6648 + atomic_inc_unchecked(&irq_err_count);
6649 }
6650
6651 void __init init_IRQ(void)
6652 diff --git a/arch/mips/kernel/process.c b/arch/mips/kernel/process.c
6653 index ddc7610..8c58f17 100644
6654 --- a/arch/mips/kernel/process.c
6655 +++ b/arch/mips/kernel/process.c
6656 @@ -566,15 +566,3 @@ unsigned long get_wchan(struct task_struct *task)
6657 out:
6658 return pc;
6659 }
6660 -
6661 -/*
6662 - * Don't forget that the stack pointer must be aligned on a 8 bytes
6663 - * boundary for 32-bits ABI and 16 bytes for 64-bits ABI.
6664 - */
6665 -unsigned long arch_align_stack(unsigned long sp)
6666 -{
6667 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
6668 - sp -= get_random_int() & ~PAGE_MASK;
6669 -
6670 - return sp & ALMASK;
6671 -}
6672 diff --git a/arch/mips/kernel/ptrace.c b/arch/mips/kernel/ptrace.c
6673 index b52e1d2..1a3ca09 100644
6674 --- a/arch/mips/kernel/ptrace.c
6675 +++ b/arch/mips/kernel/ptrace.c
6676 @@ -652,6 +652,10 @@ long arch_ptrace(struct task_struct *child, long request,
6677 return ret;
6678 }
6679
6680 +#ifdef CONFIG_GRKERNSEC_SETXID
6681 +extern void gr_delayed_cred_worker(void);
6682 +#endif
6683 +
6684 /*
6685 * Notification of system call entry/exit
6686 * - triggered by current->work.syscall_trace
6687 @@ -668,6 +672,11 @@ asmlinkage void syscall_trace_enter(struct pt_regs *regs)
6688 tracehook_report_syscall_entry(regs))
6689 ret = -1;
6690
6691 +#ifdef CONFIG_GRKERNSEC_SETXID
6692 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
6693 + gr_delayed_cred_worker();
6694 +#endif
6695 +
6696 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
6697 trace_sys_enter(regs, regs->regs[2]);
6698
6699 diff --git a/arch/mips/kernel/smtc-proc.c b/arch/mips/kernel/smtc-proc.c
6700 index c10aa84..9ec2e60 100644
6701 --- a/arch/mips/kernel/smtc-proc.c
6702 +++ b/arch/mips/kernel/smtc-proc.c
6703 @@ -31,7 +31,7 @@ unsigned long selfipis[NR_CPUS];
6704
6705 struct smtc_cpu_proc smtc_cpu_stats[NR_CPUS];
6706
6707 -atomic_t smtc_fpu_recoveries;
6708 +atomic_unchecked_t smtc_fpu_recoveries;
6709
6710 static int smtc_proc_show(struct seq_file *m, void *v)
6711 {
6712 @@ -48,7 +48,7 @@ static int smtc_proc_show(struct seq_file *m, void *v)
6713 for(i = 0; i < NR_CPUS; i++)
6714 seq_printf(m, "%d: %ld\n", i, smtc_cpu_stats[i].selfipis);
6715 seq_printf(m, "%d Recoveries of \"stolen\" FPU\n",
6716 - atomic_read(&smtc_fpu_recoveries));
6717 + atomic_read_unchecked(&smtc_fpu_recoveries));
6718 return 0;
6719 }
6720
6721 @@ -73,7 +73,7 @@ void init_smtc_stats(void)
6722 smtc_cpu_stats[i].selfipis = 0;
6723 }
6724
6725 - atomic_set(&smtc_fpu_recoveries, 0);
6726 + atomic_set_unchecked(&smtc_fpu_recoveries, 0);
6727
6728 proc_create("smtc", 0444, NULL, &smtc_proc_fops);
6729 }
6730 diff --git a/arch/mips/kernel/smtc.c b/arch/mips/kernel/smtc.c
6731 index dfc1b91..11a2c07 100644
6732 --- a/arch/mips/kernel/smtc.c
6733 +++ b/arch/mips/kernel/smtc.c
6734 @@ -1359,7 +1359,7 @@ void smtc_soft_dump(void)
6735 }
6736 smtc_ipi_qdump();
6737 printk("%d Recoveries of \"stolen\" FPU\n",
6738 - atomic_read(&smtc_fpu_recoveries));
6739 + atomic_read_unchecked(&smtc_fpu_recoveries));
6740 }
6741
6742
6743 diff --git a/arch/mips/kernel/sync-r4k.c b/arch/mips/kernel/sync-r4k.c
6744 index 84536bf..79caa4d 100644
6745 --- a/arch/mips/kernel/sync-r4k.c
6746 +++ b/arch/mips/kernel/sync-r4k.c
6747 @@ -21,8 +21,8 @@
6748 #include <asm/mipsregs.h>
6749
6750 static atomic_t count_start_flag = ATOMIC_INIT(0);
6751 -static atomic_t count_count_start = ATOMIC_INIT(0);
6752 -static atomic_t count_count_stop = ATOMIC_INIT(0);
6753 +static atomic_unchecked_t count_count_start = ATOMIC_INIT(0);
6754 +static atomic_unchecked_t count_count_stop = ATOMIC_INIT(0);
6755 static atomic_t count_reference = ATOMIC_INIT(0);
6756
6757 #define COUNTON 100
6758 @@ -69,13 +69,13 @@ void synchronise_count_master(int cpu)
6759
6760 for (i = 0; i < NR_LOOPS; i++) {
6761 /* slaves loop on '!= 2' */
6762 - while (atomic_read(&count_count_start) != 1)
6763 + while (atomic_read_unchecked(&count_count_start) != 1)
6764 mb();
6765 - atomic_set(&count_count_stop, 0);
6766 + atomic_set_unchecked(&count_count_stop, 0);
6767 smp_wmb();
6768
6769 /* this lets the slaves write their count register */
6770 - atomic_inc(&count_count_start);
6771 + atomic_inc_unchecked(&count_count_start);
6772
6773 /*
6774 * Everyone initialises count in the last loop:
6775 @@ -86,11 +86,11 @@ void synchronise_count_master(int cpu)
6776 /*
6777 * Wait for all slaves to leave the synchronization point:
6778 */
6779 - while (atomic_read(&count_count_stop) != 1)
6780 + while (atomic_read_unchecked(&count_count_stop) != 1)
6781 mb();
6782 - atomic_set(&count_count_start, 0);
6783 + atomic_set_unchecked(&count_count_start, 0);
6784 smp_wmb();
6785 - atomic_inc(&count_count_stop);
6786 + atomic_inc_unchecked(&count_count_stop);
6787 }
6788 /* Arrange for an interrupt in a short while */
6789 write_c0_compare(read_c0_count() + COUNTON);
6790 @@ -131,8 +131,8 @@ void synchronise_count_slave(int cpu)
6791 initcount = atomic_read(&count_reference);
6792
6793 for (i = 0; i < NR_LOOPS; i++) {
6794 - atomic_inc(&count_count_start);
6795 - while (atomic_read(&count_count_start) != 2)
6796 + atomic_inc_unchecked(&count_count_start);
6797 + while (atomic_read_unchecked(&count_count_start) != 2)
6798 mb();
6799
6800 /*
6801 @@ -141,8 +141,8 @@ void synchronise_count_slave(int cpu)
6802 if (i == NR_LOOPS-1)
6803 write_c0_count(initcount);
6804
6805 - atomic_inc(&count_count_stop);
6806 - while (atomic_read(&count_count_stop) != 2)
6807 + atomic_inc_unchecked(&count_count_stop);
6808 + while (atomic_read_unchecked(&count_count_stop) != 2)
6809 mb();
6810 }
6811 /* Arrange for an interrupt in a short while */
6812 diff --git a/arch/mips/kernel/traps.c b/arch/mips/kernel/traps.c
6813 index f9c8746..78b64e3 100644
6814 --- a/arch/mips/kernel/traps.c
6815 +++ b/arch/mips/kernel/traps.c
6816 @@ -690,7 +690,18 @@ asmlinkage void do_ov(struct pt_regs *regs)
6817 siginfo_t info;
6818
6819 prev_state = exception_enter();
6820 - die_if_kernel("Integer overflow", regs);
6821 + if (unlikely(!user_mode(regs))) {
6822 +
6823 +#ifdef CONFIG_PAX_REFCOUNT
6824 + if (fixup_exception(regs)) {
6825 + pax_report_refcount_overflow(regs);
6826 + exception_exit(prev_state);
6827 + return;
6828 + }
6829 +#endif
6830 +
6831 + die("Integer overflow", regs);
6832 + }
6833
6834 info.si_code = FPE_INTOVF;
6835 info.si_signo = SIGFPE;
6836 diff --git a/arch/mips/mm/fault.c b/arch/mips/mm/fault.c
6837 index becc42b..9e43d4b 100644
6838 --- a/arch/mips/mm/fault.c
6839 +++ b/arch/mips/mm/fault.c
6840 @@ -28,6 +28,23 @@
6841 #include <asm/highmem.h> /* For VMALLOC_END */
6842 #include <linux/kdebug.h>
6843
6844 +#ifdef CONFIG_PAX_PAGEEXEC
6845 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
6846 +{
6847 + unsigned long i;
6848 +
6849 + printk(KERN_ERR "PAX: bytes at PC: ");
6850 + for (i = 0; i < 5; i++) {
6851 + unsigned int c;
6852 + if (get_user(c, (unsigned int *)pc+i))
6853 + printk(KERN_CONT "???????? ");
6854 + else
6855 + printk(KERN_CONT "%08x ", c);
6856 + }
6857 + printk("\n");
6858 +}
6859 +#endif
6860 +
6861 /*
6862 * This routine handles page faults. It determines the address,
6863 * and the problem, and then passes it off to one of the appropriate
6864 @@ -199,6 +216,14 @@ bad_area:
6865 bad_area_nosemaphore:
6866 /* User mode accesses just cause a SIGSEGV */
6867 if (user_mode(regs)) {
6868 +
6869 +#ifdef CONFIG_PAX_PAGEEXEC
6870 + if (cpu_has_rixi && (mm->pax_flags & MF_PAX_PAGEEXEC) && !write && address == instruction_pointer(regs)) {
6871 + pax_report_fault(regs, (void *)address, (void *)user_stack_pointer(regs));
6872 + do_group_exit(SIGKILL);
6873 + }
6874 +#endif
6875 +
6876 tsk->thread.cp0_badvaddr = address;
6877 tsk->thread.error_code = write;
6878 #if 0
6879 diff --git a/arch/mips/mm/mmap.c b/arch/mips/mm/mmap.c
6880 index f1baadd..8537544 100644
6881 --- a/arch/mips/mm/mmap.c
6882 +++ b/arch/mips/mm/mmap.c
6883 @@ -59,6 +59,7 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6884 struct vm_area_struct *vma;
6885 unsigned long addr = addr0;
6886 int do_color_align;
6887 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
6888 struct vm_unmapped_area_info info;
6889
6890 if (unlikely(len > TASK_SIZE))
6891 @@ -84,6 +85,11 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6892 do_color_align = 1;
6893
6894 /* requesting a specific address */
6895 +
6896 +#ifdef CONFIG_PAX_RANDMMAP
6897 + if (!(current->mm->pax_flags & MF_PAX_RANDMMAP))
6898 +#endif
6899 +
6900 if (addr) {
6901 if (do_color_align)
6902 addr = COLOUR_ALIGN(addr, pgoff);
6903 @@ -91,14 +97,14 @@ static unsigned long arch_get_unmapped_area_common(struct file *filp,
6904 addr = PAGE_ALIGN(addr);
6905
6906 vma = find_vma(mm, addr);
6907 - if (TASK_SIZE - len >= addr &&
6908 - (!vma || addr + len <= vma->vm_start))
6909 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vmm, addr, len, offset))
6910 return addr;
6911 }
6912
6913 info.length = len;
6914 info.align_mask = do_color_align ? (PAGE_MASK & shm_align_mask) : 0;
6915 info.align_offset = pgoff << PAGE_SHIFT;
6916 + info.threadstack_offset = offset;
6917
6918 if (dir == DOWN) {
6919 info.flags = VM_UNMAPPED_AREA_TOPDOWN;
6920 @@ -146,6 +152,10 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6921 {
6922 unsigned long random_factor = 0UL;
6923
6924 +#ifdef CONFIG_PAX_RANDMMAP
6925 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
6926 +#endif
6927 +
6928 if (current->flags & PF_RANDOMIZE) {
6929 random_factor = get_random_int();
6930 random_factor = random_factor << PAGE_SHIFT;
6931 @@ -157,40 +167,25 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
6932
6933 if (mmap_is_legacy()) {
6934 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
6935 +
6936 +#ifdef CONFIG_PAX_RANDMMAP
6937 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6938 + mm->mmap_base += mm->delta_mmap;
6939 +#endif
6940 +
6941 mm->get_unmapped_area = arch_get_unmapped_area;
6942 } else {
6943 mm->mmap_base = mmap_base(random_factor);
6944 +
6945 +#ifdef CONFIG_PAX_RANDMMAP
6946 + if (mm->pax_flags & MF_PAX_RANDMMAP)
6947 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
6948 +#endif
6949 +
6950 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
6951 }
6952 }
6953
6954 -static inline unsigned long brk_rnd(void)
6955 -{
6956 - unsigned long rnd = get_random_int();
6957 -
6958 - rnd = rnd << PAGE_SHIFT;
6959 - /* 8MB for 32bit, 256MB for 64bit */
6960 - if (TASK_IS_32BIT_ADDR)
6961 - rnd = rnd & 0x7ffffful;
6962 - else
6963 - rnd = rnd & 0xffffffful;
6964 -
6965 - return rnd;
6966 -}
6967 -
6968 -unsigned long arch_randomize_brk(struct mm_struct *mm)
6969 -{
6970 - unsigned long base = mm->brk;
6971 - unsigned long ret;
6972 -
6973 - ret = PAGE_ALIGN(base + brk_rnd());
6974 -
6975 - if (ret < mm->brk)
6976 - return mm->brk;
6977 -
6978 - return ret;
6979 -}
6980 -
6981 int __virt_addr_valid(const volatile void *kaddr)
6982 {
6983 return pfn_valid(PFN_DOWN(virt_to_phys(kaddr)));
6984 diff --git a/arch/mips/sgi-ip27/ip27-nmi.c b/arch/mips/sgi-ip27/ip27-nmi.c
6985 index a2358b4..7cead4f 100644
6986 --- a/arch/mips/sgi-ip27/ip27-nmi.c
6987 +++ b/arch/mips/sgi-ip27/ip27-nmi.c
6988 @@ -187,9 +187,9 @@ void
6989 cont_nmi_dump(void)
6990 {
6991 #ifndef REAL_NMI_SIGNAL
6992 - static atomic_t nmied_cpus = ATOMIC_INIT(0);
6993 + static atomic_unchecked_t nmied_cpus = ATOMIC_INIT(0);
6994
6995 - atomic_inc(&nmied_cpus);
6996 + atomic_inc_unchecked(&nmied_cpus);
6997 #endif
6998 /*
6999 * Only allow 1 cpu to proceed
7000 @@ -233,7 +233,7 @@ cont_nmi_dump(void)
7001 udelay(10000);
7002 }
7003 #else
7004 - while (atomic_read(&nmied_cpus) != num_online_cpus());
7005 + while (atomic_read_unchecked(&nmied_cpus) != num_online_cpus());
7006 #endif
7007
7008 /*
7009 diff --git a/arch/mn10300/proc-mn103e010/include/proc/cache.h b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7010 index 967d144..db12197 100644
7011 --- a/arch/mn10300/proc-mn103e010/include/proc/cache.h
7012 +++ b/arch/mn10300/proc-mn103e010/include/proc/cache.h
7013 @@ -11,12 +11,14 @@
7014 #ifndef _ASM_PROC_CACHE_H
7015 #define _ASM_PROC_CACHE_H
7016
7017 +#include <linux/const.h>
7018 +
7019 /* L1 cache */
7020
7021 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7022 #define L1_CACHE_NENTRIES 256 /* number of entries in each way */
7023 -#define L1_CACHE_BYTES 16 /* bytes per entry */
7024 #define L1_CACHE_SHIFT 4 /* shift for bytes per entry */
7025 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7026 #define L1_CACHE_WAYDISP 0x1000 /* displacement of one way from the next */
7027
7028 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7029 diff --git a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7030 index bcb5df2..84fabd2 100644
7031 --- a/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7032 +++ b/arch/mn10300/proc-mn2ws0050/include/proc/cache.h
7033 @@ -16,13 +16,15 @@
7034 #ifndef _ASM_PROC_CACHE_H
7035 #define _ASM_PROC_CACHE_H
7036
7037 +#include <linux/const.h>
7038 +
7039 /*
7040 * L1 cache
7041 */
7042 #define L1_CACHE_NWAYS 4 /* number of ways in caches */
7043 #define L1_CACHE_NENTRIES 128 /* number of entries in each way */
7044 -#define L1_CACHE_BYTES 32 /* bytes per entry */
7045 #define L1_CACHE_SHIFT 5 /* shift for bytes per entry */
7046 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT) /* bytes per entry */
7047 #define L1_CACHE_WAYDISP 0x1000 /* distance from one way to the next */
7048
7049 #define L1_CACHE_TAG_VALID 0x00000001 /* cache tag valid bit */
7050 diff --git a/arch/openrisc/include/asm/cache.h b/arch/openrisc/include/asm/cache.h
7051 index 4ce7a01..449202a 100644
7052 --- a/arch/openrisc/include/asm/cache.h
7053 +++ b/arch/openrisc/include/asm/cache.h
7054 @@ -19,11 +19,13 @@
7055 #ifndef __ASM_OPENRISC_CACHE_H
7056 #define __ASM_OPENRISC_CACHE_H
7057
7058 +#include <linux/const.h>
7059 +
7060 /* FIXME: How can we replace these with values from the CPU...
7061 * they shouldn't be hard-coded!
7062 */
7063
7064 -#define L1_CACHE_BYTES 16
7065 #define L1_CACHE_SHIFT 4
7066 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7067
7068 #endif /* __ASM_OPENRISC_CACHE_H */
7069 diff --git a/arch/parisc/include/asm/atomic.h b/arch/parisc/include/asm/atomic.h
7070 index 472886c..00e7df9 100644
7071 --- a/arch/parisc/include/asm/atomic.h
7072 +++ b/arch/parisc/include/asm/atomic.h
7073 @@ -252,6 +252,16 @@ static inline long atomic64_dec_if_positive(atomic64_t *v)
7074 return dec;
7075 }
7076
7077 +#define atomic64_read_unchecked(v) atomic64_read(v)
7078 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7079 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7080 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7081 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7082 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7083 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7084 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7085 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7086 +
7087 #endif /* !CONFIG_64BIT */
7088
7089
7090 diff --git a/arch/parisc/include/asm/cache.h b/arch/parisc/include/asm/cache.h
7091 index 47f11c7..3420df2 100644
7092 --- a/arch/parisc/include/asm/cache.h
7093 +++ b/arch/parisc/include/asm/cache.h
7094 @@ -5,6 +5,7 @@
7095 #ifndef __ARCH_PARISC_CACHE_H
7096 #define __ARCH_PARISC_CACHE_H
7097
7098 +#include <linux/const.h>
7099
7100 /*
7101 * PA 2.0 processors have 64-byte cachelines; PA 1.1 processors have
7102 @@ -15,13 +16,13 @@
7103 * just ruin performance.
7104 */
7105 #ifdef CONFIG_PA20
7106 -#define L1_CACHE_BYTES 64
7107 #define L1_CACHE_SHIFT 6
7108 #else
7109 -#define L1_CACHE_BYTES 32
7110 #define L1_CACHE_SHIFT 5
7111 #endif
7112
7113 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7114 +
7115 #ifndef __ASSEMBLY__
7116
7117 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7118 diff --git a/arch/parisc/include/asm/elf.h b/arch/parisc/include/asm/elf.h
7119 index ad2b503..bdf1651 100644
7120 --- a/arch/parisc/include/asm/elf.h
7121 +++ b/arch/parisc/include/asm/elf.h
7122 @@ -342,6 +342,13 @@ struct pt_regs; /* forward declaration... */
7123
7124 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE + 0x01000000)
7125
7126 +#ifdef CONFIG_PAX_ASLR
7127 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
7128 +
7129 +#define PAX_DELTA_MMAP_LEN 16
7130 +#define PAX_DELTA_STACK_LEN 16
7131 +#endif
7132 +
7133 /* This yields a mask that user programs can use to figure out what
7134 instruction set this CPU supports. This could be done in user space,
7135 but it's not easy, and we've already done it here. */
7136 diff --git a/arch/parisc/include/asm/pgalloc.h b/arch/parisc/include/asm/pgalloc.h
7137 index f213f5b..0af3e8e 100644
7138 --- a/arch/parisc/include/asm/pgalloc.h
7139 +++ b/arch/parisc/include/asm/pgalloc.h
7140 @@ -61,6 +61,11 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7141 (__u32)(__pa((unsigned long)pmd) >> PxD_VALUE_SHIFT));
7142 }
7143
7144 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmd)
7145 +{
7146 + pgd_populate(mm, pgd, pmd);
7147 +}
7148 +
7149 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long address)
7150 {
7151 pmd_t *pmd = (pmd_t *)__get_free_pages(GFP_KERNEL|__GFP_REPEAT,
7152 @@ -93,6 +98,7 @@ static inline void pmd_free(struct mm_struct *mm, pmd_t *pmd)
7153 #define pmd_alloc_one(mm, addr) ({ BUG(); ((pmd_t *)2); })
7154 #define pmd_free(mm, x) do { } while (0)
7155 #define pgd_populate(mm, pmd, pte) BUG()
7156 +#define pgd_populate_kernel(mm, pmd, pte) BUG()
7157
7158 #endif
7159
7160 diff --git a/arch/parisc/include/asm/pgtable.h b/arch/parisc/include/asm/pgtable.h
7161 index 34899b5..02dd060 100644
7162 --- a/arch/parisc/include/asm/pgtable.h
7163 +++ b/arch/parisc/include/asm/pgtable.h
7164 @@ -223,6 +223,17 @@ extern void purge_tlb_entries(struct mm_struct *, unsigned long);
7165 #define PAGE_EXECREAD __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_EXEC |_PAGE_ACCESSED)
7166 #define PAGE_COPY PAGE_EXECREAD
7167 #define PAGE_RWX __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_EXEC |_PAGE_ACCESSED)
7168 +
7169 +#ifdef CONFIG_PAX_PAGEEXEC
7170 +# define PAGE_SHARED_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_WRITE | _PAGE_ACCESSED)
7171 +# define PAGE_COPY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7172 +# define PAGE_READONLY_NOEXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | _PAGE_READ | _PAGE_ACCESSED)
7173 +#else
7174 +# define PAGE_SHARED_NOEXEC PAGE_SHARED
7175 +# define PAGE_COPY_NOEXEC PAGE_COPY
7176 +# define PAGE_READONLY_NOEXEC PAGE_READONLY
7177 +#endif
7178 +
7179 #define PAGE_KERNEL __pgprot(_PAGE_KERNEL)
7180 #define PAGE_KERNEL_EXEC __pgprot(_PAGE_KERNEL_EXEC)
7181 #define PAGE_KERNEL_RWX __pgprot(_PAGE_KERNEL_RWX)
7182 diff --git a/arch/parisc/include/asm/uaccess.h b/arch/parisc/include/asm/uaccess.h
7183 index 4006964..fcb3cc2 100644
7184 --- a/arch/parisc/include/asm/uaccess.h
7185 +++ b/arch/parisc/include/asm/uaccess.h
7186 @@ -246,10 +246,10 @@ static inline unsigned long __must_check copy_from_user(void *to,
7187 const void __user *from,
7188 unsigned long n)
7189 {
7190 - int sz = __compiletime_object_size(to);
7191 + size_t sz = __compiletime_object_size(to);
7192 int ret = -EFAULT;
7193
7194 - if (likely(sz == -1 || !__builtin_constant_p(n) || sz >= n))
7195 + if (likely(sz == (size_t)-1 || !__builtin_constant_p(n) || sz >= n))
7196 ret = __copy_from_user(to, from, n);
7197 else
7198 copy_from_user_overflow();
7199 diff --git a/arch/parisc/kernel/module.c b/arch/parisc/kernel/module.c
7200 index 50dfafc..b9fc230 100644
7201 --- a/arch/parisc/kernel/module.c
7202 +++ b/arch/parisc/kernel/module.c
7203 @@ -98,16 +98,38 @@
7204
7205 /* three functions to determine where in the module core
7206 * or init pieces the location is */
7207 +static inline int in_init_rx(struct module *me, void *loc)
7208 +{
7209 + return (loc >= me->module_init_rx &&
7210 + loc < (me->module_init_rx + me->init_size_rx));
7211 +}
7212 +
7213 +static inline int in_init_rw(struct module *me, void *loc)
7214 +{
7215 + return (loc >= me->module_init_rw &&
7216 + loc < (me->module_init_rw + me->init_size_rw));
7217 +}
7218 +
7219 static inline int in_init(struct module *me, void *loc)
7220 {
7221 - return (loc >= me->module_init &&
7222 - loc <= (me->module_init + me->init_size));
7223 + return in_init_rx(me, loc) || in_init_rw(me, loc);
7224 +}
7225 +
7226 +static inline int in_core_rx(struct module *me, void *loc)
7227 +{
7228 + return (loc >= me->module_core_rx &&
7229 + loc < (me->module_core_rx + me->core_size_rx));
7230 +}
7231 +
7232 +static inline int in_core_rw(struct module *me, void *loc)
7233 +{
7234 + return (loc >= me->module_core_rw &&
7235 + loc < (me->module_core_rw + me->core_size_rw));
7236 }
7237
7238 static inline int in_core(struct module *me, void *loc)
7239 {
7240 - return (loc >= me->module_core &&
7241 - loc <= (me->module_core + me->core_size));
7242 + return in_core_rx(me, loc) || in_core_rw(me, loc);
7243 }
7244
7245 static inline int in_local(struct module *me, void *loc)
7246 @@ -371,13 +393,13 @@ int module_frob_arch_sections(CONST Elf_Ehdr *hdr,
7247 }
7248
7249 /* align things a bit */
7250 - me->core_size = ALIGN(me->core_size, 16);
7251 - me->arch.got_offset = me->core_size;
7252 - me->core_size += gots * sizeof(struct got_entry);
7253 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7254 + me->arch.got_offset = me->core_size_rw;
7255 + me->core_size_rw += gots * sizeof(struct got_entry);
7256
7257 - me->core_size = ALIGN(me->core_size, 16);
7258 - me->arch.fdesc_offset = me->core_size;
7259 - me->core_size += fdescs * sizeof(Elf_Fdesc);
7260 + me->core_size_rw = ALIGN(me->core_size_rw, 16);
7261 + me->arch.fdesc_offset = me->core_size_rw;
7262 + me->core_size_rw += fdescs * sizeof(Elf_Fdesc);
7263
7264 me->arch.got_max = gots;
7265 me->arch.fdesc_max = fdescs;
7266 @@ -395,7 +417,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7267
7268 BUG_ON(value == 0);
7269
7270 - got = me->module_core + me->arch.got_offset;
7271 + got = me->module_core_rw + me->arch.got_offset;
7272 for (i = 0; got[i].addr; i++)
7273 if (got[i].addr == value)
7274 goto out;
7275 @@ -413,7 +435,7 @@ static Elf64_Word get_got(struct module *me, unsigned long value, long addend)
7276 #ifdef CONFIG_64BIT
7277 static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7278 {
7279 - Elf_Fdesc *fdesc = me->module_core + me->arch.fdesc_offset;
7280 + Elf_Fdesc *fdesc = me->module_core_rw + me->arch.fdesc_offset;
7281
7282 if (!value) {
7283 printk(KERN_ERR "%s: zero OPD requested!\n", me->name);
7284 @@ -431,7 +453,7 @@ static Elf_Addr get_fdesc(struct module *me, unsigned long value)
7285
7286 /* Create new one */
7287 fdesc->addr = value;
7288 - fdesc->gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7289 + fdesc->gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7290 return (Elf_Addr)fdesc;
7291 }
7292 #endif /* CONFIG_64BIT */
7293 @@ -843,7 +865,7 @@ register_unwind_table(struct module *me,
7294
7295 table = (unsigned char *)sechdrs[me->arch.unwind_section].sh_addr;
7296 end = table + sechdrs[me->arch.unwind_section].sh_size;
7297 - gp = (Elf_Addr)me->module_core + me->arch.got_offset;
7298 + gp = (Elf_Addr)me->module_core_rw + me->arch.got_offset;
7299
7300 DEBUGP("register_unwind_table(), sect = %d at 0x%p - 0x%p (gp=0x%lx)\n",
7301 me->arch.unwind_section, table, end, gp);
7302 diff --git a/arch/parisc/kernel/sys_parisc.c b/arch/parisc/kernel/sys_parisc.c
7303 index 0d3a9d4..20a99b0 100644
7304 --- a/arch/parisc/kernel/sys_parisc.c
7305 +++ b/arch/parisc/kernel/sys_parisc.c
7306 @@ -33,9 +33,11 @@
7307 #include <linux/utsname.h>
7308 #include <linux/personality.h>
7309
7310 -static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7311 +static unsigned long get_unshared_area(unsigned long addr, unsigned long len,
7312 + unsigned long flags)
7313 {
7314 struct vm_unmapped_area_info info;
7315 + unsigned long offset = gr_rand_threadstack_offset(current->mm, NULL, flags);
7316
7317 info.flags = 0;
7318 info.length = len;
7319 @@ -43,6 +45,7 @@ static unsigned long get_unshared_area(unsigned long addr, unsigned long len)
7320 info.high_limit = TASK_SIZE;
7321 info.align_mask = 0;
7322 info.align_offset = 0;
7323 + info.threadstack_offset = offset;
7324 return vm_unmapped_area(&info);
7325 }
7326
7327 @@ -69,9 +72,10 @@ static unsigned long shared_align_offset(struct file *filp, unsigned long pgoff)
7328 }
7329
7330 static unsigned long get_shared_area(struct file *filp, unsigned long addr,
7331 - unsigned long len, unsigned long pgoff)
7332 + unsigned long len, unsigned long pgoff, unsigned long flags)
7333 {
7334 struct vm_unmapped_area_info info;
7335 + unsigned long offset = gr_rand_threadstack_offset(current->mm, filp, flags);
7336
7337 info.flags = 0;
7338 info.length = len;
7339 @@ -79,6 +83,7 @@ static unsigned long get_shared_area(struct file *filp, unsigned long addr,
7340 info.high_limit = TASK_SIZE;
7341 info.align_mask = PAGE_MASK & (SHMLBA - 1);
7342 info.align_offset = shared_align_offset(filp, pgoff);
7343 + info.threadstack_offset = offset;
7344 return vm_unmapped_area(&info);
7345 }
7346
7347 @@ -93,13 +98,20 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
7348 return -EINVAL;
7349 return addr;
7350 }
7351 - if (!addr)
7352 + if (!addr) {
7353 addr = TASK_UNMAPPED_BASE;
7354
7355 +#ifdef CONFIG_PAX_RANDMMAP
7356 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
7357 + addr += current->mm->delta_mmap;
7358 +#endif
7359 +
7360 + }
7361 +
7362 if (filp || (flags & MAP_SHARED))
7363 - addr = get_shared_area(filp, addr, len, pgoff);
7364 + addr = get_shared_area(filp, addr, len, pgoff, flags);
7365 else
7366 - addr = get_unshared_area(addr, len);
7367 + addr = get_unshared_area(addr, len, flags);
7368
7369 return addr;
7370 }
7371 diff --git a/arch/parisc/kernel/traps.c b/arch/parisc/kernel/traps.c
7372 index 1cd1d0c..44ec918 100644
7373 --- a/arch/parisc/kernel/traps.c
7374 +++ b/arch/parisc/kernel/traps.c
7375 @@ -722,9 +722,7 @@ void notrace handle_interruption(int code, struct pt_regs *regs)
7376
7377 down_read(&current->mm->mmap_sem);
7378 vma = find_vma(current->mm,regs->iaoq[0]);
7379 - if (vma && (regs->iaoq[0] >= vma->vm_start)
7380 - && (vma->vm_flags & VM_EXEC)) {
7381 -
7382 + if (vma && (regs->iaoq[0] >= vma->vm_start)) {
7383 fault_address = regs->iaoq[0];
7384 fault_space = regs->iasq[0];
7385
7386 diff --git a/arch/parisc/mm/fault.c b/arch/parisc/mm/fault.c
7387 index 9d08c71..e2b4d20 100644
7388 --- a/arch/parisc/mm/fault.c
7389 +++ b/arch/parisc/mm/fault.c
7390 @@ -15,6 +15,7 @@
7391 #include <linux/sched.h>
7392 #include <linux/interrupt.h>
7393 #include <linux/module.h>
7394 +#include <linux/unistd.h>
7395
7396 #include <asm/uaccess.h>
7397 #include <asm/traps.h>
7398 @@ -52,7 +53,7 @@ DEFINE_PER_CPU(struct exception_data, exception_data);
7399 static unsigned long
7400 parisc_acctyp(unsigned long code, unsigned int inst)
7401 {
7402 - if (code == 6 || code == 16)
7403 + if (code == 6 || code == 7 || code == 16)
7404 return VM_EXEC;
7405
7406 switch (inst & 0xf0000000) {
7407 @@ -138,6 +139,116 @@ parisc_acctyp(unsigned long code, unsigned int inst)
7408 }
7409 #endif
7410
7411 +#ifdef CONFIG_PAX_PAGEEXEC
7412 +/*
7413 + * PaX: decide what to do with offenders (instruction_pointer(regs) = fault address)
7414 + *
7415 + * returns 1 when task should be killed
7416 + * 2 when rt_sigreturn trampoline was detected
7417 + * 3 when unpatched PLT trampoline was detected
7418 + */
7419 +static int pax_handle_fetch_fault(struct pt_regs *regs)
7420 +{
7421 +
7422 +#ifdef CONFIG_PAX_EMUPLT
7423 + int err;
7424 +
7425 + do { /* PaX: unpatched PLT emulation */
7426 + unsigned int bl, depwi;
7427 +
7428 + err = get_user(bl, (unsigned int *)instruction_pointer(regs));
7429 + err |= get_user(depwi, (unsigned int *)(instruction_pointer(regs)+4));
7430 +
7431 + if (err)
7432 + break;
7433 +
7434 + if (bl == 0xEA9F1FDDU && depwi == 0xD6801C1EU) {
7435 + unsigned int ldw, bv, ldw2, addr = instruction_pointer(regs)-12;
7436 +
7437 + err = get_user(ldw, (unsigned int *)addr);
7438 + err |= get_user(bv, (unsigned int *)(addr+4));
7439 + err |= get_user(ldw2, (unsigned int *)(addr+8));
7440 +
7441 + if (err)
7442 + break;
7443 +
7444 + if (ldw == 0x0E801096U &&
7445 + bv == 0xEAC0C000U &&
7446 + ldw2 == 0x0E881095U)
7447 + {
7448 + unsigned int resolver, map;
7449 +
7450 + err = get_user(resolver, (unsigned int *)(instruction_pointer(regs)+8));
7451 + err |= get_user(map, (unsigned int *)(instruction_pointer(regs)+12));
7452 + if (err)
7453 + break;
7454 +
7455 + regs->gr[20] = instruction_pointer(regs)+8;
7456 + regs->gr[21] = map;
7457 + regs->gr[22] = resolver;
7458 + regs->iaoq[0] = resolver | 3UL;
7459 + regs->iaoq[1] = regs->iaoq[0] + 4;
7460 + return 3;
7461 + }
7462 + }
7463 + } while (0);
7464 +#endif
7465 +
7466 +#ifdef CONFIG_PAX_EMUTRAMP
7467 +
7468 +#ifndef CONFIG_PAX_EMUSIGRT
7469 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
7470 + return 1;
7471 +#endif
7472 +
7473 + do { /* PaX: rt_sigreturn emulation */
7474 + unsigned int ldi1, ldi2, bel, nop;
7475 +
7476 + err = get_user(ldi1, (unsigned int *)instruction_pointer(regs));
7477 + err |= get_user(ldi2, (unsigned int *)(instruction_pointer(regs)+4));
7478 + err |= get_user(bel, (unsigned int *)(instruction_pointer(regs)+8));
7479 + err |= get_user(nop, (unsigned int *)(instruction_pointer(regs)+12));
7480 +
7481 + if (err)
7482 + break;
7483 +
7484 + if ((ldi1 == 0x34190000U || ldi1 == 0x34190002U) &&
7485 + ldi2 == 0x3414015AU &&
7486 + bel == 0xE4008200U &&
7487 + nop == 0x08000240U)
7488 + {
7489 + regs->gr[25] = (ldi1 & 2) >> 1;
7490 + regs->gr[20] = __NR_rt_sigreturn;
7491 + regs->gr[31] = regs->iaoq[1] + 16;
7492 + regs->sr[0] = regs->iasq[1];
7493 + regs->iaoq[0] = 0x100UL;
7494 + regs->iaoq[1] = regs->iaoq[0] + 4;
7495 + regs->iasq[0] = regs->sr[2];
7496 + regs->iasq[1] = regs->sr[2];
7497 + return 2;
7498 + }
7499 + } while (0);
7500 +#endif
7501 +
7502 + return 1;
7503 +}
7504 +
7505 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
7506 +{
7507 + unsigned long i;
7508 +
7509 + printk(KERN_ERR "PAX: bytes at PC: ");
7510 + for (i = 0; i < 5; i++) {
7511 + unsigned int c;
7512 + if (get_user(c, (unsigned int *)pc+i))
7513 + printk(KERN_CONT "???????? ");
7514 + else
7515 + printk(KERN_CONT "%08x ", c);
7516 + }
7517 + printk("\n");
7518 +}
7519 +#endif
7520 +
7521 int fixup_exception(struct pt_regs *regs)
7522 {
7523 const struct exception_table_entry *fix;
7524 @@ -210,8 +321,33 @@ retry:
7525
7526 good_area:
7527
7528 - if ((vma->vm_flags & acc_type) != acc_type)
7529 + if ((vma->vm_flags & acc_type) != acc_type) {
7530 +
7531 +#ifdef CONFIG_PAX_PAGEEXEC
7532 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && (acc_type & VM_EXEC) &&
7533 + (address & ~3UL) == instruction_pointer(regs))
7534 + {
7535 + up_read(&mm->mmap_sem);
7536 + switch (pax_handle_fetch_fault(regs)) {
7537 +
7538 +#ifdef CONFIG_PAX_EMUPLT
7539 + case 3:
7540 + return;
7541 +#endif
7542 +
7543 +#ifdef CONFIG_PAX_EMUTRAMP
7544 + case 2:
7545 + return;
7546 +#endif
7547 +
7548 + }
7549 + pax_report_fault(regs, (void *)instruction_pointer(regs), (void *)regs->gr[30]);
7550 + do_group_exit(SIGKILL);
7551 + }
7552 +#endif
7553 +
7554 goto bad_area;
7555 + }
7556
7557 /*
7558 * If for any reason at all we couldn't handle the fault, make
7559 diff --git a/arch/powerpc/Kconfig b/arch/powerpc/Kconfig
7560 index b44b52c..4cd253c 100644
7561 --- a/arch/powerpc/Kconfig
7562 +++ b/arch/powerpc/Kconfig
7563 @@ -382,6 +382,7 @@ config ARCH_ENABLE_MEMORY_HOTREMOVE
7564 config KEXEC
7565 bool "kexec system call"
7566 depends on (PPC_BOOK3S || FSL_BOOKE || (44x && !SMP))
7567 + depends on !GRKERNSEC_KMEM
7568 help
7569 kexec is a system call that implements the ability to shutdown your
7570 current kernel, and to start another kernel. It is like a reboot
7571 diff --git a/arch/powerpc/include/asm/atomic.h b/arch/powerpc/include/asm/atomic.h
7572 index e3b1d41..8e81edf 100644
7573 --- a/arch/powerpc/include/asm/atomic.h
7574 +++ b/arch/powerpc/include/asm/atomic.h
7575 @@ -523,6 +523,16 @@ static __inline__ long atomic64_inc_not_zero(atomic64_t *v)
7576 return t1;
7577 }
7578
7579 +#define atomic64_read_unchecked(v) atomic64_read(v)
7580 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
7581 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
7582 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
7583 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
7584 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
7585 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
7586 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
7587 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
7588 +
7589 #endif /* __powerpc64__ */
7590
7591 #endif /* __KERNEL__ */
7592 diff --git a/arch/powerpc/include/asm/cache.h b/arch/powerpc/include/asm/cache.h
7593 index 9e495c9..b6878e5 100644
7594 --- a/arch/powerpc/include/asm/cache.h
7595 +++ b/arch/powerpc/include/asm/cache.h
7596 @@ -3,6 +3,7 @@
7597
7598 #ifdef __KERNEL__
7599
7600 +#include <linux/const.h>
7601
7602 /* bytes per L1 cache line */
7603 #if defined(CONFIG_8xx) || defined(CONFIG_403GCX)
7604 @@ -22,7 +23,7 @@
7605 #define L1_CACHE_SHIFT 7
7606 #endif
7607
7608 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
7609 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
7610
7611 #define SMP_CACHE_BYTES L1_CACHE_BYTES
7612
7613 diff --git a/arch/powerpc/include/asm/elf.h b/arch/powerpc/include/asm/elf.h
7614 index 935b5e7..7001d2d 100644
7615 --- a/arch/powerpc/include/asm/elf.h
7616 +++ b/arch/powerpc/include/asm/elf.h
7617 @@ -28,8 +28,19 @@
7618 the loader. We need to make sure that it is out of the way of the program
7619 that it will "exec", and that there is sufficient room for the brk. */
7620
7621 -extern unsigned long randomize_et_dyn(unsigned long base);
7622 -#define ELF_ET_DYN_BASE (randomize_et_dyn(0x20000000))
7623 +#define ELF_ET_DYN_BASE (0x20000000)
7624 +
7625 +#ifdef CONFIG_PAX_ASLR
7626 +#define PAX_ELF_ET_DYN_BASE (0x10000000UL)
7627 +
7628 +#ifdef __powerpc64__
7629 +#define PAX_DELTA_MMAP_LEN (is_32bit_task() ? 16 : 28)
7630 +#define PAX_DELTA_STACK_LEN (is_32bit_task() ? 16 : 28)
7631 +#else
7632 +#define PAX_DELTA_MMAP_LEN 15
7633 +#define PAX_DELTA_STACK_LEN 15
7634 +#endif
7635 +#endif
7636
7637 #define ELF_CORE_EFLAGS (is_elf2_task() ? 2 : 0)
7638
7639 @@ -127,10 +138,6 @@ extern int arch_setup_additional_pages(struct linux_binprm *bprm,
7640 (0x7ff >> (PAGE_SHIFT - 12)) : \
7641 (0x3ffff >> (PAGE_SHIFT - 12)))
7642
7643 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
7644 -#define arch_randomize_brk arch_randomize_brk
7645 -
7646 -
7647 #ifdef CONFIG_SPU_BASE
7648 /* Notes used in ET_CORE. Note name is "SPU/<fd>/<filename>". */
7649 #define NT_SPU 1
7650 diff --git a/arch/powerpc/include/asm/exec.h b/arch/powerpc/include/asm/exec.h
7651 index 8196e9c..d83a9f3 100644
7652 --- a/arch/powerpc/include/asm/exec.h
7653 +++ b/arch/powerpc/include/asm/exec.h
7654 @@ -4,6 +4,6 @@
7655 #ifndef _ASM_POWERPC_EXEC_H
7656 #define _ASM_POWERPC_EXEC_H
7657
7658 -extern unsigned long arch_align_stack(unsigned long sp);
7659 +#define arch_align_stack(x) ((x) & ~0xfUL)
7660
7661 #endif /* _ASM_POWERPC_EXEC_H */
7662 diff --git a/arch/powerpc/include/asm/kmap_types.h b/arch/powerpc/include/asm/kmap_types.h
7663 index 5acabbd..7ea14fa 100644
7664 --- a/arch/powerpc/include/asm/kmap_types.h
7665 +++ b/arch/powerpc/include/asm/kmap_types.h
7666 @@ -10,7 +10,7 @@
7667 * 2 of the License, or (at your option) any later version.
7668 */
7669
7670 -#define KM_TYPE_NR 16
7671 +#define KM_TYPE_NR 17
7672
7673 #endif /* __KERNEL__ */
7674 #endif /* _ASM_POWERPC_KMAP_TYPES_H */
7675 diff --git a/arch/powerpc/include/asm/mman.h b/arch/powerpc/include/asm/mman.h
7676 index 8565c25..2865190 100644
7677 --- a/arch/powerpc/include/asm/mman.h
7678 +++ b/arch/powerpc/include/asm/mman.h
7679 @@ -24,7 +24,7 @@ static inline unsigned long arch_calc_vm_prot_bits(unsigned long prot)
7680 }
7681 #define arch_calc_vm_prot_bits(prot) arch_calc_vm_prot_bits(prot)
7682
7683 -static inline pgprot_t arch_vm_get_page_prot(unsigned long vm_flags)
7684 +static inline pgprot_t arch_vm_get_page_prot(vm_flags_t vm_flags)
7685 {
7686 return (vm_flags & VM_SAO) ? __pgprot(_PAGE_SAO) : __pgprot(0);
7687 }
7688 diff --git a/arch/powerpc/include/asm/page.h b/arch/powerpc/include/asm/page.h
7689 index 32e4e21..62afb12 100644
7690 --- a/arch/powerpc/include/asm/page.h
7691 +++ b/arch/powerpc/include/asm/page.h
7692 @@ -230,8 +230,9 @@ extern long long virt_phys_offset;
7693 * and needs to be executable. This means the whole heap ends
7694 * up being executable.
7695 */
7696 -#define VM_DATA_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7697 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7698 +#define VM_DATA_DEFAULT_FLAGS32 \
7699 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7700 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7701
7702 #define VM_DATA_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7703 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7704 @@ -259,6 +260,9 @@ extern long long virt_phys_offset;
7705 #define is_kernel_addr(x) ((x) >= PAGE_OFFSET)
7706 #endif
7707
7708 +#define ktla_ktva(addr) (addr)
7709 +#define ktva_ktla(addr) (addr)
7710 +
7711 #ifndef CONFIG_PPC_BOOK3S_64
7712 /*
7713 * Use the top bit of the higher-level page table entries to indicate whether
7714 diff --git a/arch/powerpc/include/asm/page_64.h b/arch/powerpc/include/asm/page_64.h
7715 index 88693ce..ac6f9ab 100644
7716 --- a/arch/powerpc/include/asm/page_64.h
7717 +++ b/arch/powerpc/include/asm/page_64.h
7718 @@ -153,15 +153,18 @@ do { \
7719 * stack by default, so in the absence of a PT_GNU_STACK program header
7720 * we turn execute permission off.
7721 */
7722 -#define VM_STACK_DEFAULT_FLAGS32 (VM_READ | VM_WRITE | VM_EXEC | \
7723 - VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7724 +#define VM_STACK_DEFAULT_FLAGS32 \
7725 + (((current->personality & READ_IMPLIES_EXEC) ? VM_EXEC : 0) | \
7726 + VM_READ | VM_WRITE | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7727
7728 #define VM_STACK_DEFAULT_FLAGS64 (VM_READ | VM_WRITE | \
7729 VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)
7730
7731 +#ifndef CONFIG_PAX_PAGEEXEC
7732 #define VM_STACK_DEFAULT_FLAGS \
7733 (is_32bit_task() ? \
7734 VM_STACK_DEFAULT_FLAGS32 : VM_STACK_DEFAULT_FLAGS64)
7735 +#endif
7736
7737 #include <asm-generic/getorder.h>
7738
7739 diff --git a/arch/powerpc/include/asm/pgalloc-64.h b/arch/powerpc/include/asm/pgalloc-64.h
7740 index 4b0be20..c15a27d 100644
7741 --- a/arch/powerpc/include/asm/pgalloc-64.h
7742 +++ b/arch/powerpc/include/asm/pgalloc-64.h
7743 @@ -54,6 +54,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
7744 #ifndef CONFIG_PPC_64K_PAGES
7745
7746 #define pgd_populate(MM, PGD, PUD) pgd_set(PGD, PUD)
7747 +#define pgd_populate_kernel(MM, PGD, PUD) pgd_populate((MM), (PGD), (PUD))
7748
7749 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
7750 {
7751 @@ -71,6 +72,11 @@ static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7752 pud_set(pud, (unsigned long)pmd);
7753 }
7754
7755 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
7756 +{
7757 + pud_populate(mm, pud, pmd);
7758 +}
7759 +
7760 #define pmd_populate(mm, pmd, pte_page) \
7761 pmd_populate_kernel(mm, pmd, page_address(pte_page))
7762 #define pmd_populate_kernel(mm, pmd, pte) pmd_set(pmd, (unsigned long)(pte))
7763 @@ -173,6 +179,7 @@ extern void __tlb_remove_table(void *_table);
7764 #endif
7765
7766 #define pud_populate(mm, pud, pmd) pud_set(pud, (unsigned long)pmd)
7767 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
7768
7769 static inline void pmd_populate_kernel(struct mm_struct *mm, pmd_t *pmd,
7770 pte_t *pte)
7771 diff --git a/arch/powerpc/include/asm/pgtable.h b/arch/powerpc/include/asm/pgtable.h
7772 index 7d6eacf..14c0240 100644
7773 --- a/arch/powerpc/include/asm/pgtable.h
7774 +++ b/arch/powerpc/include/asm/pgtable.h
7775 @@ -2,6 +2,7 @@
7776 #define _ASM_POWERPC_PGTABLE_H
7777 #ifdef __KERNEL__
7778
7779 +#include <linux/const.h>
7780 #ifndef __ASSEMBLY__
7781 #include <asm/processor.h> /* For TASK_SIZE */
7782 #include <asm/mmu.h>
7783 diff --git a/arch/powerpc/include/asm/pte-hash32.h b/arch/powerpc/include/asm/pte-hash32.h
7784 index 4aad413..85d86bf 100644
7785 --- a/arch/powerpc/include/asm/pte-hash32.h
7786 +++ b/arch/powerpc/include/asm/pte-hash32.h
7787 @@ -21,6 +21,7 @@
7788 #define _PAGE_FILE 0x004 /* when !present: nonlinear file mapping */
7789 #define _PAGE_USER 0x004 /* usermode access allowed */
7790 #define _PAGE_GUARDED 0x008 /* G: prohibit speculative access */
7791 +#define _PAGE_EXEC _PAGE_GUARDED
7792 #define _PAGE_COHERENT 0x010 /* M: enforce memory coherence (SMP systems) */
7793 #define _PAGE_NO_CACHE 0x020 /* I: cache inhibit */
7794 #define _PAGE_WRITETHRU 0x040 /* W: cache write-through */
7795 diff --git a/arch/powerpc/include/asm/reg.h b/arch/powerpc/include/asm/reg.h
7796 index fa8388e..f985549 100644
7797 --- a/arch/powerpc/include/asm/reg.h
7798 +++ b/arch/powerpc/include/asm/reg.h
7799 @@ -239,6 +239,7 @@
7800 #define SPRN_DBCR 0x136 /* e300 Data Breakpoint Control Reg */
7801 #define SPRN_DSISR 0x012 /* Data Storage Interrupt Status Register */
7802 #define DSISR_NOHPTE 0x40000000 /* no translation found */
7803 +#define DSISR_GUARDED 0x10000000 /* fetch from guarded storage */
7804 #define DSISR_PROTFAULT 0x08000000 /* protection fault */
7805 #define DSISR_ISSTORE 0x02000000 /* access was a store */
7806 #define DSISR_DABRMATCH 0x00400000 /* hit data breakpoint */
7807 diff --git a/arch/powerpc/include/asm/smp.h b/arch/powerpc/include/asm/smp.h
7808 index 084e080..9415a3d 100644
7809 --- a/arch/powerpc/include/asm/smp.h
7810 +++ b/arch/powerpc/include/asm/smp.h
7811 @@ -51,7 +51,7 @@ struct smp_ops_t {
7812 int (*cpu_disable)(void);
7813 void (*cpu_die)(unsigned int nr);
7814 int (*cpu_bootable)(unsigned int nr);
7815 -};
7816 +} __no_const;
7817
7818 extern void smp_send_debugger_break(void);
7819 extern void start_secondary_resume(void);
7820 diff --git a/arch/powerpc/include/asm/thread_info.h b/arch/powerpc/include/asm/thread_info.h
7821 index 9854c56..7517190 100644
7822 --- a/arch/powerpc/include/asm/thread_info.h
7823 +++ b/arch/powerpc/include/asm/thread_info.h
7824 @@ -91,7 +91,6 @@ static inline struct thread_info *current_thread_info(void)
7825 #define TIF_POLLING_NRFLAG 3 /* true if poll_idle() is polling
7826 TIF_NEED_RESCHED */
7827 #define TIF_32BIT 4 /* 32 bit binary */
7828 -#define TIF_PERFMON_WORK 5 /* work for pfm_handle_work() */
7829 #define TIF_PERFMON_CTXSW 6 /* perfmon needs ctxsw calls */
7830 #define TIF_SYSCALL_AUDIT 7 /* syscall auditing active */
7831 #define TIF_SINGLESTEP 8 /* singlestepping active */
7832 @@ -108,6 +107,9 @@ static inline struct thread_info *current_thread_info(void)
7833 #if defined(CONFIG_PPC64)
7834 #define TIF_ELF2ABI 18 /* function descriptors must die! */
7835 #endif
7836 +#define TIF_PERFMON_WORK 19 /* work for pfm_handle_work() */
7837 +/* mask must be expressable within 16 bits to satisfy 'andi' instruction reqs */
7838 +#define TIF_GRSEC_SETXID 5 /* update credentials on syscall entry/exit */
7839
7840 /* as above, but as bit values */
7841 #define _TIF_SYSCALL_TRACE (1<<TIF_SYSCALL_TRACE)
7842 @@ -127,9 +129,10 @@ static inline struct thread_info *current_thread_info(void)
7843 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
7844 #define _TIF_EMULATE_STACK_STORE (1<<TIF_EMULATE_STACK_STORE)
7845 #define _TIF_NOHZ (1<<TIF_NOHZ)
7846 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
7847 #define _TIF_SYSCALL_T_OR_A (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | \
7848 _TIF_SECCOMP | _TIF_SYSCALL_TRACEPOINT | \
7849 - _TIF_NOHZ)
7850 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
7851
7852 #define _TIF_USER_WORK_MASK (_TIF_SIGPENDING | _TIF_NEED_RESCHED | \
7853 _TIF_NOTIFY_RESUME | _TIF_UPROBE)
7854 diff --git a/arch/powerpc/include/asm/uaccess.h b/arch/powerpc/include/asm/uaccess.h
7855 index 9485b43..4718d50 100644
7856 --- a/arch/powerpc/include/asm/uaccess.h
7857 +++ b/arch/powerpc/include/asm/uaccess.h
7858 @@ -318,52 +318,6 @@ do { \
7859 extern unsigned long __copy_tofrom_user(void __user *to,
7860 const void __user *from, unsigned long size);
7861
7862 -#ifndef __powerpc64__
7863 -
7864 -static inline unsigned long copy_from_user(void *to,
7865 - const void __user *from, unsigned long n)
7866 -{
7867 - unsigned long over;
7868 -
7869 - if (access_ok(VERIFY_READ, from, n))
7870 - return __copy_tofrom_user((__force void __user *)to, from, n);
7871 - if ((unsigned long)from < TASK_SIZE) {
7872 - over = (unsigned long)from + n - TASK_SIZE;
7873 - return __copy_tofrom_user((__force void __user *)to, from,
7874 - n - over) + over;
7875 - }
7876 - return n;
7877 -}
7878 -
7879 -static inline unsigned long copy_to_user(void __user *to,
7880 - const void *from, unsigned long n)
7881 -{
7882 - unsigned long over;
7883 -
7884 - if (access_ok(VERIFY_WRITE, to, n))
7885 - return __copy_tofrom_user(to, (__force void __user *)from, n);
7886 - if ((unsigned long)to < TASK_SIZE) {
7887 - over = (unsigned long)to + n - TASK_SIZE;
7888 - return __copy_tofrom_user(to, (__force void __user *)from,
7889 - n - over) + over;
7890 - }
7891 - return n;
7892 -}
7893 -
7894 -#else /* __powerpc64__ */
7895 -
7896 -#define __copy_in_user(to, from, size) \
7897 - __copy_tofrom_user((to), (from), (size))
7898 -
7899 -extern unsigned long copy_from_user(void *to, const void __user *from,
7900 - unsigned long n);
7901 -extern unsigned long copy_to_user(void __user *to, const void *from,
7902 - unsigned long n);
7903 -extern unsigned long copy_in_user(void __user *to, const void __user *from,
7904 - unsigned long n);
7905 -
7906 -#endif /* __powerpc64__ */
7907 -
7908 static inline unsigned long __copy_from_user_inatomic(void *to,
7909 const void __user *from, unsigned long n)
7910 {
7911 @@ -387,6 +341,10 @@ static inline unsigned long __copy_from_user_inatomic(void *to,
7912 if (ret == 0)
7913 return 0;
7914 }
7915 +
7916 + if (!__builtin_constant_p(n))
7917 + check_object_size(to, n, false);
7918 +
7919 return __copy_tofrom_user((__force void __user *)to, from, n);
7920 }
7921
7922 @@ -413,6 +371,10 @@ static inline unsigned long __copy_to_user_inatomic(void __user *to,
7923 if (ret == 0)
7924 return 0;
7925 }
7926 +
7927 + if (!__builtin_constant_p(n))
7928 + check_object_size(from, n, true);
7929 +
7930 return __copy_tofrom_user(to, (__force const void __user *)from, n);
7931 }
7932
7933 @@ -430,6 +392,92 @@ static inline unsigned long __copy_to_user(void __user *to,
7934 return __copy_to_user_inatomic(to, from, size);
7935 }
7936
7937 +#ifndef __powerpc64__
7938 +
7939 +static inline unsigned long __must_check copy_from_user(void *to,
7940 + const void __user *from, unsigned long n)
7941 +{
7942 + unsigned long over;
7943 +
7944 + if ((long)n < 0)
7945 + return n;
7946 +
7947 + if (access_ok(VERIFY_READ, from, n)) {
7948 + if (!__builtin_constant_p(n))
7949 + check_object_size(to, n, false);
7950 + return __copy_tofrom_user((__force void __user *)to, from, n);
7951 + }
7952 + if ((unsigned long)from < TASK_SIZE) {
7953 + over = (unsigned long)from + n - TASK_SIZE;
7954 + if (!__builtin_constant_p(n - over))
7955 + check_object_size(to, n - over, false);
7956 + return __copy_tofrom_user((__force void __user *)to, from,
7957 + n - over) + over;
7958 + }
7959 + return n;
7960 +}
7961 +
7962 +static inline unsigned long __must_check copy_to_user(void __user *to,
7963 + const void *from, unsigned long n)
7964 +{
7965 + unsigned long over;
7966 +
7967 + if ((long)n < 0)
7968 + return n;
7969 +
7970 + if (access_ok(VERIFY_WRITE, to, n)) {
7971 + if (!__builtin_constant_p(n))
7972 + check_object_size(from, n, true);
7973 + return __copy_tofrom_user(to, (__force void __user *)from, n);
7974 + }
7975 + if ((unsigned long)to < TASK_SIZE) {
7976 + over = (unsigned long)to + n - TASK_SIZE;
7977 + if (!__builtin_constant_p(n))
7978 + check_object_size(from, n - over, true);
7979 + return __copy_tofrom_user(to, (__force void __user *)from,
7980 + n - over) + over;
7981 + }
7982 + return n;
7983 +}
7984 +
7985 +#else /* __powerpc64__ */
7986 +
7987 +#define __copy_in_user(to, from, size) \
7988 + __copy_tofrom_user((to), (from), (size))
7989 +
7990 +static inline unsigned long __must_check copy_from_user(void *to, const void __user *from, unsigned long n)
7991 +{
7992 + if ((long)n < 0 || n > INT_MAX)
7993 + return n;
7994 +
7995 + if (!__builtin_constant_p(n))
7996 + check_object_size(to, n, false);
7997 +
7998 + if (likely(access_ok(VERIFY_READ, from, n)))
7999 + n = __copy_from_user(to, from, n);
8000 + else
8001 + memset(to, 0, n);
8002 + return n;
8003 +}
8004 +
8005 +static inline unsigned long __must_check copy_to_user(void __user *to, const void *from, unsigned long n)
8006 +{
8007 + if ((long)n < 0 || n > INT_MAX)
8008 + return n;
8009 +
8010 + if (likely(access_ok(VERIFY_WRITE, to, n))) {
8011 + if (!__builtin_constant_p(n))
8012 + check_object_size(from, n, true);
8013 + n = __copy_to_user(to, from, n);
8014 + }
8015 + return n;
8016 +}
8017 +
8018 +extern unsigned long copy_in_user(void __user *to, const void __user *from,
8019 + unsigned long n);
8020 +
8021 +#endif /* __powerpc64__ */
8022 +
8023 extern unsigned long __clear_user(void __user *addr, unsigned long size);
8024
8025 static inline unsigned long clear_user(void __user *addr, unsigned long size)
8026 diff --git a/arch/powerpc/kernel/exceptions-64e.S b/arch/powerpc/kernel/exceptions-64e.S
8027 index e775156..af2d1c0 100644
8028 --- a/arch/powerpc/kernel/exceptions-64e.S
8029 +++ b/arch/powerpc/kernel/exceptions-64e.S
8030 @@ -759,6 +759,7 @@ storage_fault_common:
8031 std r14,_DAR(r1)
8032 std r15,_DSISR(r1)
8033 addi r3,r1,STACK_FRAME_OVERHEAD
8034 + bl .save_nvgprs
8035 mr r4,r14
8036 mr r5,r15
8037 ld r14,PACA_EXGEN+EX_R14(r13)
8038 @@ -767,8 +768,7 @@ storage_fault_common:
8039 cmpdi r3,0
8040 bne- 1f
8041 b .ret_from_except_lite
8042 -1: bl .save_nvgprs
8043 - mr r5,r3
8044 +1: mr r5,r3
8045 addi r3,r1,STACK_FRAME_OVERHEAD
8046 ld r4,_DAR(r1)
8047 bl .bad_page_fault
8048 diff --git a/arch/powerpc/kernel/exceptions-64s.S b/arch/powerpc/kernel/exceptions-64s.S
8049 index 9f905e4..1d6b3d2 100644
8050 --- a/arch/powerpc/kernel/exceptions-64s.S
8051 +++ b/arch/powerpc/kernel/exceptions-64s.S
8052 @@ -1390,10 +1390,10 @@ handle_page_fault:
8053 11: ld r4,_DAR(r1)
8054 ld r5,_DSISR(r1)
8055 addi r3,r1,STACK_FRAME_OVERHEAD
8056 + bl .save_nvgprs
8057 bl .do_page_fault
8058 cmpdi r3,0
8059 beq+ 12f
8060 - bl .save_nvgprs
8061 mr r5,r3
8062 addi r3,r1,STACK_FRAME_OVERHEAD
8063 lwz r4,_DAR(r1)
8064 diff --git a/arch/powerpc/kernel/module_32.c b/arch/powerpc/kernel/module_32.c
8065 index 6cff040..74ac5d1 100644
8066 --- a/arch/powerpc/kernel/module_32.c
8067 +++ b/arch/powerpc/kernel/module_32.c
8068 @@ -161,7 +161,7 @@ int module_frob_arch_sections(Elf32_Ehdr *hdr,
8069 me->arch.core_plt_section = i;
8070 }
8071 if (!me->arch.core_plt_section || !me->arch.init_plt_section) {
8072 - printk("Module doesn't contain .plt or .init.plt sections.\n");
8073 + printk("Module %s doesn't contain .plt or .init.plt sections.\n", me->name);
8074 return -ENOEXEC;
8075 }
8076
8077 @@ -191,11 +191,16 @@ static uint32_t do_plt_call(void *location,
8078
8079 DEBUGP("Doing plt for call to 0x%x at 0x%x\n", val, (unsigned int)location);
8080 /* Init, or core PLT? */
8081 - if (location >= mod->module_core
8082 - && location < mod->module_core + mod->core_size)
8083 + if ((location >= mod->module_core_rx && location < mod->module_core_rx + mod->core_size_rx) ||
8084 + (location >= mod->module_core_rw && location < mod->module_core_rw + mod->core_size_rw))
8085 entry = (void *)sechdrs[mod->arch.core_plt_section].sh_addr;
8086 - else
8087 + else if ((location >= mod->module_init_rx && location < mod->module_init_rx + mod->init_size_rx) ||
8088 + (location >= mod->module_init_rw && location < mod->module_init_rw + mod->init_size_rw))
8089 entry = (void *)sechdrs[mod->arch.init_plt_section].sh_addr;
8090 + else {
8091 + printk(KERN_ERR "%s: invalid R_PPC_REL24 entry found\n", mod->name);
8092 + return ~0UL;
8093 + }
8094
8095 /* Find this entry, or if that fails, the next avail. entry */
8096 while (entry->jump[0]) {
8097 @@ -299,7 +304,7 @@ int apply_relocate_add(Elf32_Shdr *sechdrs,
8098 }
8099 #ifdef CONFIG_DYNAMIC_FTRACE
8100 module->arch.tramp =
8101 - do_plt_call(module->module_core,
8102 + do_plt_call(module->module_core_rx,
8103 (unsigned long)ftrace_caller,
8104 sechdrs, module);
8105 #endif
8106 diff --git a/arch/powerpc/kernel/process.c b/arch/powerpc/kernel/process.c
8107 index 4a96556..dd95f6c 100644
8108 --- a/arch/powerpc/kernel/process.c
8109 +++ b/arch/powerpc/kernel/process.c
8110 @@ -888,8 +888,8 @@ void show_regs(struct pt_regs * regs)
8111 * Lookup NIP late so we have the best change of getting the
8112 * above info out without failing
8113 */
8114 - printk("NIP ["REG"] %pS\n", regs->nip, (void *)regs->nip);
8115 - printk("LR ["REG"] %pS\n", regs->link, (void *)regs->link);
8116 + printk("NIP ["REG"] %pA\n", regs->nip, (void *)regs->nip);
8117 + printk("LR ["REG"] %pA\n", regs->link, (void *)regs->link);
8118 #endif
8119 show_stack(current, (unsigned long *) regs->gpr[1]);
8120 if (!user_mode(regs))
8121 @@ -1376,10 +1376,10 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8122 newsp = stack[0];
8123 ip = stack[STACK_FRAME_LR_SAVE];
8124 if (!firstframe || ip != lr) {
8125 - printk("["REG"] ["REG"] %pS", sp, ip, (void *)ip);
8126 + printk("["REG"] ["REG"] %pA", sp, ip, (void *)ip);
8127 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
8128 if ((ip == rth || ip == mrth) && curr_frame >= 0) {
8129 - printk(" (%pS)",
8130 + printk(" (%pA)",
8131 (void *)current->ret_stack[curr_frame].ret);
8132 curr_frame--;
8133 }
8134 @@ -1399,7 +1399,7 @@ void show_stack(struct task_struct *tsk, unsigned long *stack)
8135 struct pt_regs *regs = (struct pt_regs *)
8136 (sp + STACK_FRAME_OVERHEAD);
8137 lr = regs->link;
8138 - printk("--- Exception: %lx at %pS\n LR = %pS\n",
8139 + printk("--- Exception: %lx at %pA\n LR = %pA\n",
8140 regs->trap, (void *)regs->nip, (void *)lr);
8141 firstframe = 1;
8142 }
8143 @@ -1435,58 +1435,3 @@ void notrace __ppc64_runlatch_off(void)
8144 mtspr(SPRN_CTRLT, ctrl);
8145 }
8146 #endif /* CONFIG_PPC64 */
8147 -
8148 -unsigned long arch_align_stack(unsigned long sp)
8149 -{
8150 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8151 - sp -= get_random_int() & ~PAGE_MASK;
8152 - return sp & ~0xf;
8153 -}
8154 -
8155 -static inline unsigned long brk_rnd(void)
8156 -{
8157 - unsigned long rnd = 0;
8158 -
8159 - /* 8MB for 32bit, 1GB for 64bit */
8160 - if (is_32bit_task())
8161 - rnd = (long)(get_random_int() % (1<<(23-PAGE_SHIFT)));
8162 - else
8163 - rnd = (long)(get_random_int() % (1<<(30-PAGE_SHIFT)));
8164 -
8165 - return rnd << PAGE_SHIFT;
8166 -}
8167 -
8168 -unsigned long arch_randomize_brk(struct mm_struct *mm)
8169 -{
8170 - unsigned long base = mm->brk;
8171 - unsigned long ret;
8172 -
8173 -#ifdef CONFIG_PPC_STD_MMU_64
8174 - /*
8175 - * If we are using 1TB segments and we are allowed to randomise
8176 - * the heap, we can put it above 1TB so it is backed by a 1TB
8177 - * segment. Otherwise the heap will be in the bottom 1TB
8178 - * which always uses 256MB segments and this may result in a
8179 - * performance penalty.
8180 - */
8181 - if (!is_32bit_task() && (mmu_highuser_ssize == MMU_SEGSIZE_1T))
8182 - base = max_t(unsigned long, mm->brk, 1UL << SID_SHIFT_1T);
8183 -#endif
8184 -
8185 - ret = PAGE_ALIGN(base + brk_rnd());
8186 -
8187 - if (ret < mm->brk)
8188 - return mm->brk;
8189 -
8190 - return ret;
8191 -}
8192 -
8193 -unsigned long randomize_et_dyn(unsigned long base)
8194 -{
8195 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8196 -
8197 - if (ret < base)
8198 - return base;
8199 -
8200 - return ret;
8201 -}
8202 diff --git a/arch/powerpc/kernel/ptrace.c b/arch/powerpc/kernel/ptrace.c
8203 index 2e3d2bf..35df241 100644
8204 --- a/arch/powerpc/kernel/ptrace.c
8205 +++ b/arch/powerpc/kernel/ptrace.c
8206 @@ -1762,6 +1762,10 @@ long arch_ptrace(struct task_struct *child, long request,
8207 return ret;
8208 }
8209
8210 +#ifdef CONFIG_GRKERNSEC_SETXID
8211 +extern void gr_delayed_cred_worker(void);
8212 +#endif
8213 +
8214 /*
8215 * We must return the syscall number to actually look up in the table.
8216 * This can be -1L to skip running any syscall at all.
8217 @@ -1774,6 +1778,11 @@ long do_syscall_trace_enter(struct pt_regs *regs)
8218
8219 secure_computing_strict(regs->gpr[0]);
8220
8221 +#ifdef CONFIG_GRKERNSEC_SETXID
8222 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8223 + gr_delayed_cred_worker();
8224 +#endif
8225 +
8226 if (test_thread_flag(TIF_SYSCALL_TRACE) &&
8227 tracehook_report_syscall_entry(regs))
8228 /*
8229 @@ -1808,6 +1817,11 @@ void do_syscall_trace_leave(struct pt_regs *regs)
8230 {
8231 int step;
8232
8233 +#ifdef CONFIG_GRKERNSEC_SETXID
8234 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
8235 + gr_delayed_cred_worker();
8236 +#endif
8237 +
8238 audit_syscall_exit(regs);
8239
8240 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
8241 diff --git a/arch/powerpc/kernel/signal_32.c b/arch/powerpc/kernel/signal_32.c
8242 index 68027bf..b26fd31 100644
8243 --- a/arch/powerpc/kernel/signal_32.c
8244 +++ b/arch/powerpc/kernel/signal_32.c
8245 @@ -1004,7 +1004,7 @@ int handle_rt_signal32(unsigned long sig, struct k_sigaction *ka,
8246 /* Save user registers on the stack */
8247 frame = &rt_sf->uc.uc_mcontext;
8248 addr = frame;
8249 - if (vdso32_rt_sigtramp && current->mm->context.vdso_base) {
8250 + if (vdso32_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8251 sigret = 0;
8252 tramp = current->mm->context.vdso_base + vdso32_rt_sigtramp;
8253 } else {
8254 diff --git a/arch/powerpc/kernel/signal_64.c b/arch/powerpc/kernel/signal_64.c
8255 index 4299104..29e2c51 100644
8256 --- a/arch/powerpc/kernel/signal_64.c
8257 +++ b/arch/powerpc/kernel/signal_64.c
8258 @@ -758,7 +758,7 @@ int handle_rt_signal64(int signr, struct k_sigaction *ka, siginfo_t *info,
8259 #endif
8260
8261 /* Set up to return from userspace. */
8262 - if (vdso64_rt_sigtramp && current->mm->context.vdso_base) {
8263 + if (vdso64_rt_sigtramp && current->mm->context.vdso_base != ~0UL) {
8264 regs->link = current->mm->context.vdso_base + vdso64_rt_sigtramp;
8265 } else {
8266 err |= setup_trampoline(__NR_rt_sigreturn, &frame->tramp[0]);
8267 diff --git a/arch/powerpc/kernel/traps.c b/arch/powerpc/kernel/traps.c
8268 index 907a472..4ba206f 100644
8269 --- a/arch/powerpc/kernel/traps.c
8270 +++ b/arch/powerpc/kernel/traps.c
8271 @@ -142,6 +142,8 @@ static unsigned __kprobes long oops_begin(struct pt_regs *regs)
8272 return flags;
8273 }
8274
8275 +extern void gr_handle_kernel_exploit(void);
8276 +
8277 static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8278 int signr)
8279 {
8280 @@ -191,6 +193,9 @@ static void __kprobes oops_end(unsigned long flags, struct pt_regs *regs,
8281 panic("Fatal exception in interrupt");
8282 if (panic_on_oops)
8283 panic("Fatal exception");
8284 +
8285 + gr_handle_kernel_exploit();
8286 +
8287 do_exit(signr);
8288 }
8289
8290 diff --git a/arch/powerpc/kernel/vdso.c b/arch/powerpc/kernel/vdso.c
8291 index 094e45c..d82b848 100644
8292 --- a/arch/powerpc/kernel/vdso.c
8293 +++ b/arch/powerpc/kernel/vdso.c
8294 @@ -35,6 +35,7 @@
8295 #include <asm/vdso.h>
8296 #include <asm/vdso_datapage.h>
8297 #include <asm/setup.h>
8298 +#include <asm/mman.h>
8299
8300 #undef DEBUG
8301
8302 @@ -221,7 +222,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8303 vdso_base = VDSO32_MBASE;
8304 #endif
8305
8306 - current->mm->context.vdso_base = 0;
8307 + current->mm->context.vdso_base = ~0UL;
8308
8309 /* vDSO has a problem and was disabled, just don't "enable" it for the
8310 * process
8311 @@ -241,7 +242,7 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
8312 vdso_base = get_unmapped_area(NULL, vdso_base,
8313 (vdso_pages << PAGE_SHIFT) +
8314 ((VDSO_ALIGNMENT - 1) & PAGE_MASK),
8315 - 0, 0);
8316 + 0, MAP_PRIVATE | MAP_EXECUTABLE);
8317 if (IS_ERR_VALUE(vdso_base)) {
8318 rc = vdso_base;
8319 goto fail_mmapsem;
8320 diff --git a/arch/powerpc/lib/usercopy_64.c b/arch/powerpc/lib/usercopy_64.c
8321 index 5eea6f3..5d10396 100644
8322 --- a/arch/powerpc/lib/usercopy_64.c
8323 +++ b/arch/powerpc/lib/usercopy_64.c
8324 @@ -9,22 +9,6 @@
8325 #include <linux/module.h>
8326 #include <asm/uaccess.h>
8327
8328 -unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
8329 -{
8330 - if (likely(access_ok(VERIFY_READ, from, n)))
8331 - n = __copy_from_user(to, from, n);
8332 - else
8333 - memset(to, 0, n);
8334 - return n;
8335 -}
8336 -
8337 -unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
8338 -{
8339 - if (likely(access_ok(VERIFY_WRITE, to, n)))
8340 - n = __copy_to_user(to, from, n);
8341 - return n;
8342 -}
8343 -
8344 unsigned long copy_in_user(void __user *to, const void __user *from,
8345 unsigned long n)
8346 {
8347 @@ -35,7 +19,5 @@ unsigned long copy_in_user(void __user *to, const void __user *from,
8348 return n;
8349 }
8350
8351 -EXPORT_SYMBOL(copy_from_user);
8352 -EXPORT_SYMBOL(copy_to_user);
8353 EXPORT_SYMBOL(copy_in_user);
8354
8355 diff --git a/arch/powerpc/mm/fault.c b/arch/powerpc/mm/fault.c
8356 index 51ab9e7..7d3c78b 100644
8357 --- a/arch/powerpc/mm/fault.c
8358 +++ b/arch/powerpc/mm/fault.c
8359 @@ -33,6 +33,10 @@
8360 #include <linux/magic.h>
8361 #include <linux/ratelimit.h>
8362 #include <linux/context_tracking.h>
8363 +#include <linux/slab.h>
8364 +#include <linux/pagemap.h>
8365 +#include <linux/compiler.h>
8366 +#include <linux/unistd.h>
8367
8368 #include <asm/firmware.h>
8369 #include <asm/page.h>
8370 @@ -69,6 +73,33 @@ static inline int notify_page_fault(struct pt_regs *regs)
8371 }
8372 #endif
8373
8374 +#ifdef CONFIG_PAX_PAGEEXEC
8375 +/*
8376 + * PaX: decide what to do with offenders (regs->nip = fault address)
8377 + *
8378 + * returns 1 when task should be killed
8379 + */
8380 +static int pax_handle_fetch_fault(struct pt_regs *regs)
8381 +{
8382 + return 1;
8383 +}
8384 +
8385 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
8386 +{
8387 + unsigned long i;
8388 +
8389 + printk(KERN_ERR "PAX: bytes at PC: ");
8390 + for (i = 0; i < 5; i++) {
8391 + unsigned int c;
8392 + if (get_user(c, (unsigned int __user *)pc+i))
8393 + printk(KERN_CONT "???????? ");
8394 + else
8395 + printk(KERN_CONT "%08x ", c);
8396 + }
8397 + printk("\n");
8398 +}
8399 +#endif
8400 +
8401 /*
8402 * Check whether the instruction at regs->nip is a store using
8403 * an update addressing form which will update r1.
8404 @@ -216,7 +247,7 @@ int __kprobes do_page_fault(struct pt_regs *regs, unsigned long address,
8405 * indicate errors in DSISR but can validly be set in SRR1.
8406 */
8407 if (trap == 0x400)
8408 - error_code &= 0x48200000;
8409 + error_code &= 0x58200000;
8410 else
8411 is_write = error_code & DSISR_ISSTORE;
8412 #else
8413 @@ -378,7 +409,7 @@ good_area:
8414 * "undefined". Of those that can be set, this is the only
8415 * one which seems bad.
8416 */
8417 - if (error_code & 0x10000000)
8418 + if (error_code & DSISR_GUARDED)
8419 /* Guarded storage error. */
8420 goto bad_area;
8421 #endif /* CONFIG_8xx */
8422 @@ -393,7 +424,7 @@ good_area:
8423 * processors use the same I/D cache coherency mechanism
8424 * as embedded.
8425 */
8426 - if (error_code & DSISR_PROTFAULT)
8427 + if (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))
8428 goto bad_area;
8429 #endif /* CONFIG_PPC_STD_MMU */
8430
8431 @@ -483,6 +514,23 @@ bad_area:
8432 bad_area_nosemaphore:
8433 /* User mode accesses cause a SIGSEGV */
8434 if (user_mode(regs)) {
8435 +
8436 +#ifdef CONFIG_PAX_PAGEEXEC
8437 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
8438 +#ifdef CONFIG_PPC_STD_MMU
8439 + if (is_exec && (error_code & (DSISR_PROTFAULT | DSISR_GUARDED))) {
8440 +#else
8441 + if (is_exec && regs->nip == address) {
8442 +#endif
8443 + switch (pax_handle_fetch_fault(regs)) {
8444 + }
8445 +
8446 + pax_report_fault(regs, (void *)regs->nip, (void *)regs->gpr[PT_R1]);
8447 + do_group_exit(SIGKILL);
8448 + }
8449 + }
8450 +#endif
8451 +
8452 _exception(SIGSEGV, regs, code, address);
8453 goto bail;
8454 }
8455 diff --git a/arch/powerpc/mm/mmap.c b/arch/powerpc/mm/mmap.c
8456 index cb8bdbe..d770680 100644
8457 --- a/arch/powerpc/mm/mmap.c
8458 +++ b/arch/powerpc/mm/mmap.c
8459 @@ -57,6 +57,10 @@ static unsigned long mmap_rnd(void)
8460 {
8461 unsigned long rnd = 0;
8462
8463 +#ifdef CONFIG_PAX_RANDMMAP
8464 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8465 +#endif
8466 +
8467 if (current->flags & PF_RANDOMIZE) {
8468 /* 8MB for 32bit, 1GB for 64bit */
8469 if (is_32bit_task())
8470 @@ -91,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8471 */
8472 if (mmap_is_legacy()) {
8473 mm->mmap_base = TASK_UNMAPPED_BASE;
8474 +
8475 +#ifdef CONFIG_PAX_RANDMMAP
8476 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8477 + mm->mmap_base += mm->delta_mmap;
8478 +#endif
8479 +
8480 mm->get_unmapped_area = arch_get_unmapped_area;
8481 } else {
8482 mm->mmap_base = mmap_base();
8483 +
8484 +#ifdef CONFIG_PAX_RANDMMAP
8485 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8486 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8487 +#endif
8488 +
8489 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8490 }
8491 }
8492 diff --git a/arch/powerpc/mm/slice.c b/arch/powerpc/mm/slice.c
8493 index 7ce9cf3..a964087 100644
8494 --- a/arch/powerpc/mm/slice.c
8495 +++ b/arch/powerpc/mm/slice.c
8496 @@ -103,7 +103,7 @@ static int slice_area_is_free(struct mm_struct *mm, unsigned long addr,
8497 if ((mm->task_size - len) < addr)
8498 return 0;
8499 vma = find_vma(mm, addr);
8500 - return (!vma || (addr + len) <= vma->vm_start);
8501 + return check_heap_stack_gap(vma, addr, len, 0);
8502 }
8503
8504 static int slice_low_has_vma(struct mm_struct *mm, unsigned long slice)
8505 @@ -277,6 +277,12 @@ static unsigned long slice_find_area_bottomup(struct mm_struct *mm,
8506 info.align_offset = 0;
8507
8508 addr = TASK_UNMAPPED_BASE;
8509 +
8510 +#ifdef CONFIG_PAX_RANDMMAP
8511 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8512 + addr += mm->delta_mmap;
8513 +#endif
8514 +
8515 while (addr < TASK_SIZE) {
8516 info.low_limit = addr;
8517 if (!slice_scan_available(addr, available, 1, &addr))
8518 @@ -410,6 +416,11 @@ unsigned long slice_get_unmapped_area(unsigned long addr, unsigned long len,
8519 if (fixed && addr > (mm->task_size - len))
8520 return -EINVAL;
8521
8522 +#ifdef CONFIG_PAX_RANDMMAP
8523 + if (!fixed && (mm->pax_flags & MF_PAX_RANDMMAP))
8524 + addr = 0;
8525 +#endif
8526 +
8527 /* If hint, make sure it matches our alignment restrictions */
8528 if (!fixed && addr) {
8529 addr = _ALIGN_UP(addr, 1ul << pshift);
8530 diff --git a/arch/powerpc/platforms/cell/spufs/file.c b/arch/powerpc/platforms/cell/spufs/file.c
8531 index 9098692..3d54cd1 100644
8532 --- a/arch/powerpc/platforms/cell/spufs/file.c
8533 +++ b/arch/powerpc/platforms/cell/spufs/file.c
8534 @@ -280,9 +280,9 @@ spufs_mem_mmap_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
8535 return VM_FAULT_NOPAGE;
8536 }
8537
8538 -static int spufs_mem_mmap_access(struct vm_area_struct *vma,
8539 +static ssize_t spufs_mem_mmap_access(struct vm_area_struct *vma,
8540 unsigned long address,
8541 - void *buf, int len, int write)
8542 + void *buf, size_t len, int write)
8543 {
8544 struct spu_context *ctx = vma->vm_file->private_data;
8545 unsigned long offset = address - vma->vm_start;
8546 diff --git a/arch/s390/include/asm/atomic.h b/arch/s390/include/asm/atomic.h
8547 index fa9aaf7..3f5d836 100644
8548 --- a/arch/s390/include/asm/atomic.h
8549 +++ b/arch/s390/include/asm/atomic.h
8550 @@ -398,6 +398,16 @@ static inline long long atomic64_dec_if_positive(atomic64_t *v)
8551 #define atomic64_dec_and_test(_v) (atomic64_sub_return(1, _v) == 0)
8552 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
8553
8554 +#define atomic64_read_unchecked(v) atomic64_read(v)
8555 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
8556 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
8557 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
8558 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
8559 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
8560 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
8561 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
8562 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
8563 +
8564 #define smp_mb__before_atomic_dec() smp_mb()
8565 #define smp_mb__after_atomic_dec() smp_mb()
8566 #define smp_mb__before_atomic_inc() smp_mb()
8567 diff --git a/arch/s390/include/asm/cache.h b/arch/s390/include/asm/cache.h
8568 index 4d7ccac..d03d0ad 100644
8569 --- a/arch/s390/include/asm/cache.h
8570 +++ b/arch/s390/include/asm/cache.h
8571 @@ -9,8 +9,10 @@
8572 #ifndef __ARCH_S390_CACHE_H
8573 #define __ARCH_S390_CACHE_H
8574
8575 -#define L1_CACHE_BYTES 256
8576 +#include <linux/const.h>
8577 +
8578 #define L1_CACHE_SHIFT 8
8579 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8580 #define NET_SKB_PAD 32
8581
8582 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8583 diff --git a/arch/s390/include/asm/elf.h b/arch/s390/include/asm/elf.h
8584 index 78f4f87..598ce39 100644
8585 --- a/arch/s390/include/asm/elf.h
8586 +++ b/arch/s390/include/asm/elf.h
8587 @@ -162,8 +162,14 @@ extern unsigned int vdso_enabled;
8588 the loader. We need to make sure that it is out of the way of the program
8589 that it will "exec", and that there is sufficient room for the brk. */
8590
8591 -extern unsigned long randomize_et_dyn(unsigned long base);
8592 -#define ELF_ET_DYN_BASE (randomize_et_dyn(STACK_TOP / 3 * 2))
8593 +#define ELF_ET_DYN_BASE (STACK_TOP / 3 * 2)
8594 +
8595 +#ifdef CONFIG_PAX_ASLR
8596 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_31BIT) ? 0x10000UL : 0x80000000UL)
8597 +
8598 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8599 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_31BIT) ? 15 : 26)
8600 +#endif
8601
8602 /* This yields a mask that user programs can use to figure out what
8603 instruction set this CPU supports. */
8604 @@ -222,9 +228,6 @@ struct linux_binprm;
8605 #define ARCH_HAS_SETUP_ADDITIONAL_PAGES 1
8606 int arch_setup_additional_pages(struct linux_binprm *, int);
8607
8608 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
8609 -#define arch_randomize_brk arch_randomize_brk
8610 -
8611 void *fill_cpu_elf_notes(void *ptr, struct save_area *sa);
8612
8613 #endif
8614 diff --git a/arch/s390/include/asm/exec.h b/arch/s390/include/asm/exec.h
8615 index c4a93d6..4d2a9b4 100644
8616 --- a/arch/s390/include/asm/exec.h
8617 +++ b/arch/s390/include/asm/exec.h
8618 @@ -7,6 +7,6 @@
8619 #ifndef __ASM_EXEC_H
8620 #define __ASM_EXEC_H
8621
8622 -extern unsigned long arch_align_stack(unsigned long sp);
8623 +#define arch_align_stack(x) ((x) & ~0xfUL)
8624
8625 #endif /* __ASM_EXEC_H */
8626 diff --git a/arch/s390/include/asm/uaccess.h b/arch/s390/include/asm/uaccess.h
8627 index 79330af..a3a7b06 100644
8628 --- a/arch/s390/include/asm/uaccess.h
8629 +++ b/arch/s390/include/asm/uaccess.h
8630 @@ -245,6 +245,10 @@ static inline unsigned long __must_check
8631 copy_to_user(void __user *to, const void *from, unsigned long n)
8632 {
8633 might_fault();
8634 +
8635 + if ((long)n < 0)
8636 + return n;
8637 +
8638 return __copy_to_user(to, from, n);
8639 }
8640
8641 @@ -268,6 +272,9 @@ copy_to_user(void __user *to, const void *from, unsigned long n)
8642 static inline unsigned long __must_check
8643 __copy_from_user(void *to, const void __user *from, unsigned long n)
8644 {
8645 + if ((long)n < 0)
8646 + return n;
8647 +
8648 return uaccess.copy_from_user(n, from, to);
8649 }
8650
8651 @@ -296,10 +303,14 @@ __compiletime_warning("copy_from_user() buffer size is not provably correct")
8652 static inline unsigned long __must_check
8653 copy_from_user(void *to, const void __user *from, unsigned long n)
8654 {
8655 - unsigned int sz = __compiletime_object_size(to);
8656 + size_t sz = __compiletime_object_size(to);
8657
8658 might_fault();
8659 - if (unlikely(sz != -1 && sz < n)) {
8660 +
8661 + if ((long)n < 0)
8662 + return n;
8663 +
8664 + if (unlikely(sz != (size_t)-1 && sz < n)) {
8665 copy_from_user_overflow();
8666 return n;
8667 }
8668 diff --git a/arch/s390/kernel/module.c b/arch/s390/kernel/module.c
8669 index b89b591..fd9609d 100644
8670 --- a/arch/s390/kernel/module.c
8671 +++ b/arch/s390/kernel/module.c
8672 @@ -169,11 +169,11 @@ int module_frob_arch_sections(Elf_Ehdr *hdr, Elf_Shdr *sechdrs,
8673
8674 /* Increase core size by size of got & plt and set start
8675 offsets for got and plt. */
8676 - me->core_size = ALIGN(me->core_size, 4);
8677 - me->arch.got_offset = me->core_size;
8678 - me->core_size += me->arch.got_size;
8679 - me->arch.plt_offset = me->core_size;
8680 - me->core_size += me->arch.plt_size;
8681 + me->core_size_rw = ALIGN(me->core_size_rw, 4);
8682 + me->arch.got_offset = me->core_size_rw;
8683 + me->core_size_rw += me->arch.got_size;
8684 + me->arch.plt_offset = me->core_size_rx;
8685 + me->core_size_rx += me->arch.plt_size;
8686 return 0;
8687 }
8688
8689 @@ -289,7 +289,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8690 if (info->got_initialized == 0) {
8691 Elf_Addr *gotent;
8692
8693 - gotent = me->module_core + me->arch.got_offset +
8694 + gotent = me->module_core_rw + me->arch.got_offset +
8695 info->got_offset;
8696 *gotent = val;
8697 info->got_initialized = 1;
8698 @@ -312,7 +312,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8699 rc = apply_rela_bits(loc, val, 0, 64, 0);
8700 else if (r_type == R_390_GOTENT ||
8701 r_type == R_390_GOTPLTENT) {
8702 - val += (Elf_Addr) me->module_core - loc;
8703 + val += (Elf_Addr) me->module_core_rw - loc;
8704 rc = apply_rela_bits(loc, val, 1, 32, 1);
8705 }
8706 break;
8707 @@ -325,7 +325,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8708 case R_390_PLTOFF64: /* 16 bit offset from GOT to PLT. */
8709 if (info->plt_initialized == 0) {
8710 unsigned int *ip;
8711 - ip = me->module_core + me->arch.plt_offset +
8712 + ip = me->module_core_rx + me->arch.plt_offset +
8713 info->plt_offset;
8714 #ifndef CONFIG_64BIT
8715 ip[0] = 0x0d105810; /* basr 1,0; l 1,6(1); br 1 */
8716 @@ -350,7 +350,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8717 val - loc + 0xffffUL < 0x1ffffeUL) ||
8718 (r_type == R_390_PLT32DBL &&
8719 val - loc + 0xffffffffULL < 0x1fffffffeULL)))
8720 - val = (Elf_Addr) me->module_core +
8721 + val = (Elf_Addr) me->module_core_rx +
8722 me->arch.plt_offset +
8723 info->plt_offset;
8724 val += rela->r_addend - loc;
8725 @@ -372,7 +372,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8726 case R_390_GOTOFF32: /* 32 bit offset to GOT. */
8727 case R_390_GOTOFF64: /* 64 bit offset to GOT. */
8728 val = val + rela->r_addend -
8729 - ((Elf_Addr) me->module_core + me->arch.got_offset);
8730 + ((Elf_Addr) me->module_core_rw + me->arch.got_offset);
8731 if (r_type == R_390_GOTOFF16)
8732 rc = apply_rela_bits(loc, val, 0, 16, 0);
8733 else if (r_type == R_390_GOTOFF32)
8734 @@ -382,7 +382,7 @@ static int apply_rela(Elf_Rela *rela, Elf_Addr base, Elf_Sym *symtab,
8735 break;
8736 case R_390_GOTPC: /* 32 bit PC relative offset to GOT. */
8737 case R_390_GOTPCDBL: /* 32 bit PC rel. off. to GOT shifted by 1. */
8738 - val = (Elf_Addr) me->module_core + me->arch.got_offset +
8739 + val = (Elf_Addr) me->module_core_rw + me->arch.got_offset +
8740 rela->r_addend - loc;
8741 if (r_type == R_390_GOTPC)
8742 rc = apply_rela_bits(loc, val, 1, 32, 0);
8743 diff --git a/arch/s390/kernel/process.c b/arch/s390/kernel/process.c
8744 index 7ed0d4e..1dfc145 100644
8745 --- a/arch/s390/kernel/process.c
8746 +++ b/arch/s390/kernel/process.c
8747 @@ -242,39 +242,3 @@ unsigned long get_wchan(struct task_struct *p)
8748 }
8749 return 0;
8750 }
8751 -
8752 -unsigned long arch_align_stack(unsigned long sp)
8753 -{
8754 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
8755 - sp -= get_random_int() & ~PAGE_MASK;
8756 - return sp & ~0xf;
8757 -}
8758 -
8759 -static inline unsigned long brk_rnd(void)
8760 -{
8761 - /* 8MB for 32bit, 1GB for 64bit */
8762 - if (is_32bit_task())
8763 - return (get_random_int() & 0x7ffUL) << PAGE_SHIFT;
8764 - else
8765 - return (get_random_int() & 0x3ffffUL) << PAGE_SHIFT;
8766 -}
8767 -
8768 -unsigned long arch_randomize_brk(struct mm_struct *mm)
8769 -{
8770 - unsigned long ret = PAGE_ALIGN(mm->brk + brk_rnd());
8771 -
8772 - if (ret < mm->brk)
8773 - return mm->brk;
8774 - return ret;
8775 -}
8776 -
8777 -unsigned long randomize_et_dyn(unsigned long base)
8778 -{
8779 - unsigned long ret = PAGE_ALIGN(base + brk_rnd());
8780 -
8781 - if (!(current->flags & PF_RANDOMIZE))
8782 - return base;
8783 - if (ret < base)
8784 - return base;
8785 - return ret;
8786 -}
8787 diff --git a/arch/s390/mm/mmap.c b/arch/s390/mm/mmap.c
8788 index 9b436c2..54fbf0a 100644
8789 --- a/arch/s390/mm/mmap.c
8790 +++ b/arch/s390/mm/mmap.c
8791 @@ -95,9 +95,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8792 */
8793 if (mmap_is_legacy()) {
8794 mm->mmap_base = mmap_base_legacy();
8795 +
8796 +#ifdef CONFIG_PAX_RANDMMAP
8797 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8798 + mm->mmap_base += mm->delta_mmap;
8799 +#endif
8800 +
8801 mm->get_unmapped_area = arch_get_unmapped_area;
8802 } else {
8803 mm->mmap_base = mmap_base();
8804 +
8805 +#ifdef CONFIG_PAX_RANDMMAP
8806 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8807 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8808 +#endif
8809 +
8810 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
8811 }
8812 }
8813 @@ -170,9 +182,21 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
8814 */
8815 if (mmap_is_legacy()) {
8816 mm->mmap_base = mmap_base_legacy();
8817 +
8818 +#ifdef CONFIG_PAX_RANDMMAP
8819 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8820 + mm->mmap_base += mm->delta_mmap;
8821 +#endif
8822 +
8823 mm->get_unmapped_area = s390_get_unmapped_area;
8824 } else {
8825 mm->mmap_base = mmap_base();
8826 +
8827 +#ifdef CONFIG_PAX_RANDMMAP
8828 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8829 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
8830 +#endif
8831 +
8832 mm->get_unmapped_area = s390_get_unmapped_area_topdown;
8833 }
8834 }
8835 diff --git a/arch/score/include/asm/cache.h b/arch/score/include/asm/cache.h
8836 index ae3d59f..f65f075 100644
8837 --- a/arch/score/include/asm/cache.h
8838 +++ b/arch/score/include/asm/cache.h
8839 @@ -1,7 +1,9 @@
8840 #ifndef _ASM_SCORE_CACHE_H
8841 #define _ASM_SCORE_CACHE_H
8842
8843 +#include <linux/const.h>
8844 +
8845 #define L1_CACHE_SHIFT 4
8846 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8847 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8848
8849 #endif /* _ASM_SCORE_CACHE_H */
8850 diff --git a/arch/score/include/asm/exec.h b/arch/score/include/asm/exec.h
8851 index f9f3cd5..58ff438 100644
8852 --- a/arch/score/include/asm/exec.h
8853 +++ b/arch/score/include/asm/exec.h
8854 @@ -1,6 +1,6 @@
8855 #ifndef _ASM_SCORE_EXEC_H
8856 #define _ASM_SCORE_EXEC_H
8857
8858 -extern unsigned long arch_align_stack(unsigned long sp);
8859 +#define arch_align_stack(x) (x)
8860
8861 #endif /* _ASM_SCORE_EXEC_H */
8862 diff --git a/arch/score/kernel/process.c b/arch/score/kernel/process.c
8863 index a1519ad3..e8ac1ff 100644
8864 --- a/arch/score/kernel/process.c
8865 +++ b/arch/score/kernel/process.c
8866 @@ -116,8 +116,3 @@ unsigned long get_wchan(struct task_struct *task)
8867
8868 return task_pt_regs(task)->cp0_epc;
8869 }
8870 -
8871 -unsigned long arch_align_stack(unsigned long sp)
8872 -{
8873 - return sp;
8874 -}
8875 diff --git a/arch/sh/include/asm/cache.h b/arch/sh/include/asm/cache.h
8876 index ef9e555..331bd29 100644
8877 --- a/arch/sh/include/asm/cache.h
8878 +++ b/arch/sh/include/asm/cache.h
8879 @@ -9,10 +9,11 @@
8880 #define __ASM_SH_CACHE_H
8881 #ifdef __KERNEL__
8882
8883 +#include <linux/const.h>
8884 #include <linux/init.h>
8885 #include <cpu/cache.h>
8886
8887 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
8888 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
8889
8890 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
8891
8892 diff --git a/arch/sh/mm/mmap.c b/arch/sh/mm/mmap.c
8893 index 6777177..cb5e44f 100644
8894 --- a/arch/sh/mm/mmap.c
8895 +++ b/arch/sh/mm/mmap.c
8896 @@ -36,6 +36,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8897 struct mm_struct *mm = current->mm;
8898 struct vm_area_struct *vma;
8899 int do_colour_align;
8900 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8901 struct vm_unmapped_area_info info;
8902
8903 if (flags & MAP_FIXED) {
8904 @@ -55,6 +56,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8905 if (filp || (flags & MAP_SHARED))
8906 do_colour_align = 1;
8907
8908 +#ifdef CONFIG_PAX_RANDMMAP
8909 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8910 +#endif
8911 +
8912 if (addr) {
8913 if (do_colour_align)
8914 addr = COLOUR_ALIGN(addr, pgoff);
8915 @@ -62,14 +67,13 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr,
8916 addr = PAGE_ALIGN(addr);
8917
8918 vma = find_vma(mm, addr);
8919 - if (TASK_SIZE - len >= addr &&
8920 - (!vma || addr + len <= vma->vm_start))
8921 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8922 return addr;
8923 }
8924
8925 info.flags = 0;
8926 info.length = len;
8927 - info.low_limit = TASK_UNMAPPED_BASE;
8928 + info.low_limit = mm->mmap_base;
8929 info.high_limit = TASK_SIZE;
8930 info.align_mask = do_colour_align ? (PAGE_MASK & shm_align_mask) : 0;
8931 info.align_offset = pgoff << PAGE_SHIFT;
8932 @@ -85,6 +89,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8933 struct mm_struct *mm = current->mm;
8934 unsigned long addr = addr0;
8935 int do_colour_align;
8936 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
8937 struct vm_unmapped_area_info info;
8938
8939 if (flags & MAP_FIXED) {
8940 @@ -104,6 +109,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8941 if (filp || (flags & MAP_SHARED))
8942 do_colour_align = 1;
8943
8944 +#ifdef CONFIG_PAX_RANDMMAP
8945 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
8946 +#endif
8947 +
8948 /* requesting a specific address */
8949 if (addr) {
8950 if (do_colour_align)
8951 @@ -112,8 +121,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8952 addr = PAGE_ALIGN(addr);
8953
8954 vma = find_vma(mm, addr);
8955 - if (TASK_SIZE - len >= addr &&
8956 - (!vma || addr + len <= vma->vm_start))
8957 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
8958 return addr;
8959 }
8960
8961 @@ -135,6 +143,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
8962 VM_BUG_ON(addr != -ENOMEM);
8963 info.flags = 0;
8964 info.low_limit = TASK_UNMAPPED_BASE;
8965 +
8966 +#ifdef CONFIG_PAX_RANDMMAP
8967 + if (mm->pax_flags & MF_PAX_RANDMMAP)
8968 + info.low_limit += mm->delta_mmap;
8969 +#endif
8970 +
8971 info.high_limit = TASK_SIZE;
8972 addr = vm_unmapped_area(&info);
8973 }
8974 diff --git a/arch/sparc/include/asm/atomic_64.h b/arch/sparc/include/asm/atomic_64.h
8975 index be56a24..443328f 100644
8976 --- a/arch/sparc/include/asm/atomic_64.h
8977 +++ b/arch/sparc/include/asm/atomic_64.h
8978 @@ -14,18 +14,40 @@
8979 #define ATOMIC64_INIT(i) { (i) }
8980
8981 #define atomic_read(v) (*(volatile int *)&(v)->counter)
8982 +static inline int atomic_read_unchecked(const atomic_unchecked_t *v)
8983 +{
8984 + return v->counter;
8985 +}
8986 #define atomic64_read(v) (*(volatile long *)&(v)->counter)
8987 +static inline long atomic64_read_unchecked(const atomic64_unchecked_t *v)
8988 +{
8989 + return v->counter;
8990 +}
8991
8992 #define atomic_set(v, i) (((v)->counter) = i)
8993 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
8994 +{
8995 + v->counter = i;
8996 +}
8997 #define atomic64_set(v, i) (((v)->counter) = i)
8998 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
8999 +{
9000 + v->counter = i;
9001 +}
9002
9003 extern void atomic_add(int, atomic_t *);
9004 +extern void atomic_add_unchecked(int, atomic_unchecked_t *);
9005 extern void atomic64_add(long, atomic64_t *);
9006 +extern void atomic64_add_unchecked(long, atomic64_unchecked_t *);
9007 extern void atomic_sub(int, atomic_t *);
9008 +extern void atomic_sub_unchecked(int, atomic_unchecked_t *);
9009 extern void atomic64_sub(long, atomic64_t *);
9010 +extern void atomic64_sub_unchecked(long, atomic64_unchecked_t *);
9011
9012 extern int atomic_add_ret(int, atomic_t *);
9013 +extern int atomic_add_ret_unchecked(int, atomic_unchecked_t *);
9014 extern long atomic64_add_ret(long, atomic64_t *);
9015 +extern long atomic64_add_ret_unchecked(long, atomic64_unchecked_t *);
9016 extern int atomic_sub_ret(int, atomic_t *);
9017 extern long atomic64_sub_ret(long, atomic64_t *);
9018
9019 @@ -33,13 +55,29 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9020 #define atomic64_dec_return(v) atomic64_sub_ret(1, v)
9021
9022 #define atomic_inc_return(v) atomic_add_ret(1, v)
9023 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
9024 +{
9025 + return atomic_add_ret_unchecked(1, v);
9026 +}
9027 #define atomic64_inc_return(v) atomic64_add_ret(1, v)
9028 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
9029 +{
9030 + return atomic64_add_ret_unchecked(1, v);
9031 +}
9032
9033 #define atomic_sub_return(i, v) atomic_sub_ret(i, v)
9034 #define atomic64_sub_return(i, v) atomic64_sub_ret(i, v)
9035
9036 #define atomic_add_return(i, v) atomic_add_ret(i, v)
9037 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
9038 +{
9039 + return atomic_add_ret_unchecked(i, v);
9040 +}
9041 #define atomic64_add_return(i, v) atomic64_add_ret(i, v)
9042 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
9043 +{
9044 + return atomic64_add_ret_unchecked(i, v);
9045 +}
9046
9047 /*
9048 * atomic_inc_and_test - increment and test
9049 @@ -50,6 +88,10 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9050 * other cases.
9051 */
9052 #define atomic_inc_and_test(v) (atomic_inc_return(v) == 0)
9053 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
9054 +{
9055 + return atomic_inc_return_unchecked(v) == 0;
9056 +}
9057 #define atomic64_inc_and_test(v) (atomic64_inc_return(v) == 0)
9058
9059 #define atomic_sub_and_test(i, v) (atomic_sub_ret(i, v) == 0)
9060 @@ -59,25 +101,60 @@ extern long atomic64_sub_ret(long, atomic64_t *);
9061 #define atomic64_dec_and_test(v) (atomic64_sub_ret(1, v) == 0)
9062
9063 #define atomic_inc(v) atomic_add(1, v)
9064 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
9065 +{
9066 + atomic_add_unchecked(1, v);
9067 +}
9068 #define atomic64_inc(v) atomic64_add(1, v)
9069 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
9070 +{
9071 + atomic64_add_unchecked(1, v);
9072 +}
9073
9074 #define atomic_dec(v) atomic_sub(1, v)
9075 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
9076 +{
9077 + atomic_sub_unchecked(1, v);
9078 +}
9079 #define atomic64_dec(v) atomic64_sub(1, v)
9080 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
9081 +{
9082 + atomic64_sub_unchecked(1, v);
9083 +}
9084
9085 #define atomic_add_negative(i, v) (atomic_add_ret(i, v) < 0)
9086 #define atomic64_add_negative(i, v) (atomic64_add_ret(i, v) < 0)
9087
9088 #define atomic_cmpxchg(v, o, n) (cmpxchg(&((v)->counter), (o), (n)))
9089 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
9090 +{
9091 + return cmpxchg(&v->counter, old, new);
9092 +}
9093 #define atomic_xchg(v, new) (xchg(&((v)->counter), new))
9094 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
9095 +{
9096 + return xchg(&v->counter, new);
9097 +}
9098
9099 static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9100 {
9101 - int c, old;
9102 + int c, old, new;
9103 c = atomic_read(v);
9104 for (;;) {
9105 - if (unlikely(c == (u)))
9106 + if (unlikely(c == u))
9107 break;
9108 - old = atomic_cmpxchg((v), c, c + (a));
9109 +
9110 + asm volatile("addcc %2, %0, %0\n"
9111 +
9112 +#ifdef CONFIG_PAX_REFCOUNT
9113 + "tvs %%icc, 6\n"
9114 +#endif
9115 +
9116 + : "=r" (new)
9117 + : "0" (c), "ir" (a)
9118 + : "cc");
9119 +
9120 + old = atomic_cmpxchg(v, c, new);
9121 if (likely(old == c))
9122 break;
9123 c = old;
9124 @@ -88,20 +165,35 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
9125 #define atomic64_cmpxchg(v, o, n) \
9126 ((__typeof__((v)->counter))cmpxchg(&((v)->counter), (o), (n)))
9127 #define atomic64_xchg(v, new) (xchg(&((v)->counter), new))
9128 +static inline long atomic64_xchg_unchecked(atomic64_unchecked_t *v, long new)
9129 +{
9130 + return xchg(&v->counter, new);
9131 +}
9132
9133 static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
9134 {
9135 - long c, old;
9136 + long c, old, new;
9137 c = atomic64_read(v);
9138 for (;;) {
9139 - if (unlikely(c == (u)))
9140 + if (unlikely(c == u))
9141 break;
9142 - old = atomic64_cmpxchg((v), c, c + (a));
9143 +
9144 + asm volatile("addcc %2, %0, %0\n"
9145 +
9146 +#ifdef CONFIG_PAX_REFCOUNT
9147 + "tvs %%xcc, 6\n"
9148 +#endif
9149 +
9150 + : "=r" (new)
9151 + : "0" (c), "ir" (a)
9152 + : "cc");
9153 +
9154 + old = atomic64_cmpxchg(v, c, new);
9155 if (likely(old == c))
9156 break;
9157 c = old;
9158 }
9159 - return c != (u);
9160 + return c != u;
9161 }
9162
9163 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
9164 diff --git a/arch/sparc/include/asm/cache.h b/arch/sparc/include/asm/cache.h
9165 index 5bb6991..5c2132e 100644
9166 --- a/arch/sparc/include/asm/cache.h
9167 +++ b/arch/sparc/include/asm/cache.h
9168 @@ -7,10 +7,12 @@
9169 #ifndef _SPARC_CACHE_H
9170 #define _SPARC_CACHE_H
9171
9172 +#include <linux/const.h>
9173 +
9174 #define ARCH_SLAB_MINALIGN __alignof__(unsigned long long)
9175
9176 #define L1_CACHE_SHIFT 5
9177 -#define L1_CACHE_BYTES 32
9178 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
9179
9180 #ifdef CONFIG_SPARC32
9181 #define SMP_CACHE_BYTES_SHIFT 5
9182 diff --git a/arch/sparc/include/asm/elf_32.h b/arch/sparc/include/asm/elf_32.h
9183 index a24e41f..47677ff 100644
9184 --- a/arch/sparc/include/asm/elf_32.h
9185 +++ b/arch/sparc/include/asm/elf_32.h
9186 @@ -114,6 +114,13 @@ typedef struct {
9187
9188 #define ELF_ET_DYN_BASE (TASK_UNMAPPED_BASE)
9189
9190 +#ifdef CONFIG_PAX_ASLR
9191 +#define PAX_ELF_ET_DYN_BASE 0x10000UL
9192 +
9193 +#define PAX_DELTA_MMAP_LEN 16
9194 +#define PAX_DELTA_STACK_LEN 16
9195 +#endif
9196 +
9197 /* This yields a mask that user programs can use to figure out what
9198 instruction set this cpu supports. This can NOT be done in userspace
9199 on Sparc. */
9200 diff --git a/arch/sparc/include/asm/elf_64.h b/arch/sparc/include/asm/elf_64.h
9201 index 370ca1e..d4f4a98 100644
9202 --- a/arch/sparc/include/asm/elf_64.h
9203 +++ b/arch/sparc/include/asm/elf_64.h
9204 @@ -189,6 +189,13 @@ typedef struct {
9205 #define ELF_ET_DYN_BASE 0x0000010000000000UL
9206 #define COMPAT_ELF_ET_DYN_BASE 0x0000000070000000UL
9207
9208 +#ifdef CONFIG_PAX_ASLR
9209 +#define PAX_ELF_ET_DYN_BASE (test_thread_flag(TIF_32BIT) ? 0x10000UL : 0x100000UL)
9210 +
9211 +#define PAX_DELTA_MMAP_LEN (test_thread_flag(TIF_32BIT) ? 14 : 28)
9212 +#define PAX_DELTA_STACK_LEN (test_thread_flag(TIF_32BIT) ? 15 : 29)
9213 +#endif
9214 +
9215 extern unsigned long sparc64_elf_hwcap;
9216 #define ELF_HWCAP sparc64_elf_hwcap
9217
9218 diff --git a/arch/sparc/include/asm/pgalloc_32.h b/arch/sparc/include/asm/pgalloc_32.h
9219 index 9b1c36d..209298b 100644
9220 --- a/arch/sparc/include/asm/pgalloc_32.h
9221 +++ b/arch/sparc/include/asm/pgalloc_32.h
9222 @@ -33,6 +33,7 @@ static inline void pgd_set(pgd_t * pgdp, pmd_t * pmdp)
9223 }
9224
9225 #define pgd_populate(MM, PGD, PMD) pgd_set(PGD, PMD)
9226 +#define pgd_populate_kernel(MM, PGD, PMD) pgd_populate((MM), (PGD), (PMD))
9227
9228 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm,
9229 unsigned long address)
9230 diff --git a/arch/sparc/include/asm/pgalloc_64.h b/arch/sparc/include/asm/pgalloc_64.h
9231 index bcfe063..b333142 100644
9232 --- a/arch/sparc/include/asm/pgalloc_64.h
9233 +++ b/arch/sparc/include/asm/pgalloc_64.h
9234 @@ -26,6 +26,7 @@ static inline void pgd_free(struct mm_struct *mm, pgd_t *pgd)
9235 }
9236
9237 #define pud_populate(MM, PUD, PMD) pud_set(PUD, PMD)
9238 +#define pud_populate_kernel(MM, PUD, PMD) pud_populate((MM), (PUD), (PMD))
9239
9240 static inline pmd_t *pmd_alloc_one(struct mm_struct *mm, unsigned long addr)
9241 {
9242 diff --git a/arch/sparc/include/asm/pgtable_32.h b/arch/sparc/include/asm/pgtable_32.h
9243 index 502f632..da1917f 100644
9244 --- a/arch/sparc/include/asm/pgtable_32.h
9245 +++ b/arch/sparc/include/asm/pgtable_32.h
9246 @@ -50,6 +50,9 @@ extern unsigned long calc_highpages(void);
9247 #define PAGE_SHARED SRMMU_PAGE_SHARED
9248 #define PAGE_COPY SRMMU_PAGE_COPY
9249 #define PAGE_READONLY SRMMU_PAGE_RDONLY
9250 +#define PAGE_SHARED_NOEXEC SRMMU_PAGE_SHARED_NOEXEC
9251 +#define PAGE_COPY_NOEXEC SRMMU_PAGE_COPY_NOEXEC
9252 +#define PAGE_READONLY_NOEXEC SRMMU_PAGE_RDONLY_NOEXEC
9253 #define PAGE_KERNEL SRMMU_PAGE_KERNEL
9254
9255 /* Top-level page directory - dummy used by init-mm.
9256 @@ -62,18 +65,18 @@ extern unsigned long ptr_in_current_pgd;
9257
9258 /* xwr */
9259 #define __P000 PAGE_NONE
9260 -#define __P001 PAGE_READONLY
9261 -#define __P010 PAGE_COPY
9262 -#define __P011 PAGE_COPY
9263 +#define __P001 PAGE_READONLY_NOEXEC
9264 +#define __P010 PAGE_COPY_NOEXEC
9265 +#define __P011 PAGE_COPY_NOEXEC
9266 #define __P100 PAGE_READONLY
9267 #define __P101 PAGE_READONLY
9268 #define __P110 PAGE_COPY
9269 #define __P111 PAGE_COPY
9270
9271 #define __S000 PAGE_NONE
9272 -#define __S001 PAGE_READONLY
9273 -#define __S010 PAGE_SHARED
9274 -#define __S011 PAGE_SHARED
9275 +#define __S001 PAGE_READONLY_NOEXEC
9276 +#define __S010 PAGE_SHARED_NOEXEC
9277 +#define __S011 PAGE_SHARED_NOEXEC
9278 #define __S100 PAGE_READONLY
9279 #define __S101 PAGE_READONLY
9280 #define __S110 PAGE_SHARED
9281 diff --git a/arch/sparc/include/asm/pgtsrmmu.h b/arch/sparc/include/asm/pgtsrmmu.h
9282 index 79da178..c2eede8 100644
9283 --- a/arch/sparc/include/asm/pgtsrmmu.h
9284 +++ b/arch/sparc/include/asm/pgtsrmmu.h
9285 @@ -115,6 +115,11 @@
9286 SRMMU_EXEC | SRMMU_REF)
9287 #define SRMMU_PAGE_RDONLY __pgprot(SRMMU_VALID | SRMMU_CACHE | \
9288 SRMMU_EXEC | SRMMU_REF)
9289 +
9290 +#define SRMMU_PAGE_SHARED_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_WRITE | SRMMU_REF)
9291 +#define SRMMU_PAGE_COPY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9292 +#define SRMMU_PAGE_RDONLY_NOEXEC __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_REF)
9293 +
9294 #define SRMMU_PAGE_KERNEL __pgprot(SRMMU_VALID | SRMMU_CACHE | SRMMU_PRIV | \
9295 SRMMU_DIRTY | SRMMU_REF)
9296
9297 diff --git a/arch/sparc/include/asm/spinlock_64.h b/arch/sparc/include/asm/spinlock_64.h
9298 index 9689176..63c18ea 100644
9299 --- a/arch/sparc/include/asm/spinlock_64.h
9300 +++ b/arch/sparc/include/asm/spinlock_64.h
9301 @@ -92,14 +92,19 @@ static inline void arch_spin_lock_flags(arch_spinlock_t *lock, unsigned long fla
9302
9303 /* Multi-reader locks, these are much saner than the 32-bit Sparc ones... */
9304
9305 -static void inline arch_read_lock(arch_rwlock_t *lock)
9306 +static inline void arch_read_lock(arch_rwlock_t *lock)
9307 {
9308 unsigned long tmp1, tmp2;
9309
9310 __asm__ __volatile__ (
9311 "1: ldsw [%2], %0\n"
9312 " brlz,pn %0, 2f\n"
9313 -"4: add %0, 1, %1\n"
9314 +"4: addcc %0, 1, %1\n"
9315 +
9316 +#ifdef CONFIG_PAX_REFCOUNT
9317 +" tvs %%icc, 6\n"
9318 +#endif
9319 +
9320 " cas [%2], %0, %1\n"
9321 " cmp %0, %1\n"
9322 " bne,pn %%icc, 1b\n"
9323 @@ -112,10 +117,10 @@ static void inline arch_read_lock(arch_rwlock_t *lock)
9324 " .previous"
9325 : "=&r" (tmp1), "=&r" (tmp2)
9326 : "r" (lock)
9327 - : "memory");
9328 + : "memory", "cc");
9329 }
9330
9331 -static int inline arch_read_trylock(arch_rwlock_t *lock)
9332 +static inline int arch_read_trylock(arch_rwlock_t *lock)
9333 {
9334 int tmp1, tmp2;
9335
9336 @@ -123,7 +128,12 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9337 "1: ldsw [%2], %0\n"
9338 " brlz,a,pn %0, 2f\n"
9339 " mov 0, %0\n"
9340 -" add %0, 1, %1\n"
9341 +" addcc %0, 1, %1\n"
9342 +
9343 +#ifdef CONFIG_PAX_REFCOUNT
9344 +" tvs %%icc, 6\n"
9345 +#endif
9346 +
9347 " cas [%2], %0, %1\n"
9348 " cmp %0, %1\n"
9349 " bne,pn %%icc, 1b\n"
9350 @@ -136,13 +146,18 @@ static int inline arch_read_trylock(arch_rwlock_t *lock)
9351 return tmp1;
9352 }
9353
9354 -static void inline arch_read_unlock(arch_rwlock_t *lock)
9355 +static inline void arch_read_unlock(arch_rwlock_t *lock)
9356 {
9357 unsigned long tmp1, tmp2;
9358
9359 __asm__ __volatile__(
9360 "1: lduw [%2], %0\n"
9361 -" sub %0, 1, %1\n"
9362 +" subcc %0, 1, %1\n"
9363 +
9364 +#ifdef CONFIG_PAX_REFCOUNT
9365 +" tvs %%icc, 6\n"
9366 +#endif
9367 +
9368 " cas [%2], %0, %1\n"
9369 " cmp %0, %1\n"
9370 " bne,pn %%xcc, 1b\n"
9371 @@ -152,7 +167,7 @@ static void inline arch_read_unlock(arch_rwlock_t *lock)
9372 : "memory");
9373 }
9374
9375 -static void inline arch_write_lock(arch_rwlock_t *lock)
9376 +static inline void arch_write_lock(arch_rwlock_t *lock)
9377 {
9378 unsigned long mask, tmp1, tmp2;
9379
9380 @@ -177,7 +192,7 @@ static void inline arch_write_lock(arch_rwlock_t *lock)
9381 : "memory");
9382 }
9383
9384 -static void inline arch_write_unlock(arch_rwlock_t *lock)
9385 +static inline void arch_write_unlock(arch_rwlock_t *lock)
9386 {
9387 __asm__ __volatile__(
9388 " stw %%g0, [%0]"
9389 @@ -186,7 +201,7 @@ static void inline arch_write_unlock(arch_rwlock_t *lock)
9390 : "memory");
9391 }
9392
9393 -static int inline arch_write_trylock(arch_rwlock_t *lock)
9394 +static inline int arch_write_trylock(arch_rwlock_t *lock)
9395 {
9396 unsigned long mask, tmp1, tmp2, result;
9397
9398 diff --git a/arch/sparc/include/asm/thread_info_32.h b/arch/sparc/include/asm/thread_info_32.h
9399 index 96efa7a..16858bf 100644
9400 --- a/arch/sparc/include/asm/thread_info_32.h
9401 +++ b/arch/sparc/include/asm/thread_info_32.h
9402 @@ -49,6 +49,8 @@ struct thread_info {
9403 unsigned long w_saved;
9404
9405 struct restart_block restart_block;
9406 +
9407 + unsigned long lowest_stack;
9408 };
9409
9410 /*
9411 diff --git a/arch/sparc/include/asm/thread_info_64.h b/arch/sparc/include/asm/thread_info_64.h
9412 index a5f01ac..703b554 100644
9413 --- a/arch/sparc/include/asm/thread_info_64.h
9414 +++ b/arch/sparc/include/asm/thread_info_64.h
9415 @@ -63,6 +63,8 @@ struct thread_info {
9416 struct pt_regs *kern_una_regs;
9417 unsigned int kern_una_insn;
9418
9419 + unsigned long lowest_stack;
9420 +
9421 unsigned long fpregs[0] __attribute__ ((aligned(64)));
9422 };
9423
9424 @@ -188,12 +190,13 @@ register struct thread_info *current_thread_info_reg asm("g6");
9425 #define TIF_NEED_RESCHED 3 /* rescheduling necessary */
9426 /* flag bit 4 is available */
9427 #define TIF_UNALIGNED 5 /* allowed to do unaligned accesses */
9428 -/* flag bit 6 is available */
9429 +#define TIF_GRSEC_SETXID 6 /* update credentials on syscall entry/exit */
9430 #define TIF_32BIT 7 /* 32-bit binary */
9431 #define TIF_NOHZ 8 /* in adaptive nohz mode */
9432 #define TIF_SECCOMP 9 /* secure computing */
9433 #define TIF_SYSCALL_AUDIT 10 /* syscall auditing active */
9434 #define TIF_SYSCALL_TRACEPOINT 11 /* syscall tracepoint instrumentation */
9435 +
9436 /* NOTE: Thread flags >= 12 should be ones we have no interest
9437 * in using in assembly, else we can't use the mask as
9438 * an immediate value in instructions such as andcc.
9439 @@ -213,12 +216,18 @@ register struct thread_info *current_thread_info_reg asm("g6");
9440 #define _TIF_SYSCALL_AUDIT (1<<TIF_SYSCALL_AUDIT)
9441 #define _TIF_SYSCALL_TRACEPOINT (1<<TIF_SYSCALL_TRACEPOINT)
9442 #define _TIF_POLLING_NRFLAG (1<<TIF_POLLING_NRFLAG)
9443 +#define _TIF_GRSEC_SETXID (1<<TIF_GRSEC_SETXID)
9444
9445 #define _TIF_USER_WORK_MASK ((0xff << TI_FLAG_WSAVED_SHIFT) | \
9446 _TIF_DO_NOTIFY_RESUME_MASK | \
9447 _TIF_NEED_RESCHED)
9448 #define _TIF_DO_NOTIFY_RESUME_MASK (_TIF_NOTIFY_RESUME | _TIF_SIGPENDING)
9449
9450 +#define _TIF_WORK_SYSCALL \
9451 + (_TIF_SYSCALL_TRACE | _TIF_SECCOMP | _TIF_SYSCALL_AUDIT | \
9452 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
9453 +
9454 +
9455 /*
9456 * Thread-synchronous status.
9457 *
9458 diff --git a/arch/sparc/include/asm/uaccess.h b/arch/sparc/include/asm/uaccess.h
9459 index 0167d26..767bb0c 100644
9460 --- a/arch/sparc/include/asm/uaccess.h
9461 +++ b/arch/sparc/include/asm/uaccess.h
9462 @@ -1,5 +1,6 @@
9463 #ifndef ___ASM_SPARC_UACCESS_H
9464 #define ___ASM_SPARC_UACCESS_H
9465 +
9466 #if defined(__sparc__) && defined(__arch64__)
9467 #include <asm/uaccess_64.h>
9468 #else
9469 diff --git a/arch/sparc/include/asm/uaccess_32.h b/arch/sparc/include/asm/uaccess_32.h
9470 index 53a28dd..50c38c3 100644
9471 --- a/arch/sparc/include/asm/uaccess_32.h
9472 +++ b/arch/sparc/include/asm/uaccess_32.h
9473 @@ -250,27 +250,46 @@ extern unsigned long __copy_user(void __user *to, const void __user *from, unsig
9474
9475 static inline unsigned long copy_to_user(void __user *to, const void *from, unsigned long n)
9476 {
9477 - if (n && __access_ok((unsigned long) to, n))
9478 + if ((long)n < 0)
9479 + return n;
9480 +
9481 + if (n && __access_ok((unsigned long) to, n)) {
9482 + if (!__builtin_constant_p(n))
9483 + check_object_size(from, n, true);
9484 return __copy_user(to, (__force void __user *) from, n);
9485 - else
9486 + } else
9487 return n;
9488 }
9489
9490 static inline unsigned long __copy_to_user(void __user *to, const void *from, unsigned long n)
9491 {
9492 + if ((long)n < 0)
9493 + return n;
9494 +
9495 + if (!__builtin_constant_p(n))
9496 + check_object_size(from, n, true);
9497 +
9498 return __copy_user(to, (__force void __user *) from, n);
9499 }
9500
9501 static inline unsigned long copy_from_user(void *to, const void __user *from, unsigned long n)
9502 {
9503 - if (n && __access_ok((unsigned long) from, n))
9504 + if ((long)n < 0)
9505 + return n;
9506 +
9507 + if (n && __access_ok((unsigned long) from, n)) {
9508 + if (!__builtin_constant_p(n))
9509 + check_object_size(to, n, false);
9510 return __copy_user((__force void __user *) to, from, n);
9511 - else
9512 + } else
9513 return n;
9514 }
9515
9516 static inline unsigned long __copy_from_user(void *to, const void __user *from, unsigned long n)
9517 {
9518 + if ((long)n < 0)
9519 + return n;
9520 +
9521 return __copy_user((__force void __user *) to, from, n);
9522 }
9523
9524 diff --git a/arch/sparc/include/asm/uaccess_64.h b/arch/sparc/include/asm/uaccess_64.h
9525 index ad7e178..c9e7423 100644
9526 --- a/arch/sparc/include/asm/uaccess_64.h
9527 +++ b/arch/sparc/include/asm/uaccess_64.h
9528 @@ -10,6 +10,7 @@
9529 #include <linux/compiler.h>
9530 #include <linux/string.h>
9531 #include <linux/thread_info.h>
9532 +#include <linux/kernel.h>
9533 #include <asm/asi.h>
9534 #include <asm/spitfire.h>
9535 #include <asm-generic/uaccess-unaligned.h>
9536 @@ -214,8 +215,15 @@ extern unsigned long copy_from_user_fixup(void *to, const void __user *from,
9537 static inline unsigned long __must_check
9538 copy_from_user(void *to, const void __user *from, unsigned long size)
9539 {
9540 - unsigned long ret = ___copy_from_user(to, from, size);
9541 + unsigned long ret;
9542
9543 + if ((long)size < 0 || size > INT_MAX)
9544 + return size;
9545 +
9546 + if (!__builtin_constant_p(size))
9547 + check_object_size(to, size, false);
9548 +
9549 + ret = ___copy_from_user(to, from, size);
9550 if (unlikely(ret))
9551 ret = copy_from_user_fixup(to, from, size);
9552
9553 @@ -231,8 +239,15 @@ extern unsigned long copy_to_user_fixup(void __user *to, const void *from,
9554 static inline unsigned long __must_check
9555 copy_to_user(void __user *to, const void *from, unsigned long size)
9556 {
9557 - unsigned long ret = ___copy_to_user(to, from, size);
9558 + unsigned long ret;
9559
9560 + if ((long)size < 0 || size > INT_MAX)
9561 + return size;
9562 +
9563 + if (!__builtin_constant_p(size))
9564 + check_object_size(from, size, true);
9565 +
9566 + ret = ___copy_to_user(to, from, size);
9567 if (unlikely(ret))
9568 ret = copy_to_user_fixup(to, from, size);
9569 return ret;
9570 diff --git a/arch/sparc/kernel/Makefile b/arch/sparc/kernel/Makefile
9571 index d15cc17..d0ae796 100644
9572 --- a/arch/sparc/kernel/Makefile
9573 +++ b/arch/sparc/kernel/Makefile
9574 @@ -4,7 +4,7 @@
9575 #
9576
9577 asflags-y := -ansi
9578 -ccflags-y := -Werror
9579 +#ccflags-y := -Werror
9580
9581 extra-y := head_$(BITS).o
9582
9583 diff --git a/arch/sparc/kernel/process_32.c b/arch/sparc/kernel/process_32.c
9584 index fdd819d..5af08c8 100644
9585 --- a/arch/sparc/kernel/process_32.c
9586 +++ b/arch/sparc/kernel/process_32.c
9587 @@ -116,14 +116,14 @@ void show_regs(struct pt_regs *r)
9588
9589 printk("PSR: %08lx PC: %08lx NPC: %08lx Y: %08lx %s\n",
9590 r->psr, r->pc, r->npc, r->y, print_tainted());
9591 - printk("PC: <%pS>\n", (void *) r->pc);
9592 + printk("PC: <%pA>\n", (void *) r->pc);
9593 printk("%%G: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9594 r->u_regs[0], r->u_regs[1], r->u_regs[2], r->u_regs[3],
9595 r->u_regs[4], r->u_regs[5], r->u_regs[6], r->u_regs[7]);
9596 printk("%%O: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9597 r->u_regs[8], r->u_regs[9], r->u_regs[10], r->u_regs[11],
9598 r->u_regs[12], r->u_regs[13], r->u_regs[14], r->u_regs[15]);
9599 - printk("RPC: <%pS>\n", (void *) r->u_regs[15]);
9600 + printk("RPC: <%pA>\n", (void *) r->u_regs[15]);
9601
9602 printk("%%L: %08lx %08lx %08lx %08lx %08lx %08lx %08lx %08lx\n",
9603 rw->locals[0], rw->locals[1], rw->locals[2], rw->locals[3],
9604 @@ -160,7 +160,7 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
9605 rw = (struct reg_window32 *) fp;
9606 pc = rw->ins[7];
9607 printk("[%08lx : ", pc);
9608 - printk("%pS ] ", (void *) pc);
9609 + printk("%pA ] ", (void *) pc);
9610 fp = rw->ins[6];
9611 } while (++count < 16);
9612 printk("\n");
9613 diff --git a/arch/sparc/kernel/process_64.c b/arch/sparc/kernel/process_64.c
9614 index 32a280e..84fc6a9 100644
9615 --- a/arch/sparc/kernel/process_64.c
9616 +++ b/arch/sparc/kernel/process_64.c
9617 @@ -159,7 +159,7 @@ static void show_regwindow(struct pt_regs *regs)
9618 printk("i4: %016lx i5: %016lx i6: %016lx i7: %016lx\n",
9619 rwk->ins[4], rwk->ins[5], rwk->ins[6], rwk->ins[7]);
9620 if (regs->tstate & TSTATE_PRIV)
9621 - printk("I7: <%pS>\n", (void *) rwk->ins[7]);
9622 + printk("I7: <%pA>\n", (void *) rwk->ins[7]);
9623 }
9624
9625 void show_regs(struct pt_regs *regs)
9626 @@ -168,7 +168,7 @@ void show_regs(struct pt_regs *regs)
9627
9628 printk("TSTATE: %016lx TPC: %016lx TNPC: %016lx Y: %08x %s\n", regs->tstate,
9629 regs->tpc, regs->tnpc, regs->y, print_tainted());
9630 - printk("TPC: <%pS>\n", (void *) regs->tpc);
9631 + printk("TPC: <%pA>\n", (void *) regs->tpc);
9632 printk("g0: %016lx g1: %016lx g2: %016lx g3: %016lx\n",
9633 regs->u_regs[0], regs->u_regs[1], regs->u_regs[2],
9634 regs->u_regs[3]);
9635 @@ -181,7 +181,7 @@ void show_regs(struct pt_regs *regs)
9636 printk("o4: %016lx o5: %016lx sp: %016lx ret_pc: %016lx\n",
9637 regs->u_regs[12], regs->u_regs[13], regs->u_regs[14],
9638 regs->u_regs[15]);
9639 - printk("RPC: <%pS>\n", (void *) regs->u_regs[15]);
9640 + printk("RPC: <%pA>\n", (void *) regs->u_regs[15]);
9641 show_regwindow(regs);
9642 show_stack(current, (unsigned long *) regs->u_regs[UREG_FP]);
9643 }
9644 @@ -270,7 +270,7 @@ void arch_trigger_all_cpu_backtrace(void)
9645 ((tp && tp->task) ? tp->task->pid : -1));
9646
9647 if (gp->tstate & TSTATE_PRIV) {
9648 - printk(" TPC[%pS] O7[%pS] I7[%pS] RPC[%pS]\n",
9649 + printk(" TPC[%pA] O7[%pA] I7[%pA] RPC[%pA]\n",
9650 (void *) gp->tpc,
9651 (void *) gp->o7,
9652 (void *) gp->i7,
9653 diff --git a/arch/sparc/kernel/prom_common.c b/arch/sparc/kernel/prom_common.c
9654 index 79cc0d1..ec62734 100644
9655 --- a/arch/sparc/kernel/prom_common.c
9656 +++ b/arch/sparc/kernel/prom_common.c
9657 @@ -144,7 +144,7 @@ static int __init prom_common_nextprop(phandle node, char *prev, char *buf)
9658
9659 unsigned int prom_early_allocated __initdata;
9660
9661 -static struct of_pdt_ops prom_sparc_ops __initdata = {
9662 +static struct of_pdt_ops prom_sparc_ops __initconst = {
9663 .nextprop = prom_common_nextprop,
9664 .getproplen = prom_getproplen,
9665 .getproperty = prom_getproperty,
9666 diff --git a/arch/sparc/kernel/ptrace_64.c b/arch/sparc/kernel/ptrace_64.c
9667 index c13c9f2..d572c34 100644
9668 --- a/arch/sparc/kernel/ptrace_64.c
9669 +++ b/arch/sparc/kernel/ptrace_64.c
9670 @@ -1060,6 +1060,10 @@ long arch_ptrace(struct task_struct *child, long request,
9671 return ret;
9672 }
9673
9674 +#ifdef CONFIG_GRKERNSEC_SETXID
9675 +extern void gr_delayed_cred_worker(void);
9676 +#endif
9677 +
9678 asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9679 {
9680 int ret = 0;
9681 @@ -1070,6 +1074,11 @@ asmlinkage int syscall_trace_enter(struct pt_regs *regs)
9682 if (test_thread_flag(TIF_NOHZ))
9683 user_exit();
9684
9685 +#ifdef CONFIG_GRKERNSEC_SETXID
9686 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9687 + gr_delayed_cred_worker();
9688 +#endif
9689 +
9690 if (test_thread_flag(TIF_SYSCALL_TRACE))
9691 ret = tracehook_report_syscall_entry(regs);
9692
9693 @@ -1093,6 +1102,11 @@ asmlinkage void syscall_trace_leave(struct pt_regs *regs)
9694 if (test_thread_flag(TIF_NOHZ))
9695 user_exit();
9696
9697 +#ifdef CONFIG_GRKERNSEC_SETXID
9698 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
9699 + gr_delayed_cred_worker();
9700 +#endif
9701 +
9702 audit_syscall_exit(regs);
9703
9704 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
9705 diff --git a/arch/sparc/kernel/smp_64.c b/arch/sparc/kernel/smp_64.c
9706 index b085311..6f885f7 100644
9707 --- a/arch/sparc/kernel/smp_64.c
9708 +++ b/arch/sparc/kernel/smp_64.c
9709 @@ -870,8 +870,8 @@ extern unsigned long xcall_flush_dcache_page_cheetah;
9710 extern unsigned long xcall_flush_dcache_page_spitfire;
9711
9712 #ifdef CONFIG_DEBUG_DCFLUSH
9713 -extern atomic_t dcpage_flushes;
9714 -extern atomic_t dcpage_flushes_xcall;
9715 +extern atomic_unchecked_t dcpage_flushes;
9716 +extern atomic_unchecked_t dcpage_flushes_xcall;
9717 #endif
9718
9719 static inline void __local_flush_dcache_page(struct page *page)
9720 @@ -895,7 +895,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9721 return;
9722
9723 #ifdef CONFIG_DEBUG_DCFLUSH
9724 - atomic_inc(&dcpage_flushes);
9725 + atomic_inc_unchecked(&dcpage_flushes);
9726 #endif
9727
9728 this_cpu = get_cpu();
9729 @@ -919,7 +919,7 @@ void smp_flush_dcache_page_impl(struct page *page, int cpu)
9730 xcall_deliver(data0, __pa(pg_addr),
9731 (u64) pg_addr, cpumask_of(cpu));
9732 #ifdef CONFIG_DEBUG_DCFLUSH
9733 - atomic_inc(&dcpage_flushes_xcall);
9734 + atomic_inc_unchecked(&dcpage_flushes_xcall);
9735 #endif
9736 }
9737 }
9738 @@ -938,7 +938,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9739 preempt_disable();
9740
9741 #ifdef CONFIG_DEBUG_DCFLUSH
9742 - atomic_inc(&dcpage_flushes);
9743 + atomic_inc_unchecked(&dcpage_flushes);
9744 #endif
9745 data0 = 0;
9746 pg_addr = page_address(page);
9747 @@ -955,7 +955,7 @@ void flush_dcache_page_all(struct mm_struct *mm, struct page *page)
9748 xcall_deliver(data0, __pa(pg_addr),
9749 (u64) pg_addr, cpu_online_mask);
9750 #ifdef CONFIG_DEBUG_DCFLUSH
9751 - atomic_inc(&dcpage_flushes_xcall);
9752 + atomic_inc_unchecked(&dcpage_flushes_xcall);
9753 #endif
9754 }
9755 __local_flush_dcache_page(page);
9756 diff --git a/arch/sparc/kernel/sys_sparc_32.c b/arch/sparc/kernel/sys_sparc_32.c
9757 index 3a8d184..49498a8 100644
9758 --- a/arch/sparc/kernel/sys_sparc_32.c
9759 +++ b/arch/sparc/kernel/sys_sparc_32.c
9760 @@ -52,7 +52,7 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9761 if (len > TASK_SIZE - PAGE_SIZE)
9762 return -ENOMEM;
9763 if (!addr)
9764 - addr = TASK_UNMAPPED_BASE;
9765 + addr = current->mm->mmap_base;
9766
9767 info.flags = 0;
9768 info.length = len;
9769 diff --git a/arch/sparc/kernel/sys_sparc_64.c b/arch/sparc/kernel/sys_sparc_64.c
9770 index beb0b5a..5a153f7 100644
9771 --- a/arch/sparc/kernel/sys_sparc_64.c
9772 +++ b/arch/sparc/kernel/sys_sparc_64.c
9773 @@ -88,13 +88,14 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9774 struct vm_area_struct * vma;
9775 unsigned long task_size = TASK_SIZE;
9776 int do_color_align;
9777 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9778 struct vm_unmapped_area_info info;
9779
9780 if (flags & MAP_FIXED) {
9781 /* We do not accept a shared mapping if it would violate
9782 * cache aliasing constraints.
9783 */
9784 - if ((flags & MAP_SHARED) &&
9785 + if ((filp || (flags & MAP_SHARED)) &&
9786 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9787 return -EINVAL;
9788 return addr;
9789 @@ -109,6 +110,10 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9790 if (filp || (flags & MAP_SHARED))
9791 do_color_align = 1;
9792
9793 +#ifdef CONFIG_PAX_RANDMMAP
9794 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9795 +#endif
9796 +
9797 if (addr) {
9798 if (do_color_align)
9799 addr = COLOR_ALIGN(addr, pgoff);
9800 @@ -116,22 +121,28 @@ unsigned long arch_get_unmapped_area(struct file *filp, unsigned long addr, unsi
9801 addr = PAGE_ALIGN(addr);
9802
9803 vma = find_vma(mm, addr);
9804 - if (task_size - len >= addr &&
9805 - (!vma || addr + len <= vma->vm_start))
9806 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9807 return addr;
9808 }
9809
9810 info.flags = 0;
9811 info.length = len;
9812 - info.low_limit = TASK_UNMAPPED_BASE;
9813 + info.low_limit = mm->mmap_base;
9814 info.high_limit = min(task_size, VA_EXCLUDE_START);
9815 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9816 info.align_offset = pgoff << PAGE_SHIFT;
9817 + info.threadstack_offset = offset;
9818 addr = vm_unmapped_area(&info);
9819
9820 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
9821 VM_BUG_ON(addr != -ENOMEM);
9822 info.low_limit = VA_EXCLUDE_END;
9823 +
9824 +#ifdef CONFIG_PAX_RANDMMAP
9825 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9826 + info.low_limit += mm->delta_mmap;
9827 +#endif
9828 +
9829 info.high_limit = task_size;
9830 addr = vm_unmapped_area(&info);
9831 }
9832 @@ -149,6 +160,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9833 unsigned long task_size = STACK_TOP32;
9834 unsigned long addr = addr0;
9835 int do_color_align;
9836 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
9837 struct vm_unmapped_area_info info;
9838
9839 /* This should only ever run for 32-bit processes. */
9840 @@ -158,7 +170,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9841 /* We do not accept a shared mapping if it would violate
9842 * cache aliasing constraints.
9843 */
9844 - if ((flags & MAP_SHARED) &&
9845 + if ((filp || (flags & MAP_SHARED)) &&
9846 ((addr - (pgoff << PAGE_SHIFT)) & (SHMLBA - 1)))
9847 return -EINVAL;
9848 return addr;
9849 @@ -171,6 +183,10 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9850 if (filp || (flags & MAP_SHARED))
9851 do_color_align = 1;
9852
9853 +#ifdef CONFIG_PAX_RANDMMAP
9854 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9855 +#endif
9856 +
9857 /* requesting a specific address */
9858 if (addr) {
9859 if (do_color_align)
9860 @@ -179,8 +195,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9861 addr = PAGE_ALIGN(addr);
9862
9863 vma = find_vma(mm, addr);
9864 - if (task_size - len >= addr &&
9865 - (!vma || addr + len <= vma->vm_start))
9866 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
9867 return addr;
9868 }
9869
9870 @@ -190,6 +205,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9871 info.high_limit = mm->mmap_base;
9872 info.align_mask = do_color_align ? (PAGE_MASK & (SHMLBA - 1)) : 0;
9873 info.align_offset = pgoff << PAGE_SHIFT;
9874 + info.threadstack_offset = offset;
9875 addr = vm_unmapped_area(&info);
9876
9877 /*
9878 @@ -202,6 +218,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
9879 VM_BUG_ON(addr != -ENOMEM);
9880 info.flags = 0;
9881 info.low_limit = TASK_UNMAPPED_BASE;
9882 +
9883 +#ifdef CONFIG_PAX_RANDMMAP
9884 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9885 + info.low_limit += mm->delta_mmap;
9886 +#endif
9887 +
9888 info.high_limit = STACK_TOP32;
9889 addr = vm_unmapped_area(&info);
9890 }
9891 @@ -258,10 +280,14 @@ unsigned long get_fb_unmapped_area(struct file *filp, unsigned long orig_addr, u
9892 EXPORT_SYMBOL(get_fb_unmapped_area);
9893
9894 /* Essentially the same as PowerPC. */
9895 -static unsigned long mmap_rnd(void)
9896 +static unsigned long mmap_rnd(struct mm_struct *mm)
9897 {
9898 unsigned long rnd = 0UL;
9899
9900 +#ifdef CONFIG_PAX_RANDMMAP
9901 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
9902 +#endif
9903 +
9904 if (current->flags & PF_RANDOMIZE) {
9905 unsigned long val = get_random_int();
9906 if (test_thread_flag(TIF_32BIT))
9907 @@ -274,7 +300,7 @@ static unsigned long mmap_rnd(void)
9908
9909 void arch_pick_mmap_layout(struct mm_struct *mm)
9910 {
9911 - unsigned long random_factor = mmap_rnd();
9912 + unsigned long random_factor = mmap_rnd(mm);
9913 unsigned long gap;
9914
9915 /*
9916 @@ -287,6 +313,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9917 gap == RLIM_INFINITY ||
9918 sysctl_legacy_va_layout) {
9919 mm->mmap_base = TASK_UNMAPPED_BASE + random_factor;
9920 +
9921 +#ifdef CONFIG_PAX_RANDMMAP
9922 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9923 + mm->mmap_base += mm->delta_mmap;
9924 +#endif
9925 +
9926 mm->get_unmapped_area = arch_get_unmapped_area;
9927 } else {
9928 /* We know it's 32-bit */
9929 @@ -298,6 +330,12 @@ void arch_pick_mmap_layout(struct mm_struct *mm)
9930 gap = (task_size / 6 * 5);
9931
9932 mm->mmap_base = PAGE_ALIGN(task_size - gap - random_factor);
9933 +
9934 +#ifdef CONFIG_PAX_RANDMMAP
9935 + if (mm->pax_flags & MF_PAX_RANDMMAP)
9936 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
9937 +#endif
9938 +
9939 mm->get_unmapped_area = arch_get_unmapped_area_topdown;
9940 }
9941 }
9942 diff --git a/arch/sparc/kernel/syscalls.S b/arch/sparc/kernel/syscalls.S
9943 index 87729ff..192f9d8 100644
9944 --- a/arch/sparc/kernel/syscalls.S
9945 +++ b/arch/sparc/kernel/syscalls.S
9946 @@ -52,7 +52,7 @@ sys32_rt_sigreturn:
9947 #endif
9948 .align 32
9949 1: ldx [%g6 + TI_FLAGS], %l5
9950 - andcc %l5, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
9951 + andcc %l5, _TIF_WORK_SYSCALL, %g0
9952 be,pt %icc, rtrap
9953 nop
9954 call syscall_trace_leave
9955 @@ -184,7 +184,7 @@ linux_sparc_syscall32:
9956
9957 srl %i3, 0, %o3 ! IEU0
9958 srl %i2, 0, %o2 ! IEU0 Group
9959 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
9960 + andcc %l0, _TIF_WORK_SYSCALL, %g0
9961 bne,pn %icc, linux_syscall_trace32 ! CTI
9962 mov %i0, %l5 ! IEU1
9963 5: call %l7 ! CTI Group brk forced
9964 @@ -207,7 +207,7 @@ linux_sparc_syscall:
9965
9966 mov %i3, %o3 ! IEU1
9967 mov %i4, %o4 ! IEU0 Group
9968 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
9969 + andcc %l0, _TIF_WORK_SYSCALL, %g0
9970 bne,pn %icc, linux_syscall_trace ! CTI Group
9971 mov %i0, %l5 ! IEU0
9972 2: call %l7 ! CTI Group brk forced
9973 @@ -223,7 +223,7 @@ ret_sys_call:
9974
9975 cmp %o0, -ERESTART_RESTARTBLOCK
9976 bgeu,pn %xcc, 1f
9977 - andcc %l0, (_TIF_SYSCALL_TRACE|_TIF_SECCOMP|_TIF_SYSCALL_AUDIT|_TIF_SYSCALL_TRACEPOINT|_TIF_NOHZ), %g0
9978 + andcc %l0, _TIF_WORK_SYSCALL, %g0
9979 ldx [%sp + PTREGS_OFF + PT_V9_TNPC], %l1 ! pc = npc
9980
9981 2:
9982 diff --git a/arch/sparc/kernel/traps_32.c b/arch/sparc/kernel/traps_32.c
9983 index 6629829..036032d 100644
9984 --- a/arch/sparc/kernel/traps_32.c
9985 +++ b/arch/sparc/kernel/traps_32.c
9986 @@ -44,6 +44,8 @@ static void instruction_dump(unsigned long *pc)
9987 #define __SAVE __asm__ __volatile__("save %sp, -0x40, %sp\n\t")
9988 #define __RESTORE __asm__ __volatile__("restore %g0, %g0, %g0\n\t")
9989
9990 +extern void gr_handle_kernel_exploit(void);
9991 +
9992 void die_if_kernel(char *str, struct pt_regs *regs)
9993 {
9994 static int die_counter;
9995 @@ -76,15 +78,17 @@ void die_if_kernel(char *str, struct pt_regs *regs)
9996 count++ < 30 &&
9997 (((unsigned long) rw) >= PAGE_OFFSET) &&
9998 !(((unsigned long) rw) & 0x7)) {
9999 - printk("Caller[%08lx]: %pS\n", rw->ins[7],
10000 + printk("Caller[%08lx]: %pA\n", rw->ins[7],
10001 (void *) rw->ins[7]);
10002 rw = (struct reg_window32 *)rw->ins[6];
10003 }
10004 }
10005 printk("Instruction DUMP:");
10006 instruction_dump ((unsigned long *) regs->pc);
10007 - if(regs->psr & PSR_PS)
10008 + if(regs->psr & PSR_PS) {
10009 + gr_handle_kernel_exploit();
10010 do_exit(SIGKILL);
10011 + }
10012 do_exit(SIGSEGV);
10013 }
10014
10015 diff --git a/arch/sparc/kernel/traps_64.c b/arch/sparc/kernel/traps_64.c
10016 index 4ced92f..965eeed 100644
10017 --- a/arch/sparc/kernel/traps_64.c
10018 +++ b/arch/sparc/kernel/traps_64.c
10019 @@ -77,7 +77,7 @@ static void dump_tl1_traplog(struct tl1_traplog *p)
10020 i + 1,
10021 p->trapstack[i].tstate, p->trapstack[i].tpc,
10022 p->trapstack[i].tnpc, p->trapstack[i].tt);
10023 - printk("TRAPLOG: TPC<%pS>\n", (void *) p->trapstack[i].tpc);
10024 + printk("TRAPLOG: TPC<%pA>\n", (void *) p->trapstack[i].tpc);
10025 }
10026 }
10027
10028 @@ -97,6 +97,12 @@ void bad_trap(struct pt_regs *regs, long lvl)
10029
10030 lvl -= 0x100;
10031 if (regs->tstate & TSTATE_PRIV) {
10032 +
10033 +#ifdef CONFIG_PAX_REFCOUNT
10034 + if (lvl == 6)
10035 + pax_report_refcount_overflow(regs);
10036 +#endif
10037 +
10038 sprintf(buffer, "Kernel bad sw trap %lx", lvl);
10039 die_if_kernel(buffer, regs);
10040 }
10041 @@ -115,11 +121,16 @@ void bad_trap(struct pt_regs *regs, long lvl)
10042 void bad_trap_tl1(struct pt_regs *regs, long lvl)
10043 {
10044 char buffer[32];
10045 -
10046 +
10047 if (notify_die(DIE_TRAP_TL1, "bad trap tl1", regs,
10048 0, lvl, SIGTRAP) == NOTIFY_STOP)
10049 return;
10050
10051 +#ifdef CONFIG_PAX_REFCOUNT
10052 + if (lvl == 6)
10053 + pax_report_refcount_overflow(regs);
10054 +#endif
10055 +
10056 dump_tl1_traplog((struct tl1_traplog *)(regs + 1));
10057
10058 sprintf (buffer, "Bad trap %lx at tl>0", lvl);
10059 @@ -1149,7 +1160,7 @@ static void cheetah_log_errors(struct pt_regs *regs, struct cheetah_err_info *in
10060 regs->tpc, regs->tnpc, regs->u_regs[UREG_I7], regs->tstate);
10061 printk("%s" "ERROR(%d): ",
10062 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id());
10063 - printk("TPC<%pS>\n", (void *) regs->tpc);
10064 + printk("TPC<%pA>\n", (void *) regs->tpc);
10065 printk("%s" "ERROR(%d): M_SYND(%lx), E_SYND(%lx)%s%s\n",
10066 (recoverable ? KERN_WARNING : KERN_CRIT), smp_processor_id(),
10067 (afsr & CHAFSR_M_SYNDROME) >> CHAFSR_M_SYNDROME_SHIFT,
10068 @@ -1756,7 +1767,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10069 smp_processor_id(),
10070 (type & 0x1) ? 'I' : 'D',
10071 regs->tpc);
10072 - printk(KERN_EMERG "TPC<%pS>\n", (void *) regs->tpc);
10073 + printk(KERN_EMERG "TPC<%pA>\n", (void *) regs->tpc);
10074 panic("Irrecoverable Cheetah+ parity error.");
10075 }
10076
10077 @@ -1764,7 +1775,7 @@ void cheetah_plus_parity_error(int type, struct pt_regs *regs)
10078 smp_processor_id(),
10079 (type & 0x1) ? 'I' : 'D',
10080 regs->tpc);
10081 - printk(KERN_WARNING "TPC<%pS>\n", (void *) regs->tpc);
10082 + printk(KERN_WARNING "TPC<%pA>\n", (void *) regs->tpc);
10083 }
10084
10085 struct sun4v_error_entry {
10086 @@ -1837,8 +1848,8 @@ struct sun4v_error_entry {
10087 /*0x38*/u64 reserved_5;
10088 };
10089
10090 -static atomic_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10091 -static atomic_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10092 +static atomic_unchecked_t sun4v_resum_oflow_cnt = ATOMIC_INIT(0);
10093 +static atomic_unchecked_t sun4v_nonresum_oflow_cnt = ATOMIC_INIT(0);
10094
10095 static const char *sun4v_err_type_to_str(u8 type)
10096 {
10097 @@ -1930,7 +1941,7 @@ static void sun4v_report_real_raddr(const char *pfx, struct pt_regs *regs)
10098 }
10099
10100 static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10101 - int cpu, const char *pfx, atomic_t *ocnt)
10102 + int cpu, const char *pfx, atomic_unchecked_t *ocnt)
10103 {
10104 u64 *raw_ptr = (u64 *) ent;
10105 u32 attrs;
10106 @@ -1988,8 +1999,8 @@ static void sun4v_log_error(struct pt_regs *regs, struct sun4v_error_entry *ent,
10107
10108 show_regs(regs);
10109
10110 - if ((cnt = atomic_read(ocnt)) != 0) {
10111 - atomic_set(ocnt, 0);
10112 + if ((cnt = atomic_read_unchecked(ocnt)) != 0) {
10113 + atomic_set_unchecked(ocnt, 0);
10114 wmb();
10115 printk("%s: Queue overflowed %d times.\n",
10116 pfx, cnt);
10117 @@ -2046,7 +2057,7 @@ out:
10118 */
10119 void sun4v_resum_overflow(struct pt_regs *regs)
10120 {
10121 - atomic_inc(&sun4v_resum_oflow_cnt);
10122 + atomic_inc_unchecked(&sun4v_resum_oflow_cnt);
10123 }
10124
10125 /* We run with %pil set to PIL_NORMAL_MAX and PSTATE_IE enabled in %pstate.
10126 @@ -2099,7 +2110,7 @@ void sun4v_nonresum_overflow(struct pt_regs *regs)
10127 /* XXX Actually even this can make not that much sense. Perhaps
10128 * XXX we should just pull the plug and panic directly from here?
10129 */
10130 - atomic_inc(&sun4v_nonresum_oflow_cnt);
10131 + atomic_inc_unchecked(&sun4v_nonresum_oflow_cnt);
10132 }
10133
10134 unsigned long sun4v_err_itlb_vaddr;
10135 @@ -2114,9 +2125,9 @@ void sun4v_itlb_error_report(struct pt_regs *regs, int tl)
10136
10137 printk(KERN_EMERG "SUN4V-ITLB: Error at TPC[%lx], tl %d\n",
10138 regs->tpc, tl);
10139 - printk(KERN_EMERG "SUN4V-ITLB: TPC<%pS>\n", (void *) regs->tpc);
10140 + printk(KERN_EMERG "SUN4V-ITLB: TPC<%pA>\n", (void *) regs->tpc);
10141 printk(KERN_EMERG "SUN4V-ITLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10142 - printk(KERN_EMERG "SUN4V-ITLB: O7<%pS>\n",
10143 + printk(KERN_EMERG "SUN4V-ITLB: O7<%pA>\n",
10144 (void *) regs->u_regs[UREG_I7]);
10145 printk(KERN_EMERG "SUN4V-ITLB: vaddr[%lx] ctx[%lx] "
10146 "pte[%lx] error[%lx]\n",
10147 @@ -2138,9 +2149,9 @@ void sun4v_dtlb_error_report(struct pt_regs *regs, int tl)
10148
10149 printk(KERN_EMERG "SUN4V-DTLB: Error at TPC[%lx], tl %d\n",
10150 regs->tpc, tl);
10151 - printk(KERN_EMERG "SUN4V-DTLB: TPC<%pS>\n", (void *) regs->tpc);
10152 + printk(KERN_EMERG "SUN4V-DTLB: TPC<%pA>\n", (void *) regs->tpc);
10153 printk(KERN_EMERG "SUN4V-DTLB: O7[%lx]\n", regs->u_regs[UREG_I7]);
10154 - printk(KERN_EMERG "SUN4V-DTLB: O7<%pS>\n",
10155 + printk(KERN_EMERG "SUN4V-DTLB: O7<%pA>\n",
10156 (void *) regs->u_regs[UREG_I7]);
10157 printk(KERN_EMERG "SUN4V-DTLB: vaddr[%lx] ctx[%lx] "
10158 "pte[%lx] error[%lx]\n",
10159 @@ -2359,13 +2370,13 @@ void show_stack(struct task_struct *tsk, unsigned long *_ksp)
10160 fp = (unsigned long)sf->fp + STACK_BIAS;
10161 }
10162
10163 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10164 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10165 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
10166 if ((pc + 8UL) == (unsigned long) &return_to_handler) {
10167 int index = tsk->curr_ret_stack;
10168 if (tsk->ret_stack && index >= graph) {
10169 pc = tsk->ret_stack[index - graph].ret;
10170 - printk(" [%016lx] %pS\n", pc, (void *) pc);
10171 + printk(" [%016lx] %pA\n", pc, (void *) pc);
10172 graph++;
10173 }
10174 }
10175 @@ -2383,6 +2394,8 @@ static inline struct reg_window *kernel_stack_up(struct reg_window *rw)
10176 return (struct reg_window *) (fp + STACK_BIAS);
10177 }
10178
10179 +extern void gr_handle_kernel_exploit(void);
10180 +
10181 void die_if_kernel(char *str, struct pt_regs *regs)
10182 {
10183 static int die_counter;
10184 @@ -2411,7 +2424,7 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10185 while (rw &&
10186 count++ < 30 &&
10187 kstack_valid(tp, (unsigned long) rw)) {
10188 - printk("Caller[%016lx]: %pS\n", rw->ins[7],
10189 + printk("Caller[%016lx]: %pA\n", rw->ins[7],
10190 (void *) rw->ins[7]);
10191
10192 rw = kernel_stack_up(rw);
10193 @@ -2424,8 +2437,10 @@ void die_if_kernel(char *str, struct pt_regs *regs)
10194 }
10195 user_instruction_dump ((unsigned int __user *) regs->tpc);
10196 }
10197 - if (regs->tstate & TSTATE_PRIV)
10198 + if (regs->tstate & TSTATE_PRIV) {
10199 + gr_handle_kernel_exploit();
10200 do_exit(SIGKILL);
10201 + }
10202 do_exit(SIGSEGV);
10203 }
10204 EXPORT_SYMBOL(die_if_kernel);
10205 diff --git a/arch/sparc/kernel/unaligned_64.c b/arch/sparc/kernel/unaligned_64.c
10206 index 3c1a7cb..73e1923 100644
10207 --- a/arch/sparc/kernel/unaligned_64.c
10208 +++ b/arch/sparc/kernel/unaligned_64.c
10209 @@ -289,7 +289,7 @@ static void log_unaligned(struct pt_regs *regs)
10210 static DEFINE_RATELIMIT_STATE(ratelimit, 5 * HZ, 5);
10211
10212 if (__ratelimit(&ratelimit)) {
10213 - printk("Kernel unaligned access at TPC[%lx] %pS\n",
10214 + printk("Kernel unaligned access at TPC[%lx] %pA\n",
10215 regs->tpc, (void *) regs->tpc);
10216 }
10217 }
10218 diff --git a/arch/sparc/lib/Makefile b/arch/sparc/lib/Makefile
10219 index dbe119b..089c7c1 100644
10220 --- a/arch/sparc/lib/Makefile
10221 +++ b/arch/sparc/lib/Makefile
10222 @@ -2,7 +2,7 @@
10223 #
10224
10225 asflags-y := -ansi -DST_DIV0=0x02
10226 -ccflags-y := -Werror
10227 +#ccflags-y := -Werror
10228
10229 lib-$(CONFIG_SPARC32) += ashrdi3.o
10230 lib-$(CONFIG_SPARC32) += memcpy.o memset.o
10231 diff --git a/arch/sparc/lib/atomic_64.S b/arch/sparc/lib/atomic_64.S
10232 index 85c233d..68500e0 100644
10233 --- a/arch/sparc/lib/atomic_64.S
10234 +++ b/arch/sparc/lib/atomic_64.S
10235 @@ -17,7 +17,12 @@
10236 ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10237 BACKOFF_SETUP(%o2)
10238 1: lduw [%o1], %g1
10239 - add %g1, %o0, %g7
10240 + addcc %g1, %o0, %g7
10241 +
10242 +#ifdef CONFIG_PAX_REFCOUNT
10243 + tvs %icc, 6
10244 +#endif
10245 +
10246 cas [%o1], %g1, %g7
10247 cmp %g1, %g7
10248 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10249 @@ -27,10 +32,28 @@ ENTRY(atomic_add) /* %o0 = increment, %o1 = atomic_ptr */
10250 2: BACKOFF_SPIN(%o2, %o3, 1b)
10251 ENDPROC(atomic_add)
10252
10253 +ENTRY(atomic_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10254 + BACKOFF_SETUP(%o2)
10255 +1: lduw [%o1], %g1
10256 + add %g1, %o0, %g7
10257 + cas [%o1], %g1, %g7
10258 + cmp %g1, %g7
10259 + bne,pn %icc, 2f
10260 + nop
10261 + retl
10262 + nop
10263 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10264 +ENDPROC(atomic_add_unchecked)
10265 +
10266 ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10267 BACKOFF_SETUP(%o2)
10268 1: lduw [%o1], %g1
10269 - sub %g1, %o0, %g7
10270 + subcc %g1, %o0, %g7
10271 +
10272 +#ifdef CONFIG_PAX_REFCOUNT
10273 + tvs %icc, 6
10274 +#endif
10275 +
10276 cas [%o1], %g1, %g7
10277 cmp %g1, %g7
10278 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10279 @@ -40,10 +63,28 @@ ENTRY(atomic_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10280 2: BACKOFF_SPIN(%o2, %o3, 1b)
10281 ENDPROC(atomic_sub)
10282
10283 +ENTRY(atomic_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10284 + BACKOFF_SETUP(%o2)
10285 +1: lduw [%o1], %g1
10286 + sub %g1, %o0, %g7
10287 + cas [%o1], %g1, %g7
10288 + cmp %g1, %g7
10289 + bne,pn %icc, 2f
10290 + nop
10291 + retl
10292 + nop
10293 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10294 +ENDPROC(atomic_sub_unchecked)
10295 +
10296 ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10297 BACKOFF_SETUP(%o2)
10298 1: lduw [%o1], %g1
10299 - add %g1, %o0, %g7
10300 + addcc %g1, %o0, %g7
10301 +
10302 +#ifdef CONFIG_PAX_REFCOUNT
10303 + tvs %icc, 6
10304 +#endif
10305 +
10306 cas [%o1], %g1, %g7
10307 cmp %g1, %g7
10308 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10309 @@ -53,10 +94,29 @@ ENTRY(atomic_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10310 2: BACKOFF_SPIN(%o2, %o3, 1b)
10311 ENDPROC(atomic_add_ret)
10312
10313 +ENTRY(atomic_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10314 + BACKOFF_SETUP(%o2)
10315 +1: lduw [%o1], %g1
10316 + addcc %g1, %o0, %g7
10317 + cas [%o1], %g1, %g7
10318 + cmp %g1, %g7
10319 + bne,pn %icc, 2f
10320 + add %g7, %o0, %g7
10321 + sra %g7, 0, %o0
10322 + retl
10323 + nop
10324 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10325 +ENDPROC(atomic_add_ret_unchecked)
10326 +
10327 ENTRY(atomic_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10328 BACKOFF_SETUP(%o2)
10329 1: lduw [%o1], %g1
10330 - sub %g1, %o0, %g7
10331 + subcc %g1, %o0, %g7
10332 +
10333 +#ifdef CONFIG_PAX_REFCOUNT
10334 + tvs %icc, 6
10335 +#endif
10336 +
10337 cas [%o1], %g1, %g7
10338 cmp %g1, %g7
10339 bne,pn %icc, BACKOFF_LABEL(2f, 1b)
10340 @@ -69,7 +129,12 @@ ENDPROC(atomic_sub_ret)
10341 ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10342 BACKOFF_SETUP(%o2)
10343 1: ldx [%o1], %g1
10344 - add %g1, %o0, %g7
10345 + addcc %g1, %o0, %g7
10346 +
10347 +#ifdef CONFIG_PAX_REFCOUNT
10348 + tvs %xcc, 6
10349 +#endif
10350 +
10351 casx [%o1], %g1, %g7
10352 cmp %g1, %g7
10353 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10354 @@ -79,10 +144,28 @@ ENTRY(atomic64_add) /* %o0 = increment, %o1 = atomic_ptr */
10355 2: BACKOFF_SPIN(%o2, %o3, 1b)
10356 ENDPROC(atomic64_add)
10357
10358 +ENTRY(atomic64_add_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10359 + BACKOFF_SETUP(%o2)
10360 +1: ldx [%o1], %g1
10361 + addcc %g1, %o0, %g7
10362 + casx [%o1], %g1, %g7
10363 + cmp %g1, %g7
10364 + bne,pn %xcc, 2f
10365 + nop
10366 + retl
10367 + nop
10368 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10369 +ENDPROC(atomic64_add_unchecked)
10370 +
10371 ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10372 BACKOFF_SETUP(%o2)
10373 1: ldx [%o1], %g1
10374 - sub %g1, %o0, %g7
10375 + subcc %g1, %o0, %g7
10376 +
10377 +#ifdef CONFIG_PAX_REFCOUNT
10378 + tvs %xcc, 6
10379 +#endif
10380 +
10381 casx [%o1], %g1, %g7
10382 cmp %g1, %g7
10383 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10384 @@ -92,10 +175,28 @@ ENTRY(atomic64_sub) /* %o0 = decrement, %o1 = atomic_ptr */
10385 2: BACKOFF_SPIN(%o2, %o3, 1b)
10386 ENDPROC(atomic64_sub)
10387
10388 +ENTRY(atomic64_sub_unchecked) /* %o0 = decrement, %o1 = atomic_ptr */
10389 + BACKOFF_SETUP(%o2)
10390 +1: ldx [%o1], %g1
10391 + subcc %g1, %o0, %g7
10392 + casx [%o1], %g1, %g7
10393 + cmp %g1, %g7
10394 + bne,pn %xcc, 2f
10395 + nop
10396 + retl
10397 + nop
10398 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10399 +ENDPROC(atomic64_sub_unchecked)
10400 +
10401 ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10402 BACKOFF_SETUP(%o2)
10403 1: ldx [%o1], %g1
10404 - add %g1, %o0, %g7
10405 + addcc %g1, %o0, %g7
10406 +
10407 +#ifdef CONFIG_PAX_REFCOUNT
10408 + tvs %xcc, 6
10409 +#endif
10410 +
10411 casx [%o1], %g1, %g7
10412 cmp %g1, %g7
10413 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10414 @@ -105,10 +206,29 @@ ENTRY(atomic64_add_ret) /* %o0 = increment, %o1 = atomic_ptr */
10415 2: BACKOFF_SPIN(%o2, %o3, 1b)
10416 ENDPROC(atomic64_add_ret)
10417
10418 +ENTRY(atomic64_add_ret_unchecked) /* %o0 = increment, %o1 = atomic_ptr */
10419 + BACKOFF_SETUP(%o2)
10420 +1: ldx [%o1], %g1
10421 + addcc %g1, %o0, %g7
10422 + casx [%o1], %g1, %g7
10423 + cmp %g1, %g7
10424 + bne,pn %xcc, 2f
10425 + add %g7, %o0, %g7
10426 + mov %g7, %o0
10427 + retl
10428 + nop
10429 +2: BACKOFF_SPIN(%o2, %o3, 1b)
10430 +ENDPROC(atomic64_add_ret_unchecked)
10431 +
10432 ENTRY(atomic64_sub_ret) /* %o0 = decrement, %o1 = atomic_ptr */
10433 BACKOFF_SETUP(%o2)
10434 1: ldx [%o1], %g1
10435 - sub %g1, %o0, %g7
10436 + subcc %g1, %o0, %g7
10437 +
10438 +#ifdef CONFIG_PAX_REFCOUNT
10439 + tvs %xcc, 6
10440 +#endif
10441 +
10442 casx [%o1], %g1, %g7
10443 cmp %g1, %g7
10444 bne,pn %xcc, BACKOFF_LABEL(2f, 1b)
10445 diff --git a/arch/sparc/lib/ksyms.c b/arch/sparc/lib/ksyms.c
10446 index 323335b..ed85ea2 100644
10447 --- a/arch/sparc/lib/ksyms.c
10448 +++ b/arch/sparc/lib/ksyms.c
10449 @@ -100,12 +100,18 @@ EXPORT_SYMBOL(__clear_user);
10450
10451 /* Atomic counter implementation. */
10452 EXPORT_SYMBOL(atomic_add);
10453 +EXPORT_SYMBOL(atomic_add_unchecked);
10454 EXPORT_SYMBOL(atomic_add_ret);
10455 +EXPORT_SYMBOL(atomic_add_ret_unchecked);
10456 EXPORT_SYMBOL(atomic_sub);
10457 +EXPORT_SYMBOL(atomic_sub_unchecked);
10458 EXPORT_SYMBOL(atomic_sub_ret);
10459 EXPORT_SYMBOL(atomic64_add);
10460 +EXPORT_SYMBOL(atomic64_add_unchecked);
10461 EXPORT_SYMBOL(atomic64_add_ret);
10462 +EXPORT_SYMBOL(atomic64_add_ret_unchecked);
10463 EXPORT_SYMBOL(atomic64_sub);
10464 +EXPORT_SYMBOL(atomic64_sub_unchecked);
10465 EXPORT_SYMBOL(atomic64_sub_ret);
10466 EXPORT_SYMBOL(atomic64_dec_if_positive);
10467
10468 diff --git a/arch/sparc/mm/Makefile b/arch/sparc/mm/Makefile
10469 index 30c3ecc..736f015 100644
10470 --- a/arch/sparc/mm/Makefile
10471 +++ b/arch/sparc/mm/Makefile
10472 @@ -2,7 +2,7 @@
10473 #
10474
10475 asflags-y := -ansi
10476 -ccflags-y := -Werror
10477 +#ccflags-y := -Werror
10478
10479 obj-$(CONFIG_SPARC64) += ultra.o tlb.o tsb.o gup.o
10480 obj-y += fault_$(BITS).o
10481 diff --git a/arch/sparc/mm/fault_32.c b/arch/sparc/mm/fault_32.c
10482 index 59dbd46..1dd7f5e 100644
10483 --- a/arch/sparc/mm/fault_32.c
10484 +++ b/arch/sparc/mm/fault_32.c
10485 @@ -21,6 +21,9 @@
10486 #include <linux/perf_event.h>
10487 #include <linux/interrupt.h>
10488 #include <linux/kdebug.h>
10489 +#include <linux/slab.h>
10490 +#include <linux/pagemap.h>
10491 +#include <linux/compiler.h>
10492
10493 #include <asm/page.h>
10494 #include <asm/pgtable.h>
10495 @@ -159,6 +162,277 @@ static unsigned long compute_si_addr(struct pt_regs *regs, int text_fault)
10496 return safe_compute_effective_address(regs, insn);
10497 }
10498
10499 +#ifdef CONFIG_PAX_PAGEEXEC
10500 +#ifdef CONFIG_PAX_DLRESOLVE
10501 +static void pax_emuplt_close(struct vm_area_struct *vma)
10502 +{
10503 + vma->vm_mm->call_dl_resolve = 0UL;
10504 +}
10505 +
10506 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10507 +{
10508 + unsigned int *kaddr;
10509 +
10510 + vmf->page = alloc_page(GFP_HIGHUSER);
10511 + if (!vmf->page)
10512 + return VM_FAULT_OOM;
10513 +
10514 + kaddr = kmap(vmf->page);
10515 + memset(kaddr, 0, PAGE_SIZE);
10516 + kaddr[0] = 0x9DE3BFA8U; /* save */
10517 + flush_dcache_page(vmf->page);
10518 + kunmap(vmf->page);
10519 + return VM_FAULT_MAJOR;
10520 +}
10521 +
10522 +static const struct vm_operations_struct pax_vm_ops = {
10523 + .close = pax_emuplt_close,
10524 + .fault = pax_emuplt_fault
10525 +};
10526 +
10527 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10528 +{
10529 + int ret;
10530 +
10531 + INIT_LIST_HEAD(&vma->anon_vma_chain);
10532 + vma->vm_mm = current->mm;
10533 + vma->vm_start = addr;
10534 + vma->vm_end = addr + PAGE_SIZE;
10535 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10536 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10537 + vma->vm_ops = &pax_vm_ops;
10538 +
10539 + ret = insert_vm_struct(current->mm, vma);
10540 + if (ret)
10541 + return ret;
10542 +
10543 + ++current->mm->total_vm;
10544 + return 0;
10545 +}
10546 +#endif
10547 +
10548 +/*
10549 + * PaX: decide what to do with offenders (regs->pc = fault address)
10550 + *
10551 + * returns 1 when task should be killed
10552 + * 2 when patched PLT trampoline was detected
10553 + * 3 when unpatched PLT trampoline was detected
10554 + */
10555 +static int pax_handle_fetch_fault(struct pt_regs *regs)
10556 +{
10557 +
10558 +#ifdef CONFIG_PAX_EMUPLT
10559 + int err;
10560 +
10561 + do { /* PaX: patched PLT emulation #1 */
10562 + unsigned int sethi1, sethi2, jmpl;
10563 +
10564 + err = get_user(sethi1, (unsigned int *)regs->pc);
10565 + err |= get_user(sethi2, (unsigned int *)(regs->pc+4));
10566 + err |= get_user(jmpl, (unsigned int *)(regs->pc+8));
10567 +
10568 + if (err)
10569 + break;
10570 +
10571 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10572 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
10573 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
10574 + {
10575 + unsigned int addr;
10576 +
10577 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10578 + addr = regs->u_regs[UREG_G1];
10579 + addr += (((jmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10580 + regs->pc = addr;
10581 + regs->npc = addr+4;
10582 + return 2;
10583 + }
10584 + } while (0);
10585 +
10586 + do { /* PaX: patched PLT emulation #2 */
10587 + unsigned int ba;
10588 +
10589 + err = get_user(ba, (unsigned int *)regs->pc);
10590 +
10591 + if (err)
10592 + break;
10593 +
10594 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10595 + unsigned int addr;
10596 +
10597 + if ((ba & 0xFFC00000U) == 0x30800000U)
10598 + addr = regs->pc + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10599 + else
10600 + addr = regs->pc + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10601 + regs->pc = addr;
10602 + regs->npc = addr+4;
10603 + return 2;
10604 + }
10605 + } while (0);
10606 +
10607 + do { /* PaX: patched PLT emulation #3 */
10608 + unsigned int sethi, bajmpl, nop;
10609 +
10610 + err = get_user(sethi, (unsigned int *)regs->pc);
10611 + err |= get_user(bajmpl, (unsigned int *)(regs->pc+4));
10612 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
10613 +
10614 + if (err)
10615 + break;
10616 +
10617 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
10618 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10619 + nop == 0x01000000U)
10620 + {
10621 + unsigned int addr;
10622 +
10623 + addr = (sethi & 0x003FFFFFU) << 10;
10624 + regs->u_regs[UREG_G1] = addr;
10625 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10626 + addr += (((bajmpl | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10627 + else
10628 + addr = regs->pc + ((((bajmpl | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10629 + regs->pc = addr;
10630 + regs->npc = addr+4;
10631 + return 2;
10632 + }
10633 + } while (0);
10634 +
10635 + do { /* PaX: unpatched PLT emulation step 1 */
10636 + unsigned int sethi, ba, nop;
10637 +
10638 + err = get_user(sethi, (unsigned int *)regs->pc);
10639 + err |= get_user(ba, (unsigned int *)(regs->pc+4));
10640 + err |= get_user(nop, (unsigned int *)(regs->pc+8));
10641 +
10642 + if (err)
10643 + break;
10644 +
10645 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
10646 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
10647 + nop == 0x01000000U)
10648 + {
10649 + unsigned int addr, save, call;
10650 +
10651 + if ((ba & 0xFFC00000U) == 0x30800000U)
10652 + addr = regs->pc + 4 + ((((ba | 0xFFC00000U) ^ 0x00200000U) + 0x00200000U) << 2);
10653 + else
10654 + addr = regs->pc + 4 + ((((ba | 0xFFF80000U) ^ 0x00040000U) + 0x00040000U) << 2);
10655 +
10656 + err = get_user(save, (unsigned int *)addr);
10657 + err |= get_user(call, (unsigned int *)(addr+4));
10658 + err |= get_user(nop, (unsigned int *)(addr+8));
10659 + if (err)
10660 + break;
10661 +
10662 +#ifdef CONFIG_PAX_DLRESOLVE
10663 + if (save == 0x9DE3BFA8U &&
10664 + (call & 0xC0000000U) == 0x40000000U &&
10665 + nop == 0x01000000U)
10666 + {
10667 + struct vm_area_struct *vma;
10668 + unsigned long call_dl_resolve;
10669 +
10670 + down_read(&current->mm->mmap_sem);
10671 + call_dl_resolve = current->mm->call_dl_resolve;
10672 + up_read(&current->mm->mmap_sem);
10673 + if (likely(call_dl_resolve))
10674 + goto emulate;
10675 +
10676 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
10677 +
10678 + down_write(&current->mm->mmap_sem);
10679 + if (current->mm->call_dl_resolve) {
10680 + call_dl_resolve = current->mm->call_dl_resolve;
10681 + up_write(&current->mm->mmap_sem);
10682 + if (vma)
10683 + kmem_cache_free(vm_area_cachep, vma);
10684 + goto emulate;
10685 + }
10686 +
10687 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
10688 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
10689 + up_write(&current->mm->mmap_sem);
10690 + if (vma)
10691 + kmem_cache_free(vm_area_cachep, vma);
10692 + return 1;
10693 + }
10694 +
10695 + if (pax_insert_vma(vma, call_dl_resolve)) {
10696 + up_write(&current->mm->mmap_sem);
10697 + kmem_cache_free(vm_area_cachep, vma);
10698 + return 1;
10699 + }
10700 +
10701 + current->mm->call_dl_resolve = call_dl_resolve;
10702 + up_write(&current->mm->mmap_sem);
10703 +
10704 +emulate:
10705 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10706 + regs->pc = call_dl_resolve;
10707 + regs->npc = addr+4;
10708 + return 3;
10709 + }
10710 +#endif
10711 +
10712 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
10713 + if ((save & 0xFFC00000U) == 0x05000000U &&
10714 + (call & 0xFFFFE000U) == 0x85C0A000U &&
10715 + nop == 0x01000000U)
10716 + {
10717 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
10718 + regs->u_regs[UREG_G2] = addr + 4;
10719 + addr = (save & 0x003FFFFFU) << 10;
10720 + addr += (((call | 0xFFFFE000U) ^ 0x00001000U) + 0x00001000U);
10721 + regs->pc = addr;
10722 + regs->npc = addr+4;
10723 + return 3;
10724 + }
10725 + }
10726 + } while (0);
10727 +
10728 + do { /* PaX: unpatched PLT emulation step 2 */
10729 + unsigned int save, call, nop;
10730 +
10731 + err = get_user(save, (unsigned int *)(regs->pc-4));
10732 + err |= get_user(call, (unsigned int *)regs->pc);
10733 + err |= get_user(nop, (unsigned int *)(regs->pc+4));
10734 + if (err)
10735 + break;
10736 +
10737 + if (save == 0x9DE3BFA8U &&
10738 + (call & 0xC0000000U) == 0x40000000U &&
10739 + nop == 0x01000000U)
10740 + {
10741 + unsigned int dl_resolve = regs->pc + ((((call | 0xC0000000U) ^ 0x20000000U) + 0x20000000U) << 2);
10742 +
10743 + regs->u_regs[UREG_RETPC] = regs->pc;
10744 + regs->pc = dl_resolve;
10745 + regs->npc = dl_resolve+4;
10746 + return 3;
10747 + }
10748 + } while (0);
10749 +#endif
10750 +
10751 + return 1;
10752 +}
10753 +
10754 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
10755 +{
10756 + unsigned long i;
10757 +
10758 + printk(KERN_ERR "PAX: bytes at PC: ");
10759 + for (i = 0; i < 8; i++) {
10760 + unsigned int c;
10761 + if (get_user(c, (unsigned int *)pc+i))
10762 + printk(KERN_CONT "???????? ");
10763 + else
10764 + printk(KERN_CONT "%08x ", c);
10765 + }
10766 + printk("\n");
10767 +}
10768 +#endif
10769 +
10770 static noinline void do_fault_siginfo(int code, int sig, struct pt_regs *regs,
10771 int text_fault)
10772 {
10773 @@ -229,6 +503,24 @@ good_area:
10774 if (!(vma->vm_flags & VM_WRITE))
10775 goto bad_area;
10776 } else {
10777 +
10778 +#ifdef CONFIG_PAX_PAGEEXEC
10779 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && text_fault && !(vma->vm_flags & VM_EXEC)) {
10780 + up_read(&mm->mmap_sem);
10781 + switch (pax_handle_fetch_fault(regs)) {
10782 +
10783 +#ifdef CONFIG_PAX_EMUPLT
10784 + case 2:
10785 + case 3:
10786 + return;
10787 +#endif
10788 +
10789 + }
10790 + pax_report_fault(regs, (void *)regs->pc, (void *)regs->u_regs[UREG_FP]);
10791 + do_group_exit(SIGKILL);
10792 + }
10793 +#endif
10794 +
10795 /* Allow reads even for write-only mappings */
10796 if (!(vma->vm_flags & (VM_READ | VM_EXEC)))
10797 goto bad_area;
10798 diff --git a/arch/sparc/mm/fault_64.c b/arch/sparc/mm/fault_64.c
10799 index 69bb818..6ca35c8 100644
10800 --- a/arch/sparc/mm/fault_64.c
10801 +++ b/arch/sparc/mm/fault_64.c
10802 @@ -22,6 +22,9 @@
10803 #include <linux/kdebug.h>
10804 #include <linux/percpu.h>
10805 #include <linux/context_tracking.h>
10806 +#include <linux/slab.h>
10807 +#include <linux/pagemap.h>
10808 +#include <linux/compiler.h>
10809
10810 #include <asm/page.h>
10811 #include <asm/pgtable.h>
10812 @@ -75,7 +78,7 @@ static void __kprobes bad_kernel_pc(struct pt_regs *regs, unsigned long vaddr)
10813 printk(KERN_CRIT "OOPS: Bogus kernel PC [%016lx] in fault handler\n",
10814 regs->tpc);
10815 printk(KERN_CRIT "OOPS: RPC [%016lx]\n", regs->u_regs[15]);
10816 - printk("OOPS: RPC <%pS>\n", (void *) regs->u_regs[15]);
10817 + printk("OOPS: RPC <%pA>\n", (void *) regs->u_regs[15]);
10818 printk(KERN_CRIT "OOPS: Fault was to vaddr[%lx]\n", vaddr);
10819 dump_stack();
10820 unhandled_fault(regs->tpc, current, regs);
10821 @@ -271,6 +274,466 @@ static void noinline __kprobes bogus_32bit_fault_address(struct pt_regs *regs,
10822 show_regs(regs);
10823 }
10824
10825 +#ifdef CONFIG_PAX_PAGEEXEC
10826 +#ifdef CONFIG_PAX_DLRESOLVE
10827 +static void pax_emuplt_close(struct vm_area_struct *vma)
10828 +{
10829 + vma->vm_mm->call_dl_resolve = 0UL;
10830 +}
10831 +
10832 +static int pax_emuplt_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
10833 +{
10834 + unsigned int *kaddr;
10835 +
10836 + vmf->page = alloc_page(GFP_HIGHUSER);
10837 + if (!vmf->page)
10838 + return VM_FAULT_OOM;
10839 +
10840 + kaddr = kmap(vmf->page);
10841 + memset(kaddr, 0, PAGE_SIZE);
10842 + kaddr[0] = 0x9DE3BFA8U; /* save */
10843 + flush_dcache_page(vmf->page);
10844 + kunmap(vmf->page);
10845 + return VM_FAULT_MAJOR;
10846 +}
10847 +
10848 +static const struct vm_operations_struct pax_vm_ops = {
10849 + .close = pax_emuplt_close,
10850 + .fault = pax_emuplt_fault
10851 +};
10852 +
10853 +static int pax_insert_vma(struct vm_area_struct *vma, unsigned long addr)
10854 +{
10855 + int ret;
10856 +
10857 + INIT_LIST_HEAD(&vma->anon_vma_chain);
10858 + vma->vm_mm = current->mm;
10859 + vma->vm_start = addr;
10860 + vma->vm_end = addr + PAGE_SIZE;
10861 + vma->vm_flags = VM_READ | VM_EXEC | VM_MAYREAD | VM_MAYEXEC;
10862 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
10863 + vma->vm_ops = &pax_vm_ops;
10864 +
10865 + ret = insert_vm_struct(current->mm, vma);
10866 + if (ret)
10867 + return ret;
10868 +
10869 + ++current->mm->total_vm;
10870 + return 0;
10871 +}
10872 +#endif
10873 +
10874 +/*
10875 + * PaX: decide what to do with offenders (regs->tpc = fault address)
10876 + *
10877 + * returns 1 when task should be killed
10878 + * 2 when patched PLT trampoline was detected
10879 + * 3 when unpatched PLT trampoline was detected
10880 + */
10881 +static int pax_handle_fetch_fault(struct pt_regs *regs)
10882 +{
10883 +
10884 +#ifdef CONFIG_PAX_EMUPLT
10885 + int err;
10886 +
10887 + do { /* PaX: patched PLT emulation #1 */
10888 + unsigned int sethi1, sethi2, jmpl;
10889 +
10890 + err = get_user(sethi1, (unsigned int *)regs->tpc);
10891 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+4));
10892 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+8));
10893 +
10894 + if (err)
10895 + break;
10896 +
10897 + if ((sethi1 & 0xFFC00000U) == 0x03000000U &&
10898 + (sethi2 & 0xFFC00000U) == 0x03000000U &&
10899 + (jmpl & 0xFFFFE000U) == 0x81C06000U)
10900 + {
10901 + unsigned long addr;
10902 +
10903 + regs->u_regs[UREG_G1] = (sethi2 & 0x003FFFFFU) << 10;
10904 + addr = regs->u_regs[UREG_G1];
10905 + addr += (((jmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10906 +
10907 + if (test_thread_flag(TIF_32BIT))
10908 + addr &= 0xFFFFFFFFUL;
10909 +
10910 + regs->tpc = addr;
10911 + regs->tnpc = addr+4;
10912 + return 2;
10913 + }
10914 + } while (0);
10915 +
10916 + do { /* PaX: patched PLT emulation #2 */
10917 + unsigned int ba;
10918 +
10919 + err = get_user(ba, (unsigned int *)regs->tpc);
10920 +
10921 + if (err)
10922 + break;
10923 +
10924 + if ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30480000U) {
10925 + unsigned long addr;
10926 +
10927 + if ((ba & 0xFFC00000U) == 0x30800000U)
10928 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
10929 + else
10930 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10931 +
10932 + if (test_thread_flag(TIF_32BIT))
10933 + addr &= 0xFFFFFFFFUL;
10934 +
10935 + regs->tpc = addr;
10936 + regs->tnpc = addr+4;
10937 + return 2;
10938 + }
10939 + } while (0);
10940 +
10941 + do { /* PaX: patched PLT emulation #3 */
10942 + unsigned int sethi, bajmpl, nop;
10943 +
10944 + err = get_user(sethi, (unsigned int *)regs->tpc);
10945 + err |= get_user(bajmpl, (unsigned int *)(regs->tpc+4));
10946 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
10947 +
10948 + if (err)
10949 + break;
10950 +
10951 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
10952 + ((bajmpl & 0xFFFFE000U) == 0x81C06000U || (bajmpl & 0xFFF80000U) == 0x30480000U) &&
10953 + nop == 0x01000000U)
10954 + {
10955 + unsigned long addr;
10956 +
10957 + addr = (sethi & 0x003FFFFFU) << 10;
10958 + regs->u_regs[UREG_G1] = addr;
10959 + if ((bajmpl & 0xFFFFE000U) == 0x81C06000U)
10960 + addr += (((bajmpl | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
10961 + else
10962 + addr = regs->tpc + ((((bajmpl | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
10963 +
10964 + if (test_thread_flag(TIF_32BIT))
10965 + addr &= 0xFFFFFFFFUL;
10966 +
10967 + regs->tpc = addr;
10968 + regs->tnpc = addr+4;
10969 + return 2;
10970 + }
10971 + } while (0);
10972 +
10973 + do { /* PaX: patched PLT emulation #4 */
10974 + unsigned int sethi, mov1, call, mov2;
10975 +
10976 + err = get_user(sethi, (unsigned int *)regs->tpc);
10977 + err |= get_user(mov1, (unsigned int *)(regs->tpc+4));
10978 + err |= get_user(call, (unsigned int *)(regs->tpc+8));
10979 + err |= get_user(mov2, (unsigned int *)(regs->tpc+12));
10980 +
10981 + if (err)
10982 + break;
10983 +
10984 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
10985 + mov1 == 0x8210000FU &&
10986 + (call & 0xC0000000U) == 0x40000000U &&
10987 + mov2 == 0x9E100001U)
10988 + {
10989 + unsigned long addr;
10990 +
10991 + regs->u_regs[UREG_G1] = regs->u_regs[UREG_RETPC];
10992 + addr = regs->tpc + 4 + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
10993 +
10994 + if (test_thread_flag(TIF_32BIT))
10995 + addr &= 0xFFFFFFFFUL;
10996 +
10997 + regs->tpc = addr;
10998 + regs->tnpc = addr+4;
10999 + return 2;
11000 + }
11001 + } while (0);
11002 +
11003 + do { /* PaX: patched PLT emulation #5 */
11004 + unsigned int sethi, sethi1, sethi2, or1, or2, sllx, jmpl, nop;
11005 +
11006 + err = get_user(sethi, (unsigned int *)regs->tpc);
11007 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11008 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11009 + err |= get_user(or1, (unsigned int *)(regs->tpc+12));
11010 + err |= get_user(or2, (unsigned int *)(regs->tpc+16));
11011 + err |= get_user(sllx, (unsigned int *)(regs->tpc+20));
11012 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+24));
11013 + err |= get_user(nop, (unsigned int *)(regs->tpc+28));
11014 +
11015 + if (err)
11016 + break;
11017 +
11018 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11019 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11020 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11021 + (or1 & 0xFFFFE000U) == 0x82106000U &&
11022 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11023 + sllx == 0x83287020U &&
11024 + jmpl == 0x81C04005U &&
11025 + nop == 0x01000000U)
11026 + {
11027 + unsigned long addr;
11028 +
11029 + regs->u_regs[UREG_G1] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11030 + regs->u_regs[UREG_G1] <<= 32;
11031 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11032 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11033 + regs->tpc = addr;
11034 + regs->tnpc = addr+4;
11035 + return 2;
11036 + }
11037 + } while (0);
11038 +
11039 + do { /* PaX: patched PLT emulation #6 */
11040 + unsigned int sethi, sethi1, sethi2, sllx, or, jmpl, nop;
11041 +
11042 + err = get_user(sethi, (unsigned int *)regs->tpc);
11043 + err |= get_user(sethi1, (unsigned int *)(regs->tpc+4));
11044 + err |= get_user(sethi2, (unsigned int *)(regs->tpc+8));
11045 + err |= get_user(sllx, (unsigned int *)(regs->tpc+12));
11046 + err |= get_user(or, (unsigned int *)(regs->tpc+16));
11047 + err |= get_user(jmpl, (unsigned int *)(regs->tpc+20));
11048 + err |= get_user(nop, (unsigned int *)(regs->tpc+24));
11049 +
11050 + if (err)
11051 + break;
11052 +
11053 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11054 + (sethi1 & 0xFFC00000U) == 0x03000000U &&
11055 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11056 + sllx == 0x83287020U &&
11057 + (or & 0xFFFFE000U) == 0x8A116000U &&
11058 + jmpl == 0x81C04005U &&
11059 + nop == 0x01000000U)
11060 + {
11061 + unsigned long addr;
11062 +
11063 + regs->u_regs[UREG_G1] = (sethi1 & 0x003FFFFFU) << 10;
11064 + regs->u_regs[UREG_G1] <<= 32;
11065 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or & 0x3FFU);
11066 + addr = regs->u_regs[UREG_G1] + regs->u_regs[UREG_G5];
11067 + regs->tpc = addr;
11068 + regs->tnpc = addr+4;
11069 + return 2;
11070 + }
11071 + } while (0);
11072 +
11073 + do { /* PaX: unpatched PLT emulation step 1 */
11074 + unsigned int sethi, ba, nop;
11075 +
11076 + err = get_user(sethi, (unsigned int *)regs->tpc);
11077 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11078 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11079 +
11080 + if (err)
11081 + break;
11082 +
11083 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11084 + ((ba & 0xFFC00000U) == 0x30800000U || (ba & 0xFFF80000U) == 0x30680000U) &&
11085 + nop == 0x01000000U)
11086 + {
11087 + unsigned long addr;
11088 + unsigned int save, call;
11089 + unsigned int sethi1, sethi2, or1, or2, sllx, add, jmpl;
11090 +
11091 + if ((ba & 0xFFC00000U) == 0x30800000U)
11092 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFC00000UL) ^ 0x00200000UL) + 0x00200000UL) << 2);
11093 + else
11094 + addr = regs->tpc + 4 + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11095 +
11096 + if (test_thread_flag(TIF_32BIT))
11097 + addr &= 0xFFFFFFFFUL;
11098 +
11099 + err = get_user(save, (unsigned int *)addr);
11100 + err |= get_user(call, (unsigned int *)(addr+4));
11101 + err |= get_user(nop, (unsigned int *)(addr+8));
11102 + if (err)
11103 + break;
11104 +
11105 +#ifdef CONFIG_PAX_DLRESOLVE
11106 + if (save == 0x9DE3BFA8U &&
11107 + (call & 0xC0000000U) == 0x40000000U &&
11108 + nop == 0x01000000U)
11109 + {
11110 + struct vm_area_struct *vma;
11111 + unsigned long call_dl_resolve;
11112 +
11113 + down_read(&current->mm->mmap_sem);
11114 + call_dl_resolve = current->mm->call_dl_resolve;
11115 + up_read(&current->mm->mmap_sem);
11116 + if (likely(call_dl_resolve))
11117 + goto emulate;
11118 +
11119 + vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
11120 +
11121 + down_write(&current->mm->mmap_sem);
11122 + if (current->mm->call_dl_resolve) {
11123 + call_dl_resolve = current->mm->call_dl_resolve;
11124 + up_write(&current->mm->mmap_sem);
11125 + if (vma)
11126 + kmem_cache_free(vm_area_cachep, vma);
11127 + goto emulate;
11128 + }
11129 +
11130 + call_dl_resolve = get_unmapped_area(NULL, 0UL, PAGE_SIZE, 0UL, MAP_PRIVATE);
11131 + if (!vma || (call_dl_resolve & ~PAGE_MASK)) {
11132 + up_write(&current->mm->mmap_sem);
11133 + if (vma)
11134 + kmem_cache_free(vm_area_cachep, vma);
11135 + return 1;
11136 + }
11137 +
11138 + if (pax_insert_vma(vma, call_dl_resolve)) {
11139 + up_write(&current->mm->mmap_sem);
11140 + kmem_cache_free(vm_area_cachep, vma);
11141 + return 1;
11142 + }
11143 +
11144 + current->mm->call_dl_resolve = call_dl_resolve;
11145 + up_write(&current->mm->mmap_sem);
11146 +
11147 +emulate:
11148 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11149 + regs->tpc = call_dl_resolve;
11150 + regs->tnpc = addr+4;
11151 + return 3;
11152 + }
11153 +#endif
11154 +
11155 + /* PaX: glibc 2.4+ generates sethi/jmpl instead of save/call */
11156 + if ((save & 0xFFC00000U) == 0x05000000U &&
11157 + (call & 0xFFFFE000U) == 0x85C0A000U &&
11158 + nop == 0x01000000U)
11159 + {
11160 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11161 + regs->u_regs[UREG_G2] = addr + 4;
11162 + addr = (save & 0x003FFFFFU) << 10;
11163 + addr += (((call | 0xFFFFFFFFFFFFE000UL) ^ 0x00001000UL) + 0x00001000UL);
11164 +
11165 + if (test_thread_flag(TIF_32BIT))
11166 + addr &= 0xFFFFFFFFUL;
11167 +
11168 + regs->tpc = addr;
11169 + regs->tnpc = addr+4;
11170 + return 3;
11171 + }
11172 +
11173 + /* PaX: 64-bit PLT stub */
11174 + err = get_user(sethi1, (unsigned int *)addr);
11175 + err |= get_user(sethi2, (unsigned int *)(addr+4));
11176 + err |= get_user(or1, (unsigned int *)(addr+8));
11177 + err |= get_user(or2, (unsigned int *)(addr+12));
11178 + err |= get_user(sllx, (unsigned int *)(addr+16));
11179 + err |= get_user(add, (unsigned int *)(addr+20));
11180 + err |= get_user(jmpl, (unsigned int *)(addr+24));
11181 + err |= get_user(nop, (unsigned int *)(addr+28));
11182 + if (err)
11183 + break;
11184 +
11185 + if ((sethi1 & 0xFFC00000U) == 0x09000000U &&
11186 + (sethi2 & 0xFFC00000U) == 0x0B000000U &&
11187 + (or1 & 0xFFFFE000U) == 0x88112000U &&
11188 + (or2 & 0xFFFFE000U) == 0x8A116000U &&
11189 + sllx == 0x89293020U &&
11190 + add == 0x8A010005U &&
11191 + jmpl == 0x89C14000U &&
11192 + nop == 0x01000000U)
11193 + {
11194 + regs->u_regs[UREG_G1] = (sethi & 0x003FFFFFU) << 10;
11195 + regs->u_regs[UREG_G4] = ((sethi1 & 0x003FFFFFU) << 10) | (or1 & 0x000003FFU);
11196 + regs->u_regs[UREG_G4] <<= 32;
11197 + regs->u_regs[UREG_G5] = ((sethi2 & 0x003FFFFFU) << 10) | (or2 & 0x000003FFU);
11198 + regs->u_regs[UREG_G5] += regs->u_regs[UREG_G4];
11199 + regs->u_regs[UREG_G4] = addr + 24;
11200 + addr = regs->u_regs[UREG_G5];
11201 + regs->tpc = addr;
11202 + regs->tnpc = addr+4;
11203 + return 3;
11204 + }
11205 + }
11206 + } while (0);
11207 +
11208 +#ifdef CONFIG_PAX_DLRESOLVE
11209 + do { /* PaX: unpatched PLT emulation step 2 */
11210 + unsigned int save, call, nop;
11211 +
11212 + err = get_user(save, (unsigned int *)(regs->tpc-4));
11213 + err |= get_user(call, (unsigned int *)regs->tpc);
11214 + err |= get_user(nop, (unsigned int *)(regs->tpc+4));
11215 + if (err)
11216 + break;
11217 +
11218 + if (save == 0x9DE3BFA8U &&
11219 + (call & 0xC0000000U) == 0x40000000U &&
11220 + nop == 0x01000000U)
11221 + {
11222 + unsigned long dl_resolve = regs->tpc + ((((call | 0xFFFFFFFFC0000000UL) ^ 0x20000000UL) + 0x20000000UL) << 2);
11223 +
11224 + if (test_thread_flag(TIF_32BIT))
11225 + dl_resolve &= 0xFFFFFFFFUL;
11226 +
11227 + regs->u_regs[UREG_RETPC] = regs->tpc;
11228 + regs->tpc = dl_resolve;
11229 + regs->tnpc = dl_resolve+4;
11230 + return 3;
11231 + }
11232 + } while (0);
11233 +#endif
11234 +
11235 + do { /* PaX: patched PLT emulation #7, must be AFTER the unpatched PLT emulation */
11236 + unsigned int sethi, ba, nop;
11237 +
11238 + err = get_user(sethi, (unsigned int *)regs->tpc);
11239 + err |= get_user(ba, (unsigned int *)(regs->tpc+4));
11240 + err |= get_user(nop, (unsigned int *)(regs->tpc+8));
11241 +
11242 + if (err)
11243 + break;
11244 +
11245 + if ((sethi & 0xFFC00000U) == 0x03000000U &&
11246 + (ba & 0xFFF00000U) == 0x30600000U &&
11247 + nop == 0x01000000U)
11248 + {
11249 + unsigned long addr;
11250 +
11251 + addr = (sethi & 0x003FFFFFU) << 10;
11252 + regs->u_regs[UREG_G1] = addr;
11253 + addr = regs->tpc + ((((ba | 0xFFFFFFFFFFF80000UL) ^ 0x00040000UL) + 0x00040000UL) << 2);
11254 +
11255 + if (test_thread_flag(TIF_32BIT))
11256 + addr &= 0xFFFFFFFFUL;
11257 +
11258 + regs->tpc = addr;
11259 + regs->tnpc = addr+4;
11260 + return 2;
11261 + }
11262 + } while (0);
11263 +
11264 +#endif
11265 +
11266 + return 1;
11267 +}
11268 +
11269 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
11270 +{
11271 + unsigned long i;
11272 +
11273 + printk(KERN_ERR "PAX: bytes at PC: ");
11274 + for (i = 0; i < 8; i++) {
11275 + unsigned int c;
11276 + if (get_user(c, (unsigned int *)pc+i))
11277 + printk(KERN_CONT "???????? ");
11278 + else
11279 + printk(KERN_CONT "%08x ", c);
11280 + }
11281 + printk("\n");
11282 +}
11283 +#endif
11284 +
11285 asmlinkage void __kprobes do_sparc64_fault(struct pt_regs *regs)
11286 {
11287 enum ctx_state prev_state = exception_enter();
11288 @@ -344,6 +807,29 @@ retry:
11289 if (!vma)
11290 goto bad_area;
11291
11292 +#ifdef CONFIG_PAX_PAGEEXEC
11293 + /* PaX: detect ITLB misses on non-exec pages */
11294 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && vma->vm_start <= address &&
11295 + !(vma->vm_flags & VM_EXEC) && (fault_code & FAULT_CODE_ITLB))
11296 + {
11297 + if (address != regs->tpc)
11298 + goto good_area;
11299 +
11300 + up_read(&mm->mmap_sem);
11301 + switch (pax_handle_fetch_fault(regs)) {
11302 +
11303 +#ifdef CONFIG_PAX_EMUPLT
11304 + case 2:
11305 + case 3:
11306 + return;
11307 +#endif
11308 +
11309 + }
11310 + pax_report_fault(regs, (void *)regs->tpc, (void *)(regs->u_regs[UREG_FP] + STACK_BIAS));
11311 + do_group_exit(SIGKILL);
11312 + }
11313 +#endif
11314 +
11315 /* Pure DTLB misses do not tell us whether the fault causing
11316 * load/store/atomic was a write or not, it only says that there
11317 * was no match. So in such a case we (carefully) read the
11318 diff --git a/arch/sparc/mm/hugetlbpage.c b/arch/sparc/mm/hugetlbpage.c
11319 index 3096317..a7b7654 100644
11320 --- a/arch/sparc/mm/hugetlbpage.c
11321 +++ b/arch/sparc/mm/hugetlbpage.c
11322 @@ -26,7 +26,8 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11323 unsigned long addr,
11324 unsigned long len,
11325 unsigned long pgoff,
11326 - unsigned long flags)
11327 + unsigned long flags,
11328 + unsigned long offset)
11329 {
11330 unsigned long task_size = TASK_SIZE;
11331 struct vm_unmapped_area_info info;
11332 @@ -36,15 +37,22 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *filp,
11333
11334 info.flags = 0;
11335 info.length = len;
11336 - info.low_limit = TASK_UNMAPPED_BASE;
11337 + info.low_limit = mm->mmap_base;
11338 info.high_limit = min(task_size, VA_EXCLUDE_START);
11339 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11340 info.align_offset = 0;
11341 + info.threadstack_offset = offset;
11342 addr = vm_unmapped_area(&info);
11343
11344 if ((addr & ~PAGE_MASK) && task_size > VA_EXCLUDE_END) {
11345 VM_BUG_ON(addr != -ENOMEM);
11346 info.low_limit = VA_EXCLUDE_END;
11347 +
11348 +#ifdef CONFIG_PAX_RANDMMAP
11349 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11350 + info.low_limit += mm->delta_mmap;
11351 +#endif
11352 +
11353 info.high_limit = task_size;
11354 addr = vm_unmapped_area(&info);
11355 }
11356 @@ -56,7 +64,8 @@ static unsigned long
11357 hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11358 const unsigned long len,
11359 const unsigned long pgoff,
11360 - const unsigned long flags)
11361 + const unsigned long flags,
11362 + const unsigned long offset)
11363 {
11364 struct mm_struct *mm = current->mm;
11365 unsigned long addr = addr0;
11366 @@ -71,6 +80,7 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11367 info.high_limit = mm->mmap_base;
11368 info.align_mask = PAGE_MASK & ~HPAGE_MASK;
11369 info.align_offset = 0;
11370 + info.threadstack_offset = offset;
11371 addr = vm_unmapped_area(&info);
11372
11373 /*
11374 @@ -83,6 +93,12 @@ hugetlb_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
11375 VM_BUG_ON(addr != -ENOMEM);
11376 info.flags = 0;
11377 info.low_limit = TASK_UNMAPPED_BASE;
11378 +
11379 +#ifdef CONFIG_PAX_RANDMMAP
11380 + if (mm->pax_flags & MF_PAX_RANDMMAP)
11381 + info.low_limit += mm->delta_mmap;
11382 +#endif
11383 +
11384 info.high_limit = STACK_TOP32;
11385 addr = vm_unmapped_area(&info);
11386 }
11387 @@ -97,6 +113,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11388 struct mm_struct *mm = current->mm;
11389 struct vm_area_struct *vma;
11390 unsigned long task_size = TASK_SIZE;
11391 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
11392
11393 if (test_thread_flag(TIF_32BIT))
11394 task_size = STACK_TOP32;
11395 @@ -112,19 +129,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
11396 return addr;
11397 }
11398
11399 +#ifdef CONFIG_PAX_RANDMMAP
11400 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
11401 +#endif
11402 +
11403 if (addr) {
11404 addr = ALIGN(addr, HPAGE_SIZE);
11405 vma = find_vma(mm, addr);
11406 - if (task_size - len >= addr &&
11407 - (!vma || addr + len <= vma->vm_start))
11408 + if (task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
11409 return addr;
11410 }
11411 if (mm->get_unmapped_area == arch_get_unmapped_area)
11412 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
11413 - pgoff, flags);
11414 + pgoff, flags, offset);
11415 else
11416 return hugetlb_get_unmapped_area_topdown(file, addr, len,
11417 - pgoff, flags);
11418 + pgoff, flags, offset);
11419 }
11420
11421 pte_t *huge_pte_alloc(struct mm_struct *mm,
11422 diff --git a/arch/sparc/mm/init_64.c b/arch/sparc/mm/init_64.c
11423 index 5322e53..f820c5e 100644
11424 --- a/arch/sparc/mm/init_64.c
11425 +++ b/arch/sparc/mm/init_64.c
11426 @@ -188,9 +188,9 @@ unsigned long sparc64_kern_sec_context __read_mostly;
11427 int num_kernel_image_mappings;
11428
11429 #ifdef CONFIG_DEBUG_DCFLUSH
11430 -atomic_t dcpage_flushes = ATOMIC_INIT(0);
11431 +atomic_unchecked_t dcpage_flushes = ATOMIC_INIT(0);
11432 #ifdef CONFIG_SMP
11433 -atomic_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11434 +atomic_unchecked_t dcpage_flushes_xcall = ATOMIC_INIT(0);
11435 #endif
11436 #endif
11437
11438 @@ -198,7 +198,7 @@ inline void flush_dcache_page_impl(struct page *page)
11439 {
11440 BUG_ON(tlb_type == hypervisor);
11441 #ifdef CONFIG_DEBUG_DCFLUSH
11442 - atomic_inc(&dcpage_flushes);
11443 + atomic_inc_unchecked(&dcpage_flushes);
11444 #endif
11445
11446 #ifdef DCACHE_ALIASING_POSSIBLE
11447 @@ -466,10 +466,10 @@ void mmu_info(struct seq_file *m)
11448
11449 #ifdef CONFIG_DEBUG_DCFLUSH
11450 seq_printf(m, "DCPageFlushes\t: %d\n",
11451 - atomic_read(&dcpage_flushes));
11452 + atomic_read_unchecked(&dcpage_flushes));
11453 #ifdef CONFIG_SMP
11454 seq_printf(m, "DCPageFlushesXC\t: %d\n",
11455 - atomic_read(&dcpage_flushes_xcall));
11456 + atomic_read_unchecked(&dcpage_flushes_xcall));
11457 #endif /* CONFIG_SMP */
11458 #endif /* CONFIG_DEBUG_DCFLUSH */
11459 }
11460 diff --git a/arch/tile/Kconfig b/arch/tile/Kconfig
11461 index b3692ce..e4517c9 100644
11462 --- a/arch/tile/Kconfig
11463 +++ b/arch/tile/Kconfig
11464 @@ -184,6 +184,7 @@ source "kernel/Kconfig.hz"
11465
11466 config KEXEC
11467 bool "kexec system call"
11468 + depends on !GRKERNSEC_KMEM
11469 ---help---
11470 kexec is a system call that implements the ability to shutdown your
11471 current kernel, and to start another kernel. It is like a reboot
11472 diff --git a/arch/tile/include/asm/atomic_64.h b/arch/tile/include/asm/atomic_64.h
11473 index ad220ee..2f537b3 100644
11474 --- a/arch/tile/include/asm/atomic_64.h
11475 +++ b/arch/tile/include/asm/atomic_64.h
11476 @@ -105,6 +105,16 @@ static inline long atomic64_add_unless(atomic64_t *v, long a, long u)
11477
11478 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
11479
11480 +#define atomic64_read_unchecked(v) atomic64_read(v)
11481 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
11482 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
11483 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
11484 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
11485 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
11486 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
11487 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
11488 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
11489 +
11490 /* Atomic dec and inc don't implement barrier, so provide them if needed. */
11491 #define smp_mb__before_atomic_dec() smp_mb()
11492 #define smp_mb__after_atomic_dec() smp_mb()
11493 diff --git a/arch/tile/include/asm/cache.h b/arch/tile/include/asm/cache.h
11494 index 6160761..00cac88 100644
11495 --- a/arch/tile/include/asm/cache.h
11496 +++ b/arch/tile/include/asm/cache.h
11497 @@ -15,11 +15,12 @@
11498 #ifndef _ASM_TILE_CACHE_H
11499 #define _ASM_TILE_CACHE_H
11500
11501 +#include <linux/const.h>
11502 #include <arch/chip.h>
11503
11504 /* bytes per L1 data cache line */
11505 #define L1_CACHE_SHIFT CHIP_L1D_LOG_LINE_SIZE()
11506 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11507 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11508
11509 /* bytes per L2 cache line */
11510 #define L2_CACHE_SHIFT CHIP_L2_LOG_LINE_SIZE()
11511 diff --git a/arch/tile/include/asm/uaccess.h b/arch/tile/include/asm/uaccess.h
11512 index b6cde32..c0cb736 100644
11513 --- a/arch/tile/include/asm/uaccess.h
11514 +++ b/arch/tile/include/asm/uaccess.h
11515 @@ -414,9 +414,9 @@ static inline unsigned long __must_check copy_from_user(void *to,
11516 const void __user *from,
11517 unsigned long n)
11518 {
11519 - int sz = __compiletime_object_size(to);
11520 + size_t sz = __compiletime_object_size(to);
11521
11522 - if (likely(sz == -1 || sz >= n))
11523 + if (likely(sz == (size_t)-1 || sz >= n))
11524 n = _copy_from_user(to, from, n);
11525 else
11526 copy_from_user_overflow();
11527 diff --git a/arch/tile/mm/hugetlbpage.c b/arch/tile/mm/hugetlbpage.c
11528 index 0cb3bba..7338b2d 100644
11529 --- a/arch/tile/mm/hugetlbpage.c
11530 +++ b/arch/tile/mm/hugetlbpage.c
11531 @@ -212,6 +212,7 @@ static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
11532 info.high_limit = TASK_SIZE;
11533 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11534 info.align_offset = 0;
11535 + info.threadstack_offset = 0;
11536 return vm_unmapped_area(&info);
11537 }
11538
11539 @@ -229,6 +230,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
11540 info.high_limit = current->mm->mmap_base;
11541 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
11542 info.align_offset = 0;
11543 + info.threadstack_offset = 0;
11544 addr = vm_unmapped_area(&info);
11545
11546 /*
11547 diff --git a/arch/um/Makefile b/arch/um/Makefile
11548 index 36e658a..71a5c5a 100644
11549 --- a/arch/um/Makefile
11550 +++ b/arch/um/Makefile
11551 @@ -72,6 +72,10 @@ USER_CFLAGS = $(patsubst $(KERNEL_DEFINES),,$(patsubst -D__KERNEL__,,\
11552 $(patsubst -I%,,$(KBUILD_CFLAGS)))) $(ARCH_INCLUDE) $(MODE_INCLUDE) \
11553 $(filter -I%,$(CFLAGS)) -D_FILE_OFFSET_BITS=64 -idirafter include
11554
11555 +ifdef CONSTIFY_PLUGIN
11556 +USER_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11557 +endif
11558 +
11559 #This will adjust *FLAGS accordingly to the platform.
11560 include $(srctree)/$(ARCH_DIR)/Makefile-os-$(OS)
11561
11562 diff --git a/arch/um/include/asm/cache.h b/arch/um/include/asm/cache.h
11563 index 19e1bdd..3665b77 100644
11564 --- a/arch/um/include/asm/cache.h
11565 +++ b/arch/um/include/asm/cache.h
11566 @@ -1,6 +1,7 @@
11567 #ifndef __UM_CACHE_H
11568 #define __UM_CACHE_H
11569
11570 +#include <linux/const.h>
11571
11572 #if defined(CONFIG_UML_X86) && !defined(CONFIG_64BIT)
11573 # define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
11574 @@ -12,6 +13,6 @@
11575 # define L1_CACHE_SHIFT 5
11576 #endif
11577
11578 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11579 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11580
11581 #endif
11582 diff --git a/arch/um/include/asm/kmap_types.h b/arch/um/include/asm/kmap_types.h
11583 index 2e0a6b1..a64d0f5 100644
11584 --- a/arch/um/include/asm/kmap_types.h
11585 +++ b/arch/um/include/asm/kmap_types.h
11586 @@ -8,6 +8,6 @@
11587
11588 /* No more #include "asm/arch/kmap_types.h" ! */
11589
11590 -#define KM_TYPE_NR 14
11591 +#define KM_TYPE_NR 15
11592
11593 #endif
11594 diff --git a/arch/um/include/asm/page.h b/arch/um/include/asm/page.h
11595 index 5ff53d9..5850cdf 100644
11596 --- a/arch/um/include/asm/page.h
11597 +++ b/arch/um/include/asm/page.h
11598 @@ -14,6 +14,9 @@
11599 #define PAGE_SIZE (_AC(1, UL) << PAGE_SHIFT)
11600 #define PAGE_MASK (~(PAGE_SIZE-1))
11601
11602 +#define ktla_ktva(addr) (addr)
11603 +#define ktva_ktla(addr) (addr)
11604 +
11605 #ifndef __ASSEMBLY__
11606
11607 struct page;
11608 diff --git a/arch/um/include/asm/pgtable-3level.h b/arch/um/include/asm/pgtable-3level.h
11609 index 0032f92..cd151e0 100644
11610 --- a/arch/um/include/asm/pgtable-3level.h
11611 +++ b/arch/um/include/asm/pgtable-3level.h
11612 @@ -58,6 +58,7 @@
11613 #define pud_present(x) (pud_val(x) & _PAGE_PRESENT)
11614 #define pud_populate(mm, pud, pmd) \
11615 set_pud(pud, __pud(_PAGE_TABLE + __pa(pmd)))
11616 +#define pud_populate_kernel(mm, pud, pmd) pud_populate((mm), (pud), (pmd))
11617
11618 #ifdef CONFIG_64BIT
11619 #define set_pud(pudptr, pudval) set_64bit((u64 *) (pudptr), pud_val(pudval))
11620 diff --git a/arch/um/kernel/process.c b/arch/um/kernel/process.c
11621 index eecc414..48adb87 100644
11622 --- a/arch/um/kernel/process.c
11623 +++ b/arch/um/kernel/process.c
11624 @@ -356,22 +356,6 @@ int singlestepping(void * t)
11625 return 2;
11626 }
11627
11628 -/*
11629 - * Only x86 and x86_64 have an arch_align_stack().
11630 - * All other arches have "#define arch_align_stack(x) (x)"
11631 - * in their asm/system.h
11632 - * As this is included in UML from asm-um/system-generic.h,
11633 - * we can use it to behave as the subarch does.
11634 - */
11635 -#ifndef arch_align_stack
11636 -unsigned long arch_align_stack(unsigned long sp)
11637 -{
11638 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
11639 - sp -= get_random_int() % 8192;
11640 - return sp & ~0xf;
11641 -}
11642 -#endif
11643 -
11644 unsigned long get_wchan(struct task_struct *p)
11645 {
11646 unsigned long stack_page, sp, ip;
11647 diff --git a/arch/unicore32/include/asm/cache.h b/arch/unicore32/include/asm/cache.h
11648 index ad8f795..2c7eec6 100644
11649 --- a/arch/unicore32/include/asm/cache.h
11650 +++ b/arch/unicore32/include/asm/cache.h
11651 @@ -12,8 +12,10 @@
11652 #ifndef __UNICORE_CACHE_H__
11653 #define __UNICORE_CACHE_H__
11654
11655 -#define L1_CACHE_SHIFT (5)
11656 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
11657 +#include <linux/const.h>
11658 +
11659 +#define L1_CACHE_SHIFT 5
11660 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
11661
11662 /*
11663 * Memory returned by kmalloc() may be used for DMA, so we must make
11664 diff --git a/arch/x86/Kconfig b/arch/x86/Kconfig
11665 index 0952ecd..725c779 100644
11666 --- a/arch/x86/Kconfig
11667 +++ b/arch/x86/Kconfig
11668 @@ -249,7 +249,7 @@ config X86_HT
11669
11670 config X86_32_LAZY_GS
11671 def_bool y
11672 - depends on X86_32 && !CC_STACKPROTECTOR
11673 + depends on X86_32 && !CC_STACKPROTECTOR && !PAX_MEMORY_UDEREF
11674
11675 config ARCH_HWEIGHT_CFLAGS
11676 string
11677 @@ -602,6 +602,7 @@ config SCHED_OMIT_FRAME_POINTER
11678
11679 menuconfig HYPERVISOR_GUEST
11680 bool "Linux guest support"
11681 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_GUEST
11682 ---help---
11683 Say Y here to enable options for running Linux under various hyper-
11684 visors. This option enables basic hypervisor detection and platform
11685 @@ -1127,7 +1128,7 @@ choice
11686
11687 config NOHIGHMEM
11688 bool "off"
11689 - depends on !X86_NUMAQ
11690 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11691 ---help---
11692 Linux can use up to 64 Gigabytes of physical memory on x86 systems.
11693 However, the address space of 32-bit x86 processors is only 4
11694 @@ -1164,7 +1165,7 @@ config NOHIGHMEM
11695
11696 config HIGHMEM4G
11697 bool "4GB"
11698 - depends on !X86_NUMAQ
11699 + depends on !X86_NUMAQ && !(PAX_PAGEEXEC && PAX_ENABLE_PAE)
11700 ---help---
11701 Select this if you have a 32-bit processor and between 1 and 4
11702 gigabytes of physical RAM.
11703 @@ -1217,7 +1218,7 @@ config PAGE_OFFSET
11704 hex
11705 default 0xB0000000 if VMSPLIT_3G_OPT
11706 default 0x80000000 if VMSPLIT_2G
11707 - default 0x78000000 if VMSPLIT_2G_OPT
11708 + default 0x70000000 if VMSPLIT_2G_OPT
11709 default 0x40000000 if VMSPLIT_1G
11710 default 0xC0000000
11711 depends on X86_32
11712 @@ -1619,6 +1620,7 @@ config SECCOMP
11713
11714 config CC_STACKPROTECTOR
11715 bool "Enable -fstack-protector buffer overflow detection"
11716 + depends on X86_64 || !PAX_MEMORY_UDEREF
11717 ---help---
11718 This option turns on the -fstack-protector GCC feature. This
11719 feature puts, at the beginning of functions, a canary value on
11720 @@ -1637,6 +1639,7 @@ source kernel/Kconfig.hz
11721
11722 config KEXEC
11723 bool "kexec system call"
11724 + depends on !GRKERNSEC_KMEM
11725 ---help---
11726 kexec is a system call that implements the ability to shutdown your
11727 current kernel, and to start another kernel. It is like a reboot
11728 @@ -1738,6 +1741,8 @@ config X86_NEED_RELOCS
11729 config PHYSICAL_ALIGN
11730 hex "Alignment value to which kernel should be aligned"
11731 default "0x1000000"
11732 + range 0x200000 0x1000000 if PAX_KERNEXEC && X86_PAE
11733 + range 0x400000 0x1000000 if PAX_KERNEXEC && !X86_PAE
11734 range 0x2000 0x1000000 if X86_32
11735 range 0x200000 0x1000000 if X86_64
11736 ---help---
11737 @@ -1817,9 +1822,10 @@ config DEBUG_HOTPLUG_CPU0
11738 If unsure, say N.
11739
11740 config COMPAT_VDSO
11741 - def_bool y
11742 + def_bool n
11743 prompt "Compat VDSO support"
11744 depends on X86_32 || IA32_EMULATION
11745 + depends on !PAX_PAGEEXEC && !PAX_SEGMEXEC && !PAX_KERNEXEC && !PAX_MEMORY_UDEREF
11746 ---help---
11747 Map the 32-bit VDSO to the predictable old-style address too.
11748
11749 diff --git a/arch/x86/Kconfig.cpu b/arch/x86/Kconfig.cpu
11750 index c026cca..14657ae 100644
11751 --- a/arch/x86/Kconfig.cpu
11752 +++ b/arch/x86/Kconfig.cpu
11753 @@ -319,7 +319,7 @@ config X86_PPRO_FENCE
11754
11755 config X86_F00F_BUG
11756 def_bool y
11757 - depends on M586MMX || M586TSC || M586 || M486
11758 + depends on (M586MMX || M586TSC || M586 || M486) && !PAX_KERNEXEC
11759
11760 config X86_INVD_BUG
11761 def_bool y
11762 @@ -327,7 +327,7 @@ config X86_INVD_BUG
11763
11764 config X86_ALIGNMENT_16
11765 def_bool y
11766 - depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || MELAN || MK6 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11767 + depends on MWINCHIP3D || MWINCHIPC6 || MCYRIXIII || X86_ELAN || MK8 || MK7 || MK6 || MCORE2 || MPENTIUM4 || MPENTIUMIII || MPENTIUMII || M686 || M586MMX || M586TSC || M586 || M486 || MVIAC3_2 || MGEODEGX1
11768
11769 config X86_INTEL_USERCOPY
11770 def_bool y
11771 @@ -373,7 +373,7 @@ config X86_CMPXCHG64
11772 # generates cmov.
11773 config X86_CMOV
11774 def_bool y
11775 - depends on (MK8 || MK7 || MCORE2 || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11776 + depends on (MK8 || MK7 || MCORE2 || MPSC || MPENTIUM4 || MPENTIUMM || MPENTIUMIII || MPENTIUMII || M686 || MVIAC3_2 || MVIAC7 || MCRUSOE || MEFFICEON || X86_64 || MATOM || MGEODE_LX)
11777
11778 config X86_MINIMUM_CPU_FAMILY
11779 int
11780 diff --git a/arch/x86/Kconfig.debug b/arch/x86/Kconfig.debug
11781 index 0f3621e..282f24b 100644
11782 --- a/arch/x86/Kconfig.debug
11783 +++ b/arch/x86/Kconfig.debug
11784 @@ -84,7 +84,7 @@ config X86_PTDUMP
11785 config DEBUG_RODATA
11786 bool "Write protect kernel read-only data structures"
11787 default y
11788 - depends on DEBUG_KERNEL
11789 + depends on DEBUG_KERNEL && BROKEN
11790 ---help---
11791 Mark the kernel read-only data as write-protected in the pagetables,
11792 in order to catch accidental (and incorrect) writes to such const
11793 @@ -102,7 +102,7 @@ config DEBUG_RODATA_TEST
11794
11795 config DEBUG_SET_MODULE_RONX
11796 bool "Set loadable kernel module data as NX and text as RO"
11797 - depends on MODULES
11798 + depends on MODULES && BROKEN
11799 ---help---
11800 This option helps catch unintended modifications to loadable
11801 kernel module's text and read-only data. It also prevents execution
11802 diff --git a/arch/x86/Makefile b/arch/x86/Makefile
11803 index 57d0215..b4373fb 100644
11804 --- a/arch/x86/Makefile
11805 +++ b/arch/x86/Makefile
11806 @@ -49,14 +49,12 @@ ifeq ($(CONFIG_X86_32),y)
11807 # CPU-specific tuning. Anything which can be shared with UML should go here.
11808 include $(srctree)/arch/x86/Makefile_32.cpu
11809 KBUILD_CFLAGS += $(cflags-y)
11810 -
11811 - # temporary until string.h is fixed
11812 - KBUILD_CFLAGS += -ffreestanding
11813 else
11814 BITS := 64
11815 UTS_MACHINE := x86_64
11816 CHECKFLAGS += -D__x86_64__ -m64
11817
11818 + biarch := $(call cc-option,-m64)
11819 KBUILD_AFLAGS += -m64
11820 KBUILD_CFLAGS += -m64
11821
11822 @@ -89,6 +87,9 @@ else
11823 KBUILD_CFLAGS += -maccumulate-outgoing-args
11824 endif
11825
11826 +# temporary until string.h is fixed
11827 +KBUILD_CFLAGS += -ffreestanding
11828 +
11829 ifdef CONFIG_CC_STACKPROTECTOR
11830 cc_has_sp := $(srctree)/scripts/gcc-x86_$(BITS)-has-stack-protector.sh
11831 ifeq ($(shell $(CONFIG_SHELL) $(cc_has_sp) $(CC) $(KBUILD_CPPFLAGS) $(biarch)),y)
11832 @@ -247,3 +248,12 @@ define archhelp
11833 echo ' FDINITRD=file initrd for the booted kernel'
11834 echo ' kvmconfig - Enable additional options for guest kernel support'
11835 endef
11836 +
11837 +define OLD_LD
11838 +
11839 +*** ${VERSION}.${PATCHLEVEL} PaX kernels no longer build correctly with old versions of binutils.
11840 +*** Please upgrade your binutils to 2.18 or newer
11841 +endef
11842 +
11843 +archprepare:
11844 + $(if $(LDFLAGS_BUILD_ID),,$(error $(OLD_LD)))
11845 diff --git a/arch/x86/boot/Makefile b/arch/x86/boot/Makefile
11846 index d9c1195..a26ca0d 100644
11847 --- a/arch/x86/boot/Makefile
11848 +++ b/arch/x86/boot/Makefile
11849 @@ -65,6 +65,9 @@ KBUILD_CFLAGS := $(USERINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ \
11850 $(call cc-option, -fno-unit-at-a-time)) \
11851 $(call cc-option, -fno-stack-protector) \
11852 $(call cc-option, -mpreferred-stack-boundary=2)
11853 +ifdef CONSTIFY_PLUGIN
11854 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11855 +endif
11856 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11857 GCOV_PROFILE := n
11858
11859 diff --git a/arch/x86/boot/bitops.h b/arch/x86/boot/bitops.h
11860 index 878e4b9..20537ab 100644
11861 --- a/arch/x86/boot/bitops.h
11862 +++ b/arch/x86/boot/bitops.h
11863 @@ -26,7 +26,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11864 u8 v;
11865 const u32 *p = (const u32 *)addr;
11866
11867 - asm("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11868 + asm volatile("btl %2,%1; setc %0" : "=qm" (v) : "m" (*p), "Ir" (nr));
11869 return v;
11870 }
11871
11872 @@ -37,7 +37,7 @@ static inline int variable_test_bit(int nr, const void *addr)
11873
11874 static inline void set_bit(int nr, void *addr)
11875 {
11876 - asm("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11877 + asm volatile("btsl %1,%0" : "+m" (*(u32 *)addr) : "Ir" (nr));
11878 }
11879
11880 #endif /* BOOT_BITOPS_H */
11881 diff --git a/arch/x86/boot/boot.h b/arch/x86/boot/boot.h
11882 index ef72bae..353a184 100644
11883 --- a/arch/x86/boot/boot.h
11884 +++ b/arch/x86/boot/boot.h
11885 @@ -85,7 +85,7 @@ static inline void io_delay(void)
11886 static inline u16 ds(void)
11887 {
11888 u16 seg;
11889 - asm("movw %%ds,%0" : "=rm" (seg));
11890 + asm volatile("movw %%ds,%0" : "=rm" (seg));
11891 return seg;
11892 }
11893
11894 @@ -181,7 +181,7 @@ static inline void wrgs32(u32 v, addr_t addr)
11895 static inline int memcmp(const void *s1, const void *s2, size_t len)
11896 {
11897 u8 diff;
11898 - asm("repe; cmpsb; setnz %0"
11899 + asm volatile("repe; cmpsb; setnz %0"
11900 : "=qm" (diff), "+D" (s1), "+S" (s2), "+c" (len));
11901 return diff;
11902 }
11903 diff --git a/arch/x86/boot/compressed/Makefile b/arch/x86/boot/compressed/Makefile
11904 index c8a6792..2402765 100644
11905 --- a/arch/x86/boot/compressed/Makefile
11906 +++ b/arch/x86/boot/compressed/Makefile
11907 @@ -16,6 +16,9 @@ KBUILD_CFLAGS += $(cflags-y)
11908 KBUILD_CFLAGS += -mno-mmx -mno-sse
11909 KBUILD_CFLAGS += $(call cc-option,-ffreestanding)
11910 KBUILD_CFLAGS += $(call cc-option,-fno-stack-protector)
11911 +ifdef CONSTIFY_PLUGIN
11912 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
11913 +endif
11914
11915 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
11916 GCOV_PROFILE := n
11917 diff --git a/arch/x86/boot/compressed/efi_stub_32.S b/arch/x86/boot/compressed/efi_stub_32.S
11918 index a53440e..c3dbf1e 100644
11919 --- a/arch/x86/boot/compressed/efi_stub_32.S
11920 +++ b/arch/x86/boot/compressed/efi_stub_32.S
11921 @@ -46,16 +46,13 @@ ENTRY(efi_call_phys)
11922 * parameter 2, ..., param n. To make things easy, we save the return
11923 * address of efi_call_phys in a global variable.
11924 */
11925 - popl %ecx
11926 - movl %ecx, saved_return_addr(%edx)
11927 - /* get the function pointer into ECX*/
11928 - popl %ecx
11929 - movl %ecx, efi_rt_function_ptr(%edx)
11930 + popl saved_return_addr(%edx)
11931 + popl efi_rt_function_ptr(%edx)
11932
11933 /*
11934 * 3. Call the physical function.
11935 */
11936 - call *%ecx
11937 + call *efi_rt_function_ptr(%edx)
11938
11939 /*
11940 * 4. Balance the stack. And because EAX contain the return value,
11941 @@ -67,15 +64,12 @@ ENTRY(efi_call_phys)
11942 1: popl %edx
11943 subl $1b, %edx
11944
11945 - movl efi_rt_function_ptr(%edx), %ecx
11946 - pushl %ecx
11947 + pushl efi_rt_function_ptr(%edx)
11948
11949 /*
11950 * 10. Push the saved return address onto the stack and return.
11951 */
11952 - movl saved_return_addr(%edx), %ecx
11953 - pushl %ecx
11954 - ret
11955 + jmpl *saved_return_addr(%edx)
11956 ENDPROC(efi_call_phys)
11957 .previous
11958
11959 diff --git a/arch/x86/boot/compressed/head_32.S b/arch/x86/boot/compressed/head_32.S
11960 index 5d6f689..9d06730 100644
11961 --- a/arch/x86/boot/compressed/head_32.S
11962 +++ b/arch/x86/boot/compressed/head_32.S
11963 @@ -118,7 +118,7 @@ preferred_addr:
11964 notl %eax
11965 andl %eax, %ebx
11966 #else
11967 - movl $LOAD_PHYSICAL_ADDR, %ebx
11968 + movl $____LOAD_PHYSICAL_ADDR, %ebx
11969 #endif
11970
11971 /* Target address to relocate to for decompression */
11972 diff --git a/arch/x86/boot/compressed/head_64.S b/arch/x86/boot/compressed/head_64.S
11973 index c337422..2c5be72 100644
11974 --- a/arch/x86/boot/compressed/head_64.S
11975 +++ b/arch/x86/boot/compressed/head_64.S
11976 @@ -95,7 +95,7 @@ ENTRY(startup_32)
11977 notl %eax
11978 andl %eax, %ebx
11979 #else
11980 - movl $LOAD_PHYSICAL_ADDR, %ebx
11981 + movl $____LOAD_PHYSICAL_ADDR, %ebx
11982 #endif
11983
11984 /* Target address to relocate to for decompression */
11985 @@ -270,7 +270,7 @@ preferred_addr:
11986 notq %rax
11987 andq %rax, %rbp
11988 #else
11989 - movq $LOAD_PHYSICAL_ADDR, %rbp
11990 + movq $____LOAD_PHYSICAL_ADDR, %rbp
11991 #endif
11992
11993 /* Target address to relocate to for decompression */
11994 @@ -362,8 +362,8 @@ gdt:
11995 .long gdt
11996 .word 0
11997 .quad 0x0000000000000000 /* NULL descriptor */
11998 - .quad 0x00af9a000000ffff /* __KERNEL_CS */
11999 - .quad 0x00cf92000000ffff /* __KERNEL_DS */
12000 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
12001 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
12002 .quad 0x0080890000000000 /* TS descriptor */
12003 .quad 0x0000000000000000 /* TS continued */
12004 gdt_end:
12005 diff --git a/arch/x86/boot/compressed/misc.c b/arch/x86/boot/compressed/misc.c
12006 index 434f077..b6b4b38 100644
12007 --- a/arch/x86/boot/compressed/misc.c
12008 +++ b/arch/x86/boot/compressed/misc.c
12009 @@ -283,7 +283,7 @@ static void handle_relocations(void *output, unsigned long output_len)
12010 * Calculate the delta between where vmlinux was linked to load
12011 * and where it was actually loaded.
12012 */
12013 - delta = min_addr - LOAD_PHYSICAL_ADDR;
12014 + delta = min_addr - ____LOAD_PHYSICAL_ADDR;
12015 if (!delta) {
12016 debug_putstr("No relocation needed... ");
12017 return;
12018 @@ -380,7 +380,7 @@ static void parse_elf(void *output)
12019 case PT_LOAD:
12020 #ifdef CONFIG_RELOCATABLE
12021 dest = output;
12022 - dest += (phdr->p_paddr - LOAD_PHYSICAL_ADDR);
12023 + dest += (phdr->p_paddr - ____LOAD_PHYSICAL_ADDR);
12024 #else
12025 dest = (void *)(phdr->p_paddr);
12026 #endif
12027 @@ -432,7 +432,7 @@ asmlinkage void decompress_kernel(void *rmode, memptr heap,
12028 error("Destination address too large");
12029 #endif
12030 #ifndef CONFIG_RELOCATABLE
12031 - if ((unsigned long)output != LOAD_PHYSICAL_ADDR)
12032 + if ((unsigned long)output != ____LOAD_PHYSICAL_ADDR)
12033 error("Wrong destination address");
12034 #endif
12035
12036 diff --git a/arch/x86/boot/cpucheck.c b/arch/x86/boot/cpucheck.c
12037 index 4d3ff03..e4972ff 100644
12038 --- a/arch/x86/boot/cpucheck.c
12039 +++ b/arch/x86/boot/cpucheck.c
12040 @@ -74,7 +74,7 @@ static int has_fpu(void)
12041 u16 fcw = -1, fsw = -1;
12042 u32 cr0;
12043
12044 - asm("movl %%cr0,%0" : "=r" (cr0));
12045 + asm volatile("movl %%cr0,%0" : "=r" (cr0));
12046 if (cr0 & (X86_CR0_EM|X86_CR0_TS)) {
12047 cr0 &= ~(X86_CR0_EM|X86_CR0_TS);
12048 asm volatile("movl %0,%%cr0" : : "r" (cr0));
12049 @@ -90,7 +90,7 @@ static int has_eflag(u32 mask)
12050 {
12051 u32 f0, f1;
12052
12053 - asm("pushfl ; "
12054 + asm volatile("pushfl ; "
12055 "pushfl ; "
12056 "popl %0 ; "
12057 "movl %0,%1 ; "
12058 @@ -115,7 +115,7 @@ static void get_flags(void)
12059 set_bit(X86_FEATURE_FPU, cpu.flags);
12060
12061 if (has_eflag(X86_EFLAGS_ID)) {
12062 - asm("cpuid"
12063 + asm volatile("cpuid"
12064 : "=a" (max_intel_level),
12065 "=b" (cpu_vendor[0]),
12066 "=d" (cpu_vendor[1]),
12067 @@ -124,7 +124,7 @@ static void get_flags(void)
12068
12069 if (max_intel_level >= 0x00000001 &&
12070 max_intel_level <= 0x0000ffff) {
12071 - asm("cpuid"
12072 + asm volatile("cpuid"
12073 : "=a" (tfms),
12074 "=c" (cpu.flags[4]),
12075 "=d" (cpu.flags[0])
12076 @@ -136,7 +136,7 @@ static void get_flags(void)
12077 cpu.model += ((tfms >> 16) & 0xf) << 4;
12078 }
12079
12080 - asm("cpuid"
12081 + asm volatile("cpuid"
12082 : "=a" (max_amd_level)
12083 : "a" (0x80000000)
12084 : "ebx", "ecx", "edx");
12085 @@ -144,7 +144,7 @@ static void get_flags(void)
12086 if (max_amd_level >= 0x80000001 &&
12087 max_amd_level <= 0x8000ffff) {
12088 u32 eax = 0x80000001;
12089 - asm("cpuid"
12090 + asm volatile("cpuid"
12091 : "+a" (eax),
12092 "=c" (cpu.flags[6]),
12093 "=d" (cpu.flags[1])
12094 @@ -203,9 +203,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12095 u32 ecx = MSR_K7_HWCR;
12096 u32 eax, edx;
12097
12098 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12099 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12100 eax &= ~(1 << 15);
12101 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12102 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12103
12104 get_flags(); /* Make sure it really did something */
12105 err = check_flags();
12106 @@ -218,9 +218,9 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12107 u32 ecx = MSR_VIA_FCR;
12108 u32 eax, edx;
12109
12110 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12111 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12112 eax |= (1<<1)|(1<<7);
12113 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12114 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12115
12116 set_bit(X86_FEATURE_CX8, cpu.flags);
12117 err = check_flags();
12118 @@ -231,12 +231,12 @@ int check_cpu(int *cpu_level_ptr, int *req_level_ptr, u32 **err_flags_ptr)
12119 u32 eax, edx;
12120 u32 level = 1;
12121
12122 - asm("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12123 - asm("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12124 - asm("cpuid"
12125 + asm volatile("rdmsr" : "=a" (eax), "=d" (edx) : "c" (ecx));
12126 + asm volatile("wrmsr" : : "a" (~0), "d" (edx), "c" (ecx));
12127 + asm volatile("cpuid"
12128 : "+a" (level), "=d" (cpu.flags[0])
12129 : : "ecx", "ebx");
12130 - asm("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12131 + asm volatile("wrmsr" : : "a" (eax), "d" (edx), "c" (ecx));
12132
12133 err = check_flags();
12134 }
12135 diff --git a/arch/x86/boot/header.S b/arch/x86/boot/header.S
12136 index 9ec06a1..2c25e79 100644
12137 --- a/arch/x86/boot/header.S
12138 +++ b/arch/x86/boot/header.S
12139 @@ -409,10 +409,14 @@ setup_data: .quad 0 # 64-bit physical pointer to
12140 # single linked list of
12141 # struct setup_data
12142
12143 -pref_address: .quad LOAD_PHYSICAL_ADDR # preferred load addr
12144 +pref_address: .quad ____LOAD_PHYSICAL_ADDR # preferred load addr
12145
12146 #define ZO_INIT_SIZE (ZO__end - ZO_startup_32 + ZO_z_extract_offset)
12147 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
12148 +#define VO_INIT_SIZE (VO__end - VO__text - __PAGE_OFFSET - ____LOAD_PHYSICAL_ADDR)
12149 +#else
12150 #define VO_INIT_SIZE (VO__end - VO__text)
12151 +#endif
12152 #if ZO_INIT_SIZE > VO_INIT_SIZE
12153 #define INIT_SIZE ZO_INIT_SIZE
12154 #else
12155 diff --git a/arch/x86/boot/memory.c b/arch/x86/boot/memory.c
12156 index db75d07..8e6d0af 100644
12157 --- a/arch/x86/boot/memory.c
12158 +++ b/arch/x86/boot/memory.c
12159 @@ -19,7 +19,7 @@
12160
12161 static int detect_memory_e820(void)
12162 {
12163 - int count = 0;
12164 + unsigned int count = 0;
12165 struct biosregs ireg, oreg;
12166 struct e820entry *desc = boot_params.e820_map;
12167 static struct e820entry buf; /* static so it is zeroed */
12168 diff --git a/arch/x86/boot/video-vesa.c b/arch/x86/boot/video-vesa.c
12169 index 11e8c6e..fdbb1ed 100644
12170 --- a/arch/x86/boot/video-vesa.c
12171 +++ b/arch/x86/boot/video-vesa.c
12172 @@ -200,6 +200,7 @@ static void vesa_store_pm_info(void)
12173
12174 boot_params.screen_info.vesapm_seg = oreg.es;
12175 boot_params.screen_info.vesapm_off = oreg.di;
12176 + boot_params.screen_info.vesapm_size = oreg.cx;
12177 }
12178
12179 /*
12180 diff --git a/arch/x86/boot/video.c b/arch/x86/boot/video.c
12181 index 43eda28..5ab5fdb 100644
12182 --- a/arch/x86/boot/video.c
12183 +++ b/arch/x86/boot/video.c
12184 @@ -96,7 +96,7 @@ static void store_mode_params(void)
12185 static unsigned int get_entry(void)
12186 {
12187 char entry_buf[4];
12188 - int i, len = 0;
12189 + unsigned int i, len = 0;
12190 int key;
12191 unsigned int v;
12192
12193 diff --git a/arch/x86/crypto/aes-x86_64-asm_64.S b/arch/x86/crypto/aes-x86_64-asm_64.S
12194 index 9105655..41779c1 100644
12195 --- a/arch/x86/crypto/aes-x86_64-asm_64.S
12196 +++ b/arch/x86/crypto/aes-x86_64-asm_64.S
12197 @@ -8,6 +8,8 @@
12198 * including this sentence is retained in full.
12199 */
12200
12201 +#include <asm/alternative-asm.h>
12202 +
12203 .extern crypto_ft_tab
12204 .extern crypto_it_tab
12205 .extern crypto_fl_tab
12206 @@ -70,6 +72,8 @@
12207 je B192; \
12208 leaq 32(r9),r9;
12209
12210 +#define ret pax_force_retaddr; ret
12211 +
12212 #define epilogue(FUNC,r1,r2,r3,r4,r5,r6,r7,r8,r9) \
12213 movq r1,r2; \
12214 movq r3,r4; \
12215 diff --git a/arch/x86/crypto/aesni-intel_asm.S b/arch/x86/crypto/aesni-intel_asm.S
12216 index 477e9d7..c92c7d8 100644
12217 --- a/arch/x86/crypto/aesni-intel_asm.S
12218 +++ b/arch/x86/crypto/aesni-intel_asm.S
12219 @@ -31,6 +31,7 @@
12220
12221 #include <linux/linkage.h>
12222 #include <asm/inst.h>
12223 +#include <asm/alternative-asm.h>
12224
12225 #ifdef __x86_64__
12226 .data
12227 @@ -205,7 +206,7 @@ enc: .octa 0x2
12228 * num_initial_blocks = b mod 4
12229 * encrypt the initial num_initial_blocks blocks and apply ghash on
12230 * the ciphertext
12231 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12232 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12233 * are clobbered
12234 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12235 */
12236 @@ -214,8 +215,8 @@ enc: .octa 0x2
12237 .macro INITIAL_BLOCKS_DEC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12238 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12239 mov arg7, %r10 # %r10 = AAD
12240 - mov arg8, %r12 # %r12 = aadLen
12241 - mov %r12, %r11
12242 + mov arg8, %r15 # %r15 = aadLen
12243 + mov %r15, %r11
12244 pxor %xmm\i, %xmm\i
12245 _get_AAD_loop\num_initial_blocks\operation:
12246 movd (%r10), \TMP1
12247 @@ -223,15 +224,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12248 psrldq $4, %xmm\i
12249 pxor \TMP1, %xmm\i
12250 add $4, %r10
12251 - sub $4, %r12
12252 + sub $4, %r15
12253 jne _get_AAD_loop\num_initial_blocks\operation
12254 cmp $16, %r11
12255 je _get_AAD_loop2_done\num_initial_blocks\operation
12256 - mov $16, %r12
12257 + mov $16, %r15
12258 _get_AAD_loop2\num_initial_blocks\operation:
12259 psrldq $4, %xmm\i
12260 - sub $4, %r12
12261 - cmp %r11, %r12
12262 + sub $4, %r15
12263 + cmp %r11, %r15
12264 jne _get_AAD_loop2\num_initial_blocks\operation
12265 _get_AAD_loop2_done\num_initial_blocks\operation:
12266 movdqa SHUF_MASK(%rip), %xmm14
12267 @@ -443,7 +444,7 @@ _initial_blocks_done\num_initial_blocks\operation:
12268 * num_initial_blocks = b mod 4
12269 * encrypt the initial num_initial_blocks blocks and apply ghash on
12270 * the ciphertext
12271 -* %r10, %r11, %r12, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12272 +* %r10, %r11, %r15, %rax, %xmm5, %xmm6, %xmm7, %xmm8, %xmm9 registers
12273 * are clobbered
12274 * arg1, %arg2, %arg3, %r14 are used as a pointer only, not modified
12275 */
12276 @@ -452,8 +453,8 @@ _initial_blocks_done\num_initial_blocks\operation:
12277 .macro INITIAL_BLOCKS_ENC num_initial_blocks TMP1 TMP2 TMP3 TMP4 TMP5 XMM0 XMM1 \
12278 XMM2 XMM3 XMM4 XMMDst TMP6 TMP7 i i_seq operation
12279 mov arg7, %r10 # %r10 = AAD
12280 - mov arg8, %r12 # %r12 = aadLen
12281 - mov %r12, %r11
12282 + mov arg8, %r15 # %r15 = aadLen
12283 + mov %r15, %r11
12284 pxor %xmm\i, %xmm\i
12285 _get_AAD_loop\num_initial_blocks\operation:
12286 movd (%r10), \TMP1
12287 @@ -461,15 +462,15 @@ _get_AAD_loop\num_initial_blocks\operation:
12288 psrldq $4, %xmm\i
12289 pxor \TMP1, %xmm\i
12290 add $4, %r10
12291 - sub $4, %r12
12292 + sub $4, %r15
12293 jne _get_AAD_loop\num_initial_blocks\operation
12294 cmp $16, %r11
12295 je _get_AAD_loop2_done\num_initial_blocks\operation
12296 - mov $16, %r12
12297 + mov $16, %r15
12298 _get_AAD_loop2\num_initial_blocks\operation:
12299 psrldq $4, %xmm\i
12300 - sub $4, %r12
12301 - cmp %r11, %r12
12302 + sub $4, %r15
12303 + cmp %r11, %r15
12304 jne _get_AAD_loop2\num_initial_blocks\operation
12305 _get_AAD_loop2_done\num_initial_blocks\operation:
12306 movdqa SHUF_MASK(%rip), %xmm14
12307 @@ -1269,7 +1270,7 @@ TMP7 XMM1 XMM2 XMM3 XMM4 XMMDst
12308 *
12309 *****************************************************************************/
12310 ENTRY(aesni_gcm_dec)
12311 - push %r12
12312 + push %r15
12313 push %r13
12314 push %r14
12315 mov %rsp, %r14
12316 @@ -1279,8 +1280,8 @@ ENTRY(aesni_gcm_dec)
12317 */
12318 sub $VARIABLE_OFFSET, %rsp
12319 and $~63, %rsp # align rsp to 64 bytes
12320 - mov %arg6, %r12
12321 - movdqu (%r12), %xmm13 # %xmm13 = HashKey
12322 + mov %arg6, %r15
12323 + movdqu (%r15), %xmm13 # %xmm13 = HashKey
12324 movdqa SHUF_MASK(%rip), %xmm2
12325 PSHUFB_XMM %xmm2, %xmm13
12326
12327 @@ -1308,10 +1309,10 @@ ENTRY(aesni_gcm_dec)
12328 movdqa %xmm13, HashKey(%rsp) # store HashKey<<1 (mod poly)
12329 mov %arg4, %r13 # save the number of bytes of plaintext/ciphertext
12330 and $-16, %r13 # %r13 = %r13 - (%r13 mod 16)
12331 - mov %r13, %r12
12332 - and $(3<<4), %r12
12333 + mov %r13, %r15
12334 + and $(3<<4), %r15
12335 jz _initial_num_blocks_is_0_decrypt
12336 - cmp $(2<<4), %r12
12337 + cmp $(2<<4), %r15
12338 jb _initial_num_blocks_is_1_decrypt
12339 je _initial_num_blocks_is_2_decrypt
12340 _initial_num_blocks_is_3_decrypt:
12341 @@ -1361,16 +1362,16 @@ _zero_cipher_left_decrypt:
12342 sub $16, %r11
12343 add %r13, %r11
12344 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte block
12345 - lea SHIFT_MASK+16(%rip), %r12
12346 - sub %r13, %r12
12347 + lea SHIFT_MASK+16(%rip), %r15
12348 + sub %r13, %r15
12349 # adjust the shuffle mask pointer to be able to shift 16-%r13 bytes
12350 # (%r13 is the number of bytes in plaintext mod 16)
12351 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12352 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12353 PSHUFB_XMM %xmm2, %xmm1 # right shift 16-%r13 butes
12354
12355 movdqa %xmm1, %xmm2
12356 pxor %xmm1, %xmm0 # Ciphertext XOR E(K, Yn)
12357 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12358 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12359 # get the appropriate mask to mask out top 16-%r13 bytes of %xmm0
12360 pand %xmm1, %xmm0 # mask out top 16-%r13 bytes of %xmm0
12361 pand %xmm1, %xmm2
12362 @@ -1399,9 +1400,9 @@ _less_than_8_bytes_left_decrypt:
12363 sub $1, %r13
12364 jne _less_than_8_bytes_left_decrypt
12365 _multiple_of_16_bytes_decrypt:
12366 - mov arg8, %r12 # %r13 = aadLen (number of bytes)
12367 - shl $3, %r12 # convert into number of bits
12368 - movd %r12d, %xmm15 # len(A) in %xmm15
12369 + mov arg8, %r15 # %r13 = aadLen (number of bytes)
12370 + shl $3, %r15 # convert into number of bits
12371 + movd %r15d, %xmm15 # len(A) in %xmm15
12372 shl $3, %arg4 # len(C) in bits (*128)
12373 MOVQ_R64_XMM %arg4, %xmm1
12374 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12375 @@ -1440,7 +1441,8 @@ _return_T_done_decrypt:
12376 mov %r14, %rsp
12377 pop %r14
12378 pop %r13
12379 - pop %r12
12380 + pop %r15
12381 + pax_force_retaddr
12382 ret
12383 ENDPROC(aesni_gcm_dec)
12384
12385 @@ -1529,7 +1531,7 @@ ENDPROC(aesni_gcm_dec)
12386 * poly = x^128 + x^127 + x^126 + x^121 + 1
12387 ***************************************************************************/
12388 ENTRY(aesni_gcm_enc)
12389 - push %r12
12390 + push %r15
12391 push %r13
12392 push %r14
12393 mov %rsp, %r14
12394 @@ -1539,8 +1541,8 @@ ENTRY(aesni_gcm_enc)
12395 #
12396 sub $VARIABLE_OFFSET, %rsp
12397 and $~63, %rsp
12398 - mov %arg6, %r12
12399 - movdqu (%r12), %xmm13
12400 + mov %arg6, %r15
12401 + movdqu (%r15), %xmm13
12402 movdqa SHUF_MASK(%rip), %xmm2
12403 PSHUFB_XMM %xmm2, %xmm13
12404
12405 @@ -1564,13 +1566,13 @@ ENTRY(aesni_gcm_enc)
12406 movdqa %xmm13, HashKey(%rsp)
12407 mov %arg4, %r13 # %xmm13 holds HashKey<<1 (mod poly)
12408 and $-16, %r13
12409 - mov %r13, %r12
12410 + mov %r13, %r15
12411
12412 # Encrypt first few blocks
12413
12414 - and $(3<<4), %r12
12415 + and $(3<<4), %r15
12416 jz _initial_num_blocks_is_0_encrypt
12417 - cmp $(2<<4), %r12
12418 + cmp $(2<<4), %r15
12419 jb _initial_num_blocks_is_1_encrypt
12420 je _initial_num_blocks_is_2_encrypt
12421 _initial_num_blocks_is_3_encrypt:
12422 @@ -1623,14 +1625,14 @@ _zero_cipher_left_encrypt:
12423 sub $16, %r11
12424 add %r13, %r11
12425 movdqu (%arg3,%r11,1), %xmm1 # receive the last <16 byte blocks
12426 - lea SHIFT_MASK+16(%rip), %r12
12427 - sub %r13, %r12
12428 + lea SHIFT_MASK+16(%rip), %r15
12429 + sub %r13, %r15
12430 # adjust the shuffle mask pointer to be able to shift 16-r13 bytes
12431 # (%r13 is the number of bytes in plaintext mod 16)
12432 - movdqu (%r12), %xmm2 # get the appropriate shuffle mask
12433 + movdqu (%r15), %xmm2 # get the appropriate shuffle mask
12434 PSHUFB_XMM %xmm2, %xmm1 # shift right 16-r13 byte
12435 pxor %xmm1, %xmm0 # Plaintext XOR Encrypt(K, Yn)
12436 - movdqu ALL_F-SHIFT_MASK(%r12), %xmm1
12437 + movdqu ALL_F-SHIFT_MASK(%r15), %xmm1
12438 # get the appropriate mask to mask out top 16-r13 bytes of xmm0
12439 pand %xmm1, %xmm0 # mask out top 16-r13 bytes of xmm0
12440 movdqa SHUF_MASK(%rip), %xmm10
12441 @@ -1663,9 +1665,9 @@ _less_than_8_bytes_left_encrypt:
12442 sub $1, %r13
12443 jne _less_than_8_bytes_left_encrypt
12444 _multiple_of_16_bytes_encrypt:
12445 - mov arg8, %r12 # %r12 = addLen (number of bytes)
12446 - shl $3, %r12
12447 - movd %r12d, %xmm15 # len(A) in %xmm15
12448 + mov arg8, %r15 # %r15 = addLen (number of bytes)
12449 + shl $3, %r15
12450 + movd %r15d, %xmm15 # len(A) in %xmm15
12451 shl $3, %arg4 # len(C) in bits (*128)
12452 MOVQ_R64_XMM %arg4, %xmm1
12453 pslldq $8, %xmm15 # %xmm15 = len(A)||0x0000000000000000
12454 @@ -1704,7 +1706,8 @@ _return_T_done_encrypt:
12455 mov %r14, %rsp
12456 pop %r14
12457 pop %r13
12458 - pop %r12
12459 + pop %r15
12460 + pax_force_retaddr
12461 ret
12462 ENDPROC(aesni_gcm_enc)
12463
12464 @@ -1722,6 +1725,7 @@ _key_expansion_256a:
12465 pxor %xmm1, %xmm0
12466 movaps %xmm0, (TKEYP)
12467 add $0x10, TKEYP
12468 + pax_force_retaddr
12469 ret
12470 ENDPROC(_key_expansion_128)
12471 ENDPROC(_key_expansion_256a)
12472 @@ -1748,6 +1752,7 @@ _key_expansion_192a:
12473 shufps $0b01001110, %xmm2, %xmm1
12474 movaps %xmm1, 0x10(TKEYP)
12475 add $0x20, TKEYP
12476 + pax_force_retaddr
12477 ret
12478 ENDPROC(_key_expansion_192a)
12479
12480 @@ -1768,6 +1773,7 @@ _key_expansion_192b:
12481
12482 movaps %xmm0, (TKEYP)
12483 add $0x10, TKEYP
12484 + pax_force_retaddr
12485 ret
12486 ENDPROC(_key_expansion_192b)
12487
12488 @@ -1781,6 +1787,7 @@ _key_expansion_256b:
12489 pxor %xmm1, %xmm2
12490 movaps %xmm2, (TKEYP)
12491 add $0x10, TKEYP
12492 + pax_force_retaddr
12493 ret
12494 ENDPROC(_key_expansion_256b)
12495
12496 @@ -1894,6 +1901,7 @@ ENTRY(aesni_set_key)
12497 #ifndef __x86_64__
12498 popl KEYP
12499 #endif
12500 + pax_force_retaddr
12501 ret
12502 ENDPROC(aesni_set_key)
12503
12504 @@ -1916,6 +1924,7 @@ ENTRY(aesni_enc)
12505 popl KLEN
12506 popl KEYP
12507 #endif
12508 + pax_force_retaddr
12509 ret
12510 ENDPROC(aesni_enc)
12511
12512 @@ -1974,6 +1983,7 @@ _aesni_enc1:
12513 AESENC KEY STATE
12514 movaps 0x70(TKEYP), KEY
12515 AESENCLAST KEY STATE
12516 + pax_force_retaddr
12517 ret
12518 ENDPROC(_aesni_enc1)
12519
12520 @@ -2083,6 +2093,7 @@ _aesni_enc4:
12521 AESENCLAST KEY STATE2
12522 AESENCLAST KEY STATE3
12523 AESENCLAST KEY STATE4
12524 + pax_force_retaddr
12525 ret
12526 ENDPROC(_aesni_enc4)
12527
12528 @@ -2106,6 +2117,7 @@ ENTRY(aesni_dec)
12529 popl KLEN
12530 popl KEYP
12531 #endif
12532 + pax_force_retaddr
12533 ret
12534 ENDPROC(aesni_dec)
12535
12536 @@ -2164,6 +2176,7 @@ _aesni_dec1:
12537 AESDEC KEY STATE
12538 movaps 0x70(TKEYP), KEY
12539 AESDECLAST KEY STATE
12540 + pax_force_retaddr
12541 ret
12542 ENDPROC(_aesni_dec1)
12543
12544 @@ -2273,6 +2286,7 @@ _aesni_dec4:
12545 AESDECLAST KEY STATE2
12546 AESDECLAST KEY STATE3
12547 AESDECLAST KEY STATE4
12548 + pax_force_retaddr
12549 ret
12550 ENDPROC(_aesni_dec4)
12551
12552 @@ -2331,6 +2345,7 @@ ENTRY(aesni_ecb_enc)
12553 popl KEYP
12554 popl LEN
12555 #endif
12556 + pax_force_retaddr
12557 ret
12558 ENDPROC(aesni_ecb_enc)
12559
12560 @@ -2390,6 +2405,7 @@ ENTRY(aesni_ecb_dec)
12561 popl KEYP
12562 popl LEN
12563 #endif
12564 + pax_force_retaddr
12565 ret
12566 ENDPROC(aesni_ecb_dec)
12567
12568 @@ -2432,6 +2448,7 @@ ENTRY(aesni_cbc_enc)
12569 popl LEN
12570 popl IVP
12571 #endif
12572 + pax_force_retaddr
12573 ret
12574 ENDPROC(aesni_cbc_enc)
12575
12576 @@ -2523,6 +2540,7 @@ ENTRY(aesni_cbc_dec)
12577 popl LEN
12578 popl IVP
12579 #endif
12580 + pax_force_retaddr
12581 ret
12582 ENDPROC(aesni_cbc_dec)
12583
12584 @@ -2550,6 +2568,7 @@ _aesni_inc_init:
12585 mov $1, TCTR_LOW
12586 MOVQ_R64_XMM TCTR_LOW INC
12587 MOVQ_R64_XMM CTR TCTR_LOW
12588 + pax_force_retaddr
12589 ret
12590 ENDPROC(_aesni_inc_init)
12591
12592 @@ -2579,6 +2598,7 @@ _aesni_inc:
12593 .Linc_low:
12594 movaps CTR, IV
12595 PSHUFB_XMM BSWAP_MASK IV
12596 + pax_force_retaddr
12597 ret
12598 ENDPROC(_aesni_inc)
12599
12600 @@ -2640,6 +2660,7 @@ ENTRY(aesni_ctr_enc)
12601 .Lctr_enc_ret:
12602 movups IV, (IVP)
12603 .Lctr_enc_just_ret:
12604 + pax_force_retaddr
12605 ret
12606 ENDPROC(aesni_ctr_enc)
12607
12608 @@ -2766,6 +2787,7 @@ ENTRY(aesni_xts_crypt8)
12609 pxor INC, STATE4
12610 movdqu STATE4, 0x70(OUTP)
12611
12612 + pax_force_retaddr
12613 ret
12614 ENDPROC(aesni_xts_crypt8)
12615
12616 diff --git a/arch/x86/crypto/blowfish-x86_64-asm_64.S b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12617 index 246c670..466e2d6 100644
12618 --- a/arch/x86/crypto/blowfish-x86_64-asm_64.S
12619 +++ b/arch/x86/crypto/blowfish-x86_64-asm_64.S
12620 @@ -21,6 +21,7 @@
12621 */
12622
12623 #include <linux/linkage.h>
12624 +#include <asm/alternative-asm.h>
12625
12626 .file "blowfish-x86_64-asm.S"
12627 .text
12628 @@ -149,9 +150,11 @@ ENTRY(__blowfish_enc_blk)
12629 jnz .L__enc_xor;
12630
12631 write_block();
12632 + pax_force_retaddr
12633 ret;
12634 .L__enc_xor:
12635 xor_block();
12636 + pax_force_retaddr
12637 ret;
12638 ENDPROC(__blowfish_enc_blk)
12639
12640 @@ -183,6 +186,7 @@ ENTRY(blowfish_dec_blk)
12641
12642 movq %r11, %rbp;
12643
12644 + pax_force_retaddr
12645 ret;
12646 ENDPROC(blowfish_dec_blk)
12647
12648 @@ -334,6 +338,7 @@ ENTRY(__blowfish_enc_blk_4way)
12649
12650 popq %rbx;
12651 popq %rbp;
12652 + pax_force_retaddr
12653 ret;
12654
12655 .L__enc_xor4:
12656 @@ -341,6 +346,7 @@ ENTRY(__blowfish_enc_blk_4way)
12657
12658 popq %rbx;
12659 popq %rbp;
12660 + pax_force_retaddr
12661 ret;
12662 ENDPROC(__blowfish_enc_blk_4way)
12663
12664 @@ -375,5 +381,6 @@ ENTRY(blowfish_dec_blk_4way)
12665 popq %rbx;
12666 popq %rbp;
12667
12668 + pax_force_retaddr
12669 ret;
12670 ENDPROC(blowfish_dec_blk_4way)
12671 diff --git a/arch/x86/crypto/camellia-aesni-avx-asm_64.S b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12672 index ce71f92..1dce7ec 100644
12673 --- a/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12674 +++ b/arch/x86/crypto/camellia-aesni-avx-asm_64.S
12675 @@ -16,6 +16,7 @@
12676 */
12677
12678 #include <linux/linkage.h>
12679 +#include <asm/alternative-asm.h>
12680
12681 #define CAMELLIA_TABLE_BYTE_LEN 272
12682
12683 @@ -191,6 +192,7 @@ roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12684 roundsm16(%xmm0, %xmm1, %xmm2, %xmm3, %xmm4, %xmm5, %xmm6, %xmm7,
12685 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14, %xmm15,
12686 %rcx, (%r9));
12687 + pax_force_retaddr
12688 ret;
12689 ENDPROC(roundsm16_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12690
12691 @@ -199,6 +201,7 @@ roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12692 roundsm16(%xmm4, %xmm5, %xmm6, %xmm7, %xmm0, %xmm1, %xmm2, %xmm3,
12693 %xmm12, %xmm13, %xmm14, %xmm15, %xmm8, %xmm9, %xmm10, %xmm11,
12694 %rax, (%r9));
12695 + pax_force_retaddr
12696 ret;
12697 ENDPROC(roundsm16_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12698
12699 @@ -780,6 +783,7 @@ __camellia_enc_blk16:
12700 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12701 %xmm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 16(%rax));
12702
12703 + pax_force_retaddr
12704 ret;
12705
12706 .align 8
12707 @@ -865,6 +869,7 @@ __camellia_dec_blk16:
12708 %xmm8, %xmm9, %xmm10, %xmm11, %xmm12, %xmm13, %xmm14,
12709 %xmm15, (key_table)(CTX), (%rax), 1 * 16(%rax));
12710
12711 + pax_force_retaddr
12712 ret;
12713
12714 .align 8
12715 @@ -904,6 +909,7 @@ ENTRY(camellia_ecb_enc_16way)
12716 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12717 %xmm8, %rsi);
12718
12719 + pax_force_retaddr
12720 ret;
12721 ENDPROC(camellia_ecb_enc_16way)
12722
12723 @@ -932,6 +938,7 @@ ENTRY(camellia_ecb_dec_16way)
12724 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12725 %xmm8, %rsi);
12726
12727 + pax_force_retaddr
12728 ret;
12729 ENDPROC(camellia_ecb_dec_16way)
12730
12731 @@ -981,6 +988,7 @@ ENTRY(camellia_cbc_dec_16way)
12732 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12733 %xmm8, %rsi);
12734
12735 + pax_force_retaddr
12736 ret;
12737 ENDPROC(camellia_cbc_dec_16way)
12738
12739 @@ -1092,6 +1100,7 @@ ENTRY(camellia_ctr_16way)
12740 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12741 %xmm8, %rsi);
12742
12743 + pax_force_retaddr
12744 ret;
12745 ENDPROC(camellia_ctr_16way)
12746
12747 @@ -1234,6 +1243,7 @@ camellia_xts_crypt_16way:
12748 %xmm15, %xmm14, %xmm13, %xmm12, %xmm11, %xmm10, %xmm9,
12749 %xmm8, %rsi);
12750
12751 + pax_force_retaddr
12752 ret;
12753 ENDPROC(camellia_xts_crypt_16way)
12754
12755 diff --git a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12756 index 0e0b886..5a3123c 100644
12757 --- a/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12758 +++ b/arch/x86/crypto/camellia-aesni-avx2-asm_64.S
12759 @@ -11,6 +11,7 @@
12760 */
12761
12762 #include <linux/linkage.h>
12763 +#include <asm/alternative-asm.h>
12764
12765 #define CAMELLIA_TABLE_BYTE_LEN 272
12766
12767 @@ -230,6 +231,7 @@ roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd:
12768 roundsm32(%ymm0, %ymm1, %ymm2, %ymm3, %ymm4, %ymm5, %ymm6, %ymm7,
12769 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14, %ymm15,
12770 %rcx, (%r9));
12771 + pax_force_retaddr
12772 ret;
12773 ENDPROC(roundsm32_x0_x1_x2_x3_x4_x5_x6_x7_y0_y1_y2_y3_y4_y5_y6_y7_cd)
12774
12775 @@ -238,6 +240,7 @@ roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab:
12776 roundsm32(%ymm4, %ymm5, %ymm6, %ymm7, %ymm0, %ymm1, %ymm2, %ymm3,
12777 %ymm12, %ymm13, %ymm14, %ymm15, %ymm8, %ymm9, %ymm10, %ymm11,
12778 %rax, (%r9));
12779 + pax_force_retaddr
12780 ret;
12781 ENDPROC(roundsm32_x4_x5_x6_x7_x0_x1_x2_x3_y4_y5_y6_y7_y0_y1_y2_y3_ab)
12782
12783 @@ -820,6 +823,7 @@ __camellia_enc_blk32:
12784 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12785 %ymm15, (key_table)(CTX, %r8, 8), (%rax), 1 * 32(%rax));
12786
12787 + pax_force_retaddr
12788 ret;
12789
12790 .align 8
12791 @@ -905,6 +909,7 @@ __camellia_dec_blk32:
12792 %ymm8, %ymm9, %ymm10, %ymm11, %ymm12, %ymm13, %ymm14,
12793 %ymm15, (key_table)(CTX), (%rax), 1 * 32(%rax));
12794
12795 + pax_force_retaddr
12796 ret;
12797
12798 .align 8
12799 @@ -948,6 +953,7 @@ ENTRY(camellia_ecb_enc_32way)
12800
12801 vzeroupper;
12802
12803 + pax_force_retaddr
12804 ret;
12805 ENDPROC(camellia_ecb_enc_32way)
12806
12807 @@ -980,6 +986,7 @@ ENTRY(camellia_ecb_dec_32way)
12808
12809 vzeroupper;
12810
12811 + pax_force_retaddr
12812 ret;
12813 ENDPROC(camellia_ecb_dec_32way)
12814
12815 @@ -1046,6 +1053,7 @@ ENTRY(camellia_cbc_dec_32way)
12816
12817 vzeroupper;
12818
12819 + pax_force_retaddr
12820 ret;
12821 ENDPROC(camellia_cbc_dec_32way)
12822
12823 @@ -1184,6 +1192,7 @@ ENTRY(camellia_ctr_32way)
12824
12825 vzeroupper;
12826
12827 + pax_force_retaddr
12828 ret;
12829 ENDPROC(camellia_ctr_32way)
12830
12831 @@ -1349,6 +1358,7 @@ camellia_xts_crypt_32way:
12832
12833 vzeroupper;
12834
12835 + pax_force_retaddr
12836 ret;
12837 ENDPROC(camellia_xts_crypt_32way)
12838
12839 diff --git a/arch/x86/crypto/camellia-x86_64-asm_64.S b/arch/x86/crypto/camellia-x86_64-asm_64.S
12840 index 310319c..db3d7b5 100644
12841 --- a/arch/x86/crypto/camellia-x86_64-asm_64.S
12842 +++ b/arch/x86/crypto/camellia-x86_64-asm_64.S
12843 @@ -21,6 +21,7 @@
12844 */
12845
12846 #include <linux/linkage.h>
12847 +#include <asm/alternative-asm.h>
12848
12849 .file "camellia-x86_64-asm_64.S"
12850 .text
12851 @@ -228,12 +229,14 @@ ENTRY(__camellia_enc_blk)
12852 enc_outunpack(mov, RT1);
12853
12854 movq RRBP, %rbp;
12855 + pax_force_retaddr
12856 ret;
12857
12858 .L__enc_xor:
12859 enc_outunpack(xor, RT1);
12860
12861 movq RRBP, %rbp;
12862 + pax_force_retaddr
12863 ret;
12864 ENDPROC(__camellia_enc_blk)
12865
12866 @@ -272,6 +275,7 @@ ENTRY(camellia_dec_blk)
12867 dec_outunpack();
12868
12869 movq RRBP, %rbp;
12870 + pax_force_retaddr
12871 ret;
12872 ENDPROC(camellia_dec_blk)
12873
12874 @@ -463,6 +467,7 @@ ENTRY(__camellia_enc_blk_2way)
12875
12876 movq RRBP, %rbp;
12877 popq %rbx;
12878 + pax_force_retaddr
12879 ret;
12880
12881 .L__enc2_xor:
12882 @@ -470,6 +475,7 @@ ENTRY(__camellia_enc_blk_2way)
12883
12884 movq RRBP, %rbp;
12885 popq %rbx;
12886 + pax_force_retaddr
12887 ret;
12888 ENDPROC(__camellia_enc_blk_2way)
12889
12890 @@ -510,5 +516,6 @@ ENTRY(camellia_dec_blk_2way)
12891
12892 movq RRBP, %rbp;
12893 movq RXOR, %rbx;
12894 + pax_force_retaddr
12895 ret;
12896 ENDPROC(camellia_dec_blk_2way)
12897 diff --git a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12898 index c35fd5d..2d8c7db 100644
12899 --- a/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12900 +++ b/arch/x86/crypto/cast5-avx-x86_64-asm_64.S
12901 @@ -24,6 +24,7 @@
12902 */
12903
12904 #include <linux/linkage.h>
12905 +#include <asm/alternative-asm.h>
12906
12907 .file "cast5-avx-x86_64-asm_64.S"
12908
12909 @@ -281,6 +282,7 @@ __cast5_enc_blk16:
12910 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12911 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12912
12913 + pax_force_retaddr
12914 ret;
12915 ENDPROC(__cast5_enc_blk16)
12916
12917 @@ -352,6 +354,7 @@ __cast5_dec_blk16:
12918 outunpack_blocks(RR3, RL3, RTMP, RX, RKM);
12919 outunpack_blocks(RR4, RL4, RTMP, RX, RKM);
12920
12921 + pax_force_retaddr
12922 ret;
12923
12924 .L__skip_dec:
12925 @@ -388,6 +391,7 @@ ENTRY(cast5_ecb_enc_16way)
12926 vmovdqu RR4, (6*4*4)(%r11);
12927 vmovdqu RL4, (7*4*4)(%r11);
12928
12929 + pax_force_retaddr
12930 ret;
12931 ENDPROC(cast5_ecb_enc_16way)
12932
12933 @@ -420,6 +424,7 @@ ENTRY(cast5_ecb_dec_16way)
12934 vmovdqu RR4, (6*4*4)(%r11);
12935 vmovdqu RL4, (7*4*4)(%r11);
12936
12937 + pax_force_retaddr
12938 ret;
12939 ENDPROC(cast5_ecb_dec_16way)
12940
12941 @@ -430,10 +435,10 @@ ENTRY(cast5_cbc_dec_16way)
12942 * %rdx: src
12943 */
12944
12945 - pushq %r12;
12946 + pushq %r14;
12947
12948 movq %rsi, %r11;
12949 - movq %rdx, %r12;
12950 + movq %rdx, %r14;
12951
12952 vmovdqu (0*16)(%rdx), RL1;
12953 vmovdqu (1*16)(%rdx), RR1;
12954 @@ -447,16 +452,16 @@ ENTRY(cast5_cbc_dec_16way)
12955 call __cast5_dec_blk16;
12956
12957 /* xor with src */
12958 - vmovq (%r12), RX;
12959 + vmovq (%r14), RX;
12960 vpshufd $0x4f, RX, RX;
12961 vpxor RX, RR1, RR1;
12962 - vpxor 0*16+8(%r12), RL1, RL1;
12963 - vpxor 1*16+8(%r12), RR2, RR2;
12964 - vpxor 2*16+8(%r12), RL2, RL2;
12965 - vpxor 3*16+8(%r12), RR3, RR3;
12966 - vpxor 4*16+8(%r12), RL3, RL3;
12967 - vpxor 5*16+8(%r12), RR4, RR4;
12968 - vpxor 6*16+8(%r12), RL4, RL4;
12969 + vpxor 0*16+8(%r14), RL1, RL1;
12970 + vpxor 1*16+8(%r14), RR2, RR2;
12971 + vpxor 2*16+8(%r14), RL2, RL2;
12972 + vpxor 3*16+8(%r14), RR3, RR3;
12973 + vpxor 4*16+8(%r14), RL3, RL3;
12974 + vpxor 5*16+8(%r14), RR4, RR4;
12975 + vpxor 6*16+8(%r14), RL4, RL4;
12976
12977 vmovdqu RR1, (0*16)(%r11);
12978 vmovdqu RL1, (1*16)(%r11);
12979 @@ -467,8 +472,9 @@ ENTRY(cast5_cbc_dec_16way)
12980 vmovdqu RR4, (6*16)(%r11);
12981 vmovdqu RL4, (7*16)(%r11);
12982
12983 - popq %r12;
12984 + popq %r14;
12985
12986 + pax_force_retaddr
12987 ret;
12988 ENDPROC(cast5_cbc_dec_16way)
12989
12990 @@ -480,10 +486,10 @@ ENTRY(cast5_ctr_16way)
12991 * %rcx: iv (big endian, 64bit)
12992 */
12993
12994 - pushq %r12;
12995 + pushq %r14;
12996
12997 movq %rsi, %r11;
12998 - movq %rdx, %r12;
12999 + movq %rdx, %r14;
13000
13001 vpcmpeqd RTMP, RTMP, RTMP;
13002 vpsrldq $8, RTMP, RTMP; /* low: -1, high: 0 */
13003 @@ -523,14 +529,14 @@ ENTRY(cast5_ctr_16way)
13004 call __cast5_enc_blk16;
13005
13006 /* dst = src ^ iv */
13007 - vpxor (0*16)(%r12), RR1, RR1;
13008 - vpxor (1*16)(%r12), RL1, RL1;
13009 - vpxor (2*16)(%r12), RR2, RR2;
13010 - vpxor (3*16)(%r12), RL2, RL2;
13011 - vpxor (4*16)(%r12), RR3, RR3;
13012 - vpxor (5*16)(%r12), RL3, RL3;
13013 - vpxor (6*16)(%r12), RR4, RR4;
13014 - vpxor (7*16)(%r12), RL4, RL4;
13015 + vpxor (0*16)(%r14), RR1, RR1;
13016 + vpxor (1*16)(%r14), RL1, RL1;
13017 + vpxor (2*16)(%r14), RR2, RR2;
13018 + vpxor (3*16)(%r14), RL2, RL2;
13019 + vpxor (4*16)(%r14), RR3, RR3;
13020 + vpxor (5*16)(%r14), RL3, RL3;
13021 + vpxor (6*16)(%r14), RR4, RR4;
13022 + vpxor (7*16)(%r14), RL4, RL4;
13023 vmovdqu RR1, (0*16)(%r11);
13024 vmovdqu RL1, (1*16)(%r11);
13025 vmovdqu RR2, (2*16)(%r11);
13026 @@ -540,7 +546,8 @@ ENTRY(cast5_ctr_16way)
13027 vmovdqu RR4, (6*16)(%r11);
13028 vmovdqu RL4, (7*16)(%r11);
13029
13030 - popq %r12;
13031 + popq %r14;
13032
13033 + pax_force_retaddr
13034 ret;
13035 ENDPROC(cast5_ctr_16way)
13036 diff --git a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13037 index e3531f8..e123f35 100644
13038 --- a/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13039 +++ b/arch/x86/crypto/cast6-avx-x86_64-asm_64.S
13040 @@ -24,6 +24,7 @@
13041 */
13042
13043 #include <linux/linkage.h>
13044 +#include <asm/alternative-asm.h>
13045 #include "glue_helper-asm-avx.S"
13046
13047 .file "cast6-avx-x86_64-asm_64.S"
13048 @@ -295,6 +296,7 @@ __cast6_enc_blk8:
13049 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13050 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13051
13052 + pax_force_retaddr
13053 ret;
13054 ENDPROC(__cast6_enc_blk8)
13055
13056 @@ -340,6 +342,7 @@ __cast6_dec_blk8:
13057 outunpack_blocks(RA1, RB1, RC1, RD1, RTMP, RX, RKRF, RKM);
13058 outunpack_blocks(RA2, RB2, RC2, RD2, RTMP, RX, RKRF, RKM);
13059
13060 + pax_force_retaddr
13061 ret;
13062 ENDPROC(__cast6_dec_blk8)
13063
13064 @@ -358,6 +361,7 @@ ENTRY(cast6_ecb_enc_8way)
13065
13066 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13067
13068 + pax_force_retaddr
13069 ret;
13070 ENDPROC(cast6_ecb_enc_8way)
13071
13072 @@ -376,6 +380,7 @@ ENTRY(cast6_ecb_dec_8way)
13073
13074 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13075
13076 + pax_force_retaddr
13077 ret;
13078 ENDPROC(cast6_ecb_dec_8way)
13079
13080 @@ -386,19 +391,20 @@ ENTRY(cast6_cbc_dec_8way)
13081 * %rdx: src
13082 */
13083
13084 - pushq %r12;
13085 + pushq %r14;
13086
13087 movq %rsi, %r11;
13088 - movq %rdx, %r12;
13089 + movq %rdx, %r14;
13090
13091 load_8way(%rdx, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13092
13093 call __cast6_dec_blk8;
13094
13095 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13096 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13097
13098 - popq %r12;
13099 + popq %r14;
13100
13101 + pax_force_retaddr
13102 ret;
13103 ENDPROC(cast6_cbc_dec_8way)
13104
13105 @@ -410,20 +416,21 @@ ENTRY(cast6_ctr_8way)
13106 * %rcx: iv (little endian, 128bit)
13107 */
13108
13109 - pushq %r12;
13110 + pushq %r14;
13111
13112 movq %rsi, %r11;
13113 - movq %rdx, %r12;
13114 + movq %rdx, %r14;
13115
13116 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13117 RD2, RX, RKR, RKM);
13118
13119 call __cast6_enc_blk8;
13120
13121 - store_ctr_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13122 + store_ctr_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13123
13124 - popq %r12;
13125 + popq %r14;
13126
13127 + pax_force_retaddr
13128 ret;
13129 ENDPROC(cast6_ctr_8way)
13130
13131 @@ -446,6 +453,7 @@ ENTRY(cast6_xts_enc_8way)
13132 /* dst <= regs xor IVs(in dst) */
13133 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13134
13135 + pax_force_retaddr
13136 ret;
13137 ENDPROC(cast6_xts_enc_8way)
13138
13139 @@ -468,5 +476,6 @@ ENTRY(cast6_xts_dec_8way)
13140 /* dst <= regs xor IVs(in dst) */
13141 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13142
13143 + pax_force_retaddr
13144 ret;
13145 ENDPROC(cast6_xts_dec_8way)
13146 diff --git a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13147 index dbc4339..de6e120 100644
13148 --- a/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13149 +++ b/arch/x86/crypto/crc32c-pcl-intel-asm_64.S
13150 @@ -45,6 +45,7 @@
13151
13152 #include <asm/inst.h>
13153 #include <linux/linkage.h>
13154 +#include <asm/alternative-asm.h>
13155
13156 ## ISCSI CRC 32 Implementation with crc32 and pclmulqdq Instruction
13157
13158 @@ -312,6 +313,7 @@ do_return:
13159 popq %rsi
13160 popq %rdi
13161 popq %rbx
13162 + pax_force_retaddr
13163 ret
13164
13165 ################################################################
13166 diff --git a/arch/x86/crypto/ghash-clmulni-intel_asm.S b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13167 index 586f41a..d02851e 100644
13168 --- a/arch/x86/crypto/ghash-clmulni-intel_asm.S
13169 +++ b/arch/x86/crypto/ghash-clmulni-intel_asm.S
13170 @@ -18,6 +18,7 @@
13171
13172 #include <linux/linkage.h>
13173 #include <asm/inst.h>
13174 +#include <asm/alternative-asm.h>
13175
13176 .data
13177
13178 @@ -93,6 +94,7 @@ __clmul_gf128mul_ble:
13179 psrlq $1, T2
13180 pxor T2, T1
13181 pxor T1, DATA
13182 + pax_force_retaddr
13183 ret
13184 ENDPROC(__clmul_gf128mul_ble)
13185
13186 @@ -105,6 +107,7 @@ ENTRY(clmul_ghash_mul)
13187 call __clmul_gf128mul_ble
13188 PSHUFB_XMM BSWAP DATA
13189 movups DATA, (%rdi)
13190 + pax_force_retaddr
13191 ret
13192 ENDPROC(clmul_ghash_mul)
13193
13194 @@ -132,6 +135,7 @@ ENTRY(clmul_ghash_update)
13195 PSHUFB_XMM BSWAP DATA
13196 movups DATA, (%rdi)
13197 .Lupdate_just_ret:
13198 + pax_force_retaddr
13199 ret
13200 ENDPROC(clmul_ghash_update)
13201
13202 @@ -157,5 +161,6 @@ ENTRY(clmul_ghash_setkey)
13203 pand .Lpoly, %xmm1
13204 pxor %xmm1, %xmm0
13205 movups %xmm0, (%rdi)
13206 + pax_force_retaddr
13207 ret
13208 ENDPROC(clmul_ghash_setkey)
13209 diff --git a/arch/x86/crypto/salsa20-x86_64-asm_64.S b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13210 index 9279e0b..c4b3d2c 100644
13211 --- a/arch/x86/crypto/salsa20-x86_64-asm_64.S
13212 +++ b/arch/x86/crypto/salsa20-x86_64-asm_64.S
13213 @@ -1,4 +1,5 @@
13214 #include <linux/linkage.h>
13215 +#include <asm/alternative-asm.h>
13216
13217 # enter salsa20_encrypt_bytes
13218 ENTRY(salsa20_encrypt_bytes)
13219 @@ -789,6 +790,7 @@ ENTRY(salsa20_encrypt_bytes)
13220 add %r11,%rsp
13221 mov %rdi,%rax
13222 mov %rsi,%rdx
13223 + pax_force_retaddr
13224 ret
13225 # bytesatleast65:
13226 ._bytesatleast65:
13227 @@ -889,6 +891,7 @@ ENTRY(salsa20_keysetup)
13228 add %r11,%rsp
13229 mov %rdi,%rax
13230 mov %rsi,%rdx
13231 + pax_force_retaddr
13232 ret
13233 ENDPROC(salsa20_keysetup)
13234
13235 @@ -914,5 +917,6 @@ ENTRY(salsa20_ivsetup)
13236 add %r11,%rsp
13237 mov %rdi,%rax
13238 mov %rsi,%rdx
13239 + pax_force_retaddr
13240 ret
13241 ENDPROC(salsa20_ivsetup)
13242 diff --git a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13243 index 2f202f4..d9164d6 100644
13244 --- a/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13245 +++ b/arch/x86/crypto/serpent-avx-x86_64-asm_64.S
13246 @@ -24,6 +24,7 @@
13247 */
13248
13249 #include <linux/linkage.h>
13250 +#include <asm/alternative-asm.h>
13251 #include "glue_helper-asm-avx.S"
13252
13253 .file "serpent-avx-x86_64-asm_64.S"
13254 @@ -618,6 +619,7 @@ __serpent_enc_blk8_avx:
13255 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13256 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13257
13258 + pax_force_retaddr
13259 ret;
13260 ENDPROC(__serpent_enc_blk8_avx)
13261
13262 @@ -672,6 +674,7 @@ __serpent_dec_blk8_avx:
13263 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13264 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13265
13266 + pax_force_retaddr
13267 ret;
13268 ENDPROC(__serpent_dec_blk8_avx)
13269
13270 @@ -688,6 +691,7 @@ ENTRY(serpent_ecb_enc_8way_avx)
13271
13272 store_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13273
13274 + pax_force_retaddr
13275 ret;
13276 ENDPROC(serpent_ecb_enc_8way_avx)
13277
13278 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_8way_avx)
13279
13280 store_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13281
13282 + pax_force_retaddr
13283 ret;
13284 ENDPROC(serpent_ecb_dec_8way_avx)
13285
13286 @@ -720,6 +725,7 @@ ENTRY(serpent_cbc_dec_8way_avx)
13287
13288 store_cbc_8way(%rdx, %rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13289
13290 + pax_force_retaddr
13291 ret;
13292 ENDPROC(serpent_cbc_dec_8way_avx)
13293
13294 @@ -738,6 +744,7 @@ ENTRY(serpent_ctr_8way_avx)
13295
13296 store_ctr_8way(%rdx, %rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13297
13298 + pax_force_retaddr
13299 ret;
13300 ENDPROC(serpent_ctr_8way_avx)
13301
13302 @@ -758,6 +765,7 @@ ENTRY(serpent_xts_enc_8way_avx)
13303 /* dst <= regs xor IVs(in dst) */
13304 store_xts_8way(%rsi, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13305
13306 + pax_force_retaddr
13307 ret;
13308 ENDPROC(serpent_xts_enc_8way_avx)
13309
13310 @@ -778,5 +786,6 @@ ENTRY(serpent_xts_dec_8way_avx)
13311 /* dst <= regs xor IVs(in dst) */
13312 store_xts_8way(%rsi, RC1, RD1, RB1, RE1, RC2, RD2, RB2, RE2);
13313
13314 + pax_force_retaddr
13315 ret;
13316 ENDPROC(serpent_xts_dec_8way_avx)
13317 diff --git a/arch/x86/crypto/serpent-avx2-asm_64.S b/arch/x86/crypto/serpent-avx2-asm_64.S
13318 index b222085..abd483c 100644
13319 --- a/arch/x86/crypto/serpent-avx2-asm_64.S
13320 +++ b/arch/x86/crypto/serpent-avx2-asm_64.S
13321 @@ -15,6 +15,7 @@
13322 */
13323
13324 #include <linux/linkage.h>
13325 +#include <asm/alternative-asm.h>
13326 #include "glue_helper-asm-avx2.S"
13327
13328 .file "serpent-avx2-asm_64.S"
13329 @@ -610,6 +611,7 @@ __serpent_enc_blk16:
13330 write_blocks(RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13331 write_blocks(RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13332
13333 + pax_force_retaddr
13334 ret;
13335 ENDPROC(__serpent_enc_blk16)
13336
13337 @@ -664,6 +666,7 @@ __serpent_dec_blk16:
13338 write_blocks(RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13339 write_blocks(RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13340
13341 + pax_force_retaddr
13342 ret;
13343 ENDPROC(__serpent_dec_blk16)
13344
13345 @@ -684,6 +687,7 @@ ENTRY(serpent_ecb_enc_16way)
13346
13347 vzeroupper;
13348
13349 + pax_force_retaddr
13350 ret;
13351 ENDPROC(serpent_ecb_enc_16way)
13352
13353 @@ -704,6 +708,7 @@ ENTRY(serpent_ecb_dec_16way)
13354
13355 vzeroupper;
13356
13357 + pax_force_retaddr
13358 ret;
13359 ENDPROC(serpent_ecb_dec_16way)
13360
13361 @@ -725,6 +730,7 @@ ENTRY(serpent_cbc_dec_16way)
13362
13363 vzeroupper;
13364
13365 + pax_force_retaddr
13366 ret;
13367 ENDPROC(serpent_cbc_dec_16way)
13368
13369 @@ -748,6 +754,7 @@ ENTRY(serpent_ctr_16way)
13370
13371 vzeroupper;
13372
13373 + pax_force_retaddr
13374 ret;
13375 ENDPROC(serpent_ctr_16way)
13376
13377 @@ -772,6 +779,7 @@ ENTRY(serpent_xts_enc_16way)
13378
13379 vzeroupper;
13380
13381 + pax_force_retaddr
13382 ret;
13383 ENDPROC(serpent_xts_enc_16way)
13384
13385 @@ -796,5 +804,6 @@ ENTRY(serpent_xts_dec_16way)
13386
13387 vzeroupper;
13388
13389 + pax_force_retaddr
13390 ret;
13391 ENDPROC(serpent_xts_dec_16way)
13392 diff --git a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13393 index acc066c..1559cc4 100644
13394 --- a/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13395 +++ b/arch/x86/crypto/serpent-sse2-x86_64-asm_64.S
13396 @@ -25,6 +25,7 @@
13397 */
13398
13399 #include <linux/linkage.h>
13400 +#include <asm/alternative-asm.h>
13401
13402 .file "serpent-sse2-x86_64-asm_64.S"
13403 .text
13404 @@ -690,12 +691,14 @@ ENTRY(__serpent_enc_blk_8way)
13405 write_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13406 write_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13407
13408 + pax_force_retaddr
13409 ret;
13410
13411 .L__enc_xor8:
13412 xor_blocks(%rsi, RA1, RB1, RC1, RD1, RK0, RK1, RK2);
13413 xor_blocks(%rax, RA2, RB2, RC2, RD2, RK0, RK1, RK2);
13414
13415 + pax_force_retaddr
13416 ret;
13417 ENDPROC(__serpent_enc_blk_8way)
13418
13419 @@ -750,5 +753,6 @@ ENTRY(serpent_dec_blk_8way)
13420 write_blocks(%rsi, RC1, RD1, RB1, RE1, RK0, RK1, RK2);
13421 write_blocks(%rax, RC2, RD2, RB2, RE2, RK0, RK1, RK2);
13422
13423 + pax_force_retaddr
13424 ret;
13425 ENDPROC(serpent_dec_blk_8way)
13426 diff --git a/arch/x86/crypto/sha1_ssse3_asm.S b/arch/x86/crypto/sha1_ssse3_asm.S
13427 index a410950..9dfe7ad 100644
13428 --- a/arch/x86/crypto/sha1_ssse3_asm.S
13429 +++ b/arch/x86/crypto/sha1_ssse3_asm.S
13430 @@ -29,6 +29,7 @@
13431 */
13432
13433 #include <linux/linkage.h>
13434 +#include <asm/alternative-asm.h>
13435
13436 #define CTX %rdi // arg1
13437 #define BUF %rsi // arg2
13438 @@ -75,9 +76,9 @@
13439
13440 push %rbx
13441 push %rbp
13442 - push %r12
13443 + push %r14
13444
13445 - mov %rsp, %r12
13446 + mov %rsp, %r14
13447 sub $64, %rsp # allocate workspace
13448 and $~15, %rsp # align stack
13449
13450 @@ -99,11 +100,12 @@
13451 xor %rax, %rax
13452 rep stosq
13453
13454 - mov %r12, %rsp # deallocate workspace
13455 + mov %r14, %rsp # deallocate workspace
13456
13457 - pop %r12
13458 + pop %r14
13459 pop %rbp
13460 pop %rbx
13461 + pax_force_retaddr
13462 ret
13463
13464 ENDPROC(\name)
13465 diff --git a/arch/x86/crypto/sha256-avx-asm.S b/arch/x86/crypto/sha256-avx-asm.S
13466 index 642f156..51a513c 100644
13467 --- a/arch/x86/crypto/sha256-avx-asm.S
13468 +++ b/arch/x86/crypto/sha256-avx-asm.S
13469 @@ -49,6 +49,7 @@
13470
13471 #ifdef CONFIG_AS_AVX
13472 #include <linux/linkage.h>
13473 +#include <asm/alternative-asm.h>
13474
13475 ## assume buffers not aligned
13476 #define VMOVDQ vmovdqu
13477 @@ -460,6 +461,7 @@ done_hash:
13478 popq %r13
13479 popq %rbp
13480 popq %rbx
13481 + pax_force_retaddr
13482 ret
13483 ENDPROC(sha256_transform_avx)
13484
13485 diff --git a/arch/x86/crypto/sha256-avx2-asm.S b/arch/x86/crypto/sha256-avx2-asm.S
13486 index 9e86944..3795e6a 100644
13487 --- a/arch/x86/crypto/sha256-avx2-asm.S
13488 +++ b/arch/x86/crypto/sha256-avx2-asm.S
13489 @@ -50,6 +50,7 @@
13490
13491 #ifdef CONFIG_AS_AVX2
13492 #include <linux/linkage.h>
13493 +#include <asm/alternative-asm.h>
13494
13495 ## assume buffers not aligned
13496 #define VMOVDQ vmovdqu
13497 @@ -720,6 +721,7 @@ done_hash:
13498 popq %r12
13499 popq %rbp
13500 popq %rbx
13501 + pax_force_retaddr
13502 ret
13503 ENDPROC(sha256_transform_rorx)
13504
13505 diff --git a/arch/x86/crypto/sha256-ssse3-asm.S b/arch/x86/crypto/sha256-ssse3-asm.S
13506 index f833b74..8c62a9e 100644
13507 --- a/arch/x86/crypto/sha256-ssse3-asm.S
13508 +++ b/arch/x86/crypto/sha256-ssse3-asm.S
13509 @@ -47,6 +47,7 @@
13510 ########################################################################
13511
13512 #include <linux/linkage.h>
13513 +#include <asm/alternative-asm.h>
13514
13515 ## assume buffers not aligned
13516 #define MOVDQ movdqu
13517 @@ -471,6 +472,7 @@ done_hash:
13518 popq %rbp
13519 popq %rbx
13520
13521 + pax_force_retaddr
13522 ret
13523 ENDPROC(sha256_transform_ssse3)
13524
13525 diff --git a/arch/x86/crypto/sha512-avx-asm.S b/arch/x86/crypto/sha512-avx-asm.S
13526 index 974dde9..a823ff9 100644
13527 --- a/arch/x86/crypto/sha512-avx-asm.S
13528 +++ b/arch/x86/crypto/sha512-avx-asm.S
13529 @@ -49,6 +49,7 @@
13530
13531 #ifdef CONFIG_AS_AVX
13532 #include <linux/linkage.h>
13533 +#include <asm/alternative-asm.h>
13534
13535 .text
13536
13537 @@ -364,6 +365,7 @@ updateblock:
13538 mov frame_RSPSAVE(%rsp), %rsp
13539
13540 nowork:
13541 + pax_force_retaddr
13542 ret
13543 ENDPROC(sha512_transform_avx)
13544
13545 diff --git a/arch/x86/crypto/sha512-avx2-asm.S b/arch/x86/crypto/sha512-avx2-asm.S
13546 index 568b961..ed20c37 100644
13547 --- a/arch/x86/crypto/sha512-avx2-asm.S
13548 +++ b/arch/x86/crypto/sha512-avx2-asm.S
13549 @@ -51,6 +51,7 @@
13550
13551 #ifdef CONFIG_AS_AVX2
13552 #include <linux/linkage.h>
13553 +#include <asm/alternative-asm.h>
13554
13555 .text
13556
13557 @@ -678,6 +679,7 @@ done_hash:
13558
13559 # Restore Stack Pointer
13560 mov frame_RSPSAVE(%rsp), %rsp
13561 + pax_force_retaddr
13562 ret
13563 ENDPROC(sha512_transform_rorx)
13564
13565 diff --git a/arch/x86/crypto/sha512-ssse3-asm.S b/arch/x86/crypto/sha512-ssse3-asm.S
13566 index fb56855..6edd768 100644
13567 --- a/arch/x86/crypto/sha512-ssse3-asm.S
13568 +++ b/arch/x86/crypto/sha512-ssse3-asm.S
13569 @@ -48,6 +48,7 @@
13570 ########################################################################
13571
13572 #include <linux/linkage.h>
13573 +#include <asm/alternative-asm.h>
13574
13575 .text
13576
13577 @@ -363,6 +364,7 @@ updateblock:
13578 mov frame_RSPSAVE(%rsp), %rsp
13579
13580 nowork:
13581 + pax_force_retaddr
13582 ret
13583 ENDPROC(sha512_transform_ssse3)
13584
13585 diff --git a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13586 index 0505813..b067311 100644
13587 --- a/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13588 +++ b/arch/x86/crypto/twofish-avx-x86_64-asm_64.S
13589 @@ -24,6 +24,7 @@
13590 */
13591
13592 #include <linux/linkage.h>
13593 +#include <asm/alternative-asm.h>
13594 #include "glue_helper-asm-avx.S"
13595
13596 .file "twofish-avx-x86_64-asm_64.S"
13597 @@ -284,6 +285,7 @@ __twofish_enc_blk8:
13598 outunpack_blocks(RC1, RD1, RA1, RB1, RK1, RX0, RY0, RK2);
13599 outunpack_blocks(RC2, RD2, RA2, RB2, RK1, RX0, RY0, RK2);
13600
13601 + pax_force_retaddr
13602 ret;
13603 ENDPROC(__twofish_enc_blk8)
13604
13605 @@ -324,6 +326,7 @@ __twofish_dec_blk8:
13606 outunpack_blocks(RA1, RB1, RC1, RD1, RK1, RX0, RY0, RK2);
13607 outunpack_blocks(RA2, RB2, RC2, RD2, RK1, RX0, RY0, RK2);
13608
13609 + pax_force_retaddr
13610 ret;
13611 ENDPROC(__twofish_dec_blk8)
13612
13613 @@ -342,6 +345,7 @@ ENTRY(twofish_ecb_enc_8way)
13614
13615 store_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13616
13617 + pax_force_retaddr
13618 ret;
13619 ENDPROC(twofish_ecb_enc_8way)
13620
13621 @@ -360,6 +364,7 @@ ENTRY(twofish_ecb_dec_8way)
13622
13623 store_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13624
13625 + pax_force_retaddr
13626 ret;
13627 ENDPROC(twofish_ecb_dec_8way)
13628
13629 @@ -370,19 +375,20 @@ ENTRY(twofish_cbc_dec_8way)
13630 * %rdx: src
13631 */
13632
13633 - pushq %r12;
13634 + pushq %r14;
13635
13636 movq %rsi, %r11;
13637 - movq %rdx, %r12;
13638 + movq %rdx, %r14;
13639
13640 load_8way(%rdx, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13641
13642 call __twofish_dec_blk8;
13643
13644 - store_cbc_8way(%r12, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13645 + store_cbc_8way(%r14, %r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13646
13647 - popq %r12;
13648 + popq %r14;
13649
13650 + pax_force_retaddr
13651 ret;
13652 ENDPROC(twofish_cbc_dec_8way)
13653
13654 @@ -394,20 +400,21 @@ ENTRY(twofish_ctr_8way)
13655 * %rcx: iv (little endian, 128bit)
13656 */
13657
13658 - pushq %r12;
13659 + pushq %r14;
13660
13661 movq %rsi, %r11;
13662 - movq %rdx, %r12;
13663 + movq %rdx, %r14;
13664
13665 load_ctr_8way(%rcx, .Lbswap128_mask, RA1, RB1, RC1, RD1, RA2, RB2, RC2,
13666 RD2, RX0, RX1, RY0);
13667
13668 call __twofish_enc_blk8;
13669
13670 - store_ctr_8way(%r12, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13671 + store_ctr_8way(%r14, %r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13672
13673 - popq %r12;
13674 + popq %r14;
13675
13676 + pax_force_retaddr
13677 ret;
13678 ENDPROC(twofish_ctr_8way)
13679
13680 @@ -430,6 +437,7 @@ ENTRY(twofish_xts_enc_8way)
13681 /* dst <= regs xor IVs(in dst) */
13682 store_xts_8way(%r11, RC1, RD1, RA1, RB1, RC2, RD2, RA2, RB2);
13683
13684 + pax_force_retaddr
13685 ret;
13686 ENDPROC(twofish_xts_enc_8way)
13687
13688 @@ -452,5 +460,6 @@ ENTRY(twofish_xts_dec_8way)
13689 /* dst <= regs xor IVs(in dst) */
13690 store_xts_8way(%r11, RA1, RB1, RC1, RD1, RA2, RB2, RC2, RD2);
13691
13692 + pax_force_retaddr
13693 ret;
13694 ENDPROC(twofish_xts_dec_8way)
13695 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13696 index 1c3b7ce..02f578d 100644
13697 --- a/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13698 +++ b/arch/x86/crypto/twofish-x86_64-asm_64-3way.S
13699 @@ -21,6 +21,7 @@
13700 */
13701
13702 #include <linux/linkage.h>
13703 +#include <asm/alternative-asm.h>
13704
13705 .file "twofish-x86_64-asm-3way.S"
13706 .text
13707 @@ -258,6 +259,7 @@ ENTRY(__twofish_enc_blk_3way)
13708 popq %r13;
13709 popq %r14;
13710 popq %r15;
13711 + pax_force_retaddr
13712 ret;
13713
13714 .L__enc_xor3:
13715 @@ -269,6 +271,7 @@ ENTRY(__twofish_enc_blk_3way)
13716 popq %r13;
13717 popq %r14;
13718 popq %r15;
13719 + pax_force_retaddr
13720 ret;
13721 ENDPROC(__twofish_enc_blk_3way)
13722
13723 @@ -308,5 +311,6 @@ ENTRY(twofish_dec_blk_3way)
13724 popq %r13;
13725 popq %r14;
13726 popq %r15;
13727 + pax_force_retaddr
13728 ret;
13729 ENDPROC(twofish_dec_blk_3way)
13730 diff --git a/arch/x86/crypto/twofish-x86_64-asm_64.S b/arch/x86/crypto/twofish-x86_64-asm_64.S
13731 index a039d21..524b8b2 100644
13732 --- a/arch/x86/crypto/twofish-x86_64-asm_64.S
13733 +++ b/arch/x86/crypto/twofish-x86_64-asm_64.S
13734 @@ -22,6 +22,7 @@
13735
13736 #include <linux/linkage.h>
13737 #include <asm/asm-offsets.h>
13738 +#include <asm/alternative-asm.h>
13739
13740 #define a_offset 0
13741 #define b_offset 4
13742 @@ -265,6 +266,7 @@ ENTRY(twofish_enc_blk)
13743
13744 popq R1
13745 movq $1,%rax
13746 + pax_force_retaddr
13747 ret
13748 ENDPROC(twofish_enc_blk)
13749
13750 @@ -317,5 +319,6 @@ ENTRY(twofish_dec_blk)
13751
13752 popq R1
13753 movq $1,%rax
13754 + pax_force_retaddr
13755 ret
13756 ENDPROC(twofish_dec_blk)
13757 diff --git a/arch/x86/ia32/ia32_aout.c b/arch/x86/ia32/ia32_aout.c
13758 index d21ff89..6da8e6e 100644
13759 --- a/arch/x86/ia32/ia32_aout.c
13760 +++ b/arch/x86/ia32/ia32_aout.c
13761 @@ -153,6 +153,8 @@ static int aout_core_dump(struct coredump_params *cprm)
13762 unsigned long dump_start, dump_size;
13763 struct user32 dump;
13764
13765 + memset(&dump, 0, sizeof(dump));
13766 +
13767 fs = get_fs();
13768 set_fs(KERNEL_DS);
13769 has_dumped = 1;
13770 diff --git a/arch/x86/ia32/ia32_signal.c b/arch/x86/ia32/ia32_signal.c
13771 index 2206757..85cbcfa 100644
13772 --- a/arch/x86/ia32/ia32_signal.c
13773 +++ b/arch/x86/ia32/ia32_signal.c
13774 @@ -218,7 +218,7 @@ asmlinkage long sys32_sigreturn(void)
13775 if (__get_user(set.sig[0], &frame->sc.oldmask)
13776 || (_COMPAT_NSIG_WORDS > 1
13777 && __copy_from_user((((char *) &set.sig) + 4),
13778 - &frame->extramask,
13779 + frame->extramask,
13780 sizeof(frame->extramask))))
13781 goto badframe;
13782
13783 @@ -338,7 +338,7 @@ static void __user *get_sigframe(struct ksignal *ksig, struct pt_regs *regs,
13784 sp -= frame_size;
13785 /* Align the stack pointer according to the i386 ABI,
13786 * i.e. so that on function entry ((sp + 4) & 15) == 0. */
13787 - sp = ((sp + 4) & -16ul) - 4;
13788 + sp = ((sp - 12) & -16ul) - 4;
13789 return (void __user *) sp;
13790 }
13791
13792 @@ -386,7 +386,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
13793 restorer = VDSO32_SYMBOL(current->mm->context.vdso,
13794 sigreturn);
13795 else
13796 - restorer = &frame->retcode;
13797 + restorer = frame->retcode;
13798 }
13799
13800 put_user_try {
13801 @@ -396,7 +396,7 @@ int ia32_setup_frame(int sig, struct ksignal *ksig,
13802 * These are actually not used anymore, but left because some
13803 * gdb versions depend on them as a marker.
13804 */
13805 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13806 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13807 } put_user_catch(err);
13808
13809 if (err)
13810 @@ -438,7 +438,7 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13811 0xb8,
13812 __NR_ia32_rt_sigreturn,
13813 0x80cd,
13814 - 0,
13815 + 0
13816 };
13817
13818 frame = get_sigframe(ksig, regs, sizeof(*frame), &fpstate);
13819 @@ -461,16 +461,18 @@ int ia32_setup_rt_frame(int sig, struct ksignal *ksig,
13820
13821 if (ksig->ka.sa.sa_flags & SA_RESTORER)
13822 restorer = ksig->ka.sa.sa_restorer;
13823 + else if (current->mm->context.vdso)
13824 + /* Return stub is in 32bit vsyscall page */
13825 + restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
13826 else
13827 - restorer = VDSO32_SYMBOL(current->mm->context.vdso,
13828 - rt_sigreturn);
13829 + restorer = frame->retcode;
13830 put_user_ex(ptr_to_compat(restorer), &frame->pretcode);
13831
13832 /*
13833 * Not actually used anymore, but left because some gdb
13834 * versions need it.
13835 */
13836 - put_user_ex(*((u64 *)&code), (u64 __user *)frame->retcode);
13837 + put_user_ex(*((const u64 *)&code), (u64 __user *)frame->retcode);
13838 } put_user_catch(err);
13839
13840 err |= copy_siginfo_to_user32(&frame->info, &ksig->info);
13841 diff --git a/arch/x86/ia32/ia32entry.S b/arch/x86/ia32/ia32entry.S
13842 index 4299eb0..c0687a7 100644
13843 --- a/arch/x86/ia32/ia32entry.S
13844 +++ b/arch/x86/ia32/ia32entry.S
13845 @@ -15,8 +15,10 @@
13846 #include <asm/irqflags.h>
13847 #include <asm/asm.h>
13848 #include <asm/smap.h>
13849 +#include <asm/pgtable.h>
13850 #include <linux/linkage.h>
13851 #include <linux/err.h>
13852 +#include <asm/alternative-asm.h>
13853
13854 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
13855 #include <linux/elf-em.h>
13856 @@ -62,12 +64,12 @@
13857 */
13858 .macro LOAD_ARGS32 offset, _r9=0
13859 .if \_r9
13860 - movl \offset+16(%rsp),%r9d
13861 + movl \offset+R9(%rsp),%r9d
13862 .endif
13863 - movl \offset+40(%rsp),%ecx
13864 - movl \offset+48(%rsp),%edx
13865 - movl \offset+56(%rsp),%esi
13866 - movl \offset+64(%rsp),%edi
13867 + movl \offset+RCX(%rsp),%ecx
13868 + movl \offset+RDX(%rsp),%edx
13869 + movl \offset+RSI(%rsp),%esi
13870 + movl \offset+RDI(%rsp),%edi
13871 movl %eax,%eax /* zero extension */
13872 .endm
13873
13874 @@ -96,6 +98,32 @@ ENTRY(native_irq_enable_sysexit)
13875 ENDPROC(native_irq_enable_sysexit)
13876 #endif
13877
13878 + .macro pax_enter_kernel_user
13879 + pax_set_fptr_mask
13880 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13881 + call pax_enter_kernel_user
13882 +#endif
13883 + .endm
13884 +
13885 + .macro pax_exit_kernel_user
13886 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13887 + call pax_exit_kernel_user
13888 +#endif
13889 +#ifdef CONFIG_PAX_RANDKSTACK
13890 + pushq %rax
13891 + pushq %r11
13892 + call pax_randomize_kstack
13893 + popq %r11
13894 + popq %rax
13895 +#endif
13896 + .endm
13897 +
13898 + .macro pax_erase_kstack
13899 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
13900 + call pax_erase_kstack
13901 +#endif
13902 + .endm
13903 +
13904 /*
13905 * 32bit SYSENTER instruction entry.
13906 *
13907 @@ -122,12 +150,6 @@ ENTRY(ia32_sysenter_target)
13908 CFI_REGISTER rsp,rbp
13909 SWAPGS_UNSAFE_STACK
13910 movq PER_CPU_VAR(kernel_stack), %rsp
13911 - addq $(KERNEL_STACK_OFFSET),%rsp
13912 - /*
13913 - * No need to follow this irqs on/off section: the syscall
13914 - * disabled irqs, here we enable it straight after entry:
13915 - */
13916 - ENABLE_INTERRUPTS(CLBR_NONE)
13917 movl %ebp,%ebp /* zero extension */
13918 pushq_cfi $__USER32_DS
13919 /*CFI_REL_OFFSET ss,0*/
13920 @@ -135,24 +157,49 @@ ENTRY(ia32_sysenter_target)
13921 CFI_REL_OFFSET rsp,0
13922 pushfq_cfi
13923 /*CFI_REL_OFFSET rflags,0*/
13924 - movl TI_sysenter_return+THREAD_INFO(%rsp,3*8-KERNEL_STACK_OFFSET),%r10d
13925 - CFI_REGISTER rip,r10
13926 + orl $X86_EFLAGS_IF,(%rsp)
13927 + GET_THREAD_INFO(%r11)
13928 + movl TI_sysenter_return(%r11), %r11d
13929 + CFI_REGISTER rip,r11
13930 pushq_cfi $__USER32_CS
13931 /*CFI_REL_OFFSET cs,0*/
13932 movl %eax, %eax
13933 - pushq_cfi %r10
13934 + pushq_cfi %r11
13935 CFI_REL_OFFSET rip,0
13936 pushq_cfi %rax
13937 cld
13938 SAVE_ARGS 0,1,0
13939 + pax_enter_kernel_user
13940 +
13941 +#ifdef CONFIG_PAX_RANDKSTACK
13942 + pax_erase_kstack
13943 +#endif
13944 +
13945 + /*
13946 + * No need to follow this irqs on/off section: the syscall
13947 + * disabled irqs, here we enable it straight after entry:
13948 + */
13949 + ENABLE_INTERRUPTS(CLBR_NONE)
13950 /* no need to do an access_ok check here because rbp has been
13951 32bit zero extended */
13952 +
13953 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13954 + addq pax_user_shadow_base,%rbp
13955 + ASM_PAX_OPEN_USERLAND
13956 +#endif
13957 +
13958 ASM_STAC
13959 1: movl (%rbp),%ebp
13960 _ASM_EXTABLE(1b,ia32_badarg)
13961 ASM_CLAC
13962 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13963 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13964 +
13965 +#ifdef CONFIG_PAX_MEMORY_UDEREF
13966 + ASM_PAX_CLOSE_USERLAND
13967 +#endif
13968 +
13969 + GET_THREAD_INFO(%r11)
13970 + orl $TS_COMPAT,TI_status(%r11)
13971 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
13972 CFI_REMEMBER_STATE
13973 jnz sysenter_tracesys
13974 cmpq $(IA32_NR_syscalls-1),%rax
13975 @@ -162,15 +209,18 @@ sysenter_do_call:
13976 sysenter_dispatch:
13977 call *ia32_sys_call_table(,%rax,8)
13978 movq %rax,RAX-ARGOFFSET(%rsp)
13979 + GET_THREAD_INFO(%r11)
13980 DISABLE_INTERRUPTS(CLBR_NONE)
13981 TRACE_IRQS_OFF
13982 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13983 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
13984 jnz sysexit_audit
13985 sysexit_from_sys_call:
13986 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
13987 + pax_exit_kernel_user
13988 + pax_erase_kstack
13989 + andl $~TS_COMPAT,TI_status(%r11)
13990 /* clear IF, that popfq doesn't enable interrupts early */
13991 - andl $~0x200,EFLAGS-R11(%rsp)
13992 - movl RIP-R11(%rsp),%edx /* User %eip */
13993 + andl $~X86_EFLAGS_IF,EFLAGS(%rsp)
13994 + movl RIP(%rsp),%edx /* User %eip */
13995 CFI_REGISTER rip,rdx
13996 RESTORE_ARGS 0,24,0,0,0,0
13997 xorq %r8,%r8
13998 @@ -193,6 +243,9 @@ sysexit_from_sys_call:
13999 movl %eax,%esi /* 2nd arg: syscall number */
14000 movl $AUDIT_ARCH_I386,%edi /* 1st arg: audit arch */
14001 call __audit_syscall_entry
14002 +
14003 + pax_erase_kstack
14004 +
14005 movl RAX-ARGOFFSET(%rsp),%eax /* reload syscall number */
14006 cmpq $(IA32_NR_syscalls-1),%rax
14007 ja ia32_badsys
14008 @@ -204,7 +257,7 @@ sysexit_from_sys_call:
14009 .endm
14010
14011 .macro auditsys_exit exit
14012 - testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14013 + testl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14014 jnz ia32_ret_from_sys_call
14015 TRACE_IRQS_ON
14016 ENABLE_INTERRUPTS(CLBR_NONE)
14017 @@ -215,11 +268,12 @@ sysexit_from_sys_call:
14018 1: setbe %al /* 1 if error, 0 if not */
14019 movzbl %al,%edi /* zero-extend that into %edi */
14020 call __audit_syscall_exit
14021 + GET_THREAD_INFO(%r11)
14022 movq RAX-ARGOFFSET(%rsp),%rax /* reload syscall return value */
14023 movl $(_TIF_ALLWORK_MASK & ~_TIF_SYSCALL_AUDIT),%edi
14024 DISABLE_INTERRUPTS(CLBR_NONE)
14025 TRACE_IRQS_OFF
14026 - testl %edi,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14027 + testl %edi,TI_flags(%r11)
14028 jz \exit
14029 CLEAR_RREGS -ARGOFFSET
14030 jmp int_with_check
14031 @@ -237,7 +291,7 @@ sysexit_audit:
14032
14033 sysenter_tracesys:
14034 #ifdef CONFIG_AUDITSYSCALL
14035 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14036 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14037 jz sysenter_auditsys
14038 #endif
14039 SAVE_REST
14040 @@ -249,6 +303,9 @@ sysenter_tracesys:
14041 RESTORE_REST
14042 cmpq $(IA32_NR_syscalls-1),%rax
14043 ja int_ret_from_sys_call /* sysenter_tracesys has set RAX(%rsp) */
14044 +
14045 + pax_erase_kstack
14046 +
14047 jmp sysenter_do_call
14048 CFI_ENDPROC
14049 ENDPROC(ia32_sysenter_target)
14050 @@ -276,19 +333,25 @@ ENDPROC(ia32_sysenter_target)
14051 ENTRY(ia32_cstar_target)
14052 CFI_STARTPROC32 simple
14053 CFI_SIGNAL_FRAME
14054 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
14055 + CFI_DEF_CFA rsp,0
14056 CFI_REGISTER rip,rcx
14057 /*CFI_REGISTER rflags,r11*/
14058 SWAPGS_UNSAFE_STACK
14059 movl %esp,%r8d
14060 CFI_REGISTER rsp,r8
14061 movq PER_CPU_VAR(kernel_stack),%rsp
14062 + SAVE_ARGS 8*6,0,0
14063 + pax_enter_kernel_user
14064 +
14065 +#ifdef CONFIG_PAX_RANDKSTACK
14066 + pax_erase_kstack
14067 +#endif
14068 +
14069 /*
14070 * No need to follow this irqs on/off section: the syscall
14071 * disabled irqs and here we enable it straight after entry:
14072 */
14073 ENABLE_INTERRUPTS(CLBR_NONE)
14074 - SAVE_ARGS 8,0,0
14075 movl %eax,%eax /* zero extension */
14076 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
14077 movq %rcx,RIP-ARGOFFSET(%rsp)
14078 @@ -304,12 +367,25 @@ ENTRY(ia32_cstar_target)
14079 /* no need to do an access_ok check here because r8 has been
14080 32bit zero extended */
14081 /* hardware stack frame is complete now */
14082 +
14083 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14084 + ASM_PAX_OPEN_USERLAND
14085 + movq pax_user_shadow_base,%r8
14086 + addq RSP-ARGOFFSET(%rsp),%r8
14087 +#endif
14088 +
14089 ASM_STAC
14090 1: movl (%r8),%r9d
14091 _ASM_EXTABLE(1b,ia32_badarg)
14092 ASM_CLAC
14093 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14094 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14095 +
14096 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14097 + ASM_PAX_CLOSE_USERLAND
14098 +#endif
14099 +
14100 + GET_THREAD_INFO(%r11)
14101 + orl $TS_COMPAT,TI_status(%r11)
14102 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14103 CFI_REMEMBER_STATE
14104 jnz cstar_tracesys
14105 cmpq $IA32_NR_syscalls-1,%rax
14106 @@ -319,13 +395,16 @@ cstar_do_call:
14107 cstar_dispatch:
14108 call *ia32_sys_call_table(,%rax,8)
14109 movq %rax,RAX-ARGOFFSET(%rsp)
14110 + GET_THREAD_INFO(%r11)
14111 DISABLE_INTERRUPTS(CLBR_NONE)
14112 TRACE_IRQS_OFF
14113 - testl $_TIF_ALLWORK_MASK,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14114 + testl $_TIF_ALLWORK_MASK,TI_flags(%r11)
14115 jnz sysretl_audit
14116 sysretl_from_sys_call:
14117 - andl $~TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14118 - RESTORE_ARGS 0,-ARG_SKIP,0,0,0
14119 + pax_exit_kernel_user
14120 + pax_erase_kstack
14121 + andl $~TS_COMPAT,TI_status(%r11)
14122 + RESTORE_ARGS 0,-ORIG_RAX,0,0,0
14123 movl RIP-ARGOFFSET(%rsp),%ecx
14124 CFI_REGISTER rip,rcx
14125 movl EFLAGS-ARGOFFSET(%rsp),%r11d
14126 @@ -352,7 +431,7 @@ sysretl_audit:
14127
14128 cstar_tracesys:
14129 #ifdef CONFIG_AUDITSYSCALL
14130 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14131 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%r11)
14132 jz cstar_auditsys
14133 #endif
14134 xchgl %r9d,%ebp
14135 @@ -366,11 +445,19 @@ cstar_tracesys:
14136 xchgl %ebp,%r9d
14137 cmpq $(IA32_NR_syscalls-1),%rax
14138 ja int_ret_from_sys_call /* cstar_tracesys has set RAX(%rsp) */
14139 +
14140 + pax_erase_kstack
14141 +
14142 jmp cstar_do_call
14143 END(ia32_cstar_target)
14144
14145 ia32_badarg:
14146 ASM_CLAC
14147 +
14148 +#ifdef CONFIG_PAX_MEMORY_UDEREF
14149 + ASM_PAX_CLOSE_USERLAND
14150 +#endif
14151 +
14152 movq $-EFAULT,%rax
14153 jmp ia32_sysret
14154 CFI_ENDPROC
14155 @@ -407,19 +494,26 @@ ENTRY(ia32_syscall)
14156 CFI_REL_OFFSET rip,RIP-RIP
14157 PARAVIRT_ADJUST_EXCEPTION_FRAME
14158 SWAPGS
14159 - /*
14160 - * No need to follow this irqs on/off section: the syscall
14161 - * disabled irqs and here we enable it straight after entry:
14162 - */
14163 - ENABLE_INTERRUPTS(CLBR_NONE)
14164 movl %eax,%eax
14165 pushq_cfi %rax
14166 cld
14167 /* note the registers are not zero extended to the sf.
14168 this could be a problem. */
14169 SAVE_ARGS 0,1,0
14170 - orl $TS_COMPAT,TI_status+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14171 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
14172 + pax_enter_kernel_user
14173 +
14174 +#ifdef CONFIG_PAX_RANDKSTACK
14175 + pax_erase_kstack
14176 +#endif
14177 +
14178 + /*
14179 + * No need to follow this irqs on/off section: the syscall
14180 + * disabled irqs and here we enable it straight after entry:
14181 + */
14182 + ENABLE_INTERRUPTS(CLBR_NONE)
14183 + GET_THREAD_INFO(%r11)
14184 + orl $TS_COMPAT,TI_status(%r11)
14185 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%r11)
14186 jnz ia32_tracesys
14187 cmpq $(IA32_NR_syscalls-1),%rax
14188 ja ia32_badsys
14189 @@ -442,6 +536,9 @@ ia32_tracesys:
14190 RESTORE_REST
14191 cmpq $(IA32_NR_syscalls-1),%rax
14192 ja int_ret_from_sys_call /* ia32_tracesys has set RAX(%rsp) */
14193 +
14194 + pax_erase_kstack
14195 +
14196 jmp ia32_do_call
14197 END(ia32_syscall)
14198
14199 diff --git a/arch/x86/ia32/sys_ia32.c b/arch/x86/ia32/sys_ia32.c
14200 index 8e0ceec..af13504 100644
14201 --- a/arch/x86/ia32/sys_ia32.c
14202 +++ b/arch/x86/ia32/sys_ia32.c
14203 @@ -69,8 +69,8 @@ asmlinkage long sys32_ftruncate64(unsigned int fd, unsigned long offset_low,
14204 */
14205 static int cp_stat64(struct stat64 __user *ubuf, struct kstat *stat)
14206 {
14207 - typeof(ubuf->st_uid) uid = 0;
14208 - typeof(ubuf->st_gid) gid = 0;
14209 + typeof(((struct stat64 *)0)->st_uid) uid = 0;
14210 + typeof(((struct stat64 *)0)->st_gid) gid = 0;
14211 SET_UID(uid, from_kuid_munged(current_user_ns(), stat->uid));
14212 SET_GID(gid, from_kgid_munged(current_user_ns(), stat->gid));
14213 if (!access_ok(VERIFY_WRITE, ubuf, sizeof(struct stat64)) ||
14214 diff --git a/arch/x86/include/asm/alternative-asm.h b/arch/x86/include/asm/alternative-asm.h
14215 index 372231c..51b537d 100644
14216 --- a/arch/x86/include/asm/alternative-asm.h
14217 +++ b/arch/x86/include/asm/alternative-asm.h
14218 @@ -18,6 +18,45 @@
14219 .endm
14220 #endif
14221
14222 +#ifdef KERNEXEC_PLUGIN
14223 + .macro pax_force_retaddr_bts rip=0
14224 + btsq $63,\rip(%rsp)
14225 + .endm
14226 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
14227 + .macro pax_force_retaddr rip=0, reload=0
14228 + btsq $63,\rip(%rsp)
14229 + .endm
14230 + .macro pax_force_fptr ptr
14231 + btsq $63,\ptr
14232 + .endm
14233 + .macro pax_set_fptr_mask
14234 + .endm
14235 +#endif
14236 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
14237 + .macro pax_force_retaddr rip=0, reload=0
14238 + .if \reload
14239 + pax_set_fptr_mask
14240 + .endif
14241 + orq %r12,\rip(%rsp)
14242 + .endm
14243 + .macro pax_force_fptr ptr
14244 + orq %r12,\ptr
14245 + .endm
14246 + .macro pax_set_fptr_mask
14247 + movabs $0x8000000000000000,%r12
14248 + .endm
14249 +#endif
14250 +#else
14251 + .macro pax_force_retaddr rip=0, reload=0
14252 + .endm
14253 + .macro pax_force_fptr ptr
14254 + .endm
14255 + .macro pax_force_retaddr_bts rip=0
14256 + .endm
14257 + .macro pax_set_fptr_mask
14258 + .endm
14259 +#endif
14260 +
14261 .macro altinstruction_entry orig alt feature orig_len alt_len
14262 .long \orig - .
14263 .long \alt - .
14264 diff --git a/arch/x86/include/asm/alternative.h b/arch/x86/include/asm/alternative.h
14265 index 0a3f9c9..c9d081d 100644
14266 --- a/arch/x86/include/asm/alternative.h
14267 +++ b/arch/x86/include/asm/alternative.h
14268 @@ -106,7 +106,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14269 ".pushsection .discard,\"aw\",@progbits\n" \
14270 DISCARD_ENTRY(1) \
14271 ".popsection\n" \
14272 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14273 + ".pushsection .altinstr_replacement, \"a\"\n" \
14274 ALTINSTR_REPLACEMENT(newinstr, feature, 1) \
14275 ".popsection"
14276
14277 @@ -120,7 +120,7 @@ static inline int alternatives_text_reserved(void *start, void *end)
14278 DISCARD_ENTRY(1) \
14279 DISCARD_ENTRY(2) \
14280 ".popsection\n" \
14281 - ".pushsection .altinstr_replacement, \"ax\"\n" \
14282 + ".pushsection .altinstr_replacement, \"a\"\n" \
14283 ALTINSTR_REPLACEMENT(newinstr1, feature1, 1) \
14284 ALTINSTR_REPLACEMENT(newinstr2, feature2, 2) \
14285 ".popsection"
14286 diff --git a/arch/x86/include/asm/apic.h b/arch/x86/include/asm/apic.h
14287 index 1d2091a..f5074c1 100644
14288 --- a/arch/x86/include/asm/apic.h
14289 +++ b/arch/x86/include/asm/apic.h
14290 @@ -45,7 +45,7 @@ static inline void generic_apic_probe(void)
14291
14292 #ifdef CONFIG_X86_LOCAL_APIC
14293
14294 -extern unsigned int apic_verbosity;
14295 +extern int apic_verbosity;
14296 extern int local_apic_timer_c2_ok;
14297
14298 extern int disable_apic;
14299 diff --git a/arch/x86/include/asm/apm.h b/arch/x86/include/asm/apm.h
14300 index 20370c6..a2eb9b0 100644
14301 --- a/arch/x86/include/asm/apm.h
14302 +++ b/arch/x86/include/asm/apm.h
14303 @@ -34,7 +34,7 @@ static inline void apm_bios_call_asm(u32 func, u32 ebx_in, u32 ecx_in,
14304 __asm__ __volatile__(APM_DO_ZERO_SEGS
14305 "pushl %%edi\n\t"
14306 "pushl %%ebp\n\t"
14307 - "lcall *%%cs:apm_bios_entry\n\t"
14308 + "lcall *%%ss:apm_bios_entry\n\t"
14309 "setc %%al\n\t"
14310 "popl %%ebp\n\t"
14311 "popl %%edi\n\t"
14312 @@ -58,7 +58,7 @@ static inline u8 apm_bios_call_simple_asm(u32 func, u32 ebx_in,
14313 __asm__ __volatile__(APM_DO_ZERO_SEGS
14314 "pushl %%edi\n\t"
14315 "pushl %%ebp\n\t"
14316 - "lcall *%%cs:apm_bios_entry\n\t"
14317 + "lcall *%%ss:apm_bios_entry\n\t"
14318 "setc %%bl\n\t"
14319 "popl %%ebp\n\t"
14320 "popl %%edi\n\t"
14321 diff --git a/arch/x86/include/asm/atomic.h b/arch/x86/include/asm/atomic.h
14322 index b17f4f4..9620151 100644
14323 --- a/arch/x86/include/asm/atomic.h
14324 +++ b/arch/x86/include/asm/atomic.h
14325 @@ -23,7 +23,18 @@
14326 */
14327 static inline int atomic_read(const atomic_t *v)
14328 {
14329 - return (*(volatile int *)&(v)->counter);
14330 + return (*(volatile const int *)&(v)->counter);
14331 +}
14332 +
14333 +/**
14334 + * atomic_read_unchecked - read atomic variable
14335 + * @v: pointer of type atomic_unchecked_t
14336 + *
14337 + * Atomically reads the value of @v.
14338 + */
14339 +static inline int __intentional_overflow(-1) atomic_read_unchecked(const atomic_unchecked_t *v)
14340 +{
14341 + return (*(volatile const int *)&(v)->counter);
14342 }
14343
14344 /**
14345 @@ -39,6 +50,18 @@ static inline void atomic_set(atomic_t *v, int i)
14346 }
14347
14348 /**
14349 + * atomic_set_unchecked - set atomic variable
14350 + * @v: pointer of type atomic_unchecked_t
14351 + * @i: required value
14352 + *
14353 + * Atomically sets the value of @v to @i.
14354 + */
14355 +static inline void atomic_set_unchecked(atomic_unchecked_t *v, int i)
14356 +{
14357 + v->counter = i;
14358 +}
14359 +
14360 +/**
14361 * atomic_add - add integer to atomic variable
14362 * @i: integer value to add
14363 * @v: pointer of type atomic_t
14364 @@ -47,7 +70,29 @@ static inline void atomic_set(atomic_t *v, int i)
14365 */
14366 static inline void atomic_add(int i, atomic_t *v)
14367 {
14368 - asm volatile(LOCK_PREFIX "addl %1,%0"
14369 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14370 +
14371 +#ifdef CONFIG_PAX_REFCOUNT
14372 + "jno 0f\n"
14373 + LOCK_PREFIX "subl %1,%0\n"
14374 + "int $4\n0:\n"
14375 + _ASM_EXTABLE(0b, 0b)
14376 +#endif
14377 +
14378 + : "+m" (v->counter)
14379 + : "ir" (i));
14380 +}
14381 +
14382 +/**
14383 + * atomic_add_unchecked - add integer to atomic variable
14384 + * @i: integer value to add
14385 + * @v: pointer of type atomic_unchecked_t
14386 + *
14387 + * Atomically adds @i to @v.
14388 + */
14389 +static inline void atomic_add_unchecked(int i, atomic_unchecked_t *v)
14390 +{
14391 + asm volatile(LOCK_PREFIX "addl %1,%0\n"
14392 : "+m" (v->counter)
14393 : "ir" (i));
14394 }
14395 @@ -61,7 +106,29 @@ static inline void atomic_add(int i, atomic_t *v)
14396 */
14397 static inline void atomic_sub(int i, atomic_t *v)
14398 {
14399 - asm volatile(LOCK_PREFIX "subl %1,%0"
14400 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
14401 +
14402 +#ifdef CONFIG_PAX_REFCOUNT
14403 + "jno 0f\n"
14404 + LOCK_PREFIX "addl %1,%0\n"
14405 + "int $4\n0:\n"
14406 + _ASM_EXTABLE(0b, 0b)
14407 +#endif
14408 +
14409 + : "+m" (v->counter)
14410 + : "ir" (i));
14411 +}
14412 +
14413 +/**
14414 + * atomic_sub_unchecked - subtract integer from atomic variable
14415 + * @i: integer value to subtract
14416 + * @v: pointer of type atomic_unchecked_t
14417 + *
14418 + * Atomically subtracts @i from @v.
14419 + */
14420 +static inline void atomic_sub_unchecked(int i, atomic_unchecked_t *v)
14421 +{
14422 + asm volatile(LOCK_PREFIX "subl %1,%0\n"
14423 : "+m" (v->counter)
14424 : "ir" (i));
14425 }
14426 @@ -77,7 +144,7 @@ static inline void atomic_sub(int i, atomic_t *v)
14427 */
14428 static inline int atomic_sub_and_test(int i, atomic_t *v)
14429 {
14430 - GEN_BINARY_RMWcc(LOCK_PREFIX "subl", v->counter, "er", i, "%0", "e");
14431 + GEN_BINARY_RMWcc(LOCK_PREFIX "subl", LOCK_PREFIX "addl", v->counter, "er", i, "%0", "e");
14432 }
14433
14434 /**
14435 @@ -88,7 +155,27 @@ static inline int atomic_sub_and_test(int i, atomic_t *v)
14436 */
14437 static inline void atomic_inc(atomic_t *v)
14438 {
14439 - asm volatile(LOCK_PREFIX "incl %0"
14440 + asm volatile(LOCK_PREFIX "incl %0\n"
14441 +
14442 +#ifdef CONFIG_PAX_REFCOUNT
14443 + "jno 0f\n"
14444 + LOCK_PREFIX "decl %0\n"
14445 + "int $4\n0:\n"
14446 + _ASM_EXTABLE(0b, 0b)
14447 +#endif
14448 +
14449 + : "+m" (v->counter));
14450 +}
14451 +
14452 +/**
14453 + * atomic_inc_unchecked - increment atomic variable
14454 + * @v: pointer of type atomic_unchecked_t
14455 + *
14456 + * Atomically increments @v by 1.
14457 + */
14458 +static inline void atomic_inc_unchecked(atomic_unchecked_t *v)
14459 +{
14460 + asm volatile(LOCK_PREFIX "incl %0\n"
14461 : "+m" (v->counter));
14462 }
14463
14464 @@ -100,7 +187,27 @@ static inline void atomic_inc(atomic_t *v)
14465 */
14466 static inline void atomic_dec(atomic_t *v)
14467 {
14468 - asm volatile(LOCK_PREFIX "decl %0"
14469 + asm volatile(LOCK_PREFIX "decl %0\n"
14470 +
14471 +#ifdef CONFIG_PAX_REFCOUNT
14472 + "jno 0f\n"
14473 + LOCK_PREFIX "incl %0\n"
14474 + "int $4\n0:\n"
14475 + _ASM_EXTABLE(0b, 0b)
14476 +#endif
14477 +
14478 + : "+m" (v->counter));
14479 +}
14480 +
14481 +/**
14482 + * atomic_dec_unchecked - decrement atomic variable
14483 + * @v: pointer of type atomic_unchecked_t
14484 + *
14485 + * Atomically decrements @v by 1.
14486 + */
14487 +static inline void atomic_dec_unchecked(atomic_unchecked_t *v)
14488 +{
14489 + asm volatile(LOCK_PREFIX "decl %0\n"
14490 : "+m" (v->counter));
14491 }
14492
14493 @@ -114,7 +221,7 @@ static inline void atomic_dec(atomic_t *v)
14494 */
14495 static inline int atomic_dec_and_test(atomic_t *v)
14496 {
14497 - GEN_UNARY_RMWcc(LOCK_PREFIX "decl", v->counter, "%0", "e");
14498 + GEN_UNARY_RMWcc(LOCK_PREFIX "decl", LOCK_PREFIX "incl", v->counter, "%0", "e");
14499 }
14500
14501 /**
14502 @@ -127,7 +234,20 @@ static inline int atomic_dec_and_test(atomic_t *v)
14503 */
14504 static inline int atomic_inc_and_test(atomic_t *v)
14505 {
14506 - GEN_UNARY_RMWcc(LOCK_PREFIX "incl", v->counter, "%0", "e");
14507 + GEN_UNARY_RMWcc(LOCK_PREFIX "incl", LOCK_PREFIX "decl", v->counter, "%0", "e");
14508 +}
14509 +
14510 +/**
14511 + * atomic_inc_and_test_unchecked - increment and test
14512 + * @v: pointer of type atomic_unchecked_t
14513 + *
14514 + * Atomically increments @v by 1
14515 + * and returns true if the result is zero, or false for all
14516 + * other cases.
14517 + */
14518 +static inline int atomic_inc_and_test_unchecked(atomic_unchecked_t *v)
14519 +{
14520 + GEN_UNARY_RMWcc_unchecked(LOCK_PREFIX "incl", v->counter, "%0", "e");
14521 }
14522
14523 /**
14524 @@ -141,7 +261,7 @@ static inline int atomic_inc_and_test(atomic_t *v)
14525 */
14526 static inline int atomic_add_negative(int i, atomic_t *v)
14527 {
14528 - GEN_BINARY_RMWcc(LOCK_PREFIX "addl", v->counter, "er", i, "%0", "s");
14529 + GEN_BINARY_RMWcc(LOCK_PREFIX "addl", LOCK_PREFIX "subl", v->counter, "er", i, "%0", "s");
14530 }
14531
14532 /**
14533 @@ -153,6 +273,18 @@ static inline int atomic_add_negative(int i, atomic_t *v)
14534 */
14535 static inline int atomic_add_return(int i, atomic_t *v)
14536 {
14537 + return i + xadd_check_overflow(&v->counter, i);
14538 +}
14539 +
14540 +/**
14541 + * atomic_add_return_unchecked - add integer and return
14542 + * @i: integer value to add
14543 + * @v: pointer of type atomic_unchecked_t
14544 + *
14545 + * Atomically adds @i to @v and returns @i + @v
14546 + */
14547 +static inline int atomic_add_return_unchecked(int i, atomic_unchecked_t *v)
14548 +{
14549 return i + xadd(&v->counter, i);
14550 }
14551
14552 @@ -169,9 +301,18 @@ static inline int atomic_sub_return(int i, atomic_t *v)
14553 }
14554
14555 #define atomic_inc_return(v) (atomic_add_return(1, v))
14556 +static inline int atomic_inc_return_unchecked(atomic_unchecked_t *v)
14557 +{
14558 + return atomic_add_return_unchecked(1, v);
14559 +}
14560 #define atomic_dec_return(v) (atomic_sub_return(1, v))
14561
14562 -static inline int atomic_cmpxchg(atomic_t *v, int old, int new)
14563 +static inline int __intentional_overflow(-1) atomic_cmpxchg(atomic_t *v, int old, int new)
14564 +{
14565 + return cmpxchg(&v->counter, old, new);
14566 +}
14567 +
14568 +static inline int atomic_cmpxchg_unchecked(atomic_unchecked_t *v, int old, int new)
14569 {
14570 return cmpxchg(&v->counter, old, new);
14571 }
14572 @@ -181,6 +322,11 @@ static inline int atomic_xchg(atomic_t *v, int new)
14573 return xchg(&v->counter, new);
14574 }
14575
14576 +static inline int atomic_xchg_unchecked(atomic_unchecked_t *v, int new)
14577 +{
14578 + return xchg(&v->counter, new);
14579 +}
14580 +
14581 /**
14582 * __atomic_add_unless - add unless the number is already a given value
14583 * @v: pointer of type atomic_t
14584 @@ -190,14 +336,27 @@ static inline int atomic_xchg(atomic_t *v, int new)
14585 * Atomically adds @a to @v, so long as @v was not already @u.
14586 * Returns the old value of @v.
14587 */
14588 -static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14589 +static inline int __intentional_overflow(-1) __atomic_add_unless(atomic_t *v, int a, int u)
14590 {
14591 - int c, old;
14592 + int c, old, new;
14593 c = atomic_read(v);
14594 for (;;) {
14595 - if (unlikely(c == (u)))
14596 + if (unlikely(c == u))
14597 break;
14598 - old = atomic_cmpxchg((v), c, c + (a));
14599 +
14600 + asm volatile("addl %2,%0\n"
14601 +
14602 +#ifdef CONFIG_PAX_REFCOUNT
14603 + "jno 0f\n"
14604 + "subl %2,%0\n"
14605 + "int $4\n0:\n"
14606 + _ASM_EXTABLE(0b, 0b)
14607 +#endif
14608 +
14609 + : "=r" (new)
14610 + : "0" (c), "ir" (a));
14611 +
14612 + old = atomic_cmpxchg(v, c, new);
14613 if (likely(old == c))
14614 break;
14615 c = old;
14616 @@ -206,6 +365,49 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
14617 }
14618
14619 /**
14620 + * atomic_inc_not_zero_hint - increment if not null
14621 + * @v: pointer of type atomic_t
14622 + * @hint: probable value of the atomic before the increment
14623 + *
14624 + * This version of atomic_inc_not_zero() gives a hint of probable
14625 + * value of the atomic. This helps processor to not read the memory
14626 + * before doing the atomic read/modify/write cycle, lowering
14627 + * number of bus transactions on some arches.
14628 + *
14629 + * Returns: 0 if increment was not done, 1 otherwise.
14630 + */
14631 +#define atomic_inc_not_zero_hint atomic_inc_not_zero_hint
14632 +static inline int atomic_inc_not_zero_hint(atomic_t *v, int hint)
14633 +{
14634 + int val, c = hint, new;
14635 +
14636 + /* sanity test, should be removed by compiler if hint is a constant */
14637 + if (!hint)
14638 + return __atomic_add_unless(v, 1, 0);
14639 +
14640 + do {
14641 + asm volatile("incl %0\n"
14642 +
14643 +#ifdef CONFIG_PAX_REFCOUNT
14644 + "jno 0f\n"
14645 + "decl %0\n"
14646 + "int $4\n0:\n"
14647 + _ASM_EXTABLE(0b, 0b)
14648 +#endif
14649 +
14650 + : "=r" (new)
14651 + : "0" (c));
14652 +
14653 + val = atomic_cmpxchg(v, c, new);
14654 + if (val == c)
14655 + return 1;
14656 + c = val;
14657 + } while (c);
14658 +
14659 + return 0;
14660 +}
14661 +
14662 +/**
14663 * atomic_inc_short - increment of a short integer
14664 * @v: pointer to type int
14665 *
14666 @@ -234,14 +436,37 @@ static inline void atomic_or_long(unsigned long *v1, unsigned long v2)
14667 #endif
14668
14669 /* These are x86-specific, used by some header files */
14670 -#define atomic_clear_mask(mask, addr) \
14671 - asm volatile(LOCK_PREFIX "andl %0,%1" \
14672 - : : "r" (~(mask)), "m" (*(addr)) : "memory")
14673 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
14674 +{
14675 + asm volatile(LOCK_PREFIX "andl %1,%0"
14676 + : "+m" (v->counter)
14677 + : "r" (~(mask))
14678 + : "memory");
14679 +}
14680
14681 -#define atomic_set_mask(mask, addr) \
14682 - asm volatile(LOCK_PREFIX "orl %0,%1" \
14683 - : : "r" ((unsigned)(mask)), "m" (*(addr)) \
14684 - : "memory")
14685 +static inline void atomic_clear_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14686 +{
14687 + asm volatile(LOCK_PREFIX "andl %1,%0"
14688 + : "+m" (v->counter)
14689 + : "r" (~(mask))
14690 + : "memory");
14691 +}
14692 +
14693 +static inline void atomic_set_mask(unsigned int mask, atomic_t *v)
14694 +{
14695 + asm volatile(LOCK_PREFIX "orl %1,%0"
14696 + : "+m" (v->counter)
14697 + : "r" (mask)
14698 + : "memory");
14699 +}
14700 +
14701 +static inline void atomic_set_mask_unchecked(unsigned int mask, atomic_unchecked_t *v)
14702 +{
14703 + asm volatile(LOCK_PREFIX "orl %1,%0"
14704 + : "+m" (v->counter)
14705 + : "r" (mask)
14706 + : "memory");
14707 +}
14708
14709 /* Atomic operations are already serializing on x86 */
14710 #define smp_mb__before_atomic_dec() barrier()
14711 diff --git a/arch/x86/include/asm/atomic64_32.h b/arch/x86/include/asm/atomic64_32.h
14712 index b154de7..bf18a5a 100644
14713 --- a/arch/x86/include/asm/atomic64_32.h
14714 +++ b/arch/x86/include/asm/atomic64_32.h
14715 @@ -12,6 +12,14 @@ typedef struct {
14716 u64 __aligned(8) counter;
14717 } atomic64_t;
14718
14719 +#ifdef CONFIG_PAX_REFCOUNT
14720 +typedef struct {
14721 + u64 __aligned(8) counter;
14722 +} atomic64_unchecked_t;
14723 +#else
14724 +typedef atomic64_t atomic64_unchecked_t;
14725 +#endif
14726 +
14727 #define ATOMIC64_INIT(val) { (val) }
14728
14729 #define __ATOMIC64_DECL(sym) void atomic64_##sym(atomic64_t *, ...)
14730 @@ -37,21 +45,31 @@ typedef struct {
14731 ATOMIC64_DECL_ONE(sym##_386)
14732
14733 ATOMIC64_DECL_ONE(add_386);
14734 +ATOMIC64_DECL_ONE(add_unchecked_386);
14735 ATOMIC64_DECL_ONE(sub_386);
14736 +ATOMIC64_DECL_ONE(sub_unchecked_386);
14737 ATOMIC64_DECL_ONE(inc_386);
14738 +ATOMIC64_DECL_ONE(inc_unchecked_386);
14739 ATOMIC64_DECL_ONE(dec_386);
14740 +ATOMIC64_DECL_ONE(dec_unchecked_386);
14741 #endif
14742
14743 #define alternative_atomic64(f, out, in...) \
14744 __alternative_atomic64(f, f, ASM_OUTPUT2(out), ## in)
14745
14746 ATOMIC64_DECL(read);
14747 +ATOMIC64_DECL(read_unchecked);
14748 ATOMIC64_DECL(set);
14749 +ATOMIC64_DECL(set_unchecked);
14750 ATOMIC64_DECL(xchg);
14751 ATOMIC64_DECL(add_return);
14752 +ATOMIC64_DECL(add_return_unchecked);
14753 ATOMIC64_DECL(sub_return);
14754 +ATOMIC64_DECL(sub_return_unchecked);
14755 ATOMIC64_DECL(inc_return);
14756 +ATOMIC64_DECL(inc_return_unchecked);
14757 ATOMIC64_DECL(dec_return);
14758 +ATOMIC64_DECL(dec_return_unchecked);
14759 ATOMIC64_DECL(dec_if_positive);
14760 ATOMIC64_DECL(inc_not_zero);
14761 ATOMIC64_DECL(add_unless);
14762 @@ -77,6 +95,21 @@ static inline long long atomic64_cmpxchg(atomic64_t *v, long long o, long long n
14763 }
14764
14765 /**
14766 + * atomic64_cmpxchg_unchecked - cmpxchg atomic64 variable
14767 + * @p: pointer to type atomic64_unchecked_t
14768 + * @o: expected value
14769 + * @n: new value
14770 + *
14771 + * Atomically sets @v to @n if it was equal to @o and returns
14772 + * the old value.
14773 + */
14774 +
14775 +static inline long long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long long o, long long n)
14776 +{
14777 + return cmpxchg64(&v->counter, o, n);
14778 +}
14779 +
14780 +/**
14781 * atomic64_xchg - xchg atomic64 variable
14782 * @v: pointer to type atomic64_t
14783 * @n: value to assign
14784 @@ -112,6 +145,22 @@ static inline void atomic64_set(atomic64_t *v, long long i)
14785 }
14786
14787 /**
14788 + * atomic64_set_unchecked - set atomic64 variable
14789 + * @v: pointer to type atomic64_unchecked_t
14790 + * @n: value to assign
14791 + *
14792 + * Atomically sets the value of @v to @n.
14793 + */
14794 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long long i)
14795 +{
14796 + unsigned high = (unsigned)(i >> 32);
14797 + unsigned low = (unsigned)i;
14798 + alternative_atomic64(set, /* no output */,
14799 + "S" (v), "b" (low), "c" (high)
14800 + : "eax", "edx", "memory");
14801 +}
14802 +
14803 +/**
14804 * atomic64_read - read atomic64 variable
14805 * @v: pointer to type atomic64_t
14806 *
14807 @@ -125,6 +174,19 @@ static inline long long atomic64_read(const atomic64_t *v)
14808 }
14809
14810 /**
14811 + * atomic64_read_unchecked - read atomic64 variable
14812 + * @v: pointer to type atomic64_unchecked_t
14813 + *
14814 + * Atomically reads the value of @v and returns it.
14815 + */
14816 +static inline long long __intentional_overflow(-1) atomic64_read_unchecked(atomic64_unchecked_t *v)
14817 +{
14818 + long long r;
14819 + alternative_atomic64(read, "=&A" (r), "c" (v) : "memory");
14820 + return r;
14821 + }
14822 +
14823 +/**
14824 * atomic64_add_return - add and return
14825 * @i: integer value to add
14826 * @v: pointer to type atomic64_t
14827 @@ -139,6 +201,21 @@ static inline long long atomic64_add_return(long long i, atomic64_t *v)
14828 return i;
14829 }
14830
14831 +/**
14832 + * atomic64_add_return_unchecked - add and return
14833 + * @i: integer value to add
14834 + * @v: pointer to type atomic64_unchecked_t
14835 + *
14836 + * Atomically adds @i to @v and returns @i + *@v
14837 + */
14838 +static inline long long atomic64_add_return_unchecked(long long i, atomic64_unchecked_t *v)
14839 +{
14840 + alternative_atomic64(add_return_unchecked,
14841 + ASM_OUTPUT2("+A" (i), "+c" (v)),
14842 + ASM_NO_INPUT_CLOBBER("memory"));
14843 + return i;
14844 +}
14845 +
14846 /*
14847 * Other variants with different arithmetic operators:
14848 */
14849 @@ -158,6 +235,14 @@ static inline long long atomic64_inc_return(atomic64_t *v)
14850 return a;
14851 }
14852
14853 +static inline long long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
14854 +{
14855 + long long a;
14856 + alternative_atomic64(inc_return_unchecked, "=&A" (a),
14857 + "S" (v) : "memory", "ecx");
14858 + return a;
14859 +}
14860 +
14861 static inline long long atomic64_dec_return(atomic64_t *v)
14862 {
14863 long long a;
14864 @@ -182,6 +267,21 @@ static inline long long atomic64_add(long long i, atomic64_t *v)
14865 }
14866
14867 /**
14868 + * atomic64_add_unchecked - add integer to atomic64 variable
14869 + * @i: integer value to add
14870 + * @v: pointer to type atomic64_unchecked_t
14871 + *
14872 + * Atomically adds @i to @v.
14873 + */
14874 +static inline long long atomic64_add_unchecked(long long i, atomic64_unchecked_t *v)
14875 +{
14876 + __alternative_atomic64(add_unchecked, add_return_unchecked,
14877 + ASM_OUTPUT2("+A" (i), "+c" (v)),
14878 + ASM_NO_INPUT_CLOBBER("memory"));
14879 + return i;
14880 +}
14881 +
14882 +/**
14883 * atomic64_sub - subtract the atomic64 variable
14884 * @i: integer value to subtract
14885 * @v: pointer to type atomic64_t
14886 diff --git a/arch/x86/include/asm/atomic64_64.h b/arch/x86/include/asm/atomic64_64.h
14887 index 46e9052..ae45136 100644
14888 --- a/arch/x86/include/asm/atomic64_64.h
14889 +++ b/arch/x86/include/asm/atomic64_64.h
14890 @@ -18,7 +18,19 @@
14891 */
14892 static inline long atomic64_read(const atomic64_t *v)
14893 {
14894 - return (*(volatile long *)&(v)->counter);
14895 + return (*(volatile const long *)&(v)->counter);
14896 +}
14897 +
14898 +/**
14899 + * atomic64_read_unchecked - read atomic64 variable
14900 + * @v: pointer of type atomic64_unchecked_t
14901 + *
14902 + * Atomically reads the value of @v.
14903 + * Doesn't imply a read memory barrier.
14904 + */
14905 +static inline long __intentional_overflow(-1) atomic64_read_unchecked(const atomic64_unchecked_t *v)
14906 +{
14907 + return (*(volatile const long *)&(v)->counter);
14908 }
14909
14910 /**
14911 @@ -34,6 +46,18 @@ static inline void atomic64_set(atomic64_t *v, long i)
14912 }
14913
14914 /**
14915 + * atomic64_set_unchecked - set atomic64 variable
14916 + * @v: pointer to type atomic64_unchecked_t
14917 + * @i: required value
14918 + *
14919 + * Atomically sets the value of @v to @i.
14920 + */
14921 +static inline void atomic64_set_unchecked(atomic64_unchecked_t *v, long i)
14922 +{
14923 + v->counter = i;
14924 +}
14925 +
14926 +/**
14927 * atomic64_add - add integer to atomic64 variable
14928 * @i: integer value to add
14929 * @v: pointer to type atomic64_t
14930 @@ -42,6 +66,28 @@ static inline void atomic64_set(atomic64_t *v, long i)
14931 */
14932 static inline void atomic64_add(long i, atomic64_t *v)
14933 {
14934 + asm volatile(LOCK_PREFIX "addq %1,%0\n"
14935 +
14936 +#ifdef CONFIG_PAX_REFCOUNT
14937 + "jno 0f\n"
14938 + LOCK_PREFIX "subq %1,%0\n"
14939 + "int $4\n0:\n"
14940 + _ASM_EXTABLE(0b, 0b)
14941 +#endif
14942 +
14943 + : "=m" (v->counter)
14944 + : "er" (i), "m" (v->counter));
14945 +}
14946 +
14947 +/**
14948 + * atomic64_add_unchecked - add integer to atomic64 variable
14949 + * @i: integer value to add
14950 + * @v: pointer to type atomic64_unchecked_t
14951 + *
14952 + * Atomically adds @i to @v.
14953 + */
14954 +static inline void atomic64_add_unchecked(long i, atomic64_unchecked_t *v)
14955 +{
14956 asm volatile(LOCK_PREFIX "addq %1,%0"
14957 : "=m" (v->counter)
14958 : "er" (i), "m" (v->counter));
14959 @@ -56,7 +102,29 @@ static inline void atomic64_add(long i, atomic64_t *v)
14960 */
14961 static inline void atomic64_sub(long i, atomic64_t *v)
14962 {
14963 - asm volatile(LOCK_PREFIX "subq %1,%0"
14964 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
14965 +
14966 +#ifdef CONFIG_PAX_REFCOUNT
14967 + "jno 0f\n"
14968 + LOCK_PREFIX "addq %1,%0\n"
14969 + "int $4\n0:\n"
14970 + _ASM_EXTABLE(0b, 0b)
14971 +#endif
14972 +
14973 + : "=m" (v->counter)
14974 + : "er" (i), "m" (v->counter));
14975 +}
14976 +
14977 +/**
14978 + * atomic64_sub_unchecked - subtract the atomic64 variable
14979 + * @i: integer value to subtract
14980 + * @v: pointer to type atomic64_unchecked_t
14981 + *
14982 + * Atomically subtracts @i from @v.
14983 + */
14984 +static inline void atomic64_sub_unchecked(long i, atomic64_unchecked_t *v)
14985 +{
14986 + asm volatile(LOCK_PREFIX "subq %1,%0\n"
14987 : "=m" (v->counter)
14988 : "er" (i), "m" (v->counter));
14989 }
14990 @@ -72,7 +140,7 @@ static inline void atomic64_sub(long i, atomic64_t *v)
14991 */
14992 static inline int atomic64_sub_and_test(long i, atomic64_t *v)
14993 {
14994 - GEN_BINARY_RMWcc(LOCK_PREFIX "subq", v->counter, "er", i, "%0", "e");
14995 + GEN_BINARY_RMWcc(LOCK_PREFIX "subq", LOCK_PREFIX "addq", v->counter, "er", i, "%0", "e");
14996 }
14997
14998 /**
14999 @@ -83,6 +151,27 @@ static inline int atomic64_sub_and_test(long i, atomic64_t *v)
15000 */
15001 static inline void atomic64_inc(atomic64_t *v)
15002 {
15003 + asm volatile(LOCK_PREFIX "incq %0\n"
15004 +
15005 +#ifdef CONFIG_PAX_REFCOUNT
15006 + "jno 0f\n"
15007 + LOCK_PREFIX "decq %0\n"
15008 + "int $4\n0:\n"
15009 + _ASM_EXTABLE(0b, 0b)
15010 +#endif
15011 +
15012 + : "=m" (v->counter)
15013 + : "m" (v->counter));
15014 +}
15015 +
15016 +/**
15017 + * atomic64_inc_unchecked - increment atomic64 variable
15018 + * @v: pointer to type atomic64_unchecked_t
15019 + *
15020 + * Atomically increments @v by 1.
15021 + */
15022 +static inline void atomic64_inc_unchecked(atomic64_unchecked_t *v)
15023 +{
15024 asm volatile(LOCK_PREFIX "incq %0"
15025 : "=m" (v->counter)
15026 : "m" (v->counter));
15027 @@ -96,7 +185,28 @@ static inline void atomic64_inc(atomic64_t *v)
15028 */
15029 static inline void atomic64_dec(atomic64_t *v)
15030 {
15031 - asm volatile(LOCK_PREFIX "decq %0"
15032 + asm volatile(LOCK_PREFIX "decq %0\n"
15033 +
15034 +#ifdef CONFIG_PAX_REFCOUNT
15035 + "jno 0f\n"
15036 + LOCK_PREFIX "incq %0\n"
15037 + "int $4\n0:\n"
15038 + _ASM_EXTABLE(0b, 0b)
15039 +#endif
15040 +
15041 + : "=m" (v->counter)
15042 + : "m" (v->counter));
15043 +}
15044 +
15045 +/**
15046 + * atomic64_dec_unchecked - decrement atomic64 variable
15047 + * @v: pointer to type atomic64_t
15048 + *
15049 + * Atomically decrements @v by 1.
15050 + */
15051 +static inline void atomic64_dec_unchecked(atomic64_unchecked_t *v)
15052 +{
15053 + asm volatile(LOCK_PREFIX "decq %0\n"
15054 : "=m" (v->counter)
15055 : "m" (v->counter));
15056 }
15057 @@ -111,7 +221,7 @@ static inline void atomic64_dec(atomic64_t *v)
15058 */
15059 static inline int atomic64_dec_and_test(atomic64_t *v)
15060 {
15061 - GEN_UNARY_RMWcc(LOCK_PREFIX "decq", v->counter, "%0", "e");
15062 + GEN_UNARY_RMWcc(LOCK_PREFIX "decq", LOCK_PREFIX "incq", v->counter, "%0", "e");
15063 }
15064
15065 /**
15066 @@ -124,7 +234,7 @@ static inline int atomic64_dec_and_test(atomic64_t *v)
15067 */
15068 static inline int atomic64_inc_and_test(atomic64_t *v)
15069 {
15070 - GEN_UNARY_RMWcc(LOCK_PREFIX "incq", v->counter, "%0", "e");
15071 + GEN_UNARY_RMWcc(LOCK_PREFIX "incq", LOCK_PREFIX "decq", v->counter, "%0", "e");
15072 }
15073
15074 /**
15075 @@ -138,7 +248,7 @@ static inline int atomic64_inc_and_test(atomic64_t *v)
15076 */
15077 static inline int atomic64_add_negative(long i, atomic64_t *v)
15078 {
15079 - GEN_BINARY_RMWcc(LOCK_PREFIX "addq", v->counter, "er", i, "%0", "s");
15080 + GEN_BINARY_RMWcc(LOCK_PREFIX "addq", LOCK_PREFIX "subq", v->counter, "er", i, "%0", "s");
15081 }
15082
15083 /**
15084 @@ -150,6 +260,18 @@ static inline int atomic64_add_negative(long i, atomic64_t *v)
15085 */
15086 static inline long atomic64_add_return(long i, atomic64_t *v)
15087 {
15088 + return i + xadd_check_overflow(&v->counter, i);
15089 +}
15090 +
15091 +/**
15092 + * atomic64_add_return_unchecked - add and return
15093 + * @i: integer value to add
15094 + * @v: pointer to type atomic64_unchecked_t
15095 + *
15096 + * Atomically adds @i to @v and returns @i + @v
15097 + */
15098 +static inline long atomic64_add_return_unchecked(long i, atomic64_unchecked_t *v)
15099 +{
15100 return i + xadd(&v->counter, i);
15101 }
15102
15103 @@ -159,6 +281,10 @@ static inline long atomic64_sub_return(long i, atomic64_t *v)
15104 }
15105
15106 #define atomic64_inc_return(v) (atomic64_add_return(1, (v)))
15107 +static inline long atomic64_inc_return_unchecked(atomic64_unchecked_t *v)
15108 +{
15109 + return atomic64_add_return_unchecked(1, v);
15110 +}
15111 #define atomic64_dec_return(v) (atomic64_sub_return(1, (v)))
15112
15113 static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15114 @@ -166,6 +292,11 @@ static inline long atomic64_cmpxchg(atomic64_t *v, long old, long new)
15115 return cmpxchg(&v->counter, old, new);
15116 }
15117
15118 +static inline long atomic64_cmpxchg_unchecked(atomic64_unchecked_t *v, long old, long new)
15119 +{
15120 + return cmpxchg(&v->counter, old, new);
15121 +}
15122 +
15123 static inline long atomic64_xchg(atomic64_t *v, long new)
15124 {
15125 return xchg(&v->counter, new);
15126 @@ -182,17 +313,30 @@ static inline long atomic64_xchg(atomic64_t *v, long new)
15127 */
15128 static inline int atomic64_add_unless(atomic64_t *v, long a, long u)
15129 {
15130 - long c, old;
15131 + long c, old, new;
15132 c = atomic64_read(v);
15133 for (;;) {
15134 - if (unlikely(c == (u)))
15135 + if (unlikely(c == u))
15136 break;
15137 - old = atomic64_cmpxchg((v), c, c + (a));
15138 +
15139 + asm volatile("add %2,%0\n"
15140 +
15141 +#ifdef CONFIG_PAX_REFCOUNT
15142 + "jno 0f\n"
15143 + "sub %2,%0\n"
15144 + "int $4\n0:\n"
15145 + _ASM_EXTABLE(0b, 0b)
15146 +#endif
15147 +
15148 + : "=r" (new)
15149 + : "0" (c), "ir" (a));
15150 +
15151 + old = atomic64_cmpxchg(v, c, new);
15152 if (likely(old == c))
15153 break;
15154 c = old;
15155 }
15156 - return c != (u);
15157 + return c != u;
15158 }
15159
15160 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1, 0)
15161 diff --git a/arch/x86/include/asm/bitops.h b/arch/x86/include/asm/bitops.h
15162 index 9fc1af7..fc71228 100644
15163 --- a/arch/x86/include/asm/bitops.h
15164 +++ b/arch/x86/include/asm/bitops.h
15165 @@ -49,7 +49,7 @@
15166 * a mask operation on a byte.
15167 */
15168 #define IS_IMMEDIATE(nr) (__builtin_constant_p(nr))
15169 -#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((void *)(addr) + ((nr)>>3))
15170 +#define CONST_MASK_ADDR(nr, addr) BITOP_ADDR((volatile void *)(addr) + ((nr)>>3))
15171 #define CONST_MASK(nr) (1 << ((nr) & 7))
15172
15173 /**
15174 @@ -205,7 +205,7 @@ static inline void change_bit(long nr, volatile unsigned long *addr)
15175 */
15176 static inline int test_and_set_bit(long nr, volatile unsigned long *addr)
15177 {
15178 - GEN_BINARY_RMWcc(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15179 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "bts", *addr, "Ir", nr, "%0", "c");
15180 }
15181
15182 /**
15183 @@ -251,7 +251,7 @@ static inline int __test_and_set_bit(long nr, volatile unsigned long *addr)
15184 */
15185 static inline int test_and_clear_bit(long nr, volatile unsigned long *addr)
15186 {
15187 - GEN_BINARY_RMWcc(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15188 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btr", *addr, "Ir", nr, "%0", "c");
15189 }
15190
15191 /**
15192 @@ -304,7 +304,7 @@ static inline int __test_and_change_bit(long nr, volatile unsigned long *addr)
15193 */
15194 static inline int test_and_change_bit(long nr, volatile unsigned long *addr)
15195 {
15196 - GEN_BINARY_RMWcc(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15197 + GEN_BINARY_RMWcc_unchecked(LOCK_PREFIX "btc", *addr, "Ir", nr, "%0", "c");
15198 }
15199
15200 static __always_inline int constant_test_bit(long nr, const volatile unsigned long *addr)
15201 @@ -345,7 +345,7 @@ static int test_bit(int nr, const volatile unsigned long *addr);
15202 *
15203 * Undefined if no bit exists, so code should check against 0 first.
15204 */
15205 -static inline unsigned long __ffs(unsigned long word)
15206 +static inline unsigned long __intentional_overflow(-1) __ffs(unsigned long word)
15207 {
15208 asm("rep; bsf %1,%0"
15209 : "=r" (word)
15210 @@ -359,7 +359,7 @@ static inline unsigned long __ffs(unsigned long word)
15211 *
15212 * Undefined if no zero exists, so code should check against ~0UL first.
15213 */
15214 -static inline unsigned long ffz(unsigned long word)
15215 +static inline unsigned long __intentional_overflow(-1) ffz(unsigned long word)
15216 {
15217 asm("rep; bsf %1,%0"
15218 : "=r" (word)
15219 @@ -373,7 +373,7 @@ static inline unsigned long ffz(unsigned long word)
15220 *
15221 * Undefined if no set bit exists, so code should check against 0 first.
15222 */
15223 -static inline unsigned long __fls(unsigned long word)
15224 +static inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
15225 {
15226 asm("bsr %1,%0"
15227 : "=r" (word)
15228 @@ -436,7 +436,7 @@ static inline int ffs(int x)
15229 * set bit if value is nonzero. The last (most significant) bit is
15230 * at position 32.
15231 */
15232 -static inline int fls(int x)
15233 +static inline int __intentional_overflow(-1) fls(int x)
15234 {
15235 int r;
15236
15237 @@ -478,7 +478,7 @@ static inline int fls(int x)
15238 * at position 64.
15239 */
15240 #ifdef CONFIG_X86_64
15241 -static __always_inline int fls64(__u64 x)
15242 +static __always_inline long fls64(__u64 x)
15243 {
15244 int bitpos = -1;
15245 /*
15246 diff --git a/arch/x86/include/asm/boot.h b/arch/x86/include/asm/boot.h
15247 index 4fa687a..60f2d39 100644
15248 --- a/arch/x86/include/asm/boot.h
15249 +++ b/arch/x86/include/asm/boot.h
15250 @@ -6,10 +6,15 @@
15251 #include <uapi/asm/boot.h>
15252
15253 /* Physical address where kernel should be loaded. */
15254 -#define LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15255 +#define ____LOAD_PHYSICAL_ADDR ((CONFIG_PHYSICAL_START \
15256 + (CONFIG_PHYSICAL_ALIGN - 1)) \
15257 & ~(CONFIG_PHYSICAL_ALIGN - 1))
15258
15259 +#ifndef __ASSEMBLY__
15260 +extern unsigned char __LOAD_PHYSICAL_ADDR[];
15261 +#define LOAD_PHYSICAL_ADDR ((unsigned long)__LOAD_PHYSICAL_ADDR)
15262 +#endif
15263 +
15264 /* Minimum kernel alignment, as a power of two */
15265 #ifdef CONFIG_X86_64
15266 #define MIN_KERNEL_ALIGN_LG2 PMD_SHIFT
15267 diff --git a/arch/x86/include/asm/cache.h b/arch/x86/include/asm/cache.h
15268 index 48f99f1..d78ebf9 100644
15269 --- a/arch/x86/include/asm/cache.h
15270 +++ b/arch/x86/include/asm/cache.h
15271 @@ -5,12 +5,13 @@
15272
15273 /* L1 cache line size */
15274 #define L1_CACHE_SHIFT (CONFIG_X86_L1_CACHE_SHIFT)
15275 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
15276 +#define L1_CACHE_BYTES (_AC(1,UL) << L1_CACHE_SHIFT)
15277
15278 #define __read_mostly __attribute__((__section__(".data..read_mostly")))
15279 +#define __read_only __attribute__((__section__(".data..read_only")))
15280
15281 #define INTERNODE_CACHE_SHIFT CONFIG_X86_INTERNODE_CACHE_SHIFT
15282 -#define INTERNODE_CACHE_BYTES (1 << INTERNODE_CACHE_SHIFT)
15283 +#define INTERNODE_CACHE_BYTES (_AC(1,UL) << INTERNODE_CACHE_SHIFT)
15284
15285 #ifdef CONFIG_X86_VSMP
15286 #ifdef CONFIG_SMP
15287 diff --git a/arch/x86/include/asm/cacheflush.h b/arch/x86/include/asm/cacheflush.h
15288 index 9863ee3..4a1f8e1 100644
15289 --- a/arch/x86/include/asm/cacheflush.h
15290 +++ b/arch/x86/include/asm/cacheflush.h
15291 @@ -27,7 +27,7 @@ static inline unsigned long get_page_memtype(struct page *pg)
15292 unsigned long pg_flags = pg->flags & _PGMT_MASK;
15293
15294 if (pg_flags == _PGMT_DEFAULT)
15295 - return -1;
15296 + return ~0UL;
15297 else if (pg_flags == _PGMT_WC)
15298 return _PAGE_CACHE_WC;
15299 else if (pg_flags == _PGMT_UC_MINUS)
15300 diff --git a/arch/x86/include/asm/calling.h b/arch/x86/include/asm/calling.h
15301 index cb4c73b..c473c29 100644
15302 --- a/arch/x86/include/asm/calling.h
15303 +++ b/arch/x86/include/asm/calling.h
15304 @@ -82,103 +82,113 @@ For 32-bit we have the following conventions - kernel is built with
15305 #define RSP 152
15306 #define SS 160
15307
15308 -#define ARGOFFSET R11
15309 -#define SWFRAME ORIG_RAX
15310 +#define ARGOFFSET R15
15311
15312 .macro SAVE_ARGS addskip=0, save_rcx=1, save_r891011=1
15313 - subq $9*8+\addskip, %rsp
15314 - CFI_ADJUST_CFA_OFFSET 9*8+\addskip
15315 - movq_cfi rdi, 8*8
15316 - movq_cfi rsi, 7*8
15317 - movq_cfi rdx, 6*8
15318 + subq $ORIG_RAX-ARGOFFSET+\addskip, %rsp
15319 + CFI_ADJUST_CFA_OFFSET ORIG_RAX-ARGOFFSET+\addskip
15320 + movq_cfi rdi, RDI
15321 + movq_cfi rsi, RSI
15322 + movq_cfi rdx, RDX
15323
15324 .if \save_rcx
15325 - movq_cfi rcx, 5*8
15326 + movq_cfi rcx, RCX
15327 .endif
15328
15329 - movq_cfi rax, 4*8
15330 + movq_cfi rax, RAX
15331
15332 .if \save_r891011
15333 - movq_cfi r8, 3*8
15334 - movq_cfi r9, 2*8
15335 - movq_cfi r10, 1*8
15336 - movq_cfi r11, 0*8
15337 + movq_cfi r8, R8
15338 + movq_cfi r9, R9
15339 + movq_cfi r10, R10
15340 + movq_cfi r11, R11
15341 .endif
15342
15343 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15344 + movq_cfi r12, R12
15345 +#endif
15346 +
15347 .endm
15348
15349 -#define ARG_SKIP (9*8)
15350 +#define ARG_SKIP ORIG_RAX
15351
15352 .macro RESTORE_ARGS rstor_rax=1, addskip=0, rstor_rcx=1, rstor_r11=1, \
15353 rstor_r8910=1, rstor_rdx=1
15354 +
15355 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15356 + movq_cfi_restore R12, r12
15357 +#endif
15358 +
15359 .if \rstor_r11
15360 - movq_cfi_restore 0*8, r11
15361 + movq_cfi_restore R11, r11
15362 .endif
15363
15364 .if \rstor_r8910
15365 - movq_cfi_restore 1*8, r10
15366 - movq_cfi_restore 2*8, r9
15367 - movq_cfi_restore 3*8, r8
15368 + movq_cfi_restore R10, r10
15369 + movq_cfi_restore R9, r9
15370 + movq_cfi_restore R8, r8
15371 .endif
15372
15373 .if \rstor_rax
15374 - movq_cfi_restore 4*8, rax
15375 + movq_cfi_restore RAX, rax
15376 .endif
15377
15378 .if \rstor_rcx
15379 - movq_cfi_restore 5*8, rcx
15380 + movq_cfi_restore RCX, rcx
15381 .endif
15382
15383 .if \rstor_rdx
15384 - movq_cfi_restore 6*8, rdx
15385 + movq_cfi_restore RDX, rdx
15386 .endif
15387
15388 - movq_cfi_restore 7*8, rsi
15389 - movq_cfi_restore 8*8, rdi
15390 + movq_cfi_restore RSI, rsi
15391 + movq_cfi_restore RDI, rdi
15392
15393 - .if ARG_SKIP+\addskip > 0
15394 - addq $ARG_SKIP+\addskip, %rsp
15395 - CFI_ADJUST_CFA_OFFSET -(ARG_SKIP+\addskip)
15396 + .if ORIG_RAX+\addskip > 0
15397 + addq $ORIG_RAX+\addskip, %rsp
15398 + CFI_ADJUST_CFA_OFFSET -(ORIG_RAX+\addskip)
15399 .endif
15400 .endm
15401
15402 - .macro LOAD_ARGS offset, skiprax=0
15403 - movq \offset(%rsp), %r11
15404 - movq \offset+8(%rsp), %r10
15405 - movq \offset+16(%rsp), %r9
15406 - movq \offset+24(%rsp), %r8
15407 - movq \offset+40(%rsp), %rcx
15408 - movq \offset+48(%rsp), %rdx
15409 - movq \offset+56(%rsp), %rsi
15410 - movq \offset+64(%rsp), %rdi
15411 + .macro LOAD_ARGS skiprax=0
15412 + movq R11(%rsp), %r11
15413 + movq R10(%rsp), %r10
15414 + movq R9(%rsp), %r9
15415 + movq R8(%rsp), %r8
15416 + movq RCX(%rsp), %rcx
15417 + movq RDX(%rsp), %rdx
15418 + movq RSI(%rsp), %rsi
15419 + movq RDI(%rsp), %rdi
15420 .if \skiprax
15421 .else
15422 - movq \offset+72(%rsp), %rax
15423 + movq RAX(%rsp), %rax
15424 .endif
15425 .endm
15426
15427 -#define REST_SKIP (6*8)
15428 -
15429 .macro SAVE_REST
15430 - subq $REST_SKIP, %rsp
15431 - CFI_ADJUST_CFA_OFFSET REST_SKIP
15432 - movq_cfi rbx, 5*8
15433 - movq_cfi rbp, 4*8
15434 - movq_cfi r12, 3*8
15435 - movq_cfi r13, 2*8
15436 - movq_cfi r14, 1*8
15437 - movq_cfi r15, 0*8
15438 + movq_cfi rbx, RBX
15439 + movq_cfi rbp, RBP
15440 +
15441 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15442 + movq_cfi r12, R12
15443 +#endif
15444 +
15445 + movq_cfi r13, R13
15446 + movq_cfi r14, R14
15447 + movq_cfi r15, R15
15448 .endm
15449
15450 .macro RESTORE_REST
15451 - movq_cfi_restore 0*8, r15
15452 - movq_cfi_restore 1*8, r14
15453 - movq_cfi_restore 2*8, r13
15454 - movq_cfi_restore 3*8, r12
15455 - movq_cfi_restore 4*8, rbp
15456 - movq_cfi_restore 5*8, rbx
15457 - addq $REST_SKIP, %rsp
15458 - CFI_ADJUST_CFA_OFFSET -(REST_SKIP)
15459 + movq_cfi_restore R15, r15
15460 + movq_cfi_restore R14, r14
15461 + movq_cfi_restore R13, r13
15462 +
15463 +#ifndef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
15464 + movq_cfi_restore R12, r12
15465 +#endif
15466 +
15467 + movq_cfi_restore RBP, rbp
15468 + movq_cfi_restore RBX, rbx
15469 .endm
15470
15471 .macro SAVE_ALL
15472 diff --git a/arch/x86/include/asm/checksum_32.h b/arch/x86/include/asm/checksum_32.h
15473 index f50de69..2b0a458 100644
15474 --- a/arch/x86/include/asm/checksum_32.h
15475 +++ b/arch/x86/include/asm/checksum_32.h
15476 @@ -31,6 +31,14 @@ asmlinkage __wsum csum_partial_copy_generic(const void *src, void *dst,
15477 int len, __wsum sum,
15478 int *src_err_ptr, int *dst_err_ptr);
15479
15480 +asmlinkage __wsum csum_partial_copy_generic_to_user(const void *src, void *dst,
15481 + int len, __wsum sum,
15482 + int *src_err_ptr, int *dst_err_ptr);
15483 +
15484 +asmlinkage __wsum csum_partial_copy_generic_from_user(const void *src, void *dst,
15485 + int len, __wsum sum,
15486 + int *src_err_ptr, int *dst_err_ptr);
15487 +
15488 /*
15489 * Note: when you get a NULL pointer exception here this means someone
15490 * passed in an incorrect kernel address to one of these functions.
15491 @@ -53,7 +61,7 @@ static inline __wsum csum_partial_copy_from_user(const void __user *src,
15492
15493 might_sleep();
15494 stac();
15495 - ret = csum_partial_copy_generic((__force void *)src, dst,
15496 + ret = csum_partial_copy_generic_from_user((__force void *)src, dst,
15497 len, sum, err_ptr, NULL);
15498 clac();
15499
15500 @@ -187,7 +195,7 @@ static inline __wsum csum_and_copy_to_user(const void *src,
15501 might_sleep();
15502 if (access_ok(VERIFY_WRITE, dst, len)) {
15503 stac();
15504 - ret = csum_partial_copy_generic(src, (__force void *)dst,
15505 + ret = csum_partial_copy_generic_to_user(src, (__force void *)dst,
15506 len, sum, NULL, err_ptr);
15507 clac();
15508 return ret;
15509 diff --git a/arch/x86/include/asm/cmpxchg.h b/arch/x86/include/asm/cmpxchg.h
15510 index d47786a..ce1b05d 100644
15511 --- a/arch/x86/include/asm/cmpxchg.h
15512 +++ b/arch/x86/include/asm/cmpxchg.h
15513 @@ -14,8 +14,12 @@ extern void __cmpxchg_wrong_size(void)
15514 __compiletime_error("Bad argument size for cmpxchg");
15515 extern void __xadd_wrong_size(void)
15516 __compiletime_error("Bad argument size for xadd");
15517 +extern void __xadd_check_overflow_wrong_size(void)
15518 + __compiletime_error("Bad argument size for xadd_check_overflow");
15519 extern void __add_wrong_size(void)
15520 __compiletime_error("Bad argument size for add");
15521 +extern void __add_check_overflow_wrong_size(void)
15522 + __compiletime_error("Bad argument size for add_check_overflow");
15523
15524 /*
15525 * Constants for operation sizes. On 32-bit, the 64-bit size it set to
15526 @@ -67,6 +71,34 @@ extern void __add_wrong_size(void)
15527 __ret; \
15528 })
15529
15530 +#define __xchg_op_check_overflow(ptr, arg, op, lock) \
15531 + ({ \
15532 + __typeof__ (*(ptr)) __ret = (arg); \
15533 + switch (sizeof(*(ptr))) { \
15534 + case __X86_CASE_L: \
15535 + asm volatile (lock #op "l %0, %1\n" \
15536 + "jno 0f\n" \
15537 + "mov %0,%1\n" \
15538 + "int $4\n0:\n" \
15539 + _ASM_EXTABLE(0b, 0b) \
15540 + : "+r" (__ret), "+m" (*(ptr)) \
15541 + : : "memory", "cc"); \
15542 + break; \
15543 + case __X86_CASE_Q: \
15544 + asm volatile (lock #op "q %q0, %1\n" \
15545 + "jno 0f\n" \
15546 + "mov %0,%1\n" \
15547 + "int $4\n0:\n" \
15548 + _ASM_EXTABLE(0b, 0b) \
15549 + : "+r" (__ret), "+m" (*(ptr)) \
15550 + : : "memory", "cc"); \
15551 + break; \
15552 + default: \
15553 + __ ## op ## _check_overflow_wrong_size(); \
15554 + } \
15555 + __ret; \
15556 + })
15557 +
15558 /*
15559 * Note: no "lock" prefix even on SMP: xchg always implies lock anyway.
15560 * Since this is generally used to protect other memory information, we
15561 @@ -167,6 +199,9 @@ extern void __add_wrong_size(void)
15562 #define xadd_sync(ptr, inc) __xadd((ptr), (inc), "lock; ")
15563 #define xadd_local(ptr, inc) __xadd((ptr), (inc), "")
15564
15565 +#define __xadd_check_overflow(ptr, inc, lock) __xchg_op_check_overflow((ptr), (inc), xadd, lock)
15566 +#define xadd_check_overflow(ptr, inc) __xadd_check_overflow((ptr), (inc), LOCK_PREFIX)
15567 +
15568 #define __add(ptr, inc, lock) \
15569 ({ \
15570 __typeof__ (*(ptr)) __ret = (inc); \
15571 diff --git a/arch/x86/include/asm/compat.h b/arch/x86/include/asm/compat.h
15572 index 59c6c40..5e0b22c 100644
15573 --- a/arch/x86/include/asm/compat.h
15574 +++ b/arch/x86/include/asm/compat.h
15575 @@ -41,7 +41,7 @@ typedef s64 __attribute__((aligned(4))) compat_s64;
15576 typedef u32 compat_uint_t;
15577 typedef u32 compat_ulong_t;
15578 typedef u64 __attribute__((aligned(4))) compat_u64;
15579 -typedef u32 compat_uptr_t;
15580 +typedef u32 __user compat_uptr_t;
15581
15582 struct compat_timespec {
15583 compat_time_t tv_sec;
15584 diff --git a/arch/x86/include/asm/cpufeature.h b/arch/x86/include/asm/cpufeature.h
15585 index 89270b4..f0abf8e 100644
15586 --- a/arch/x86/include/asm/cpufeature.h
15587 +++ b/arch/x86/include/asm/cpufeature.h
15588 @@ -203,7 +203,7 @@
15589 #define X86_FEATURE_DECODEASSISTS (8*32+12) /* AMD Decode Assists support */
15590 #define X86_FEATURE_PAUSEFILTER (8*32+13) /* AMD filtered pause intercept */
15591 #define X86_FEATURE_PFTHRESHOLD (8*32+14) /* AMD pause filter threshold */
15592 -
15593 +#define X86_FEATURE_STRONGUDEREF (8*32+31) /* PaX PCID based strong UDEREF */
15594
15595 /* Intel-defined CPU features, CPUID level 0x00000007:0 (ebx), word 9 */
15596 #define X86_FEATURE_FSGSBASE (9*32+ 0) /* {RD/WR}{FS/GS}BASE instructions*/
15597 @@ -211,7 +211,7 @@
15598 #define X86_FEATURE_BMI1 (9*32+ 3) /* 1st group bit manipulation extensions */
15599 #define X86_FEATURE_HLE (9*32+ 4) /* Hardware Lock Elision */
15600 #define X86_FEATURE_AVX2 (9*32+ 5) /* AVX2 instructions */
15601 -#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Protection */
15602 +#define X86_FEATURE_SMEP (9*32+ 7) /* Supervisor Mode Execution Prevention */
15603 #define X86_FEATURE_BMI2 (9*32+ 8) /* 2nd group bit manipulation extensions */
15604 #define X86_FEATURE_ERMS (9*32+ 9) /* Enhanced REP MOVSB/STOSB */
15605 #define X86_FEATURE_INVPCID (9*32+10) /* Invalidate Processor Context ID */
15606 @@ -353,6 +353,7 @@ extern const char * const x86_power_flags[32];
15607 #undef cpu_has_centaur_mcr
15608 #define cpu_has_centaur_mcr 0
15609
15610 +#define cpu_has_pcid boot_cpu_has(X86_FEATURE_PCID)
15611 #endif /* CONFIG_X86_64 */
15612
15613 #if __GNUC__ >= 4
15614 @@ -405,7 +406,8 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
15615
15616 #ifdef CONFIG_X86_DEBUG_STATIC_CPU_HAS
15617 t_warn:
15618 - warn_pre_alternatives();
15619 + if (bit != X86_FEATURE_PCID && bit != X86_FEATURE_INVPCID)
15620 + warn_pre_alternatives();
15621 return false;
15622 #endif
15623
15624 @@ -425,7 +427,7 @@ static __always_inline __pure bool __static_cpu_has(u16 bit)
15625 ".section .discard,\"aw\",@progbits\n"
15626 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
15627 ".previous\n"
15628 - ".section .altinstr_replacement,\"ax\"\n"
15629 + ".section .altinstr_replacement,\"a\"\n"
15630 "3: movb $1,%0\n"
15631 "4:\n"
15632 ".previous\n"
15633 @@ -462,7 +464,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15634 " .byte 2b - 1b\n" /* src len */
15635 " .byte 4f - 3f\n" /* repl len */
15636 ".previous\n"
15637 - ".section .altinstr_replacement,\"ax\"\n"
15638 + ".section .altinstr_replacement,\"a\"\n"
15639 "3: .byte 0xe9\n .long %l[t_no] - 2b\n"
15640 "4:\n"
15641 ".previous\n"
15642 @@ -495,7 +497,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15643 ".section .discard,\"aw\",@progbits\n"
15644 " .byte 0xff + (4f-3f) - (2b-1b)\n" /* size check */
15645 ".previous\n"
15646 - ".section .altinstr_replacement,\"ax\"\n"
15647 + ".section .altinstr_replacement,\"a\"\n"
15648 "3: movb $0,%0\n"
15649 "4:\n"
15650 ".previous\n"
15651 @@ -509,7 +511,7 @@ static __always_inline __pure bool _static_cpu_has_safe(u16 bit)
15652 ".section .discard,\"aw\",@progbits\n"
15653 " .byte 0xff + (6f-5f) - (4b-3b)\n" /* size check */
15654 ".previous\n"
15655 - ".section .altinstr_replacement,\"ax\"\n"
15656 + ".section .altinstr_replacement,\"a\"\n"
15657 "5: movb $1,%0\n"
15658 "6:\n"
15659 ".previous\n"
15660 diff --git a/arch/x86/include/asm/desc.h b/arch/x86/include/asm/desc.h
15661 index 50d033a..37deb26 100644
15662 --- a/arch/x86/include/asm/desc.h
15663 +++ b/arch/x86/include/asm/desc.h
15664 @@ -4,6 +4,7 @@
15665 #include <asm/desc_defs.h>
15666 #include <asm/ldt.h>
15667 #include <asm/mmu.h>
15668 +#include <asm/pgtable.h>
15669
15670 #include <linux/smp.h>
15671 #include <linux/percpu.h>
15672 @@ -17,6 +18,7 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
15673
15674 desc->type = (info->read_exec_only ^ 1) << 1;
15675 desc->type |= info->contents << 2;
15676 + desc->type |= info->seg_not_present ^ 1;
15677
15678 desc->s = 1;
15679 desc->dpl = 0x3;
15680 @@ -35,19 +37,14 @@ static inline void fill_ldt(struct desc_struct *desc, const struct user_desc *in
15681 }
15682
15683 extern struct desc_ptr idt_descr;
15684 -extern gate_desc idt_table[];
15685 -extern struct desc_ptr debug_idt_descr;
15686 -extern gate_desc debug_idt_table[];
15687 -
15688 -struct gdt_page {
15689 - struct desc_struct gdt[GDT_ENTRIES];
15690 -} __attribute__((aligned(PAGE_SIZE)));
15691 -
15692 -DECLARE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page);
15693 +extern gate_desc idt_table[IDT_ENTRIES];
15694 +extern const struct desc_ptr debug_idt_descr;
15695 +extern gate_desc debug_idt_table[IDT_ENTRIES];
15696
15697 +extern struct desc_struct cpu_gdt_table[NR_CPUS][PAGE_SIZE / sizeof(struct desc_struct)];
15698 static inline struct desc_struct *get_cpu_gdt_table(unsigned int cpu)
15699 {
15700 - return per_cpu(gdt_page, cpu).gdt;
15701 + return cpu_gdt_table[cpu];
15702 }
15703
15704 #ifdef CONFIG_X86_64
15705 @@ -72,8 +69,14 @@ static inline void pack_gate(gate_desc *gate, unsigned char type,
15706 unsigned long base, unsigned dpl, unsigned flags,
15707 unsigned short seg)
15708 {
15709 - gate->a = (seg << 16) | (base & 0xffff);
15710 - gate->b = (base & 0xffff0000) | (((0x80 | type | (dpl << 5)) & 0xff) << 8);
15711 + gate->gate.offset_low = base;
15712 + gate->gate.seg = seg;
15713 + gate->gate.reserved = 0;
15714 + gate->gate.type = type;
15715 + gate->gate.s = 0;
15716 + gate->gate.dpl = dpl;
15717 + gate->gate.p = 1;
15718 + gate->gate.offset_high = base >> 16;
15719 }
15720
15721 #endif
15722 @@ -118,12 +121,16 @@ static inline void paravirt_free_ldt(struct desc_struct *ldt, unsigned entries)
15723
15724 static inline void native_write_idt_entry(gate_desc *idt, int entry, const gate_desc *gate)
15725 {
15726 + pax_open_kernel();
15727 memcpy(&idt[entry], gate, sizeof(*gate));
15728 + pax_close_kernel();
15729 }
15730
15731 static inline void native_write_ldt_entry(struct desc_struct *ldt, int entry, const void *desc)
15732 {
15733 + pax_open_kernel();
15734 memcpy(&ldt[entry], desc, 8);
15735 + pax_close_kernel();
15736 }
15737
15738 static inline void
15739 @@ -137,7 +144,9 @@ native_write_gdt_entry(struct desc_struct *gdt, int entry, const void *desc, int
15740 default: size = sizeof(*gdt); break;
15741 }
15742
15743 + pax_open_kernel();
15744 memcpy(&gdt[entry], desc, size);
15745 + pax_close_kernel();
15746 }
15747
15748 static inline void pack_descriptor(struct desc_struct *desc, unsigned long base,
15749 @@ -210,7 +219,9 @@ static inline void native_set_ldt(const void *addr, unsigned int entries)
15750
15751 static inline void native_load_tr_desc(void)
15752 {
15753 + pax_open_kernel();
15754 asm volatile("ltr %w0"::"q" (GDT_ENTRY_TSS*8));
15755 + pax_close_kernel();
15756 }
15757
15758 static inline void native_load_gdt(const struct desc_ptr *dtr)
15759 @@ -247,8 +258,10 @@ static inline void native_load_tls(struct thread_struct *t, unsigned int cpu)
15760 struct desc_struct *gdt = get_cpu_gdt_table(cpu);
15761 unsigned int i;
15762
15763 + pax_open_kernel();
15764 for (i = 0; i < GDT_ENTRY_TLS_ENTRIES; i++)
15765 gdt[GDT_ENTRY_TLS_MIN + i] = t->tls_array[i];
15766 + pax_close_kernel();
15767 }
15768
15769 #define _LDT_empty(info) \
15770 @@ -287,7 +300,7 @@ static inline void load_LDT(mm_context_t *pc)
15771 preempt_enable();
15772 }
15773
15774 -static inline unsigned long get_desc_base(const struct desc_struct *desc)
15775 +static inline unsigned long __intentional_overflow(-1) get_desc_base(const struct desc_struct *desc)
15776 {
15777 return (unsigned)(desc->base0 | ((desc->base1) << 16) | ((desc->base2) << 24));
15778 }
15779 @@ -311,7 +324,7 @@ static inline void set_desc_limit(struct desc_struct *desc, unsigned long limit)
15780 }
15781
15782 #ifdef CONFIG_X86_64
15783 -static inline void set_nmi_gate(int gate, void *addr)
15784 +static inline void set_nmi_gate(int gate, const void *addr)
15785 {
15786 gate_desc s;
15787
15788 @@ -321,14 +334,14 @@ static inline void set_nmi_gate(int gate, void *addr)
15789 #endif
15790
15791 #ifdef CONFIG_TRACING
15792 -extern struct desc_ptr trace_idt_descr;
15793 -extern gate_desc trace_idt_table[];
15794 +extern const struct desc_ptr trace_idt_descr;
15795 +extern gate_desc trace_idt_table[IDT_ENTRIES];
15796 static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15797 {
15798 write_idt_entry(trace_idt_table, entry, gate);
15799 }
15800
15801 -static inline void _trace_set_gate(int gate, unsigned type, void *addr,
15802 +static inline void _trace_set_gate(int gate, unsigned type, const void *addr,
15803 unsigned dpl, unsigned ist, unsigned seg)
15804 {
15805 gate_desc s;
15806 @@ -348,7 +361,7 @@ static inline void write_trace_idt_entry(int entry, const gate_desc *gate)
15807 #define _trace_set_gate(gate, type, addr, dpl, ist, seg)
15808 #endif
15809
15810 -static inline void _set_gate(int gate, unsigned type, void *addr,
15811 +static inline void _set_gate(int gate, unsigned type, const void *addr,
15812 unsigned dpl, unsigned ist, unsigned seg)
15813 {
15814 gate_desc s;
15815 @@ -371,9 +384,9 @@ static inline void _set_gate(int gate, unsigned type, void *addr,
15816 #define set_intr_gate(n, addr) \
15817 do { \
15818 BUG_ON((unsigned)n > 0xFF); \
15819 - _set_gate(n, GATE_INTERRUPT, (void *)addr, 0, 0, \
15820 + _set_gate(n, GATE_INTERRUPT, (const void *)addr, 0, 0, \
15821 __KERNEL_CS); \
15822 - _trace_set_gate(n, GATE_INTERRUPT, (void *)trace_##addr,\
15823 + _trace_set_gate(n, GATE_INTERRUPT, (const void *)trace_##addr,\
15824 0, 0, __KERNEL_CS); \
15825 } while (0)
15826
15827 @@ -401,19 +414,19 @@ static inline void alloc_system_vector(int vector)
15828 /*
15829 * This routine sets up an interrupt gate at directory privilege level 3.
15830 */
15831 -static inline void set_system_intr_gate(unsigned int n, void *addr)
15832 +static inline void set_system_intr_gate(unsigned int n, const void *addr)
15833 {
15834 BUG_ON((unsigned)n > 0xFF);
15835 _set_gate(n, GATE_INTERRUPT, addr, 0x3, 0, __KERNEL_CS);
15836 }
15837
15838 -static inline void set_system_trap_gate(unsigned int n, void *addr)
15839 +static inline void set_system_trap_gate(unsigned int n, const void *addr)
15840 {
15841 BUG_ON((unsigned)n > 0xFF);
15842 _set_gate(n, GATE_TRAP, addr, 0x3, 0, __KERNEL_CS);
15843 }
15844
15845 -static inline void set_trap_gate(unsigned int n, void *addr)
15846 +static inline void set_trap_gate(unsigned int n, const void *addr)
15847 {
15848 BUG_ON((unsigned)n > 0xFF);
15849 _set_gate(n, GATE_TRAP, addr, 0, 0, __KERNEL_CS);
15850 @@ -422,16 +435,16 @@ static inline void set_trap_gate(unsigned int n, void *addr)
15851 static inline void set_task_gate(unsigned int n, unsigned int gdt_entry)
15852 {
15853 BUG_ON((unsigned)n > 0xFF);
15854 - _set_gate(n, GATE_TASK, (void *)0, 0, 0, (gdt_entry<<3));
15855 + _set_gate(n, GATE_TASK, (const void *)0, 0, 0, (gdt_entry<<3));
15856 }
15857
15858 -static inline void set_intr_gate_ist(int n, void *addr, unsigned ist)
15859 +static inline void set_intr_gate_ist(int n, const void *addr, unsigned ist)
15860 {
15861 BUG_ON((unsigned)n > 0xFF);
15862 _set_gate(n, GATE_INTERRUPT, addr, 0, ist, __KERNEL_CS);
15863 }
15864
15865 -static inline void set_system_intr_gate_ist(int n, void *addr, unsigned ist)
15866 +static inline void set_system_intr_gate_ist(int n, const void *addr, unsigned ist)
15867 {
15868 BUG_ON((unsigned)n > 0xFF);
15869 _set_gate(n, GATE_INTERRUPT, addr, 0x3, ist, __KERNEL_CS);
15870 @@ -503,4 +516,17 @@ static inline void load_current_idt(void)
15871 else
15872 load_idt((const struct desc_ptr *)&idt_descr);
15873 }
15874 +
15875 +#ifdef CONFIG_X86_32
15876 +static inline void set_user_cs(unsigned long base, unsigned long limit, int cpu)
15877 +{
15878 + struct desc_struct d;
15879 +
15880 + if (likely(limit))
15881 + limit = (limit - 1UL) >> PAGE_SHIFT;
15882 + pack_descriptor(&d, base, limit, 0xFB, 0xC);
15883 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_DEFAULT_USER_CS, &d, DESCTYPE_S);
15884 +}
15885 +#endif
15886 +
15887 #endif /* _ASM_X86_DESC_H */
15888 diff --git a/arch/x86/include/asm/desc_defs.h b/arch/x86/include/asm/desc_defs.h
15889 index 278441f..b95a174 100644
15890 --- a/arch/x86/include/asm/desc_defs.h
15891 +++ b/arch/x86/include/asm/desc_defs.h
15892 @@ -31,6 +31,12 @@ struct desc_struct {
15893 unsigned base1: 8, type: 4, s: 1, dpl: 2, p: 1;
15894 unsigned limit: 4, avl: 1, l: 1, d: 1, g: 1, base2: 8;
15895 };
15896 + struct {
15897 + u16 offset_low;
15898 + u16 seg;
15899 + unsigned reserved: 8, type: 4, s: 1, dpl: 2, p: 1;
15900 + unsigned offset_high: 16;
15901 + } gate;
15902 };
15903 } __attribute__((packed));
15904
15905 diff --git a/arch/x86/include/asm/div64.h b/arch/x86/include/asm/div64.h
15906 index ced283a..ffe04cc 100644
15907 --- a/arch/x86/include/asm/div64.h
15908 +++ b/arch/x86/include/asm/div64.h
15909 @@ -39,7 +39,7 @@
15910 __mod; \
15911 })
15912
15913 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15914 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
15915 {
15916 union {
15917 u64 v64;
15918 diff --git a/arch/x86/include/asm/elf.h b/arch/x86/include/asm/elf.h
15919 index 9c999c1..3860cb8 100644
15920 --- a/arch/x86/include/asm/elf.h
15921 +++ b/arch/x86/include/asm/elf.h
15922 @@ -243,7 +243,25 @@ extern int force_personality32;
15923 the loader. We need to make sure that it is out of the way of the program
15924 that it will "exec", and that there is sufficient room for the brk. */
15925
15926 +#ifdef CONFIG_PAX_SEGMEXEC
15927 +#define ELF_ET_DYN_BASE ((current->mm->pax_flags & MF_PAX_SEGMEXEC) ? SEGMEXEC_TASK_SIZE/3*2 : TASK_SIZE/3*2)
15928 +#else
15929 #define ELF_ET_DYN_BASE (TASK_SIZE / 3 * 2)
15930 +#endif
15931 +
15932 +#ifdef CONFIG_PAX_ASLR
15933 +#ifdef CONFIG_X86_32
15934 +#define PAX_ELF_ET_DYN_BASE 0x10000000UL
15935 +
15936 +#define PAX_DELTA_MMAP_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15937 +#define PAX_DELTA_STACK_LEN (current->mm->pax_flags & MF_PAX_SEGMEXEC ? 15 : 16)
15938 +#else
15939 +#define PAX_ELF_ET_DYN_BASE 0x400000UL
15940 +
15941 +#define PAX_DELTA_MMAP_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15942 +#define PAX_DELTA_STACK_LEN ((test_thread_flag(TIF_ADDR32)) ? 16 : TASK_SIZE_MAX_SHIFT - PAGE_SHIFT - 3)
15943 +#endif
15944 +#endif
15945
15946 /* This yields a mask that user programs can use to figure out what
15947 instruction set this CPU supports. This could be done in user space,
15948 @@ -296,16 +314,12 @@ do { \
15949
15950 #define ARCH_DLINFO \
15951 do { \
15952 - if (vdso_enabled) \
15953 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15954 - (unsigned long)current->mm->context.vdso); \
15955 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15956 } while (0)
15957
15958 #define ARCH_DLINFO_X32 \
15959 do { \
15960 - if (vdso_enabled) \
15961 - NEW_AUX_ENT(AT_SYSINFO_EHDR, \
15962 - (unsigned long)current->mm->context.vdso); \
15963 + NEW_AUX_ENT(AT_SYSINFO_EHDR, current->mm->context.vdso); \
15964 } while (0)
15965
15966 #define AT_SYSINFO 32
15967 @@ -320,7 +334,7 @@ else \
15968
15969 #endif /* !CONFIG_X86_32 */
15970
15971 -#define VDSO_CURRENT_BASE ((unsigned long)current->mm->context.vdso)
15972 +#define VDSO_CURRENT_BASE (current->mm->context.vdso)
15973
15974 #define VDSO_ENTRY \
15975 ((unsigned long)VDSO32_SYMBOL(VDSO_CURRENT_BASE, vsyscall))
15976 @@ -336,9 +350,6 @@ extern int x32_setup_additional_pages(struct linux_binprm *bprm,
15977 extern int syscall32_setup_pages(struct linux_binprm *, int exstack);
15978 #define compat_arch_setup_additional_pages syscall32_setup_pages
15979
15980 -extern unsigned long arch_randomize_brk(struct mm_struct *mm);
15981 -#define arch_randomize_brk arch_randomize_brk
15982 -
15983 /*
15984 * True on X86_32 or when emulating IA32 on X86_64
15985 */
15986 diff --git a/arch/x86/include/asm/emergency-restart.h b/arch/x86/include/asm/emergency-restart.h
15987 index 77a99ac..39ff7f5 100644
15988 --- a/arch/x86/include/asm/emergency-restart.h
15989 +++ b/arch/x86/include/asm/emergency-restart.h
15990 @@ -1,6 +1,6 @@
15991 #ifndef _ASM_X86_EMERGENCY_RESTART_H
15992 #define _ASM_X86_EMERGENCY_RESTART_H
15993
15994 -extern void machine_emergency_restart(void);
15995 +extern void machine_emergency_restart(void) __noreturn;
15996
15997 #endif /* _ASM_X86_EMERGENCY_RESTART_H */
15998 diff --git a/arch/x86/include/asm/floppy.h b/arch/x86/include/asm/floppy.h
15999 index d3d7469..677ef72 100644
16000 --- a/arch/x86/include/asm/floppy.h
16001 +++ b/arch/x86/include/asm/floppy.h
16002 @@ -229,18 +229,18 @@ static struct fd_routine_l {
16003 int (*_dma_setup)(char *addr, unsigned long size, int mode, int io);
16004 } fd_routine[] = {
16005 {
16006 - request_dma,
16007 - free_dma,
16008 - get_dma_residue,
16009 - dma_mem_alloc,
16010 - hard_dma_setup
16011 + ._request_dma = request_dma,
16012 + ._free_dma = free_dma,
16013 + ._get_dma_residue = get_dma_residue,
16014 + ._dma_mem_alloc = dma_mem_alloc,
16015 + ._dma_setup = hard_dma_setup
16016 },
16017 {
16018 - vdma_request_dma,
16019 - vdma_nop,
16020 - vdma_get_dma_residue,
16021 - vdma_mem_alloc,
16022 - vdma_dma_setup
16023 + ._request_dma = vdma_request_dma,
16024 + ._free_dma = vdma_nop,
16025 + ._get_dma_residue = vdma_get_dma_residue,
16026 + ._dma_mem_alloc = vdma_mem_alloc,
16027 + ._dma_setup = vdma_dma_setup
16028 }
16029 };
16030
16031 diff --git a/arch/x86/include/asm/fpu-internal.h b/arch/x86/include/asm/fpu-internal.h
16032 index cea1c76..6c0d79b 100644
16033 --- a/arch/x86/include/asm/fpu-internal.h
16034 +++ b/arch/x86/include/asm/fpu-internal.h
16035 @@ -124,8 +124,11 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16036 #define user_insn(insn, output, input...) \
16037 ({ \
16038 int err; \
16039 + pax_open_userland(); \
16040 asm volatile(ASM_STAC "\n" \
16041 - "1:" #insn "\n\t" \
16042 + "1:" \
16043 + __copyuser_seg \
16044 + #insn "\n\t" \
16045 "2: " ASM_CLAC "\n" \
16046 ".section .fixup,\"ax\"\n" \
16047 "3: movl $-1,%[err]\n" \
16048 @@ -134,6 +137,7 @@ static inline void sanitize_i387_state(struct task_struct *tsk)
16049 _ASM_EXTABLE(1b, 3b) \
16050 : [err] "=r" (err), output \
16051 : "0"(0), input); \
16052 + pax_close_userland(); \
16053 err; \
16054 })
16055
16056 @@ -298,7 +302,7 @@ static inline int restore_fpu_checking(struct task_struct *tsk)
16057 "fnclex\n\t"
16058 "emms\n\t"
16059 "fildl %P[addr]" /* set F?P to defined value */
16060 - : : [addr] "m" (tsk->thread.fpu.has_fpu));
16061 + : : [addr] "m" (init_tss[raw_smp_processor_id()].x86_tss.sp0));
16062 }
16063
16064 return fpu_restore_checking(&tsk->thread.fpu);
16065 diff --git a/arch/x86/include/asm/futex.h b/arch/x86/include/asm/futex.h
16066 index be27ba1..04a8801 100644
16067 --- a/arch/x86/include/asm/futex.h
16068 +++ b/arch/x86/include/asm/futex.h
16069 @@ -12,6 +12,7 @@
16070 #include <asm/smap.h>
16071
16072 #define __futex_atomic_op1(insn, ret, oldval, uaddr, oparg) \
16073 + typecheck(u32 __user *, uaddr); \
16074 asm volatile("\t" ASM_STAC "\n" \
16075 "1:\t" insn "\n" \
16076 "2:\t" ASM_CLAC "\n" \
16077 @@ -20,15 +21,16 @@
16078 "\tjmp\t2b\n" \
16079 "\t.previous\n" \
16080 _ASM_EXTABLE(1b, 3b) \
16081 - : "=r" (oldval), "=r" (ret), "+m" (*uaddr) \
16082 + : "=r" (oldval), "=r" (ret), "+m" (*(u32 __user *)____m(uaddr)) \
16083 : "i" (-EFAULT), "0" (oparg), "1" (0))
16084
16085 #define __futex_atomic_op2(insn, ret, oldval, uaddr, oparg) \
16086 + typecheck(u32 __user *, uaddr); \
16087 asm volatile("\t" ASM_STAC "\n" \
16088 "1:\tmovl %2, %0\n" \
16089 "\tmovl\t%0, %3\n" \
16090 "\t" insn "\n" \
16091 - "2:\t" LOCK_PREFIX "cmpxchgl %3, %2\n" \
16092 + "2:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %3, %2\n" \
16093 "\tjnz\t1b\n" \
16094 "3:\t" ASM_CLAC "\n" \
16095 "\t.section .fixup,\"ax\"\n" \
16096 @@ -38,7 +40,7 @@
16097 _ASM_EXTABLE(1b, 4b) \
16098 _ASM_EXTABLE(2b, 4b) \
16099 : "=&a" (oldval), "=&r" (ret), \
16100 - "+m" (*uaddr), "=&r" (tem) \
16101 + "+m" (*(u32 __user *)____m(uaddr)), "=&r" (tem) \
16102 : "r" (oparg), "i" (-EFAULT), "1" (0))
16103
16104 static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16105 @@ -57,12 +59,13 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16106
16107 pagefault_disable();
16108
16109 + pax_open_userland();
16110 switch (op) {
16111 case FUTEX_OP_SET:
16112 - __futex_atomic_op1("xchgl %0, %2", ret, oldval, uaddr, oparg);
16113 + __futex_atomic_op1(__copyuser_seg"xchgl %0, %2", ret, oldval, uaddr, oparg);
16114 break;
16115 case FUTEX_OP_ADD:
16116 - __futex_atomic_op1(LOCK_PREFIX "xaddl %0, %2", ret, oldval,
16117 + __futex_atomic_op1(LOCK_PREFIX __copyuser_seg"xaddl %0, %2", ret, oldval,
16118 uaddr, oparg);
16119 break;
16120 case FUTEX_OP_OR:
16121 @@ -77,6 +80,7 @@ static inline int futex_atomic_op_inuser(int encoded_op, u32 __user *uaddr)
16122 default:
16123 ret = -ENOSYS;
16124 }
16125 + pax_close_userland();
16126
16127 pagefault_enable();
16128
16129 @@ -115,18 +119,20 @@ static inline int futex_atomic_cmpxchg_inatomic(u32 *uval, u32 __user *uaddr,
16130 if (!access_ok(VERIFY_WRITE, uaddr, sizeof(u32)))
16131 return -EFAULT;
16132
16133 + pax_open_userland();
16134 asm volatile("\t" ASM_STAC "\n"
16135 - "1:\t" LOCK_PREFIX "cmpxchgl %4, %2\n"
16136 + "1:\t" LOCK_PREFIX __copyuser_seg"cmpxchgl %4, %2\n"
16137 "2:\t" ASM_CLAC "\n"
16138 "\t.section .fixup, \"ax\"\n"
16139 "3:\tmov %3, %0\n"
16140 "\tjmp 2b\n"
16141 "\t.previous\n"
16142 _ASM_EXTABLE(1b, 3b)
16143 - : "+r" (ret), "=a" (oldval), "+m" (*uaddr)
16144 + : "+r" (ret), "=a" (oldval), "+m" (*(u32 __user *)____m(uaddr))
16145 : "i" (-EFAULT), "r" (newval), "1" (oldval)
16146 : "memory"
16147 );
16148 + pax_close_userland();
16149
16150 *uval = oldval;
16151 return ret;
16152 diff --git a/arch/x86/include/asm/hw_irq.h b/arch/x86/include/asm/hw_irq.h
16153 index cba45d9..86344ba 100644
16154 --- a/arch/x86/include/asm/hw_irq.h
16155 +++ b/arch/x86/include/asm/hw_irq.h
16156 @@ -165,8 +165,8 @@ extern void setup_ioapic_dest(void);
16157 extern void enable_IO_APIC(void);
16158
16159 /* Statistics */
16160 -extern atomic_t irq_err_count;
16161 -extern atomic_t irq_mis_count;
16162 +extern atomic_unchecked_t irq_err_count;
16163 +extern atomic_unchecked_t irq_mis_count;
16164
16165 /* EISA */
16166 extern void eisa_set_level_irq(unsigned int irq);
16167 diff --git a/arch/x86/include/asm/i8259.h b/arch/x86/include/asm/i8259.h
16168 index a203659..9889f1c 100644
16169 --- a/arch/x86/include/asm/i8259.h
16170 +++ b/arch/x86/include/asm/i8259.h
16171 @@ -62,7 +62,7 @@ struct legacy_pic {
16172 void (*init)(int auto_eoi);
16173 int (*irq_pending)(unsigned int irq);
16174 void (*make_irq)(unsigned int irq);
16175 -};
16176 +} __do_const;
16177
16178 extern struct legacy_pic *legacy_pic;
16179 extern struct legacy_pic null_legacy_pic;
16180 diff --git a/arch/x86/include/asm/io.h b/arch/x86/include/asm/io.h
16181 index 34f69cb..6d95446 100644
16182 --- a/arch/x86/include/asm/io.h
16183 +++ b/arch/x86/include/asm/io.h
16184 @@ -51,12 +51,12 @@ static inline void name(type val, volatile void __iomem *addr) \
16185 "m" (*(volatile type __force *)addr) barrier); }
16186
16187 build_mmio_read(readb, "b", unsigned char, "=q", :"memory")
16188 -build_mmio_read(readw, "w", unsigned short, "=r", :"memory")
16189 -build_mmio_read(readl, "l", unsigned int, "=r", :"memory")
16190 +build_mmio_read(__intentional_overflow(-1) readw, "w", unsigned short, "=r", :"memory")
16191 +build_mmio_read(__intentional_overflow(-1) readl, "l", unsigned int, "=r", :"memory")
16192
16193 build_mmio_read(__readb, "b", unsigned char, "=q", )
16194 -build_mmio_read(__readw, "w", unsigned short, "=r", )
16195 -build_mmio_read(__readl, "l", unsigned int, "=r", )
16196 +build_mmio_read(__intentional_overflow(-1) __readw, "w", unsigned short, "=r", )
16197 +build_mmio_read(__intentional_overflow(-1) __readl, "l", unsigned int, "=r", )
16198
16199 build_mmio_write(writeb, "b", unsigned char, "q", :"memory")
16200 build_mmio_write(writew, "w", unsigned short, "r", :"memory")
16201 @@ -184,7 +184,7 @@ static inline void __iomem *ioremap(resource_size_t offset, unsigned long size)
16202 return ioremap_nocache(offset, size);
16203 }
16204
16205 -extern void iounmap(volatile void __iomem *addr);
16206 +extern void iounmap(const volatile void __iomem *addr);
16207
16208 extern void set_iounmap_nonlazy(void);
16209
16210 @@ -194,6 +194,17 @@ extern void set_iounmap_nonlazy(void);
16211
16212 #include <linux/vmalloc.h>
16213
16214 +#define ARCH_HAS_VALID_PHYS_ADDR_RANGE
16215 +static inline int valid_phys_addr_range(unsigned long addr, size_t count)
16216 +{
16217 + return ((addr + count + PAGE_SIZE - 1) >> PAGE_SHIFT) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16218 +}
16219 +
16220 +static inline int valid_mmap_phys_addr_range(unsigned long pfn, size_t count)
16221 +{
16222 + return (pfn + (count >> PAGE_SHIFT)) < (1ULL << (boot_cpu_data.x86_phys_bits - PAGE_SHIFT)) ? 1 : 0;
16223 +}
16224 +
16225 /*
16226 * Convert a virtual cached pointer to an uncached pointer
16227 */
16228 diff --git a/arch/x86/include/asm/irqflags.h b/arch/x86/include/asm/irqflags.h
16229 index bba3cf8..06bc8da 100644
16230 --- a/arch/x86/include/asm/irqflags.h
16231 +++ b/arch/x86/include/asm/irqflags.h
16232 @@ -141,6 +141,11 @@ static inline notrace unsigned long arch_local_irq_save(void)
16233 sti; \
16234 sysexit
16235
16236 +#define GET_CR0_INTO_RDI mov %cr0, %rdi
16237 +#define SET_RDI_INTO_CR0 mov %rdi, %cr0
16238 +#define GET_CR3_INTO_RDI mov %cr3, %rdi
16239 +#define SET_RDI_INTO_CR3 mov %rdi, %cr3
16240 +
16241 #else
16242 #define INTERRUPT_RETURN iret
16243 #define ENABLE_INTERRUPTS_SYSEXIT sti; sysexit
16244 diff --git a/arch/x86/include/asm/kprobes.h b/arch/x86/include/asm/kprobes.h
16245 index 9454c16..e4100e3 100644
16246 --- a/arch/x86/include/asm/kprobes.h
16247 +++ b/arch/x86/include/asm/kprobes.h
16248 @@ -38,13 +38,8 @@ typedef u8 kprobe_opcode_t;
16249 #define RELATIVEJUMP_SIZE 5
16250 #define RELATIVECALL_OPCODE 0xe8
16251 #define RELATIVE_ADDR_SIZE 4
16252 -#define MAX_STACK_SIZE 64
16253 -#define MIN_STACK_SIZE(ADDR) \
16254 - (((MAX_STACK_SIZE) < (((unsigned long)current_thread_info()) + \
16255 - THREAD_SIZE - (unsigned long)(ADDR))) \
16256 - ? (MAX_STACK_SIZE) \
16257 - : (((unsigned long)current_thread_info()) + \
16258 - THREAD_SIZE - (unsigned long)(ADDR)))
16259 +#define MAX_STACK_SIZE 64UL
16260 +#define MIN_STACK_SIZE(ADDR) min(MAX_STACK_SIZE, current->thread.sp0 - (unsigned long)(ADDR))
16261
16262 #define flush_insn_slot(p) do { } while (0)
16263
16264 diff --git a/arch/x86/include/asm/local.h b/arch/x86/include/asm/local.h
16265 index 4ad6560..75c7bdd 100644
16266 --- a/arch/x86/include/asm/local.h
16267 +++ b/arch/x86/include/asm/local.h
16268 @@ -10,33 +10,97 @@ typedef struct {
16269 atomic_long_t a;
16270 } local_t;
16271
16272 +typedef struct {
16273 + atomic_long_unchecked_t a;
16274 +} local_unchecked_t;
16275 +
16276 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
16277
16278 #define local_read(l) atomic_long_read(&(l)->a)
16279 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
16280 #define local_set(l, i) atomic_long_set(&(l)->a, (i))
16281 +#define local_set_unchecked(l, i) atomic_long_set_unchecked(&(l)->a, (i))
16282
16283 static inline void local_inc(local_t *l)
16284 {
16285 - asm volatile(_ASM_INC "%0"
16286 + asm volatile(_ASM_INC "%0\n"
16287 +
16288 +#ifdef CONFIG_PAX_REFCOUNT
16289 + "jno 0f\n"
16290 + _ASM_DEC "%0\n"
16291 + "int $4\n0:\n"
16292 + _ASM_EXTABLE(0b, 0b)
16293 +#endif
16294 +
16295 + : "+m" (l->a.counter));
16296 +}
16297 +
16298 +static inline void local_inc_unchecked(local_unchecked_t *l)
16299 +{
16300 + asm volatile(_ASM_INC "%0\n"
16301 : "+m" (l->a.counter));
16302 }
16303
16304 static inline void local_dec(local_t *l)
16305 {
16306 - asm volatile(_ASM_DEC "%0"
16307 + asm volatile(_ASM_DEC "%0\n"
16308 +
16309 +#ifdef CONFIG_PAX_REFCOUNT
16310 + "jno 0f\n"
16311 + _ASM_INC "%0\n"
16312 + "int $4\n0:\n"
16313 + _ASM_EXTABLE(0b, 0b)
16314 +#endif
16315 +
16316 + : "+m" (l->a.counter));
16317 +}
16318 +
16319 +static inline void local_dec_unchecked(local_unchecked_t *l)
16320 +{
16321 + asm volatile(_ASM_DEC "%0\n"
16322 : "+m" (l->a.counter));
16323 }
16324
16325 static inline void local_add(long i, local_t *l)
16326 {
16327 - asm volatile(_ASM_ADD "%1,%0"
16328 + asm volatile(_ASM_ADD "%1,%0\n"
16329 +
16330 +#ifdef CONFIG_PAX_REFCOUNT
16331 + "jno 0f\n"
16332 + _ASM_SUB "%1,%0\n"
16333 + "int $4\n0:\n"
16334 + _ASM_EXTABLE(0b, 0b)
16335 +#endif
16336 +
16337 + : "+m" (l->a.counter)
16338 + : "ir" (i));
16339 +}
16340 +
16341 +static inline void local_add_unchecked(long i, local_unchecked_t *l)
16342 +{
16343 + asm volatile(_ASM_ADD "%1,%0\n"
16344 : "+m" (l->a.counter)
16345 : "ir" (i));
16346 }
16347
16348 static inline void local_sub(long i, local_t *l)
16349 {
16350 - asm volatile(_ASM_SUB "%1,%0"
16351 + asm volatile(_ASM_SUB "%1,%0\n"
16352 +
16353 +#ifdef CONFIG_PAX_REFCOUNT
16354 + "jno 0f\n"
16355 + _ASM_ADD "%1,%0\n"
16356 + "int $4\n0:\n"
16357 + _ASM_EXTABLE(0b, 0b)
16358 +#endif
16359 +
16360 + : "+m" (l->a.counter)
16361 + : "ir" (i));
16362 +}
16363 +
16364 +static inline void local_sub_unchecked(long i, local_unchecked_t *l)
16365 +{
16366 + asm volatile(_ASM_SUB "%1,%0\n"
16367 : "+m" (l->a.counter)
16368 : "ir" (i));
16369 }
16370 @@ -52,7 +116,7 @@ static inline void local_sub(long i, local_t *l)
16371 */
16372 static inline int local_sub_and_test(long i, local_t *l)
16373 {
16374 - GEN_BINARY_RMWcc(_ASM_SUB, l->a.counter, "er", i, "%0", "e");
16375 + GEN_BINARY_RMWcc(_ASM_SUB, _ASM_ADD, l->a.counter, "er", i, "%0", "e");
16376 }
16377
16378 /**
16379 @@ -65,7 +129,7 @@ static inline int local_sub_and_test(long i, local_t *l)
16380 */
16381 static inline int local_dec_and_test(local_t *l)
16382 {
16383 - GEN_UNARY_RMWcc(_ASM_DEC, l->a.counter, "%0", "e");
16384 + GEN_UNARY_RMWcc(_ASM_DEC, _ASM_INC, l->a.counter, "%0", "e");
16385 }
16386
16387 /**
16388 @@ -78,7 +142,7 @@ static inline int local_dec_and_test(local_t *l)
16389 */
16390 static inline int local_inc_and_test(local_t *l)
16391 {
16392 - GEN_UNARY_RMWcc(_ASM_INC, l->a.counter, "%0", "e");
16393 + GEN_UNARY_RMWcc(_ASM_INC, _ASM_DEC, l->a.counter, "%0", "e");
16394 }
16395
16396 /**
16397 @@ -92,7 +156,7 @@ static inline int local_inc_and_test(local_t *l)
16398 */
16399 static inline int local_add_negative(long i, local_t *l)
16400 {
16401 - GEN_BINARY_RMWcc(_ASM_ADD, l->a.counter, "er", i, "%0", "s");
16402 + GEN_BINARY_RMWcc(_ASM_ADD, _ASM_SUB, l->a.counter, "er", i, "%0", "s");
16403 }
16404
16405 /**
16406 @@ -105,6 +169,30 @@ static inline int local_add_negative(long i, local_t *l)
16407 static inline long local_add_return(long i, local_t *l)
16408 {
16409 long __i = i;
16410 + asm volatile(_ASM_XADD "%0, %1\n"
16411 +
16412 +#ifdef CONFIG_PAX_REFCOUNT
16413 + "jno 0f\n"
16414 + _ASM_MOV "%0,%1\n"
16415 + "int $4\n0:\n"
16416 + _ASM_EXTABLE(0b, 0b)
16417 +#endif
16418 +
16419 + : "+r" (i), "+m" (l->a.counter)
16420 + : : "memory");
16421 + return i + __i;
16422 +}
16423 +
16424 +/**
16425 + * local_add_return_unchecked - add and return
16426 + * @i: integer value to add
16427 + * @l: pointer to type local_unchecked_t
16428 + *
16429 + * Atomically adds @i to @l and returns @i + @l
16430 + */
16431 +static inline long local_add_return_unchecked(long i, local_unchecked_t *l)
16432 +{
16433 + long __i = i;
16434 asm volatile(_ASM_XADD "%0, %1;"
16435 : "+r" (i), "+m" (l->a.counter)
16436 : : "memory");
16437 @@ -121,6 +209,8 @@ static inline long local_sub_return(long i, local_t *l)
16438
16439 #define local_cmpxchg(l, o, n) \
16440 (cmpxchg_local(&((l)->a.counter), (o), (n)))
16441 +#define local_cmpxchg_unchecked(l, o, n) \
16442 + (cmpxchg_local(&((l)->a.counter), (o), (n)))
16443 /* Always has a lock prefix */
16444 #define local_xchg(l, n) (xchg(&((l)->a.counter), (n)))
16445
16446 diff --git a/arch/x86/include/asm/mman.h b/arch/x86/include/asm/mman.h
16447 new file mode 100644
16448 index 0000000..2bfd3ba
16449 --- /dev/null
16450 +++ b/arch/x86/include/asm/mman.h
16451 @@ -0,0 +1,15 @@
16452 +#ifndef _X86_MMAN_H
16453 +#define _X86_MMAN_H
16454 +
16455 +#include <uapi/asm/mman.h>
16456 +
16457 +#ifdef __KERNEL__
16458 +#ifndef __ASSEMBLY__
16459 +#ifdef CONFIG_X86_32
16460 +#define arch_mmap_check i386_mmap_check
16461 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags);
16462 +#endif
16463 +#endif
16464 +#endif
16465 +
16466 +#endif /* X86_MMAN_H */
16467 diff --git a/arch/x86/include/asm/mmu.h b/arch/x86/include/asm/mmu.h
16468 index 5f55e69..e20bfb1 100644
16469 --- a/arch/x86/include/asm/mmu.h
16470 +++ b/arch/x86/include/asm/mmu.h
16471 @@ -9,7 +9,7 @@
16472 * we put the segment information here.
16473 */
16474 typedef struct {
16475 - void *ldt;
16476 + struct desc_struct *ldt;
16477 int size;
16478
16479 #ifdef CONFIG_X86_64
16480 @@ -18,7 +18,19 @@ typedef struct {
16481 #endif
16482
16483 struct mutex lock;
16484 - void *vdso;
16485 + unsigned long vdso;
16486 +
16487 +#ifdef CONFIG_X86_32
16488 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
16489 + unsigned long user_cs_base;
16490 + unsigned long user_cs_limit;
16491 +
16492 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16493 + cpumask_t cpu_user_cs_mask;
16494 +#endif
16495 +
16496 +#endif
16497 +#endif
16498 } mm_context_t;
16499
16500 #ifdef CONFIG_SMP
16501 diff --git a/arch/x86/include/asm/mmu_context.h b/arch/x86/include/asm/mmu_context.h
16502 index be12c53..4d24039 100644
16503 --- a/arch/x86/include/asm/mmu_context.h
16504 +++ b/arch/x86/include/asm/mmu_context.h
16505 @@ -24,6 +24,20 @@ void destroy_context(struct mm_struct *mm);
16506
16507 static inline void enter_lazy_tlb(struct mm_struct *mm, struct task_struct *tsk)
16508 {
16509 +
16510 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16511 + if (!(static_cpu_has(X86_FEATURE_PCID))) {
16512 + unsigned int i;
16513 + pgd_t *pgd;
16514 +
16515 + pax_open_kernel();
16516 + pgd = get_cpu_pgd(smp_processor_id(), kernel);
16517 + for (i = USER_PGD_PTRS; i < 2 * USER_PGD_PTRS; ++i)
16518 + set_pgd_batched(pgd+i, native_make_pgd(0));
16519 + pax_close_kernel();
16520 + }
16521 +#endif
16522 +
16523 #ifdef CONFIG_SMP
16524 if (this_cpu_read(cpu_tlbstate.state) == TLBSTATE_OK)
16525 this_cpu_write(cpu_tlbstate.state, TLBSTATE_LAZY);
16526 @@ -34,16 +48,59 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16527 struct task_struct *tsk)
16528 {
16529 unsigned cpu = smp_processor_id();
16530 +#if defined(CONFIG_X86_32) && defined(CONFIG_SMP) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16531 + int tlbstate = TLBSTATE_OK;
16532 +#endif
16533
16534 if (likely(prev != next)) {
16535 #ifdef CONFIG_SMP
16536 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16537 + tlbstate = this_cpu_read(cpu_tlbstate.state);
16538 +#endif
16539 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16540 this_cpu_write(cpu_tlbstate.active_mm, next);
16541 #endif
16542 cpumask_set_cpu(cpu, mm_cpumask(next));
16543
16544 /* Re-load page tables */
16545 +#ifdef CONFIG_PAX_PER_CPU_PGD
16546 + pax_open_kernel();
16547 +
16548 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16549 + if (static_cpu_has(X86_FEATURE_PCID))
16550 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16551 + else
16552 +#endif
16553 +
16554 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16555 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16556 + pax_close_kernel();
16557 + 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));
16558 +
16559 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16560 + if (static_cpu_has(X86_FEATURE_PCID)) {
16561 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
16562 + u64 descriptor[2];
16563 + descriptor[0] = PCID_USER;
16564 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16565 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
16566 + descriptor[0] = PCID_KERNEL;
16567 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16568 + }
16569 + } else {
16570 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16571 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16572 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16573 + else
16574 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16575 + }
16576 + } else
16577 +#endif
16578 +
16579 + load_cr3(get_cpu_pgd(cpu, kernel));
16580 +#else
16581 load_cr3(next->pgd);
16582 +#endif
16583
16584 /* Stop flush ipis for the previous mm */
16585 cpumask_clear_cpu(cpu, mm_cpumask(prev));
16586 @@ -51,9 +108,67 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16587 /* Load the LDT, if the LDT is different: */
16588 if (unlikely(prev->context.ldt != next->context.ldt))
16589 load_LDT_nolock(&next->context);
16590 +
16591 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
16592 + if (!(__supported_pte_mask & _PAGE_NX)) {
16593 + smp_mb__before_clear_bit();
16594 + cpu_clear(cpu, prev->context.cpu_user_cs_mask);
16595 + smp_mb__after_clear_bit();
16596 + cpu_set(cpu, next->context.cpu_user_cs_mask);
16597 + }
16598 +#endif
16599 +
16600 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16601 + if (unlikely(prev->context.user_cs_base != next->context.user_cs_base ||
16602 + prev->context.user_cs_limit != next->context.user_cs_limit))
16603 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16604 +#ifdef CONFIG_SMP
16605 + else if (unlikely(tlbstate != TLBSTATE_OK))
16606 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16607 +#endif
16608 +#endif
16609 +
16610 }
16611 + else {
16612 +
16613 +#ifdef CONFIG_PAX_PER_CPU_PGD
16614 + pax_open_kernel();
16615 +
16616 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16617 + if (static_cpu_has(X86_FEATURE_PCID))
16618 + __clone_user_pgds(get_cpu_pgd(cpu, user), next->pgd);
16619 + else
16620 +#endif
16621 +
16622 + __clone_user_pgds(get_cpu_pgd(cpu, kernel), next->pgd);
16623 + __shadow_user_pgds(get_cpu_pgd(cpu, kernel) + USER_PGD_PTRS, next->pgd);
16624 + pax_close_kernel();
16625 + 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));
16626 +
16627 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
16628 + if (static_cpu_has(X86_FEATURE_PCID)) {
16629 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
16630 + u64 descriptor[2];
16631 + descriptor[0] = PCID_USER;
16632 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16633 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF)) {
16634 + descriptor[0] = PCID_KERNEL;
16635 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_CONTEXT) : "memory");
16636 + }
16637 + } else {
16638 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
16639 + if (static_cpu_has(X86_FEATURE_STRONGUDEREF))
16640 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
16641 + else
16642 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
16643 + }
16644 + } else
16645 +#endif
16646 +
16647 + load_cr3(get_cpu_pgd(cpu, kernel));
16648 +#endif
16649 +
16650 #ifdef CONFIG_SMP
16651 - else {
16652 this_cpu_write(cpu_tlbstate.state, TLBSTATE_OK);
16653 BUG_ON(this_cpu_read(cpu_tlbstate.active_mm) != next);
16654
16655 @@ -70,11 +185,28 @@ static inline void switch_mm(struct mm_struct *prev, struct mm_struct *next,
16656 * tlb flush IPI delivery. We must reload CR3
16657 * to make sure to use no freed page tables.
16658 */
16659 +
16660 +#ifndef CONFIG_PAX_PER_CPU_PGD
16661 load_cr3(next->pgd);
16662 +#endif
16663 +
16664 load_LDT_nolock(&next->context);
16665 +
16666 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
16667 + if (!(__supported_pte_mask & _PAGE_NX))
16668 + cpu_set(cpu, next->context.cpu_user_cs_mask);
16669 +#endif
16670 +
16671 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC))
16672 +#ifdef CONFIG_PAX_PAGEEXEC
16673 + if (!((next->pax_flags & MF_PAX_PAGEEXEC) && (__supported_pte_mask & _PAGE_NX)))
16674 +#endif
16675 + set_user_cs(next->context.user_cs_base, next->context.user_cs_limit, cpu);
16676 +#endif
16677 +
16678 }
16679 +#endif
16680 }
16681 -#endif
16682 }
16683
16684 #define activate_mm(prev, next) \
16685 diff --git a/arch/x86/include/asm/module.h b/arch/x86/include/asm/module.h
16686 index e3b7819..b257c64 100644
16687 --- a/arch/x86/include/asm/module.h
16688 +++ b/arch/x86/include/asm/module.h
16689 @@ -5,6 +5,7 @@
16690
16691 #ifdef CONFIG_X86_64
16692 /* X86_64 does not define MODULE_PROC_FAMILY */
16693 +#define MODULE_PROC_FAMILY ""
16694 #elif defined CONFIG_M486
16695 #define MODULE_PROC_FAMILY "486 "
16696 #elif defined CONFIG_M586
16697 @@ -57,8 +58,20 @@
16698 #error unknown processor family
16699 #endif
16700
16701 -#ifdef CONFIG_X86_32
16702 -# define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY
16703 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_BTS
16704 +#define MODULE_PAX_KERNEXEC "KERNEXEC_BTS "
16705 +#elif defined(CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR)
16706 +#define MODULE_PAX_KERNEXEC "KERNEXEC_OR "
16707 +#else
16708 +#define MODULE_PAX_KERNEXEC ""
16709 #endif
16710
16711 +#ifdef CONFIG_PAX_MEMORY_UDEREF
16712 +#define MODULE_PAX_UDEREF "UDEREF "
16713 +#else
16714 +#define MODULE_PAX_UDEREF ""
16715 +#endif
16716 +
16717 +#define MODULE_ARCH_VERMAGIC MODULE_PROC_FAMILY MODULE_PAX_KERNEXEC MODULE_PAX_UDEREF
16718 +
16719 #endif /* _ASM_X86_MODULE_H */
16720 diff --git a/arch/x86/include/asm/nmi.h b/arch/x86/include/asm/nmi.h
16721 index 86f9301..b365cda 100644
16722 --- a/arch/x86/include/asm/nmi.h
16723 +++ b/arch/x86/include/asm/nmi.h
16724 @@ -40,11 +40,11 @@ struct nmiaction {
16725 nmi_handler_t handler;
16726 unsigned long flags;
16727 const char *name;
16728 -};
16729 +} __do_const;
16730
16731 #define register_nmi_handler(t, fn, fg, n, init...) \
16732 ({ \
16733 - static struct nmiaction init fn##_na = { \
16734 + static const struct nmiaction init fn##_na = { \
16735 .handler = (fn), \
16736 .name = (n), \
16737 .flags = (fg), \
16738 @@ -52,7 +52,7 @@ struct nmiaction {
16739 __register_nmi_handler((t), &fn##_na); \
16740 })
16741
16742 -int __register_nmi_handler(unsigned int, struct nmiaction *);
16743 +int __register_nmi_handler(unsigned int, const struct nmiaction *);
16744
16745 void unregister_nmi_handler(unsigned int, const char *);
16746
16747 diff --git a/arch/x86/include/asm/page.h b/arch/x86/include/asm/page.h
16748 index c878924..21f4889 100644
16749 --- a/arch/x86/include/asm/page.h
16750 +++ b/arch/x86/include/asm/page.h
16751 @@ -52,6 +52,7 @@ static inline void copy_user_page(void *to, void *from, unsigned long vaddr,
16752 __phys_addr_symbol(__phys_reloc_hide((unsigned long)(x)))
16753
16754 #define __va(x) ((void *)((unsigned long)(x)+PAGE_OFFSET))
16755 +#define __early_va(x) ((void *)((unsigned long)(x)+__START_KERNEL_map - phys_base))
16756
16757 #define __boot_va(x) __va(x)
16758 #define __boot_pa(x) __pa(x)
16759 diff --git a/arch/x86/include/asm/page_64.h b/arch/x86/include/asm/page_64.h
16760 index 0f1ddee..e2fc3d1 100644
16761 --- a/arch/x86/include/asm/page_64.h
16762 +++ b/arch/x86/include/asm/page_64.h
16763 @@ -7,9 +7,9 @@
16764
16765 /* duplicated to the one in bootmem.h */
16766 extern unsigned long max_pfn;
16767 -extern unsigned long phys_base;
16768 +extern const unsigned long phys_base;
16769
16770 -static inline unsigned long __phys_addr_nodebug(unsigned long x)
16771 +static inline unsigned long __intentional_overflow(-1) __phys_addr_nodebug(unsigned long x)
16772 {
16773 unsigned long y = x - __START_KERNEL_map;
16774
16775 diff --git a/arch/x86/include/asm/paravirt.h b/arch/x86/include/asm/paravirt.h
16776 index 401f350..dee5d13 100644
16777 --- a/arch/x86/include/asm/paravirt.h
16778 +++ b/arch/x86/include/asm/paravirt.h
16779 @@ -560,7 +560,7 @@ static inline pmd_t __pmd(pmdval_t val)
16780 return (pmd_t) { ret };
16781 }
16782
16783 -static inline pmdval_t pmd_val(pmd_t pmd)
16784 +static inline __intentional_overflow(-1) pmdval_t pmd_val(pmd_t pmd)
16785 {
16786 pmdval_t ret;
16787
16788 @@ -626,6 +626,18 @@ static inline void set_pgd(pgd_t *pgdp, pgd_t pgd)
16789 val);
16790 }
16791
16792 +static inline void set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
16793 +{
16794 + pgdval_t val = native_pgd_val(pgd);
16795 +
16796 + if (sizeof(pgdval_t) > sizeof(long))
16797 + PVOP_VCALL3(pv_mmu_ops.set_pgd_batched, pgdp,
16798 + val, (u64)val >> 32);
16799 + else
16800 + PVOP_VCALL2(pv_mmu_ops.set_pgd_batched, pgdp,
16801 + val);
16802 +}
16803 +
16804 static inline void pgd_clear(pgd_t *pgdp)
16805 {
16806 set_pgd(pgdp, __pgd(0));
16807 @@ -710,6 +722,21 @@ static inline void __set_fixmap(unsigned /* enum fixed_addresses */ idx,
16808 pv_mmu_ops.set_fixmap(idx, phys, flags);
16809 }
16810
16811 +#ifdef CONFIG_PAX_KERNEXEC
16812 +static inline unsigned long pax_open_kernel(void)
16813 +{
16814 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_open_kernel);
16815 +}
16816 +
16817 +static inline unsigned long pax_close_kernel(void)
16818 +{
16819 + return PVOP_CALL0(unsigned long, pv_mmu_ops.pax_close_kernel);
16820 +}
16821 +#else
16822 +static inline unsigned long pax_open_kernel(void) { return 0; }
16823 +static inline unsigned long pax_close_kernel(void) { return 0; }
16824 +#endif
16825 +
16826 #if defined(CONFIG_SMP) && defined(CONFIG_PARAVIRT_SPINLOCKS)
16827
16828 static __always_inline void __ticket_lock_spinning(struct arch_spinlock *lock,
16829 @@ -906,7 +933,7 @@ extern void default_banner(void);
16830
16831 #define PARA_PATCH(struct, off) ((PARAVIRT_PATCH_##struct + (off)) / 4)
16832 #define PARA_SITE(ptype, clobbers, ops) _PVSITE(ptype, clobbers, ops, .long, 4)
16833 -#define PARA_INDIRECT(addr) *%cs:addr
16834 +#define PARA_INDIRECT(addr) *%ss:addr
16835 #endif
16836
16837 #define INTERRUPT_RETURN \
16838 @@ -981,6 +1008,21 @@ extern void default_banner(void);
16839 PARA_SITE(PARA_PATCH(pv_cpu_ops, PV_CPU_irq_enable_sysexit), \
16840 CLBR_NONE, \
16841 jmp PARA_INDIRECT(pv_cpu_ops+PV_CPU_irq_enable_sysexit))
16842 +
16843 +#define GET_CR0_INTO_RDI \
16844 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0); \
16845 + mov %rax,%rdi
16846 +
16847 +#define SET_RDI_INTO_CR0 \
16848 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
16849 +
16850 +#define GET_CR3_INTO_RDI \
16851 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_read_cr3); \
16852 + mov %rax,%rdi
16853 +
16854 +#define SET_RDI_INTO_CR3 \
16855 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_write_cr3)
16856 +
16857 #endif /* CONFIG_X86_32 */
16858
16859 #endif /* __ASSEMBLY__ */
16860 diff --git a/arch/x86/include/asm/paravirt_types.h b/arch/x86/include/asm/paravirt_types.h
16861 index aab8f67..0fb0ee4 100644
16862 --- a/arch/x86/include/asm/paravirt_types.h
16863 +++ b/arch/x86/include/asm/paravirt_types.h
16864 @@ -84,7 +84,7 @@ struct pv_init_ops {
16865 */
16866 unsigned (*patch)(u8 type, u16 clobber, void *insnbuf,
16867 unsigned long addr, unsigned len);
16868 -};
16869 +} __no_const __no_randomize_layout;
16870
16871
16872 struct pv_lazy_ops {
16873 @@ -92,13 +92,13 @@ struct pv_lazy_ops {
16874 void (*enter)(void);
16875 void (*leave)(void);
16876 void (*flush)(void);
16877 -};
16878 +} __no_randomize_layout;
16879
16880 struct pv_time_ops {
16881 unsigned long long (*sched_clock)(void);
16882 unsigned long long (*steal_clock)(int cpu);
16883 unsigned long (*get_tsc_khz)(void);
16884 -};
16885 +} __no_const __no_randomize_layout;
16886
16887 struct pv_cpu_ops {
16888 /* hooks for various privileged instructions */
16889 @@ -192,7 +192,7 @@ struct pv_cpu_ops {
16890
16891 void (*start_context_switch)(struct task_struct *prev);
16892 void (*end_context_switch)(struct task_struct *next);
16893 -};
16894 +} __no_const __no_randomize_layout;
16895
16896 struct pv_irq_ops {
16897 /*
16898 @@ -215,7 +215,7 @@ struct pv_irq_ops {
16899 #ifdef CONFIG_X86_64
16900 void (*adjust_exception_frame)(void);
16901 #endif
16902 -};
16903 +} __no_randomize_layout;
16904
16905 struct pv_apic_ops {
16906 #ifdef CONFIG_X86_LOCAL_APIC
16907 @@ -223,7 +223,7 @@ struct pv_apic_ops {
16908 unsigned long start_eip,
16909 unsigned long start_esp);
16910 #endif
16911 -};
16912 +} __no_const __no_randomize_layout;
16913
16914 struct pv_mmu_ops {
16915 unsigned long (*read_cr2)(void);
16916 @@ -313,6 +313,7 @@ struct pv_mmu_ops {
16917 struct paravirt_callee_save make_pud;
16918
16919 void (*set_pgd)(pgd_t *pudp, pgd_t pgdval);
16920 + void (*set_pgd_batched)(pgd_t *pudp, pgd_t pgdval);
16921 #endif /* PAGETABLE_LEVELS == 4 */
16922 #endif /* PAGETABLE_LEVELS >= 3 */
16923
16924 @@ -324,7 +325,13 @@ struct pv_mmu_ops {
16925 an mfn. We can tell which is which from the index. */
16926 void (*set_fixmap)(unsigned /* enum fixed_addresses */ idx,
16927 phys_addr_t phys, pgprot_t flags);
16928 -};
16929 +
16930 +#ifdef CONFIG_PAX_KERNEXEC
16931 + unsigned long (*pax_open_kernel)(void);
16932 + unsigned long (*pax_close_kernel)(void);
16933 +#endif
16934 +
16935 +} __no_randomize_layout;
16936
16937 struct arch_spinlock;
16938 #ifdef CONFIG_SMP
16939 @@ -336,11 +343,14 @@ typedef u16 __ticket_t;
16940 struct pv_lock_ops {
16941 struct paravirt_callee_save lock_spinning;
16942 void (*unlock_kick)(struct arch_spinlock *lock, __ticket_t ticket);
16943 -};
16944 +} __no_randomize_layout;
16945
16946 /* This contains all the paravirt structures: we get a convenient
16947 * number for each function using the offset which we use to indicate
16948 - * what to patch. */
16949 + * what to patch.
16950 + * shouldn't be randomized due to the "NEAT TRICK" in paravirt.c
16951 + */
16952 +
16953 struct paravirt_patch_template {
16954 struct pv_init_ops pv_init_ops;
16955 struct pv_time_ops pv_time_ops;
16956 @@ -349,7 +359,7 @@ struct paravirt_patch_template {
16957 struct pv_apic_ops pv_apic_ops;
16958 struct pv_mmu_ops pv_mmu_ops;
16959 struct pv_lock_ops pv_lock_ops;
16960 -};
16961 +} __no_randomize_layout;
16962
16963 extern struct pv_info pv_info;
16964 extern struct pv_init_ops pv_init_ops;
16965 diff --git a/arch/x86/include/asm/pgalloc.h b/arch/x86/include/asm/pgalloc.h
16966 index c4412e9..90e88c5 100644
16967 --- a/arch/x86/include/asm/pgalloc.h
16968 +++ b/arch/x86/include/asm/pgalloc.h
16969 @@ -63,6 +63,13 @@ static inline void pmd_populate_kernel(struct mm_struct *mm,
16970 pmd_t *pmd, pte_t *pte)
16971 {
16972 paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16973 + set_pmd(pmd, __pmd(__pa(pte) | _KERNPG_TABLE));
16974 +}
16975 +
16976 +static inline void pmd_populate_user(struct mm_struct *mm,
16977 + pmd_t *pmd, pte_t *pte)
16978 +{
16979 + paravirt_alloc_pte(mm, __pa(pte) >> PAGE_SHIFT);
16980 set_pmd(pmd, __pmd(__pa(pte) | _PAGE_TABLE));
16981 }
16982
16983 @@ -108,12 +115,22 @@ static inline void __pmd_free_tlb(struct mmu_gather *tlb, pmd_t *pmd,
16984
16985 #ifdef CONFIG_X86_PAE
16986 extern void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd);
16987 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
16988 +{
16989 + pud_populate(mm, pudp, pmd);
16990 +}
16991 #else /* !CONFIG_X86_PAE */
16992 static inline void pud_populate(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16993 {
16994 paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
16995 set_pud(pud, __pud(_PAGE_TABLE | __pa(pmd)));
16996 }
16997 +
16998 +static inline void pud_populate_kernel(struct mm_struct *mm, pud_t *pud, pmd_t *pmd)
16999 +{
17000 + paravirt_alloc_pmd(mm, __pa(pmd) >> PAGE_SHIFT);
17001 + set_pud(pud, __pud(_KERNPG_TABLE | __pa(pmd)));
17002 +}
17003 #endif /* CONFIG_X86_PAE */
17004
17005 #if PAGETABLE_LEVELS > 3
17006 @@ -123,6 +140,12 @@ static inline void pgd_populate(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17007 set_pgd(pgd, __pgd(_PAGE_TABLE | __pa(pud)));
17008 }
17009
17010 +static inline void pgd_populate_kernel(struct mm_struct *mm, pgd_t *pgd, pud_t *pud)
17011 +{
17012 + paravirt_alloc_pud(mm, __pa(pud) >> PAGE_SHIFT);
17013 + set_pgd(pgd, __pgd(_KERNPG_TABLE | __pa(pud)));
17014 +}
17015 +
17016 static inline pud_t *pud_alloc_one(struct mm_struct *mm, unsigned long addr)
17017 {
17018 return (pud_t *)get_zeroed_page(GFP_KERNEL|__GFP_REPEAT);
17019 diff --git a/arch/x86/include/asm/pgtable-2level.h b/arch/x86/include/asm/pgtable-2level.h
17020 index 3bf2dd0..23d2a9f 100644
17021 --- a/arch/x86/include/asm/pgtable-2level.h
17022 +++ b/arch/x86/include/asm/pgtable-2level.h
17023 @@ -18,7 +18,9 @@ static inline void native_set_pte(pte_t *ptep , pte_t pte)
17024
17025 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17026 {
17027 + pax_open_kernel();
17028 *pmdp = pmd;
17029 + pax_close_kernel();
17030 }
17031
17032 static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17033 diff --git a/arch/x86/include/asm/pgtable-3level.h b/arch/x86/include/asm/pgtable-3level.h
17034 index 81bb91b..9392125 100644
17035 --- a/arch/x86/include/asm/pgtable-3level.h
17036 +++ b/arch/x86/include/asm/pgtable-3level.h
17037 @@ -92,12 +92,16 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17038
17039 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17040 {
17041 + pax_open_kernel();
17042 set_64bit((unsigned long long *)(pmdp), native_pmd_val(pmd));
17043 + pax_close_kernel();
17044 }
17045
17046 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17047 {
17048 + pax_open_kernel();
17049 set_64bit((unsigned long long *)(pudp), native_pud_val(pud));
17050 + pax_close_kernel();
17051 }
17052
17053 /*
17054 diff --git a/arch/x86/include/asm/pgtable.h b/arch/x86/include/asm/pgtable.h
17055 index bbc8b12..f228861 100644
17056 --- a/arch/x86/include/asm/pgtable.h
17057 +++ b/arch/x86/include/asm/pgtable.h
17058 @@ -45,6 +45,7 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17059
17060 #ifndef __PAGETABLE_PUD_FOLDED
17061 #define set_pgd(pgdp, pgd) native_set_pgd(pgdp, pgd)
17062 +#define set_pgd_batched(pgdp, pgd) native_set_pgd_batched(pgdp, pgd)
17063 #define pgd_clear(pgd) native_pgd_clear(pgd)
17064 #endif
17065
17066 @@ -82,12 +83,51 @@ extern struct mm_struct *pgd_page_get_mm(struct page *page);
17067
17068 #define arch_end_context_switch(prev) do {} while(0)
17069
17070 +#define pax_open_kernel() native_pax_open_kernel()
17071 +#define pax_close_kernel() native_pax_close_kernel()
17072 #endif /* CONFIG_PARAVIRT */
17073
17074 +#define __HAVE_ARCH_PAX_OPEN_KERNEL
17075 +#define __HAVE_ARCH_PAX_CLOSE_KERNEL
17076 +
17077 +#ifdef CONFIG_PAX_KERNEXEC
17078 +static inline unsigned long native_pax_open_kernel(void)
17079 +{
17080 + unsigned long cr0;
17081 +
17082 + preempt_disable();
17083 + barrier();
17084 + cr0 = read_cr0() ^ X86_CR0_WP;
17085 + BUG_ON(cr0 & X86_CR0_WP);
17086 + write_cr0(cr0);
17087 + return cr0 ^ X86_CR0_WP;
17088 +}
17089 +
17090 +static inline unsigned long native_pax_close_kernel(void)
17091 +{
17092 + unsigned long cr0;
17093 +
17094 + cr0 = read_cr0() ^ X86_CR0_WP;
17095 + BUG_ON(!(cr0 & X86_CR0_WP));
17096 + write_cr0(cr0);
17097 + barrier();
17098 + preempt_enable_no_resched();
17099 + return cr0 ^ X86_CR0_WP;
17100 +}
17101 +#else
17102 +static inline unsigned long native_pax_open_kernel(void) { return 0; }
17103 +static inline unsigned long native_pax_close_kernel(void) { return 0; }
17104 +#endif
17105 +
17106 /*
17107 * The following only work if pte_present() is true.
17108 * Undefined behaviour if not..
17109 */
17110 +static inline int pte_user(pte_t pte)
17111 +{
17112 + return pte_val(pte) & _PAGE_USER;
17113 +}
17114 +
17115 static inline int pte_dirty(pte_t pte)
17116 {
17117 return pte_flags(pte) & _PAGE_DIRTY;
17118 @@ -148,6 +188,11 @@ static inline unsigned long pud_pfn(pud_t pud)
17119 return (pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT;
17120 }
17121
17122 +static inline unsigned long pgd_pfn(pgd_t pgd)
17123 +{
17124 + return (pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT;
17125 +}
17126 +
17127 #define pte_page(pte) pfn_to_page(pte_pfn(pte))
17128
17129 static inline int pmd_large(pmd_t pte)
17130 @@ -201,9 +246,29 @@ static inline pte_t pte_wrprotect(pte_t pte)
17131 return pte_clear_flags(pte, _PAGE_RW);
17132 }
17133
17134 +static inline pte_t pte_mkread(pte_t pte)
17135 +{
17136 + return __pte(pte_val(pte) | _PAGE_USER);
17137 +}
17138 +
17139 static inline pte_t pte_mkexec(pte_t pte)
17140 {
17141 - return pte_clear_flags(pte, _PAGE_NX);
17142 +#ifdef CONFIG_X86_PAE
17143 + if (__supported_pte_mask & _PAGE_NX)
17144 + return pte_clear_flags(pte, _PAGE_NX);
17145 + else
17146 +#endif
17147 + return pte_set_flags(pte, _PAGE_USER);
17148 +}
17149 +
17150 +static inline pte_t pte_exprotect(pte_t pte)
17151 +{
17152 +#ifdef CONFIG_X86_PAE
17153 + if (__supported_pte_mask & _PAGE_NX)
17154 + return pte_set_flags(pte, _PAGE_NX);
17155 + else
17156 +#endif
17157 + return pte_clear_flags(pte, _PAGE_USER);
17158 }
17159
17160 static inline pte_t pte_mkdirty(pte_t pte)
17161 @@ -430,6 +495,16 @@ pte_t *populate_extra_pte(unsigned long vaddr);
17162 #endif
17163
17164 #ifndef __ASSEMBLY__
17165 +
17166 +#ifdef CONFIG_PAX_PER_CPU_PGD
17167 +extern pgd_t cpu_pgd[NR_CPUS][2][PTRS_PER_PGD];
17168 +enum cpu_pgd_type {kernel = 0, user = 1};
17169 +static inline pgd_t *get_cpu_pgd(unsigned int cpu, enum cpu_pgd_type type)
17170 +{
17171 + return cpu_pgd[cpu][type];
17172 +}
17173 +#endif
17174 +
17175 #include <linux/mm_types.h>
17176 #include <linux/mmdebug.h>
17177 #include <linux/log2.h>
17178 @@ -570,7 +645,7 @@ static inline unsigned long pud_page_vaddr(pud_t pud)
17179 * Currently stuck as a macro due to indirect forward reference to
17180 * linux/mmzone.h's __section_mem_map_addr() definition:
17181 */
17182 -#define pud_page(pud) pfn_to_page(pud_val(pud) >> PAGE_SHIFT)
17183 +#define pud_page(pud) pfn_to_page((pud_val(pud) & PTE_PFN_MASK) >> PAGE_SHIFT)
17184
17185 /* Find an entry in the second-level page table.. */
17186 static inline pmd_t *pmd_offset(pud_t *pud, unsigned long address)
17187 @@ -610,7 +685,7 @@ static inline unsigned long pgd_page_vaddr(pgd_t pgd)
17188 * Currently stuck as a macro due to indirect forward reference to
17189 * linux/mmzone.h's __section_mem_map_addr() definition:
17190 */
17191 -#define pgd_page(pgd) pfn_to_page(pgd_val(pgd) >> PAGE_SHIFT)
17192 +#define pgd_page(pgd) pfn_to_page((pgd_val(pgd) & PTE_PFN_MASK) >> PAGE_SHIFT)
17193
17194 /* to find an entry in a page-table-directory. */
17195 static inline unsigned long pud_index(unsigned long address)
17196 @@ -625,7 +700,7 @@ static inline pud_t *pud_offset(pgd_t *pgd, unsigned long address)
17197
17198 static inline int pgd_bad(pgd_t pgd)
17199 {
17200 - return (pgd_flags(pgd) & ~_PAGE_USER) != _KERNPG_TABLE;
17201 + return (pgd_flags(pgd) & ~(_PAGE_USER | _PAGE_NX)) != _KERNPG_TABLE;
17202 }
17203
17204 static inline int pgd_none(pgd_t pgd)
17205 @@ -648,7 +723,12 @@ static inline int pgd_none(pgd_t pgd)
17206 * pgd_offset() returns a (pgd_t *)
17207 * pgd_index() is used get the offset into the pgd page's array of pgd_t's;
17208 */
17209 -#define pgd_offset(mm, address) ((mm)->pgd + pgd_index((address)))
17210 +#define pgd_offset(mm, address) ((mm)->pgd + pgd_index(address))
17211 +
17212 +#ifdef CONFIG_PAX_PER_CPU_PGD
17213 +#define pgd_offset_cpu(cpu, type, address) (get_cpu_pgd(cpu, type) + pgd_index(address))
17214 +#endif
17215 +
17216 /*
17217 * a shortcut which implies the use of the kernel's pgd, instead
17218 * of a process's
17219 @@ -659,6 +739,23 @@ static inline int pgd_none(pgd_t pgd)
17220 #define KERNEL_PGD_BOUNDARY pgd_index(PAGE_OFFSET)
17221 #define KERNEL_PGD_PTRS (PTRS_PER_PGD - KERNEL_PGD_BOUNDARY)
17222
17223 +#ifdef CONFIG_X86_32
17224 +#define USER_PGD_PTRS KERNEL_PGD_BOUNDARY
17225 +#else
17226 +#define TASK_SIZE_MAX_SHIFT CONFIG_TASK_SIZE_MAX_SHIFT
17227 +#define USER_PGD_PTRS (_AC(1,UL) << (TASK_SIZE_MAX_SHIFT - PGDIR_SHIFT))
17228 +
17229 +#ifdef CONFIG_PAX_MEMORY_UDEREF
17230 +#ifdef __ASSEMBLY__
17231 +#define pax_user_shadow_base pax_user_shadow_base(%rip)
17232 +#else
17233 +extern unsigned long pax_user_shadow_base;
17234 +extern pgdval_t clone_pgd_mask;
17235 +#endif
17236 +#endif
17237 +
17238 +#endif
17239 +
17240 #ifndef __ASSEMBLY__
17241
17242 extern int direct_gbpages;
17243 @@ -825,11 +922,24 @@ static inline void pmdp_set_wrprotect(struct mm_struct *mm,
17244 * dst and src can be on the same page, but the range must not overlap,
17245 * and must not cross a page boundary.
17246 */
17247 -static inline void clone_pgd_range(pgd_t *dst, pgd_t *src, int count)
17248 +static inline void clone_pgd_range(pgd_t *dst, const pgd_t *src, int count)
17249 {
17250 - memcpy(dst, src, count * sizeof(pgd_t));
17251 + pax_open_kernel();
17252 + while (count--)
17253 + *dst++ = *src++;
17254 + pax_close_kernel();
17255 }
17256
17257 +#ifdef CONFIG_PAX_PER_CPU_PGD
17258 +extern void __clone_user_pgds(pgd_t *dst, const pgd_t *src);
17259 +#endif
17260 +
17261 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
17262 +extern void __shadow_user_pgds(pgd_t *dst, const pgd_t *src);
17263 +#else
17264 +static inline void __shadow_user_pgds(pgd_t *dst, const pgd_t *src) {}
17265 +#endif
17266 +
17267 #define PTE_SHIFT ilog2(PTRS_PER_PTE)
17268 static inline int page_level_shift(enum pg_level level)
17269 {
17270 diff --git a/arch/x86/include/asm/pgtable_32.h b/arch/x86/include/asm/pgtable_32.h
17271 index 9ee3221..b979c6b 100644
17272 --- a/arch/x86/include/asm/pgtable_32.h
17273 +++ b/arch/x86/include/asm/pgtable_32.h
17274 @@ -25,9 +25,6 @@
17275 struct mm_struct;
17276 struct vm_area_struct;
17277
17278 -extern pgd_t swapper_pg_dir[1024];
17279 -extern pgd_t initial_page_table[1024];
17280 -
17281 static inline void pgtable_cache_init(void) { }
17282 static inline void check_pgt_cache(void) { }
17283 void paging_init(void);
17284 @@ -48,6 +45,12 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17285 # include <asm/pgtable-2level.h>
17286 #endif
17287
17288 +extern pgd_t swapper_pg_dir[PTRS_PER_PGD];
17289 +extern pgd_t initial_page_table[PTRS_PER_PGD];
17290 +#ifdef CONFIG_X86_PAE
17291 +extern pmd_t swapper_pm_dir[PTRS_PER_PGD][PTRS_PER_PMD];
17292 +#endif
17293 +
17294 #if defined(CONFIG_HIGHPTE)
17295 #define pte_offset_map(dir, address) \
17296 ((pte_t *)kmap_atomic(pmd_page(*(dir))) + \
17297 @@ -62,12 +65,17 @@ extern void set_pmd_pfn(unsigned long, unsigned long, pgprot_t);
17298 /* Clear a kernel PTE and flush it from the TLB */
17299 #define kpte_clear_flush(ptep, vaddr) \
17300 do { \
17301 + pax_open_kernel(); \
17302 pte_clear(&init_mm, (vaddr), (ptep)); \
17303 + pax_close_kernel(); \
17304 __flush_tlb_one((vaddr)); \
17305 } while (0)
17306
17307 #endif /* !__ASSEMBLY__ */
17308
17309 +#define HAVE_ARCH_UNMAPPED_AREA
17310 +#define HAVE_ARCH_UNMAPPED_AREA_TOPDOWN
17311 +
17312 /*
17313 * kern_addr_valid() is (1) for FLATMEM and (0) for
17314 * SPARSEMEM and DISCONTIGMEM
17315 diff --git a/arch/x86/include/asm/pgtable_32_types.h b/arch/x86/include/asm/pgtable_32_types.h
17316 index ed5903b..c7fe163 100644
17317 --- a/arch/x86/include/asm/pgtable_32_types.h
17318 +++ b/arch/x86/include/asm/pgtable_32_types.h
17319 @@ -8,7 +8,7 @@
17320 */
17321 #ifdef CONFIG_X86_PAE
17322 # include <asm/pgtable-3level_types.h>
17323 -# define PMD_SIZE (1UL << PMD_SHIFT)
17324 +# define PMD_SIZE (_AC(1, UL) << PMD_SHIFT)
17325 # define PMD_MASK (~(PMD_SIZE - 1))
17326 #else
17327 # include <asm/pgtable-2level_types.h>
17328 @@ -46,6 +46,19 @@ extern bool __vmalloc_start_set; /* set once high_memory is set */
17329 # define VMALLOC_END (FIXADDR_START - 2 * PAGE_SIZE)
17330 #endif
17331
17332 +#ifdef CONFIG_PAX_KERNEXEC
17333 +#ifndef __ASSEMBLY__
17334 +extern unsigned char MODULES_EXEC_VADDR[];
17335 +extern unsigned char MODULES_EXEC_END[];
17336 +#endif
17337 +#include <asm/boot.h>
17338 +#define ktla_ktva(addr) (addr + LOAD_PHYSICAL_ADDR + PAGE_OFFSET)
17339 +#define ktva_ktla(addr) (addr - LOAD_PHYSICAL_ADDR - PAGE_OFFSET)
17340 +#else
17341 +#define ktla_ktva(addr) (addr)
17342 +#define ktva_ktla(addr) (addr)
17343 +#endif
17344 +
17345 #define MODULES_VADDR VMALLOC_START
17346 #define MODULES_END VMALLOC_END
17347 #define MODULES_LEN (MODULES_VADDR - MODULES_END)
17348 diff --git a/arch/x86/include/asm/pgtable_64.h b/arch/x86/include/asm/pgtable_64.h
17349 index e22c1db..23a625a 100644
17350 --- a/arch/x86/include/asm/pgtable_64.h
17351 +++ b/arch/x86/include/asm/pgtable_64.h
17352 @@ -16,10 +16,14 @@
17353
17354 extern pud_t level3_kernel_pgt[512];
17355 extern pud_t level3_ident_pgt[512];
17356 +extern pud_t level3_vmalloc_start_pgt[512];
17357 +extern pud_t level3_vmalloc_end_pgt[512];
17358 +extern pud_t level3_vmemmap_pgt[512];
17359 +extern pud_t level2_vmemmap_pgt[512];
17360 extern pmd_t level2_kernel_pgt[512];
17361 extern pmd_t level2_fixmap_pgt[512];
17362 -extern pmd_t level2_ident_pgt[512];
17363 -extern pgd_t init_level4_pgt[];
17364 +extern pmd_t level2_ident_pgt[512*2];
17365 +extern pgd_t init_level4_pgt[512];
17366
17367 #define swapper_pg_dir init_level4_pgt
17368
17369 @@ -61,7 +65,9 @@ static inline void native_set_pte_atomic(pte_t *ptep, pte_t pte)
17370
17371 static inline void native_set_pmd(pmd_t *pmdp, pmd_t pmd)
17372 {
17373 + pax_open_kernel();
17374 *pmdp = pmd;
17375 + pax_close_kernel();
17376 }
17377
17378 static inline void native_pmd_clear(pmd_t *pmd)
17379 @@ -97,7 +103,9 @@ static inline pmd_t native_pmdp_get_and_clear(pmd_t *xp)
17380
17381 static inline void native_set_pud(pud_t *pudp, pud_t pud)
17382 {
17383 + pax_open_kernel();
17384 *pudp = pud;
17385 + pax_close_kernel();
17386 }
17387
17388 static inline void native_pud_clear(pud_t *pud)
17389 @@ -107,6 +115,13 @@ static inline void native_pud_clear(pud_t *pud)
17390
17391 static inline void native_set_pgd(pgd_t *pgdp, pgd_t pgd)
17392 {
17393 + pax_open_kernel();
17394 + *pgdp = pgd;
17395 + pax_close_kernel();
17396 +}
17397 +
17398 +static inline void native_set_pgd_batched(pgd_t *pgdp, pgd_t pgd)
17399 +{
17400 *pgdp = pgd;
17401 }
17402
17403 diff --git a/arch/x86/include/asm/pgtable_64_types.h b/arch/x86/include/asm/pgtable_64_types.h
17404 index 2d88344..4679fc3 100644
17405 --- a/arch/x86/include/asm/pgtable_64_types.h
17406 +++ b/arch/x86/include/asm/pgtable_64_types.h
17407 @@ -61,6 +61,11 @@ typedef struct { pteval_t pte; } pte_t;
17408 #define MODULES_VADDR _AC(0xffffffffa0000000, UL)
17409 #define MODULES_END _AC(0xffffffffff000000, UL)
17410 #define MODULES_LEN (MODULES_END - MODULES_VADDR)
17411 +#define MODULES_EXEC_VADDR MODULES_VADDR
17412 +#define MODULES_EXEC_END MODULES_END
17413 +
17414 +#define ktla_ktva(addr) (addr)
17415 +#define ktva_ktla(addr) (addr)
17416
17417 #define EARLY_DYNAMIC_PAGE_TABLES 64
17418
17419 diff --git a/arch/x86/include/asm/pgtable_types.h b/arch/x86/include/asm/pgtable_types.h
17420 index 840c127..a8f297b 100644
17421 --- a/arch/x86/include/asm/pgtable_types.h
17422 +++ b/arch/x86/include/asm/pgtable_types.h
17423 @@ -16,13 +16,12 @@
17424 #define _PAGE_BIT_PSE 7 /* 4 MB (or 2MB) page */
17425 #define _PAGE_BIT_PAT 7 /* on 4KB pages */
17426 #define _PAGE_BIT_GLOBAL 8 /* Global TLB entry PPro+ */
17427 -#define _PAGE_BIT_UNUSED1 9 /* available for programmer */
17428 +#define _PAGE_BIT_SPECIAL 9 /* special mappings, no associated struct page */
17429 #define _PAGE_BIT_IOMAP 10 /* flag used to indicate IO mapping */
17430 #define _PAGE_BIT_HIDDEN 11 /* hidden by kmemcheck */
17431 #define _PAGE_BIT_PAT_LARGE 12 /* On 2MB or 1GB pages */
17432 -#define _PAGE_BIT_SPECIAL _PAGE_BIT_UNUSED1
17433 -#define _PAGE_BIT_CPA_TEST _PAGE_BIT_UNUSED1
17434 -#define _PAGE_BIT_SPLITTING _PAGE_BIT_UNUSED1 /* only valid on a PSE pmd */
17435 +#define _PAGE_BIT_CPA_TEST _PAGE_BIT_SPECIAL
17436 +#define _PAGE_BIT_SPLITTING _PAGE_BIT_SPECIAL /* only valid on a PSE pmd */
17437 #define _PAGE_BIT_NX 63 /* No execute: only valid after cpuid check */
17438
17439 /* If _PAGE_BIT_PRESENT is clear, we use these: */
17440 @@ -40,7 +39,6 @@
17441 #define _PAGE_DIRTY (_AT(pteval_t, 1) << _PAGE_BIT_DIRTY)
17442 #define _PAGE_PSE (_AT(pteval_t, 1) << _PAGE_BIT_PSE)
17443 #define _PAGE_GLOBAL (_AT(pteval_t, 1) << _PAGE_BIT_GLOBAL)
17444 -#define _PAGE_UNUSED1 (_AT(pteval_t, 1) << _PAGE_BIT_UNUSED1)
17445 #define _PAGE_IOMAP (_AT(pteval_t, 1) << _PAGE_BIT_IOMAP)
17446 #define _PAGE_PAT (_AT(pteval_t, 1) << _PAGE_BIT_PAT)
17447 #define _PAGE_PAT_LARGE (_AT(pteval_t, 1) << _PAGE_BIT_PAT_LARGE)
17448 @@ -87,8 +85,10 @@
17449
17450 #if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
17451 #define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_NX)
17452 -#else
17453 +#elif defined(CONFIG_KMEMCHECK) || defined(CONFIG_MEM_SOFT_DIRTY)
17454 #define _PAGE_NX (_AT(pteval_t, 0))
17455 +#else
17456 +#define _PAGE_NX (_AT(pteval_t, 1) << _PAGE_BIT_HIDDEN)
17457 #endif
17458
17459 #define _PAGE_FILE (_AT(pteval_t, 1) << _PAGE_BIT_FILE)
17460 @@ -147,6 +147,9 @@
17461 #define PAGE_READONLY_EXEC __pgprot(_PAGE_PRESENT | _PAGE_USER | \
17462 _PAGE_ACCESSED)
17463
17464 +#define PAGE_READONLY_NOEXEC PAGE_READONLY
17465 +#define PAGE_SHARED_NOEXEC PAGE_SHARED
17466 +
17467 #define __PAGE_KERNEL_EXEC \
17468 (_PAGE_PRESENT | _PAGE_RW | _PAGE_DIRTY | _PAGE_ACCESSED | _PAGE_GLOBAL)
17469 #define __PAGE_KERNEL (__PAGE_KERNEL_EXEC | _PAGE_NX)
17470 @@ -157,7 +160,7 @@
17471 #define __PAGE_KERNEL_WC (__PAGE_KERNEL | _PAGE_CACHE_WC)
17472 #define __PAGE_KERNEL_NOCACHE (__PAGE_KERNEL | _PAGE_PCD | _PAGE_PWT)
17473 #define __PAGE_KERNEL_UC_MINUS (__PAGE_KERNEL | _PAGE_PCD)
17474 -#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RX | _PAGE_USER)
17475 +#define __PAGE_KERNEL_VSYSCALL (__PAGE_KERNEL_RO | _PAGE_USER)
17476 #define __PAGE_KERNEL_VVAR (__PAGE_KERNEL_RO | _PAGE_USER)
17477 #define __PAGE_KERNEL_VVAR_NOCACHE (__PAGE_KERNEL_VVAR | _PAGE_PCD | _PAGE_PWT)
17478 #define __PAGE_KERNEL_LARGE (__PAGE_KERNEL | _PAGE_PSE)
17479 @@ -219,8 +222,8 @@
17480 * bits are combined, this will alow user to access the high address mapped
17481 * VDSO in the presence of CONFIG_COMPAT_VDSO
17482 */
17483 -#define PTE_IDENT_ATTR 0x003 /* PRESENT+RW */
17484 -#define PDE_IDENT_ATTR 0x067 /* PRESENT+RW+USER+DIRTY+ACCESSED */
17485 +#define PTE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17486 +#define PDE_IDENT_ATTR 0x063 /* PRESENT+RW+DIRTY+ACCESSED */
17487 #define PGD_IDENT_ATTR 0x001 /* PRESENT (no other attributes) */
17488 #endif
17489
17490 @@ -258,7 +261,17 @@ static inline pgdval_t pgd_flags(pgd_t pgd)
17491 {
17492 return native_pgd_val(pgd) & PTE_FLAGS_MASK;
17493 }
17494 +#endif
17495
17496 +#if PAGETABLE_LEVELS == 3
17497 +#include <asm-generic/pgtable-nopud.h>
17498 +#endif
17499 +
17500 +#if PAGETABLE_LEVELS == 2
17501 +#include <asm-generic/pgtable-nopmd.h>
17502 +#endif
17503 +
17504 +#ifndef __ASSEMBLY__
17505 #if PAGETABLE_LEVELS > 3
17506 typedef struct { pudval_t pud; } pud_t;
17507
17508 @@ -272,8 +285,6 @@ static inline pudval_t native_pud_val(pud_t pud)
17509 return pud.pud;
17510 }
17511 #else
17512 -#include <asm-generic/pgtable-nopud.h>
17513 -
17514 static inline pudval_t native_pud_val(pud_t pud)
17515 {
17516 return native_pgd_val(pud.pgd);
17517 @@ -293,8 +304,6 @@ static inline pmdval_t native_pmd_val(pmd_t pmd)
17518 return pmd.pmd;
17519 }
17520 #else
17521 -#include <asm-generic/pgtable-nopmd.h>
17522 -
17523 static inline pmdval_t native_pmd_val(pmd_t pmd)
17524 {
17525 return native_pgd_val(pmd.pud.pgd);
17526 @@ -334,7 +343,6 @@ typedef struct page *pgtable_t;
17527
17528 extern pteval_t __supported_pte_mask;
17529 extern void set_nx(void);
17530 -extern int nx_enabled;
17531
17532 #define pgprot_writecombine pgprot_writecombine
17533 extern pgprot_t pgprot_writecombine(pgprot_t prot);
17534 diff --git a/arch/x86/include/asm/preempt.h b/arch/x86/include/asm/preempt.h
17535 index c8b0519..fd29e73 100644
17536 --- a/arch/x86/include/asm/preempt.h
17537 +++ b/arch/x86/include/asm/preempt.h
17538 @@ -87,7 +87,7 @@ static __always_inline void __preempt_count_sub(int val)
17539 */
17540 static __always_inline bool __preempt_count_dec_and_test(void)
17541 {
17542 - GEN_UNARY_RMWcc("decl", __preempt_count, __percpu_arg(0), "e");
17543 + GEN_UNARY_RMWcc("decl", "incl", __preempt_count, __percpu_arg(0), "e");
17544 }
17545
17546 /*
17547 diff --git a/arch/x86/include/asm/processor.h b/arch/x86/include/asm/processor.h
17548 index 7b034a4..4fe3e3f 100644
17549 --- a/arch/x86/include/asm/processor.h
17550 +++ b/arch/x86/include/asm/processor.h
17551 @@ -128,7 +128,7 @@ struct cpuinfo_x86 {
17552 /* Index into per_cpu list: */
17553 u16 cpu_index;
17554 u32 microcode;
17555 -} __attribute__((__aligned__(SMP_CACHE_BYTES)));
17556 +} __attribute__((__aligned__(SMP_CACHE_BYTES))) __randomize_layout;
17557
17558 #define X86_VENDOR_INTEL 0
17559 #define X86_VENDOR_CYRIX 1
17560 @@ -199,9 +199,21 @@ static inline void native_cpuid(unsigned int *eax, unsigned int *ebx,
17561 : "memory");
17562 }
17563
17564 +/* invpcid (%rdx),%rax */
17565 +#define __ASM_INVPCID ".byte 0x66,0x0f,0x38,0x82,0x02"
17566 +
17567 +#define INVPCID_SINGLE_ADDRESS 0UL
17568 +#define INVPCID_SINGLE_CONTEXT 1UL
17569 +#define INVPCID_ALL_GLOBAL 2UL
17570 +#define INVPCID_ALL_MONGLOBAL 3UL
17571 +
17572 +#define PCID_KERNEL 0UL
17573 +#define PCID_USER 1UL
17574 +#define PCID_NOFLUSH (1UL << 63)
17575 +
17576 static inline void load_cr3(pgd_t *pgdir)
17577 {
17578 - write_cr3(__pa(pgdir));
17579 + write_cr3(__pa(pgdir) | PCID_KERNEL);
17580 }
17581
17582 #ifdef CONFIG_X86_32
17583 @@ -283,7 +295,7 @@ struct tss_struct {
17584
17585 } ____cacheline_aligned;
17586
17587 -DECLARE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss);
17588 +extern struct tss_struct init_tss[NR_CPUS];
17589
17590 /*
17591 * Save the original ist values for checking stack pointers during debugging
17592 @@ -453,6 +465,7 @@ struct thread_struct {
17593 unsigned short ds;
17594 unsigned short fsindex;
17595 unsigned short gsindex;
17596 + unsigned short ss;
17597 #endif
17598 #ifdef CONFIG_X86_32
17599 unsigned long ip;
17600 @@ -562,29 +575,8 @@ static inline void load_sp0(struct tss_struct *tss,
17601 extern unsigned long mmu_cr4_features;
17602 extern u32 *trampoline_cr4_features;
17603
17604 -static inline void set_in_cr4(unsigned long mask)
17605 -{
17606 - unsigned long cr4;
17607 -
17608 - mmu_cr4_features |= mask;
17609 - if (trampoline_cr4_features)
17610 - *trampoline_cr4_features = mmu_cr4_features;
17611 - cr4 = read_cr4();
17612 - cr4 |= mask;
17613 - write_cr4(cr4);
17614 -}
17615 -
17616 -static inline void clear_in_cr4(unsigned long mask)
17617 -{
17618 - unsigned long cr4;
17619 -
17620 - mmu_cr4_features &= ~mask;
17621 - if (trampoline_cr4_features)
17622 - *trampoline_cr4_features = mmu_cr4_features;
17623 - cr4 = read_cr4();
17624 - cr4 &= ~mask;
17625 - write_cr4(cr4);
17626 -}
17627 +extern void set_in_cr4(unsigned long mask);
17628 +extern void clear_in_cr4(unsigned long mask);
17629
17630 typedef struct {
17631 unsigned long seg;
17632 @@ -833,11 +825,18 @@ static inline void spin_lock_prefetch(const void *x)
17633 */
17634 #define TASK_SIZE PAGE_OFFSET
17635 #define TASK_SIZE_MAX TASK_SIZE
17636 +
17637 +#ifdef CONFIG_PAX_SEGMEXEC
17638 +#define SEGMEXEC_TASK_SIZE (TASK_SIZE / 2)
17639 +#define STACK_TOP ((current->mm->pax_flags & MF_PAX_SEGMEXEC)?SEGMEXEC_TASK_SIZE:TASK_SIZE)
17640 +#else
17641 #define STACK_TOP TASK_SIZE
17642 -#define STACK_TOP_MAX STACK_TOP
17643 +#endif
17644 +
17645 +#define STACK_TOP_MAX TASK_SIZE
17646
17647 #define INIT_THREAD { \
17648 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
17649 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
17650 .vm86_info = NULL, \
17651 .sysenter_cs = __KERNEL_CS, \
17652 .io_bitmap_ptr = NULL, \
17653 @@ -851,7 +850,7 @@ static inline void spin_lock_prefetch(const void *x)
17654 */
17655 #define INIT_TSS { \
17656 .x86_tss = { \
17657 - .sp0 = sizeof(init_stack) + (long)&init_stack, \
17658 + .sp0 = sizeof(init_stack) + (long)&init_stack - 8, \
17659 .ss0 = __KERNEL_DS, \
17660 .ss1 = __KERNEL_CS, \
17661 .io_bitmap_base = INVALID_IO_BITMAP_OFFSET, \
17662 @@ -862,11 +861,7 @@ static inline void spin_lock_prefetch(const void *x)
17663 extern unsigned long thread_saved_pc(struct task_struct *tsk);
17664
17665 #define THREAD_SIZE_LONGS (THREAD_SIZE/sizeof(unsigned long))
17666 -#define KSTK_TOP(info) \
17667 -({ \
17668 - unsigned long *__ptr = (unsigned long *)(info); \
17669 - (unsigned long)(&__ptr[THREAD_SIZE_LONGS]); \
17670 -})
17671 +#define KSTK_TOP(info) ((container_of(info, struct task_struct, tinfo))->thread.sp0)
17672
17673 /*
17674 * The below -8 is to reserve 8 bytes on top of the ring0 stack.
17675 @@ -881,7 +876,7 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17676 #define task_pt_regs(task) \
17677 ({ \
17678 struct pt_regs *__regs__; \
17679 - __regs__ = (struct pt_regs *)(KSTK_TOP(task_stack_page(task))-8); \
17680 + __regs__ = (struct pt_regs *)((task)->thread.sp0); \
17681 __regs__ - 1; \
17682 })
17683
17684 @@ -891,13 +886,13 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17685 /*
17686 * User space process size. 47bits minus one guard page.
17687 */
17688 -#define TASK_SIZE_MAX ((1UL << 47) - PAGE_SIZE)
17689 +#define TASK_SIZE_MAX ((1UL << TASK_SIZE_MAX_SHIFT) - PAGE_SIZE)
17690
17691 /* This decides where the kernel will search for a free chunk of vm
17692 * space during mmap's.
17693 */
17694 #define IA32_PAGE_OFFSET ((current->personality & ADDR_LIMIT_3GB) ? \
17695 - 0xc0000000 : 0xFFFFe000)
17696 + 0xc0000000 : 0xFFFFf000)
17697
17698 #define TASK_SIZE (test_thread_flag(TIF_ADDR32) ? \
17699 IA32_PAGE_OFFSET : TASK_SIZE_MAX)
17700 @@ -908,11 +903,11 @@ extern unsigned long thread_saved_pc(struct task_struct *tsk);
17701 #define STACK_TOP_MAX TASK_SIZE_MAX
17702
17703 #define INIT_THREAD { \
17704 - .sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
17705 + .sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
17706 }
17707
17708 #define INIT_TSS { \
17709 - .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) \
17710 + .x86_tss.sp0 = (unsigned long)&init_stack + sizeof(init_stack) - 16 \
17711 }
17712
17713 /*
17714 @@ -940,6 +935,10 @@ extern void start_thread(struct pt_regs *regs, unsigned long new_ip,
17715 */
17716 #define TASK_UNMAPPED_BASE (PAGE_ALIGN(TASK_SIZE / 3))
17717
17718 +#ifdef CONFIG_PAX_SEGMEXEC
17719 +#define SEGMEXEC_TASK_UNMAPPED_BASE (PAGE_ALIGN(SEGMEXEC_TASK_SIZE / 3))
17720 +#endif
17721 +
17722 #define KSTK_EIP(task) (task_pt_regs(task)->ip)
17723
17724 /* Get/set a process' ability to use the timestamp counter instruction */
17725 @@ -966,7 +965,7 @@ static inline uint32_t hypervisor_cpuid_base(const char *sig, uint32_t leaves)
17726 return 0;
17727 }
17728
17729 -extern unsigned long arch_align_stack(unsigned long sp);
17730 +#define arch_align_stack(x) ((x) & ~0xfUL)
17731 extern void free_init_pages(char *what, unsigned long begin, unsigned long end);
17732
17733 void default_idle(void);
17734 @@ -976,6 +975,6 @@ bool xen_set_default_idle(void);
17735 #define xen_set_default_idle 0
17736 #endif
17737
17738 -void stop_this_cpu(void *dummy);
17739 +void stop_this_cpu(void *dummy) __noreturn;
17740 void df_debug(struct pt_regs *regs, long error_code);
17741 #endif /* _ASM_X86_PROCESSOR_H */
17742 diff --git a/arch/x86/include/asm/ptrace.h b/arch/x86/include/asm/ptrace.h
17743 index 942a086..6c26446 100644
17744 --- a/arch/x86/include/asm/ptrace.h
17745 +++ b/arch/x86/include/asm/ptrace.h
17746 @@ -85,28 +85,29 @@ static inline unsigned long regs_return_value(struct pt_regs *regs)
17747 }
17748
17749 /*
17750 - * user_mode_vm(regs) determines whether a register set came from user mode.
17751 + * user_mode(regs) determines whether a register set came from user mode.
17752 * This is true if V8086 mode was enabled OR if the register set was from
17753 * protected mode with RPL-3 CS value. This tricky test checks that with
17754 * one comparison. Many places in the kernel can bypass this full check
17755 - * if they have already ruled out V8086 mode, so user_mode(regs) can be used.
17756 + * if they have already ruled out V8086 mode, so user_mode_novm(regs) can
17757 + * be used.
17758 */
17759 -static inline int user_mode(struct pt_regs *regs)
17760 +static inline int user_mode_novm(struct pt_regs *regs)
17761 {
17762 #ifdef CONFIG_X86_32
17763 return (regs->cs & SEGMENT_RPL_MASK) == USER_RPL;
17764 #else
17765 - return !!(regs->cs & 3);
17766 + return !!(regs->cs & SEGMENT_RPL_MASK);
17767 #endif
17768 }
17769
17770 -static inline int user_mode_vm(struct pt_regs *regs)
17771 +static inline int user_mode(struct pt_regs *regs)
17772 {
17773 #ifdef CONFIG_X86_32
17774 return ((regs->cs & SEGMENT_RPL_MASK) | (regs->flags & X86_VM_MASK)) >=
17775 USER_RPL;
17776 #else
17777 - return user_mode(regs);
17778 + return user_mode_novm(regs);
17779 #endif
17780 }
17781
17782 @@ -122,15 +123,16 @@ static inline int v8086_mode(struct pt_regs *regs)
17783 #ifdef CONFIG_X86_64
17784 static inline bool user_64bit_mode(struct pt_regs *regs)
17785 {
17786 + unsigned long cs = regs->cs & 0xffff;
17787 #ifndef CONFIG_PARAVIRT
17788 /*
17789 * On non-paravirt systems, this is the only long mode CPL 3
17790 * selector. We do not allow long mode selectors in the LDT.
17791 */
17792 - return regs->cs == __USER_CS;
17793 + return cs == __USER_CS;
17794 #else
17795 /* Headers are too twisted for this to go in paravirt.h. */
17796 - return regs->cs == __USER_CS || regs->cs == pv_info.extra_user_64bit_cs;
17797 + return cs == __USER_CS || cs == pv_info.extra_user_64bit_cs;
17798 #endif
17799 }
17800
17801 @@ -181,9 +183,11 @@ static inline unsigned long regs_get_register(struct pt_regs *regs,
17802 * Traps from the kernel do not save sp and ss.
17803 * Use the helper function to retrieve sp.
17804 */
17805 - if (offset == offsetof(struct pt_regs, sp) &&
17806 - regs->cs == __KERNEL_CS)
17807 - return kernel_stack_pointer(regs);
17808 + if (offset == offsetof(struct pt_regs, sp)) {
17809 + unsigned long cs = regs->cs & 0xffff;
17810 + if (cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS)
17811 + return kernel_stack_pointer(regs);
17812 + }
17813 #endif
17814 return *(unsigned long *)((unsigned long)regs + offset);
17815 }
17816 diff --git a/arch/x86/include/asm/realmode.h b/arch/x86/include/asm/realmode.h
17817 index 9c6b890..5305f53 100644
17818 --- a/arch/x86/include/asm/realmode.h
17819 +++ b/arch/x86/include/asm/realmode.h
17820 @@ -22,16 +22,14 @@ struct real_mode_header {
17821 #endif
17822 /* APM/BIOS reboot */
17823 u32 machine_real_restart_asm;
17824 -#ifdef CONFIG_X86_64
17825 u32 machine_real_restart_seg;
17826 -#endif
17827 };
17828
17829 /* This must match data at trampoline_32/64.S */
17830 struct trampoline_header {
17831 #ifdef CONFIG_X86_32
17832 u32 start;
17833 - u16 gdt_pad;
17834 + u16 boot_cs;
17835 u16 gdt_limit;
17836 u32 gdt_base;
17837 #else
17838 diff --git a/arch/x86/include/asm/reboot.h b/arch/x86/include/asm/reboot.h
17839 index a82c4f1..ac45053 100644
17840 --- a/arch/x86/include/asm/reboot.h
17841 +++ b/arch/x86/include/asm/reboot.h
17842 @@ -6,13 +6,13 @@
17843 struct pt_regs;
17844
17845 struct machine_ops {
17846 - void (*restart)(char *cmd);
17847 - void (*halt)(void);
17848 - void (*power_off)(void);
17849 + void (* __noreturn restart)(char *cmd);
17850 + void (* __noreturn halt)(void);
17851 + void (* __noreturn power_off)(void);
17852 void (*shutdown)(void);
17853 void (*crash_shutdown)(struct pt_regs *);
17854 - void (*emergency_restart)(void);
17855 -};
17856 + void (* __noreturn emergency_restart)(void);
17857 +} __no_const;
17858
17859 extern struct machine_ops machine_ops;
17860
17861 diff --git a/arch/x86/include/asm/rmwcc.h b/arch/x86/include/asm/rmwcc.h
17862 index 8f7866a..e442f20 100644
17863 --- a/arch/x86/include/asm/rmwcc.h
17864 +++ b/arch/x86/include/asm/rmwcc.h
17865 @@ -3,7 +3,34 @@
17866
17867 #ifdef CC_HAVE_ASM_GOTO
17868
17869 -#define __GEN_RMWcc(fullop, var, cc, ...) \
17870 +#ifdef CONFIG_PAX_REFCOUNT
17871 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
17872 +do { \
17873 + asm_volatile_goto (fullop \
17874 + ";jno 0f\n" \
17875 + fullantiop \
17876 + ";int $4\n0:\n" \
17877 + _ASM_EXTABLE(0b, 0b) \
17878 + ";j" cc " %l[cc_label]" \
17879 + : : "m" (var), ## __VA_ARGS__ \
17880 + : "memory" : cc_label); \
17881 + return 0; \
17882 +cc_label: \
17883 + return 1; \
17884 +} while (0)
17885 +#else
17886 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
17887 +do { \
17888 + asm_volatile_goto (fullop ";j" cc " %l[cc_label]" \
17889 + : : "m" (var), ## __VA_ARGS__ \
17890 + : "memory" : cc_label); \
17891 + return 0; \
17892 +cc_label: \
17893 + return 1; \
17894 +} while (0)
17895 +#endif
17896 +
17897 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
17898 do { \
17899 asm_volatile_goto (fullop "; j" cc " %l[cc_label]" \
17900 : : "m" (var), ## __VA_ARGS__ \
17901 @@ -13,15 +40,46 @@ cc_label: \
17902 return 1; \
17903 } while (0)
17904
17905 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
17906 - __GEN_RMWcc(op " " arg0, var, cc)
17907 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
17908 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
17909
17910 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
17911 - __GEN_RMWcc(op " %1, " arg0, var, cc, vcon (val))
17912 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
17913 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
17914 +
17915 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
17916 + __GEN_RMWcc(op " %1, " arg0, antiop " %1, " arg0, var, cc, vcon (val))
17917 +
17918 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
17919 + __GEN_RMWcc_unchecked(op " %1, " arg0, var, cc, vcon (val))
17920
17921 #else /* !CC_HAVE_ASM_GOTO */
17922
17923 -#define __GEN_RMWcc(fullop, var, cc, ...) \
17924 +#ifdef CONFIG_PAX_REFCOUNT
17925 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
17926 +do { \
17927 + char c; \
17928 + asm volatile (fullop \
17929 + ";jno 0f\n" \
17930 + fullantiop \
17931 + ";int $4\n0:\n" \
17932 + _ASM_EXTABLE(0b, 0b) \
17933 + "; set" cc " %1" \
17934 + : "+m" (var), "=qm" (c) \
17935 + : __VA_ARGS__ : "memory"); \
17936 + return c != 0; \
17937 +} while (0)
17938 +#else
17939 +#define __GEN_RMWcc(fullop, fullantiop, var, cc, ...) \
17940 +do { \
17941 + char c; \
17942 + asm volatile (fullop "; set" cc " %1" \
17943 + : "+m" (var), "=qm" (c) \
17944 + : __VA_ARGS__ : "memory"); \
17945 + return c != 0; \
17946 +} while (0)
17947 +#endif
17948 +
17949 +#define __GEN_RMWcc_unchecked(fullop, var, cc, ...) \
17950 do { \
17951 char c; \
17952 asm volatile (fullop "; set" cc " %1" \
17953 @@ -30,11 +88,17 @@ do { \
17954 return c != 0; \
17955 } while (0)
17956
17957 -#define GEN_UNARY_RMWcc(op, var, arg0, cc) \
17958 - __GEN_RMWcc(op " " arg0, var, cc)
17959 +#define GEN_UNARY_RMWcc(op, antiop, var, arg0, cc) \
17960 + __GEN_RMWcc(op " " arg0, antiop " " arg0, var, cc)
17961 +
17962 +#define GEN_UNARY_RMWcc_unchecked(op, var, arg0, cc) \
17963 + __GEN_RMWcc_unchecked(op " " arg0, var, cc)
17964 +
17965 +#define GEN_BINARY_RMWcc(op, antiop, var, vcon, val, arg0, cc) \
17966 + __GEN_RMWcc(op " %2, " arg0, antiop " %2, " arg0, var, cc, vcon (val))
17967
17968 -#define GEN_BINARY_RMWcc(op, var, vcon, val, arg0, cc) \
17969 - __GEN_RMWcc(op " %2, " arg0, var, cc, vcon (val))
17970 +#define GEN_BINARY_RMWcc_unchecked(op, var, vcon, val, arg0, cc) \
17971 + __GEN_RMWcc_unchecked(op " %2, " arg0, var, cc, vcon (val))
17972
17973 #endif /* CC_HAVE_ASM_GOTO */
17974
17975 diff --git a/arch/x86/include/asm/rwsem.h b/arch/x86/include/asm/rwsem.h
17976 index cad82c9..2e5c5c1 100644
17977 --- a/arch/x86/include/asm/rwsem.h
17978 +++ b/arch/x86/include/asm/rwsem.h
17979 @@ -64,6 +64,14 @@ static inline void __down_read(struct rw_semaphore *sem)
17980 {
17981 asm volatile("# beginning down_read\n\t"
17982 LOCK_PREFIX _ASM_INC "(%1)\n\t"
17983 +
17984 +#ifdef CONFIG_PAX_REFCOUNT
17985 + "jno 0f\n"
17986 + LOCK_PREFIX _ASM_DEC "(%1)\n"
17987 + "int $4\n0:\n"
17988 + _ASM_EXTABLE(0b, 0b)
17989 +#endif
17990 +
17991 /* adds 0x00000001 */
17992 " jns 1f\n"
17993 " call call_rwsem_down_read_failed\n"
17994 @@ -85,6 +93,14 @@ static inline int __down_read_trylock(struct rw_semaphore *sem)
17995 "1:\n\t"
17996 " mov %1,%2\n\t"
17997 " add %3,%2\n\t"
17998 +
17999 +#ifdef CONFIG_PAX_REFCOUNT
18000 + "jno 0f\n"
18001 + "sub %3,%2\n"
18002 + "int $4\n0:\n"
18003 + _ASM_EXTABLE(0b, 0b)
18004 +#endif
18005 +
18006 " jle 2f\n\t"
18007 LOCK_PREFIX " cmpxchg %2,%0\n\t"
18008 " jnz 1b\n\t"
18009 @@ -104,6 +120,14 @@ static inline void __down_write_nested(struct rw_semaphore *sem, int subclass)
18010 long tmp;
18011 asm volatile("# beginning down_write\n\t"
18012 LOCK_PREFIX " xadd %1,(%2)\n\t"
18013 +
18014 +#ifdef CONFIG_PAX_REFCOUNT
18015 + "jno 0f\n"
18016 + "mov %1,(%2)\n"
18017 + "int $4\n0:\n"
18018 + _ASM_EXTABLE(0b, 0b)
18019 +#endif
18020 +
18021 /* adds 0xffff0001, returns the old value */
18022 " test " __ASM_SEL(%w1,%k1) "," __ASM_SEL(%w1,%k1) "\n\t"
18023 /* was the active mask 0 before? */
18024 @@ -155,6 +179,14 @@ static inline void __up_read(struct rw_semaphore *sem)
18025 long tmp;
18026 asm volatile("# beginning __up_read\n\t"
18027 LOCK_PREFIX " xadd %1,(%2)\n\t"
18028 +
18029 +#ifdef CONFIG_PAX_REFCOUNT
18030 + "jno 0f\n"
18031 + "mov %1,(%2)\n"
18032 + "int $4\n0:\n"
18033 + _ASM_EXTABLE(0b, 0b)
18034 +#endif
18035 +
18036 /* subtracts 1, returns the old value */
18037 " jns 1f\n\t"
18038 " call call_rwsem_wake\n" /* expects old value in %edx */
18039 @@ -173,6 +205,14 @@ static inline void __up_write(struct rw_semaphore *sem)
18040 long tmp;
18041 asm volatile("# beginning __up_write\n\t"
18042 LOCK_PREFIX " xadd %1,(%2)\n\t"
18043 +
18044 +#ifdef CONFIG_PAX_REFCOUNT
18045 + "jno 0f\n"
18046 + "mov %1,(%2)\n"
18047 + "int $4\n0:\n"
18048 + _ASM_EXTABLE(0b, 0b)
18049 +#endif
18050 +
18051 /* subtracts 0xffff0001, returns the old value */
18052 " jns 1f\n\t"
18053 " call call_rwsem_wake\n" /* expects old value in %edx */
18054 @@ -190,6 +230,14 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18055 {
18056 asm volatile("# beginning __downgrade_write\n\t"
18057 LOCK_PREFIX _ASM_ADD "%2,(%1)\n\t"
18058 +
18059 +#ifdef CONFIG_PAX_REFCOUNT
18060 + "jno 0f\n"
18061 + LOCK_PREFIX _ASM_SUB "%2,(%1)\n"
18062 + "int $4\n0:\n"
18063 + _ASM_EXTABLE(0b, 0b)
18064 +#endif
18065 +
18066 /*
18067 * transitions 0xZZZZ0001 -> 0xYYYY0001 (i386)
18068 * 0xZZZZZZZZ00000001 -> 0xYYYYYYYY00000001 (x86_64)
18069 @@ -208,7 +256,15 @@ static inline void __downgrade_write(struct rw_semaphore *sem)
18070 */
18071 static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18072 {
18073 - asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0"
18074 + asm volatile(LOCK_PREFIX _ASM_ADD "%1,%0\n"
18075 +
18076 +#ifdef CONFIG_PAX_REFCOUNT
18077 + "jno 0f\n"
18078 + LOCK_PREFIX _ASM_SUB "%1,%0\n"
18079 + "int $4\n0:\n"
18080 + _ASM_EXTABLE(0b, 0b)
18081 +#endif
18082 +
18083 : "+m" (sem->count)
18084 : "er" (delta));
18085 }
18086 @@ -218,7 +274,7 @@ static inline void rwsem_atomic_add(long delta, struct rw_semaphore *sem)
18087 */
18088 static inline long rwsem_atomic_update(long delta, struct rw_semaphore *sem)
18089 {
18090 - return delta + xadd(&sem->count, delta);
18091 + return delta + xadd_check_overflow(&sem->count, delta);
18092 }
18093
18094 #endif /* __KERNEL__ */
18095 diff --git a/arch/x86/include/asm/segment.h b/arch/x86/include/asm/segment.h
18096 index 6f1c3a8..7744f19 100644
18097 --- a/arch/x86/include/asm/segment.h
18098 +++ b/arch/x86/include/asm/segment.h
18099 @@ -64,10 +64,15 @@
18100 * 26 - ESPFIX small SS
18101 * 27 - per-cpu [ offset to per-cpu data area ]
18102 * 28 - stack_canary-20 [ for stack protector ]
18103 - * 29 - unused
18104 - * 30 - unused
18105 + * 29 - PCI BIOS CS
18106 + * 30 - PCI BIOS DS
18107 * 31 - TSS for double fault handler
18108 */
18109 +#define GDT_ENTRY_KERNEXEC_EFI_CS (1)
18110 +#define GDT_ENTRY_KERNEXEC_EFI_DS (2)
18111 +#define __KERNEXEC_EFI_CS (GDT_ENTRY_KERNEXEC_EFI_CS*8)
18112 +#define __KERNEXEC_EFI_DS (GDT_ENTRY_KERNEXEC_EFI_DS*8)
18113 +
18114 #define GDT_ENTRY_TLS_MIN 6
18115 #define GDT_ENTRY_TLS_MAX (GDT_ENTRY_TLS_MIN + GDT_ENTRY_TLS_ENTRIES - 1)
18116
18117 @@ -79,6 +84,8 @@
18118
18119 #define GDT_ENTRY_KERNEL_CS (GDT_ENTRY_KERNEL_BASE+0)
18120
18121 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS (4)
18122 +
18123 #define GDT_ENTRY_KERNEL_DS (GDT_ENTRY_KERNEL_BASE+1)
18124
18125 #define GDT_ENTRY_TSS (GDT_ENTRY_KERNEL_BASE+4)
18126 @@ -104,6 +111,12 @@
18127 #define __KERNEL_STACK_CANARY 0
18128 #endif
18129
18130 +#define GDT_ENTRY_PCIBIOS_CS (GDT_ENTRY_KERNEL_BASE+17)
18131 +#define __PCIBIOS_CS (GDT_ENTRY_PCIBIOS_CS * 8)
18132 +
18133 +#define GDT_ENTRY_PCIBIOS_DS (GDT_ENTRY_KERNEL_BASE+18)
18134 +#define __PCIBIOS_DS (GDT_ENTRY_PCIBIOS_DS * 8)
18135 +
18136 #define GDT_ENTRY_DOUBLEFAULT_TSS 31
18137
18138 /*
18139 @@ -141,7 +154,7 @@
18140 */
18141
18142 /* Matches PNP_CS32 and PNP_CS16 (they must be consecutive) */
18143 -#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xf4) == GDT_ENTRY_PNPBIOS_BASE * 8)
18144 +#define SEGMENT_IS_PNP_CODE(x) (((x) & 0xFFFCU) == PNP_CS32 || ((x) & 0xFFFCU) == PNP_CS16)
18145
18146
18147 #else
18148 @@ -165,6 +178,8 @@
18149 #define __USER32_CS (GDT_ENTRY_DEFAULT_USER32_CS*8+3)
18150 #define __USER32_DS __USER_DS
18151
18152 +#define GDT_ENTRY_KERNEXEC_KERNEL_CS 7
18153 +
18154 #define GDT_ENTRY_TSS 8 /* needs two entries */
18155 #define GDT_ENTRY_LDT 10 /* needs two entries */
18156 #define GDT_ENTRY_TLS_MIN 12
18157 @@ -173,6 +188,8 @@
18158 #define GDT_ENTRY_PER_CPU 15 /* Abused to load per CPU data from limit */
18159 #define __PER_CPU_SEG (GDT_ENTRY_PER_CPU * 8 + 3)
18160
18161 +#define GDT_ENTRY_UDEREF_KERNEL_DS 16
18162 +
18163 /* TLS indexes for 64bit - hardcoded in arch_prctl */
18164 #define FS_TLS 0
18165 #define GS_TLS 1
18166 @@ -180,12 +197,14 @@
18167 #define GS_TLS_SEL ((GDT_ENTRY_TLS_MIN+GS_TLS)*8 + 3)
18168 #define FS_TLS_SEL ((GDT_ENTRY_TLS_MIN+FS_TLS)*8 + 3)
18169
18170 -#define GDT_ENTRIES 16
18171 +#define GDT_ENTRIES 17
18172
18173 #endif
18174
18175 #define __KERNEL_CS (GDT_ENTRY_KERNEL_CS*8)
18176 +#define __KERNEXEC_KERNEL_CS (GDT_ENTRY_KERNEXEC_KERNEL_CS*8)
18177 #define __KERNEL_DS (GDT_ENTRY_KERNEL_DS*8)
18178 +#define __UDEREF_KERNEL_DS (GDT_ENTRY_UDEREF_KERNEL_DS*8)
18179 #define __USER_DS (GDT_ENTRY_DEFAULT_USER_DS*8+3)
18180 #define __USER_CS (GDT_ENTRY_DEFAULT_USER_CS*8+3)
18181 #ifndef CONFIG_PARAVIRT
18182 @@ -268,7 +287,7 @@ static inline unsigned long get_limit(unsigned long segment)
18183 {
18184 unsigned long __limit;
18185 asm("lsll %1,%0" : "=r" (__limit) : "r" (segment));
18186 - return __limit + 1;
18187 + return __limit;
18188 }
18189
18190 #endif /* !__ASSEMBLY__ */
18191 diff --git a/arch/x86/include/asm/smap.h b/arch/x86/include/asm/smap.h
18192 index 8d3120f..352b440 100644
18193 --- a/arch/x86/include/asm/smap.h
18194 +++ b/arch/x86/include/asm/smap.h
18195 @@ -25,11 +25,40 @@
18196
18197 #include <asm/alternative-asm.h>
18198
18199 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18200 +#define ASM_PAX_OPEN_USERLAND \
18201 + 661: jmp 663f; \
18202 + .pushsection .altinstr_replacement, "a" ; \
18203 + 662: pushq %rax; nop; \
18204 + .popsection ; \
18205 + .pushsection .altinstructions, "a" ; \
18206 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18207 + .popsection ; \
18208 + call __pax_open_userland; \
18209 + popq %rax; \
18210 + 663:
18211 +
18212 +#define ASM_PAX_CLOSE_USERLAND \
18213 + 661: jmp 663f; \
18214 + .pushsection .altinstr_replacement, "a" ; \
18215 + 662: pushq %rax; nop; \
18216 + .popsection; \
18217 + .pushsection .altinstructions, "a" ; \
18218 + altinstruction_entry 661b, 662b, X86_FEATURE_STRONGUDEREF, 2, 2;\
18219 + .popsection; \
18220 + call __pax_close_userland; \
18221 + popq %rax; \
18222 + 663:
18223 +#else
18224 +#define ASM_PAX_OPEN_USERLAND
18225 +#define ASM_PAX_CLOSE_USERLAND
18226 +#endif
18227 +
18228 #ifdef CONFIG_X86_SMAP
18229
18230 #define ASM_CLAC \
18231 661: ASM_NOP3 ; \
18232 - .pushsection .altinstr_replacement, "ax" ; \
18233 + .pushsection .altinstr_replacement, "a" ; \
18234 662: __ASM_CLAC ; \
18235 .popsection ; \
18236 .pushsection .altinstructions, "a" ; \
18237 @@ -38,7 +67,7 @@
18238
18239 #define ASM_STAC \
18240 661: ASM_NOP3 ; \
18241 - .pushsection .altinstr_replacement, "ax" ; \
18242 + .pushsection .altinstr_replacement, "a" ; \
18243 662: __ASM_STAC ; \
18244 .popsection ; \
18245 .pushsection .altinstructions, "a" ; \
18246 @@ -56,6 +85,37 @@
18247
18248 #include <asm/alternative.h>
18249
18250 +#define __HAVE_ARCH_PAX_OPEN_USERLAND
18251 +#define __HAVE_ARCH_PAX_CLOSE_USERLAND
18252 +
18253 +extern void __pax_open_userland(void);
18254 +static __always_inline unsigned long pax_open_userland(void)
18255 +{
18256 +
18257 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18258 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[open]", X86_FEATURE_STRONGUDEREF)
18259 + :
18260 + : [open] "i" (__pax_open_userland)
18261 + : "memory", "rax");
18262 +#endif
18263 +
18264 + return 0;
18265 +}
18266 +
18267 +extern void __pax_close_userland(void);
18268 +static __always_inline unsigned long pax_close_userland(void)
18269 +{
18270 +
18271 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18272 + asm volatile(ALTERNATIVE(ASM_NOP5, "call %P[close]", X86_FEATURE_STRONGUDEREF)
18273 + :
18274 + : [close] "i" (__pax_close_userland)
18275 + : "memory", "rax");
18276 +#endif
18277 +
18278 + return 0;
18279 +}
18280 +
18281 #ifdef CONFIG_X86_SMAP
18282
18283 static __always_inline void clac(void)
18284 diff --git a/arch/x86/include/asm/smp.h b/arch/x86/include/asm/smp.h
18285 index 4137890..03fa172 100644
18286 --- a/arch/x86/include/asm/smp.h
18287 +++ b/arch/x86/include/asm/smp.h
18288 @@ -36,7 +36,7 @@ DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_core_map);
18289 /* cpus sharing the last level cache: */
18290 DECLARE_PER_CPU_READ_MOSTLY(cpumask_var_t, cpu_llc_shared_map);
18291 DECLARE_PER_CPU_READ_MOSTLY(u16, cpu_llc_id);
18292 -DECLARE_PER_CPU_READ_MOSTLY(int, cpu_number);
18293 +DECLARE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
18294
18295 static inline struct cpumask *cpu_sibling_mask(int cpu)
18296 {
18297 @@ -79,7 +79,7 @@ struct smp_ops {
18298
18299 void (*send_call_func_ipi)(const struct cpumask *mask);
18300 void (*send_call_func_single_ipi)(int cpu);
18301 -};
18302 +} __no_const;
18303
18304 /* Globals due to paravirt */
18305 extern void set_cpu_sibling_map(int cpu);
18306 @@ -191,14 +191,8 @@ extern unsigned disabled_cpus;
18307 extern int safe_smp_processor_id(void);
18308
18309 #elif defined(CONFIG_X86_64_SMP)
18310 -#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18311 -
18312 -#define stack_smp_processor_id() \
18313 -({ \
18314 - struct thread_info *ti; \
18315 - __asm__("andq %%rsp,%0; ":"=r" (ti) : "0" (CURRENT_MASK)); \
18316 - ti->cpu; \
18317 -})
18318 +#define raw_smp_processor_id() (this_cpu_read(cpu_number))
18319 +#define stack_smp_processor_id() raw_smp_processor_id()
18320 #define safe_smp_processor_id() smp_processor_id()
18321
18322 #endif
18323 diff --git a/arch/x86/include/asm/spinlock.h b/arch/x86/include/asm/spinlock.h
18324 index bf156de..1a782ab 100644
18325 --- a/arch/x86/include/asm/spinlock.h
18326 +++ b/arch/x86/include/asm/spinlock.h
18327 @@ -223,6 +223,14 @@ static inline int arch_write_can_lock(arch_rwlock_t *lock)
18328 static inline void arch_read_lock(arch_rwlock_t *rw)
18329 {
18330 asm volatile(LOCK_PREFIX READ_LOCK_SIZE(dec) " (%0)\n\t"
18331 +
18332 +#ifdef CONFIG_PAX_REFCOUNT
18333 + "jno 0f\n"
18334 + LOCK_PREFIX READ_LOCK_SIZE(inc) " (%0)\n"
18335 + "int $4\n0:\n"
18336 + _ASM_EXTABLE(0b, 0b)
18337 +#endif
18338 +
18339 "jns 1f\n"
18340 "call __read_lock_failed\n\t"
18341 "1:\n"
18342 @@ -232,6 +240,14 @@ static inline void arch_read_lock(arch_rwlock_t *rw)
18343 static inline void arch_write_lock(arch_rwlock_t *rw)
18344 {
18345 asm volatile(LOCK_PREFIX WRITE_LOCK_SUB(%1) "(%0)\n\t"
18346 +
18347 +#ifdef CONFIG_PAX_REFCOUNT
18348 + "jno 0f\n"
18349 + LOCK_PREFIX WRITE_LOCK_ADD(%1) "(%0)\n"
18350 + "int $4\n0:\n"
18351 + _ASM_EXTABLE(0b, 0b)
18352 +#endif
18353 +
18354 "jz 1f\n"
18355 "call __write_lock_failed\n\t"
18356 "1:\n"
18357 @@ -261,13 +277,29 @@ static inline int arch_write_trylock(arch_rwlock_t *lock)
18358
18359 static inline void arch_read_unlock(arch_rwlock_t *rw)
18360 {
18361 - asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0"
18362 + asm volatile(LOCK_PREFIX READ_LOCK_SIZE(inc) " %0\n"
18363 +
18364 +#ifdef CONFIG_PAX_REFCOUNT
18365 + "jno 0f\n"
18366 + LOCK_PREFIX READ_LOCK_SIZE(dec) " %0\n"
18367 + "int $4\n0:\n"
18368 + _ASM_EXTABLE(0b, 0b)
18369 +#endif
18370 +
18371 :"+m" (rw->lock) : : "memory");
18372 }
18373
18374 static inline void arch_write_unlock(arch_rwlock_t *rw)
18375 {
18376 - asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0"
18377 + asm volatile(LOCK_PREFIX WRITE_LOCK_ADD(%1) "%0\n"
18378 +
18379 +#ifdef CONFIG_PAX_REFCOUNT
18380 + "jno 0f\n"
18381 + LOCK_PREFIX WRITE_LOCK_SUB(%1) "%0\n"
18382 + "int $4\n0:\n"
18383 + _ASM_EXTABLE(0b, 0b)
18384 +#endif
18385 +
18386 : "+m" (rw->write) : "i" (RW_LOCK_BIAS) : "memory");
18387 }
18388
18389 diff --git a/arch/x86/include/asm/stackprotector.h b/arch/x86/include/asm/stackprotector.h
18390 index 6a99859..03cb807 100644
18391 --- a/arch/x86/include/asm/stackprotector.h
18392 +++ b/arch/x86/include/asm/stackprotector.h
18393 @@ -47,7 +47,7 @@
18394 * head_32 for boot CPU and setup_per_cpu_areas() for others.
18395 */
18396 #define GDT_STACK_CANARY_INIT \
18397 - [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x18),
18398 + [GDT_ENTRY_STACK_CANARY] = GDT_ENTRY_INIT(0x4090, 0, 0x17),
18399
18400 /*
18401 * Initialize the stackprotector canary value.
18402 @@ -112,7 +112,7 @@ static inline void setup_stack_canary_segment(int cpu)
18403
18404 static inline void load_stack_canary_segment(void)
18405 {
18406 -#ifdef CONFIG_X86_32
18407 +#if defined(CONFIG_X86_32) && !defined(CONFIG_PAX_MEMORY_UDEREF)
18408 asm volatile ("mov %0, %%gs" : : "r" (0));
18409 #endif
18410 }
18411 diff --git a/arch/x86/include/asm/stacktrace.h b/arch/x86/include/asm/stacktrace.h
18412 index 70bbe39..4ae2bd4 100644
18413 --- a/arch/x86/include/asm/stacktrace.h
18414 +++ b/arch/x86/include/asm/stacktrace.h
18415 @@ -11,28 +11,20 @@
18416
18417 extern int kstack_depth_to_print;
18418
18419 -struct thread_info;
18420 +struct task_struct;
18421 struct stacktrace_ops;
18422
18423 -typedef unsigned long (*walk_stack_t)(struct thread_info *tinfo,
18424 - unsigned long *stack,
18425 - unsigned long bp,
18426 - const struct stacktrace_ops *ops,
18427 - void *data,
18428 - unsigned long *end,
18429 - int *graph);
18430 +typedef unsigned long walk_stack_t(struct task_struct *task,
18431 + void *stack_start,
18432 + unsigned long *stack,
18433 + unsigned long bp,
18434 + const struct stacktrace_ops *ops,
18435 + void *data,
18436 + unsigned long *end,
18437 + int *graph);
18438
18439 -extern unsigned long
18440 -print_context_stack(struct thread_info *tinfo,
18441 - unsigned long *stack, unsigned long bp,
18442 - const struct stacktrace_ops *ops, void *data,
18443 - unsigned long *end, int *graph);
18444 -
18445 -extern unsigned long
18446 -print_context_stack_bp(struct thread_info *tinfo,
18447 - unsigned long *stack, unsigned long bp,
18448 - const struct stacktrace_ops *ops, void *data,
18449 - unsigned long *end, int *graph);
18450 +extern walk_stack_t print_context_stack;
18451 +extern walk_stack_t print_context_stack_bp;
18452
18453 /* Generic stack tracer with callbacks */
18454
18455 @@ -40,7 +32,7 @@ struct stacktrace_ops {
18456 void (*address)(void *data, unsigned long address, int reliable);
18457 /* On negative return stop dumping */
18458 int (*stack)(void *data, char *name);
18459 - walk_stack_t walk_stack;
18460 + walk_stack_t *walk_stack;
18461 };
18462
18463 void dump_trace(struct task_struct *tsk, struct pt_regs *regs,
18464 diff --git a/arch/x86/include/asm/switch_to.h b/arch/x86/include/asm/switch_to.h
18465 index d7f3b3b..3cc39f1 100644
18466 --- a/arch/x86/include/asm/switch_to.h
18467 +++ b/arch/x86/include/asm/switch_to.h
18468 @@ -108,7 +108,7 @@ do { \
18469 "call __switch_to\n\t" \
18470 "movq "__percpu_arg([current_task])",%%rsi\n\t" \
18471 __switch_canary \
18472 - "movq %P[thread_info](%%rsi),%%r8\n\t" \
18473 + "movq "__percpu_arg([thread_info])",%%r8\n\t" \
18474 "movq %%rax,%%rdi\n\t" \
18475 "testl %[_tif_fork],%P[ti_flags](%%r8)\n\t" \
18476 "jnz ret_from_fork\n\t" \
18477 @@ -119,7 +119,7 @@ do { \
18478 [threadrsp] "i" (offsetof(struct task_struct, thread.sp)), \
18479 [ti_flags] "i" (offsetof(struct thread_info, flags)), \
18480 [_tif_fork] "i" (_TIF_FORK), \
18481 - [thread_info] "i" (offsetof(struct task_struct, stack)), \
18482 + [thread_info] "m" (current_tinfo), \
18483 [current_task] "m" (current_task) \
18484 __switch_canary_iparam \
18485 : "memory", "cc" __EXTRA_CLOBBER)
18486 diff --git a/arch/x86/include/asm/thread_info.h b/arch/x86/include/asm/thread_info.h
18487 index 3ba3de4..6c113b2 100644
18488 --- a/arch/x86/include/asm/thread_info.h
18489 +++ b/arch/x86/include/asm/thread_info.h
18490 @@ -10,6 +10,7 @@
18491 #include <linux/compiler.h>
18492 #include <asm/page.h>
18493 #include <asm/types.h>
18494 +#include <asm/percpu.h>
18495
18496 /*
18497 * low level task data that entry.S needs immediate access to
18498 @@ -23,7 +24,6 @@ struct exec_domain;
18499 #include <linux/atomic.h>
18500
18501 struct thread_info {
18502 - struct task_struct *task; /* main task structure */
18503 struct exec_domain *exec_domain; /* execution domain */
18504 __u32 flags; /* low level flags */
18505 __u32 status; /* thread synchronous flags */
18506 @@ -32,19 +32,13 @@ struct thread_info {
18507 mm_segment_t addr_limit;
18508 struct restart_block restart_block;
18509 void __user *sysenter_return;
18510 -#ifdef CONFIG_X86_32
18511 - unsigned long previous_esp; /* ESP of the previous stack in
18512 - case of nested (IRQ) stacks
18513 - */
18514 - __u8 supervisor_stack[0];
18515 -#endif
18516 + unsigned long lowest_stack;
18517 unsigned int sig_on_uaccess_error:1;
18518 unsigned int uaccess_err:1; /* uaccess failed */
18519 };
18520
18521 -#define INIT_THREAD_INFO(tsk) \
18522 +#define INIT_THREAD_INFO \
18523 { \
18524 - .task = &tsk, \
18525 .exec_domain = &default_exec_domain, \
18526 .flags = 0, \
18527 .cpu = 0, \
18528 @@ -55,7 +49,7 @@ struct thread_info {
18529 }, \
18530 }
18531
18532 -#define init_thread_info (init_thread_union.thread_info)
18533 +#define init_thread_info (init_thread_union.stack)
18534 #define init_stack (init_thread_union.stack)
18535
18536 #else /* !__ASSEMBLY__ */
18537 @@ -95,6 +89,7 @@ struct thread_info {
18538 #define TIF_SYSCALL_TRACEPOINT 28 /* syscall tracepoint instrumentation */
18539 #define TIF_ADDR32 29 /* 32-bit address space on 64 bits */
18540 #define TIF_X32 30 /* 32-bit native x86-64 binary */
18541 +#define TIF_GRSEC_SETXID 31 /* update credentials on syscall entry/exit */
18542
18543 #define _TIF_SYSCALL_TRACE (1 << TIF_SYSCALL_TRACE)
18544 #define _TIF_NOTIFY_RESUME (1 << TIF_NOTIFY_RESUME)
18545 @@ -118,17 +113,18 @@ struct thread_info {
18546 #define _TIF_SYSCALL_TRACEPOINT (1 << TIF_SYSCALL_TRACEPOINT)
18547 #define _TIF_ADDR32 (1 << TIF_ADDR32)
18548 #define _TIF_X32 (1 << TIF_X32)
18549 +#define _TIF_GRSEC_SETXID (1 << TIF_GRSEC_SETXID)
18550
18551 /* work to do in syscall_trace_enter() */
18552 #define _TIF_WORK_SYSCALL_ENTRY \
18553 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_EMU | _TIF_SYSCALL_AUDIT | \
18554 _TIF_SECCOMP | _TIF_SINGLESTEP | _TIF_SYSCALL_TRACEPOINT | \
18555 - _TIF_NOHZ)
18556 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
18557
18558 /* work to do in syscall_trace_leave() */
18559 #define _TIF_WORK_SYSCALL_EXIT \
18560 (_TIF_SYSCALL_TRACE | _TIF_SYSCALL_AUDIT | _TIF_SINGLESTEP | \
18561 - _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ)
18562 + _TIF_SYSCALL_TRACEPOINT | _TIF_NOHZ | _TIF_GRSEC_SETXID)
18563
18564 /* work to do on interrupt/exception return */
18565 #define _TIF_WORK_MASK \
18566 @@ -139,7 +135,7 @@ struct thread_info {
18567 /* work to do on any return to user space */
18568 #define _TIF_ALLWORK_MASK \
18569 ((0x0000FFFF & ~_TIF_SECCOMP) | _TIF_SYSCALL_TRACEPOINT | \
18570 - _TIF_NOHZ)
18571 + _TIF_NOHZ | _TIF_GRSEC_SETXID)
18572
18573 /* Only used for 64 bit */
18574 #define _TIF_DO_NOTIFY_MASK \
18575 @@ -153,45 +149,40 @@ struct thread_info {
18576 #define _TIF_WORK_CTXSW_PREV (_TIF_WORK_CTXSW|_TIF_USER_RETURN_NOTIFY)
18577 #define _TIF_WORK_CTXSW_NEXT (_TIF_WORK_CTXSW)
18578
18579 -#ifdef CONFIG_X86_32
18580 -
18581 -#define STACK_WARN (THREAD_SIZE/8)
18582 -/*
18583 - * macros/functions for gaining access to the thread information structure
18584 - *
18585 - * preempt_count needs to be 1 initially, until the scheduler is functional.
18586 - */
18587 -#ifndef __ASSEMBLY__
18588 -
18589 -
18590 -/* how to get the current stack pointer from C */
18591 -register unsigned long current_stack_pointer asm("esp") __used;
18592 -
18593 -/* how to get the thread information struct from C */
18594 -static inline struct thread_info *current_thread_info(void)
18595 -{
18596 - return (struct thread_info *)
18597 - (current_stack_pointer & ~(THREAD_SIZE - 1));
18598 -}
18599 -
18600 -#else /* !__ASSEMBLY__ */
18601 -
18602 +#ifdef __ASSEMBLY__
18603 /* how to get the thread information struct from ASM */
18604 #define GET_THREAD_INFO(reg) \
18605 - movl $-THREAD_SIZE, reg; \
18606 - andl %esp, reg
18607 + mov PER_CPU_VAR(current_tinfo), reg
18608
18609 /* use this one if reg already contains %esp */
18610 -#define GET_THREAD_INFO_WITH_ESP(reg) \
18611 - andl $-THREAD_SIZE, reg
18612 +#define GET_THREAD_INFO_WITH_ESP(reg) GET_THREAD_INFO(reg)
18613 +#else
18614 +/* how to get the thread information struct from C */
18615 +DECLARE_PER_CPU(struct thread_info *, current_tinfo);
18616 +
18617 +static __always_inline struct thread_info *current_thread_info(void)
18618 +{
18619 + return this_cpu_read_stable(current_tinfo);
18620 +}
18621 +#endif
18622 +
18623 +#ifdef CONFIG_X86_32
18624 +
18625 +#define STACK_WARN (THREAD_SIZE/8)
18626 +/*
18627 + * macros/functions for gaining access to the thread information structure
18628 + *
18629 + * preempt_count needs to be 1 initially, until the scheduler is functional.
18630 + */
18631 +#ifndef __ASSEMBLY__
18632 +
18633 +/* how to get the current stack pointer from C */
18634 +register unsigned long current_stack_pointer asm("esp") __used;
18635
18636 #endif
18637
18638 #else /* X86_32 */
18639
18640 -#include <asm/percpu.h>
18641 -#define KERNEL_STACK_OFFSET (5*8)
18642 -
18643 /*
18644 * macros/functions for gaining access to the thread information structure
18645 * preempt_count needs to be 1 initially, until the scheduler is functional.
18646 @@ -199,27 +190,8 @@ static inline struct thread_info *current_thread_info(void)
18647 #ifndef __ASSEMBLY__
18648 DECLARE_PER_CPU(unsigned long, kernel_stack);
18649
18650 -static inline struct thread_info *current_thread_info(void)
18651 -{
18652 - struct thread_info *ti;
18653 - ti = (void *)(this_cpu_read_stable(kernel_stack) +
18654 - KERNEL_STACK_OFFSET - THREAD_SIZE);
18655 - return ti;
18656 -}
18657 -
18658 -#else /* !__ASSEMBLY__ */
18659 -
18660 -/* how to get the thread information struct from ASM */
18661 -#define GET_THREAD_INFO(reg) \
18662 - movq PER_CPU_VAR(kernel_stack),reg ; \
18663 - subq $(THREAD_SIZE-KERNEL_STACK_OFFSET),reg
18664 -
18665 -/*
18666 - * Same if PER_CPU_VAR(kernel_stack) is, perhaps with some offset, already in
18667 - * a certain register (to be used in assembler memory operands).
18668 - */
18669 -#define THREAD_INFO(reg, off) KERNEL_STACK_OFFSET+(off)-THREAD_SIZE(reg)
18670 -
18671 +/* how to get the current stack pointer from C */
18672 +register unsigned long current_stack_pointer asm("rsp") __used;
18673 #endif
18674
18675 #endif /* !X86_32 */
18676 @@ -278,5 +250,12 @@ static inline bool is_ia32_task(void)
18677 extern void arch_task_cache_init(void);
18678 extern int arch_dup_task_struct(struct task_struct *dst, struct task_struct *src);
18679 extern void arch_release_task_struct(struct task_struct *tsk);
18680 +
18681 +#define __HAVE_THREAD_FUNCTIONS
18682 +#define task_thread_info(task) (&(task)->tinfo)
18683 +#define task_stack_page(task) ((task)->stack)
18684 +#define setup_thread_stack(p, org) do {} while (0)
18685 +#define end_of_stack(p) ((unsigned long *)task_stack_page(p) + 1)
18686 +
18687 #endif
18688 #endif /* _ASM_X86_THREAD_INFO_H */
18689 diff --git a/arch/x86/include/asm/tlbflush.h b/arch/x86/include/asm/tlbflush.h
18690 index e6d90ba..f81f114 100644
18691 --- a/arch/x86/include/asm/tlbflush.h
18692 +++ b/arch/x86/include/asm/tlbflush.h
18693 @@ -17,18 +17,44 @@
18694
18695 static inline void __native_flush_tlb(void)
18696 {
18697 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
18698 + u64 descriptor[2];
18699 +
18700 + descriptor[0] = PCID_KERNEL;
18701 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_MONGLOBAL) : "memory");
18702 + return;
18703 + }
18704 +
18705 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18706 + if (static_cpu_has(X86_FEATURE_PCID)) {
18707 + unsigned int cpu = raw_get_cpu();
18708 +
18709 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER);
18710 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL);
18711 + raw_put_cpu_no_resched();
18712 + return;
18713 + }
18714 +#endif
18715 +
18716 native_write_cr3(native_read_cr3());
18717 }
18718
18719 static inline void __native_flush_tlb_global_irq_disabled(void)
18720 {
18721 - unsigned long cr4;
18722 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
18723 + u64 descriptor[2];
18724
18725 - cr4 = native_read_cr4();
18726 - /* clear PGE */
18727 - native_write_cr4(cr4 & ~X86_CR4_PGE);
18728 - /* write old PGE again and flush TLBs */
18729 - native_write_cr4(cr4);
18730 + descriptor[0] = PCID_KERNEL;
18731 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_ALL_GLOBAL) : "memory");
18732 + } else {
18733 + unsigned long cr4;
18734 +
18735 + cr4 = native_read_cr4();
18736 + /* clear PGE */
18737 + native_write_cr4(cr4 & ~X86_CR4_PGE);
18738 + /* write old PGE again and flush TLBs */
18739 + native_write_cr4(cr4);
18740 + }
18741 }
18742
18743 static inline void __native_flush_tlb_global(void)
18744 @@ -49,6 +75,41 @@ static inline void __native_flush_tlb_global(void)
18745
18746 static inline void __native_flush_tlb_single(unsigned long addr)
18747 {
18748 + if (static_cpu_has(X86_FEATURE_INVPCID)) {
18749 + u64 descriptor[2];
18750 +
18751 + descriptor[0] = PCID_KERNEL;
18752 + descriptor[1] = addr;
18753 +
18754 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18755 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) || addr >= TASK_SIZE_MAX) {
18756 + if (addr < TASK_SIZE_MAX)
18757 + descriptor[1] += pax_user_shadow_base;
18758 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
18759 + }
18760 +
18761 + descriptor[0] = PCID_USER;
18762 + descriptor[1] = addr;
18763 +#endif
18764 +
18765 + asm volatile(__ASM_INVPCID : : "d"(&descriptor), "a"(INVPCID_SINGLE_ADDRESS) : "memory");
18766 + return;
18767 + }
18768 +
18769 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18770 + if (static_cpu_has(X86_FEATURE_PCID)) {
18771 + unsigned int cpu = raw_get_cpu();
18772 +
18773 + native_write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
18774 + asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
18775 + native_write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
18776 + raw_put_cpu_no_resched();
18777 +
18778 + if (!static_cpu_has(X86_FEATURE_STRONGUDEREF) && addr < TASK_SIZE_MAX)
18779 + addr += pax_user_shadow_base;
18780 + }
18781 +#endif
18782 +
18783 asm volatile("invlpg (%0)" ::"r" (addr) : "memory");
18784 }
18785
18786 diff --git a/arch/x86/include/asm/uaccess.h b/arch/x86/include/asm/uaccess.h
18787 index 8ec57c0..3ee58c9 100644
18788 --- a/arch/x86/include/asm/uaccess.h
18789 +++ b/arch/x86/include/asm/uaccess.h
18790 @@ -7,6 +7,7 @@
18791 #include <linux/compiler.h>
18792 #include <linux/thread_info.h>
18793 #include <linux/string.h>
18794 +#include <linux/spinlock.h>
18795 #include <asm/asm.h>
18796 #include <asm/page.h>
18797 #include <asm/smap.h>
18798 @@ -29,7 +30,12 @@
18799
18800 #define get_ds() (KERNEL_DS)
18801 #define get_fs() (current_thread_info()->addr_limit)
18802 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18803 +void __set_fs(mm_segment_t x);
18804 +void set_fs(mm_segment_t x);
18805 +#else
18806 #define set_fs(x) (current_thread_info()->addr_limit = (x))
18807 +#endif
18808
18809 #define segment_eq(a, b) ((a).seg == (b).seg)
18810
18811 @@ -77,8 +83,34 @@
18812 * checks that the pointer is in the user space range - after calling
18813 * this function, memory access functions may still return -EFAULT.
18814 */
18815 -#define access_ok(type, addr, size) \
18816 - (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
18817 +extern int _cond_resched(void);
18818 +#define __access_ok(type, addr, size) (likely(__range_not_ok(addr, size, user_addr_max()) == 0))
18819 +#define access_ok(type, addr, size) \
18820 +({ \
18821 + long __size = size; \
18822 + unsigned long __addr = (unsigned long)addr; \
18823 + unsigned long __addr_ao = __addr & PAGE_MASK; \
18824 + unsigned long __end_ao = __addr + __size - 1; \
18825 + bool __ret_ao = __range_not_ok(__addr, __size, user_addr_max()) == 0;\
18826 + if (__ret_ao && unlikely((__end_ao ^ __addr_ao) & PAGE_MASK)) { \
18827 + while(__addr_ao <= __end_ao) { \
18828 + char __c_ao; \
18829 + __addr_ao += PAGE_SIZE; \
18830 + if (__size > PAGE_SIZE) \
18831 + _cond_resched(); \
18832 + if (__get_user(__c_ao, (char __user *)__addr)) \
18833 + break; \
18834 + if (type != VERIFY_WRITE) { \
18835 + __addr = __addr_ao; \
18836 + continue; \
18837 + } \
18838 + if (__put_user(__c_ao, (char __user *)__addr)) \
18839 + break; \
18840 + __addr = __addr_ao; \
18841 + } \
18842 + } \
18843 + __ret_ao; \
18844 +})
18845
18846 /*
18847 * The exception table consists of pairs of addresses relative to the
18848 @@ -168,10 +200,12 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18849 register __inttype(*(ptr)) __val_gu asm("%"_ASM_DX); \
18850 __chk_user_ptr(ptr); \
18851 might_fault(); \
18852 + pax_open_userland(); \
18853 asm volatile("call __get_user_%P3" \
18854 : "=a" (__ret_gu), "=r" (__val_gu) \
18855 : "0" (ptr), "i" (sizeof(*(ptr)))); \
18856 (x) = (__typeof__(*(ptr))) __val_gu; \
18857 + pax_close_userland(); \
18858 __ret_gu; \
18859 })
18860
18861 @@ -179,13 +213,21 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18862 asm volatile("call __put_user_" #size : "=a" (__ret_pu) \
18863 : "0" ((typeof(*(ptr)))(x)), "c" (ptr) : "ebx")
18864
18865 -
18866 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
18867 +#define __copyuser_seg "gs;"
18868 +#define __COPYUSER_SET_ES "pushl %%gs; popl %%es\n"
18869 +#define __COPYUSER_RESTORE_ES "pushl %%ss; popl %%es\n"
18870 +#else
18871 +#define __copyuser_seg
18872 +#define __COPYUSER_SET_ES
18873 +#define __COPYUSER_RESTORE_ES
18874 +#endif
18875
18876 #ifdef CONFIG_X86_32
18877 #define __put_user_asm_u64(x, addr, err, errret) \
18878 asm volatile(ASM_STAC "\n" \
18879 - "1: movl %%eax,0(%2)\n" \
18880 - "2: movl %%edx,4(%2)\n" \
18881 + "1: "__copyuser_seg"movl %%eax,0(%2)\n" \
18882 + "2: "__copyuser_seg"movl %%edx,4(%2)\n" \
18883 "3: " ASM_CLAC "\n" \
18884 ".section .fixup,\"ax\"\n" \
18885 "4: movl %3,%0\n" \
18886 @@ -198,8 +240,8 @@ __typeof__(__builtin_choose_expr(sizeof(x) > sizeof(0UL), 0ULL, 0UL))
18887
18888 #define __put_user_asm_ex_u64(x, addr) \
18889 asm volatile(ASM_STAC "\n" \
18890 - "1: movl %%eax,0(%1)\n" \
18891 - "2: movl %%edx,4(%1)\n" \
18892 + "1: "__copyuser_seg"movl %%eax,0(%1)\n" \
18893 + "2: "__copyuser_seg"movl %%edx,4(%1)\n" \
18894 "3: " ASM_CLAC "\n" \
18895 _ASM_EXTABLE_EX(1b, 2b) \
18896 _ASM_EXTABLE_EX(2b, 3b) \
18897 @@ -249,7 +291,8 @@ extern void __put_user_8(void);
18898 __typeof__(*(ptr)) __pu_val; \
18899 __chk_user_ptr(ptr); \
18900 might_fault(); \
18901 - __pu_val = x; \
18902 + __pu_val = (x); \
18903 + pax_open_userland(); \
18904 switch (sizeof(*(ptr))) { \
18905 case 1: \
18906 __put_user_x(1, __pu_val, ptr, __ret_pu); \
18907 @@ -267,6 +310,7 @@ extern void __put_user_8(void);
18908 __put_user_x(X, __pu_val, ptr, __ret_pu); \
18909 break; \
18910 } \
18911 + pax_close_userland(); \
18912 __ret_pu; \
18913 })
18914
18915 @@ -347,8 +391,10 @@ do { \
18916 } while (0)
18917
18918 #define __get_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18919 +do { \
18920 + pax_open_userland(); \
18921 asm volatile(ASM_STAC "\n" \
18922 - "1: mov"itype" %2,%"rtype"1\n" \
18923 + "1: "__copyuser_seg"mov"itype" %2,%"rtype"1\n"\
18924 "2: " ASM_CLAC "\n" \
18925 ".section .fixup,\"ax\"\n" \
18926 "3: mov %3,%0\n" \
18927 @@ -356,8 +402,10 @@ do { \
18928 " jmp 2b\n" \
18929 ".previous\n" \
18930 _ASM_EXTABLE(1b, 3b) \
18931 - : "=r" (err), ltype(x) \
18932 - : "m" (__m(addr)), "i" (errret), "0" (err))
18933 + : "=r" (err), ltype (x) \
18934 + : "m" (__m(addr)), "i" (errret), "0" (err)); \
18935 + pax_close_userland(); \
18936 +} while (0)
18937
18938 #define __get_user_size_ex(x, ptr, size) \
18939 do { \
18940 @@ -381,7 +429,7 @@ do { \
18941 } while (0)
18942
18943 #define __get_user_asm_ex(x, addr, itype, rtype, ltype) \
18944 - asm volatile("1: mov"itype" %1,%"rtype"0\n" \
18945 + asm volatile("1: "__copyuser_seg"mov"itype" %1,%"rtype"0\n"\
18946 "2:\n" \
18947 _ASM_EXTABLE_EX(1b, 2b) \
18948 : ltype(x) : "m" (__m(addr)))
18949 @@ -398,13 +446,24 @@ do { \
18950 int __gu_err; \
18951 unsigned long __gu_val; \
18952 __get_user_size(__gu_val, (ptr), (size), __gu_err, -EFAULT); \
18953 - (x) = (__force __typeof__(*(ptr)))__gu_val; \
18954 + (x) = (__typeof__(*(ptr)))__gu_val; \
18955 __gu_err; \
18956 })
18957
18958 /* FIXME: this hack is definitely wrong -AK */
18959 struct __large_struct { unsigned long buf[100]; };
18960 -#define __m(x) (*(struct __large_struct __user *)(x))
18961 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
18962 +#define ____m(x) \
18963 +({ \
18964 + unsigned long ____x = (unsigned long)(x); \
18965 + if (____x < pax_user_shadow_base) \
18966 + ____x += pax_user_shadow_base; \
18967 + (typeof(x))____x; \
18968 +})
18969 +#else
18970 +#define ____m(x) (x)
18971 +#endif
18972 +#define __m(x) (*(struct __large_struct __user *)____m(x))
18973
18974 /*
18975 * Tell gcc we read from memory instead of writing: this is because
18976 @@ -412,8 +471,10 @@ struct __large_struct { unsigned long buf[100]; };
18977 * aliasing issues.
18978 */
18979 #define __put_user_asm(x, addr, err, itype, rtype, ltype, errret) \
18980 +do { \
18981 + pax_open_userland(); \
18982 asm volatile(ASM_STAC "\n" \
18983 - "1: mov"itype" %"rtype"1,%2\n" \
18984 + "1: "__copyuser_seg"mov"itype" %"rtype"1,%2\n"\
18985 "2: " ASM_CLAC "\n" \
18986 ".section .fixup,\"ax\"\n" \
18987 "3: mov %3,%0\n" \
18988 @@ -421,10 +482,12 @@ struct __large_struct { unsigned long buf[100]; };
18989 ".previous\n" \
18990 _ASM_EXTABLE(1b, 3b) \
18991 : "=r"(err) \
18992 - : ltype(x), "m" (__m(addr)), "i" (errret), "0" (err))
18993 + : ltype (x), "m" (__m(addr)), "i" (errret), "0" (err));\
18994 + pax_close_userland(); \
18995 +} while (0)
18996
18997 #define __put_user_asm_ex(x, addr, itype, rtype, ltype) \
18998 - asm volatile("1: mov"itype" %"rtype"0,%1\n" \
18999 + asm volatile("1: "__copyuser_seg"mov"itype" %"rtype"0,%1\n"\
19000 "2:\n" \
19001 _ASM_EXTABLE_EX(1b, 2b) \
19002 : : ltype(x), "m" (__m(addr)))
19003 @@ -434,11 +497,13 @@ struct __large_struct { unsigned long buf[100]; };
19004 */
19005 #define uaccess_try do { \
19006 current_thread_info()->uaccess_err = 0; \
19007 + pax_open_userland(); \
19008 stac(); \
19009 barrier();
19010
19011 #define uaccess_catch(err) \
19012 clac(); \
19013 + pax_close_userland(); \
19014 (err) |= (current_thread_info()->uaccess_err ? -EFAULT : 0); \
19015 } while (0)
19016
19017 @@ -463,8 +528,12 @@ struct __large_struct { unsigned long buf[100]; };
19018 * On error, the variable @x is set to zero.
19019 */
19020
19021 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19022 +#define __get_user(x, ptr) get_user((x), (ptr))
19023 +#else
19024 #define __get_user(x, ptr) \
19025 __get_user_nocheck((x), (ptr), sizeof(*(ptr)))
19026 +#endif
19027
19028 /**
19029 * __put_user: - Write a simple value into user space, with less checking.
19030 @@ -486,8 +555,12 @@ struct __large_struct { unsigned long buf[100]; };
19031 * Returns zero on success, or -EFAULT on error.
19032 */
19033
19034 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
19035 +#define __put_user(x, ptr) put_user((x), (ptr))
19036 +#else
19037 #define __put_user(x, ptr) \
19038 __put_user_nocheck((__typeof__(*(ptr)))(x), (ptr), sizeof(*(ptr)))
19039 +#endif
19040
19041 #define __get_user_unaligned __get_user
19042 #define __put_user_unaligned __put_user
19043 @@ -505,7 +578,7 @@ struct __large_struct { unsigned long buf[100]; };
19044 #define get_user_ex(x, ptr) do { \
19045 unsigned long __gue_val; \
19046 __get_user_size_ex((__gue_val), (ptr), (sizeof(*(ptr)))); \
19047 - (x) = (__force __typeof__(*(ptr)))__gue_val; \
19048 + (x) = (__typeof__(*(ptr)))__gue_val; \
19049 } while (0)
19050
19051 #define put_user_try uaccess_try
19052 @@ -536,17 +609,6 @@ extern struct movsl_mask {
19053
19054 #define ARCH_HAS_NOCACHE_UACCESS 1
19055
19056 -#ifdef CONFIG_X86_32
19057 -# include <asm/uaccess_32.h>
19058 -#else
19059 -# include <asm/uaccess_64.h>
19060 -#endif
19061 -
19062 -unsigned long __must_check _copy_from_user(void *to, const void __user *from,
19063 - unsigned n);
19064 -unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19065 - unsigned n);
19066 -
19067 #ifdef CONFIG_DEBUG_STRICT_USER_COPY_CHECKS
19068 # define copy_user_diag __compiletime_error
19069 #else
19070 @@ -556,7 +618,7 @@ unsigned long __must_check _copy_to_user(void __user *to, const void *from,
19071 extern void copy_user_diag("copy_from_user() buffer size is too small")
19072 copy_from_user_overflow(void);
19073 extern void copy_user_diag("copy_to_user() buffer size is too small")
19074 -copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19075 +copy_to_user_overflow(void);
19076
19077 #undef copy_user_diag
19078
19079 @@ -569,7 +631,7 @@ __copy_from_user_overflow(void) __asm__("copy_from_user_overflow");
19080
19081 extern void
19082 __compiletime_warning("copy_to_user() buffer size is not provably correct")
19083 -__copy_to_user_overflow(void) __asm__("copy_from_user_overflow");
19084 +__copy_to_user_overflow(void) __asm__("copy_to_user_overflow");
19085 #define __copy_to_user_overflow(size, count) __copy_to_user_overflow()
19086
19087 #else
19088 @@ -584,10 +646,16 @@ __copy_from_user_overflow(int size, unsigned long count)
19089
19090 #endif
19091
19092 +#ifdef CONFIG_X86_32
19093 +# include <asm/uaccess_32.h>
19094 +#else
19095 +# include <asm/uaccess_64.h>
19096 +#endif
19097 +
19098 static inline unsigned long __must_check
19099 copy_from_user(void *to, const void __user *from, unsigned long n)
19100 {
19101 - int sz = __compiletime_object_size(to);
19102 + size_t sz = __compiletime_object_size(to);
19103
19104 might_fault();
19105
19106 @@ -609,12 +677,15 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19107 * case, and do only runtime checking for non-constant sizes.
19108 */
19109
19110 - if (likely(sz < 0 || sz >= n))
19111 - n = _copy_from_user(to, from, n);
19112 - else if(__builtin_constant_p(n))
19113 - copy_from_user_overflow();
19114 - else
19115 - __copy_from_user_overflow(sz, n);
19116 + if (likely(sz != (size_t)-1 && sz < n)) {
19117 + if(__builtin_constant_p(n))
19118 + copy_from_user_overflow();
19119 + else
19120 + __copy_from_user_overflow(sz, n);
19121 + } if (access_ok(VERIFY_READ, from, n))
19122 + n = __copy_from_user(to, from, n);
19123 + else if ((long)n > 0)
19124 + memset(to, 0, n);
19125
19126 return n;
19127 }
19128 @@ -622,17 +693,18 @@ copy_from_user(void *to, const void __user *from, unsigned long n)
19129 static inline unsigned long __must_check
19130 copy_to_user(void __user *to, const void *from, unsigned long n)
19131 {
19132 - int sz = __compiletime_object_size(from);
19133 + size_t sz = __compiletime_object_size(from);
19134
19135 might_fault();
19136
19137 /* See the comment in copy_from_user() above. */
19138 - if (likely(sz < 0 || sz >= n))
19139 - n = _copy_to_user(to, from, n);
19140 - else if(__builtin_constant_p(n))
19141 - copy_to_user_overflow();
19142 - else
19143 - __copy_to_user_overflow(sz, n);
19144 + if (likely(sz != (size_t)-1 && sz < n)) {
19145 + if(__builtin_constant_p(n))
19146 + copy_to_user_overflow();
19147 + else
19148 + __copy_to_user_overflow(sz, n);
19149 + } else if (access_ok(VERIFY_WRITE, to, n))
19150 + n = __copy_to_user(to, from, n);
19151
19152 return n;
19153 }
19154 diff --git a/arch/x86/include/asm/uaccess_32.h b/arch/x86/include/asm/uaccess_32.h
19155 index 3c03a5d..1071638 100644
19156 --- a/arch/x86/include/asm/uaccess_32.h
19157 +++ b/arch/x86/include/asm/uaccess_32.h
19158 @@ -43,6 +43,11 @@ unsigned long __must_check __copy_from_user_ll_nocache_nozero
19159 static __always_inline unsigned long __must_check
19160 __copy_to_user_inatomic(void __user *to, const void *from, unsigned long n)
19161 {
19162 + if ((long)n < 0)
19163 + return n;
19164 +
19165 + check_object_size(from, n, true);
19166 +
19167 if (__builtin_constant_p(n)) {
19168 unsigned long ret;
19169
19170 @@ -82,12 +87,16 @@ static __always_inline unsigned long __must_check
19171 __copy_to_user(void __user *to, const void *from, unsigned long n)
19172 {
19173 might_fault();
19174 +
19175 return __copy_to_user_inatomic(to, from, n);
19176 }
19177
19178 static __always_inline unsigned long
19179 __copy_from_user_inatomic(void *to, const void __user *from, unsigned long n)
19180 {
19181 + if ((long)n < 0)
19182 + return n;
19183 +
19184 /* Avoid zeroing the tail if the copy fails..
19185 * If 'n' is constant and 1, 2, or 4, we do still zero on a failure,
19186 * but as the zeroing behaviour is only significant when n is not
19187 @@ -137,6 +146,12 @@ static __always_inline unsigned long
19188 __copy_from_user(void *to, const void __user *from, unsigned long n)
19189 {
19190 might_fault();
19191 +
19192 + if ((long)n < 0)
19193 + return n;
19194 +
19195 + check_object_size(to, n, false);
19196 +
19197 if (__builtin_constant_p(n)) {
19198 unsigned long ret;
19199
19200 @@ -159,6 +174,10 @@ static __always_inline unsigned long __copy_from_user_nocache(void *to,
19201 const void __user *from, unsigned long n)
19202 {
19203 might_fault();
19204 +
19205 + if ((long)n < 0)
19206 + return n;
19207 +
19208 if (__builtin_constant_p(n)) {
19209 unsigned long ret;
19210
19211 @@ -181,7 +200,10 @@ static __always_inline unsigned long
19212 __copy_from_user_inatomic_nocache(void *to, const void __user *from,
19213 unsigned long n)
19214 {
19215 - return __copy_from_user_ll_nocache_nozero(to, from, n);
19216 + if ((long)n < 0)
19217 + return n;
19218 +
19219 + return __copy_from_user_ll_nocache_nozero(to, from, n);
19220 }
19221
19222 #endif /* _ASM_X86_UACCESS_32_H */
19223 diff --git a/arch/x86/include/asm/uaccess_64.h b/arch/x86/include/asm/uaccess_64.h
19224 index 190413d..8a80c2a 100644
19225 --- a/arch/x86/include/asm/uaccess_64.h
19226 +++ b/arch/x86/include/asm/uaccess_64.h
19227 @@ -10,6 +10,9 @@
19228 #include <asm/alternative.h>
19229 #include <asm/cpufeature.h>
19230 #include <asm/page.h>
19231 +#include <asm/pgtable.h>
19232 +
19233 +#define set_fs(x) (current_thread_info()->addr_limit = (x))
19234
19235 /*
19236 * Copy To/From Userspace
19237 @@ -17,14 +20,14 @@
19238
19239 /* Handles exceptions in both to and from, but doesn't do access_ok */
19240 __must_check unsigned long
19241 -copy_user_enhanced_fast_string(void *to, const void *from, unsigned len);
19242 +copy_user_enhanced_fast_string(void *to, const void *from, unsigned len) __size_overflow(3);
19243 __must_check unsigned long
19244 -copy_user_generic_string(void *to, const void *from, unsigned len);
19245 +copy_user_generic_string(void *to, const void *from, unsigned len) __size_overflow(3);
19246 __must_check unsigned long
19247 -copy_user_generic_unrolled(void *to, const void *from, unsigned len);
19248 +copy_user_generic_unrolled(void *to, const void *from, unsigned len) __size_overflow(3);
19249
19250 static __always_inline __must_check unsigned long
19251 -copy_user_generic(void *to, const void *from, unsigned len)
19252 +copy_user_generic(void *to, const void *from, unsigned long len)
19253 {
19254 unsigned ret;
19255
19256 @@ -46,121 +49,170 @@ copy_user_generic(void *to, const void *from, unsigned len)
19257 }
19258
19259 __must_check unsigned long
19260 -copy_in_user(void __user *to, const void __user *from, unsigned len);
19261 +copy_in_user(void __user *to, const void __user *from, unsigned long len);
19262
19263 static __always_inline __must_check
19264 -int __copy_from_user_nocheck(void *dst, const void __user *src, unsigned size)
19265 +unsigned long __copy_from_user_nocheck(void *dst, const void __user *src, unsigned long size)
19266 {
19267 - int ret = 0;
19268 + size_t sz = __compiletime_object_size(dst);
19269 + unsigned ret = 0;
19270 +
19271 + if (size > INT_MAX)
19272 + return size;
19273 +
19274 + check_object_size(dst, size, false);
19275 +
19276 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19277 + if (!__access_ok(VERIFY_READ, src, size))
19278 + return size;
19279 +#endif
19280 +
19281 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19282 + if(__builtin_constant_p(size))
19283 + copy_from_user_overflow();
19284 + else
19285 + __copy_from_user_overflow(sz, size);
19286 + return size;
19287 + }
19288
19289 if (!__builtin_constant_p(size))
19290 - return copy_user_generic(dst, (__force void *)src, size);
19291 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19292 switch (size) {
19293 - case 1:__get_user_asm(*(u8 *)dst, (u8 __user *)src,
19294 + case 1:__get_user_asm(*(u8 *)dst, (const u8 __user *)src,
19295 ret, "b", "b", "=q", 1);
19296 return ret;
19297 - case 2:__get_user_asm(*(u16 *)dst, (u16 __user *)src,
19298 + case 2:__get_user_asm(*(u16 *)dst, (const u16 __user *)src,
19299 ret, "w", "w", "=r", 2);
19300 return ret;
19301 - case 4:__get_user_asm(*(u32 *)dst, (u32 __user *)src,
19302 + case 4:__get_user_asm(*(u32 *)dst, (const u32 __user *)src,
19303 ret, "l", "k", "=r", 4);
19304 return ret;
19305 - case 8:__get_user_asm(*(u64 *)dst, (u64 __user *)src,
19306 + case 8:__get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19307 ret, "q", "", "=r", 8);
19308 return ret;
19309 case 10:
19310 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19311 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19312 ret, "q", "", "=r", 10);
19313 if (unlikely(ret))
19314 return ret;
19315 __get_user_asm(*(u16 *)(8 + (char *)dst),
19316 - (u16 __user *)(8 + (char __user *)src),
19317 + (const u16 __user *)(8 + (const char __user *)src),
19318 ret, "w", "w", "=r", 2);
19319 return ret;
19320 case 16:
19321 - __get_user_asm(*(u64 *)dst, (u64 __user *)src,
19322 + __get_user_asm(*(u64 *)dst, (const u64 __user *)src,
19323 ret, "q", "", "=r", 16);
19324 if (unlikely(ret))
19325 return ret;
19326 __get_user_asm(*(u64 *)(8 + (char *)dst),
19327 - (u64 __user *)(8 + (char __user *)src),
19328 + (const u64 __user *)(8 + (const char __user *)src),
19329 ret, "q", "", "=r", 8);
19330 return ret;
19331 default:
19332 - return copy_user_generic(dst, (__force void *)src, size);
19333 + return copy_user_generic(dst, (__force_kernel const void *)____m(src), size);
19334 }
19335 }
19336
19337 static __always_inline __must_check
19338 -int __copy_from_user(void *dst, const void __user *src, unsigned size)
19339 +unsigned long __copy_from_user(void *dst, const void __user *src, unsigned long size)
19340 {
19341 might_fault();
19342 return __copy_from_user_nocheck(dst, src, size);
19343 }
19344
19345 static __always_inline __must_check
19346 -int __copy_to_user_nocheck(void __user *dst, const void *src, unsigned size)
19347 +unsigned long __copy_to_user_nocheck(void __user *dst, const void *src, unsigned long size)
19348 {
19349 - int ret = 0;
19350 + size_t sz = __compiletime_object_size(src);
19351 + unsigned ret = 0;
19352 +
19353 + if (size > INT_MAX)
19354 + return size;
19355 +
19356 + check_object_size(src, size, true);
19357 +
19358 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19359 + if (!__access_ok(VERIFY_WRITE, dst, size))
19360 + return size;
19361 +#endif
19362 +
19363 + if (unlikely(sz != (size_t)-1 && sz < size)) {
19364 + if(__builtin_constant_p(size))
19365 + copy_to_user_overflow();
19366 + else
19367 + __copy_to_user_overflow(sz, size);
19368 + return size;
19369 + }
19370
19371 if (!__builtin_constant_p(size))
19372 - return copy_user_generic((__force void *)dst, src, size);
19373 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19374 switch (size) {
19375 - case 1:__put_user_asm(*(u8 *)src, (u8 __user *)dst,
19376 + case 1:__put_user_asm(*(const u8 *)src, (u8 __user *)dst,
19377 ret, "b", "b", "iq", 1);
19378 return ret;
19379 - case 2:__put_user_asm(*(u16 *)src, (u16 __user *)dst,
19380 + case 2:__put_user_asm(*(const u16 *)src, (u16 __user *)dst,
19381 ret, "w", "w", "ir", 2);
19382 return ret;
19383 - case 4:__put_user_asm(*(u32 *)src, (u32 __user *)dst,
19384 + case 4:__put_user_asm(*(const u32 *)src, (u32 __user *)dst,
19385 ret, "l", "k", "ir", 4);
19386 return ret;
19387 - case 8:__put_user_asm(*(u64 *)src, (u64 __user *)dst,
19388 + case 8:__put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19389 ret, "q", "", "er", 8);
19390 return ret;
19391 case 10:
19392 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19393 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19394 ret, "q", "", "er", 10);
19395 if (unlikely(ret))
19396 return ret;
19397 asm("":::"memory");
19398 - __put_user_asm(4[(u16 *)src], 4 + (u16 __user *)dst,
19399 + __put_user_asm(4[(const u16 *)src], 4 + (u16 __user *)dst,
19400 ret, "w", "w", "ir", 2);
19401 return ret;
19402 case 16:
19403 - __put_user_asm(*(u64 *)src, (u64 __user *)dst,
19404 + __put_user_asm(*(const u64 *)src, (u64 __user *)dst,
19405 ret, "q", "", "er", 16);
19406 if (unlikely(ret))
19407 return ret;
19408 asm("":::"memory");
19409 - __put_user_asm(1[(u64 *)src], 1 + (u64 __user *)dst,
19410 + __put_user_asm(1[(const u64 *)src], 1 + (u64 __user *)dst,
19411 ret, "q", "", "er", 8);
19412 return ret;
19413 default:
19414 - return copy_user_generic((__force void *)dst, src, size);
19415 + return copy_user_generic((__force_kernel void *)____m(dst), src, size);
19416 }
19417 }
19418
19419 static __always_inline __must_check
19420 -int __copy_to_user(void __user *dst, const void *src, unsigned size)
19421 +unsigned long __copy_to_user(void __user *dst, const void *src, unsigned long size)
19422 {
19423 might_fault();
19424 return __copy_to_user_nocheck(dst, src, size);
19425 }
19426
19427 static __always_inline __must_check
19428 -int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19429 +unsigned long __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19430 {
19431 - int ret = 0;
19432 + unsigned ret = 0;
19433
19434 might_fault();
19435 +
19436 + if (size > INT_MAX)
19437 + return size;
19438 +
19439 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19440 + if (!__access_ok(VERIFY_READ, src, size))
19441 + return size;
19442 + if (!__access_ok(VERIFY_WRITE, dst, size))
19443 + return size;
19444 +#endif
19445 +
19446 if (!__builtin_constant_p(size))
19447 - return copy_user_generic((__force void *)dst,
19448 - (__force void *)src, size);
19449 + return copy_user_generic((__force_kernel void *)____m(dst),
19450 + (__force_kernel const void *)____m(src), size);
19451 switch (size) {
19452 case 1: {
19453 u8 tmp;
19454 - __get_user_asm(tmp, (u8 __user *)src,
19455 + __get_user_asm(tmp, (const u8 __user *)src,
19456 ret, "b", "b", "=q", 1);
19457 if (likely(!ret))
19458 __put_user_asm(tmp, (u8 __user *)dst,
19459 @@ -169,7 +221,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19460 }
19461 case 2: {
19462 u16 tmp;
19463 - __get_user_asm(tmp, (u16 __user *)src,
19464 + __get_user_asm(tmp, (const u16 __user *)src,
19465 ret, "w", "w", "=r", 2);
19466 if (likely(!ret))
19467 __put_user_asm(tmp, (u16 __user *)dst,
19468 @@ -179,7 +231,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19469
19470 case 4: {
19471 u32 tmp;
19472 - __get_user_asm(tmp, (u32 __user *)src,
19473 + __get_user_asm(tmp, (const u32 __user *)src,
19474 ret, "l", "k", "=r", 4);
19475 if (likely(!ret))
19476 __put_user_asm(tmp, (u32 __user *)dst,
19477 @@ -188,7 +240,7 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19478 }
19479 case 8: {
19480 u64 tmp;
19481 - __get_user_asm(tmp, (u64 __user *)src,
19482 + __get_user_asm(tmp, (const u64 __user *)src,
19483 ret, "q", "", "=r", 8);
19484 if (likely(!ret))
19485 __put_user_asm(tmp, (u64 __user *)dst,
19486 @@ -196,41 +248,58 @@ int __copy_in_user(void __user *dst, const void __user *src, unsigned size)
19487 return ret;
19488 }
19489 default:
19490 - return copy_user_generic((__force void *)dst,
19491 - (__force void *)src, size);
19492 + return copy_user_generic((__force_kernel void *)____m(dst),
19493 + (__force_kernel const void *)____m(src), size);
19494 }
19495 }
19496
19497 -static __must_check __always_inline int
19498 -__copy_from_user_inatomic(void *dst, const void __user *src, unsigned size)
19499 +static __must_check __always_inline unsigned long
19500 +__copy_from_user_inatomic(void *dst, const void __user *src, unsigned long size)
19501 {
19502 - return __copy_from_user_nocheck(dst, (__force const void *)src, size);
19503 + return __copy_from_user_nocheck(dst, src, size);
19504 }
19505
19506 -static __must_check __always_inline int
19507 -__copy_to_user_inatomic(void __user *dst, const void *src, unsigned size)
19508 +static __must_check __always_inline unsigned long
19509 +__copy_to_user_inatomic(void __user *dst, const void *src, unsigned long size)
19510 {
19511 - return __copy_to_user_nocheck((__force void *)dst, src, size);
19512 + return __copy_to_user_nocheck(dst, src, size);
19513 }
19514
19515 -extern long __copy_user_nocache(void *dst, const void __user *src,
19516 - unsigned size, int zerorest);
19517 +extern unsigned long __copy_user_nocache(void *dst, const void __user *src,
19518 + unsigned long size, int zerorest);
19519
19520 -static inline int
19521 -__copy_from_user_nocache(void *dst, const void __user *src, unsigned size)
19522 +static inline unsigned long
19523 +__copy_from_user_nocache(void *dst, const void __user *src, unsigned long size)
19524 {
19525 might_fault();
19526 +
19527 + if (size > INT_MAX)
19528 + return size;
19529 +
19530 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19531 + if (!__access_ok(VERIFY_READ, src, size))
19532 + return size;
19533 +#endif
19534 +
19535 return __copy_user_nocache(dst, src, size, 1);
19536 }
19537
19538 -static inline int
19539 +static inline unsigned long
19540 __copy_from_user_inatomic_nocache(void *dst, const void __user *src,
19541 - unsigned size)
19542 + unsigned long size)
19543 {
19544 + if (size > INT_MAX)
19545 + return size;
19546 +
19547 +#ifdef CONFIG_PAX_MEMORY_UDEREF
19548 + if (!__access_ok(VERIFY_READ, src, size))
19549 + return size;
19550 +#endif
19551 +
19552 return __copy_user_nocache(dst, src, size, 0);
19553 }
19554
19555 unsigned long
19556 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest);
19557 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest) __size_overflow(3);
19558
19559 #endif /* _ASM_X86_UACCESS_64_H */
19560 diff --git a/arch/x86/include/asm/word-at-a-time.h b/arch/x86/include/asm/word-at-a-time.h
19561 index 5b238981..77fdd78 100644
19562 --- a/arch/x86/include/asm/word-at-a-time.h
19563 +++ b/arch/x86/include/asm/word-at-a-time.h
19564 @@ -11,7 +11,7 @@
19565 * and shift, for example.
19566 */
19567 struct word_at_a_time {
19568 - const unsigned long one_bits, high_bits;
19569 + unsigned long one_bits, high_bits;
19570 };
19571
19572 #define WORD_AT_A_TIME_CONSTANTS { REPEAT_BYTE(0x01), REPEAT_BYTE(0x80) }
19573 diff --git a/arch/x86/include/asm/x86_init.h b/arch/x86/include/asm/x86_init.h
19574 index 0f1be11..f7542bf 100644
19575 --- a/arch/x86/include/asm/x86_init.h
19576 +++ b/arch/x86/include/asm/x86_init.h
19577 @@ -129,7 +129,7 @@ struct x86_init_ops {
19578 struct x86_init_timers timers;
19579 struct x86_init_iommu iommu;
19580 struct x86_init_pci pci;
19581 -};
19582 +} __no_const;
19583
19584 /**
19585 * struct x86_cpuinit_ops - platform specific cpu hotplug setups
19586 @@ -140,7 +140,7 @@ struct x86_cpuinit_ops {
19587 void (*setup_percpu_clockev)(void);
19588 void (*early_percpu_clock_init)(void);
19589 void (*fixup_cpu_id)(struct cpuinfo_x86 *c, int node);
19590 -};
19591 +} __no_const;
19592
19593 struct timespec;
19594
19595 @@ -168,7 +168,7 @@ struct x86_platform_ops {
19596 void (*save_sched_clock_state)(void);
19597 void (*restore_sched_clock_state)(void);
19598 void (*apic_post_init)(void);
19599 -};
19600 +} __no_const;
19601
19602 struct pci_dev;
19603 struct msi_msg;
19604 @@ -185,7 +185,7 @@ struct x86_msi_ops {
19605 int (*setup_hpet_msi)(unsigned int irq, unsigned int id);
19606 u32 (*msi_mask_irq)(struct msi_desc *desc, u32 mask, u32 flag);
19607 u32 (*msix_mask_irq)(struct msi_desc *desc, u32 flag);
19608 -};
19609 +} __no_const;
19610
19611 struct IO_APIC_route_entry;
19612 struct io_apic_irq_attr;
19613 @@ -206,7 +206,7 @@ struct x86_io_apic_ops {
19614 unsigned int destination, int vector,
19615 struct io_apic_irq_attr *attr);
19616 void (*eoi_ioapic_pin)(int apic, int pin, int vector);
19617 -};
19618 +} __no_const;
19619
19620 extern struct x86_init_ops x86_init;
19621 extern struct x86_cpuinit_ops x86_cpuinit;
19622 diff --git a/arch/x86/include/asm/xen/page.h b/arch/x86/include/asm/xen/page.h
19623 index b913915..4f5a581 100644
19624 --- a/arch/x86/include/asm/xen/page.h
19625 +++ b/arch/x86/include/asm/xen/page.h
19626 @@ -56,7 +56,7 @@ extern int m2p_remove_override(struct page *page,
19627 extern struct page *m2p_find_override(unsigned long mfn);
19628 extern unsigned long m2p_find_override_pfn(unsigned long mfn, unsigned long pfn);
19629
19630 -static inline unsigned long pfn_to_mfn(unsigned long pfn)
19631 +static inline unsigned long __intentional_overflow(-1) pfn_to_mfn(unsigned long pfn)
19632 {
19633 unsigned long mfn;
19634
19635 diff --git a/arch/x86/include/asm/xsave.h b/arch/x86/include/asm/xsave.h
19636 index 0415cda..3b22adc 100644
19637 --- a/arch/x86/include/asm/xsave.h
19638 +++ b/arch/x86/include/asm/xsave.h
19639 @@ -70,8 +70,11 @@ static inline int xsave_user(struct xsave_struct __user *buf)
19640 if (unlikely(err))
19641 return -EFAULT;
19642
19643 + pax_open_userland();
19644 __asm__ __volatile__(ASM_STAC "\n"
19645 - "1: .byte " REX_PREFIX "0x0f,0xae,0x27\n"
19646 + "1:"
19647 + __copyuser_seg
19648 + ".byte " REX_PREFIX "0x0f,0xae,0x27\n"
19649 "2: " ASM_CLAC "\n"
19650 ".section .fixup,\"ax\"\n"
19651 "3: movl $-1,%[err]\n"
19652 @@ -81,18 +84,22 @@ static inline int xsave_user(struct xsave_struct __user *buf)
19653 : [err] "=r" (err)
19654 : "D" (buf), "a" (-1), "d" (-1), "0" (0)
19655 : "memory");
19656 + pax_close_userland();
19657 return err;
19658 }
19659
19660 static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
19661 {
19662 int err;
19663 - struct xsave_struct *xstate = ((__force struct xsave_struct *)buf);
19664 + struct xsave_struct *xstate = ((__force_kernel struct xsave_struct *)buf);
19665 u32 lmask = mask;
19666 u32 hmask = mask >> 32;
19667
19668 + pax_open_userland();
19669 __asm__ __volatile__(ASM_STAC "\n"
19670 - "1: .byte " REX_PREFIX "0x0f,0xae,0x2f\n"
19671 + "1:"
19672 + __copyuser_seg
19673 + ".byte " REX_PREFIX "0x0f,0xae,0x2f\n"
19674 "2: " ASM_CLAC "\n"
19675 ".section .fixup,\"ax\"\n"
19676 "3: movl $-1,%[err]\n"
19677 @@ -102,6 +109,7 @@ static inline int xrestore_user(struct xsave_struct __user *buf, u64 mask)
19678 : [err] "=r" (err)
19679 : "D" (xstate), "a" (lmask), "d" (hmask), "0" (0)
19680 : "memory"); /* memory required? */
19681 + pax_close_userland();
19682 return err;
19683 }
19684
19685 diff --git a/arch/x86/include/uapi/asm/e820.h b/arch/x86/include/uapi/asm/e820.h
19686 index bbae024..e1528f9 100644
19687 --- a/arch/x86/include/uapi/asm/e820.h
19688 +++ b/arch/x86/include/uapi/asm/e820.h
19689 @@ -63,7 +63,7 @@ struct e820map {
19690 #define ISA_START_ADDRESS 0xa0000
19691 #define ISA_END_ADDRESS 0x100000
19692
19693 -#define BIOS_BEGIN 0x000a0000
19694 +#define BIOS_BEGIN 0x000c0000
19695 #define BIOS_END 0x00100000
19696
19697 #define BIOS_ROM_BASE 0xffe00000
19698 diff --git a/arch/x86/include/uapi/asm/ptrace-abi.h b/arch/x86/include/uapi/asm/ptrace-abi.h
19699 index 7b0a55a..ad115bf 100644
19700 --- a/arch/x86/include/uapi/asm/ptrace-abi.h
19701 +++ b/arch/x86/include/uapi/asm/ptrace-abi.h
19702 @@ -49,7 +49,6 @@
19703 #define EFLAGS 144
19704 #define RSP 152
19705 #define SS 160
19706 -#define ARGOFFSET R11
19707 #endif /* __ASSEMBLY__ */
19708
19709 /* top of stack page */
19710 diff --git a/arch/x86/kernel/Makefile b/arch/x86/kernel/Makefile
19711 index 9b0a34e..fc7e553 100644
19712 --- a/arch/x86/kernel/Makefile
19713 +++ b/arch/x86/kernel/Makefile
19714 @@ -24,7 +24,7 @@ obj-y += time.o ioport.o ldt.o dumpstack.o nmi.o
19715 obj-y += setup.o x86_init.o i8259.o irqinit.o jump_label.o
19716 obj-$(CONFIG_IRQ_WORK) += irq_work.o
19717 obj-y += probe_roms.o
19718 -obj-$(CONFIG_X86_32) += i386_ksyms_32.o
19719 +obj-$(CONFIG_X86_32) += sys_i386_32.o i386_ksyms_32.o
19720 obj-$(CONFIG_X86_64) += sys_x86_64.o x8664_ksyms_64.o
19721 obj-y += syscall_$(BITS).o
19722 obj-$(CONFIG_X86_64) += vsyscall_64.o
19723 diff --git a/arch/x86/kernel/acpi/boot.c b/arch/x86/kernel/acpi/boot.c
19724 index 6c0b43b..e67bb31 100644
19725 --- a/arch/x86/kernel/acpi/boot.c
19726 +++ b/arch/x86/kernel/acpi/boot.c
19727 @@ -1315,7 +1315,7 @@ static int __init dmi_ignore_irq0_timer_override(const struct dmi_system_id *d)
19728 * If your system is blacklisted here, but you find that acpi=force
19729 * works for you, please contact linux-acpi@vger.kernel.org
19730 */
19731 -static struct dmi_system_id __initdata acpi_dmi_table[] = {
19732 +static const struct dmi_system_id __initconst acpi_dmi_table[] = {
19733 /*
19734 * Boxes that need ACPI disabled
19735 */
19736 @@ -1390,7 +1390,7 @@ static struct dmi_system_id __initdata acpi_dmi_table[] = {
19737 };
19738
19739 /* second table for DMI checks that should run after early-quirks */
19740 -static struct dmi_system_id __initdata acpi_dmi_table_late[] = {
19741 +static const struct dmi_system_id __initconst acpi_dmi_table_late[] = {
19742 /*
19743 * HP laptops which use a DSDT reporting as HP/SB400/10000,
19744 * which includes some code which overrides all temperature
19745 diff --git a/arch/x86/kernel/acpi/sleep.c b/arch/x86/kernel/acpi/sleep.c
19746 index 3a2ae4c..9db31d6 100644
19747 --- a/arch/x86/kernel/acpi/sleep.c
19748 +++ b/arch/x86/kernel/acpi/sleep.c
19749 @@ -99,8 +99,12 @@ int x86_acpi_suspend_lowlevel(void)
19750 #else /* CONFIG_64BIT */
19751 #ifdef CONFIG_SMP
19752 stack_start = (unsigned long)temp_stack + sizeof(temp_stack);
19753 +
19754 + pax_open_kernel();
19755 early_gdt_descr.address =
19756 (unsigned long)get_cpu_gdt_table(smp_processor_id());
19757 + pax_close_kernel();
19758 +
19759 initial_gs = per_cpu_offset(smp_processor_id());
19760 #endif
19761 initial_code = (unsigned long)wakeup_long64;
19762 diff --git a/arch/x86/kernel/acpi/wakeup_32.S b/arch/x86/kernel/acpi/wakeup_32.S
19763 index 665c6b7..eae4d56 100644
19764 --- a/arch/x86/kernel/acpi/wakeup_32.S
19765 +++ b/arch/x86/kernel/acpi/wakeup_32.S
19766 @@ -29,13 +29,11 @@ wakeup_pmode_return:
19767 # and restore the stack ... but you need gdt for this to work
19768 movl saved_context_esp, %esp
19769
19770 - movl %cs:saved_magic, %eax
19771 - cmpl $0x12345678, %eax
19772 + cmpl $0x12345678, saved_magic
19773 jne bogus_magic
19774
19775 # jump to place where we left off
19776 - movl saved_eip, %eax
19777 - jmp *%eax
19778 + jmp *(saved_eip)
19779
19780 bogus_magic:
19781 jmp bogus_magic
19782 diff --git a/arch/x86/kernel/alternative.c b/arch/x86/kernel/alternative.c
19783 index df94598..f3b29bf 100644
19784 --- a/arch/x86/kernel/alternative.c
19785 +++ b/arch/x86/kernel/alternative.c
19786 @@ -269,6 +269,13 @@ void __init_or_module apply_alternatives(struct alt_instr *start,
19787 */
19788 for (a = start; a < end; a++) {
19789 instr = (u8 *)&a->instr_offset + a->instr_offset;
19790 +
19791 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19792 + instr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19793 + if (instr < (u8 *)_text || (u8 *)_einittext <= instr)
19794 + instr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19795 +#endif
19796 +
19797 replacement = (u8 *)&a->repl_offset + a->repl_offset;
19798 BUG_ON(a->replacementlen > a->instrlen);
19799 BUG_ON(a->instrlen > sizeof(insnbuf));
19800 @@ -300,10 +307,16 @@ static void alternatives_smp_lock(const s32 *start, const s32 *end,
19801 for (poff = start; poff < end; poff++) {
19802 u8 *ptr = (u8 *)poff + *poff;
19803
19804 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19805 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19806 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
19807 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19808 +#endif
19809 +
19810 if (!*poff || ptr < text || ptr >= text_end)
19811 continue;
19812 /* turn DS segment override prefix into lock prefix */
19813 - if (*ptr == 0x3e)
19814 + if (*ktla_ktva(ptr) == 0x3e)
19815 text_poke(ptr, ((unsigned char []){0xf0}), 1);
19816 }
19817 mutex_unlock(&text_mutex);
19818 @@ -318,10 +331,16 @@ static void alternatives_smp_unlock(const s32 *start, const s32 *end,
19819 for (poff = start; poff < end; poff++) {
19820 u8 *ptr = (u8 *)poff + *poff;
19821
19822 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
19823 + ptr += ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19824 + if (ptr < (u8 *)_text || (u8 *)_einittext <= ptr)
19825 + ptr -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
19826 +#endif
19827 +
19828 if (!*poff || ptr < text || ptr >= text_end)
19829 continue;
19830 /* turn lock prefix into DS segment override prefix */
19831 - if (*ptr == 0xf0)
19832 + if (*ktla_ktva(ptr) == 0xf0)
19833 text_poke(ptr, ((unsigned char []){0x3E}), 1);
19834 }
19835 mutex_unlock(&text_mutex);
19836 @@ -458,7 +477,7 @@ void __init_or_module apply_paravirt(struct paravirt_patch_site *start,
19837
19838 BUG_ON(p->len > MAX_PATCH_LEN);
19839 /* prep the buffer with the original instructions */
19840 - memcpy(insnbuf, p->instr, p->len);
19841 + memcpy(insnbuf, ktla_ktva(p->instr), p->len);
19842 used = pv_init_ops.patch(p->instrtype, p->clobbers, insnbuf,
19843 (unsigned long)p->instr, p->len);
19844
19845 @@ -505,7 +524,7 @@ void __init alternative_instructions(void)
19846 if (!uniproc_patched || num_possible_cpus() == 1)
19847 free_init_pages("SMP alternatives",
19848 (unsigned long)__smp_locks,
19849 - (unsigned long)__smp_locks_end);
19850 + PAGE_ALIGN((unsigned long)__smp_locks_end));
19851 #endif
19852
19853 apply_paravirt(__parainstructions, __parainstructions_end);
19854 @@ -525,13 +544,17 @@ void __init alternative_instructions(void)
19855 * instructions. And on the local CPU you need to be protected again NMI or MCE
19856 * handlers seeing an inconsistent instruction while you patch.
19857 */
19858 -void *__init_or_module text_poke_early(void *addr, const void *opcode,
19859 +void *__kprobes text_poke_early(void *addr, const void *opcode,
19860 size_t len)
19861 {
19862 unsigned long flags;
19863 local_irq_save(flags);
19864 - memcpy(addr, opcode, len);
19865 +
19866 + pax_open_kernel();
19867 + memcpy(ktla_ktva(addr), opcode, len);
19868 sync_core();
19869 + pax_close_kernel();
19870 +
19871 local_irq_restore(flags);
19872 /* Could also do a CLFLUSH here to speed up CPU recovery; but
19873 that causes hangs on some VIA CPUs. */
19874 @@ -553,36 +576,22 @@ void *__init_or_module text_poke_early(void *addr, const void *opcode,
19875 */
19876 void *__kprobes text_poke(void *addr, const void *opcode, size_t len)
19877 {
19878 - unsigned long flags;
19879 - char *vaddr;
19880 + unsigned char *vaddr = ktla_ktva(addr);
19881 struct page *pages[2];
19882 - int i;
19883 + size_t i;
19884
19885 if (!core_kernel_text((unsigned long)addr)) {
19886 - pages[0] = vmalloc_to_page(addr);
19887 - pages[1] = vmalloc_to_page(addr + PAGE_SIZE);
19888 + pages[0] = vmalloc_to_page(vaddr);
19889 + pages[1] = vmalloc_to_page(vaddr + PAGE_SIZE);
19890 } else {
19891 - pages[0] = virt_to_page(addr);
19892 + pages[0] = virt_to_page(vaddr);
19893 WARN_ON(!PageReserved(pages[0]));
19894 - pages[1] = virt_to_page(addr + PAGE_SIZE);
19895 + pages[1] = virt_to_page(vaddr + PAGE_SIZE);
19896 }
19897 BUG_ON(!pages[0]);
19898 - local_irq_save(flags);
19899 - set_fixmap(FIX_TEXT_POKE0, page_to_phys(pages[0]));
19900 - if (pages[1])
19901 - set_fixmap(FIX_TEXT_POKE1, page_to_phys(pages[1]));
19902 - vaddr = (char *)fix_to_virt(FIX_TEXT_POKE0);
19903 - memcpy(&vaddr[(unsigned long)addr & ~PAGE_MASK], opcode, len);
19904 - clear_fixmap(FIX_TEXT_POKE0);
19905 - if (pages[1])
19906 - clear_fixmap(FIX_TEXT_POKE1);
19907 - local_flush_tlb();
19908 - sync_core();
19909 - /* Could also do a CLFLUSH here to speed up CPU recovery; but
19910 - that causes hangs on some VIA CPUs. */
19911 + text_poke_early(addr, opcode, len);
19912 for (i = 0; i < len; i++)
19913 - BUG_ON(((char *)addr)[i] != ((char *)opcode)[i]);
19914 - local_irq_restore(flags);
19915 + BUG_ON((vaddr)[i] != ((const unsigned char *)opcode)[i]);
19916 return addr;
19917 }
19918
19919 @@ -602,7 +611,7 @@ int poke_int3_handler(struct pt_regs *regs)
19920 if (likely(!bp_patching_in_progress))
19921 return 0;
19922
19923 - if (user_mode_vm(regs) || regs->ip != (unsigned long)bp_int3_addr)
19924 + if (user_mode(regs) || regs->ip != (unsigned long)bp_int3_addr)
19925 return 0;
19926
19927 /* set up the specified breakpoint handler */
19928 @@ -636,7 +645,7 @@ int poke_int3_handler(struct pt_regs *regs)
19929 */
19930 void *text_poke_bp(void *addr, const void *opcode, size_t len, void *handler)
19931 {
19932 - unsigned char int3 = 0xcc;
19933 + const unsigned char int3 = 0xcc;
19934
19935 bp_int3_handler = handler;
19936 bp_int3_addr = (u8 *)addr + sizeof(int3);
19937 diff --git a/arch/x86/kernel/apic/apic.c b/arch/x86/kernel/apic/apic.c
19938 index d278736..0b4af9a8 100644
19939 --- a/arch/x86/kernel/apic/apic.c
19940 +++ b/arch/x86/kernel/apic/apic.c
19941 @@ -191,7 +191,7 @@ int first_system_vector = 0xfe;
19942 /*
19943 * Debug level, exported for io_apic.c
19944 */
19945 -unsigned int apic_verbosity;
19946 +int apic_verbosity;
19947
19948 int pic_mode;
19949
19950 @@ -1986,7 +1986,7 @@ static inline void __smp_error_interrupt(struct pt_regs *regs)
19951 apic_write(APIC_ESR, 0);
19952 v1 = apic_read(APIC_ESR);
19953 ack_APIC_irq();
19954 - atomic_inc(&irq_err_count);
19955 + atomic_inc_unchecked(&irq_err_count);
19956
19957 apic_printk(APIC_DEBUG, KERN_DEBUG "APIC error on CPU%d: %02x(%02x)",
19958 smp_processor_id(), v0 , v1);
19959 diff --git a/arch/x86/kernel/apic/apic_flat_64.c b/arch/x86/kernel/apic/apic_flat_64.c
19960 index 00c77cf..2dc6a2d 100644
19961 --- a/arch/x86/kernel/apic/apic_flat_64.c
19962 +++ b/arch/x86/kernel/apic/apic_flat_64.c
19963 @@ -157,7 +157,7 @@ static int flat_probe(void)
19964 return 1;
19965 }
19966
19967 -static struct apic apic_flat = {
19968 +static struct apic apic_flat __read_only = {
19969 .name = "flat",
19970 .probe = flat_probe,
19971 .acpi_madt_oem_check = flat_acpi_madt_oem_check,
19972 @@ -271,7 +271,7 @@ static int physflat_probe(void)
19973 return 0;
19974 }
19975
19976 -static struct apic apic_physflat = {
19977 +static struct apic apic_physflat __read_only = {
19978
19979 .name = "physical flat",
19980 .probe = physflat_probe,
19981 diff --git a/arch/x86/kernel/apic/apic_noop.c b/arch/x86/kernel/apic/apic_noop.c
19982 index e145f28..2752888 100644
19983 --- a/arch/x86/kernel/apic/apic_noop.c
19984 +++ b/arch/x86/kernel/apic/apic_noop.c
19985 @@ -119,7 +119,7 @@ static void noop_apic_write(u32 reg, u32 v)
19986 WARN_ON_ONCE(cpu_has_apic && !disable_apic);
19987 }
19988
19989 -struct apic apic_noop = {
19990 +struct apic apic_noop __read_only = {
19991 .name = "noop",
19992 .probe = noop_probe,
19993 .acpi_madt_oem_check = NULL,
19994 diff --git a/arch/x86/kernel/apic/bigsmp_32.c b/arch/x86/kernel/apic/bigsmp_32.c
19995 index d50e364..543bee3 100644
19996 --- a/arch/x86/kernel/apic/bigsmp_32.c
19997 +++ b/arch/x86/kernel/apic/bigsmp_32.c
19998 @@ -152,7 +152,7 @@ static int probe_bigsmp(void)
19999 return dmi_bigsmp;
20000 }
20001
20002 -static struct apic apic_bigsmp = {
20003 +static struct apic apic_bigsmp __read_only = {
20004
20005 .name = "bigsmp",
20006 .probe = probe_bigsmp,
20007 diff --git a/arch/x86/kernel/apic/es7000_32.c b/arch/x86/kernel/apic/es7000_32.c
20008 index c552247..587a316 100644
20009 --- a/arch/x86/kernel/apic/es7000_32.c
20010 +++ b/arch/x86/kernel/apic/es7000_32.c
20011 @@ -608,8 +608,7 @@ static int es7000_mps_oem_check_cluster(struct mpc_table *mpc, char *oem,
20012 return ret && es7000_apic_is_cluster();
20013 }
20014
20015 -/* We've been warned by a false positive warning.Use __refdata to keep calm. */
20016 -static struct apic __refdata apic_es7000_cluster = {
20017 +static struct apic apic_es7000_cluster __read_only = {
20018
20019 .name = "es7000",
20020 .probe = probe_es7000,
20021 @@ -675,7 +674,7 @@ static struct apic __refdata apic_es7000_cluster = {
20022 .x86_32_early_logical_apicid = es7000_early_logical_apicid,
20023 };
20024
20025 -static struct apic __refdata apic_es7000 = {
20026 +static struct apic apic_es7000 __read_only = {
20027
20028 .name = "es7000",
20029 .probe = probe_es7000,
20030 diff --git a/arch/x86/kernel/apic/io_apic.c b/arch/x86/kernel/apic/io_apic.c
20031 index e63a5bd..c0babf8 100644
20032 --- a/arch/x86/kernel/apic/io_apic.c
20033 +++ b/arch/x86/kernel/apic/io_apic.c
20034 @@ -1060,7 +1060,7 @@ int IO_APIC_get_PCI_irq_vector(int bus, int slot, int pin,
20035 }
20036 EXPORT_SYMBOL(IO_APIC_get_PCI_irq_vector);
20037
20038 -void lock_vector_lock(void)
20039 +void lock_vector_lock(void) __acquires(vector_lock)
20040 {
20041 /* Used to the online set of cpus does not change
20042 * during assign_irq_vector.
20043 @@ -1068,7 +1068,7 @@ void lock_vector_lock(void)
20044 raw_spin_lock(&vector_lock);
20045 }
20046
20047 -void unlock_vector_lock(void)
20048 +void unlock_vector_lock(void) __releases(vector_lock)
20049 {
20050 raw_spin_unlock(&vector_lock);
20051 }
20052 @@ -2367,7 +2367,7 @@ static void ack_apic_edge(struct irq_data *data)
20053 ack_APIC_irq();
20054 }
20055
20056 -atomic_t irq_mis_count;
20057 +atomic_unchecked_t irq_mis_count;
20058
20059 #ifdef CONFIG_GENERIC_PENDING_IRQ
20060 static bool io_apic_level_ack_pending(struct irq_cfg *cfg)
20061 @@ -2508,7 +2508,7 @@ static void ack_apic_level(struct irq_data *data)
20062 * at the cpu.
20063 */
20064 if (!(v & (1 << (i & 0x1f)))) {
20065 - atomic_inc(&irq_mis_count);
20066 + atomic_inc_unchecked(&irq_mis_count);
20067
20068 eoi_ioapic_irq(irq, cfg);
20069 }
20070 diff --git a/arch/x86/kernel/apic/numaq_32.c b/arch/x86/kernel/apic/numaq_32.c
20071 index 1e42e8f..daacf44 100644
20072 --- a/arch/x86/kernel/apic/numaq_32.c
20073 +++ b/arch/x86/kernel/apic/numaq_32.c
20074 @@ -455,8 +455,7 @@ static void numaq_setup_portio_remap(void)
20075 (u_long) xquad_portio, (u_long) num_quads*XQUAD_PORTIO_QUAD);
20076 }
20077
20078 -/* Use __refdata to keep false positive warning calm. */
20079 -static struct apic __refdata apic_numaq = {
20080 +static struct apic apic_numaq __read_only = {
20081
20082 .name = "NUMAQ",
20083 .probe = probe_numaq,
20084 diff --git a/arch/x86/kernel/apic/probe_32.c b/arch/x86/kernel/apic/probe_32.c
20085 index eb35ef9..f184a21 100644
20086 --- a/arch/x86/kernel/apic/probe_32.c
20087 +++ b/arch/x86/kernel/apic/probe_32.c
20088 @@ -72,7 +72,7 @@ static int probe_default(void)
20089 return 1;
20090 }
20091
20092 -static struct apic apic_default = {
20093 +static struct apic apic_default __read_only = {
20094
20095 .name = "default",
20096 .probe = probe_default,
20097 diff --git a/arch/x86/kernel/apic/summit_32.c b/arch/x86/kernel/apic/summit_32.c
20098 index 77c95c0..434f8a4 100644
20099 --- a/arch/x86/kernel/apic/summit_32.c
20100 +++ b/arch/x86/kernel/apic/summit_32.c
20101 @@ -486,7 +486,7 @@ void setup_summit(void)
20102 }
20103 #endif
20104
20105 -static struct apic apic_summit = {
20106 +static struct apic apic_summit __read_only = {
20107
20108 .name = "summit",
20109 .probe = probe_summit,
20110 diff --git a/arch/x86/kernel/apic/x2apic_cluster.c b/arch/x86/kernel/apic/x2apic_cluster.c
20111 index 140e29d..d88bc95 100644
20112 --- a/arch/x86/kernel/apic/x2apic_cluster.c
20113 +++ b/arch/x86/kernel/apic/x2apic_cluster.c
20114 @@ -183,7 +183,7 @@ update_clusterinfo(struct notifier_block *nfb, unsigned long action, void *hcpu)
20115 return notifier_from_errno(err);
20116 }
20117
20118 -static struct notifier_block __refdata x2apic_cpu_notifier = {
20119 +static struct notifier_block x2apic_cpu_notifier = {
20120 .notifier_call = update_clusterinfo,
20121 };
20122
20123 @@ -235,7 +235,7 @@ static void cluster_vector_allocation_domain(int cpu, struct cpumask *retmask,
20124 cpumask_and(retmask, mask, per_cpu(cpus_in_cluster, cpu));
20125 }
20126
20127 -static struct apic apic_x2apic_cluster = {
20128 +static struct apic apic_x2apic_cluster __read_only = {
20129
20130 .name = "cluster x2apic",
20131 .probe = x2apic_cluster_probe,
20132 diff --git a/arch/x86/kernel/apic/x2apic_phys.c b/arch/x86/kernel/apic/x2apic_phys.c
20133 index 562a76d..a003c0f 100644
20134 --- a/arch/x86/kernel/apic/x2apic_phys.c
20135 +++ b/arch/x86/kernel/apic/x2apic_phys.c
20136 @@ -89,7 +89,7 @@ static int x2apic_phys_probe(void)
20137 return apic == &apic_x2apic_phys;
20138 }
20139
20140 -static struct apic apic_x2apic_phys = {
20141 +static struct apic apic_x2apic_phys __read_only = {
20142
20143 .name = "physical x2apic",
20144 .probe = x2apic_phys_probe,
20145 diff --git a/arch/x86/kernel/apic/x2apic_uv_x.c b/arch/x86/kernel/apic/x2apic_uv_x.c
20146 index ad0dc04..0d9cc56 100644
20147 --- a/arch/x86/kernel/apic/x2apic_uv_x.c
20148 +++ b/arch/x86/kernel/apic/x2apic_uv_x.c
20149 @@ -350,7 +350,7 @@ static int uv_probe(void)
20150 return apic == &apic_x2apic_uv_x;
20151 }
20152
20153 -static struct apic __refdata apic_x2apic_uv_x = {
20154 +static struct apic apic_x2apic_uv_x __read_only = {
20155
20156 .name = "UV large system",
20157 .probe = uv_probe,
20158 diff --git a/arch/x86/kernel/apm_32.c b/arch/x86/kernel/apm_32.c
20159 index 3ab0343..814c4787 100644
20160 --- a/arch/x86/kernel/apm_32.c
20161 +++ b/arch/x86/kernel/apm_32.c
20162 @@ -433,7 +433,7 @@ static DEFINE_MUTEX(apm_mutex);
20163 * This is for buggy BIOS's that refer to (real mode) segment 0x40
20164 * even though they are called in protected mode.
20165 */
20166 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
20167 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
20168 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
20169
20170 static const char driver_version[] = "1.16ac"; /* no spaces */
20171 @@ -611,7 +611,10 @@ static long __apm_bios_call(void *_call)
20172 BUG_ON(cpu != 0);
20173 gdt = get_cpu_gdt_table(cpu);
20174 save_desc_40 = gdt[0x40 / 8];
20175 +
20176 + pax_open_kernel();
20177 gdt[0x40 / 8] = bad_bios_desc;
20178 + pax_close_kernel();
20179
20180 apm_irq_save(flags);
20181 APM_DO_SAVE_SEGS;
20182 @@ -620,7 +623,11 @@ static long __apm_bios_call(void *_call)
20183 &call->esi);
20184 APM_DO_RESTORE_SEGS;
20185 apm_irq_restore(flags);
20186 +
20187 + pax_open_kernel();
20188 gdt[0x40 / 8] = save_desc_40;
20189 + pax_close_kernel();
20190 +
20191 put_cpu();
20192
20193 return call->eax & 0xff;
20194 @@ -687,7 +694,10 @@ static long __apm_bios_call_simple(void *_call)
20195 BUG_ON(cpu != 0);
20196 gdt = get_cpu_gdt_table(cpu);
20197 save_desc_40 = gdt[0x40 / 8];
20198 +
20199 + pax_open_kernel();
20200 gdt[0x40 / 8] = bad_bios_desc;
20201 + pax_close_kernel();
20202
20203 apm_irq_save(flags);
20204 APM_DO_SAVE_SEGS;
20205 @@ -695,7 +705,11 @@ static long __apm_bios_call_simple(void *_call)
20206 &call->eax);
20207 APM_DO_RESTORE_SEGS;
20208 apm_irq_restore(flags);
20209 +
20210 + pax_open_kernel();
20211 gdt[0x40 / 8] = save_desc_40;
20212 + pax_close_kernel();
20213 +
20214 put_cpu();
20215 return error;
20216 }
20217 @@ -2362,12 +2376,15 @@ static int __init apm_init(void)
20218 * code to that CPU.
20219 */
20220 gdt = get_cpu_gdt_table(0);
20221 +
20222 + pax_open_kernel();
20223 set_desc_base(&gdt[APM_CS >> 3],
20224 (unsigned long)__va((unsigned long)apm_info.bios.cseg << 4));
20225 set_desc_base(&gdt[APM_CS_16 >> 3],
20226 (unsigned long)__va((unsigned long)apm_info.bios.cseg_16 << 4));
20227 set_desc_base(&gdt[APM_DS >> 3],
20228 (unsigned long)__va((unsigned long)apm_info.bios.dseg << 4));
20229 + pax_close_kernel();
20230
20231 proc_create("apm", 0, NULL, &apm_file_ops);
20232
20233 diff --git a/arch/x86/kernel/asm-offsets.c b/arch/x86/kernel/asm-offsets.c
20234 index 9f6b934..cf5ffb3 100644
20235 --- a/arch/x86/kernel/asm-offsets.c
20236 +++ b/arch/x86/kernel/asm-offsets.c
20237 @@ -32,6 +32,8 @@ void common(void) {
20238 OFFSET(TI_flags, thread_info, flags);
20239 OFFSET(TI_status, thread_info, status);
20240 OFFSET(TI_addr_limit, thread_info, addr_limit);
20241 + OFFSET(TI_lowest_stack, thread_info, lowest_stack);
20242 + DEFINE(TI_task_thread_sp0, offsetof(struct task_struct, thread.sp0) - offsetof(struct task_struct, tinfo));
20243
20244 BLANK();
20245 OFFSET(crypto_tfm_ctx_offset, crypto_tfm, __crt_ctx);
20246 @@ -52,8 +54,26 @@ void common(void) {
20247 OFFSET(PV_CPU_irq_enable_sysexit, pv_cpu_ops, irq_enable_sysexit);
20248 OFFSET(PV_CPU_read_cr0, pv_cpu_ops, read_cr0);
20249 OFFSET(PV_MMU_read_cr2, pv_mmu_ops, read_cr2);
20250 +
20251 +#ifdef CONFIG_PAX_KERNEXEC
20252 + OFFSET(PV_CPU_write_cr0, pv_cpu_ops, write_cr0);
20253 #endif
20254
20255 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20256 + OFFSET(PV_MMU_read_cr3, pv_mmu_ops, read_cr3);
20257 + OFFSET(PV_MMU_write_cr3, pv_mmu_ops, write_cr3);
20258 +#ifdef CONFIG_X86_64
20259 + OFFSET(PV_MMU_set_pgd_batched, pv_mmu_ops, set_pgd_batched);
20260 +#endif
20261 +#endif
20262 +
20263 +#endif
20264 +
20265 + BLANK();
20266 + DEFINE(PAGE_SIZE_asm, PAGE_SIZE);
20267 + DEFINE(PAGE_SHIFT_asm, PAGE_SHIFT);
20268 + DEFINE(THREAD_SIZE_asm, THREAD_SIZE);
20269 +
20270 #ifdef CONFIG_XEN
20271 BLANK();
20272 OFFSET(XEN_vcpu_info_mask, vcpu_info, evtchn_upcall_mask);
20273 diff --git a/arch/x86/kernel/asm-offsets_64.c b/arch/x86/kernel/asm-offsets_64.c
20274 index e7c798b..2b2019b 100644
20275 --- a/arch/x86/kernel/asm-offsets_64.c
20276 +++ b/arch/x86/kernel/asm-offsets_64.c
20277 @@ -77,6 +77,7 @@ int main(void)
20278 BLANK();
20279 #undef ENTRY
20280
20281 + DEFINE(TSS_size, sizeof(struct tss_struct));
20282 OFFSET(TSS_ist, tss_struct, x86_tss.ist);
20283 BLANK();
20284
20285 diff --git a/arch/x86/kernel/cpu/Makefile b/arch/x86/kernel/cpu/Makefile
20286 index 47b56a7..efc2bc6 100644
20287 --- a/arch/x86/kernel/cpu/Makefile
20288 +++ b/arch/x86/kernel/cpu/Makefile
20289 @@ -8,10 +8,6 @@ CFLAGS_REMOVE_common.o = -pg
20290 CFLAGS_REMOVE_perf_event.o = -pg
20291 endif
20292
20293 -# Make sure load_percpu_segment has no stackprotector
20294 -nostackp := $(call cc-option, -fno-stack-protector)
20295 -CFLAGS_common.o := $(nostackp)
20296 -
20297 obj-y := intel_cacheinfo.o scattered.o topology.o
20298 obj-y += proc.o capflags.o powerflags.o common.o
20299 obj-y += rdrand.o
20300 diff --git a/arch/x86/kernel/cpu/amd.c b/arch/x86/kernel/cpu/amd.c
20301 index 59bfebc..d8f27bd 100644
20302 --- a/arch/x86/kernel/cpu/amd.c
20303 +++ b/arch/x86/kernel/cpu/amd.c
20304 @@ -753,7 +753,7 @@ static void init_amd(struct cpuinfo_x86 *c)
20305 static unsigned int amd_size_cache(struct cpuinfo_x86 *c, unsigned int size)
20306 {
20307 /* AMD errata T13 (order #21922) */
20308 - if ((c->x86 == 6)) {
20309 + if (c->x86 == 6) {
20310 /* Duron Rev A0 */
20311 if (c->x86_model == 3 && c->x86_mask == 0)
20312 size = 64;
20313 diff --git a/arch/x86/kernel/cpu/common.c b/arch/x86/kernel/cpu/common.c
20314 index 6abc172..3b0df94 100644
20315 --- a/arch/x86/kernel/cpu/common.c
20316 +++ b/arch/x86/kernel/cpu/common.c
20317 @@ -88,60 +88,6 @@ static const struct cpu_dev default_cpu = {
20318
20319 static const struct cpu_dev *this_cpu = &default_cpu;
20320
20321 -DEFINE_PER_CPU_PAGE_ALIGNED(struct gdt_page, gdt_page) = { .gdt = {
20322 -#ifdef CONFIG_X86_64
20323 - /*
20324 - * We need valid kernel segments for data and code in long mode too
20325 - * IRET will check the segment types kkeil 2000/10/28
20326 - * Also sysret mandates a special GDT layout
20327 - *
20328 - * TLS descriptors are currently at a different place compared to i386.
20329 - * Hopefully nobody expects them at a fixed place (Wine?)
20330 - */
20331 - [GDT_ENTRY_KERNEL32_CS] = GDT_ENTRY_INIT(0xc09b, 0, 0xfffff),
20332 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xa09b, 0, 0xfffff),
20333 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc093, 0, 0xfffff),
20334 - [GDT_ENTRY_DEFAULT_USER32_CS] = GDT_ENTRY_INIT(0xc0fb, 0, 0xfffff),
20335 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f3, 0, 0xfffff),
20336 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xa0fb, 0, 0xfffff),
20337 -#else
20338 - [GDT_ENTRY_KERNEL_CS] = GDT_ENTRY_INIT(0xc09a, 0, 0xfffff),
20339 - [GDT_ENTRY_KERNEL_DS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20340 - [GDT_ENTRY_DEFAULT_USER_CS] = GDT_ENTRY_INIT(0xc0fa, 0, 0xfffff),
20341 - [GDT_ENTRY_DEFAULT_USER_DS] = GDT_ENTRY_INIT(0xc0f2, 0, 0xfffff),
20342 - /*
20343 - * Segments used for calling PnP BIOS have byte granularity.
20344 - * They code segments and data segments have fixed 64k limits,
20345 - * the transfer segment sizes are set at run time.
20346 - */
20347 - /* 32-bit code */
20348 - [GDT_ENTRY_PNPBIOS_CS32] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20349 - /* 16-bit code */
20350 - [GDT_ENTRY_PNPBIOS_CS16] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20351 - /* 16-bit data */
20352 - [GDT_ENTRY_PNPBIOS_DS] = GDT_ENTRY_INIT(0x0092, 0, 0xffff),
20353 - /* 16-bit data */
20354 - [GDT_ENTRY_PNPBIOS_TS1] = GDT_ENTRY_INIT(0x0092, 0, 0),
20355 - /* 16-bit data */
20356 - [GDT_ENTRY_PNPBIOS_TS2] = GDT_ENTRY_INIT(0x0092, 0, 0),
20357 - /*
20358 - * The APM segments have byte granularity and their bases
20359 - * are set at run time. All have 64k limits.
20360 - */
20361 - /* 32-bit code */
20362 - [GDT_ENTRY_APMBIOS_BASE] = GDT_ENTRY_INIT(0x409a, 0, 0xffff),
20363 - /* 16-bit code */
20364 - [GDT_ENTRY_APMBIOS_BASE+1] = GDT_ENTRY_INIT(0x009a, 0, 0xffff),
20365 - /* data */
20366 - [GDT_ENTRY_APMBIOS_BASE+2] = GDT_ENTRY_INIT(0x4092, 0, 0xffff),
20367 -
20368 - [GDT_ENTRY_ESPFIX_SS] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20369 - [GDT_ENTRY_PERCPU] = GDT_ENTRY_INIT(0xc092, 0, 0xfffff),
20370 - GDT_STACK_CANARY_INIT
20371 -#endif
20372 -} };
20373 -EXPORT_PER_CPU_SYMBOL_GPL(gdt_page);
20374 -
20375 static int __init x86_xsave_setup(char *s)
20376 {
20377 setup_clear_cpu_cap(X86_FEATURE_XSAVE);
20378 @@ -288,6 +234,59 @@ static __always_inline void setup_smap(struct cpuinfo_x86 *c)
20379 set_in_cr4(X86_CR4_SMAP);
20380 }
20381
20382 +#ifdef CONFIG_X86_64
20383 +static __init int setup_disable_pcid(char *arg)
20384 +{
20385 + setup_clear_cpu_cap(X86_FEATURE_PCID);
20386 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
20387 +
20388 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20389 + if (clone_pgd_mask != ~(pgdval_t)0UL)
20390 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20391 +#endif
20392 +
20393 + return 1;
20394 +}
20395 +__setup("nopcid", setup_disable_pcid);
20396 +
20397 +static void setup_pcid(struct cpuinfo_x86 *c)
20398 +{
20399 + if (!cpu_has(c, X86_FEATURE_PCID)) {
20400 + clear_cpu_cap(c, X86_FEATURE_INVPCID);
20401 +
20402 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20403 + if (clone_pgd_mask != ~(pgdval_t)0UL) {
20404 + pax_open_kernel();
20405 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
20406 + pax_close_kernel();
20407 + printk("PAX: slow and weak UDEREF enabled\n");
20408 + } else
20409 + printk("PAX: UDEREF disabled\n");
20410 +#endif
20411 +
20412 + return;
20413 + }
20414 +
20415 + printk("PAX: PCID detected\n");
20416 + set_in_cr4(X86_CR4_PCIDE);
20417 +
20418 +#ifdef CONFIG_PAX_MEMORY_UDEREF
20419 + pax_open_kernel();
20420 + clone_pgd_mask = ~(pgdval_t)0UL;
20421 + pax_close_kernel();
20422 + if (pax_user_shadow_base)
20423 + printk("PAX: weak UDEREF enabled\n");
20424 + else {
20425 + set_cpu_cap(c, X86_FEATURE_STRONGUDEREF);
20426 + printk("PAX: strong UDEREF enabled\n");
20427 + }
20428 +#endif
20429 +
20430 + if (cpu_has(c, X86_FEATURE_INVPCID))
20431 + printk("PAX: INVPCID detected\n");
20432 +}
20433 +#endif
20434 +
20435 /*
20436 * Some CPU features depend on higher CPUID levels, which may not always
20437 * be available due to CPUID level capping or broken virtualization
20438 @@ -388,7 +387,7 @@ void switch_to_new_gdt(int cpu)
20439 {
20440 struct desc_ptr gdt_descr;
20441
20442 - gdt_descr.address = (long)get_cpu_gdt_table(cpu);
20443 + gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
20444 gdt_descr.size = GDT_SIZE - 1;
20445 load_gdt(&gdt_descr);
20446 /* Reload the per-cpu base */
20447 @@ -877,6 +876,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20448 setup_smep(c);
20449 setup_smap(c);
20450
20451 +#ifdef CONFIG_X86_64
20452 + setup_pcid(c);
20453 +#endif
20454 +
20455 /*
20456 * The vendor-specific functions might have changed features.
20457 * Now we do "generic changes."
20458 @@ -885,6 +888,10 @@ static void identify_cpu(struct cpuinfo_x86 *c)
20459 /* Filter out anything that depends on CPUID levels we don't have */
20460 filter_cpuid_features(c, true);
20461
20462 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
20463 + setup_clear_cpu_cap(X86_FEATURE_SEP);
20464 +#endif
20465 +
20466 /* If the model name is still unset, do table lookup. */
20467 if (!c->x86_model_id[0]) {
20468 const char *p;
20469 @@ -1072,10 +1079,12 @@ static __init int setup_disablecpuid(char *arg)
20470 }
20471 __setup("clearcpuid=", setup_disablecpuid);
20472
20473 +DEFINE_PER_CPU(struct thread_info *, current_tinfo) = &init_task.tinfo;
20474 +EXPORT_PER_CPU_SYMBOL(current_tinfo);
20475 +
20476 #ifdef CONFIG_X86_64
20477 -struct desc_ptr idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20478 -struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1,
20479 - (unsigned long) debug_idt_table };
20480 +struct desc_ptr idt_descr __read_only = { NR_VECTORS * 16 - 1, (unsigned long) idt_table };
20481 +const struct desc_ptr debug_idt_descr = { NR_VECTORS * 16 - 1, (unsigned long) debug_idt_table };
20482
20483 DEFINE_PER_CPU_FIRST(union irq_stack_union,
20484 irq_stack_union) __aligned(PAGE_SIZE) __visible;
20485 @@ -1089,7 +1098,7 @@ DEFINE_PER_CPU(struct task_struct *, current_task) ____cacheline_aligned =
20486 EXPORT_PER_CPU_SYMBOL(current_task);
20487
20488 DEFINE_PER_CPU(unsigned long, kernel_stack) =
20489 - (unsigned long)&init_thread_union - KERNEL_STACK_OFFSET + THREAD_SIZE;
20490 + (unsigned long)&init_thread_union - 16 + THREAD_SIZE;
20491 EXPORT_PER_CPU_SYMBOL(kernel_stack);
20492
20493 DEFINE_PER_CPU(char *, irq_stack_ptr) =
20494 @@ -1239,7 +1248,7 @@ void cpu_init(void)
20495 load_ucode_ap();
20496
20497 cpu = stack_smp_processor_id();
20498 - t = &per_cpu(init_tss, cpu);
20499 + t = init_tss + cpu;
20500 oist = &per_cpu(orig_ist, cpu);
20501
20502 #ifdef CONFIG_NUMA
20503 @@ -1274,7 +1283,6 @@ void cpu_init(void)
20504 wrmsrl(MSR_KERNEL_GS_BASE, 0);
20505 barrier();
20506
20507 - x86_configure_nx();
20508 enable_x2apic();
20509
20510 /*
20511 @@ -1326,7 +1334,7 @@ void cpu_init(void)
20512 {
20513 int cpu = smp_processor_id();
20514 struct task_struct *curr = current;
20515 - struct tss_struct *t = &per_cpu(init_tss, cpu);
20516 + struct tss_struct *t = init_tss + cpu;
20517 struct thread_struct *thread = &curr->thread;
20518
20519 show_ucode_info_early();
20520 diff --git a/arch/x86/kernel/cpu/intel_cacheinfo.c b/arch/x86/kernel/cpu/intel_cacheinfo.c
20521 index 0641113..06f5ba4 100644
20522 --- a/arch/x86/kernel/cpu/intel_cacheinfo.c
20523 +++ b/arch/x86/kernel/cpu/intel_cacheinfo.c
20524 @@ -1014,6 +1014,22 @@ static struct attribute *default_attrs[] = {
20525 };
20526
20527 #ifdef CONFIG_AMD_NB
20528 +static struct attribute *default_attrs_amd_nb[] = {
20529 + &type.attr,
20530 + &level.attr,
20531 + &coherency_line_size.attr,
20532 + &physical_line_partition.attr,
20533 + &ways_of_associativity.attr,
20534 + &number_of_sets.attr,
20535 + &size.attr,
20536 + &shared_cpu_map.attr,
20537 + &shared_cpu_list.attr,
20538 + NULL,
20539 + NULL,
20540 + NULL,
20541 + NULL
20542 +};
20543 +
20544 static struct attribute **amd_l3_attrs(void)
20545 {
20546 static struct attribute **attrs;
20547 @@ -1024,18 +1040,7 @@ static struct attribute **amd_l3_attrs(void)
20548
20549 n = ARRAY_SIZE(default_attrs);
20550
20551 - if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE))
20552 - n += 2;
20553 -
20554 - if (amd_nb_has_feature(AMD_NB_L3_PARTITIONING))
20555 - n += 1;
20556 -
20557 - attrs = kzalloc(n * sizeof (struct attribute *), GFP_KERNEL);
20558 - if (attrs == NULL)
20559 - return attrs = default_attrs;
20560 -
20561 - for (n = 0; default_attrs[n]; n++)
20562 - attrs[n] = default_attrs[n];
20563 + attrs = default_attrs_amd_nb;
20564
20565 if (amd_nb_has_feature(AMD_NB_L3_INDEX_DISABLE)) {
20566 attrs[n++] = &cache_disable_0.attr;
20567 @@ -1086,6 +1091,13 @@ static struct kobj_type ktype_cache = {
20568 .default_attrs = default_attrs,
20569 };
20570
20571 +#ifdef CONFIG_AMD_NB
20572 +static struct kobj_type ktype_cache_amd_nb = {
20573 + .sysfs_ops = &sysfs_ops,
20574 + .default_attrs = default_attrs_amd_nb,
20575 +};
20576 +#endif
20577 +
20578 static struct kobj_type ktype_percpu_entry = {
20579 .sysfs_ops = &sysfs_ops,
20580 };
20581 @@ -1151,20 +1163,26 @@ static int cache_add_dev(struct device *dev)
20582 return retval;
20583 }
20584
20585 +#ifdef CONFIG_AMD_NB
20586 + amd_l3_attrs();
20587 +#endif
20588 +
20589 for (i = 0; i < num_cache_leaves; i++) {
20590 + struct kobj_type *ktype;
20591 +
20592 this_object = INDEX_KOBJECT_PTR(cpu, i);
20593 this_object->cpu = cpu;
20594 this_object->index = i;
20595
20596 this_leaf = CPUID4_INFO_IDX(cpu, i);
20597
20598 - ktype_cache.default_attrs = default_attrs;
20599 + ktype = &ktype_cache;
20600 #ifdef CONFIG_AMD_NB
20601 if (this_leaf->base.nb)
20602 - ktype_cache.default_attrs = amd_l3_attrs();
20603 + ktype = &ktype_cache_amd_nb;
20604 #endif
20605 retval = kobject_init_and_add(&(this_object->kobj),
20606 - &ktype_cache,
20607 + ktype,
20608 per_cpu(ici_cache_kobject, cpu),
20609 "index%1lu", i);
20610 if (unlikely(retval)) {
20611 diff --git a/arch/x86/kernel/cpu/mcheck/mce.c b/arch/x86/kernel/cpu/mcheck/mce.c
20612 index b3218cd..99a75de 100644
20613 --- a/arch/x86/kernel/cpu/mcheck/mce.c
20614 +++ b/arch/x86/kernel/cpu/mcheck/mce.c
20615 @@ -45,6 +45,7 @@
20616 #include <asm/processor.h>
20617 #include <asm/mce.h>
20618 #include <asm/msr.h>
20619 +#include <asm/local.h>
20620
20621 #include "mce-internal.h"
20622
20623 @@ -258,7 +259,7 @@ static void print_mce(struct mce *m)
20624 !(m->mcgstatus & MCG_STATUS_EIPV) ? " !INEXACT!" : "",
20625 m->cs, m->ip);
20626
20627 - if (m->cs == __KERNEL_CS)
20628 + if (m->cs == __KERNEL_CS || m->cs == __KERNEXEC_KERNEL_CS)
20629 print_symbol("{%s}", m->ip);
20630 pr_cont("\n");
20631 }
20632 @@ -291,10 +292,10 @@ static void print_mce(struct mce *m)
20633
20634 #define PANIC_TIMEOUT 5 /* 5 seconds */
20635
20636 -static atomic_t mce_paniced;
20637 +static atomic_unchecked_t mce_paniced;
20638
20639 static int fake_panic;
20640 -static atomic_t mce_fake_paniced;
20641 +static atomic_unchecked_t mce_fake_paniced;
20642
20643 /* Panic in progress. Enable interrupts and wait for final IPI */
20644 static void wait_for_panic(void)
20645 @@ -318,7 +319,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20646 /*
20647 * Make sure only one CPU runs in machine check panic
20648 */
20649 - if (atomic_inc_return(&mce_paniced) > 1)
20650 + if (atomic_inc_return_unchecked(&mce_paniced) > 1)
20651 wait_for_panic();
20652 barrier();
20653
20654 @@ -326,7 +327,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20655 console_verbose();
20656 } else {
20657 /* Don't log too much for fake panic */
20658 - if (atomic_inc_return(&mce_fake_paniced) > 1)
20659 + if (atomic_inc_return_unchecked(&mce_fake_paniced) > 1)
20660 return;
20661 }
20662 /* First print corrected ones that are still unlogged */
20663 @@ -365,7 +366,7 @@ static void mce_panic(char *msg, struct mce *final, char *exp)
20664 if (!fake_panic) {
20665 if (panic_timeout == 0)
20666 panic_timeout = mca_cfg.panic_timeout;
20667 - panic(msg);
20668 + panic("%s", msg);
20669 } else
20670 pr_emerg(HW_ERR "Fake kernel panic: %s\n", msg);
20671 }
20672 @@ -695,7 +696,7 @@ static int mce_timed_out(u64 *t)
20673 * might have been modified by someone else.
20674 */
20675 rmb();
20676 - if (atomic_read(&mce_paniced))
20677 + if (atomic_read_unchecked(&mce_paniced))
20678 wait_for_panic();
20679 if (!mca_cfg.monarch_timeout)
20680 goto out;
20681 @@ -1666,7 +1667,7 @@ static void unexpected_machine_check(struct pt_regs *regs, long error_code)
20682 }
20683
20684 /* Call the installed machine check handler for this CPU setup. */
20685 -void (*machine_check_vector)(struct pt_regs *, long error_code) =
20686 +void (*machine_check_vector)(struct pt_regs *, long error_code) __read_only =
20687 unexpected_machine_check;
20688
20689 /*
20690 @@ -1689,7 +1690,9 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
20691 return;
20692 }
20693
20694 + pax_open_kernel();
20695 machine_check_vector = do_machine_check;
20696 + pax_close_kernel();
20697
20698 __mcheck_cpu_init_generic();
20699 __mcheck_cpu_init_vendor(c);
20700 @@ -1703,7 +1706,7 @@ void mcheck_cpu_init(struct cpuinfo_x86 *c)
20701 */
20702
20703 static DEFINE_SPINLOCK(mce_chrdev_state_lock);
20704 -static int mce_chrdev_open_count; /* #times opened */
20705 +static local_t mce_chrdev_open_count; /* #times opened */
20706 static int mce_chrdev_open_exclu; /* already open exclusive? */
20707
20708 static int mce_chrdev_open(struct inode *inode, struct file *file)
20709 @@ -1711,7 +1714,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
20710 spin_lock(&mce_chrdev_state_lock);
20711
20712 if (mce_chrdev_open_exclu ||
20713 - (mce_chrdev_open_count && (file->f_flags & O_EXCL))) {
20714 + (local_read(&mce_chrdev_open_count) && (file->f_flags & O_EXCL))) {
20715 spin_unlock(&mce_chrdev_state_lock);
20716
20717 return -EBUSY;
20718 @@ -1719,7 +1722,7 @@ static int mce_chrdev_open(struct inode *inode, struct file *file)
20719
20720 if (file->f_flags & O_EXCL)
20721 mce_chrdev_open_exclu = 1;
20722 - mce_chrdev_open_count++;
20723 + local_inc(&mce_chrdev_open_count);
20724
20725 spin_unlock(&mce_chrdev_state_lock);
20726
20727 @@ -1730,7 +1733,7 @@ static int mce_chrdev_release(struct inode *inode, struct file *file)
20728 {
20729 spin_lock(&mce_chrdev_state_lock);
20730
20731 - mce_chrdev_open_count--;
20732 + local_dec(&mce_chrdev_open_count);
20733 mce_chrdev_open_exclu = 0;
20734
20735 spin_unlock(&mce_chrdev_state_lock);
20736 @@ -2404,7 +2407,7 @@ static __init void mce_init_banks(void)
20737
20738 for (i = 0; i < mca_cfg.banks; i++) {
20739 struct mce_bank *b = &mce_banks[i];
20740 - struct device_attribute *a = &b->attr;
20741 + device_attribute_no_const *a = &b->attr;
20742
20743 sysfs_attr_init(&a->attr);
20744 a->attr.name = b->attrname;
20745 @@ -2472,7 +2475,7 @@ struct dentry *mce_get_debugfs_dir(void)
20746 static void mce_reset(void)
20747 {
20748 cpu_missing = 0;
20749 - atomic_set(&mce_fake_paniced, 0);
20750 + atomic_set_unchecked(&mce_fake_paniced, 0);
20751 atomic_set(&mce_executing, 0);
20752 atomic_set(&mce_callin, 0);
20753 atomic_set(&global_nwo, 0);
20754 diff --git a/arch/x86/kernel/cpu/mcheck/p5.c b/arch/x86/kernel/cpu/mcheck/p5.c
20755 index 1c044b1..37a2a43 100644
20756 --- a/arch/x86/kernel/cpu/mcheck/p5.c
20757 +++ b/arch/x86/kernel/cpu/mcheck/p5.c
20758 @@ -11,6 +11,7 @@
20759 #include <asm/processor.h>
20760 #include <asm/mce.h>
20761 #include <asm/msr.h>
20762 +#include <asm/pgtable.h>
20763
20764 /* By default disabled */
20765 int mce_p5_enabled __read_mostly;
20766 @@ -49,7 +50,9 @@ void intel_p5_mcheck_init(struct cpuinfo_x86 *c)
20767 if (!cpu_has(c, X86_FEATURE_MCE))
20768 return;
20769
20770 + pax_open_kernel();
20771 machine_check_vector = pentium_machine_check;
20772 + pax_close_kernel();
20773 /* Make sure the vector pointer is visible before we enable MCEs: */
20774 wmb();
20775
20776 diff --git a/arch/x86/kernel/cpu/mcheck/winchip.c b/arch/x86/kernel/cpu/mcheck/winchip.c
20777 index e9a701a..35317d6 100644
20778 --- a/arch/x86/kernel/cpu/mcheck/winchip.c
20779 +++ b/arch/x86/kernel/cpu/mcheck/winchip.c
20780 @@ -10,6 +10,7 @@
20781 #include <asm/processor.h>
20782 #include <asm/mce.h>
20783 #include <asm/msr.h>
20784 +#include <asm/pgtable.h>
20785
20786 /* Machine check handler for WinChip C6: */
20787 static void winchip_machine_check(struct pt_regs *regs, long error_code)
20788 @@ -23,7 +24,9 @@ void winchip_mcheck_init(struct cpuinfo_x86 *c)
20789 {
20790 u32 lo, hi;
20791
20792 + pax_open_kernel();
20793 machine_check_vector = winchip_machine_check;
20794 + pax_close_kernel();
20795 /* Make sure the vector pointer is visible before we enable MCEs: */
20796 wmb();
20797
20798 diff --git a/arch/x86/kernel/cpu/mtrr/main.c b/arch/x86/kernel/cpu/mtrr/main.c
20799 index f961de9..8a9d332 100644
20800 --- a/arch/x86/kernel/cpu/mtrr/main.c
20801 +++ b/arch/x86/kernel/cpu/mtrr/main.c
20802 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(mtrr_mutex);
20803 u64 size_or_mask, size_and_mask;
20804 static bool mtrr_aps_delayed_init;
20805
20806 -static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM];
20807 +static const struct mtrr_ops *mtrr_ops[X86_VENDOR_NUM] __read_only;
20808
20809 const struct mtrr_ops *mtrr_if;
20810
20811 diff --git a/arch/x86/kernel/cpu/mtrr/mtrr.h b/arch/x86/kernel/cpu/mtrr/mtrr.h
20812 index df5e41f..816c719 100644
20813 --- a/arch/x86/kernel/cpu/mtrr/mtrr.h
20814 +++ b/arch/x86/kernel/cpu/mtrr/mtrr.h
20815 @@ -25,7 +25,7 @@ struct mtrr_ops {
20816 int (*validate_add_page)(unsigned long base, unsigned long size,
20817 unsigned int type);
20818 int (*have_wrcomb)(void);
20819 -};
20820 +} __do_const;
20821
20822 extern int generic_get_free_region(unsigned long base, unsigned long size,
20823 int replace_reg);
20824 diff --git a/arch/x86/kernel/cpu/perf_event.c b/arch/x86/kernel/cpu/perf_event.c
20825 index 8e13293..9bfd68c 100644
20826 --- a/arch/x86/kernel/cpu/perf_event.c
20827 +++ b/arch/x86/kernel/cpu/perf_event.c
20828 @@ -1348,7 +1348,7 @@ static void __init pmu_check_apic(void)
20829 pr_info("no hardware sampling interrupt available.\n");
20830 }
20831
20832 -static struct attribute_group x86_pmu_format_group = {
20833 +static attribute_group_no_const x86_pmu_format_group = {
20834 .name = "format",
20835 .attrs = NULL,
20836 };
20837 @@ -1447,7 +1447,7 @@ static struct attribute *events_attr[] = {
20838 NULL,
20839 };
20840
20841 -static struct attribute_group x86_pmu_events_group = {
20842 +static attribute_group_no_const x86_pmu_events_group = {
20843 .name = "events",
20844 .attrs = events_attr,
20845 };
20846 @@ -1958,7 +1958,7 @@ static unsigned long get_segment_base(unsigned int segment)
20847 if (idx > GDT_ENTRIES)
20848 return 0;
20849
20850 - desc = __this_cpu_ptr(&gdt_page.gdt[0]);
20851 + desc = get_cpu_gdt_table(smp_processor_id());
20852 }
20853
20854 return get_desc_base(desc + idx);
20855 @@ -2048,7 +2048,7 @@ perf_callchain_user(struct perf_callchain_entry *entry, struct pt_regs *regs)
20856 break;
20857
20858 perf_callchain_store(entry, frame.return_address);
20859 - fp = frame.next_frame;
20860 + fp = (const void __force_user *)frame.next_frame;
20861 }
20862 }
20863
20864 diff --git a/arch/x86/kernel/cpu/perf_event_amd_iommu.c b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20865 index 639d128..e92d7e5 100644
20866 --- a/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20867 +++ b/arch/x86/kernel/cpu/perf_event_amd_iommu.c
20868 @@ -405,7 +405,7 @@ static void perf_iommu_del(struct perf_event *event, int flags)
20869 static __init int _init_events_attrs(struct perf_amd_iommu *perf_iommu)
20870 {
20871 struct attribute **attrs;
20872 - struct attribute_group *attr_group;
20873 + attribute_group_no_const *attr_group;
20874 int i = 0, j;
20875
20876 while (amd_iommu_v2_event_descs[i].attr.attr.name)
20877 diff --git a/arch/x86/kernel/cpu/perf_event_intel.c b/arch/x86/kernel/cpu/perf_event_intel.c
20878 index 0fa4f24..17990ed 100644
20879 --- a/arch/x86/kernel/cpu/perf_event_intel.c
20880 +++ b/arch/x86/kernel/cpu/perf_event_intel.c
20881 @@ -2314,10 +2314,10 @@ __init int intel_pmu_init(void)
20882 * v2 and above have a perf capabilities MSR
20883 */
20884 if (version > 1) {
20885 - u64 capabilities;
20886 + u64 capabilities = x86_pmu.intel_cap.capabilities;
20887
20888 - rdmsrl(MSR_IA32_PERF_CAPABILITIES, capabilities);
20889 - x86_pmu.intel_cap.capabilities = capabilities;
20890 + if (rdmsrl_safe(MSR_IA32_PERF_CAPABILITIES, &x86_pmu.intel_cap.capabilities))
20891 + x86_pmu.intel_cap.capabilities = capabilities;
20892 }
20893
20894 intel_ds_init();
20895 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.c b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20896 index 29c2487..a5606fa 100644
20897 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20898 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.c
20899 @@ -3318,7 +3318,7 @@ static void __init uncore_types_exit(struct intel_uncore_type **types)
20900 static int __init uncore_type_init(struct intel_uncore_type *type)
20901 {
20902 struct intel_uncore_pmu *pmus;
20903 - struct attribute_group *attr_group;
20904 + attribute_group_no_const *attr_group;
20905 struct attribute **attrs;
20906 int i, j;
20907
20908 diff --git a/arch/x86/kernel/cpu/perf_event_intel_uncore.h b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20909 index a80ab71..4089da5 100644
20910 --- a/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20911 +++ b/arch/x86/kernel/cpu/perf_event_intel_uncore.h
20912 @@ -498,7 +498,7 @@ struct intel_uncore_box {
20913 struct uncore_event_desc {
20914 struct kobj_attribute attr;
20915 const char *config;
20916 -};
20917 +} __do_const;
20918
20919 #define INTEL_UNCORE_EVENT_DESC(_name, _config) \
20920 { \
20921 diff --git a/arch/x86/kernel/cpuid.c b/arch/x86/kernel/cpuid.c
20922 index 7d9481c..99c7e4b 100644
20923 --- a/arch/x86/kernel/cpuid.c
20924 +++ b/arch/x86/kernel/cpuid.c
20925 @@ -170,7 +170,7 @@ static int cpuid_class_cpu_callback(struct notifier_block *nfb,
20926 return notifier_from_errno(err);
20927 }
20928
20929 -static struct notifier_block __refdata cpuid_class_cpu_notifier =
20930 +static struct notifier_block cpuid_class_cpu_notifier =
20931 {
20932 .notifier_call = cpuid_class_cpu_callback,
20933 };
20934 diff --git a/arch/x86/kernel/crash.c b/arch/x86/kernel/crash.c
20935 index 18677a9..f67c45b 100644
20936 --- a/arch/x86/kernel/crash.c
20937 +++ b/arch/x86/kernel/crash.c
20938 @@ -58,10 +58,8 @@ static void kdump_nmi_callback(int cpu, struct pt_regs *regs)
20939 {
20940 #ifdef CONFIG_X86_32
20941 struct pt_regs fixed_regs;
20942 -#endif
20943
20944 -#ifdef CONFIG_X86_32
20945 - if (!user_mode_vm(regs)) {
20946 + if (!user_mode(regs)) {
20947 crash_fixup_ss_esp(&fixed_regs, regs);
20948 regs = &fixed_regs;
20949 }
20950 diff --git a/arch/x86/kernel/crash_dump_64.c b/arch/x86/kernel/crash_dump_64.c
20951 index afa64ad..dce67dd 100644
20952 --- a/arch/x86/kernel/crash_dump_64.c
20953 +++ b/arch/x86/kernel/crash_dump_64.c
20954 @@ -36,7 +36,7 @@ ssize_t copy_oldmem_page(unsigned long pfn, char *buf,
20955 return -ENOMEM;
20956
20957 if (userbuf) {
20958 - if (copy_to_user(buf, vaddr + offset, csize)) {
20959 + if (copy_to_user((char __force_user *)buf, vaddr + offset, csize)) {
20960 iounmap(vaddr);
20961 return -EFAULT;
20962 }
20963 diff --git a/arch/x86/kernel/doublefault.c b/arch/x86/kernel/doublefault.c
20964 index 5d3fe8d..02e1429 100644
20965 --- a/arch/x86/kernel/doublefault.c
20966 +++ b/arch/x86/kernel/doublefault.c
20967 @@ -13,7 +13,7 @@
20968
20969 #define DOUBLEFAULT_STACKSIZE (1024)
20970 static unsigned long doublefault_stack[DOUBLEFAULT_STACKSIZE];
20971 -#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE)
20972 +#define STACK_START (unsigned long)(doublefault_stack+DOUBLEFAULT_STACKSIZE-2)
20973
20974 #define ptr_ok(x) ((x) > PAGE_OFFSET && (x) < PAGE_OFFSET + MAXMEM)
20975
20976 @@ -23,7 +23,7 @@ static void doublefault_fn(void)
20977 unsigned long gdt, tss;
20978
20979 native_store_gdt(&gdt_desc);
20980 - gdt = gdt_desc.address;
20981 + gdt = (unsigned long)gdt_desc.address;
20982
20983 printk(KERN_EMERG "PANIC: double fault, gdt at %08lx [%d bytes]\n", gdt, gdt_desc.size);
20984
20985 @@ -60,10 +60,10 @@ struct tss_struct doublefault_tss __cacheline_aligned = {
20986 /* 0x2 bit is always set */
20987 .flags = X86_EFLAGS_SF | 0x2,
20988 .sp = STACK_START,
20989 - .es = __USER_DS,
20990 + .es = __KERNEL_DS,
20991 .cs = __KERNEL_CS,
20992 .ss = __KERNEL_DS,
20993 - .ds = __USER_DS,
20994 + .ds = __KERNEL_DS,
20995 .fs = __KERNEL_PERCPU,
20996
20997 .__cr3 = __pa_nodebug(swapper_pg_dir),
20998 diff --git a/arch/x86/kernel/dumpstack.c b/arch/x86/kernel/dumpstack.c
20999 index d9c12d3..7858b62 100644
21000 --- a/arch/x86/kernel/dumpstack.c
21001 +++ b/arch/x86/kernel/dumpstack.c
21002 @@ -2,6 +2,9 @@
21003 * Copyright (C) 1991, 1992 Linus Torvalds
21004 * Copyright (C) 2000, 2001, 2002 Andi Kleen, SuSE Labs
21005 */
21006 +#ifdef CONFIG_GRKERNSEC_HIDESYM
21007 +#define __INCLUDED_BY_HIDESYM 1
21008 +#endif
21009 #include <linux/kallsyms.h>
21010 #include <linux/kprobes.h>
21011 #include <linux/uaccess.h>
21012 @@ -40,16 +43,14 @@ void printk_address(unsigned long address)
21013 static void
21014 print_ftrace_graph_addr(unsigned long addr, void *data,
21015 const struct stacktrace_ops *ops,
21016 - struct thread_info *tinfo, int *graph)
21017 + struct task_struct *task, int *graph)
21018 {
21019 - struct task_struct *task;
21020 unsigned long ret_addr;
21021 int index;
21022
21023 if (addr != (unsigned long)return_to_handler)
21024 return;
21025
21026 - task = tinfo->task;
21027 index = task->curr_ret_stack;
21028
21029 if (!task->ret_stack || index < *graph)
21030 @@ -66,7 +67,7 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21031 static inline void
21032 print_ftrace_graph_addr(unsigned long addr, void *data,
21033 const struct stacktrace_ops *ops,
21034 - struct thread_info *tinfo, int *graph)
21035 + struct task_struct *task, int *graph)
21036 { }
21037 #endif
21038
21039 @@ -77,10 +78,8 @@ print_ftrace_graph_addr(unsigned long addr, void *data,
21040 * severe exception (double fault, nmi, stack fault, debug, mce) hardware stack
21041 */
21042
21043 -static inline int valid_stack_ptr(struct thread_info *tinfo,
21044 - void *p, unsigned int size, void *end)
21045 +static inline int valid_stack_ptr(void *t, void *p, unsigned int size, void *end)
21046 {
21047 - void *t = tinfo;
21048 if (end) {
21049 if (p < end && p >= (end-THREAD_SIZE))
21050 return 1;
21051 @@ -91,14 +90,14 @@ static inline int valid_stack_ptr(struct thread_info *tinfo,
21052 }
21053
21054 unsigned long
21055 -print_context_stack(struct thread_info *tinfo,
21056 +print_context_stack(struct task_struct *task, void *stack_start,
21057 unsigned long *stack, unsigned long bp,
21058 const struct stacktrace_ops *ops, void *data,
21059 unsigned long *end, int *graph)
21060 {
21061 struct stack_frame *frame = (struct stack_frame *)bp;
21062
21063 - while (valid_stack_ptr(tinfo, stack, sizeof(*stack), end)) {
21064 + while (valid_stack_ptr(stack_start, stack, sizeof(*stack), end)) {
21065 unsigned long addr;
21066
21067 addr = *stack;
21068 @@ -110,7 +109,7 @@ print_context_stack(struct thread_info *tinfo,
21069 } else {
21070 ops->address(data, addr, 0);
21071 }
21072 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21073 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21074 }
21075 stack++;
21076 }
21077 @@ -119,7 +118,7 @@ print_context_stack(struct thread_info *tinfo,
21078 EXPORT_SYMBOL_GPL(print_context_stack);
21079
21080 unsigned long
21081 -print_context_stack_bp(struct thread_info *tinfo,
21082 +print_context_stack_bp(struct task_struct *task, void *stack_start,
21083 unsigned long *stack, unsigned long bp,
21084 const struct stacktrace_ops *ops, void *data,
21085 unsigned long *end, int *graph)
21086 @@ -127,7 +126,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21087 struct stack_frame *frame = (struct stack_frame *)bp;
21088 unsigned long *ret_addr = &frame->return_address;
21089
21090 - while (valid_stack_ptr(tinfo, ret_addr, sizeof(*ret_addr), end)) {
21091 + while (valid_stack_ptr(stack_start, ret_addr, sizeof(*ret_addr), end)) {
21092 unsigned long addr = *ret_addr;
21093
21094 if (!__kernel_text_address(addr))
21095 @@ -136,7 +135,7 @@ print_context_stack_bp(struct thread_info *tinfo,
21096 ops->address(data, addr, 1);
21097 frame = frame->next_frame;
21098 ret_addr = &frame->return_address;
21099 - print_ftrace_graph_addr(addr, data, ops, tinfo, graph);
21100 + print_ftrace_graph_addr(addr, data, ops, task, graph);
21101 }
21102
21103 return (unsigned long)frame;
21104 @@ -155,7 +154,7 @@ static int print_trace_stack(void *data, char *name)
21105 static void print_trace_address(void *data, unsigned long addr, int reliable)
21106 {
21107 touch_nmi_watchdog();
21108 - printk(data);
21109 + printk("%s", (char *)data);
21110 printk_stack_address(addr, reliable);
21111 }
21112
21113 @@ -224,6 +223,8 @@ unsigned __kprobes long oops_begin(void)
21114 }
21115 EXPORT_SYMBOL_GPL(oops_begin);
21116
21117 +extern void gr_handle_kernel_exploit(void);
21118 +
21119 void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21120 {
21121 if (regs && kexec_should_crash(current))
21122 @@ -245,7 +246,10 @@ void __kprobes oops_end(unsigned long flags, struct pt_regs *regs, int signr)
21123 panic("Fatal exception in interrupt");
21124 if (panic_on_oops)
21125 panic("Fatal exception");
21126 - do_exit(signr);
21127 +
21128 + gr_handle_kernel_exploit();
21129 +
21130 + do_group_exit(signr);
21131 }
21132
21133 int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21134 @@ -273,7 +277,7 @@ int __kprobes __die(const char *str, struct pt_regs *regs, long err)
21135 print_modules();
21136 show_regs(regs);
21137 #ifdef CONFIG_X86_32
21138 - if (user_mode_vm(regs)) {
21139 + if (user_mode(regs)) {
21140 sp = regs->sp;
21141 ss = regs->ss & 0xffff;
21142 } else {
21143 @@ -301,7 +305,7 @@ void die(const char *str, struct pt_regs *regs, long err)
21144 unsigned long flags = oops_begin();
21145 int sig = SIGSEGV;
21146
21147 - if (!user_mode_vm(regs))
21148 + if (!user_mode(regs))
21149 report_bug(regs->ip, regs);
21150
21151 if (__die(str, regs, err))
21152 diff --git a/arch/x86/kernel/dumpstack_32.c b/arch/x86/kernel/dumpstack_32.c
21153 index f2a1770..540657f 100644
21154 --- a/arch/x86/kernel/dumpstack_32.c
21155 +++ b/arch/x86/kernel/dumpstack_32.c
21156 @@ -38,15 +38,13 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21157 bp = stack_frame(task, regs);
21158
21159 for (;;) {
21160 - struct thread_info *context;
21161 + void *stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21162
21163 - context = (struct thread_info *)
21164 - ((unsigned long)stack & (~(THREAD_SIZE - 1)));
21165 - bp = ops->walk_stack(context, stack, bp, ops, data, NULL, &graph);
21166 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21167
21168 - stack = (unsigned long *)context->previous_esp;
21169 - if (!stack)
21170 + if (stack_start == task_stack_page(task))
21171 break;
21172 + stack = *(unsigned long **)stack_start;
21173 if (ops->stack(data, "IRQ") < 0)
21174 break;
21175 touch_nmi_watchdog();
21176 @@ -87,27 +85,28 @@ void show_regs(struct pt_regs *regs)
21177 int i;
21178
21179 show_regs_print_info(KERN_EMERG);
21180 - __show_regs(regs, !user_mode_vm(regs));
21181 + __show_regs(regs, !user_mode(regs));
21182
21183 /*
21184 * When in-kernel, we also print out the stack and code at the
21185 * time of the fault..
21186 */
21187 - if (!user_mode_vm(regs)) {
21188 + if (!user_mode(regs)) {
21189 unsigned int code_prologue = code_bytes * 43 / 64;
21190 unsigned int code_len = code_bytes;
21191 unsigned char c;
21192 u8 *ip;
21193 + unsigned long cs_base = get_desc_base(&get_cpu_gdt_table(0)[(0xffff & regs->cs) >> 3]);
21194
21195 pr_emerg("Stack:\n");
21196 show_stack_log_lvl(NULL, regs, &regs->sp, 0, KERN_EMERG);
21197
21198 pr_emerg("Code:");
21199
21200 - ip = (u8 *)regs->ip - code_prologue;
21201 + ip = (u8 *)regs->ip - code_prologue + cs_base;
21202 if (ip < (u8 *)PAGE_OFFSET || probe_kernel_address(ip, c)) {
21203 /* try starting at IP */
21204 - ip = (u8 *)regs->ip;
21205 + ip = (u8 *)regs->ip + cs_base;
21206 code_len = code_len - code_prologue + 1;
21207 }
21208 for (i = 0; i < code_len; i++, ip++) {
21209 @@ -116,7 +115,7 @@ void show_regs(struct pt_regs *regs)
21210 pr_cont(" Bad EIP value.");
21211 break;
21212 }
21213 - if (ip == (u8 *)regs->ip)
21214 + if (ip == (u8 *)regs->ip + cs_base)
21215 pr_cont(" <%02x>", c);
21216 else
21217 pr_cont(" %02x", c);
21218 @@ -129,6 +128,7 @@ int is_valid_bugaddr(unsigned long ip)
21219 {
21220 unsigned short ud2;
21221
21222 + ip = ktla_ktva(ip);
21223 if (ip < PAGE_OFFSET)
21224 return 0;
21225 if (probe_kernel_address((unsigned short *)ip, ud2))
21226 @@ -136,3 +136,15 @@ int is_valid_bugaddr(unsigned long ip)
21227
21228 return ud2 == 0x0b0f;
21229 }
21230 +
21231 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21232 +void pax_check_alloca(unsigned long size)
21233 +{
21234 + unsigned long sp = (unsigned long)&sp, stack_left;
21235 +
21236 + /* all kernel stacks are of the same size */
21237 + stack_left = sp & (THREAD_SIZE - 1);
21238 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21239 +}
21240 +EXPORT_SYMBOL(pax_check_alloca);
21241 +#endif
21242 diff --git a/arch/x86/kernel/dumpstack_64.c b/arch/x86/kernel/dumpstack_64.c
21243 index addb207..99635fa 100644
21244 --- a/arch/x86/kernel/dumpstack_64.c
21245 +++ b/arch/x86/kernel/dumpstack_64.c
21246 @@ -119,9 +119,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21247 unsigned long *irq_stack_end =
21248 (unsigned long *)per_cpu(irq_stack_ptr, cpu);
21249 unsigned used = 0;
21250 - struct thread_info *tinfo;
21251 int graph = 0;
21252 unsigned long dummy;
21253 + void *stack_start;
21254
21255 if (!task)
21256 task = current;
21257 @@ -142,10 +142,10 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21258 * current stack address. If the stacks consist of nested
21259 * exceptions
21260 */
21261 - tinfo = task_thread_info(task);
21262 for (;;) {
21263 char *id;
21264 unsigned long *estack_end;
21265 +
21266 estack_end = in_exception_stack(cpu, (unsigned long)stack,
21267 &used, &id);
21268
21269 @@ -153,7 +153,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21270 if (ops->stack(data, id) < 0)
21271 break;
21272
21273 - bp = ops->walk_stack(tinfo, stack, bp, ops,
21274 + bp = ops->walk_stack(task, estack_end - EXCEPTION_STKSZ, stack, bp, ops,
21275 data, estack_end, &graph);
21276 ops->stack(data, "<EOE>");
21277 /*
21278 @@ -161,6 +161,8 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21279 * second-to-last pointer (index -2 to end) in the
21280 * exception stack:
21281 */
21282 + if ((u16)estack_end[-1] != __KERNEL_DS)
21283 + goto out;
21284 stack = (unsigned long *) estack_end[-2];
21285 continue;
21286 }
21287 @@ -172,7 +174,7 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21288 if (in_irq_stack(stack, irq_stack, irq_stack_end)) {
21289 if (ops->stack(data, "IRQ") < 0)
21290 break;
21291 - bp = ops->walk_stack(tinfo, stack, bp,
21292 + bp = ops->walk_stack(task, irq_stack, stack, bp,
21293 ops, data, irq_stack_end, &graph);
21294 /*
21295 * We link to the next stack (which would be
21296 @@ -191,7 +193,9 @@ void dump_trace(struct task_struct *task, struct pt_regs *regs,
21297 /*
21298 * This handles the process stack:
21299 */
21300 - bp = ops->walk_stack(tinfo, stack, bp, ops, data, NULL, &graph);
21301 + stack_start = (void *)((unsigned long)stack & ~(THREAD_SIZE-1));
21302 + bp = ops->walk_stack(task, stack_start, stack, bp, ops, data, NULL, &graph);
21303 +out:
21304 put_cpu();
21305 }
21306 EXPORT_SYMBOL(dump_trace);
21307 @@ -300,3 +304,50 @@ int is_valid_bugaddr(unsigned long ip)
21308
21309 return ud2 == 0x0b0f;
21310 }
21311 +
21312 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21313 +void pax_check_alloca(unsigned long size)
21314 +{
21315 + unsigned long sp = (unsigned long)&sp, stack_start, stack_end;
21316 + unsigned cpu, used;
21317 + char *id;
21318 +
21319 + /* check the process stack first */
21320 + stack_start = (unsigned long)task_stack_page(current);
21321 + stack_end = stack_start + THREAD_SIZE;
21322 + if (likely(stack_start <= sp && sp < stack_end)) {
21323 + unsigned long stack_left = sp & (THREAD_SIZE - 1);
21324 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21325 + return;
21326 + }
21327 +
21328 + cpu = get_cpu();
21329 +
21330 + /* check the irq stacks */
21331 + stack_end = (unsigned long)per_cpu(irq_stack_ptr, cpu);
21332 + stack_start = stack_end - IRQ_STACK_SIZE;
21333 + if (stack_start <= sp && sp < stack_end) {
21334 + unsigned long stack_left = sp & (IRQ_STACK_SIZE - 1);
21335 + put_cpu();
21336 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21337 + return;
21338 + }
21339 +
21340 + /* check the exception stacks */
21341 + used = 0;
21342 + stack_end = (unsigned long)in_exception_stack(cpu, sp, &used, &id);
21343 + stack_start = stack_end - EXCEPTION_STKSZ;
21344 + if (stack_end && stack_start <= sp && sp < stack_end) {
21345 + unsigned long stack_left = sp & (EXCEPTION_STKSZ - 1);
21346 + put_cpu();
21347 + BUG_ON(stack_left < 256 || size >= stack_left - 256);
21348 + return;
21349 + }
21350 +
21351 + put_cpu();
21352 +
21353 + /* unknown stack */
21354 + BUG();
21355 +}
21356 +EXPORT_SYMBOL(pax_check_alloca);
21357 +#endif
21358 diff --git a/arch/x86/kernel/e820.c b/arch/x86/kernel/e820.c
21359 index 174da5f..5e55606 100644
21360 --- a/arch/x86/kernel/e820.c
21361 +++ b/arch/x86/kernel/e820.c
21362 @@ -803,8 +803,8 @@ unsigned long __init e820_end_of_low_ram_pfn(void)
21363
21364 static void early_panic(char *msg)
21365 {
21366 - early_printk(msg);
21367 - panic(msg);
21368 + early_printk("%s", msg);
21369 + panic("%s", msg);
21370 }
21371
21372 static int userdef __initdata;
21373 diff --git a/arch/x86/kernel/early_printk.c b/arch/x86/kernel/early_printk.c
21374 index 01d1c18..8073693 100644
21375 --- a/arch/x86/kernel/early_printk.c
21376 +++ b/arch/x86/kernel/early_printk.c
21377 @@ -7,6 +7,7 @@
21378 #include <linux/pci_regs.h>
21379 #include <linux/pci_ids.h>
21380 #include <linux/errno.h>
21381 +#include <linux/sched.h>
21382 #include <asm/io.h>
21383 #include <asm/processor.h>
21384 #include <asm/fcntl.h>
21385 diff --git a/arch/x86/kernel/entry_32.S b/arch/x86/kernel/entry_32.S
21386 index a2a4f46..6cab058 100644
21387 --- a/arch/x86/kernel/entry_32.S
21388 +++ b/arch/x86/kernel/entry_32.S
21389 @@ -177,13 +177,153 @@
21390 /*CFI_REL_OFFSET gs, PT_GS*/
21391 .endm
21392 .macro SET_KERNEL_GS reg
21393 +
21394 +#ifdef CONFIG_CC_STACKPROTECTOR
21395 movl $(__KERNEL_STACK_CANARY), \reg
21396 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
21397 + movl $(__USER_DS), \reg
21398 +#else
21399 + xorl \reg, \reg
21400 +#endif
21401 +
21402 movl \reg, %gs
21403 .endm
21404
21405 #endif /* CONFIG_X86_32_LAZY_GS */
21406
21407 -.macro SAVE_ALL
21408 +.macro pax_enter_kernel
21409 +#ifdef CONFIG_PAX_KERNEXEC
21410 + call pax_enter_kernel
21411 +#endif
21412 +.endm
21413 +
21414 +.macro pax_exit_kernel
21415 +#ifdef CONFIG_PAX_KERNEXEC
21416 + call pax_exit_kernel
21417 +#endif
21418 +.endm
21419 +
21420 +#ifdef CONFIG_PAX_KERNEXEC
21421 +ENTRY(pax_enter_kernel)
21422 +#ifdef CONFIG_PARAVIRT
21423 + pushl %eax
21424 + pushl %ecx
21425 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0)
21426 + mov %eax, %esi
21427 +#else
21428 + mov %cr0, %esi
21429 +#endif
21430 + bts $16, %esi
21431 + jnc 1f
21432 + mov %cs, %esi
21433 + cmp $__KERNEL_CS, %esi
21434 + jz 3f
21435 + ljmp $__KERNEL_CS, $3f
21436 +1: ljmp $__KERNEXEC_KERNEL_CS, $2f
21437 +2:
21438 +#ifdef CONFIG_PARAVIRT
21439 + mov %esi, %eax
21440 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0)
21441 +#else
21442 + mov %esi, %cr0
21443 +#endif
21444 +3:
21445 +#ifdef CONFIG_PARAVIRT
21446 + popl %ecx
21447 + popl %eax
21448 +#endif
21449 + ret
21450 +ENDPROC(pax_enter_kernel)
21451 +
21452 +ENTRY(pax_exit_kernel)
21453 +#ifdef CONFIG_PARAVIRT
21454 + pushl %eax
21455 + pushl %ecx
21456 +#endif
21457 + mov %cs, %esi
21458 + cmp $__KERNEXEC_KERNEL_CS, %esi
21459 + jnz 2f
21460 +#ifdef CONFIG_PARAVIRT
21461 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_read_cr0);
21462 + mov %eax, %esi
21463 +#else
21464 + mov %cr0, %esi
21465 +#endif
21466 + btr $16, %esi
21467 + ljmp $__KERNEL_CS, $1f
21468 +1:
21469 +#ifdef CONFIG_PARAVIRT
21470 + mov %esi, %eax
21471 + call PARA_INDIRECT(pv_cpu_ops+PV_CPU_write_cr0);
21472 +#else
21473 + mov %esi, %cr0
21474 +#endif
21475 +2:
21476 +#ifdef CONFIG_PARAVIRT
21477 + popl %ecx
21478 + popl %eax
21479 +#endif
21480 + ret
21481 +ENDPROC(pax_exit_kernel)
21482 +#endif
21483 +
21484 + .macro pax_erase_kstack
21485 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21486 + call pax_erase_kstack
21487 +#endif
21488 + .endm
21489 +
21490 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
21491 +/*
21492 + * ebp: thread_info
21493 + */
21494 +ENTRY(pax_erase_kstack)
21495 + pushl %edi
21496 + pushl %ecx
21497 + pushl %eax
21498 +
21499 + mov TI_lowest_stack(%ebp), %edi
21500 + mov $-0xBEEF, %eax
21501 + std
21502 +
21503 +1: mov %edi, %ecx
21504 + and $THREAD_SIZE_asm - 1, %ecx
21505 + shr $2, %ecx
21506 + repne scasl
21507 + jecxz 2f
21508 +
21509 + cmp $2*16, %ecx
21510 + jc 2f
21511 +
21512 + mov $2*16, %ecx
21513 + repe scasl
21514 + jecxz 2f
21515 + jne 1b
21516 +
21517 +2: cld
21518 + mov %esp, %ecx
21519 + sub %edi, %ecx
21520 +
21521 + cmp $THREAD_SIZE_asm, %ecx
21522 + jb 3f
21523 + ud2
21524 +3:
21525 +
21526 + shr $2, %ecx
21527 + rep stosl
21528 +
21529 + mov TI_task_thread_sp0(%ebp), %edi
21530 + sub $128, %edi
21531 + mov %edi, TI_lowest_stack(%ebp)
21532 +
21533 + popl %eax
21534 + popl %ecx
21535 + popl %edi
21536 + ret
21537 +ENDPROC(pax_erase_kstack)
21538 +#endif
21539 +
21540 +.macro __SAVE_ALL _DS
21541 cld
21542 PUSH_GS
21543 pushl_cfi %fs
21544 @@ -206,7 +346,7 @@
21545 CFI_REL_OFFSET ecx, 0
21546 pushl_cfi %ebx
21547 CFI_REL_OFFSET ebx, 0
21548 - movl $(__USER_DS), %edx
21549 + movl $\_DS, %edx
21550 movl %edx, %ds
21551 movl %edx, %es
21552 movl $(__KERNEL_PERCPU), %edx
21553 @@ -214,6 +354,15 @@
21554 SET_KERNEL_GS %edx
21555 .endm
21556
21557 +.macro SAVE_ALL
21558 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
21559 + __SAVE_ALL __KERNEL_DS
21560 + pax_enter_kernel
21561 +#else
21562 + __SAVE_ALL __USER_DS
21563 +#endif
21564 +.endm
21565 +
21566 .macro RESTORE_INT_REGS
21567 popl_cfi %ebx
21568 CFI_RESTORE ebx
21569 @@ -297,7 +446,7 @@ ENTRY(ret_from_fork)
21570 popfl_cfi
21571 jmp syscall_exit
21572 CFI_ENDPROC
21573 -END(ret_from_fork)
21574 +ENDPROC(ret_from_fork)
21575
21576 ENTRY(ret_from_kernel_thread)
21577 CFI_STARTPROC
21578 @@ -344,7 +493,15 @@ ret_from_intr:
21579 andl $SEGMENT_RPL_MASK, %eax
21580 #endif
21581 cmpl $USER_RPL, %eax
21582 +
21583 +#ifdef CONFIG_PAX_KERNEXEC
21584 + jae resume_userspace
21585 +
21586 + pax_exit_kernel
21587 + jmp resume_kernel
21588 +#else
21589 jb resume_kernel # not returning to v8086 or userspace
21590 +#endif
21591
21592 ENTRY(resume_userspace)
21593 LOCKDEP_SYS_EXIT
21594 @@ -356,8 +513,8 @@ ENTRY(resume_userspace)
21595 andl $_TIF_WORK_MASK, %ecx # is there any work to be done on
21596 # int/exception return?
21597 jne work_pending
21598 - jmp restore_all
21599 -END(ret_from_exception)
21600 + jmp restore_all_pax
21601 +ENDPROC(ret_from_exception)
21602
21603 #ifdef CONFIG_PREEMPT
21604 ENTRY(resume_kernel)
21605 @@ -369,7 +526,7 @@ need_resched:
21606 jz restore_all
21607 call preempt_schedule_irq
21608 jmp need_resched
21609 -END(resume_kernel)
21610 +ENDPROC(resume_kernel)
21611 #endif
21612 CFI_ENDPROC
21613 /*
21614 @@ -403,30 +560,45 @@ sysenter_past_esp:
21615 /*CFI_REL_OFFSET cs, 0*/
21616 /*
21617 * Push current_thread_info()->sysenter_return to the stack.
21618 - * A tiny bit of offset fixup is necessary - 4*4 means the 4 words
21619 - * pushed above; +8 corresponds to copy_thread's esp0 setting.
21620 */
21621 - pushl_cfi ((TI_sysenter_return)-THREAD_SIZE+8+4*4)(%esp)
21622 + pushl_cfi $0
21623 CFI_REL_OFFSET eip, 0
21624
21625 pushl_cfi %eax
21626 SAVE_ALL
21627 + GET_THREAD_INFO(%ebp)
21628 + movl TI_sysenter_return(%ebp),%ebp
21629 + movl %ebp,PT_EIP(%esp)
21630 ENABLE_INTERRUPTS(CLBR_NONE)
21631
21632 /*
21633 * Load the potential sixth argument from user stack.
21634 * Careful about security.
21635 */
21636 + movl PT_OLDESP(%esp),%ebp
21637 +
21638 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21639 + mov PT_OLDSS(%esp),%ds
21640 +1: movl %ds:(%ebp),%ebp
21641 + push %ss
21642 + pop %ds
21643 +#else
21644 cmpl $__PAGE_OFFSET-3,%ebp
21645 jae syscall_fault
21646 ASM_STAC
21647 1: movl (%ebp),%ebp
21648 ASM_CLAC
21649 +#endif
21650 +
21651 movl %ebp,PT_EBP(%esp)
21652 _ASM_EXTABLE(1b,syscall_fault)
21653
21654 GET_THREAD_INFO(%ebp)
21655
21656 +#ifdef CONFIG_PAX_RANDKSTACK
21657 + pax_erase_kstack
21658 +#endif
21659 +
21660 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
21661 jnz sysenter_audit
21662 sysenter_do_call:
21663 @@ -441,12 +613,24 @@ sysenter_do_call:
21664 testl $_TIF_ALLWORK_MASK, %ecx
21665 jne sysexit_audit
21666 sysenter_exit:
21667 +
21668 +#ifdef CONFIG_PAX_RANDKSTACK
21669 + pushl_cfi %eax
21670 + movl %esp, %eax
21671 + call pax_randomize_kstack
21672 + popl_cfi %eax
21673 +#endif
21674 +
21675 + pax_erase_kstack
21676 +
21677 /* if something modifies registers it must also disable sysexit */
21678 movl PT_EIP(%esp), %edx
21679 movl PT_OLDESP(%esp), %ecx
21680 xorl %ebp,%ebp
21681 TRACE_IRQS_ON
21682 1: mov PT_FS(%esp), %fs
21683 +2: mov PT_DS(%esp), %ds
21684 +3: mov PT_ES(%esp), %es
21685 PTGS_TO_GS
21686 ENABLE_INTERRUPTS_SYSEXIT
21687
21688 @@ -463,6 +647,9 @@ sysenter_audit:
21689 movl %eax,%edx /* 2nd arg: syscall number */
21690 movl $AUDIT_ARCH_I386,%eax /* 1st arg: audit arch */
21691 call __audit_syscall_entry
21692 +
21693 + pax_erase_kstack
21694 +
21695 pushl_cfi %ebx
21696 movl PT_EAX(%esp),%eax /* reload syscall number */
21697 jmp sysenter_do_call
21698 @@ -488,10 +675,16 @@ sysexit_audit:
21699
21700 CFI_ENDPROC
21701 .pushsection .fixup,"ax"
21702 -2: movl $0,PT_FS(%esp)
21703 +4: movl $0,PT_FS(%esp)
21704 + jmp 1b
21705 +5: movl $0,PT_DS(%esp)
21706 + jmp 1b
21707 +6: movl $0,PT_ES(%esp)
21708 jmp 1b
21709 .popsection
21710 - _ASM_EXTABLE(1b,2b)
21711 + _ASM_EXTABLE(1b,4b)
21712 + _ASM_EXTABLE(2b,5b)
21713 + _ASM_EXTABLE(3b,6b)
21714 PTGS_TO_GS_EX
21715 ENDPROC(ia32_sysenter_target)
21716
21717 @@ -506,6 +699,11 @@ ENTRY(system_call)
21718 pushl_cfi %eax # save orig_eax
21719 SAVE_ALL
21720 GET_THREAD_INFO(%ebp)
21721 +
21722 +#ifdef CONFIG_PAX_RANDKSTACK
21723 + pax_erase_kstack
21724 +#endif
21725 +
21726 # system call tracing in operation / emulation
21727 testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%ebp)
21728 jnz syscall_trace_entry
21729 @@ -524,6 +722,15 @@ syscall_exit:
21730 testl $_TIF_ALLWORK_MASK, %ecx # current->work
21731 jne syscall_exit_work
21732
21733 +restore_all_pax:
21734 +
21735 +#ifdef CONFIG_PAX_RANDKSTACK
21736 + movl %esp, %eax
21737 + call pax_randomize_kstack
21738 +#endif
21739 +
21740 + pax_erase_kstack
21741 +
21742 restore_all:
21743 TRACE_IRQS_IRET
21744 restore_all_notrace:
21745 @@ -580,14 +787,34 @@ ldt_ss:
21746 * compensating for the offset by changing to the ESPFIX segment with
21747 * a base address that matches for the difference.
21748 */
21749 -#define GDT_ESPFIX_SS PER_CPU_VAR(gdt_page) + (GDT_ENTRY_ESPFIX_SS * 8)
21750 +#define GDT_ESPFIX_SS (GDT_ENTRY_ESPFIX_SS * 8)(%ebx)
21751 mov %esp, %edx /* load kernel esp */
21752 mov PT_OLDESP(%esp), %eax /* load userspace esp */
21753 mov %dx, %ax /* eax: new kernel esp */
21754 sub %eax, %edx /* offset (low word is 0) */
21755 +#ifdef CONFIG_SMP
21756 + movl PER_CPU_VAR(cpu_number), %ebx
21757 + shll $PAGE_SHIFT_asm, %ebx
21758 + addl $cpu_gdt_table, %ebx
21759 +#else
21760 + movl $cpu_gdt_table, %ebx
21761 +#endif
21762 shr $16, %edx
21763 - mov %dl, GDT_ESPFIX_SS + 4 /* bits 16..23 */
21764 - mov %dh, GDT_ESPFIX_SS + 7 /* bits 24..31 */
21765 +
21766 +#ifdef CONFIG_PAX_KERNEXEC
21767 + mov %cr0, %esi
21768 + btr $16, %esi
21769 + mov %esi, %cr0
21770 +#endif
21771 +
21772 + mov %dl, 4 + GDT_ESPFIX_SS /* bits 16..23 */
21773 + mov %dh, 7 + GDT_ESPFIX_SS /* bits 24..31 */
21774 +
21775 +#ifdef CONFIG_PAX_KERNEXEC
21776 + bts $16, %esi
21777 + mov %esi, %cr0
21778 +#endif
21779 +
21780 pushl_cfi $__ESPFIX_SS
21781 pushl_cfi %eax /* new kernel esp */
21782 /* Disable interrupts, but do not irqtrace this section: we
21783 @@ -616,20 +843,18 @@ work_resched:
21784 movl TI_flags(%ebp), %ecx
21785 andl $_TIF_WORK_MASK, %ecx # is there any work to be done other
21786 # than syscall tracing?
21787 - jz restore_all
21788 + jz restore_all_pax
21789 testb $_TIF_NEED_RESCHED, %cl
21790 jnz work_resched
21791
21792 work_notifysig: # deal with pending signals and
21793 # notify-resume requests
21794 + movl %esp, %eax
21795 #ifdef CONFIG_VM86
21796 testl $X86_EFLAGS_VM, PT_EFLAGS(%esp)
21797 - movl %esp, %eax
21798 jne work_notifysig_v86 # returning to kernel-space or
21799 # vm86-space
21800 1:
21801 -#else
21802 - movl %esp, %eax
21803 #endif
21804 TRACE_IRQS_ON
21805 ENABLE_INTERRUPTS(CLBR_NONE)
21806 @@ -650,7 +875,7 @@ work_notifysig_v86:
21807 movl %eax, %esp
21808 jmp 1b
21809 #endif
21810 -END(work_pending)
21811 +ENDPROC(work_pending)
21812
21813 # perform syscall exit tracing
21814 ALIGN
21815 @@ -658,11 +883,14 @@ syscall_trace_entry:
21816 movl $-ENOSYS,PT_EAX(%esp)
21817 movl %esp, %eax
21818 call syscall_trace_enter
21819 +
21820 + pax_erase_kstack
21821 +
21822 /* What it returned is what we'll actually use. */
21823 cmpl $(NR_syscalls), %eax
21824 jnae syscall_call
21825 jmp syscall_exit
21826 -END(syscall_trace_entry)
21827 +ENDPROC(syscall_trace_entry)
21828
21829 # perform syscall exit tracing
21830 ALIGN
21831 @@ -675,21 +903,25 @@ syscall_exit_work:
21832 movl %esp, %eax
21833 call syscall_trace_leave
21834 jmp resume_userspace
21835 -END(syscall_exit_work)
21836 +ENDPROC(syscall_exit_work)
21837 CFI_ENDPROC
21838
21839 RING0_INT_FRAME # can't unwind into user space anyway
21840 syscall_fault:
21841 +#ifdef CONFIG_PAX_MEMORY_UDEREF
21842 + push %ss
21843 + pop %ds
21844 +#endif
21845 ASM_CLAC
21846 GET_THREAD_INFO(%ebp)
21847 movl $-EFAULT,PT_EAX(%esp)
21848 jmp resume_userspace
21849 -END(syscall_fault)
21850 +ENDPROC(syscall_fault)
21851
21852 syscall_badsys:
21853 movl $-ENOSYS,PT_EAX(%esp)
21854 jmp resume_userspace
21855 -END(syscall_badsys)
21856 +ENDPROC(syscall_badsys)
21857 CFI_ENDPROC
21858 /*
21859 * End of kprobes section
21860 @@ -705,8 +937,15 @@ END(syscall_badsys)
21861 * normal stack and adjusts ESP with the matching offset.
21862 */
21863 /* fixup the stack */
21864 - mov GDT_ESPFIX_SS + 4, %al /* bits 16..23 */
21865 - mov GDT_ESPFIX_SS + 7, %ah /* bits 24..31 */
21866 +#ifdef CONFIG_SMP
21867 + movl PER_CPU_VAR(cpu_number), %ebx
21868 + shll $PAGE_SHIFT_asm, %ebx
21869 + addl $cpu_gdt_table, %ebx
21870 +#else
21871 + movl $cpu_gdt_table, %ebx
21872 +#endif
21873 + mov 4 + GDT_ESPFIX_SS, %al /* bits 16..23 */
21874 + mov 7 + GDT_ESPFIX_SS, %ah /* bits 24..31 */
21875 shl $16, %eax
21876 addl %esp, %eax /* the adjusted stack pointer */
21877 pushl_cfi $__KERNEL_DS
21878 @@ -759,7 +998,7 @@ vector=vector+1
21879 .endr
21880 2: jmp common_interrupt
21881 .endr
21882 -END(irq_entries_start)
21883 +ENDPROC(irq_entries_start)
21884
21885 .previous
21886 END(interrupt)
21887 @@ -820,7 +1059,7 @@ ENTRY(coprocessor_error)
21888 pushl_cfi $do_coprocessor_error
21889 jmp error_code
21890 CFI_ENDPROC
21891 -END(coprocessor_error)
21892 +ENDPROC(coprocessor_error)
21893
21894 ENTRY(simd_coprocessor_error)
21895 RING0_INT_FRAME
21896 @@ -833,7 +1072,7 @@ ENTRY(simd_coprocessor_error)
21897 .section .altinstructions,"a"
21898 altinstruction_entry 661b, 663f, X86_FEATURE_XMM, 662b-661b, 664f-663f
21899 .previous
21900 -.section .altinstr_replacement,"ax"
21901 +.section .altinstr_replacement,"a"
21902 663: pushl $do_simd_coprocessor_error
21903 664:
21904 .previous
21905 @@ -842,7 +1081,7 @@ ENTRY(simd_coprocessor_error)
21906 #endif
21907 jmp error_code
21908 CFI_ENDPROC
21909 -END(simd_coprocessor_error)
21910 +ENDPROC(simd_coprocessor_error)
21911
21912 ENTRY(device_not_available)
21913 RING0_INT_FRAME
21914 @@ -851,18 +1090,18 @@ ENTRY(device_not_available)
21915 pushl_cfi $do_device_not_available
21916 jmp error_code
21917 CFI_ENDPROC
21918 -END(device_not_available)
21919 +ENDPROC(device_not_available)
21920
21921 #ifdef CONFIG_PARAVIRT
21922 ENTRY(native_iret)
21923 iret
21924 _ASM_EXTABLE(native_iret, iret_exc)
21925 -END(native_iret)
21926 +ENDPROC(native_iret)
21927
21928 ENTRY(native_irq_enable_sysexit)
21929 sti
21930 sysexit
21931 -END(native_irq_enable_sysexit)
21932 +ENDPROC(native_irq_enable_sysexit)
21933 #endif
21934
21935 ENTRY(overflow)
21936 @@ -872,7 +1111,7 @@ ENTRY(overflow)
21937 pushl_cfi $do_overflow
21938 jmp error_code
21939 CFI_ENDPROC
21940 -END(overflow)
21941 +ENDPROC(overflow)
21942
21943 ENTRY(bounds)
21944 RING0_INT_FRAME
21945 @@ -881,7 +1120,7 @@ ENTRY(bounds)
21946 pushl_cfi $do_bounds
21947 jmp error_code
21948 CFI_ENDPROC
21949 -END(bounds)
21950 +ENDPROC(bounds)
21951
21952 ENTRY(invalid_op)
21953 RING0_INT_FRAME
21954 @@ -890,7 +1129,7 @@ ENTRY(invalid_op)
21955 pushl_cfi $do_invalid_op
21956 jmp error_code
21957 CFI_ENDPROC
21958 -END(invalid_op)
21959 +ENDPROC(invalid_op)
21960
21961 ENTRY(coprocessor_segment_overrun)
21962 RING0_INT_FRAME
21963 @@ -899,7 +1138,7 @@ ENTRY(coprocessor_segment_overrun)
21964 pushl_cfi $do_coprocessor_segment_overrun
21965 jmp error_code
21966 CFI_ENDPROC
21967 -END(coprocessor_segment_overrun)
21968 +ENDPROC(coprocessor_segment_overrun)
21969
21970 ENTRY(invalid_TSS)
21971 RING0_EC_FRAME
21972 @@ -907,7 +1146,7 @@ ENTRY(invalid_TSS)
21973 pushl_cfi $do_invalid_TSS
21974 jmp error_code
21975 CFI_ENDPROC
21976 -END(invalid_TSS)
21977 +ENDPROC(invalid_TSS)
21978
21979 ENTRY(segment_not_present)
21980 RING0_EC_FRAME
21981 @@ -915,7 +1154,7 @@ ENTRY(segment_not_present)
21982 pushl_cfi $do_segment_not_present
21983 jmp error_code
21984 CFI_ENDPROC
21985 -END(segment_not_present)
21986 +ENDPROC(segment_not_present)
21987
21988 ENTRY(stack_segment)
21989 RING0_EC_FRAME
21990 @@ -923,7 +1162,7 @@ ENTRY(stack_segment)
21991 pushl_cfi $do_stack_segment
21992 jmp error_code
21993 CFI_ENDPROC
21994 -END(stack_segment)
21995 +ENDPROC(stack_segment)
21996
21997 ENTRY(alignment_check)
21998 RING0_EC_FRAME
21999 @@ -931,7 +1170,7 @@ ENTRY(alignment_check)
22000 pushl_cfi $do_alignment_check
22001 jmp error_code
22002 CFI_ENDPROC
22003 -END(alignment_check)
22004 +ENDPROC(alignment_check)
22005
22006 ENTRY(divide_error)
22007 RING0_INT_FRAME
22008 @@ -940,7 +1179,7 @@ ENTRY(divide_error)
22009 pushl_cfi $do_divide_error
22010 jmp error_code
22011 CFI_ENDPROC
22012 -END(divide_error)
22013 +ENDPROC(divide_error)
22014
22015 #ifdef CONFIG_X86_MCE
22016 ENTRY(machine_check)
22017 @@ -950,7 +1189,7 @@ ENTRY(machine_check)
22018 pushl_cfi machine_check_vector
22019 jmp error_code
22020 CFI_ENDPROC
22021 -END(machine_check)
22022 +ENDPROC(machine_check)
22023 #endif
22024
22025 ENTRY(spurious_interrupt_bug)
22026 @@ -960,7 +1199,7 @@ ENTRY(spurious_interrupt_bug)
22027 pushl_cfi $do_spurious_interrupt_bug
22028 jmp error_code
22029 CFI_ENDPROC
22030 -END(spurious_interrupt_bug)
22031 +ENDPROC(spurious_interrupt_bug)
22032 /*
22033 * End of kprobes section
22034 */
22035 @@ -1070,7 +1309,7 @@ BUILD_INTERRUPT3(hyperv_callback_vector, HYPERVISOR_CALLBACK_VECTOR,
22036
22037 ENTRY(mcount)
22038 ret
22039 -END(mcount)
22040 +ENDPROC(mcount)
22041
22042 ENTRY(ftrace_caller)
22043 cmpl $0, function_trace_stop
22044 @@ -1103,7 +1342,7 @@ ftrace_graph_call:
22045 .globl ftrace_stub
22046 ftrace_stub:
22047 ret
22048 -END(ftrace_caller)
22049 +ENDPROC(ftrace_caller)
22050
22051 ENTRY(ftrace_regs_caller)
22052 pushf /* push flags before compare (in cs location) */
22053 @@ -1207,7 +1446,7 @@ trace:
22054 popl %ecx
22055 popl %eax
22056 jmp ftrace_stub
22057 -END(mcount)
22058 +ENDPROC(mcount)
22059 #endif /* CONFIG_DYNAMIC_FTRACE */
22060 #endif /* CONFIG_FUNCTION_TRACER */
22061
22062 @@ -1225,7 +1464,7 @@ ENTRY(ftrace_graph_caller)
22063 popl %ecx
22064 popl %eax
22065 ret
22066 -END(ftrace_graph_caller)
22067 +ENDPROC(ftrace_graph_caller)
22068
22069 .globl return_to_handler
22070 return_to_handler:
22071 @@ -1291,15 +1530,18 @@ error_code:
22072 movl $-1, PT_ORIG_EAX(%esp) # no syscall to restart
22073 REG_TO_PTGS %ecx
22074 SET_KERNEL_GS %ecx
22075 - movl $(__USER_DS), %ecx
22076 + movl $(__KERNEL_DS), %ecx
22077 movl %ecx, %ds
22078 movl %ecx, %es
22079 +
22080 + pax_enter_kernel
22081 +
22082 TRACE_IRQS_OFF
22083 movl %esp,%eax # pt_regs pointer
22084 call *%edi
22085 jmp ret_from_exception
22086 CFI_ENDPROC
22087 -END(page_fault)
22088 +ENDPROC(page_fault)
22089
22090 /*
22091 * Debug traps and NMI can happen at the one SYSENTER instruction
22092 @@ -1342,7 +1584,7 @@ debug_stack_correct:
22093 call do_debug
22094 jmp ret_from_exception
22095 CFI_ENDPROC
22096 -END(debug)
22097 +ENDPROC(debug)
22098
22099 /*
22100 * NMI is doubly nasty. It can happen _while_ we're handling
22101 @@ -1380,6 +1622,9 @@ nmi_stack_correct:
22102 xorl %edx,%edx # zero error code
22103 movl %esp,%eax # pt_regs pointer
22104 call do_nmi
22105 +
22106 + pax_exit_kernel
22107 +
22108 jmp restore_all_notrace
22109 CFI_ENDPROC
22110
22111 @@ -1416,12 +1661,15 @@ nmi_espfix_stack:
22112 FIXUP_ESPFIX_STACK # %eax == %esp
22113 xorl %edx,%edx # zero error code
22114 call do_nmi
22115 +
22116 + pax_exit_kernel
22117 +
22118 RESTORE_REGS
22119 lss 12+4(%esp), %esp # back to espfix stack
22120 CFI_ADJUST_CFA_OFFSET -24
22121 jmp irq_return
22122 CFI_ENDPROC
22123 -END(nmi)
22124 +ENDPROC(nmi)
22125
22126 ENTRY(int3)
22127 RING0_INT_FRAME
22128 @@ -1434,14 +1682,14 @@ ENTRY(int3)
22129 call do_int3
22130 jmp ret_from_exception
22131 CFI_ENDPROC
22132 -END(int3)
22133 +ENDPROC(int3)
22134
22135 ENTRY(general_protection)
22136 RING0_EC_FRAME
22137 pushl_cfi $do_general_protection
22138 jmp error_code
22139 CFI_ENDPROC
22140 -END(general_protection)
22141 +ENDPROC(general_protection)
22142
22143 #ifdef CONFIG_KVM_GUEST
22144 ENTRY(async_page_fault)
22145 @@ -1450,7 +1698,7 @@ ENTRY(async_page_fault)
22146 pushl_cfi $do_async_page_fault
22147 jmp error_code
22148 CFI_ENDPROC
22149 -END(async_page_fault)
22150 +ENDPROC(async_page_fault)
22151 #endif
22152
22153 /*
22154 diff --git a/arch/x86/kernel/entry_64.S b/arch/x86/kernel/entry_64.S
22155 index 1e96c36..3ff710a 100644
22156 --- a/arch/x86/kernel/entry_64.S
22157 +++ b/arch/x86/kernel/entry_64.S
22158 @@ -59,6 +59,8 @@
22159 #include <asm/context_tracking.h>
22160 #include <asm/smap.h>
22161 #include <linux/err.h>
22162 +#include <asm/pgtable.h>
22163 +#include <asm/alternative-asm.h>
22164
22165 /* Avoid __ASSEMBLER__'ifying <linux/audit.h> just for this. */
22166 #include <linux/elf-em.h>
22167 @@ -80,8 +82,9 @@
22168 #ifdef CONFIG_DYNAMIC_FTRACE
22169
22170 ENTRY(function_hook)
22171 + pax_force_retaddr
22172 retq
22173 -END(function_hook)
22174 +ENDPROC(function_hook)
22175
22176 /* skip is set if stack has been adjusted */
22177 .macro ftrace_caller_setup skip=0
22178 @@ -122,8 +125,9 @@ GLOBAL(ftrace_graph_call)
22179 #endif
22180
22181 GLOBAL(ftrace_stub)
22182 + pax_force_retaddr
22183 retq
22184 -END(ftrace_caller)
22185 +ENDPROC(ftrace_caller)
22186
22187 ENTRY(ftrace_regs_caller)
22188 /* Save the current flags before compare (in SS location)*/
22189 @@ -191,7 +195,7 @@ ftrace_restore_flags:
22190 popfq
22191 jmp ftrace_stub
22192
22193 -END(ftrace_regs_caller)
22194 +ENDPROC(ftrace_regs_caller)
22195
22196
22197 #else /* ! CONFIG_DYNAMIC_FTRACE */
22198 @@ -212,6 +216,7 @@ ENTRY(function_hook)
22199 #endif
22200
22201 GLOBAL(ftrace_stub)
22202 + pax_force_retaddr
22203 retq
22204
22205 trace:
22206 @@ -225,12 +230,13 @@ trace:
22207 #endif
22208 subq $MCOUNT_INSN_SIZE, %rdi
22209
22210 + pax_force_fptr ftrace_trace_function
22211 call *ftrace_trace_function
22212
22213 MCOUNT_RESTORE_FRAME
22214
22215 jmp ftrace_stub
22216 -END(function_hook)
22217 +ENDPROC(function_hook)
22218 #endif /* CONFIG_DYNAMIC_FTRACE */
22219 #endif /* CONFIG_FUNCTION_TRACER */
22220
22221 @@ -252,8 +258,9 @@ ENTRY(ftrace_graph_caller)
22222
22223 MCOUNT_RESTORE_FRAME
22224
22225 + pax_force_retaddr
22226 retq
22227 -END(ftrace_graph_caller)
22228 +ENDPROC(ftrace_graph_caller)
22229
22230 GLOBAL(return_to_handler)
22231 subq $24, %rsp
22232 @@ -269,7 +276,9 @@ GLOBAL(return_to_handler)
22233 movq 8(%rsp), %rdx
22234 movq (%rsp), %rax
22235 addq $24, %rsp
22236 + pax_force_fptr %rdi
22237 jmp *%rdi
22238 +ENDPROC(return_to_handler)
22239 #endif
22240
22241
22242 @@ -284,6 +293,430 @@ ENTRY(native_usergs_sysret64)
22243 ENDPROC(native_usergs_sysret64)
22244 #endif /* CONFIG_PARAVIRT */
22245
22246 + .macro ljmpq sel, off
22247 +#if defined(CONFIG_MPSC) || defined(CONFIG_MCORE2) || defined (CONFIG_MATOM)
22248 + .byte 0x48; ljmp *1234f(%rip)
22249 + .pushsection .rodata
22250 + .align 16
22251 + 1234: .quad \off; .word \sel
22252 + .popsection
22253 +#else
22254 + pushq $\sel
22255 + pushq $\off
22256 + lretq
22257 +#endif
22258 + .endm
22259 +
22260 + .macro pax_enter_kernel
22261 + pax_set_fptr_mask
22262 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22263 + call pax_enter_kernel
22264 +#endif
22265 + .endm
22266 +
22267 + .macro pax_exit_kernel
22268 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22269 + call pax_exit_kernel
22270 +#endif
22271 +
22272 + .endm
22273 +
22274 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
22275 +ENTRY(pax_enter_kernel)
22276 + pushq %rdi
22277 +
22278 +#ifdef CONFIG_PARAVIRT
22279 + PV_SAVE_REGS(CLBR_RDI)
22280 +#endif
22281 +
22282 +#ifdef CONFIG_PAX_KERNEXEC
22283 + GET_CR0_INTO_RDI
22284 + bts $16,%rdi
22285 + jnc 3f
22286 + mov %cs,%edi
22287 + cmp $__KERNEL_CS,%edi
22288 + jnz 2f
22289 +1:
22290 +#endif
22291 +
22292 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22293 + 661: jmp 111f
22294 + .pushsection .altinstr_replacement, "a"
22295 + 662: ASM_NOP2
22296 + .popsection
22297 + .pushsection .altinstructions, "a"
22298 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22299 + .popsection
22300 + GET_CR3_INTO_RDI
22301 + cmp $0,%dil
22302 + jnz 112f
22303 + mov $__KERNEL_DS,%edi
22304 + mov %edi,%ss
22305 + jmp 111f
22306 +112: cmp $1,%dil
22307 + jz 113f
22308 + ud2
22309 +113: sub $4097,%rdi
22310 + bts $63,%rdi
22311 + SET_RDI_INTO_CR3
22312 + mov $__UDEREF_KERNEL_DS,%edi
22313 + mov %edi,%ss
22314 +111:
22315 +#endif
22316 +
22317 +#ifdef CONFIG_PARAVIRT
22318 + PV_RESTORE_REGS(CLBR_RDI)
22319 +#endif
22320 +
22321 + popq %rdi
22322 + pax_force_retaddr
22323 + retq
22324 +
22325 +#ifdef CONFIG_PAX_KERNEXEC
22326 +2: ljmpq __KERNEL_CS,1b
22327 +3: ljmpq __KERNEXEC_KERNEL_CS,4f
22328 +4: SET_RDI_INTO_CR0
22329 + jmp 1b
22330 +#endif
22331 +ENDPROC(pax_enter_kernel)
22332 +
22333 +ENTRY(pax_exit_kernel)
22334 + pushq %rdi
22335 +
22336 +#ifdef CONFIG_PARAVIRT
22337 + PV_SAVE_REGS(CLBR_RDI)
22338 +#endif
22339 +
22340 +#ifdef CONFIG_PAX_KERNEXEC
22341 + mov %cs,%rdi
22342 + cmp $__KERNEXEC_KERNEL_CS,%edi
22343 + jz 2f
22344 + GET_CR0_INTO_RDI
22345 + bts $16,%rdi
22346 + jnc 4f
22347 +1:
22348 +#endif
22349 +
22350 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22351 + 661: jmp 111f
22352 + .pushsection .altinstr_replacement, "a"
22353 + 662: ASM_NOP2
22354 + .popsection
22355 + .pushsection .altinstructions, "a"
22356 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22357 + .popsection
22358 + mov %ss,%edi
22359 + cmp $__UDEREF_KERNEL_DS,%edi
22360 + jnz 111f
22361 + GET_CR3_INTO_RDI
22362 + cmp $0,%dil
22363 + jz 112f
22364 + ud2
22365 +112: add $4097,%rdi
22366 + bts $63,%rdi
22367 + SET_RDI_INTO_CR3
22368 + mov $__KERNEL_DS,%edi
22369 + mov %edi,%ss
22370 +111:
22371 +#endif
22372 +
22373 +#ifdef CONFIG_PARAVIRT
22374 + PV_RESTORE_REGS(CLBR_RDI);
22375 +#endif
22376 +
22377 + popq %rdi
22378 + pax_force_retaddr
22379 + retq
22380 +
22381 +#ifdef CONFIG_PAX_KERNEXEC
22382 +2: GET_CR0_INTO_RDI
22383 + btr $16,%rdi
22384 + jnc 4f
22385 + ljmpq __KERNEL_CS,3f
22386 +3: SET_RDI_INTO_CR0
22387 + jmp 1b
22388 +4: ud2
22389 + jmp 4b
22390 +#endif
22391 +ENDPROC(pax_exit_kernel)
22392 +#endif
22393 +
22394 + .macro pax_enter_kernel_user
22395 + pax_set_fptr_mask
22396 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22397 + call pax_enter_kernel_user
22398 +#endif
22399 + .endm
22400 +
22401 + .macro pax_exit_kernel_user
22402 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22403 + call pax_exit_kernel_user
22404 +#endif
22405 +#ifdef CONFIG_PAX_RANDKSTACK
22406 + pushq %rax
22407 + pushq %r11
22408 + call pax_randomize_kstack
22409 + popq %r11
22410 + popq %rax
22411 +#endif
22412 + .endm
22413 +
22414 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22415 +ENTRY(pax_enter_kernel_user)
22416 + pushq %rdi
22417 + pushq %rbx
22418 +
22419 +#ifdef CONFIG_PARAVIRT
22420 + PV_SAVE_REGS(CLBR_RDI)
22421 +#endif
22422 +
22423 + 661: jmp 111f
22424 + .pushsection .altinstr_replacement, "a"
22425 + 662: ASM_NOP2
22426 + .popsection
22427 + .pushsection .altinstructions, "a"
22428 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22429 + .popsection
22430 + GET_CR3_INTO_RDI
22431 + cmp $1,%dil
22432 + jnz 4f
22433 + sub $4097,%rdi
22434 + bts $63,%rdi
22435 + SET_RDI_INTO_CR3
22436 + jmp 3f
22437 +111:
22438 +
22439 + GET_CR3_INTO_RDI
22440 + mov %rdi,%rbx
22441 + add $__START_KERNEL_map,%rbx
22442 + sub phys_base(%rip),%rbx
22443 +
22444 +#ifdef CONFIG_PARAVIRT
22445 + cmpl $0, pv_info+PARAVIRT_enabled
22446 + jz 1f
22447 + pushq %rdi
22448 + i = 0
22449 + .rept USER_PGD_PTRS
22450 + mov i*8(%rbx),%rsi
22451 + mov $0,%sil
22452 + lea i*8(%rbx),%rdi
22453 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22454 + i = i + 1
22455 + .endr
22456 + popq %rdi
22457 + jmp 2f
22458 +1:
22459 +#endif
22460 +
22461 + i = 0
22462 + .rept USER_PGD_PTRS
22463 + movb $0,i*8(%rbx)
22464 + i = i + 1
22465 + .endr
22466 +
22467 +2: SET_RDI_INTO_CR3
22468 +
22469 +#ifdef CONFIG_PAX_KERNEXEC
22470 + GET_CR0_INTO_RDI
22471 + bts $16,%rdi
22472 + SET_RDI_INTO_CR0
22473 +#endif
22474 +
22475 +3:
22476 +
22477 +#ifdef CONFIG_PARAVIRT
22478 + PV_RESTORE_REGS(CLBR_RDI)
22479 +#endif
22480 +
22481 + popq %rbx
22482 + popq %rdi
22483 + pax_force_retaddr
22484 + retq
22485 +4: ud2
22486 +ENDPROC(pax_enter_kernel_user)
22487 +
22488 +ENTRY(pax_exit_kernel_user)
22489 + pushq %rdi
22490 + pushq %rbx
22491 +
22492 +#ifdef CONFIG_PARAVIRT
22493 + PV_SAVE_REGS(CLBR_RDI)
22494 +#endif
22495 +
22496 + GET_CR3_INTO_RDI
22497 + 661: jmp 1f
22498 + .pushsection .altinstr_replacement, "a"
22499 + 662: ASM_NOP2
22500 + .popsection
22501 + .pushsection .altinstructions, "a"
22502 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22503 + .popsection
22504 + cmp $0,%dil
22505 + jnz 3f
22506 + add $4097,%rdi
22507 + bts $63,%rdi
22508 + SET_RDI_INTO_CR3
22509 + jmp 2f
22510 +1:
22511 +
22512 + mov %rdi,%rbx
22513 +
22514 +#ifdef CONFIG_PAX_KERNEXEC
22515 + GET_CR0_INTO_RDI
22516 + btr $16,%rdi
22517 + jnc 3f
22518 + SET_RDI_INTO_CR0
22519 +#endif
22520 +
22521 + add $__START_KERNEL_map,%rbx
22522 + sub phys_base(%rip),%rbx
22523 +
22524 +#ifdef CONFIG_PARAVIRT
22525 + cmpl $0, pv_info+PARAVIRT_enabled
22526 + jz 1f
22527 + i = 0
22528 + .rept USER_PGD_PTRS
22529 + mov i*8(%rbx),%rsi
22530 + mov $0x67,%sil
22531 + lea i*8(%rbx),%rdi
22532 + call PARA_INDIRECT(pv_mmu_ops+PV_MMU_set_pgd_batched)
22533 + i = i + 1
22534 + .endr
22535 + jmp 2f
22536 +1:
22537 +#endif
22538 +
22539 + i = 0
22540 + .rept USER_PGD_PTRS
22541 + movb $0x67,i*8(%rbx)
22542 + i = i + 1
22543 + .endr
22544 +2:
22545 +
22546 +#ifdef CONFIG_PARAVIRT
22547 + PV_RESTORE_REGS(CLBR_RDI)
22548 +#endif
22549 +
22550 + popq %rbx
22551 + popq %rdi
22552 + pax_force_retaddr
22553 + retq
22554 +3: ud2
22555 +ENDPROC(pax_exit_kernel_user)
22556 +#endif
22557 +
22558 + .macro pax_enter_kernel_nmi
22559 + pax_set_fptr_mask
22560 +
22561 +#ifdef CONFIG_PAX_KERNEXEC
22562 + GET_CR0_INTO_RDI
22563 + bts $16,%rdi
22564 + jc 110f
22565 + SET_RDI_INTO_CR0
22566 + or $2,%ebx
22567 +110:
22568 +#endif
22569 +
22570 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22571 + 661: jmp 111f
22572 + .pushsection .altinstr_replacement, "a"
22573 + 662: ASM_NOP2
22574 + .popsection
22575 + .pushsection .altinstructions, "a"
22576 + altinstruction_entry 661b, 662b, X86_FEATURE_PCID, 2, 2
22577 + .popsection
22578 + GET_CR3_INTO_RDI
22579 + cmp $0,%dil
22580 + jz 111f
22581 + sub $4097,%rdi
22582 + or $4,%ebx
22583 + bts $63,%rdi
22584 + SET_RDI_INTO_CR3
22585 + mov $__UDEREF_KERNEL_DS,%edi
22586 + mov %edi,%ss
22587 +111:
22588 +#endif
22589 + .endm
22590 +
22591 + .macro pax_exit_kernel_nmi
22592 +#ifdef CONFIG_PAX_KERNEXEC
22593 + btr $1,%ebx
22594 + jnc 110f
22595 + GET_CR0_INTO_RDI
22596 + btr $16,%rdi
22597 + SET_RDI_INTO_CR0
22598 +110:
22599 +#endif
22600 +
22601 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22602 + btr $2,%ebx
22603 + jnc 111f
22604 + GET_CR3_INTO_RDI
22605 + add $4097,%rdi
22606 + bts $63,%rdi
22607 + SET_RDI_INTO_CR3
22608 + mov $__KERNEL_DS,%edi
22609 + mov %edi,%ss
22610 +111:
22611 +#endif
22612 + .endm
22613 +
22614 + .macro pax_erase_kstack
22615 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22616 + call pax_erase_kstack
22617 +#endif
22618 + .endm
22619 +
22620 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
22621 +ENTRY(pax_erase_kstack)
22622 + pushq %rdi
22623 + pushq %rcx
22624 + pushq %rax
22625 + pushq %r11
22626 +
22627 + GET_THREAD_INFO(%r11)
22628 + mov TI_lowest_stack(%r11), %rdi
22629 + mov $-0xBEEF, %rax
22630 + std
22631 +
22632 +1: mov %edi, %ecx
22633 + and $THREAD_SIZE_asm - 1, %ecx
22634 + shr $3, %ecx
22635 + repne scasq
22636 + jecxz 2f
22637 +
22638 + cmp $2*8, %ecx
22639 + jc 2f
22640 +
22641 + mov $2*8, %ecx
22642 + repe scasq
22643 + jecxz 2f
22644 + jne 1b
22645 +
22646 +2: cld
22647 + mov %esp, %ecx
22648 + sub %edi, %ecx
22649 +
22650 + cmp $THREAD_SIZE_asm, %rcx
22651 + jb 3f
22652 + ud2
22653 +3:
22654 +
22655 + shr $3, %ecx
22656 + rep stosq
22657 +
22658 + mov TI_task_thread_sp0(%r11), %rdi
22659 + sub $256, %rdi
22660 + mov %rdi, TI_lowest_stack(%r11)
22661 +
22662 + popq %r11
22663 + popq %rax
22664 + popq %rcx
22665 + popq %rdi
22666 + pax_force_retaddr
22667 + ret
22668 +ENDPROC(pax_erase_kstack)
22669 +#endif
22670
22671 .macro TRACE_IRQS_IRETQ offset=ARGOFFSET
22672 #ifdef CONFIG_TRACE_IRQFLAGS
22673 @@ -320,7 +753,7 @@ ENDPROC(native_usergs_sysret64)
22674 .endm
22675
22676 .macro TRACE_IRQS_IRETQ_DEBUG offset=ARGOFFSET
22677 - bt $9,EFLAGS-\offset(%rsp) /* interrupts off? */
22678 + bt $X86_EFLAGS_IF_BIT,EFLAGS-\offset(%rsp) /* interrupts off? */
22679 jnc 1f
22680 TRACE_IRQS_ON_DEBUG
22681 1:
22682 @@ -358,27 +791,6 @@ ENDPROC(native_usergs_sysret64)
22683 movq \tmp,R11+\offset(%rsp)
22684 .endm
22685
22686 - .macro FAKE_STACK_FRAME child_rip
22687 - /* push in order ss, rsp, eflags, cs, rip */
22688 - xorl %eax, %eax
22689 - pushq_cfi $__KERNEL_DS /* ss */
22690 - /*CFI_REL_OFFSET ss,0*/
22691 - pushq_cfi %rax /* rsp */
22692 - CFI_REL_OFFSET rsp,0
22693 - pushq_cfi $(X86_EFLAGS_IF|X86_EFLAGS_FIXED) /* eflags - interrupts on */
22694 - /*CFI_REL_OFFSET rflags,0*/
22695 - pushq_cfi $__KERNEL_CS /* cs */
22696 - /*CFI_REL_OFFSET cs,0*/
22697 - pushq_cfi \child_rip /* rip */
22698 - CFI_REL_OFFSET rip,0
22699 - pushq_cfi %rax /* orig rax */
22700 - .endm
22701 -
22702 - .macro UNFAKE_STACK_FRAME
22703 - addq $8*6, %rsp
22704 - CFI_ADJUST_CFA_OFFSET -(6*8)
22705 - .endm
22706 -
22707 /*
22708 * initial frame state for interrupts (and exceptions without error code)
22709 */
22710 @@ -445,25 +857,26 @@ ENDPROC(native_usergs_sysret64)
22711 /* save partial stack frame */
22712 .macro SAVE_ARGS_IRQ
22713 cld
22714 - /* start from rbp in pt_regs and jump over */
22715 - movq_cfi rdi, (RDI-RBP)
22716 - movq_cfi rsi, (RSI-RBP)
22717 - movq_cfi rdx, (RDX-RBP)
22718 - movq_cfi rcx, (RCX-RBP)
22719 - movq_cfi rax, (RAX-RBP)
22720 - movq_cfi r8, (R8-RBP)
22721 - movq_cfi r9, (R9-RBP)
22722 - movq_cfi r10, (R10-RBP)
22723 - movq_cfi r11, (R11-RBP)
22724 + /* start from r15 in pt_regs and jump over */
22725 + movq_cfi rdi, RDI
22726 + movq_cfi rsi, RSI
22727 + movq_cfi rdx, RDX
22728 + movq_cfi rcx, RCX
22729 + movq_cfi rax, RAX
22730 + movq_cfi r8, R8
22731 + movq_cfi r9, R9
22732 + movq_cfi r10, R10
22733 + movq_cfi r11, R11
22734 + movq_cfi r12, R12
22735
22736 /* Save rbp so that we can unwind from get_irq_regs() */
22737 - movq_cfi rbp, 0
22738 + movq_cfi rbp, RBP
22739
22740 /* Save previous stack value */
22741 movq %rsp, %rsi
22742
22743 - leaq -RBP(%rsp),%rdi /* arg1 for handler */
22744 - testl $3, CS-RBP(%rsi)
22745 + movq %rsp,%rdi /* arg1 for handler */
22746 + testb $3, CS(%rsi)
22747 je 1f
22748 SWAPGS
22749 /*
22750 @@ -483,6 +896,18 @@ ENDPROC(native_usergs_sysret64)
22751 0x06 /* DW_OP_deref */, \
22752 0x08 /* DW_OP_const1u */, SS+8-RBP, \
22753 0x22 /* DW_OP_plus */
22754 +
22755 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22756 + testb $3, CS(%rdi)
22757 + jnz 1f
22758 + pax_enter_kernel
22759 + jmp 2f
22760 +1: pax_enter_kernel_user
22761 +2:
22762 +#else
22763 + pax_enter_kernel
22764 +#endif
22765 +
22766 /* We entered an interrupt context - irqs are off: */
22767 TRACE_IRQS_OFF
22768 .endm
22769 @@ -514,9 +939,52 @@ ENTRY(save_paranoid)
22770 js 1f /* negative -> in kernel */
22771 SWAPGS
22772 xorl %ebx,%ebx
22773 -1: ret
22774 +1:
22775 +#ifdef CONFIG_PAX_MEMORY_UDEREF
22776 + testb $3, CS+8(%rsp)
22777 + jnz 1f
22778 + pax_enter_kernel
22779 + jmp 2f
22780 +1: pax_enter_kernel_user
22781 +2:
22782 +#else
22783 + pax_enter_kernel
22784 +#endif
22785 + pax_force_retaddr
22786 + ret
22787 CFI_ENDPROC
22788 -END(save_paranoid)
22789 +ENDPROC(save_paranoid)
22790 +
22791 +ENTRY(save_paranoid_nmi)
22792 + XCPT_FRAME 1 RDI+8
22793 + cld
22794 + movq_cfi rdi, RDI+8
22795 + movq_cfi rsi, RSI+8
22796 + movq_cfi rdx, RDX+8
22797 + movq_cfi rcx, RCX+8
22798 + movq_cfi rax, RAX+8
22799 + movq_cfi r8, R8+8
22800 + movq_cfi r9, R9+8
22801 + movq_cfi r10, R10+8
22802 + movq_cfi r11, R11+8
22803 + movq_cfi rbx, RBX+8
22804 + movq_cfi rbp, RBP+8
22805 + movq_cfi r12, R12+8
22806 + movq_cfi r13, R13+8
22807 + movq_cfi r14, R14+8
22808 + movq_cfi r15, R15+8
22809 + movl $1,%ebx
22810 + movl $MSR_GS_BASE,%ecx
22811 + rdmsr
22812 + testl %edx,%edx
22813 + js 1f /* negative -> in kernel */
22814 + SWAPGS
22815 + xorl %ebx,%ebx
22816 +1: pax_enter_kernel_nmi
22817 + pax_force_retaddr
22818 + ret
22819 + CFI_ENDPROC
22820 +ENDPROC(save_paranoid_nmi)
22821 .popsection
22822
22823 /*
22824 @@ -538,7 +1006,7 @@ ENTRY(ret_from_fork)
22825
22826 RESTORE_REST
22827
22828 - testl $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
22829 + testb $3, CS-ARGOFFSET(%rsp) # from kernel_thread?
22830 jz 1f
22831
22832 testl $_TIF_IA32, TI_flags(%rcx) # 32-bit compat task needs IRET
22833 @@ -548,15 +1016,13 @@ ENTRY(ret_from_fork)
22834 jmp ret_from_sys_call # go to the SYSRET fastpath
22835
22836 1:
22837 - subq $REST_SKIP, %rsp # leave space for volatiles
22838 - CFI_ADJUST_CFA_OFFSET REST_SKIP
22839 movq %rbp, %rdi
22840 call *%rbx
22841 movl $0, RAX(%rsp)
22842 RESTORE_REST
22843 jmp int_ret_from_sys_call
22844 CFI_ENDPROC
22845 -END(ret_from_fork)
22846 +ENDPROC(ret_from_fork)
22847
22848 /*
22849 * System call entry. Up to 6 arguments in registers are supported.
22850 @@ -593,7 +1059,7 @@ END(ret_from_fork)
22851 ENTRY(system_call)
22852 CFI_STARTPROC simple
22853 CFI_SIGNAL_FRAME
22854 - CFI_DEF_CFA rsp,KERNEL_STACK_OFFSET
22855 + CFI_DEF_CFA rsp,0
22856 CFI_REGISTER rip,rcx
22857 /*CFI_REGISTER rflags,r11*/
22858 SWAPGS_UNSAFE_STACK
22859 @@ -606,16 +1072,23 @@ GLOBAL(system_call_after_swapgs)
22860
22861 movq %rsp,PER_CPU_VAR(old_rsp)
22862 movq PER_CPU_VAR(kernel_stack),%rsp
22863 + SAVE_ARGS 8*6,0
22864 + pax_enter_kernel_user
22865 +
22866 +#ifdef CONFIG_PAX_RANDKSTACK
22867 + pax_erase_kstack
22868 +#endif
22869 +
22870 /*
22871 * No need to follow this irqs off/on section - it's straight
22872 * and short:
22873 */
22874 ENABLE_INTERRUPTS(CLBR_NONE)
22875 - SAVE_ARGS 8,0
22876 movq %rax,ORIG_RAX-ARGOFFSET(%rsp)
22877 movq %rcx,RIP-ARGOFFSET(%rsp)
22878 CFI_REL_OFFSET rip,RIP-ARGOFFSET
22879 - testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
22880 + GET_THREAD_INFO(%rcx)
22881 + testl $_TIF_WORK_SYSCALL_ENTRY,TI_flags(%rcx)
22882 jnz tracesys
22883 system_call_fastpath:
22884 #if __SYSCALL_MASK == ~0
22885 @@ -639,10 +1112,13 @@ sysret_check:
22886 LOCKDEP_SYS_EXIT
22887 DISABLE_INTERRUPTS(CLBR_NONE)
22888 TRACE_IRQS_OFF
22889 - movl TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET),%edx
22890 + GET_THREAD_INFO(%rcx)
22891 + movl TI_flags(%rcx),%edx
22892 andl %edi,%edx
22893 jnz sysret_careful
22894 CFI_REMEMBER_STATE
22895 + pax_exit_kernel_user
22896 + pax_erase_kstack
22897 /*
22898 * sysretq will re-enable interrupts:
22899 */
22900 @@ -701,6 +1177,9 @@ auditsys:
22901 movq %rax,%rsi /* 2nd arg: syscall number */
22902 movl $AUDIT_ARCH_X86_64,%edi /* 1st arg: audit arch */
22903 call __audit_syscall_entry
22904 +
22905 + pax_erase_kstack
22906 +
22907 LOAD_ARGS 0 /* reload call-clobbered registers */
22908 jmp system_call_fastpath
22909
22910 @@ -722,7 +1201,7 @@ sysret_audit:
22911 /* Do syscall tracing */
22912 tracesys:
22913 #ifdef CONFIG_AUDITSYSCALL
22914 - testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags+THREAD_INFO(%rsp,RIP-ARGOFFSET)
22915 + testl $(_TIF_WORK_SYSCALL_ENTRY & ~_TIF_SYSCALL_AUDIT),TI_flags(%rcx)
22916 jz auditsys
22917 #endif
22918 SAVE_REST
22919 @@ -730,12 +1209,15 @@ tracesys:
22920 FIXUP_TOP_OF_STACK %rdi
22921 movq %rsp,%rdi
22922 call syscall_trace_enter
22923 +
22924 + pax_erase_kstack
22925 +
22926 /*
22927 * Reload arg registers from stack in case ptrace changed them.
22928 * We don't reload %rax because syscall_trace_enter() returned
22929 * the value it wants us to use in the table lookup.
22930 */
22931 - LOAD_ARGS ARGOFFSET, 1
22932 + LOAD_ARGS 1
22933 RESTORE_REST
22934 #if __SYSCALL_MASK == ~0
22935 cmpq $__NR_syscall_max,%rax
22936 @@ -765,7 +1247,9 @@ GLOBAL(int_with_check)
22937 andl %edi,%edx
22938 jnz int_careful
22939 andl $~TS_COMPAT,TI_status(%rcx)
22940 - jmp retint_swapgs
22941 + pax_exit_kernel_user
22942 + pax_erase_kstack
22943 + jmp retint_swapgs_pax
22944
22945 /* Either reschedule or signal or syscall exit tracking needed. */
22946 /* First do a reschedule test. */
22947 @@ -811,7 +1295,7 @@ int_restore_rest:
22948 TRACE_IRQS_OFF
22949 jmp int_with_check
22950 CFI_ENDPROC
22951 -END(system_call)
22952 +ENDPROC(system_call)
22953
22954 .macro FORK_LIKE func
22955 ENTRY(stub_\func)
22956 @@ -824,9 +1308,10 @@ ENTRY(stub_\func)
22957 DEFAULT_FRAME 0 8 /* offset 8: return address */
22958 call sys_\func
22959 RESTORE_TOP_OF_STACK %r11, 8
22960 - ret $REST_SKIP /* pop extended registers */
22961 + pax_force_retaddr
22962 + ret
22963 CFI_ENDPROC
22964 -END(stub_\func)
22965 +ENDPROC(stub_\func)
22966 .endm
22967
22968 .macro FIXED_FRAME label,func
22969 @@ -836,9 +1321,10 @@ ENTRY(\label)
22970 FIXUP_TOP_OF_STACK %r11, 8-ARGOFFSET
22971 call \func
22972 RESTORE_TOP_OF_STACK %r11, 8-ARGOFFSET
22973 + pax_force_retaddr
22974 ret
22975 CFI_ENDPROC
22976 -END(\label)
22977 +ENDPROC(\label)
22978 .endm
22979
22980 FORK_LIKE clone
22981 @@ -846,19 +1332,6 @@ END(\label)
22982 FORK_LIKE vfork
22983 FIXED_FRAME stub_iopl, sys_iopl
22984
22985 -ENTRY(ptregscall_common)
22986 - DEFAULT_FRAME 1 8 /* offset 8: return address */
22987 - RESTORE_TOP_OF_STACK %r11, 8
22988 - movq_cfi_restore R15+8, r15
22989 - movq_cfi_restore R14+8, r14
22990 - movq_cfi_restore R13+8, r13
22991 - movq_cfi_restore R12+8, r12
22992 - movq_cfi_restore RBP+8, rbp
22993 - movq_cfi_restore RBX+8, rbx
22994 - ret $REST_SKIP /* pop extended registers */
22995 - CFI_ENDPROC
22996 -END(ptregscall_common)
22997 -
22998 ENTRY(stub_execve)
22999 CFI_STARTPROC
23000 addq $8, %rsp
23001 @@ -870,7 +1343,7 @@ ENTRY(stub_execve)
23002 RESTORE_REST
23003 jmp int_ret_from_sys_call
23004 CFI_ENDPROC
23005 -END(stub_execve)
23006 +ENDPROC(stub_execve)
23007
23008 /*
23009 * sigreturn is special because it needs to restore all registers on return.
23010 @@ -887,7 +1360,7 @@ ENTRY(stub_rt_sigreturn)
23011 RESTORE_REST
23012 jmp int_ret_from_sys_call
23013 CFI_ENDPROC
23014 -END(stub_rt_sigreturn)
23015 +ENDPROC(stub_rt_sigreturn)
23016
23017 #ifdef CONFIG_X86_X32_ABI
23018 ENTRY(stub_x32_rt_sigreturn)
23019 @@ -901,7 +1374,7 @@ ENTRY(stub_x32_rt_sigreturn)
23020 RESTORE_REST
23021 jmp int_ret_from_sys_call
23022 CFI_ENDPROC
23023 -END(stub_x32_rt_sigreturn)
23024 +ENDPROC(stub_x32_rt_sigreturn)
23025
23026 ENTRY(stub_x32_execve)
23027 CFI_STARTPROC
23028 @@ -915,7 +1388,7 @@ ENTRY(stub_x32_execve)
23029 RESTORE_REST
23030 jmp int_ret_from_sys_call
23031 CFI_ENDPROC
23032 -END(stub_x32_execve)
23033 +ENDPROC(stub_x32_execve)
23034
23035 #endif
23036
23037 @@ -952,7 +1425,7 @@ vector=vector+1
23038 2: jmp common_interrupt
23039 .endr
23040 CFI_ENDPROC
23041 -END(irq_entries_start)
23042 +ENDPROC(irq_entries_start)
23043
23044 .previous
23045 END(interrupt)
23046 @@ -969,8 +1442,8 @@ END(interrupt)
23047 /* 0(%rsp): ~(interrupt number) */
23048 .macro interrupt func
23049 /* reserve pt_regs for scratch regs and rbp */
23050 - subq $ORIG_RAX-RBP, %rsp
23051 - CFI_ADJUST_CFA_OFFSET ORIG_RAX-RBP
23052 + subq $ORIG_RAX, %rsp
23053 + CFI_ADJUST_CFA_OFFSET ORIG_RAX
23054 SAVE_ARGS_IRQ
23055 call \func
23056 .endm
23057 @@ -997,14 +1470,14 @@ ret_from_intr:
23058
23059 /* Restore saved previous stack */
23060 popq %rsi
23061 - CFI_DEF_CFA rsi,SS+8-RBP /* reg/off reset after def_cfa_expr */
23062 - leaq ARGOFFSET-RBP(%rsi), %rsp
23063 + CFI_DEF_CFA rsi,SS+8 /* reg/off reset after def_cfa_expr */
23064 + movq %rsi, %rsp
23065 CFI_DEF_CFA_REGISTER rsp
23066 - CFI_ADJUST_CFA_OFFSET RBP-ARGOFFSET
23067 + CFI_ADJUST_CFA_OFFSET -ARGOFFSET
23068
23069 exit_intr:
23070 GET_THREAD_INFO(%rcx)
23071 - testl $3,CS-ARGOFFSET(%rsp)
23072 + testb $3,CS-ARGOFFSET(%rsp)
23073 je retint_kernel
23074
23075 /* Interrupt came from user space */
23076 @@ -1026,12 +1499,16 @@ retint_swapgs: /* return to user-space */
23077 * The iretq could re-enable interrupts:
23078 */
23079 DISABLE_INTERRUPTS(CLBR_ANY)
23080 + pax_exit_kernel_user
23081 +retint_swapgs_pax:
23082 TRACE_IRQS_IRETQ
23083 SWAPGS
23084 jmp restore_args
23085
23086 retint_restore_args: /* return to kernel space */
23087 DISABLE_INTERRUPTS(CLBR_ANY)
23088 + pax_exit_kernel
23089 + pax_force_retaddr (RIP-ARGOFFSET)
23090 /*
23091 * The iretq could re-enable interrupts:
23092 */
23093 @@ -1112,7 +1589,7 @@ ENTRY(retint_kernel)
23094 #endif
23095
23096 CFI_ENDPROC
23097 -END(common_interrupt)
23098 +ENDPROC(common_interrupt)
23099 /*
23100 * End of kprobes section
23101 */
23102 @@ -1130,7 +1607,7 @@ ENTRY(\sym)
23103 interrupt \do_sym
23104 jmp ret_from_intr
23105 CFI_ENDPROC
23106 -END(\sym)
23107 +ENDPROC(\sym)
23108 .endm
23109
23110 #ifdef CONFIG_TRACING
23111 @@ -1218,7 +1695,7 @@ ENTRY(\sym)
23112 call \do_sym
23113 jmp error_exit /* %ebx: no swapgs flag */
23114 CFI_ENDPROC
23115 -END(\sym)
23116 +ENDPROC(\sym)
23117 .endm
23118
23119 .macro paranoidzeroentry sym do_sym
23120 @@ -1236,10 +1713,10 @@ ENTRY(\sym)
23121 call \do_sym
23122 jmp paranoid_exit /* %ebx: no swapgs flag */
23123 CFI_ENDPROC
23124 -END(\sym)
23125 +ENDPROC(\sym)
23126 .endm
23127
23128 -#define INIT_TSS_IST(x) PER_CPU_VAR(init_tss) + (TSS_ist + ((x) - 1) * 8)
23129 +#define INIT_TSS_IST(x) (TSS_ist + ((x) - 1) * 8)(%r13)
23130 .macro paranoidzeroentry_ist sym do_sym ist
23131 ENTRY(\sym)
23132 INTR_FRAME
23133 @@ -1252,12 +1729,18 @@ ENTRY(\sym)
23134 TRACE_IRQS_OFF_DEBUG
23135 movq %rsp,%rdi /* pt_regs pointer */
23136 xorl %esi,%esi /* no error code */
23137 +#ifdef CONFIG_SMP
23138 + imul $TSS_size, PER_CPU_VAR(cpu_number), %r13d
23139 + lea init_tss(%r13), %r13
23140 +#else
23141 + lea init_tss(%rip), %r13
23142 +#endif
23143 subq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23144 call \do_sym
23145 addq $EXCEPTION_STKSZ, INIT_TSS_IST(\ist)
23146 jmp paranoid_exit /* %ebx: no swapgs flag */
23147 CFI_ENDPROC
23148 -END(\sym)
23149 +ENDPROC(\sym)
23150 .endm
23151
23152 .macro errorentry sym do_sym
23153 @@ -1275,7 +1758,7 @@ ENTRY(\sym)
23154 call \do_sym
23155 jmp error_exit /* %ebx: no swapgs flag */
23156 CFI_ENDPROC
23157 -END(\sym)
23158 +ENDPROC(\sym)
23159 .endm
23160
23161 #ifdef CONFIG_TRACING
23162 @@ -1306,7 +1789,7 @@ ENTRY(\sym)
23163 call \do_sym
23164 jmp paranoid_exit /* %ebx: no swapgs flag */
23165 CFI_ENDPROC
23166 -END(\sym)
23167 +ENDPROC(\sym)
23168 .endm
23169
23170 zeroentry divide_error do_divide_error
23171 @@ -1336,9 +1819,10 @@ gs_change:
23172 2: mfence /* workaround */
23173 SWAPGS
23174 popfq_cfi
23175 + pax_force_retaddr
23176 ret
23177 CFI_ENDPROC
23178 -END(native_load_gs_index)
23179 +ENDPROC(native_load_gs_index)
23180
23181 _ASM_EXTABLE(gs_change,bad_gs)
23182 .section .fixup,"ax"
23183 @@ -1366,9 +1850,10 @@ ENTRY(do_softirq_own_stack)
23184 CFI_DEF_CFA_REGISTER rsp
23185 CFI_ADJUST_CFA_OFFSET -8
23186 decl PER_CPU_VAR(irq_count)
23187 + pax_force_retaddr
23188 ret
23189 CFI_ENDPROC
23190 -END(do_softirq_own_stack)
23191 +ENDPROC(do_softirq_own_stack)
23192
23193 #ifdef CONFIG_XEN
23194 zeroentry xen_hypervisor_callback xen_do_hypervisor_callback
23195 @@ -1406,7 +1891,7 @@ ENTRY(xen_do_hypervisor_callback) # do_hypervisor_callback(struct *pt_regs)
23196 decl PER_CPU_VAR(irq_count)
23197 jmp error_exit
23198 CFI_ENDPROC
23199 -END(xen_do_hypervisor_callback)
23200 +ENDPROC(xen_do_hypervisor_callback)
23201
23202 /*
23203 * Hypervisor uses this for application faults while it executes.
23204 @@ -1465,7 +1950,7 @@ ENTRY(xen_failsafe_callback)
23205 SAVE_ALL
23206 jmp error_exit
23207 CFI_ENDPROC
23208 -END(xen_failsafe_callback)
23209 +ENDPROC(xen_failsafe_callback)
23210
23211 apicinterrupt3 HYPERVISOR_CALLBACK_VECTOR \
23212 xen_hvm_callback_vector xen_evtchn_do_upcall
23213 @@ -1517,18 +2002,33 @@ ENTRY(paranoid_exit)
23214 DEFAULT_FRAME
23215 DISABLE_INTERRUPTS(CLBR_NONE)
23216 TRACE_IRQS_OFF_DEBUG
23217 - testl %ebx,%ebx /* swapgs needed? */
23218 + testl $1,%ebx /* swapgs needed? */
23219 jnz paranoid_restore
23220 - testl $3,CS(%rsp)
23221 + testb $3,CS(%rsp)
23222 jnz paranoid_userspace
23223 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23224 + pax_exit_kernel
23225 + TRACE_IRQS_IRETQ 0
23226 + SWAPGS_UNSAFE_STACK
23227 + RESTORE_ALL 8
23228 + pax_force_retaddr_bts
23229 + jmp irq_return
23230 +#endif
23231 paranoid_swapgs:
23232 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23233 + pax_exit_kernel_user
23234 +#else
23235 + pax_exit_kernel
23236 +#endif
23237 TRACE_IRQS_IRETQ 0
23238 SWAPGS_UNSAFE_STACK
23239 RESTORE_ALL 8
23240 jmp irq_return
23241 paranoid_restore:
23242 + pax_exit_kernel
23243 TRACE_IRQS_IRETQ_DEBUG 0
23244 RESTORE_ALL 8
23245 + pax_force_retaddr_bts
23246 jmp irq_return
23247 paranoid_userspace:
23248 GET_THREAD_INFO(%rcx)
23249 @@ -1557,7 +2057,7 @@ paranoid_schedule:
23250 TRACE_IRQS_OFF
23251 jmp paranoid_userspace
23252 CFI_ENDPROC
23253 -END(paranoid_exit)
23254 +ENDPROC(paranoid_exit)
23255
23256 /*
23257 * Exception entry point. This expects an error code/orig_rax on the stack.
23258 @@ -1584,12 +2084,23 @@ ENTRY(error_entry)
23259 movq_cfi r14, R14+8
23260 movq_cfi r15, R15+8
23261 xorl %ebx,%ebx
23262 - testl $3,CS+8(%rsp)
23263 + testb $3,CS+8(%rsp)
23264 je error_kernelspace
23265 error_swapgs:
23266 SWAPGS
23267 error_sti:
23268 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23269 + testb $3, CS+8(%rsp)
23270 + jnz 1f
23271 + pax_enter_kernel
23272 + jmp 2f
23273 +1: pax_enter_kernel_user
23274 +2:
23275 +#else
23276 + pax_enter_kernel
23277 +#endif
23278 TRACE_IRQS_OFF
23279 + pax_force_retaddr
23280 ret
23281
23282 /*
23283 @@ -1616,7 +2127,7 @@ bstep_iret:
23284 movq %rcx,RIP+8(%rsp)
23285 jmp error_swapgs
23286 CFI_ENDPROC
23287 -END(error_entry)
23288 +ENDPROC(error_entry)
23289
23290
23291 /* ebx: no swapgs flag (1: don't need swapgs, 0: need it) */
23292 @@ -1627,7 +2138,7 @@ ENTRY(error_exit)
23293 DISABLE_INTERRUPTS(CLBR_NONE)
23294 TRACE_IRQS_OFF
23295 GET_THREAD_INFO(%rcx)
23296 - testl %eax,%eax
23297 + testl $1,%eax
23298 jne retint_kernel
23299 LOCKDEP_SYS_EXIT_IRQ
23300 movl TI_flags(%rcx),%edx
23301 @@ -1636,7 +2147,7 @@ ENTRY(error_exit)
23302 jnz retint_careful
23303 jmp retint_swapgs
23304 CFI_ENDPROC
23305 -END(error_exit)
23306 +ENDPROC(error_exit)
23307
23308 /*
23309 * Test if a given stack is an NMI stack or not.
23310 @@ -1694,9 +2205,11 @@ ENTRY(nmi)
23311 * If %cs was not the kernel segment, then the NMI triggered in user
23312 * space, which means it is definitely not nested.
23313 */
23314 + cmpl $__KERNEXEC_KERNEL_CS, 16(%rsp)
23315 + je 1f
23316 cmpl $__KERNEL_CS, 16(%rsp)
23317 jne first_nmi
23318 -
23319 +1:
23320 /*
23321 * Check the special variable on the stack to see if NMIs are
23322 * executing.
23323 @@ -1730,8 +2243,7 @@ nested_nmi:
23324
23325 1:
23326 /* Set up the interrupted NMIs stack to jump to repeat_nmi */
23327 - leaq -1*8(%rsp), %rdx
23328 - movq %rdx, %rsp
23329 + subq $8, %rsp
23330 CFI_ADJUST_CFA_OFFSET 1*8
23331 leaq -10*8(%rsp), %rdx
23332 pushq_cfi $__KERNEL_DS
23333 @@ -1749,6 +2261,7 @@ nested_nmi_out:
23334 CFI_RESTORE rdx
23335
23336 /* No need to check faults here */
23337 +# pax_force_retaddr_bts
23338 INTERRUPT_RETURN
23339
23340 CFI_RESTORE_STATE
23341 @@ -1845,13 +2358,13 @@ end_repeat_nmi:
23342 subq $ORIG_RAX-R15, %rsp
23343 CFI_ADJUST_CFA_OFFSET ORIG_RAX-R15
23344 /*
23345 - * Use save_paranoid to handle SWAPGS, but no need to use paranoid_exit
23346 + * Use save_paranoid_nmi to handle SWAPGS, but no need to use paranoid_exit
23347 * as we should not be calling schedule in NMI context.
23348 * Even with normal interrupts enabled. An NMI should not be
23349 * setting NEED_RESCHED or anything that normal interrupts and
23350 * exceptions might do.
23351 */
23352 - call save_paranoid
23353 + call save_paranoid_nmi
23354 DEFAULT_FRAME 0
23355
23356 /*
23357 @@ -1861,9 +2374,9 @@ end_repeat_nmi:
23358 * NMI itself takes a page fault, the page fault that was preempted
23359 * will read the information from the NMI page fault and not the
23360 * origin fault. Save it off and restore it if it changes.
23361 - * Use the r12 callee-saved register.
23362 + * Use the r13 callee-saved register.
23363 */
23364 - movq %cr2, %r12
23365 + movq %cr2, %r13
23366
23367 /* paranoidentry do_nmi, 0; without TRACE_IRQS_OFF */
23368 movq %rsp,%rdi
23369 @@ -1872,31 +2385,36 @@ end_repeat_nmi:
23370
23371 /* Did the NMI take a page fault? Restore cr2 if it did */
23372 movq %cr2, %rcx
23373 - cmpq %rcx, %r12
23374 + cmpq %rcx, %r13
23375 je 1f
23376 - movq %r12, %cr2
23377 + movq %r13, %cr2
23378 1:
23379
23380 - testl %ebx,%ebx /* swapgs needed? */
23381 + testl $1,%ebx /* swapgs needed? */
23382 jnz nmi_restore
23383 nmi_swapgs:
23384 SWAPGS_UNSAFE_STACK
23385 nmi_restore:
23386 + pax_exit_kernel_nmi
23387 /* Pop the extra iret frame at once */
23388 RESTORE_ALL 6*8
23389 + testb $3, 8(%rsp)
23390 + jnz 1f
23391 + pax_force_retaddr_bts
23392 +1:
23393
23394 /* Clear the NMI executing stack variable */
23395 movq $0, 5*8(%rsp)
23396 jmp irq_return
23397 CFI_ENDPROC
23398 -END(nmi)
23399 +ENDPROC(nmi)
23400
23401 ENTRY(ignore_sysret)
23402 CFI_STARTPROC
23403 mov $-ENOSYS,%eax
23404 sysret
23405 CFI_ENDPROC
23406 -END(ignore_sysret)
23407 +ENDPROC(ignore_sysret)
23408
23409 /*
23410 * End of kprobes section
23411 diff --git a/arch/x86/kernel/ftrace.c b/arch/x86/kernel/ftrace.c
23412 index d4bdd25..912664c 100644
23413 --- a/arch/x86/kernel/ftrace.c
23414 +++ b/arch/x86/kernel/ftrace.c
23415 @@ -105,6 +105,8 @@ ftrace_modify_code_direct(unsigned long ip, unsigned const char *old_code,
23416 {
23417 unsigned char replaced[MCOUNT_INSN_SIZE];
23418
23419 + ip = ktla_ktva(ip);
23420 +
23421 /*
23422 * Note: Due to modules and __init, code can
23423 * disappear and change, we need to protect against faulting
23424 @@ -227,7 +229,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
23425 unsigned char old[MCOUNT_INSN_SIZE], *new;
23426 int ret;
23427
23428 - memcpy(old, &ftrace_call, MCOUNT_INSN_SIZE);
23429 + memcpy(old, (void *)ktla_ktva((unsigned long)ftrace_call), MCOUNT_INSN_SIZE);
23430 new = ftrace_call_replace(ip, (unsigned long)func);
23431
23432 /* See comment above by declaration of modifying_ftrace_code */
23433 @@ -238,7 +240,7 @@ int ftrace_update_ftrace_func(ftrace_func_t func)
23434 /* Also update the regs callback function */
23435 if (!ret) {
23436 ip = (unsigned long)(&ftrace_regs_call);
23437 - memcpy(old, &ftrace_regs_call, MCOUNT_INSN_SIZE);
23438 + memcpy(old, ktla_ktva((void *)&ftrace_regs_call), MCOUNT_INSN_SIZE);
23439 new = ftrace_call_replace(ip, (unsigned long)func);
23440 ret = ftrace_modify_code(ip, old, new);
23441 }
23442 @@ -291,7 +293,7 @@ static int ftrace_write(unsigned long ip, const char *val, int size)
23443 * kernel identity mapping to modify code.
23444 */
23445 if (within(ip, (unsigned long)_text, (unsigned long)_etext))
23446 - ip = (unsigned long)__va(__pa_symbol(ip));
23447 + ip = (unsigned long)__va(__pa_symbol(ktla_ktva(ip)));
23448
23449 return probe_kernel_write((void *)ip, val, size);
23450 }
23451 @@ -301,7 +303,7 @@ static int add_break(unsigned long ip, const char *old)
23452 unsigned char replaced[MCOUNT_INSN_SIZE];
23453 unsigned char brk = BREAKPOINT_INSTRUCTION;
23454
23455 - if (probe_kernel_read(replaced, (void *)ip, MCOUNT_INSN_SIZE))
23456 + if (probe_kernel_read(replaced, (void *)ktla_ktva(ip), MCOUNT_INSN_SIZE))
23457 return -EFAULT;
23458
23459 /* Make sure it is what we expect it to be */
23460 @@ -649,7 +651,7 @@ ftrace_modify_code(unsigned long ip, unsigned const char *old_code,
23461 return ret;
23462
23463 fail_update:
23464 - probe_kernel_write((void *)ip, &old_code[0], 1);
23465 + probe_kernel_write((void *)ktla_ktva(ip), &old_code[0], 1);
23466 goto out;
23467 }
23468
23469 @@ -682,6 +684,8 @@ static int ftrace_mod_jmp(unsigned long ip,
23470 {
23471 unsigned char code[MCOUNT_INSN_SIZE];
23472
23473 + ip = ktla_ktva(ip);
23474 +
23475 if (probe_kernel_read(code, (void *)ip, MCOUNT_INSN_SIZE))
23476 return -EFAULT;
23477
23478 diff --git a/arch/x86/kernel/head64.c b/arch/x86/kernel/head64.c
23479 index 85126cc..1bbce17 100644
23480 --- a/arch/x86/kernel/head64.c
23481 +++ b/arch/x86/kernel/head64.c
23482 @@ -67,12 +67,12 @@ again:
23483 pgd = *pgd_p;
23484
23485 /*
23486 - * The use of __START_KERNEL_map rather than __PAGE_OFFSET here is
23487 - * critical -- __PAGE_OFFSET would point us back into the dynamic
23488 + * The use of __early_va rather than __va here is critical:
23489 + * __va would point us back into the dynamic
23490 * range and we might end up looping forever...
23491 */
23492 if (pgd)
23493 - pud_p = (pudval_t *)((pgd & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23494 + pud_p = (pudval_t *)(__early_va(pgd & PTE_PFN_MASK));
23495 else {
23496 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23497 reset_early_page_tables();
23498 @@ -82,13 +82,13 @@ again:
23499 pud_p = (pudval_t *)early_dynamic_pgts[next_early_pgt++];
23500 for (i = 0; i < PTRS_PER_PUD; i++)
23501 pud_p[i] = 0;
23502 - *pgd_p = (pgdval_t)pud_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
23503 + *pgd_p = (pgdval_t)__pa(pud_p) + _KERNPG_TABLE;
23504 }
23505 pud_p += pud_index(address);
23506 pud = *pud_p;
23507
23508 if (pud)
23509 - pmd_p = (pmdval_t *)((pud & PTE_PFN_MASK) + __START_KERNEL_map - phys_base);
23510 + pmd_p = (pmdval_t *)(__early_va(pud & PTE_PFN_MASK));
23511 else {
23512 if (next_early_pgt >= EARLY_DYNAMIC_PAGE_TABLES) {
23513 reset_early_page_tables();
23514 @@ -98,7 +98,7 @@ again:
23515 pmd_p = (pmdval_t *)early_dynamic_pgts[next_early_pgt++];
23516 for (i = 0; i < PTRS_PER_PMD; i++)
23517 pmd_p[i] = 0;
23518 - *pud_p = (pudval_t)pmd_p - __START_KERNEL_map + phys_base + _KERNPG_TABLE;
23519 + *pud_p = (pudval_t)__pa(pmd_p) + _KERNPG_TABLE;
23520 }
23521 pmd = (physaddr & PMD_MASK) + early_pmd_flags;
23522 pmd_p[pmd_index(address)] = pmd;
23523 @@ -175,7 +175,6 @@ asmlinkage void __init x86_64_start_kernel(char * real_mode_data)
23524 if (console_loglevel == 10)
23525 early_printk("Kernel alive\n");
23526
23527 - clear_page(init_level4_pgt);
23528 /* set init_level4_pgt kernel high mapping*/
23529 init_level4_pgt[511] = early_level4_pgt[511];
23530
23531 diff --git a/arch/x86/kernel/head_32.S b/arch/x86/kernel/head_32.S
23532 index 81ba276..30c5411 100644
23533 --- a/arch/x86/kernel/head_32.S
23534 +++ b/arch/x86/kernel/head_32.S
23535 @@ -26,6 +26,12 @@
23536 /* Physical address */
23537 #define pa(X) ((X) - __PAGE_OFFSET)
23538
23539 +#ifdef CONFIG_PAX_KERNEXEC
23540 +#define ta(X) (X)
23541 +#else
23542 +#define ta(X) ((X) - __PAGE_OFFSET)
23543 +#endif
23544 +
23545 /*
23546 * References to members of the new_cpu_data structure.
23547 */
23548 @@ -55,11 +61,7 @@
23549 * and small than max_low_pfn, otherwise will waste some page table entries
23550 */
23551
23552 -#if PTRS_PER_PMD > 1
23553 -#define PAGE_TABLE_SIZE(pages) (((pages) / PTRS_PER_PMD) + PTRS_PER_PGD)
23554 -#else
23555 -#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PGD)
23556 -#endif
23557 +#define PAGE_TABLE_SIZE(pages) ((pages) / PTRS_PER_PTE)
23558
23559 /* Number of possible pages in the lowmem region */
23560 LOWMEM_PAGES = (((1<<32) - __PAGE_OFFSET) >> PAGE_SHIFT)
23561 @@ -78,6 +80,12 @@ INIT_MAP_SIZE = PAGE_TABLE_SIZE(KERNEL_PAGES) * PAGE_SIZE
23562 RESERVE_BRK(pagetables, INIT_MAP_SIZE)
23563
23564 /*
23565 + * Real beginning of normal "text" segment
23566 + */
23567 +ENTRY(stext)
23568 +ENTRY(_stext)
23569 +
23570 +/*
23571 * 32-bit kernel entrypoint; only used by the boot CPU. On entry,
23572 * %esi points to the real-mode code as a 32-bit pointer.
23573 * CS and DS must be 4 GB flat segments, but we don't depend on
23574 @@ -85,6 +93,13 @@ RESERVE_BRK(pagetables, INIT_MAP_SIZE)
23575 * can.
23576 */
23577 __HEAD
23578 +
23579 +#ifdef CONFIG_PAX_KERNEXEC
23580 + jmp startup_32
23581 +/* PaX: fill first page in .text with int3 to catch NULL derefs in kernel mode */
23582 +.fill PAGE_SIZE-5,1,0xcc
23583 +#endif
23584 +
23585 ENTRY(startup_32)
23586 movl pa(stack_start),%ecx
23587
23588 @@ -106,6 +121,59 @@ ENTRY(startup_32)
23589 2:
23590 leal -__PAGE_OFFSET(%ecx),%esp
23591
23592 +#ifdef CONFIG_SMP
23593 + movl $pa(cpu_gdt_table),%edi
23594 + movl $__per_cpu_load,%eax
23595 + movw %ax,GDT_ENTRY_PERCPU * 8 + 2(%edi)
23596 + rorl $16,%eax
23597 + movb %al,GDT_ENTRY_PERCPU * 8 + 4(%edi)
23598 + movb %ah,GDT_ENTRY_PERCPU * 8 + 7(%edi)
23599 + movl $__per_cpu_end - 1,%eax
23600 + subl $__per_cpu_start,%eax
23601 + movw %ax,GDT_ENTRY_PERCPU * 8 + 0(%edi)
23602 +#endif
23603 +
23604 +#ifdef CONFIG_PAX_MEMORY_UDEREF
23605 + movl $NR_CPUS,%ecx
23606 + movl $pa(cpu_gdt_table),%edi
23607 +1:
23608 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c09700),GDT_ENTRY_KERNEL_DS * 8 + 4(%edi)
23609 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0fb00),GDT_ENTRY_DEFAULT_USER_CS * 8 + 4(%edi)
23610 + movl $((((__PAGE_OFFSET-1) & 0xf0000000) >> 12) | 0x00c0f300),GDT_ENTRY_DEFAULT_USER_DS * 8 + 4(%edi)
23611 + addl $PAGE_SIZE_asm,%edi
23612 + loop 1b
23613 +#endif
23614 +
23615 +#ifdef CONFIG_PAX_KERNEXEC
23616 + movl $pa(boot_gdt),%edi
23617 + movl $__LOAD_PHYSICAL_ADDR,%eax
23618 + movw %ax,GDT_ENTRY_BOOT_CS * 8 + 2(%edi)
23619 + rorl $16,%eax
23620 + movb %al,GDT_ENTRY_BOOT_CS * 8 + 4(%edi)
23621 + movb %ah,GDT_ENTRY_BOOT_CS * 8 + 7(%edi)
23622 + rorl $16,%eax
23623 +
23624 + ljmp $(__BOOT_CS),$1f
23625 +1:
23626 +
23627 + movl $NR_CPUS,%ecx
23628 + movl $pa(cpu_gdt_table),%edi
23629 + addl $__PAGE_OFFSET,%eax
23630 +1:
23631 + movb $0xc0,GDT_ENTRY_KERNEL_CS * 8 + 6(%edi)
23632 + movb $0xc0,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 6(%edi)
23633 + movw %ax,GDT_ENTRY_KERNEL_CS * 8 + 2(%edi)
23634 + movw %ax,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 2(%edi)
23635 + rorl $16,%eax
23636 + movb %al,GDT_ENTRY_KERNEL_CS * 8 + 4(%edi)
23637 + movb %al,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 4(%edi)
23638 + movb %ah,GDT_ENTRY_KERNEL_CS * 8 + 7(%edi)
23639 + movb %ah,GDT_ENTRY_KERNEXEC_KERNEL_CS * 8 + 7(%edi)
23640 + rorl $16,%eax
23641 + addl $PAGE_SIZE_asm,%edi
23642 + loop 1b
23643 +#endif
23644 +
23645 /*
23646 * Clear BSS first so that there are no surprises...
23647 */
23648 @@ -201,8 +269,11 @@ ENTRY(startup_32)
23649 movl %eax, pa(max_pfn_mapped)
23650
23651 /* Do early initialization of the fixmap area */
23652 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
23653 - movl %eax,pa(initial_pg_pmd+0x1000*KPMDS-8)
23654 +#ifdef CONFIG_COMPAT_VDSO
23655 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_pg_pmd+0x1000*KPMDS-8)
23656 +#else
23657 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_pg_pmd+0x1000*KPMDS-8)
23658 +#endif
23659 #else /* Not PAE */
23660
23661 page_pde_offset = (__PAGE_OFFSET >> 20);
23662 @@ -232,8 +303,11 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
23663 movl %eax, pa(max_pfn_mapped)
23664
23665 /* Do early initialization of the fixmap area */
23666 - movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,%eax
23667 - movl %eax,pa(initial_page_table+0xffc)
23668 +#ifdef CONFIG_COMPAT_VDSO
23669 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR+_PAGE_USER,pa(initial_page_table+0xffc)
23670 +#else
23671 + movl $pa(initial_pg_fixmap)+PDE_IDENT_ATTR,pa(initial_page_table+0xffc)
23672 +#endif
23673 #endif
23674
23675 #ifdef CONFIG_PARAVIRT
23676 @@ -247,9 +321,7 @@ page_pde_offset = (__PAGE_OFFSET >> 20);
23677 cmpl $num_subarch_entries, %eax
23678 jae bad_subarch
23679
23680 - movl pa(subarch_entries)(,%eax,4), %eax
23681 - subl $__PAGE_OFFSET, %eax
23682 - jmp *%eax
23683 + jmp *pa(subarch_entries)(,%eax,4)
23684
23685 bad_subarch:
23686 WEAK(lguest_entry)
23687 @@ -261,10 +333,10 @@ WEAK(xen_entry)
23688 __INITDATA
23689
23690 subarch_entries:
23691 - .long default_entry /* normal x86/PC */
23692 - .long lguest_entry /* lguest hypervisor */
23693 - .long xen_entry /* Xen hypervisor */
23694 - .long default_entry /* Moorestown MID */
23695 + .long ta(default_entry) /* normal x86/PC */
23696 + .long ta(lguest_entry) /* lguest hypervisor */
23697 + .long ta(xen_entry) /* Xen hypervisor */
23698 + .long ta(default_entry) /* Moorestown MID */
23699 num_subarch_entries = (. - subarch_entries) / 4
23700 .previous
23701 #else
23702 @@ -354,6 +426,7 @@ default_entry:
23703 movl pa(mmu_cr4_features),%eax
23704 movl %eax,%cr4
23705
23706 +#ifdef CONFIG_X86_PAE
23707 testb $X86_CR4_PAE, %al # check if PAE is enabled
23708 jz enable_paging
23709
23710 @@ -382,6 +455,9 @@ default_entry:
23711 /* Make changes effective */
23712 wrmsr
23713
23714 + btsl $_PAGE_BIT_NX-32,pa(__supported_pte_mask+4)
23715 +#endif
23716 +
23717 enable_paging:
23718
23719 /*
23720 @@ -449,14 +525,20 @@ is486:
23721 1: movl $(__KERNEL_DS),%eax # reload all the segment registers
23722 movl %eax,%ss # after changing gdt.
23723
23724 - movl $(__USER_DS),%eax # DS/ES contains default USER segment
23725 +# movl $(__KERNEL_DS),%eax # DS/ES contains default KERNEL segment
23726 movl %eax,%ds
23727 movl %eax,%es
23728
23729 movl $(__KERNEL_PERCPU), %eax
23730 movl %eax,%fs # set this cpu's percpu
23731
23732 +#ifdef CONFIG_CC_STACKPROTECTOR
23733 movl $(__KERNEL_STACK_CANARY),%eax
23734 +#elif defined(CONFIG_PAX_MEMORY_UDEREF)
23735 + movl $(__USER_DS),%eax
23736 +#else
23737 + xorl %eax,%eax
23738 +#endif
23739 movl %eax,%gs
23740
23741 xorl %eax,%eax # Clear LDT
23742 @@ -512,8 +594,11 @@ setup_once:
23743 * relocation. Manually set base address in stack canary
23744 * segment descriptor.
23745 */
23746 - movl $gdt_page,%eax
23747 + movl $cpu_gdt_table,%eax
23748 movl $stack_canary,%ecx
23749 +#ifdef CONFIG_SMP
23750 + addl $__per_cpu_load,%ecx
23751 +#endif
23752 movw %cx, 8 * GDT_ENTRY_STACK_CANARY + 2(%eax)
23753 shrl $16, %ecx
23754 movb %cl, 8 * GDT_ENTRY_STACK_CANARY + 4(%eax)
23755 @@ -544,7 +629,7 @@ ENDPROC(early_idt_handlers)
23756 /* This is global to keep gas from relaxing the jumps */
23757 ENTRY(early_idt_handler)
23758 cld
23759 - cmpl $2,%ss:early_recursion_flag
23760 + cmpl $1,%ss:early_recursion_flag
23761 je hlt_loop
23762 incl %ss:early_recursion_flag
23763
23764 @@ -582,8 +667,8 @@ ENTRY(early_idt_handler)
23765 pushl (20+6*4)(%esp) /* trapno */
23766 pushl $fault_msg
23767 call printk
23768 -#endif
23769 call dump_stack
23770 +#endif
23771 hlt_loop:
23772 hlt
23773 jmp hlt_loop
23774 @@ -602,8 +687,11 @@ ENDPROC(early_idt_handler)
23775 /* This is the default interrupt "handler" :-) */
23776 ALIGN
23777 ignore_int:
23778 - cld
23779 #ifdef CONFIG_PRINTK
23780 + cmpl $2,%ss:early_recursion_flag
23781 + je hlt_loop
23782 + incl %ss:early_recursion_flag
23783 + cld
23784 pushl %eax
23785 pushl %ecx
23786 pushl %edx
23787 @@ -612,9 +700,6 @@ ignore_int:
23788 movl $(__KERNEL_DS),%eax
23789 movl %eax,%ds
23790 movl %eax,%es
23791 - cmpl $2,early_recursion_flag
23792 - je hlt_loop
23793 - incl early_recursion_flag
23794 pushl 16(%esp)
23795 pushl 24(%esp)
23796 pushl 32(%esp)
23797 @@ -648,29 +733,34 @@ ENTRY(setup_once_ref)
23798 /*
23799 * BSS section
23800 */
23801 -__PAGE_ALIGNED_BSS
23802 - .align PAGE_SIZE
23803 #ifdef CONFIG_X86_PAE
23804 +.section .initial_pg_pmd,"a",@progbits
23805 initial_pg_pmd:
23806 .fill 1024*KPMDS,4,0
23807 #else
23808 +.section .initial_page_table,"a",@progbits
23809 ENTRY(initial_page_table)
23810 .fill 1024,4,0
23811 #endif
23812 +.section .initial_pg_fixmap,"a",@progbits
23813 initial_pg_fixmap:
23814 .fill 1024,4,0
23815 +.section .empty_zero_page,"a",@progbits
23816 ENTRY(empty_zero_page)
23817 .fill 4096,1,0
23818 +.section .swapper_pg_dir,"a",@progbits
23819 ENTRY(swapper_pg_dir)
23820 +#ifdef CONFIG_X86_PAE
23821 + .fill 4,8,0
23822 +#else
23823 .fill 1024,4,0
23824 +#endif
23825
23826 /*
23827 * This starts the data section.
23828 */
23829 #ifdef CONFIG_X86_PAE
23830 -__PAGE_ALIGNED_DATA
23831 - /* Page-aligned for the benefit of paravirt? */
23832 - .align PAGE_SIZE
23833 +.section .initial_page_table,"a",@progbits
23834 ENTRY(initial_page_table)
23835 .long pa(initial_pg_pmd+PGD_IDENT_ATTR),0 /* low identity map */
23836 # if KPMDS == 3
23837 @@ -689,12 +779,20 @@ ENTRY(initial_page_table)
23838 # error "Kernel PMDs should be 1, 2 or 3"
23839 # endif
23840 .align PAGE_SIZE /* needs to be page-sized too */
23841 +
23842 +#ifdef CONFIG_PAX_PER_CPU_PGD
23843 +ENTRY(cpu_pgd)
23844 + .rept 2*NR_CPUS
23845 + .fill 4,8,0
23846 + .endr
23847 +#endif
23848 +
23849 #endif
23850
23851 .data
23852 .balign 4
23853 ENTRY(stack_start)
23854 - .long init_thread_union+THREAD_SIZE
23855 + .long init_thread_union+THREAD_SIZE-8
23856
23857 __INITRODATA
23858 int_msg:
23859 @@ -722,7 +820,7 @@ fault_msg:
23860 * segment size, and 32-bit linear address value:
23861 */
23862
23863 - .data
23864 +.section .rodata,"a",@progbits
23865 .globl boot_gdt_descr
23866 .globl idt_descr
23867
23868 @@ -731,7 +829,7 @@ fault_msg:
23869 .word 0 # 32 bit align gdt_desc.address
23870 boot_gdt_descr:
23871 .word __BOOT_DS+7
23872 - .long boot_gdt - __PAGE_OFFSET
23873 + .long pa(boot_gdt)
23874
23875 .word 0 # 32-bit align idt_desc.address
23876 idt_descr:
23877 @@ -742,7 +840,7 @@ idt_descr:
23878 .word 0 # 32 bit align gdt_desc.address
23879 ENTRY(early_gdt_descr)
23880 .word GDT_ENTRIES*8-1
23881 - .long gdt_page /* Overwritten for secondary CPUs */
23882 + .long cpu_gdt_table /* Overwritten for secondary CPUs */
23883
23884 /*
23885 * The boot_gdt must mirror the equivalent in setup.S and is
23886 @@ -751,5 +849,65 @@ ENTRY(early_gdt_descr)
23887 .align L1_CACHE_BYTES
23888 ENTRY(boot_gdt)
23889 .fill GDT_ENTRY_BOOT_CS,8,0
23890 - .quad 0x00cf9a000000ffff /* kernel 4GB code at 0x00000000 */
23891 - .quad 0x00cf92000000ffff /* kernel 4GB data at 0x00000000 */
23892 + .quad 0x00cf9b000000ffff /* kernel 4GB code at 0x00000000 */
23893 + .quad 0x00cf93000000ffff /* kernel 4GB data at 0x00000000 */
23894 +
23895 + .align PAGE_SIZE_asm
23896 +ENTRY(cpu_gdt_table)
23897 + .rept NR_CPUS
23898 + .quad 0x0000000000000000 /* NULL descriptor */
23899 + .quad 0x0000000000000000 /* 0x0b reserved */
23900 + .quad 0x0000000000000000 /* 0x13 reserved */
23901 + .quad 0x0000000000000000 /* 0x1b reserved */
23902 +
23903 +#ifdef CONFIG_PAX_KERNEXEC
23904 + .quad 0x00cf9b000000ffff /* 0x20 alternate kernel 4GB code at 0x00000000 */
23905 +#else
23906 + .quad 0x0000000000000000 /* 0x20 unused */
23907 +#endif
23908 +
23909 + .quad 0x0000000000000000 /* 0x28 unused */
23910 + .quad 0x0000000000000000 /* 0x33 TLS entry 1 */
23911 + .quad 0x0000000000000000 /* 0x3b TLS entry 2 */
23912 + .quad 0x0000000000000000 /* 0x43 TLS entry 3 */
23913 + .quad 0x0000000000000000 /* 0x4b reserved */
23914 + .quad 0x0000000000000000 /* 0x53 reserved */
23915 + .quad 0x0000000000000000 /* 0x5b reserved */
23916 +
23917 + .quad 0x00cf9b000000ffff /* 0x60 kernel 4GB code at 0x00000000 */
23918 + .quad 0x00cf93000000ffff /* 0x68 kernel 4GB data at 0x00000000 */
23919 + .quad 0x00cffb000000ffff /* 0x73 user 4GB code at 0x00000000 */
23920 + .quad 0x00cff3000000ffff /* 0x7b user 4GB data at 0x00000000 */
23921 +
23922 + .quad 0x0000000000000000 /* 0x80 TSS descriptor */
23923 + .quad 0x0000000000000000 /* 0x88 LDT descriptor */
23924 +
23925 + /*
23926 + * Segments used for calling PnP BIOS have byte granularity.
23927 + * The code segments and data segments have fixed 64k limits,
23928 + * the transfer segment sizes are set at run time.
23929 + */
23930 + .quad 0x00409b000000ffff /* 0x90 32-bit code */
23931 + .quad 0x00009b000000ffff /* 0x98 16-bit code */
23932 + .quad 0x000093000000ffff /* 0xa0 16-bit data */
23933 + .quad 0x0000930000000000 /* 0xa8 16-bit data */
23934 + .quad 0x0000930000000000 /* 0xb0 16-bit data */
23935 +
23936 + /*
23937 + * The APM segments have byte granularity and their bases
23938 + * are set at run time. All have 64k limits.
23939 + */
23940 + .quad 0x00409b000000ffff /* 0xb8 APM CS code */
23941 + .quad 0x00009b000000ffff /* 0xc0 APM CS 16 code (16 bit) */
23942 + .quad 0x004093000000ffff /* 0xc8 APM DS data */
23943 +
23944 + .quad 0x00c0930000000000 /* 0xd0 - ESPFIX SS */
23945 + .quad 0x0040930000000000 /* 0xd8 - PERCPU */
23946 + .quad 0x0040910000000017 /* 0xe0 - STACK_CANARY */
23947 + .quad 0x0000000000000000 /* 0xe8 - PCIBIOS_CS */
23948 + .quad 0x0000000000000000 /* 0xf0 - PCIBIOS_DS */
23949 + .quad 0x0000000000000000 /* 0xf8 - GDT entry 31: double-fault TSS */
23950 +
23951 + /* Be sure this is zeroed to avoid false validations in Xen */
23952 + .fill PAGE_SIZE_asm - GDT_SIZE,1,0
23953 + .endr
23954 diff --git a/arch/x86/kernel/head_64.S b/arch/x86/kernel/head_64.S
23955 index e1aabdb..fee4fee 100644
23956 --- a/arch/x86/kernel/head_64.S
23957 +++ b/arch/x86/kernel/head_64.S
23958 @@ -20,6 +20,8 @@
23959 #include <asm/processor-flags.h>
23960 #include <asm/percpu.h>
23961 #include <asm/nops.h>
23962 +#include <asm/cpufeature.h>
23963 +#include <asm/alternative-asm.h>
23964
23965 #ifdef CONFIG_PARAVIRT
23966 #include <asm/asm-offsets.h>
23967 @@ -41,6 +43,12 @@ L4_PAGE_OFFSET = pgd_index(__PAGE_OFFSET)
23968 L3_PAGE_OFFSET = pud_index(__PAGE_OFFSET)
23969 L4_START_KERNEL = pgd_index(__START_KERNEL_map)
23970 L3_START_KERNEL = pud_index(__START_KERNEL_map)
23971 +L4_VMALLOC_START = pgd_index(VMALLOC_START)
23972 +L3_VMALLOC_START = pud_index(VMALLOC_START)
23973 +L4_VMALLOC_END = pgd_index(VMALLOC_END)
23974 +L3_VMALLOC_END = pud_index(VMALLOC_END)
23975 +L4_VMEMMAP_START = pgd_index(VMEMMAP_START)
23976 +L3_VMEMMAP_START = pud_index(VMEMMAP_START)
23977
23978 .text
23979 __HEAD
23980 @@ -89,11 +97,24 @@ startup_64:
23981 * Fixup the physical addresses in the page table
23982 */
23983 addq %rbp, early_level4_pgt + (L4_START_KERNEL*8)(%rip)
23984 + addq %rbp, init_level4_pgt + (L4_PAGE_OFFSET*8)(%rip)
23985 + addq %rbp, init_level4_pgt + (L4_VMALLOC_START*8)(%rip)
23986 + addq %rbp, init_level4_pgt + (L4_VMALLOC_END*8)(%rip)
23987 + addq %rbp, init_level4_pgt + (L4_VMEMMAP_START*8)(%rip)
23988 + addq %rbp, init_level4_pgt + (L4_START_KERNEL*8)(%rip)
23989
23990 - addq %rbp, level3_kernel_pgt + (510*8)(%rip)
23991 - addq %rbp, level3_kernel_pgt + (511*8)(%rip)
23992 + addq %rbp, level3_ident_pgt + (0*8)(%rip)
23993 +#ifndef CONFIG_XEN
23994 + addq %rbp, level3_ident_pgt + (1*8)(%rip)
23995 +#endif
23996 +
23997 + addq %rbp, level3_vmemmap_pgt + (L3_VMEMMAP_START*8)(%rip)
23998 +
23999 + addq %rbp, level3_kernel_pgt + (L3_START_KERNEL*8)(%rip)
24000 + addq %rbp, level3_kernel_pgt + ((L3_START_KERNEL+1)*8)(%rip)
24001
24002 addq %rbp, level2_fixmap_pgt + (506*8)(%rip)
24003 + addq %rbp, level2_fixmap_pgt + (507*8)(%rip)
24004
24005 /*
24006 * Set up the identity mapping for the switchover. These
24007 @@ -177,8 +198,8 @@ ENTRY(secondary_startup_64)
24008 movq $(init_level4_pgt - __START_KERNEL_map), %rax
24009 1:
24010
24011 - /* Enable PAE mode and PGE */
24012 - movl $(X86_CR4_PAE | X86_CR4_PGE), %ecx
24013 + /* Enable PAE mode and PSE/PGE */
24014 + movl $(X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE), %ecx
24015 movq %rcx, %cr4
24016
24017 /* Setup early boot stage 4 level pagetables. */
24018 @@ -199,10 +220,19 @@ ENTRY(secondary_startup_64)
24019 movl $MSR_EFER, %ecx
24020 rdmsr
24021 btsl $_EFER_SCE, %eax /* Enable System Call */
24022 - btl $20,%edi /* No Execute supported? */
24023 + btl $(X86_FEATURE_NX & 31),%edi /* No Execute supported? */
24024 jnc 1f
24025 btsl $_EFER_NX, %eax
24026 btsq $_PAGE_BIT_NX,early_pmd_flags(%rip)
24027 +#ifndef CONFIG_EFI
24028 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_PAGE_OFFSET(%rip)
24029 +#endif
24030 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_START(%rip)
24031 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMALLOC_END(%rip)
24032 + btsq $_PAGE_BIT_NX, init_level4_pgt + 8*L4_VMEMMAP_START(%rip)
24033 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*506(%rip)
24034 + btsq $_PAGE_BIT_NX, level2_fixmap_pgt + 8*507(%rip)
24035 + btsq $_PAGE_BIT_NX, __supported_pte_mask(%rip)
24036 1: wrmsr /* Make changes effective */
24037
24038 /* Setup cr0 */
24039 @@ -282,6 +312,7 @@ ENTRY(secondary_startup_64)
24040 * REX.W + FF /5 JMP m16:64 Jump far, absolute indirect,
24041 * address given in m16:64.
24042 */
24043 + pax_set_fptr_mask
24044 movq initial_code(%rip),%rax
24045 pushq $0 # fake return address to stop unwinder
24046 pushq $__KERNEL_CS # set correct cs
24047 @@ -388,7 +419,7 @@ ENTRY(early_idt_handler)
24048 call dump_stack
24049 #ifdef CONFIG_KALLSYMS
24050 leaq early_idt_ripmsg(%rip),%rdi
24051 - movq 40(%rsp),%rsi # %rip again
24052 + movq 88(%rsp),%rsi # %rip again
24053 call __print_symbol
24054 #endif
24055 #endif /* EARLY_PRINTK */
24056 @@ -416,6 +447,7 @@ ENDPROC(early_idt_handler)
24057 early_recursion_flag:
24058 .long 0
24059
24060 + .section .rodata,"a",@progbits
24061 #ifdef CONFIG_EARLY_PRINTK
24062 early_idt_msg:
24063 .asciz "PANIC: early exception %02lx rip %lx:%lx error %lx cr2 %lx\n"
24064 @@ -443,29 +475,52 @@ NEXT_PAGE(early_level4_pgt)
24065 NEXT_PAGE(early_dynamic_pgts)
24066 .fill 512*EARLY_DYNAMIC_PAGE_TABLES,8,0
24067
24068 - .data
24069 + .section .rodata,"a",@progbits
24070
24071 -#ifndef CONFIG_XEN
24072 NEXT_PAGE(init_level4_pgt)
24073 - .fill 512,8,0
24074 -#else
24075 -NEXT_PAGE(init_level4_pgt)
24076 - .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24077 .org init_level4_pgt + L4_PAGE_OFFSET*8, 0
24078 .quad level3_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24079 + .org init_level4_pgt + L4_VMALLOC_START*8, 0
24080 + .quad level3_vmalloc_start_pgt - __START_KERNEL_map + _KERNPG_TABLE
24081 + .org init_level4_pgt + L4_VMALLOC_END*8, 0
24082 + .quad level3_vmalloc_end_pgt - __START_KERNEL_map + _KERNPG_TABLE
24083 + .org init_level4_pgt + L4_VMEMMAP_START*8, 0
24084 + .quad level3_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24085 .org init_level4_pgt + L4_START_KERNEL*8, 0
24086 /* (2^48-(2*1024*1024*1024))/(2^39) = 511 */
24087 .quad level3_kernel_pgt - __START_KERNEL_map + _PAGE_TABLE
24088
24089 +#ifdef CONFIG_PAX_PER_CPU_PGD
24090 +NEXT_PAGE(cpu_pgd)
24091 + .rept 2*NR_CPUS
24092 + .fill 512,8,0
24093 + .endr
24094 +#endif
24095 +
24096 NEXT_PAGE(level3_ident_pgt)
24097 .quad level2_ident_pgt - __START_KERNEL_map + _KERNPG_TABLE
24098 +#ifdef CONFIG_XEN
24099 .fill 511, 8, 0
24100 +#else
24101 + .quad level2_ident_pgt + PAGE_SIZE - __START_KERNEL_map + _KERNPG_TABLE
24102 + .fill 510,8,0
24103 +#endif
24104 +
24105 +NEXT_PAGE(level3_vmalloc_start_pgt)
24106 + .fill 512,8,0
24107 +
24108 +NEXT_PAGE(level3_vmalloc_end_pgt)
24109 + .fill 512,8,0
24110 +
24111 +NEXT_PAGE(level3_vmemmap_pgt)
24112 + .fill L3_VMEMMAP_START,8,0
24113 + .quad level2_vmemmap_pgt - __START_KERNEL_map + _KERNPG_TABLE
24114 +
24115 NEXT_PAGE(level2_ident_pgt)
24116 - /* Since I easily can, map the first 1G.
24117 + /* Since I easily can, map the first 2G.
24118 * Don't set NX because code runs from these pages.
24119 */
24120 - PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, PTRS_PER_PMD)
24121 -#endif
24122 + PMDS(0, __PAGE_KERNEL_IDENT_LARGE_EXEC, 2*PTRS_PER_PMD)
24123
24124 NEXT_PAGE(level3_kernel_pgt)
24125 .fill L3_START_KERNEL,8,0
24126 @@ -473,6 +528,9 @@ NEXT_PAGE(level3_kernel_pgt)
24127 .quad level2_kernel_pgt - __START_KERNEL_map + _KERNPG_TABLE
24128 .quad level2_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24129
24130 +NEXT_PAGE(level2_vmemmap_pgt)
24131 + .fill 512,8,0
24132 +
24133 NEXT_PAGE(level2_kernel_pgt)
24134 /*
24135 * 512 MB kernel mapping. We spend a full page on this pagetable
24136 @@ -490,28 +548,64 @@ NEXT_PAGE(level2_kernel_pgt)
24137 NEXT_PAGE(level2_fixmap_pgt)
24138 .fill 506,8,0
24139 .quad level1_fixmap_pgt - __START_KERNEL_map + _PAGE_TABLE
24140 - /* 8MB reserved for vsyscalls + a 2MB hole = 4 + 1 entries */
24141 - .fill 5,8,0
24142 + .quad level1_vsyscall_pgt - __START_KERNEL_map + _PAGE_TABLE
24143 + /* 6MB reserved for vsyscalls + a 2MB hole = 3 + 1 entries */
24144 + .fill 4,8,0
24145
24146 NEXT_PAGE(level1_fixmap_pgt)
24147 .fill 512,8,0
24148
24149 +NEXT_PAGE(level1_vsyscall_pgt)
24150 + .fill 512,8,0
24151 +
24152 #undef PMDS
24153
24154 - .data
24155 + .align PAGE_SIZE
24156 +ENTRY(cpu_gdt_table)
24157 + .rept NR_CPUS
24158 + .quad 0x0000000000000000 /* NULL descriptor */
24159 + .quad 0x00cf9b000000ffff /* __KERNEL32_CS */
24160 + .quad 0x00af9b000000ffff /* __KERNEL_CS */
24161 + .quad 0x00cf93000000ffff /* __KERNEL_DS */
24162 + .quad 0x00cffb000000ffff /* __USER32_CS */
24163 + .quad 0x00cff3000000ffff /* __USER_DS, __USER32_DS */
24164 + .quad 0x00affb000000ffff /* __USER_CS */
24165 +
24166 +#ifdef CONFIG_PAX_KERNEXEC
24167 + .quad 0x00af9b000000ffff /* __KERNEXEC_KERNEL_CS */
24168 +#else
24169 + .quad 0x0 /* unused */
24170 +#endif
24171 +
24172 + .quad 0,0 /* TSS */
24173 + .quad 0,0 /* LDT */
24174 + .quad 0,0,0 /* three TLS descriptors */
24175 + .quad 0x0000f40000000000 /* node/CPU stored in limit */
24176 + /* asm/segment.h:GDT_ENTRIES must match this */
24177 +
24178 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24179 + .quad 0x00cf93000000ffff /* __UDEREF_KERNEL_DS */
24180 +#else
24181 + .quad 0x0 /* unused */
24182 +#endif
24183 +
24184 + /* zero the remaining page */
24185 + .fill PAGE_SIZE / 8 - GDT_ENTRIES,8,0
24186 + .endr
24187 +
24188 .align 16
24189 .globl early_gdt_descr
24190 early_gdt_descr:
24191 .word GDT_ENTRIES*8-1
24192 early_gdt_descr_base:
24193 - .quad INIT_PER_CPU_VAR(gdt_page)
24194 + .quad cpu_gdt_table
24195
24196 ENTRY(phys_base)
24197 /* This must match the first entry in level2_kernel_pgt */
24198 .quad 0x0000000000000000
24199
24200 #include "../../x86/xen/xen-head.S"
24201 -
24202 - __PAGE_ALIGNED_BSS
24203 +
24204 + .section .rodata,"a",@progbits
24205 NEXT_PAGE(empty_zero_page)
24206 .skip PAGE_SIZE
24207 diff --git a/arch/x86/kernel/i386_ksyms_32.c b/arch/x86/kernel/i386_ksyms_32.c
24208 index 05fd74f..c3548b1 100644
24209 --- a/arch/x86/kernel/i386_ksyms_32.c
24210 +++ b/arch/x86/kernel/i386_ksyms_32.c
24211 @@ -20,8 +20,12 @@ extern void cmpxchg8b_emu(void);
24212 EXPORT_SYMBOL(cmpxchg8b_emu);
24213 #endif
24214
24215 +EXPORT_SYMBOL_GPL(cpu_gdt_table);
24216 +
24217 /* Networking helper routines. */
24218 EXPORT_SYMBOL(csum_partial_copy_generic);
24219 +EXPORT_SYMBOL(csum_partial_copy_generic_to_user);
24220 +EXPORT_SYMBOL(csum_partial_copy_generic_from_user);
24221
24222 EXPORT_SYMBOL(__get_user_1);
24223 EXPORT_SYMBOL(__get_user_2);
24224 @@ -44,3 +48,11 @@ EXPORT_SYMBOL(___preempt_schedule);
24225 EXPORT_SYMBOL(___preempt_schedule_context);
24226 #endif
24227 #endif
24228 +
24229 +#ifdef CONFIG_PAX_KERNEXEC
24230 +EXPORT_SYMBOL(__LOAD_PHYSICAL_ADDR);
24231 +#endif
24232 +
24233 +#ifdef CONFIG_PAX_PER_CPU_PGD
24234 +EXPORT_SYMBOL(cpu_pgd);
24235 +#endif
24236 diff --git a/arch/x86/kernel/i387.c b/arch/x86/kernel/i387.c
24237 index e8368c6..9c1a712 100644
24238 --- a/arch/x86/kernel/i387.c
24239 +++ b/arch/x86/kernel/i387.c
24240 @@ -51,7 +51,7 @@ static inline bool interrupted_kernel_fpu_idle(void)
24241 static inline bool interrupted_user_mode(void)
24242 {
24243 struct pt_regs *regs = get_irq_regs();
24244 - return regs && user_mode_vm(regs);
24245 + return regs && user_mode(regs);
24246 }
24247
24248 /*
24249 diff --git a/arch/x86/kernel/i8259.c b/arch/x86/kernel/i8259.c
24250 index 2e977b5..5f2c273 100644
24251 --- a/arch/x86/kernel/i8259.c
24252 +++ b/arch/x86/kernel/i8259.c
24253 @@ -110,7 +110,7 @@ static int i8259A_irq_pending(unsigned int irq)
24254 static void make_8259A_irq(unsigned int irq)
24255 {
24256 disable_irq_nosync(irq);
24257 - io_apic_irqs &= ~(1<<irq);
24258 + io_apic_irqs &= ~(1UL<<irq);
24259 irq_set_chip_and_handler_name(irq, &i8259A_chip, handle_level_irq,
24260 i8259A_chip.name);
24261 enable_irq(irq);
24262 @@ -209,7 +209,7 @@ spurious_8259A_irq:
24263 "spurious 8259A interrupt: IRQ%d.\n", irq);
24264 spurious_irq_mask |= irqmask;
24265 }
24266 - atomic_inc(&irq_err_count);
24267 + atomic_inc_unchecked(&irq_err_count);
24268 /*
24269 * Theoretically we do not have to handle this IRQ,
24270 * but in Linux this does not cause problems and is
24271 @@ -332,14 +332,16 @@ static void init_8259A(int auto_eoi)
24272 /* (slave's support for AEOI in flat mode is to be investigated) */
24273 outb_pic(SLAVE_ICW4_DEFAULT, PIC_SLAVE_IMR);
24274
24275 + pax_open_kernel();
24276 if (auto_eoi)
24277 /*
24278 * In AEOI mode we just have to mask the interrupt
24279 * when acking.
24280 */
24281 - i8259A_chip.irq_mask_ack = disable_8259A_irq;
24282 + *(void **)&i8259A_chip.irq_mask_ack = disable_8259A_irq;
24283 else
24284 - i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24285 + *(void **)&i8259A_chip.irq_mask_ack = mask_and_ack_8259A;
24286 + pax_close_kernel();
24287
24288 udelay(100); /* wait for 8259A to initialize */
24289
24290 diff --git a/arch/x86/kernel/io_delay.c b/arch/x86/kernel/io_delay.c
24291 index a979b5b..1d6db75 100644
24292 --- a/arch/x86/kernel/io_delay.c
24293 +++ b/arch/x86/kernel/io_delay.c
24294 @@ -58,7 +58,7 @@ static int __init dmi_io_delay_0xed_port(const struct dmi_system_id *id)
24295 * Quirk table for systems that misbehave (lock up, etc.) if port
24296 * 0x80 is used:
24297 */
24298 -static struct dmi_system_id __initdata io_delay_0xed_port_dmi_table[] = {
24299 +static const struct dmi_system_id __initconst io_delay_0xed_port_dmi_table[] = {
24300 {
24301 .callback = dmi_io_delay_0xed_port,
24302 .ident = "Compaq Presario V6000",
24303 diff --git a/arch/x86/kernel/ioport.c b/arch/x86/kernel/ioport.c
24304 index 4ddaf66..49d5c18 100644
24305 --- a/arch/x86/kernel/ioport.c
24306 +++ b/arch/x86/kernel/ioport.c
24307 @@ -6,6 +6,7 @@
24308 #include <linux/sched.h>
24309 #include <linux/kernel.h>
24310 #include <linux/capability.h>
24311 +#include <linux/security.h>
24312 #include <linux/errno.h>
24313 #include <linux/types.h>
24314 #include <linux/ioport.h>
24315 @@ -30,6 +31,12 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24316 return -EINVAL;
24317 if (turn_on && !capable(CAP_SYS_RAWIO))
24318 return -EPERM;
24319 +#ifdef CONFIG_GRKERNSEC_IO
24320 + if (turn_on && grsec_disable_privio) {
24321 + gr_handle_ioperm();
24322 + return -ENODEV;
24323 + }
24324 +#endif
24325
24326 /*
24327 * If it's the first ioperm() call in this thread's lifetime, set the
24328 @@ -54,7 +61,7 @@ asmlinkage long sys_ioperm(unsigned long from, unsigned long num, int turn_on)
24329 * because the ->io_bitmap_max value must match the bitmap
24330 * contents:
24331 */
24332 - tss = &per_cpu(init_tss, get_cpu());
24333 + tss = init_tss + get_cpu();
24334
24335 if (turn_on)
24336 bitmap_clear(t->io_bitmap_ptr, from, num);
24337 @@ -105,6 +112,12 @@ SYSCALL_DEFINE1(iopl, unsigned int, level)
24338 if (level > old) {
24339 if (!capable(CAP_SYS_RAWIO))
24340 return -EPERM;
24341 +#ifdef CONFIG_GRKERNSEC_IO
24342 + if (grsec_disable_privio) {
24343 + gr_handle_iopl();
24344 + return -ENODEV;
24345 + }
24346 +#endif
24347 }
24348 regs->flags = (regs->flags & ~X86_EFLAGS_IOPL) | (level << 12);
24349 t->iopl = level << 12;
24350 diff --git a/arch/x86/kernel/irq.c b/arch/x86/kernel/irq.c
24351 index 22d0687..e07b2a5 100644
24352 --- a/arch/x86/kernel/irq.c
24353 +++ b/arch/x86/kernel/irq.c
24354 @@ -21,7 +21,7 @@
24355 #define CREATE_TRACE_POINTS
24356 #include <asm/trace/irq_vectors.h>
24357
24358 -atomic_t irq_err_count;
24359 +atomic_unchecked_t irq_err_count;
24360
24361 /* Function pointer for generic interrupt vector handling */
24362 void (*x86_platform_ipi_callback)(void) = NULL;
24363 @@ -125,9 +125,9 @@ int arch_show_interrupts(struct seq_file *p, int prec)
24364 seq_printf(p, "%10u ", per_cpu(mce_poll_count, j));
24365 seq_printf(p, " Machine check polls\n");
24366 #endif
24367 - seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read(&irq_err_count));
24368 + seq_printf(p, "%*s: %10u\n", prec, "ERR", atomic_read_unchecked(&irq_err_count));
24369 #if defined(CONFIG_X86_IO_APIC)
24370 - seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read(&irq_mis_count));
24371 + seq_printf(p, "%*s: %10u\n", prec, "MIS", atomic_read_unchecked(&irq_mis_count));
24372 #endif
24373 return 0;
24374 }
24375 @@ -167,7 +167,7 @@ u64 arch_irq_stat_cpu(unsigned int cpu)
24376
24377 u64 arch_irq_stat(void)
24378 {
24379 - u64 sum = atomic_read(&irq_err_count);
24380 + u64 sum = atomic_read_unchecked(&irq_err_count);
24381 return sum;
24382 }
24383
24384 diff --git a/arch/x86/kernel/irq_32.c b/arch/x86/kernel/irq_32.c
24385 index d7fcbed..1f747f7 100644
24386 --- a/arch/x86/kernel/irq_32.c
24387 +++ b/arch/x86/kernel/irq_32.c
24388 @@ -39,7 +39,7 @@ static int check_stack_overflow(void)
24389 __asm__ __volatile__("andl %%esp,%0" :
24390 "=r" (sp) : "0" (THREAD_SIZE - 1));
24391
24392 - return sp < (sizeof(struct thread_info) + STACK_WARN);
24393 + return sp < STACK_WARN;
24394 }
24395
24396 static void print_stack_overflow(void)
24397 @@ -59,8 +59,8 @@ static inline void print_stack_overflow(void) { }
24398 * per-CPU IRQ handling contexts (thread information and stack)
24399 */
24400 union irq_ctx {
24401 - struct thread_info tinfo;
24402 - u32 stack[THREAD_SIZE/sizeof(u32)];
24403 + unsigned long previous_esp;
24404 + u32 stack[THREAD_SIZE/sizeof(u32)];
24405 } __attribute__((aligned(THREAD_SIZE)));
24406
24407 static DEFINE_PER_CPU(union irq_ctx *, hardirq_ctx);
24408 @@ -80,10 +80,9 @@ static void call_on_stack(void *func, void *stack)
24409 static inline int
24410 execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24411 {
24412 - union irq_ctx *curctx, *irqctx;
24413 + union irq_ctx *irqctx;
24414 u32 *isp, arg1, arg2;
24415
24416 - curctx = (union irq_ctx *) current_thread_info();
24417 irqctx = __this_cpu_read(hardirq_ctx);
24418
24419 /*
24420 @@ -92,13 +91,16 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24421 * handler) we can't do that and just have to keep using the
24422 * current stack (which is the irq stack already after all)
24423 */
24424 - if (unlikely(curctx == irqctx))
24425 + if (unlikely((void *)current_stack_pointer - (void *)irqctx < THREAD_SIZE))
24426 return 0;
24427
24428 /* build the stack frame on the IRQ stack */
24429 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24430 - irqctx->tinfo.task = curctx->tinfo.task;
24431 - irqctx->tinfo.previous_esp = current_stack_pointer;
24432 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24433 + irqctx->previous_esp = current_stack_pointer;
24434 +
24435 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24436 + __set_fs(MAKE_MM_SEG(0));
24437 +#endif
24438
24439 if (unlikely(overflow))
24440 call_on_stack(print_stack_overflow, isp);
24441 @@ -110,6 +112,11 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24442 : "0" (irq), "1" (desc), "2" (isp),
24443 "D" (desc->handle_irq)
24444 : "memory", "cc", "ecx");
24445 +
24446 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24447 + __set_fs(current_thread_info()->addr_limit);
24448 +#endif
24449 +
24450 return 1;
24451 }
24452
24453 @@ -118,48 +125,34 @@ execute_on_irq_stack(int overflow, struct irq_desc *desc, int irq)
24454 */
24455 void irq_ctx_init(int cpu)
24456 {
24457 - union irq_ctx *irqctx;
24458 -
24459 if (per_cpu(hardirq_ctx, cpu))
24460 return;
24461
24462 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24463 - THREADINFO_GFP,
24464 - THREAD_SIZE_ORDER));
24465 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24466 - irqctx->tinfo.cpu = cpu;
24467 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24468 -
24469 - per_cpu(hardirq_ctx, cpu) = irqctx;
24470 -
24471 - irqctx = page_address(alloc_pages_node(cpu_to_node(cpu),
24472 - THREADINFO_GFP,
24473 - THREAD_SIZE_ORDER));
24474 - memset(&irqctx->tinfo, 0, sizeof(struct thread_info));
24475 - irqctx->tinfo.cpu = cpu;
24476 - irqctx->tinfo.addr_limit = MAKE_MM_SEG(0);
24477 -
24478 - per_cpu(softirq_ctx, cpu) = irqctx;
24479 -
24480 - printk(KERN_DEBUG "CPU %u irqstacks, hard=%p soft=%p\n",
24481 - cpu, per_cpu(hardirq_ctx, cpu), per_cpu(softirq_ctx, cpu));
24482 + per_cpu(hardirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24483 + per_cpu(softirq_ctx, cpu) = page_address(alloc_pages_node(cpu_to_node(cpu), THREADINFO_GFP, THREAD_SIZE_ORDER));
24484 }
24485
24486 void do_softirq_own_stack(void)
24487 {
24488 - struct thread_info *curctx;
24489 union irq_ctx *irqctx;
24490 u32 *isp;
24491
24492 - curctx = current_thread_info();
24493 irqctx = __this_cpu_read(softirq_ctx);
24494 - irqctx->tinfo.task = curctx->task;
24495 - irqctx->tinfo.previous_esp = current_stack_pointer;
24496 + irqctx->previous_esp = current_stack_pointer;
24497
24498 /* build the stack frame on the softirq stack */
24499 - isp = (u32 *) ((char *)irqctx + sizeof(*irqctx));
24500 + isp = (u32 *) ((char *)irqctx + sizeof(*irqctx) - 8);
24501 +
24502 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24503 + __set_fs(MAKE_MM_SEG(0));
24504 +#endif
24505
24506 call_on_stack(__do_softirq, isp);
24507 +
24508 +#ifdef CONFIG_PAX_MEMORY_UDEREF
24509 + __set_fs(current_thread_info()->addr_limit);
24510 +#endif
24511 +
24512 }
24513
24514 bool handle_irq(unsigned irq, struct pt_regs *regs)
24515 @@ -173,7 +166,7 @@ bool handle_irq(unsigned irq, struct pt_regs *regs)
24516 if (unlikely(!desc))
24517 return false;
24518
24519 - if (user_mode_vm(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
24520 + if (user_mode(regs) || !execute_on_irq_stack(overflow, desc, irq)) {
24521 if (unlikely(overflow))
24522 print_stack_overflow();
24523 desc->handle_irq(irq, desc);
24524 diff --git a/arch/x86/kernel/irq_64.c b/arch/x86/kernel/irq_64.c
24525 index 4d1c746..232961d 100644
24526 --- a/arch/x86/kernel/irq_64.c
24527 +++ b/arch/x86/kernel/irq_64.c
24528 @@ -44,7 +44,7 @@ static inline void stack_overflow_check(struct pt_regs *regs)
24529 u64 estack_top, estack_bottom;
24530 u64 curbase = (u64)task_stack_page(current);
24531
24532 - if (user_mode_vm(regs))
24533 + if (user_mode(regs))
24534 return;
24535
24536 if (regs->sp >= curbase + sizeof(struct thread_info) +
24537 diff --git a/arch/x86/kernel/jump_label.c b/arch/x86/kernel/jump_label.c
24538 index 26d5a55..a01160a 100644
24539 --- a/arch/x86/kernel/jump_label.c
24540 +++ b/arch/x86/kernel/jump_label.c
24541 @@ -51,7 +51,7 @@ static void __jump_label_transform(struct jump_entry *entry,
24542 * Jump label is enabled for the first time.
24543 * So we expect a default_nop...
24544 */
24545 - if (unlikely(memcmp((void *)entry->code, default_nop, 5)
24546 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5)
24547 != 0))
24548 bug_at((void *)entry->code, __LINE__);
24549 } else {
24550 @@ -59,7 +59,7 @@ static void __jump_label_transform(struct jump_entry *entry,
24551 * ...otherwise expect an ideal_nop. Otherwise
24552 * something went horribly wrong.
24553 */
24554 - if (unlikely(memcmp((void *)entry->code, ideal_nop, 5)
24555 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), ideal_nop, 5)
24556 != 0))
24557 bug_at((void *)entry->code, __LINE__);
24558 }
24559 @@ -75,13 +75,13 @@ static void __jump_label_transform(struct jump_entry *entry,
24560 * are converting the default nop to the ideal nop.
24561 */
24562 if (init) {
24563 - if (unlikely(memcmp((void *)entry->code, default_nop, 5) != 0))
24564 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), default_nop, 5) != 0))
24565 bug_at((void *)entry->code, __LINE__);
24566 } else {
24567 code.jump = 0xe9;
24568 code.offset = entry->target -
24569 (entry->code + JUMP_LABEL_NOP_SIZE);
24570 - if (unlikely(memcmp((void *)entry->code, &code, 5) != 0))
24571 + if (unlikely(memcmp((void *)ktla_ktva(entry->code), &code, 5) != 0))
24572 bug_at((void *)entry->code, __LINE__);
24573 }
24574 memcpy(&code, ideal_nops[NOP_ATOMIC5], JUMP_LABEL_NOP_SIZE);
24575 diff --git a/arch/x86/kernel/kgdb.c b/arch/x86/kernel/kgdb.c
24576 index 836f832..a8bda67 100644
24577 --- a/arch/x86/kernel/kgdb.c
24578 +++ b/arch/x86/kernel/kgdb.c
24579 @@ -127,11 +127,11 @@ char *dbg_get_reg(int regno, void *mem, struct pt_regs *regs)
24580 #ifdef CONFIG_X86_32
24581 switch (regno) {
24582 case GDB_SS:
24583 - if (!user_mode_vm(regs))
24584 + if (!user_mode(regs))
24585 *(unsigned long *)mem = __KERNEL_DS;
24586 break;
24587 case GDB_SP:
24588 - if (!user_mode_vm(regs))
24589 + if (!user_mode(regs))
24590 *(unsigned long *)mem = kernel_stack_pointer(regs);
24591 break;
24592 case GDB_GS:
24593 @@ -229,7 +229,10 @@ static void kgdb_correct_hw_break(void)
24594 bp->attr.bp_addr = breakinfo[breakno].addr;
24595 bp->attr.bp_len = breakinfo[breakno].len;
24596 bp->attr.bp_type = breakinfo[breakno].type;
24597 - info->address = breakinfo[breakno].addr;
24598 + if (breakinfo[breakno].type == X86_BREAKPOINT_EXECUTE)
24599 + info->address = ktla_ktva(breakinfo[breakno].addr);
24600 + else
24601 + info->address = breakinfo[breakno].addr;
24602 info->len = breakinfo[breakno].len;
24603 info->type = breakinfo[breakno].type;
24604 val = arch_install_hw_breakpoint(bp);
24605 @@ -476,12 +479,12 @@ int kgdb_arch_handle_exception(int e_vector, int signo, int err_code,
24606 case 'k':
24607 /* clear the trace bit */
24608 linux_regs->flags &= ~X86_EFLAGS_TF;
24609 - atomic_set(&kgdb_cpu_doing_single_step, -1);
24610 + atomic_set_unchecked(&kgdb_cpu_doing_single_step, -1);
24611
24612 /* set the trace bit if we're stepping */
24613 if (remcomInBuffer[0] == 's') {
24614 linux_regs->flags |= X86_EFLAGS_TF;
24615 - atomic_set(&kgdb_cpu_doing_single_step,
24616 + atomic_set_unchecked(&kgdb_cpu_doing_single_step,
24617 raw_smp_processor_id());
24618 }
24619
24620 @@ -546,7 +549,7 @@ static int __kgdb_notify(struct die_args *args, unsigned long cmd)
24621
24622 switch (cmd) {
24623 case DIE_DEBUG:
24624 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
24625 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
24626 if (user_mode(regs))
24627 return single_step_cont(regs, args);
24628 break;
24629 @@ -751,11 +754,11 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
24630 #endif /* CONFIG_DEBUG_RODATA */
24631
24632 bpt->type = BP_BREAKPOINT;
24633 - err = probe_kernel_read(bpt->saved_instr, (char *)bpt->bpt_addr,
24634 + err = probe_kernel_read(bpt->saved_instr, ktla_ktva((char *)bpt->bpt_addr),
24635 BREAK_INSTR_SIZE);
24636 if (err)
24637 return err;
24638 - err = probe_kernel_write((char *)bpt->bpt_addr,
24639 + err = probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
24640 arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE);
24641 #ifdef CONFIG_DEBUG_RODATA
24642 if (!err)
24643 @@ -768,7 +771,7 @@ int kgdb_arch_set_breakpoint(struct kgdb_bkpt *bpt)
24644 return -EBUSY;
24645 text_poke((void *)bpt->bpt_addr, arch_kgdb_ops.gdb_bpt_instr,
24646 BREAK_INSTR_SIZE);
24647 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
24648 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
24649 if (err)
24650 return err;
24651 if (memcmp(opc, arch_kgdb_ops.gdb_bpt_instr, BREAK_INSTR_SIZE))
24652 @@ -793,13 +796,13 @@ int kgdb_arch_remove_breakpoint(struct kgdb_bkpt *bpt)
24653 if (mutex_is_locked(&text_mutex))
24654 goto knl_write;
24655 text_poke((void *)bpt->bpt_addr, bpt->saved_instr, BREAK_INSTR_SIZE);
24656 - err = probe_kernel_read(opc, (char *)bpt->bpt_addr, BREAK_INSTR_SIZE);
24657 + err = probe_kernel_read(opc, ktla_ktva((char *)bpt->bpt_addr), BREAK_INSTR_SIZE);
24658 if (err || memcmp(opc, bpt->saved_instr, BREAK_INSTR_SIZE))
24659 goto knl_write;
24660 return err;
24661 knl_write:
24662 #endif /* CONFIG_DEBUG_RODATA */
24663 - return probe_kernel_write((char *)bpt->bpt_addr,
24664 + return probe_kernel_write(ktla_ktva((char *)bpt->bpt_addr),
24665 (char *)bpt->saved_instr, BREAK_INSTR_SIZE);
24666 }
24667
24668 diff --git a/arch/x86/kernel/kprobes/core.c b/arch/x86/kernel/kprobes/core.c
24669 index 79a3f96..6ba030a 100644
24670 --- a/arch/x86/kernel/kprobes/core.c
24671 +++ b/arch/x86/kernel/kprobes/core.c
24672 @@ -119,9 +119,12 @@ static void __kprobes __synthesize_relative_insn(void *from, void *to, u8 op)
24673 s32 raddr;
24674 } __packed *insn;
24675
24676 - insn = (struct __arch_relative_insn *)from;
24677 + insn = (struct __arch_relative_insn *)ktla_ktva(from);
24678 +
24679 + pax_open_kernel();
24680 insn->raddr = (s32)((long)(to) - ((long)(from) + 5));
24681 insn->op = op;
24682 + pax_close_kernel();
24683 }
24684
24685 /* Insert a jump instruction at address 'from', which jumps to address 'to'.*/
24686 @@ -164,7 +167,7 @@ int __kprobes can_boost(kprobe_opcode_t *opcodes)
24687 kprobe_opcode_t opcode;
24688 kprobe_opcode_t *orig_opcodes = opcodes;
24689
24690 - if (search_exception_tables((unsigned long)opcodes))
24691 + if (search_exception_tables(ktva_ktla((unsigned long)opcodes)))
24692 return 0; /* Page fault may occur on this address. */
24693
24694 retry:
24695 @@ -238,9 +241,9 @@ __recover_probed_insn(kprobe_opcode_t *buf, unsigned long addr)
24696 * for the first byte, we can recover the original instruction
24697 * from it and kp->opcode.
24698 */
24699 - memcpy(buf, kp->addr, MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
24700 + memcpy(buf, ktla_ktva(kp->addr), MAX_INSN_SIZE * sizeof(kprobe_opcode_t));
24701 buf[0] = kp->opcode;
24702 - return (unsigned long)buf;
24703 + return ktva_ktla((unsigned long)buf);
24704 }
24705
24706 /*
24707 @@ -332,7 +335,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
24708 /* Another subsystem puts a breakpoint, failed to recover */
24709 if (insn.opcode.bytes[0] == BREAKPOINT_INSTRUCTION)
24710 return 0;
24711 + pax_open_kernel();
24712 memcpy(dest, insn.kaddr, insn.length);
24713 + pax_close_kernel();
24714
24715 #ifdef CONFIG_X86_64
24716 if (insn_rip_relative(&insn)) {
24717 @@ -359,7 +364,9 @@ int __kprobes __copy_instruction(u8 *dest, u8 *src)
24718 return 0;
24719 }
24720 disp = (u8 *) dest + insn_offset_displacement(&insn);
24721 + pax_open_kernel();
24722 *(s32 *) disp = (s32) newdisp;
24723 + pax_close_kernel();
24724 }
24725 #endif
24726 return insn.length;
24727 @@ -498,7 +505,7 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
24728 * nor set current_kprobe, because it doesn't use single
24729 * stepping.
24730 */
24731 - regs->ip = (unsigned long)p->ainsn.insn;
24732 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
24733 preempt_enable_no_resched();
24734 return;
24735 }
24736 @@ -515,9 +522,9 @@ setup_singlestep(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *k
24737 regs->flags &= ~X86_EFLAGS_IF;
24738 /* single step inline if the instruction is an int3 */
24739 if (p->opcode == BREAKPOINT_INSTRUCTION)
24740 - regs->ip = (unsigned long)p->addr;
24741 + regs->ip = ktla_ktva((unsigned long)p->addr);
24742 else
24743 - regs->ip = (unsigned long)p->ainsn.insn;
24744 + regs->ip = ktva_ktla((unsigned long)p->ainsn.insn);
24745 }
24746
24747 /*
24748 @@ -596,7 +603,7 @@ static int __kprobes kprobe_handler(struct pt_regs *regs)
24749 setup_singlestep(p, regs, kcb, 0);
24750 return 1;
24751 }
24752 - } else if (*addr != BREAKPOINT_INSTRUCTION) {
24753 + } else if (*(kprobe_opcode_t *)ktla_ktva((unsigned long)addr) != BREAKPOINT_INSTRUCTION) {
24754 /*
24755 * The breakpoint instruction was removed right
24756 * after we hit it. Another cpu has removed
24757 @@ -642,6 +649,9 @@ static void __used __kprobes kretprobe_trampoline_holder(void)
24758 " movq %rax, 152(%rsp)\n"
24759 RESTORE_REGS_STRING
24760 " popfq\n"
24761 +#ifdef KERNEXEC_PLUGIN
24762 + " btsq $63,(%rsp)\n"
24763 +#endif
24764 #else
24765 " pushf\n"
24766 SAVE_REGS_STRING
24767 @@ -779,7 +789,7 @@ static void __kprobes
24768 resume_execution(struct kprobe *p, struct pt_regs *regs, struct kprobe_ctlblk *kcb)
24769 {
24770 unsigned long *tos = stack_addr(regs);
24771 - unsigned long copy_ip = (unsigned long)p->ainsn.insn;
24772 + unsigned long copy_ip = ktva_ktla((unsigned long)p->ainsn.insn);
24773 unsigned long orig_ip = (unsigned long)p->addr;
24774 kprobe_opcode_t *insn = p->ainsn.insn;
24775
24776 @@ -961,7 +971,7 @@ kprobe_exceptions_notify(struct notifier_block *self, unsigned long val, void *d
24777 struct die_args *args = data;
24778 int ret = NOTIFY_DONE;
24779
24780 - if (args->regs && user_mode_vm(args->regs))
24781 + if (args->regs && user_mode(args->regs))
24782 return ret;
24783
24784 switch (val) {
24785 diff --git a/arch/x86/kernel/kprobes/opt.c b/arch/x86/kernel/kprobes/opt.c
24786 index 898160b..758cde8 100644
24787 --- a/arch/x86/kernel/kprobes/opt.c
24788 +++ b/arch/x86/kernel/kprobes/opt.c
24789 @@ -79,6 +79,7 @@ found:
24790 /* Insert a move instruction which sets a pointer to eax/rdi (1st arg). */
24791 static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long val)
24792 {
24793 + pax_open_kernel();
24794 #ifdef CONFIG_X86_64
24795 *addr++ = 0x48;
24796 *addr++ = 0xbf;
24797 @@ -86,6 +87,7 @@ static void __kprobes synthesize_set_arg1(kprobe_opcode_t *addr, unsigned long v
24798 *addr++ = 0xb8;
24799 #endif
24800 *(unsigned long *)addr = val;
24801 + pax_close_kernel();
24802 }
24803
24804 asm (
24805 @@ -335,7 +337,7 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
24806 * Verify if the address gap is in 2GB range, because this uses
24807 * a relative jump.
24808 */
24809 - rel = (long)op->optinsn.insn - (long)op->kp.addr + RELATIVEJUMP_SIZE;
24810 + rel = (long)op->optinsn.insn - ktla_ktva((long)op->kp.addr) + RELATIVEJUMP_SIZE;
24811 if (abs(rel) > 0x7fffffff)
24812 return -ERANGE;
24813
24814 @@ -350,16 +352,18 @@ int __kprobes arch_prepare_optimized_kprobe(struct optimized_kprobe *op)
24815 op->optinsn.size = ret;
24816
24817 /* Copy arch-dep-instance from template */
24818 - memcpy(buf, &optprobe_template_entry, TMPL_END_IDX);
24819 + pax_open_kernel();
24820 + memcpy(buf, ktla_ktva(&optprobe_template_entry), TMPL_END_IDX);
24821 + pax_close_kernel();
24822
24823 /* Set probe information */
24824 synthesize_set_arg1(buf + TMPL_MOVE_IDX, (unsigned long)op);
24825
24826 /* Set probe function call */
24827 - synthesize_relcall(buf + TMPL_CALL_IDX, optimized_callback);
24828 + synthesize_relcall(ktva_ktla(buf) + TMPL_CALL_IDX, optimized_callback);
24829
24830 /* Set returning jmp instruction at the tail of out-of-line buffer */
24831 - synthesize_reljump(buf + TMPL_END_IDX + op->optinsn.size,
24832 + synthesize_reljump(ktva_ktla(buf) + TMPL_END_IDX + op->optinsn.size,
24833 (u8 *)op->kp.addr + op->optinsn.size);
24834
24835 flush_icache_range((unsigned long) buf,
24836 @@ -384,7 +388,7 @@ void __kprobes arch_optimize_kprobes(struct list_head *oplist)
24837 WARN_ON(kprobe_disabled(&op->kp));
24838
24839 /* Backup instructions which will be replaced by jump address */
24840 - memcpy(op->optinsn.copied_insn, op->kp.addr + INT3_SIZE,
24841 + memcpy(op->optinsn.copied_insn, ktla_ktva(op->kp.addr) + INT3_SIZE,
24842 RELATIVE_ADDR_SIZE);
24843
24844 insn_buf[0] = RELATIVEJUMP_OPCODE;
24845 @@ -433,7 +437,7 @@ setup_detour_execution(struct kprobe *p, struct pt_regs *regs, int reenter)
24846 /* This kprobe is really able to run optimized path. */
24847 op = container_of(p, struct optimized_kprobe, kp);
24848 /* Detour through copied instructions */
24849 - regs->ip = (unsigned long)op->optinsn.insn + TMPL_END_IDX;
24850 + regs->ip = ktva_ktla((unsigned long)op->optinsn.insn) + TMPL_END_IDX;
24851 if (!reenter)
24852 reset_current_kprobe();
24853 preempt_enable_no_resched();
24854 diff --git a/arch/x86/kernel/ldt.c b/arch/x86/kernel/ldt.c
24855 index ebc9873..1b9724b 100644
24856 --- a/arch/x86/kernel/ldt.c
24857 +++ b/arch/x86/kernel/ldt.c
24858 @@ -66,13 +66,13 @@ static int alloc_ldt(mm_context_t *pc, int mincount, int reload)
24859 if (reload) {
24860 #ifdef CONFIG_SMP
24861 preempt_disable();
24862 - load_LDT(pc);
24863 + load_LDT_nolock(pc);
24864 if (!cpumask_equal(mm_cpumask(current->mm),
24865 cpumask_of(smp_processor_id())))
24866 smp_call_function(flush_ldt, current->mm, 1);
24867 preempt_enable();
24868 #else
24869 - load_LDT(pc);
24870 + load_LDT_nolock(pc);
24871 #endif
24872 }
24873 if (oldsize) {
24874 @@ -94,7 +94,7 @@ static inline int copy_ldt(mm_context_t *new, mm_context_t *old)
24875 return err;
24876
24877 for (i = 0; i < old->size; i++)
24878 - write_ldt_entry(new->ldt, i, old->ldt + i * LDT_ENTRY_SIZE);
24879 + write_ldt_entry(new->ldt, i, old->ldt + i);
24880 return 0;
24881 }
24882
24883 @@ -115,6 +115,24 @@ int init_new_context(struct task_struct *tsk, struct mm_struct *mm)
24884 retval = copy_ldt(&mm->context, &old_mm->context);
24885 mutex_unlock(&old_mm->context.lock);
24886 }
24887 +
24888 + if (tsk == current) {
24889 + mm->context.vdso = 0;
24890 +
24891 +#ifdef CONFIG_X86_32
24892 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
24893 + mm->context.user_cs_base = 0UL;
24894 + mm->context.user_cs_limit = ~0UL;
24895 +
24896 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_SMP)
24897 + cpus_clear(mm->context.cpu_user_cs_mask);
24898 +#endif
24899 +
24900 +#endif
24901 +#endif
24902 +
24903 + }
24904 +
24905 return retval;
24906 }
24907
24908 @@ -229,6 +247,13 @@ static int write_ldt(void __user *ptr, unsigned long bytecount, int oldmode)
24909 }
24910 }
24911
24912 +#ifdef CONFIG_PAX_SEGMEXEC
24913 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (ldt_info.contents & MODIFY_LDT_CONTENTS_CODE)) {
24914 + error = -EINVAL;
24915 + goto out_unlock;
24916 + }
24917 +#endif
24918 +
24919 fill_ldt(&ldt, &ldt_info);
24920 if (oldmode)
24921 ldt.avl = 0;
24922 diff --git a/arch/x86/kernel/machine_kexec_32.c b/arch/x86/kernel/machine_kexec_32.c
24923 index 5b19e4d..6476a76 100644
24924 --- a/arch/x86/kernel/machine_kexec_32.c
24925 +++ b/arch/x86/kernel/machine_kexec_32.c
24926 @@ -26,7 +26,7 @@
24927 #include <asm/cacheflush.h>
24928 #include <asm/debugreg.h>
24929
24930 -static void set_idt(void *newidt, __u16 limit)
24931 +static void set_idt(struct desc_struct *newidt, __u16 limit)
24932 {
24933 struct desc_ptr curidt;
24934
24935 @@ -38,7 +38,7 @@ static void set_idt(void *newidt, __u16 limit)
24936 }
24937
24938
24939 -static void set_gdt(void *newgdt, __u16 limit)
24940 +static void set_gdt(struct desc_struct *newgdt, __u16 limit)
24941 {
24942 struct desc_ptr curgdt;
24943
24944 @@ -216,7 +216,7 @@ void machine_kexec(struct kimage *image)
24945 }
24946
24947 control_page = page_address(image->control_code_page);
24948 - memcpy(control_page, relocate_kernel, KEXEC_CONTROL_CODE_MAX_SIZE);
24949 + memcpy(control_page, (void *)ktla_ktva((unsigned long)relocate_kernel), KEXEC_CONTROL_CODE_MAX_SIZE);
24950
24951 relocate_kernel_ptr = control_page;
24952 page_list[PA_CONTROL_PAGE] = __pa(control_page);
24953 diff --git a/arch/x86/kernel/microcode_core.c b/arch/x86/kernel/microcode_core.c
24954 index 15c9876..0a43909 100644
24955 --- a/arch/x86/kernel/microcode_core.c
24956 +++ b/arch/x86/kernel/microcode_core.c
24957 @@ -513,7 +513,7 @@ mc_cpu_callback(struct notifier_block *nb, unsigned long action, void *hcpu)
24958 return NOTIFY_OK;
24959 }
24960
24961 -static struct notifier_block __refdata mc_cpu_notifier = {
24962 +static struct notifier_block mc_cpu_notifier = {
24963 .notifier_call = mc_cpu_callback,
24964 };
24965
24966 diff --git a/arch/x86/kernel/microcode_intel.c b/arch/x86/kernel/microcode_intel.c
24967 index 5fb2ceb..3ae90bb 100644
24968 --- a/arch/x86/kernel/microcode_intel.c
24969 +++ b/arch/x86/kernel/microcode_intel.c
24970 @@ -293,13 +293,13 @@ static enum ucode_state request_microcode_fw(int cpu, struct device *device,
24971
24972 static int get_ucode_user(void *to, const void *from, size_t n)
24973 {
24974 - return copy_from_user(to, from, n);
24975 + return copy_from_user(to, (const void __force_user *)from, n);
24976 }
24977
24978 static enum ucode_state
24979 request_microcode_user(int cpu, const void __user *buf, size_t size)
24980 {
24981 - return generic_load_microcode(cpu, (void *)buf, size, &get_ucode_user);
24982 + return generic_load_microcode(cpu, (__force_kernel void *)buf, size, &get_ucode_user);
24983 }
24984
24985 static void microcode_fini_cpu(int cpu)
24986 diff --git a/arch/x86/kernel/module.c b/arch/x86/kernel/module.c
24987 index 18be189..4a9fe40 100644
24988 --- a/arch/x86/kernel/module.c
24989 +++ b/arch/x86/kernel/module.c
24990 @@ -43,15 +43,60 @@ do { \
24991 } while (0)
24992 #endif
24993
24994 -void *module_alloc(unsigned long size)
24995 +static inline void *__module_alloc(unsigned long size, pgprot_t prot)
24996 {
24997 - if (PAGE_ALIGN(size) > MODULES_LEN)
24998 + if (!size || PAGE_ALIGN(size) > MODULES_LEN)
24999 return NULL;
25000 return __vmalloc_node_range(size, 1, MODULES_VADDR, MODULES_END,
25001 - GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
25002 + GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, prot,
25003 NUMA_NO_NODE, __builtin_return_address(0));
25004 }
25005
25006 +void *module_alloc(unsigned long size)
25007 +{
25008 +
25009 +#ifdef CONFIG_PAX_KERNEXEC
25010 + return __module_alloc(size, PAGE_KERNEL);
25011 +#else
25012 + return __module_alloc(size, PAGE_KERNEL_EXEC);
25013 +#endif
25014 +
25015 +}
25016 +
25017 +#ifdef CONFIG_PAX_KERNEXEC
25018 +#ifdef CONFIG_X86_32
25019 +void *module_alloc_exec(unsigned long size)
25020 +{
25021 + struct vm_struct *area;
25022 +
25023 + if (size == 0)
25024 + return NULL;
25025 +
25026 + area = __get_vm_area(size, VM_ALLOC, (unsigned long)&MODULES_EXEC_VADDR, (unsigned long)&MODULES_EXEC_END);
25027 + return area ? area->addr : NULL;
25028 +}
25029 +EXPORT_SYMBOL(module_alloc_exec);
25030 +
25031 +void module_free_exec(struct module *mod, void *module_region)
25032 +{
25033 + vunmap(module_region);
25034 +}
25035 +EXPORT_SYMBOL(module_free_exec);
25036 +#else
25037 +void module_free_exec(struct module *mod, void *module_region)
25038 +{
25039 + module_free(mod, module_region);
25040 +}
25041 +EXPORT_SYMBOL(module_free_exec);
25042 +
25043 +void *module_alloc_exec(unsigned long size)
25044 +{
25045 + return __module_alloc(size, PAGE_KERNEL_RX);
25046 +}
25047 +EXPORT_SYMBOL(module_alloc_exec);
25048 +#endif
25049 +#endif
25050 +
25051 #ifdef CONFIG_X86_32
25052 int apply_relocate(Elf32_Shdr *sechdrs,
25053 const char *strtab,
25054 @@ -62,14 +107,16 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25055 unsigned int i;
25056 Elf32_Rel *rel = (void *)sechdrs[relsec].sh_addr;
25057 Elf32_Sym *sym;
25058 - uint32_t *location;
25059 + uint32_t *plocation, location;
25060
25061 DEBUGP("Applying relocate section %u to %u\n",
25062 relsec, sechdrs[relsec].sh_info);
25063 for (i = 0; i < sechdrs[relsec].sh_size / sizeof(*rel); i++) {
25064 /* This is where to make the change */
25065 - location = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr
25066 - + rel[i].r_offset;
25067 + plocation = (void *)sechdrs[sechdrs[relsec].sh_info].sh_addr + rel[i].r_offset;
25068 + location = (uint32_t)plocation;
25069 + if (sechdrs[sechdrs[relsec].sh_info].sh_flags & SHF_EXECINSTR)
25070 + plocation = ktla_ktva((void *)plocation);
25071 /* This is the symbol it is referring to. Note that all
25072 undefined symbols have been resolved. */
25073 sym = (Elf32_Sym *)sechdrs[symindex].sh_addr
25074 @@ -78,11 +125,15 @@ int apply_relocate(Elf32_Shdr *sechdrs,
25075 switch (ELF32_R_TYPE(rel[i].r_info)) {
25076 case R_386_32:
25077 /* We add the value into the location given */
25078 - *location += sym->st_value;
25079 + pax_open_kernel();
25080 + *plocation += sym->st_value;
25081 + pax_close_kernel();
25082 break;
25083 case R_386_PC32:
25084 /* Add the value, subtract its position */
25085 - *location += sym->st_value - (uint32_t)location;
25086 + pax_open_kernel();
25087 + *plocation += sym->st_value - location;
25088 + pax_close_kernel();
25089 break;
25090 default:
25091 pr_err("%s: Unknown relocation: %u\n",
25092 @@ -127,21 +178,30 @@ int apply_relocate_add(Elf64_Shdr *sechdrs,
25093 case R_X86_64_NONE:
25094 break;
25095 case R_X86_64_64:
25096 + pax_open_kernel();
25097 *(u64 *)loc = val;
25098 + pax_close_kernel();
25099 break;
25100 case R_X86_64_32:
25101 + pax_open_kernel();
25102 *(u32 *)loc = val;
25103 + pax_close_kernel();
25104 if (val != *(u32 *)loc)
25105 goto overflow;
25106 break;
25107 case R_X86_64_32S:
25108 + pax_open_kernel();
25109 *(s32 *)loc = val;
25110 + pax_close_kernel();
25111 if ((s64)val != *(s32 *)loc)
25112 goto overflow;
25113 break;
25114 case R_X86_64_PC32:
25115 val -= (u64)loc;
25116 + pax_open_kernel();
25117 *(u32 *)loc = val;
25118 + pax_close_kernel();
25119 +
25120 #if 0
25121 if ((s64)val != *(s32 *)loc)
25122 goto overflow;
25123 diff --git a/arch/x86/kernel/msr.c b/arch/x86/kernel/msr.c
25124 index 05266b5..3432443 100644
25125 --- a/arch/x86/kernel/msr.c
25126 +++ b/arch/x86/kernel/msr.c
25127 @@ -37,6 +37,7 @@
25128 #include <linux/notifier.h>
25129 #include <linux/uaccess.h>
25130 #include <linux/gfp.h>
25131 +#include <linux/grsecurity.h>
25132
25133 #include <asm/processor.h>
25134 #include <asm/msr.h>
25135 @@ -103,6 +104,11 @@ static ssize_t msr_write(struct file *file, const char __user *buf,
25136 int err = 0;
25137 ssize_t bytes = 0;
25138
25139 +#ifdef CONFIG_GRKERNSEC_KMEM
25140 + gr_handle_msr_write();
25141 + return -EPERM;
25142 +#endif
25143 +
25144 if (count % 8)
25145 return -EINVAL; /* Invalid chunk size */
25146
25147 @@ -150,6 +156,10 @@ static long msr_ioctl(struct file *file, unsigned int ioc, unsigned long arg)
25148 err = -EBADF;
25149 break;
25150 }
25151 +#ifdef CONFIG_GRKERNSEC_KMEM
25152 + gr_handle_msr_write();
25153 + return -EPERM;
25154 +#endif
25155 if (copy_from_user(&regs, uregs, sizeof regs)) {
25156 err = -EFAULT;
25157 break;
25158 @@ -233,7 +243,7 @@ static int msr_class_cpu_callback(struct notifier_block *nfb,
25159 return notifier_from_errno(err);
25160 }
25161
25162 -static struct notifier_block __refdata msr_class_cpu_notifier = {
25163 +static struct notifier_block msr_class_cpu_notifier = {
25164 .notifier_call = msr_class_cpu_callback,
25165 };
25166
25167 diff --git a/arch/x86/kernel/nmi.c b/arch/x86/kernel/nmi.c
25168 index 6fcb49c..5b3f4ff 100644
25169 --- a/arch/x86/kernel/nmi.c
25170 +++ b/arch/x86/kernel/nmi.c
25171 @@ -138,7 +138,7 @@ static int __kprobes nmi_handle(unsigned int type, struct pt_regs *regs, bool b2
25172 return handled;
25173 }
25174
25175 -int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25176 +int __register_nmi_handler(unsigned int type, const struct nmiaction *action)
25177 {
25178 struct nmi_desc *desc = nmi_to_desc(type);
25179 unsigned long flags;
25180 @@ -162,9 +162,9 @@ int __register_nmi_handler(unsigned int type, struct nmiaction *action)
25181 * event confuses some handlers (kdump uses this flag)
25182 */
25183 if (action->flags & NMI_FLAG_FIRST)
25184 - list_add_rcu(&action->list, &desc->head);
25185 + pax_list_add_rcu((struct list_head *)&action->list, &desc->head);
25186 else
25187 - list_add_tail_rcu(&action->list, &desc->head);
25188 + pax_list_add_tail_rcu((struct list_head *)&action->list, &desc->head);
25189
25190 spin_unlock_irqrestore(&desc->lock, flags);
25191 return 0;
25192 @@ -187,7 +187,7 @@ void unregister_nmi_handler(unsigned int type, const char *name)
25193 if (!strcmp(n->name, name)) {
25194 WARN(in_nmi(),
25195 "Trying to free NMI (%s) from NMI context!\n", n->name);
25196 - list_del_rcu(&n->list);
25197 + pax_list_del_rcu((struct list_head *)&n->list);
25198 break;
25199 }
25200 }
25201 @@ -512,6 +512,17 @@ static inline void nmi_nesting_postprocess(void)
25202 dotraplinkage notrace __kprobes void
25203 do_nmi(struct pt_regs *regs, long error_code)
25204 {
25205 +
25206 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
25207 + if (!user_mode(regs)) {
25208 + unsigned long cs = regs->cs & 0xFFFF;
25209 + unsigned long ip = ktva_ktla(regs->ip);
25210 +
25211 + if ((cs == __KERNEL_CS || cs == __KERNEXEC_KERNEL_CS) && ip <= (unsigned long)_etext)
25212 + regs->ip = ip;
25213 + }
25214 +#endif
25215 +
25216 nmi_nesting_preprocess(regs);
25217
25218 nmi_enter();
25219 diff --git a/arch/x86/kernel/nmi_selftest.c b/arch/x86/kernel/nmi_selftest.c
25220 index 6d9582e..f746287 100644
25221 --- a/arch/x86/kernel/nmi_selftest.c
25222 +++ b/arch/x86/kernel/nmi_selftest.c
25223 @@ -43,7 +43,7 @@ static void __init init_nmi_testsuite(void)
25224 {
25225 /* trap all the unknown NMIs we may generate */
25226 register_nmi_handler(NMI_UNKNOWN, nmi_unk_cb, 0, "nmi_selftest_unk",
25227 - __initdata);
25228 + __initconst);
25229 }
25230
25231 static void __init cleanup_nmi_testsuite(void)
25232 @@ -66,7 +66,7 @@ static void __init test_nmi_ipi(struct cpumask *mask)
25233 unsigned long timeout;
25234
25235 if (register_nmi_handler(NMI_LOCAL, test_nmi_ipi_callback,
25236 - NMI_FLAG_FIRST, "nmi_selftest", __initdata)) {
25237 + NMI_FLAG_FIRST, "nmi_selftest", __initconst)) {
25238 nmi_fail = FAILURE;
25239 return;
25240 }
25241 diff --git a/arch/x86/kernel/paravirt-spinlocks.c b/arch/x86/kernel/paravirt-spinlocks.c
25242 index bbb6c73..24a58ef 100644
25243 --- a/arch/x86/kernel/paravirt-spinlocks.c
25244 +++ b/arch/x86/kernel/paravirt-spinlocks.c
25245 @@ -8,7 +8,7 @@
25246
25247 #include <asm/paravirt.h>
25248
25249 -struct pv_lock_ops pv_lock_ops = {
25250 +struct pv_lock_ops pv_lock_ops __read_only = {
25251 #ifdef CONFIG_SMP
25252 .lock_spinning = __PV_IS_CALLEE_SAVE(paravirt_nop),
25253 .unlock_kick = paravirt_nop,
25254 diff --git a/arch/x86/kernel/paravirt.c b/arch/x86/kernel/paravirt.c
25255 index 1b10af8..0b58cbc 100644
25256 --- a/arch/x86/kernel/paravirt.c
25257 +++ b/arch/x86/kernel/paravirt.c
25258 @@ -55,6 +55,9 @@ u64 _paravirt_ident_64(u64 x)
25259 {
25260 return x;
25261 }
25262 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25263 +PV_CALLEE_SAVE_REGS_THUNK(_paravirt_ident_64);
25264 +#endif
25265
25266 void __init default_banner(void)
25267 {
25268 @@ -142,15 +145,19 @@ unsigned paravirt_patch_default(u8 type, u16 clobbers, void *insnbuf,
25269 if (opfunc == NULL)
25270 /* If there's no function, patch it with a ud2a (BUG) */
25271 ret = paravirt_patch_insns(insnbuf, len, ud2a, ud2a+sizeof(ud2a));
25272 - else if (opfunc == _paravirt_nop)
25273 + else if (opfunc == (void *)_paravirt_nop)
25274 /* If the operation is a nop, then nop the callsite */
25275 ret = paravirt_patch_nop();
25276
25277 /* identity functions just return their single argument */
25278 - else if (opfunc == _paravirt_ident_32)
25279 + else if (opfunc == (void *)_paravirt_ident_32)
25280 ret = paravirt_patch_ident_32(insnbuf, len);
25281 - else if (opfunc == _paravirt_ident_64)
25282 + else if (opfunc == (void *)_paravirt_ident_64)
25283 ret = paravirt_patch_ident_64(insnbuf, len);
25284 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
25285 + else if (opfunc == (void *)__raw_callee_save__paravirt_ident_64)
25286 + ret = paravirt_patch_ident_64(insnbuf, len);
25287 +#endif
25288
25289 else if (type == PARAVIRT_PATCH(pv_cpu_ops.iret) ||
25290 type == PARAVIRT_PATCH(pv_cpu_ops.irq_enable_sysexit) ||
25291 @@ -175,7 +182,7 @@ unsigned paravirt_patch_insns(void *insnbuf, unsigned len,
25292 if (insn_len > len || start == NULL)
25293 insn_len = len;
25294 else
25295 - memcpy(insnbuf, start, insn_len);
25296 + memcpy(insnbuf, ktla_ktva(start), insn_len);
25297
25298 return insn_len;
25299 }
25300 @@ -299,7 +306,7 @@ enum paravirt_lazy_mode paravirt_get_lazy_mode(void)
25301 return this_cpu_read(paravirt_lazy_mode);
25302 }
25303
25304 -struct pv_info pv_info = {
25305 +struct pv_info pv_info __read_only = {
25306 .name = "bare hardware",
25307 .paravirt_enabled = 0,
25308 .kernel_rpl = 0,
25309 @@ -310,16 +317,16 @@ struct pv_info pv_info = {
25310 #endif
25311 };
25312
25313 -struct pv_init_ops pv_init_ops = {
25314 +struct pv_init_ops pv_init_ops __read_only = {
25315 .patch = native_patch,
25316 };
25317
25318 -struct pv_time_ops pv_time_ops = {
25319 +struct pv_time_ops pv_time_ops __read_only = {
25320 .sched_clock = native_sched_clock,
25321 .steal_clock = native_steal_clock,
25322 };
25323
25324 -__visible struct pv_irq_ops pv_irq_ops = {
25325 +__visible struct pv_irq_ops pv_irq_ops __read_only = {
25326 .save_fl = __PV_IS_CALLEE_SAVE(native_save_fl),
25327 .restore_fl = __PV_IS_CALLEE_SAVE(native_restore_fl),
25328 .irq_disable = __PV_IS_CALLEE_SAVE(native_irq_disable),
25329 @@ -331,7 +338,7 @@ __visible struct pv_irq_ops pv_irq_ops = {
25330 #endif
25331 };
25332
25333 -__visible struct pv_cpu_ops pv_cpu_ops = {
25334 +__visible struct pv_cpu_ops pv_cpu_ops __read_only = {
25335 .cpuid = native_cpuid,
25336 .get_debugreg = native_get_debugreg,
25337 .set_debugreg = native_set_debugreg,
25338 @@ -389,21 +396,26 @@ __visible struct pv_cpu_ops pv_cpu_ops = {
25339 .end_context_switch = paravirt_nop,
25340 };
25341
25342 -struct pv_apic_ops pv_apic_ops = {
25343 +struct pv_apic_ops pv_apic_ops __read_only= {
25344 #ifdef CONFIG_X86_LOCAL_APIC
25345 .startup_ipi_hook = paravirt_nop,
25346 #endif
25347 };
25348
25349 -#if defined(CONFIG_X86_32) && !defined(CONFIG_X86_PAE)
25350 +#ifdef CONFIG_X86_32
25351 +#ifdef CONFIG_X86_PAE
25352 +/* 64-bit pagetable entries */
25353 +#define PTE_IDENT PV_CALLEE_SAVE(_paravirt_ident_64)
25354 +#else
25355 /* 32-bit pagetable entries */
25356 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_32)
25357 +#endif
25358 #else
25359 /* 64-bit pagetable entries */
25360 #define PTE_IDENT __PV_IS_CALLEE_SAVE(_paravirt_ident_64)
25361 #endif
25362
25363 -struct pv_mmu_ops pv_mmu_ops = {
25364 +struct pv_mmu_ops pv_mmu_ops __read_only = {
25365
25366 .read_cr2 = native_read_cr2,
25367 .write_cr2 = native_write_cr2,
25368 @@ -453,6 +465,7 @@ struct pv_mmu_ops pv_mmu_ops = {
25369 .make_pud = PTE_IDENT,
25370
25371 .set_pgd = native_set_pgd,
25372 + .set_pgd_batched = native_set_pgd_batched,
25373 #endif
25374 #endif /* PAGETABLE_LEVELS >= 3 */
25375
25376 @@ -473,6 +486,12 @@ struct pv_mmu_ops pv_mmu_ops = {
25377 },
25378
25379 .set_fixmap = native_set_fixmap,
25380 +
25381 +#ifdef CONFIG_PAX_KERNEXEC
25382 + .pax_open_kernel = native_pax_open_kernel,
25383 + .pax_close_kernel = native_pax_close_kernel,
25384 +#endif
25385 +
25386 };
25387
25388 EXPORT_SYMBOL_GPL(pv_time_ops);
25389 diff --git a/arch/x86/kernel/pci-calgary_64.c b/arch/x86/kernel/pci-calgary_64.c
25390 index 299d493..2ccb0ee 100644
25391 --- a/arch/x86/kernel/pci-calgary_64.c
25392 +++ b/arch/x86/kernel/pci-calgary_64.c
25393 @@ -1339,7 +1339,7 @@ static void __init get_tce_space_from_tar(void)
25394 tce_space = be64_to_cpu(readq(target));
25395 tce_space = tce_space & TAR_SW_BITS;
25396
25397 - tce_space = tce_space & (~specified_table_size);
25398 + tce_space = tce_space & (~(unsigned long)specified_table_size);
25399 info->tce_space = (u64 *)__va(tce_space);
25400 }
25401 }
25402 diff --git a/arch/x86/kernel/pci-iommu_table.c b/arch/x86/kernel/pci-iommu_table.c
25403 index 35ccf75..7a15747 100644
25404 --- a/arch/x86/kernel/pci-iommu_table.c
25405 +++ b/arch/x86/kernel/pci-iommu_table.c
25406 @@ -2,7 +2,7 @@
25407 #include <asm/iommu_table.h>
25408 #include <linux/string.h>
25409 #include <linux/kallsyms.h>
25410 -
25411 +#include <linux/sched.h>
25412
25413 #define DEBUG 1
25414
25415 diff --git a/arch/x86/kernel/pci-swiotlb.c b/arch/x86/kernel/pci-swiotlb.c
25416 index 6c483ba..d10ce2f 100644
25417 --- a/arch/x86/kernel/pci-swiotlb.c
25418 +++ b/arch/x86/kernel/pci-swiotlb.c
25419 @@ -32,7 +32,7 @@ static void x86_swiotlb_free_coherent(struct device *dev, size_t size,
25420 void *vaddr, dma_addr_t dma_addr,
25421 struct dma_attrs *attrs)
25422 {
25423 - swiotlb_free_coherent(dev, size, vaddr, dma_addr);
25424 + swiotlb_free_coherent(dev, size, vaddr, dma_addr, attrs);
25425 }
25426
25427 static struct dma_map_ops swiotlb_dma_ops = {
25428 diff --git a/arch/x86/kernel/preempt.S b/arch/x86/kernel/preempt.S
25429 index ca7f0d5..8996469 100644
25430 --- a/arch/x86/kernel/preempt.S
25431 +++ b/arch/x86/kernel/preempt.S
25432 @@ -3,12 +3,14 @@
25433 #include <asm/dwarf2.h>
25434 #include <asm/asm.h>
25435 #include <asm/calling.h>
25436 +#include <asm/alternative-asm.h>
25437
25438 ENTRY(___preempt_schedule)
25439 CFI_STARTPROC
25440 SAVE_ALL
25441 call preempt_schedule
25442 RESTORE_ALL
25443 + pax_force_retaddr
25444 ret
25445 CFI_ENDPROC
25446
25447 @@ -19,6 +21,7 @@ ENTRY(___preempt_schedule_context)
25448 SAVE_ALL
25449 call preempt_schedule_context
25450 RESTORE_ALL
25451 + pax_force_retaddr
25452 ret
25453 CFI_ENDPROC
25454
25455 diff --git a/arch/x86/kernel/process.c b/arch/x86/kernel/process.c
25456 index 3fb8d95..254dc51 100644
25457 --- a/arch/x86/kernel/process.c
25458 +++ b/arch/x86/kernel/process.c
25459 @@ -36,7 +36,8 @@
25460 * section. Since TSS's are completely CPU-local, we want them
25461 * on exact cacheline boundaries, to eliminate cacheline ping-pong.
25462 */
25463 -__visible DEFINE_PER_CPU_SHARED_ALIGNED(struct tss_struct, init_tss) = INIT_TSS;
25464 +struct tss_struct init_tss[NR_CPUS] __visible ____cacheline_internodealigned_in_smp = { [0 ... NR_CPUS-1] = INIT_TSS };
25465 +EXPORT_SYMBOL(init_tss);
25466
25467 #ifdef CONFIG_X86_64
25468 static DEFINE_PER_CPU(unsigned char, is_idle);
25469 @@ -92,7 +93,7 @@ void arch_task_cache_init(void)
25470 task_xstate_cachep =
25471 kmem_cache_create("task_xstate", xstate_size,
25472 __alignof__(union thread_xstate),
25473 - SLAB_PANIC | SLAB_NOTRACK, NULL);
25474 + SLAB_PANIC | SLAB_NOTRACK | SLAB_USERCOPY, NULL);
25475 }
25476
25477 /*
25478 @@ -105,7 +106,7 @@ void exit_thread(void)
25479 unsigned long *bp = t->io_bitmap_ptr;
25480
25481 if (bp) {
25482 - struct tss_struct *tss = &per_cpu(init_tss, get_cpu());
25483 + struct tss_struct *tss = init_tss + get_cpu();
25484
25485 t->io_bitmap_ptr = NULL;
25486 clear_thread_flag(TIF_IO_BITMAP);
25487 @@ -125,6 +126,9 @@ void flush_thread(void)
25488 {
25489 struct task_struct *tsk = current;
25490
25491 +#if defined(CONFIG_X86_32) && !defined(CONFIG_CC_STACKPROTECTOR) && !defined(CONFIG_PAX_MEMORY_UDEREF)
25492 + loadsegment(gs, 0);
25493 +#endif
25494 flush_ptrace_hw_breakpoint(tsk);
25495 memset(tsk->thread.tls_array, 0, sizeof(tsk->thread.tls_array));
25496 drop_init_fpu(tsk);
25497 @@ -271,7 +275,7 @@ static void __exit_idle(void)
25498 void exit_idle(void)
25499 {
25500 /* idle loop has pid 0 */
25501 - if (current->pid)
25502 + if (task_pid_nr(current))
25503 return;
25504 __exit_idle();
25505 }
25506 @@ -327,7 +331,7 @@ bool xen_set_default_idle(void)
25507 return ret;
25508 }
25509 #endif
25510 -void stop_this_cpu(void *dummy)
25511 +__noreturn void stop_this_cpu(void *dummy)
25512 {
25513 local_irq_disable();
25514 /*
25515 @@ -456,16 +460,37 @@ static int __init idle_setup(char *str)
25516 }
25517 early_param("idle", idle_setup);
25518
25519 -unsigned long arch_align_stack(unsigned long sp)
25520 +#ifdef CONFIG_PAX_RANDKSTACK
25521 +void pax_randomize_kstack(struct pt_regs *regs)
25522 {
25523 - if (!(current->personality & ADDR_NO_RANDOMIZE) && randomize_va_space)
25524 - sp -= get_random_int() % 8192;
25525 - return sp & ~0xf;
25526 -}
25527 + struct thread_struct *thread = &current->thread;
25528 + unsigned long time;
25529
25530 -unsigned long arch_randomize_brk(struct mm_struct *mm)
25531 -{
25532 - unsigned long range_end = mm->brk + 0x02000000;
25533 - return randomize_range(mm->brk, range_end, 0) ? : mm->brk;
25534 -}
25535 + if (!randomize_va_space)
25536 + return;
25537 +
25538 + if (v8086_mode(regs))
25539 + return;
25540
25541 + rdtscl(time);
25542 +
25543 + /* P4 seems to return a 0 LSB, ignore it */
25544 +#ifdef CONFIG_MPENTIUM4
25545 + time &= 0x3EUL;
25546 + time <<= 2;
25547 +#elif defined(CONFIG_X86_64)
25548 + time &= 0xFUL;
25549 + time <<= 4;
25550 +#else
25551 + time &= 0x1FUL;
25552 + time <<= 3;
25553 +#endif
25554 +
25555 + thread->sp0 ^= time;
25556 + load_sp0(init_tss + smp_processor_id(), thread);
25557 +
25558 +#ifdef CONFIG_X86_64
25559 + this_cpu_write(kernel_stack, thread->sp0);
25560 +#endif
25561 +}
25562 +#endif
25563 diff --git a/arch/x86/kernel/process_32.c b/arch/x86/kernel/process_32.c
25564 index 6f1236c..fd448d4 100644
25565 --- a/arch/x86/kernel/process_32.c
25566 +++ b/arch/x86/kernel/process_32.c
25567 @@ -65,6 +65,7 @@ asmlinkage void ret_from_kernel_thread(void) __asm__("ret_from_kernel_thread");
25568 unsigned long thread_saved_pc(struct task_struct *tsk)
25569 {
25570 return ((unsigned long *)tsk->thread.sp)[3];
25571 +//XXX return tsk->thread.eip;
25572 }
25573
25574 void __show_regs(struct pt_regs *regs, int all)
25575 @@ -74,19 +75,18 @@ void __show_regs(struct pt_regs *regs, int all)
25576 unsigned long sp;
25577 unsigned short ss, gs;
25578
25579 - if (user_mode_vm(regs)) {
25580 + if (user_mode(regs)) {
25581 sp = regs->sp;
25582 ss = regs->ss & 0xffff;
25583 - gs = get_user_gs(regs);
25584 } else {
25585 sp = kernel_stack_pointer(regs);
25586 savesegment(ss, ss);
25587 - savesegment(gs, gs);
25588 }
25589 + gs = get_user_gs(regs);
25590
25591 printk(KERN_DEFAULT "EIP: %04x:[<%08lx>] EFLAGS: %08lx CPU: %d\n",
25592 (u16)regs->cs, regs->ip, regs->flags,
25593 - smp_processor_id());
25594 + raw_smp_processor_id());
25595 print_symbol("EIP is at %s\n", regs->ip);
25596
25597 printk(KERN_DEFAULT "EAX: %08lx EBX: %08lx ECX: %08lx EDX: %08lx\n",
25598 @@ -133,20 +133,21 @@ void release_thread(struct task_struct *dead_task)
25599 int copy_thread(unsigned long clone_flags, unsigned long sp,
25600 unsigned long arg, struct task_struct *p)
25601 {
25602 - struct pt_regs *childregs = task_pt_regs(p);
25603 + struct pt_regs *childregs = task_stack_page(p) + THREAD_SIZE - sizeof(struct pt_regs) - 8;
25604 struct task_struct *tsk;
25605 int err;
25606
25607 p->thread.sp = (unsigned long) childregs;
25608 p->thread.sp0 = (unsigned long) (childregs+1);
25609 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
25610
25611 if (unlikely(p->flags & PF_KTHREAD)) {
25612 /* kernel thread */
25613 memset(childregs, 0, sizeof(struct pt_regs));
25614 p->thread.ip = (unsigned long) ret_from_kernel_thread;
25615 - task_user_gs(p) = __KERNEL_STACK_CANARY;
25616 - childregs->ds = __USER_DS;
25617 - childregs->es = __USER_DS;
25618 + savesegment(gs, childregs->gs);
25619 + childregs->ds = __KERNEL_DS;
25620 + childregs->es = __KERNEL_DS;
25621 childregs->fs = __KERNEL_PERCPU;
25622 childregs->bx = sp; /* function */
25623 childregs->bp = arg;
25624 @@ -253,7 +254,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25625 struct thread_struct *prev = &prev_p->thread,
25626 *next = &next_p->thread;
25627 int cpu = smp_processor_id();
25628 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
25629 + struct tss_struct *tss = init_tss + cpu;
25630 fpu_switch_t fpu;
25631
25632 /* never put a printk in __switch_to... printk() calls wake_up*() indirectly */
25633 @@ -277,6 +278,10 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25634 */
25635 lazy_save_gs(prev->gs);
25636
25637 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25638 + __set_fs(task_thread_info(next_p)->addr_limit);
25639 +#endif
25640 +
25641 /*
25642 * Load the per-thread Thread-Local Storage descriptor.
25643 */
25644 @@ -315,6 +320,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25645 */
25646 arch_end_context_switch(next_p);
25647
25648 + this_cpu_write(current_task, next_p);
25649 + this_cpu_write(current_tinfo, &next_p->tinfo);
25650 +
25651 /*
25652 * Restore %gs if needed (which is common)
25653 */
25654 @@ -323,8 +331,6 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25655
25656 switch_fpu_finish(next_p, fpu);
25657
25658 - this_cpu_write(current_task, next_p);
25659 -
25660 return prev_p;
25661 }
25662
25663 @@ -354,4 +360,3 @@ unsigned long get_wchan(struct task_struct *p)
25664 } while (count++ < 16);
25665 return 0;
25666 }
25667 -
25668 diff --git a/arch/x86/kernel/process_64.c b/arch/x86/kernel/process_64.c
25669 index 9c0280f..5bbb1c0 100644
25670 --- a/arch/x86/kernel/process_64.c
25671 +++ b/arch/x86/kernel/process_64.c
25672 @@ -158,10 +158,11 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
25673 struct pt_regs *childregs;
25674 struct task_struct *me = current;
25675
25676 - p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE;
25677 + p->thread.sp0 = (unsigned long)task_stack_page(p) + THREAD_SIZE - 16;
25678 childregs = task_pt_regs(p);
25679 p->thread.sp = (unsigned long) childregs;
25680 p->thread.usersp = me->thread.usersp;
25681 + p->tinfo.lowest_stack = (unsigned long)task_stack_page(p);
25682 set_tsk_thread_flag(p, TIF_FORK);
25683 p->thread.fpu_counter = 0;
25684 p->thread.io_bitmap_ptr = NULL;
25685 @@ -172,6 +173,8 @@ int copy_thread(unsigned long clone_flags, unsigned long sp,
25686 p->thread.fs = p->thread.fsindex ? 0 : me->thread.fs;
25687 savesegment(es, p->thread.es);
25688 savesegment(ds, p->thread.ds);
25689 + savesegment(ss, p->thread.ss);
25690 + BUG_ON(p->thread.ss == __UDEREF_KERNEL_DS);
25691 memset(p->thread.ptrace_bps, 0, sizeof(p->thread.ptrace_bps));
25692
25693 if (unlikely(p->flags & PF_KTHREAD)) {
25694 @@ -280,7 +283,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25695 struct thread_struct *prev = &prev_p->thread;
25696 struct thread_struct *next = &next_p->thread;
25697 int cpu = smp_processor_id();
25698 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
25699 + struct tss_struct *tss = init_tss + cpu;
25700 unsigned fsindex, gsindex;
25701 fpu_switch_t fpu;
25702
25703 @@ -303,6 +306,9 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25704 if (unlikely(next->ds | prev->ds))
25705 loadsegment(ds, next->ds);
25706
25707 + savesegment(ss, prev->ss);
25708 + if (unlikely(next->ss != prev->ss))
25709 + loadsegment(ss, next->ss);
25710
25711 /* We must save %fs and %gs before load_TLS() because
25712 * %fs and %gs may be cleared by load_TLS().
25713 @@ -362,6 +368,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25714 prev->usersp = this_cpu_read(old_rsp);
25715 this_cpu_write(old_rsp, next->usersp);
25716 this_cpu_write(current_task, next_p);
25717 + this_cpu_write(current_tinfo, &next_p->tinfo);
25718
25719 /*
25720 * If it were not for PREEMPT_ACTIVE we could guarantee that the
25721 @@ -371,9 +378,7 @@ __switch_to(struct task_struct *prev_p, struct task_struct *next_p)
25722 task_thread_info(prev_p)->saved_preempt_count = this_cpu_read(__preempt_count);
25723 this_cpu_write(__preempt_count, task_thread_info(next_p)->saved_preempt_count);
25724
25725 - this_cpu_write(kernel_stack,
25726 - (unsigned long)task_stack_page(next_p) +
25727 - THREAD_SIZE - KERNEL_STACK_OFFSET);
25728 + this_cpu_write(kernel_stack, next->sp0);
25729
25730 /*
25731 * Now maybe reload the debug registers and handle I/O bitmaps
25732 @@ -442,12 +447,11 @@ unsigned long get_wchan(struct task_struct *p)
25733 if (!p || p == current || p->state == TASK_RUNNING)
25734 return 0;
25735 stack = (unsigned long)task_stack_page(p);
25736 - if (p->thread.sp < stack || p->thread.sp >= stack+THREAD_SIZE)
25737 + if (p->thread.sp < stack || p->thread.sp > stack+THREAD_SIZE-16-sizeof(u64))
25738 return 0;
25739 fp = *(u64 *)(p->thread.sp);
25740 do {
25741 - if (fp < (unsigned long)stack ||
25742 - fp >= (unsigned long)stack+THREAD_SIZE)
25743 + if (fp < stack || fp > stack+THREAD_SIZE-16-sizeof(u64))
25744 return 0;
25745 ip = *(u64 *)(fp+8);
25746 if (!in_sched_functions(ip))
25747 diff --git a/arch/x86/kernel/ptrace.c b/arch/x86/kernel/ptrace.c
25748 index 7461f50..1334029 100644
25749 --- a/arch/x86/kernel/ptrace.c
25750 +++ b/arch/x86/kernel/ptrace.c
25751 @@ -184,14 +184,13 @@ unsigned long kernel_stack_pointer(struct pt_regs *regs)
25752 {
25753 unsigned long context = (unsigned long)regs & ~(THREAD_SIZE - 1);
25754 unsigned long sp = (unsigned long)&regs->sp;
25755 - struct thread_info *tinfo;
25756
25757 - if (context == (sp & ~(THREAD_SIZE - 1)))
25758 + if (context == ((sp + 8) & ~(THREAD_SIZE - 1)))
25759 return sp;
25760
25761 - tinfo = (struct thread_info *)context;
25762 - if (tinfo->previous_esp)
25763 - return tinfo->previous_esp;
25764 + sp = *(unsigned long *)context;
25765 + if (sp)
25766 + return sp;
25767
25768 return (unsigned long)regs;
25769 }
25770 @@ -588,7 +587,7 @@ static void ptrace_triggered(struct perf_event *bp,
25771 static unsigned long ptrace_get_dr7(struct perf_event *bp[])
25772 {
25773 int i;
25774 - int dr7 = 0;
25775 + unsigned long dr7 = 0;
25776 struct arch_hw_breakpoint *info;
25777
25778 for (i = 0; i < HBP_NUM; i++) {
25779 @@ -822,7 +821,7 @@ long arch_ptrace(struct task_struct *child, long request,
25780 unsigned long addr, unsigned long data)
25781 {
25782 int ret;
25783 - unsigned long __user *datap = (unsigned long __user *)data;
25784 + unsigned long __user *datap = (__force unsigned long __user *)data;
25785
25786 switch (request) {
25787 /* read the word at location addr in the USER area. */
25788 @@ -907,14 +906,14 @@ long arch_ptrace(struct task_struct *child, long request,
25789 if ((int) addr < 0)
25790 return -EIO;
25791 ret = do_get_thread_area(child, addr,
25792 - (struct user_desc __user *)data);
25793 + (__force struct user_desc __user *) data);
25794 break;
25795
25796 case PTRACE_SET_THREAD_AREA:
25797 if ((int) addr < 0)
25798 return -EIO;
25799 ret = do_set_thread_area(child, addr,
25800 - (struct user_desc __user *)data, 0);
25801 + (__force struct user_desc __user *) data, 0);
25802 break;
25803 #endif
25804
25805 @@ -1292,7 +1291,7 @@ long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
25806
25807 #ifdef CONFIG_X86_64
25808
25809 -static struct user_regset x86_64_regsets[] __read_mostly = {
25810 +static user_regset_no_const x86_64_regsets[] __read_only = {
25811 [REGSET_GENERAL] = {
25812 .core_note_type = NT_PRSTATUS,
25813 .n = sizeof(struct user_regs_struct) / sizeof(long),
25814 @@ -1333,7 +1332,7 @@ static const struct user_regset_view user_x86_64_view = {
25815 #endif /* CONFIG_X86_64 */
25816
25817 #if defined CONFIG_X86_32 || defined CONFIG_IA32_EMULATION
25818 -static struct user_regset x86_32_regsets[] __read_mostly = {
25819 +static user_regset_no_const x86_32_regsets[] __read_only = {
25820 [REGSET_GENERAL] = {
25821 .core_note_type = NT_PRSTATUS,
25822 .n = sizeof(struct user_regs_struct32) / sizeof(u32),
25823 @@ -1386,7 +1385,7 @@ static const struct user_regset_view user_x86_32_view = {
25824 */
25825 u64 xstate_fx_sw_bytes[USER_XSTATE_FX_SW_WORDS];
25826
25827 -void update_regset_xstate_info(unsigned int size, u64 xstate_mask)
25828 +void __init update_regset_xstate_info(unsigned int size, u64 xstate_mask)
25829 {
25830 #ifdef CONFIG_X86_64
25831 x86_64_regsets[REGSET_XSTATE].n = size / sizeof(u64);
25832 @@ -1421,7 +1420,7 @@ static void fill_sigtrap_info(struct task_struct *tsk,
25833 memset(info, 0, sizeof(*info));
25834 info->si_signo = SIGTRAP;
25835 info->si_code = si_code;
25836 - info->si_addr = user_mode_vm(regs) ? (void __user *)regs->ip : NULL;
25837 + info->si_addr = user_mode(regs) ? (__force void __user *)regs->ip : NULL;
25838 }
25839
25840 void user_single_step_siginfo(struct task_struct *tsk,
25841 @@ -1450,6 +1449,10 @@ void send_sigtrap(struct task_struct *tsk, struct pt_regs *regs,
25842 # define IS_IA32 0
25843 #endif
25844
25845 +#ifdef CONFIG_GRKERNSEC_SETXID
25846 +extern void gr_delayed_cred_worker(void);
25847 +#endif
25848 +
25849 /*
25850 * We must return the syscall number to actually look up in the table.
25851 * This can be -1L to skip running any syscall at all.
25852 @@ -1460,6 +1463,11 @@ long syscall_trace_enter(struct pt_regs *regs)
25853
25854 user_exit();
25855
25856 +#ifdef CONFIG_GRKERNSEC_SETXID
25857 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
25858 + gr_delayed_cred_worker();
25859 +#endif
25860 +
25861 /*
25862 * If we stepped into a sysenter/syscall insn, it trapped in
25863 * kernel mode; do_debug() cleared TF and set TIF_SINGLESTEP.
25864 @@ -1515,6 +1523,11 @@ void syscall_trace_leave(struct pt_regs *regs)
25865 */
25866 user_exit();
25867
25868 +#ifdef CONFIG_GRKERNSEC_SETXID
25869 + if (unlikely(test_and_clear_thread_flag(TIF_GRSEC_SETXID)))
25870 + gr_delayed_cred_worker();
25871 +#endif
25872 +
25873 audit_syscall_exit(regs);
25874
25875 if (unlikely(test_thread_flag(TIF_SYSCALL_TRACEPOINT)))
25876 diff --git a/arch/x86/kernel/pvclock.c b/arch/x86/kernel/pvclock.c
25877 index 2f355d2..e75ed0a 100644
25878 --- a/arch/x86/kernel/pvclock.c
25879 +++ b/arch/x86/kernel/pvclock.c
25880 @@ -51,11 +51,11 @@ void pvclock_touch_watchdogs(void)
25881 reset_hung_task_detector();
25882 }
25883
25884 -static atomic64_t last_value = ATOMIC64_INIT(0);
25885 +static atomic64_unchecked_t last_value = ATOMIC64_INIT(0);
25886
25887 void pvclock_resume(void)
25888 {
25889 - atomic64_set(&last_value, 0);
25890 + atomic64_set_unchecked(&last_value, 0);
25891 }
25892
25893 u8 pvclock_read_flags(struct pvclock_vcpu_time_info *src)
25894 @@ -105,11 +105,11 @@ cycle_t pvclock_clocksource_read(struct pvclock_vcpu_time_info *src)
25895 * updating at the same time, and one of them could be slightly behind,
25896 * making the assumption that last_value always go forward fail to hold.
25897 */
25898 - last = atomic64_read(&last_value);
25899 + last = atomic64_read_unchecked(&last_value);
25900 do {
25901 if (ret < last)
25902 return last;
25903 - last = atomic64_cmpxchg(&last_value, last, ret);
25904 + last = atomic64_cmpxchg_unchecked(&last_value, last, ret);
25905 } while (unlikely(last != ret));
25906
25907 return ret;
25908 diff --git a/arch/x86/kernel/reboot.c b/arch/x86/kernel/reboot.c
25909 index c752cb4..866c432 100644
25910 --- a/arch/x86/kernel/reboot.c
25911 +++ b/arch/x86/kernel/reboot.c
25912 @@ -68,6 +68,11 @@ static int __init set_bios_reboot(const struct dmi_system_id *d)
25913
25914 void __noreturn machine_real_restart(unsigned int type)
25915 {
25916 +
25917 +#if defined(CONFIG_X86_32) && (defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF))
25918 + struct desc_struct *gdt;
25919 +#endif
25920 +
25921 local_irq_disable();
25922
25923 /*
25924 @@ -95,7 +100,29 @@ void __noreturn machine_real_restart(unsigned int type)
25925
25926 /* Jump to the identity-mapped low memory code */
25927 #ifdef CONFIG_X86_32
25928 - asm volatile("jmpl *%0" : :
25929 +
25930 +#if defined(CONFIG_PAX_KERNEXEC) || defined(CONFIG_PAX_MEMORY_UDEREF)
25931 + gdt = get_cpu_gdt_table(smp_processor_id());
25932 + pax_open_kernel();
25933 +#ifdef CONFIG_PAX_MEMORY_UDEREF
25934 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
25935 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
25936 + loadsegment(ds, __KERNEL_DS);
25937 + loadsegment(es, __KERNEL_DS);
25938 + loadsegment(ss, __KERNEL_DS);
25939 +#endif
25940 +#ifdef CONFIG_PAX_KERNEXEC
25941 + gdt[GDT_ENTRY_KERNEL_CS].base0 = 0;
25942 + gdt[GDT_ENTRY_KERNEL_CS].base1 = 0;
25943 + gdt[GDT_ENTRY_KERNEL_CS].base2 = 0;
25944 + gdt[GDT_ENTRY_KERNEL_CS].limit0 = 0xffff;
25945 + gdt[GDT_ENTRY_KERNEL_CS].limit = 0xf;
25946 + gdt[GDT_ENTRY_KERNEL_CS].g = 1;
25947 +#endif
25948 + pax_close_kernel();
25949 +#endif
25950 +
25951 + asm volatile("ljmpl *%0" : :
25952 "rm" (real_mode_header->machine_real_restart_asm),
25953 "a" (type));
25954 #else
25955 @@ -470,7 +497,7 @@ void __attribute__((weak)) mach_reboot_fixups(void)
25956 * try to force a triple fault and then cycle between hitting the keyboard
25957 * controller and doing that
25958 */
25959 -static void native_machine_emergency_restart(void)
25960 +static void __noreturn native_machine_emergency_restart(void)
25961 {
25962 int i;
25963 int attempt = 0;
25964 @@ -593,13 +620,13 @@ void native_machine_shutdown(void)
25965 #endif
25966 }
25967
25968 -static void __machine_emergency_restart(int emergency)
25969 +static void __noreturn __machine_emergency_restart(int emergency)
25970 {
25971 reboot_emergency = emergency;
25972 machine_ops.emergency_restart();
25973 }
25974
25975 -static void native_machine_restart(char *__unused)
25976 +static void __noreturn native_machine_restart(char *__unused)
25977 {
25978 pr_notice("machine restart\n");
25979
25980 @@ -608,7 +635,7 @@ static void native_machine_restart(char *__unused)
25981 __machine_emergency_restart(0);
25982 }
25983
25984 -static void native_machine_halt(void)
25985 +static void __noreturn native_machine_halt(void)
25986 {
25987 /* Stop other cpus and apics */
25988 machine_shutdown();
25989 @@ -618,7 +645,7 @@ static void native_machine_halt(void)
25990 stop_this_cpu(NULL);
25991 }
25992
25993 -static void native_machine_power_off(void)
25994 +static void __noreturn native_machine_power_off(void)
25995 {
25996 if (pm_power_off) {
25997 if (!reboot_force)
25998 @@ -627,9 +654,10 @@ static void native_machine_power_off(void)
25999 }
26000 /* A fallback in case there is no PM info available */
26001 tboot_shutdown(TB_SHUTDOWN_HALT);
26002 + unreachable();
26003 }
26004
26005 -struct machine_ops machine_ops = {
26006 +struct machine_ops machine_ops __read_only = {
26007 .power_off = native_machine_power_off,
26008 .shutdown = native_machine_shutdown,
26009 .emergency_restart = native_machine_emergency_restart,
26010 diff --git a/arch/x86/kernel/reboot_fixups_32.c b/arch/x86/kernel/reboot_fixups_32.c
26011 index c8e41e9..64049ef 100644
26012 --- a/arch/x86/kernel/reboot_fixups_32.c
26013 +++ b/arch/x86/kernel/reboot_fixups_32.c
26014 @@ -57,7 +57,7 @@ struct device_fixup {
26015 unsigned int vendor;
26016 unsigned int device;
26017 void (*reboot_fixup)(struct pci_dev *);
26018 -};
26019 +} __do_const;
26020
26021 /*
26022 * PCI ids solely used for fixups_table go here
26023 diff --git a/arch/x86/kernel/relocate_kernel_64.S b/arch/x86/kernel/relocate_kernel_64.S
26024 index 3fd2c69..16ef367 100644
26025 --- a/arch/x86/kernel/relocate_kernel_64.S
26026 +++ b/arch/x86/kernel/relocate_kernel_64.S
26027 @@ -11,6 +11,7 @@
26028 #include <asm/kexec.h>
26029 #include <asm/processor-flags.h>
26030 #include <asm/pgtable_types.h>
26031 +#include <asm/alternative-asm.h>
26032
26033 /*
26034 * Must be relocatable PIC code callable as a C function
26035 @@ -96,8 +97,7 @@ relocate_kernel:
26036
26037 /* jump to identity mapped page */
26038 addq $(identity_mapped - relocate_kernel), %r8
26039 - pushq %r8
26040 - ret
26041 + jmp *%r8
26042
26043 identity_mapped:
26044 /* set return address to 0 if not preserving context */
26045 @@ -167,6 +167,7 @@ identity_mapped:
26046 xorl %r14d, %r14d
26047 xorl %r15d, %r15d
26048
26049 + pax_force_retaddr 0, 1
26050 ret
26051
26052 1:
26053 diff --git a/arch/x86/kernel/setup.c b/arch/x86/kernel/setup.c
26054 index cb233bc..23b4879 100644
26055 --- a/arch/x86/kernel/setup.c
26056 +++ b/arch/x86/kernel/setup.c
26057 @@ -110,6 +110,7 @@
26058 #include <asm/mce.h>
26059 #include <asm/alternative.h>
26060 #include <asm/prom.h>
26061 +#include <asm/boot.h>
26062
26063 /*
26064 * max_low_pfn_mapped: highest direct mapped pfn under 4GB
26065 @@ -205,12 +206,50 @@ EXPORT_SYMBOL(boot_cpu_data);
26066 #endif
26067
26068
26069 -#if !defined(CONFIG_X86_PAE) || defined(CONFIG_X86_64)
26070 -__visible unsigned long mmu_cr4_features;
26071 +#ifdef CONFIG_X86_64
26072 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PSE | X86_CR4_PAE | X86_CR4_PGE;
26073 +#elif defined(CONFIG_X86_PAE)
26074 +__visible unsigned long mmu_cr4_features __read_only = X86_CR4_PAE;
26075 #else
26076 -__visible unsigned long mmu_cr4_features = X86_CR4_PAE;
26077 +__visible unsigned long mmu_cr4_features __read_only;
26078 #endif
26079
26080 +void set_in_cr4(unsigned long mask)
26081 +{
26082 + unsigned long cr4 = read_cr4();
26083 +
26084 + if ((cr4 & mask) == mask && cr4 == mmu_cr4_features)
26085 + return;
26086 +
26087 + pax_open_kernel();
26088 + mmu_cr4_features |= mask;
26089 + pax_close_kernel();
26090 +
26091 + if (trampoline_cr4_features)
26092 + *trampoline_cr4_features = mmu_cr4_features;
26093 + cr4 |= mask;
26094 + write_cr4(cr4);
26095 +}
26096 +EXPORT_SYMBOL(set_in_cr4);
26097 +
26098 +void clear_in_cr4(unsigned long mask)
26099 +{
26100 + unsigned long cr4 = read_cr4();
26101 +
26102 + if (!(cr4 & mask) && cr4 == mmu_cr4_features)
26103 + return;
26104 +
26105 + pax_open_kernel();
26106 + mmu_cr4_features &= ~mask;
26107 + pax_close_kernel();
26108 +
26109 + if (trampoline_cr4_features)
26110 + *trampoline_cr4_features = mmu_cr4_features;
26111 + cr4 &= ~mask;
26112 + write_cr4(cr4);
26113 +}
26114 +EXPORT_SYMBOL(clear_in_cr4);
26115 +
26116 /* Boot loader ID and version as integers, for the benefit of proc_dointvec */
26117 int bootloader_type, bootloader_version;
26118
26119 @@ -768,7 +807,7 @@ static void __init trim_bios_range(void)
26120 * area (640->1Mb) as ram even though it is not.
26121 * take them out.
26122 */
26123 - e820_remove_range(BIOS_BEGIN, BIOS_END - BIOS_BEGIN, E820_RAM, 1);
26124 + e820_remove_range(ISA_START_ADDRESS, ISA_END_ADDRESS - ISA_START_ADDRESS, E820_RAM, 1);
26125
26126 sanitize_e820_map(e820.map, ARRAY_SIZE(e820.map), &e820.nr_map);
26127 }
26128 @@ -776,7 +815,7 @@ static void __init trim_bios_range(void)
26129 /* called before trim_bios_range() to spare extra sanitize */
26130 static void __init e820_add_kernel_range(void)
26131 {
26132 - u64 start = __pa_symbol(_text);
26133 + u64 start = __pa_symbol(ktla_ktva(_text));
26134 u64 size = __pa_symbol(_end) - start;
26135
26136 /*
26137 @@ -838,8 +877,12 @@ static void __init trim_low_memory_range(void)
26138
26139 void __init setup_arch(char **cmdline_p)
26140 {
26141 +#ifdef CONFIG_X86_32
26142 + memblock_reserve(LOAD_PHYSICAL_ADDR, __pa_symbol(__bss_stop) - LOAD_PHYSICAL_ADDR);
26143 +#else
26144 memblock_reserve(__pa_symbol(_text),
26145 (unsigned long)__bss_stop - (unsigned long)_text);
26146 +#endif
26147
26148 early_reserve_initrd();
26149
26150 @@ -931,14 +974,14 @@ void __init setup_arch(char **cmdline_p)
26151
26152 if (!boot_params.hdr.root_flags)
26153 root_mountflags &= ~MS_RDONLY;
26154 - init_mm.start_code = (unsigned long) _text;
26155 - init_mm.end_code = (unsigned long) _etext;
26156 + init_mm.start_code = ktla_ktva((unsigned long) _text);
26157 + init_mm.end_code = ktla_ktva((unsigned long) _etext);
26158 init_mm.end_data = (unsigned long) _edata;
26159 init_mm.brk = _brk_end;
26160
26161 - code_resource.start = __pa_symbol(_text);
26162 - code_resource.end = __pa_symbol(_etext)-1;
26163 - data_resource.start = __pa_symbol(_etext);
26164 + code_resource.start = __pa_symbol(ktla_ktva(_text));
26165 + code_resource.end = __pa_symbol(ktla_ktva(_etext))-1;
26166 + data_resource.start = __pa_symbol(_sdata);
26167 data_resource.end = __pa_symbol(_edata)-1;
26168 bss_resource.start = __pa_symbol(__bss_start);
26169 bss_resource.end = __pa_symbol(__bss_stop)-1;
26170 diff --git a/arch/x86/kernel/setup_percpu.c b/arch/x86/kernel/setup_percpu.c
26171 index 5cdff03..80fa283 100644
26172 --- a/arch/x86/kernel/setup_percpu.c
26173 +++ b/arch/x86/kernel/setup_percpu.c
26174 @@ -21,19 +21,17 @@
26175 #include <asm/cpu.h>
26176 #include <asm/stackprotector.h>
26177
26178 -DEFINE_PER_CPU_READ_MOSTLY(int, cpu_number);
26179 +#ifdef CONFIG_SMP
26180 +DEFINE_PER_CPU_READ_MOSTLY(unsigned int, cpu_number);
26181 EXPORT_PER_CPU_SYMBOL(cpu_number);
26182 +#endif
26183
26184 -#ifdef CONFIG_X86_64
26185 #define BOOT_PERCPU_OFFSET ((unsigned long)__per_cpu_load)
26186 -#else
26187 -#define BOOT_PERCPU_OFFSET 0
26188 -#endif
26189
26190 DEFINE_PER_CPU(unsigned long, this_cpu_off) = BOOT_PERCPU_OFFSET;
26191 EXPORT_PER_CPU_SYMBOL(this_cpu_off);
26192
26193 -unsigned long __per_cpu_offset[NR_CPUS] __read_mostly = {
26194 +unsigned long __per_cpu_offset[NR_CPUS] __read_only = {
26195 [0 ... NR_CPUS-1] = BOOT_PERCPU_OFFSET,
26196 };
26197 EXPORT_SYMBOL(__per_cpu_offset);
26198 @@ -66,7 +64,7 @@ static bool __init pcpu_need_numa(void)
26199 {
26200 #ifdef CONFIG_NEED_MULTIPLE_NODES
26201 pg_data_t *last = NULL;
26202 - unsigned int cpu;
26203 + int cpu;
26204
26205 for_each_possible_cpu(cpu) {
26206 int node = early_cpu_to_node(cpu);
26207 @@ -155,10 +153,10 @@ static inline void setup_percpu_segment(int cpu)
26208 {
26209 #ifdef CONFIG_X86_32
26210 struct desc_struct gdt;
26211 + unsigned long base = per_cpu_offset(cpu);
26212
26213 - pack_descriptor(&gdt, per_cpu_offset(cpu), 0xFFFFF,
26214 - 0x2 | DESCTYPE_S, 0x8);
26215 - gdt.s = 1;
26216 + pack_descriptor(&gdt, base, (VMALLOC_END - base - 1) >> PAGE_SHIFT,
26217 + 0x83 | DESCTYPE_S, 0xC);
26218 write_gdt_entry(get_cpu_gdt_table(cpu),
26219 GDT_ENTRY_PERCPU, &gdt, DESCTYPE_S);
26220 #endif
26221 @@ -219,6 +217,11 @@ void __init setup_per_cpu_areas(void)
26222 /* alrighty, percpu areas up and running */
26223 delta = (unsigned long)pcpu_base_addr - (unsigned long)__per_cpu_start;
26224 for_each_possible_cpu(cpu) {
26225 +#ifdef CONFIG_CC_STACKPROTECTOR
26226 +#ifdef CONFIG_X86_32
26227 + unsigned long canary = per_cpu(stack_canary.canary, cpu);
26228 +#endif
26229 +#endif
26230 per_cpu_offset(cpu) = delta + pcpu_unit_offsets[cpu];
26231 per_cpu(this_cpu_off, cpu) = per_cpu_offset(cpu);
26232 per_cpu(cpu_number, cpu) = cpu;
26233 @@ -259,6 +262,12 @@ void __init setup_per_cpu_areas(void)
26234 */
26235 set_cpu_numa_node(cpu, early_cpu_to_node(cpu));
26236 #endif
26237 +#ifdef CONFIG_CC_STACKPROTECTOR
26238 +#ifdef CONFIG_X86_32
26239 + if (!cpu)
26240 + per_cpu(stack_canary.canary, cpu) = canary;
26241 +#endif
26242 +#endif
26243 /*
26244 * Up to this point, the boot CPU has been using .init.data
26245 * area. Reload any changed state for the boot CPU.
26246 diff --git a/arch/x86/kernel/signal.c b/arch/x86/kernel/signal.c
26247 index 9e5de68..16c53cb 100644
26248 --- a/arch/x86/kernel/signal.c
26249 +++ b/arch/x86/kernel/signal.c
26250 @@ -190,7 +190,7 @@ static unsigned long align_sigframe(unsigned long sp)
26251 * Align the stack pointer according to the i386 ABI,
26252 * i.e. so that on function entry ((sp + 4) & 15) == 0.
26253 */
26254 - sp = ((sp + 4) & -16ul) - 4;
26255 + sp = ((sp - 12) & -16ul) - 4;
26256 #else /* !CONFIG_X86_32 */
26257 sp = round_down(sp, 16) - 8;
26258 #endif
26259 @@ -298,9 +298,9 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26260 }
26261
26262 if (current->mm->context.vdso)
26263 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26264 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, sigreturn);
26265 else
26266 - restorer = &frame->retcode;
26267 + restorer = (void __user *)&frame->retcode;
26268 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26269 restorer = ksig->ka.sa.sa_restorer;
26270
26271 @@ -314,7 +314,7 @@ __setup_frame(int sig, struct ksignal *ksig, sigset_t *set,
26272 * reasons and because gdb uses it as a signature to notice
26273 * signal handler stack frames.
26274 */
26275 - err |= __put_user(*((u64 *)&retcode), (u64 *)frame->retcode);
26276 + err |= __put_user(*((u64 *)&retcode), (u64 __user *)frame->retcode);
26277
26278 if (err)
26279 return -EFAULT;
26280 @@ -361,7 +361,10 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26281 save_altstack_ex(&frame->uc.uc_stack, regs->sp);
26282
26283 /* Set up to return from userspace. */
26284 - restorer = VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26285 + if (current->mm->context.vdso)
26286 + restorer = (__force void __user *)VDSO32_SYMBOL(current->mm->context.vdso, rt_sigreturn);
26287 + else
26288 + restorer = (void __user *)&frame->retcode;
26289 if (ksig->ka.sa.sa_flags & SA_RESTORER)
26290 restorer = ksig->ka.sa.sa_restorer;
26291 put_user_ex(restorer, &frame->pretcode);
26292 @@ -373,7 +376,7 @@ static int __setup_rt_frame(int sig, struct ksignal *ksig,
26293 * reasons and because gdb uses it as a signature to notice
26294 * signal handler stack frames.
26295 */
26296 - put_user_ex(*((u64 *)&rt_retcode), (u64 *)frame->retcode);
26297 + put_user_ex(*((u64 *)&rt_retcode), (u64 __user *)frame->retcode);
26298 } put_user_catch(err);
26299
26300 err |= copy_siginfo_to_user(&frame->info, &ksig->info);
26301 @@ -609,7 +612,12 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26302 {
26303 int usig = signr_convert(ksig->sig);
26304 sigset_t *set = sigmask_to_save();
26305 - compat_sigset_t *cset = (compat_sigset_t *) set;
26306 + sigset_t sigcopy;
26307 + compat_sigset_t *cset;
26308 +
26309 + sigcopy = *set;
26310 +
26311 + cset = (compat_sigset_t *) &sigcopy;
26312
26313 /* Set up the stack frame */
26314 if (is_ia32_frame()) {
26315 @@ -620,7 +628,7 @@ setup_rt_frame(struct ksignal *ksig, struct pt_regs *regs)
26316 } else if (is_x32_frame()) {
26317 return x32_setup_rt_frame(ksig, cset, regs);
26318 } else {
26319 - return __setup_rt_frame(ksig->sig, ksig, set, regs);
26320 + return __setup_rt_frame(ksig->sig, ksig, &sigcopy, regs);
26321 }
26322 }
26323
26324 diff --git a/arch/x86/kernel/smp.c b/arch/x86/kernel/smp.c
26325 index 7c3a5a6..f0a8961 100644
26326 --- a/arch/x86/kernel/smp.c
26327 +++ b/arch/x86/kernel/smp.c
26328 @@ -341,7 +341,7 @@ static int __init nonmi_ipi_setup(char *str)
26329
26330 __setup("nonmi_ipi", nonmi_ipi_setup);
26331
26332 -struct smp_ops smp_ops = {
26333 +struct smp_ops smp_ops __read_only = {
26334 .smp_prepare_boot_cpu = native_smp_prepare_boot_cpu,
26335 .smp_prepare_cpus = native_smp_prepare_cpus,
26336 .smp_cpus_done = native_smp_cpus_done,
26337 diff --git a/arch/x86/kernel/smpboot.c b/arch/x86/kernel/smpboot.c
26338 index 85dc05a..1241266 100644
26339 --- a/arch/x86/kernel/smpboot.c
26340 +++ b/arch/x86/kernel/smpboot.c
26341 @@ -229,14 +229,18 @@ static void notrace start_secondary(void *unused)
26342
26343 enable_start_cpu0 = 0;
26344
26345 -#ifdef CONFIG_X86_32
26346 - /* switch away from the initial page table */
26347 - load_cr3(swapper_pg_dir);
26348 - __flush_tlb_all();
26349 -#endif
26350 -
26351 /* otherwise gcc will move up smp_processor_id before the cpu_init */
26352 barrier();
26353 +
26354 + /* switch away from the initial page table */
26355 +#ifdef CONFIG_PAX_PER_CPU_PGD
26356 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
26357 + __flush_tlb_all();
26358 +#elif defined(CONFIG_X86_32)
26359 + load_cr3(swapper_pg_dir);
26360 + __flush_tlb_all();
26361 +#endif
26362 +
26363 /*
26364 * Check TSC synchronization with the BP:
26365 */
26366 @@ -751,6 +755,7 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26367 idle->thread.sp = (unsigned long) (((struct pt_regs *)
26368 (THREAD_SIZE + task_stack_page(idle))) - 1);
26369 per_cpu(current_task, cpu) = idle;
26370 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
26371
26372 #ifdef CONFIG_X86_32
26373 /* Stack for startup_32 can be just as for start_secondary onwards */
26374 @@ -758,11 +763,13 @@ static int do_boot_cpu(int apicid, int cpu, struct task_struct *idle)
26375 #else
26376 clear_tsk_thread_flag(idle, TIF_FORK);
26377 initial_gs = per_cpu_offset(cpu);
26378 - per_cpu(kernel_stack, cpu) =
26379 - (unsigned long)task_stack_page(idle) -
26380 - KERNEL_STACK_OFFSET + THREAD_SIZE;
26381 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
26382 #endif
26383 +
26384 + pax_open_kernel();
26385 early_gdt_descr.address = (unsigned long)get_cpu_gdt_table(cpu);
26386 + pax_close_kernel();
26387 +
26388 initial_code = (unsigned long)start_secondary;
26389 stack_start = idle->thread.sp;
26390
26391 @@ -911,6 +918,15 @@ int native_cpu_up(unsigned int cpu, struct task_struct *tidle)
26392 /* the FPU context is blank, nobody can own it */
26393 __cpu_disable_lazy_restore(cpu);
26394
26395 +#ifdef CONFIG_PAX_PER_CPU_PGD
26396 + clone_pgd_range(get_cpu_pgd(cpu, kernel) + KERNEL_PGD_BOUNDARY,
26397 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26398 + KERNEL_PGD_PTRS);
26399 + clone_pgd_range(get_cpu_pgd(cpu, user) + KERNEL_PGD_BOUNDARY,
26400 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
26401 + KERNEL_PGD_PTRS);
26402 +#endif
26403 +
26404 err = do_boot_cpu(apicid, cpu, tidle);
26405 if (err) {
26406 pr_debug("do_boot_cpu failed %d\n", err);
26407 diff --git a/arch/x86/kernel/step.c b/arch/x86/kernel/step.c
26408 index 9b4d51d..5d28b58 100644
26409 --- a/arch/x86/kernel/step.c
26410 +++ b/arch/x86/kernel/step.c
26411 @@ -27,10 +27,10 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26412 struct desc_struct *desc;
26413 unsigned long base;
26414
26415 - seg &= ~7UL;
26416 + seg >>= 3;
26417
26418 mutex_lock(&child->mm->context.lock);
26419 - if (unlikely((seg >> 3) >= child->mm->context.size))
26420 + if (unlikely(seg >= child->mm->context.size))
26421 addr = -1L; /* bogus selector, access would fault */
26422 else {
26423 desc = child->mm->context.ldt + seg;
26424 @@ -42,7 +42,8 @@ unsigned long convert_ip_to_linear(struct task_struct *child, struct pt_regs *re
26425 addr += base;
26426 }
26427 mutex_unlock(&child->mm->context.lock);
26428 - }
26429 + } else if (seg == __KERNEL_CS || seg == __KERNEXEC_KERNEL_CS)
26430 + addr = ktla_ktva(addr);
26431
26432 return addr;
26433 }
26434 @@ -53,6 +54,9 @@ static int is_setting_trap_flag(struct task_struct *child, struct pt_regs *regs)
26435 unsigned char opcode[15];
26436 unsigned long addr = convert_ip_to_linear(child, regs);
26437
26438 + if (addr == -EINVAL)
26439 + return 0;
26440 +
26441 copied = access_process_vm(child, addr, opcode, sizeof(opcode), 0);
26442 for (i = 0; i < copied; i++) {
26443 switch (opcode[i]) {
26444 diff --git a/arch/x86/kernel/sys_i386_32.c b/arch/x86/kernel/sys_i386_32.c
26445 new file mode 100644
26446 index 0000000..5877189
26447 --- /dev/null
26448 +++ b/arch/x86/kernel/sys_i386_32.c
26449 @@ -0,0 +1,189 @@
26450 +/*
26451 + * This file contains various random system calls that
26452 + * have a non-standard calling sequence on the Linux/i386
26453 + * platform.
26454 + */
26455 +
26456 +#include <linux/errno.h>
26457 +#include <linux/sched.h>
26458 +#include <linux/mm.h>
26459 +#include <linux/fs.h>
26460 +#include <linux/smp.h>
26461 +#include <linux/sem.h>
26462 +#include <linux/msg.h>
26463 +#include <linux/shm.h>
26464 +#include <linux/stat.h>
26465 +#include <linux/syscalls.h>
26466 +#include <linux/mman.h>
26467 +#include <linux/file.h>
26468 +#include <linux/utsname.h>
26469 +#include <linux/ipc.h>
26470 +#include <linux/elf.h>
26471 +
26472 +#include <linux/uaccess.h>
26473 +#include <linux/unistd.h>
26474 +
26475 +#include <asm/syscalls.h>
26476 +
26477 +int i386_mmap_check(unsigned long addr, unsigned long len, unsigned long flags)
26478 +{
26479 + unsigned long pax_task_size = TASK_SIZE;
26480 +
26481 +#ifdef CONFIG_PAX_SEGMEXEC
26482 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
26483 + pax_task_size = SEGMEXEC_TASK_SIZE;
26484 +#endif
26485 +
26486 + if (flags & MAP_FIXED)
26487 + if (len > pax_task_size || addr > pax_task_size - len)
26488 + return -EINVAL;
26489 +
26490 + return 0;
26491 +}
26492 +
26493 +/*
26494 + * Align a virtual address to avoid aliasing in the I$ on AMD F15h.
26495 + */
26496 +static unsigned long get_align_mask(void)
26497 +{
26498 + if (va_align.flags < 0 || !(va_align.flags & ALIGN_VA_32))
26499 + return 0;
26500 +
26501 + if (!(current->flags & PF_RANDOMIZE))
26502 + return 0;
26503 +
26504 + return va_align.mask;
26505 +}
26506 +
26507 +unsigned long
26508 +arch_get_unmapped_area(struct file *filp, unsigned long addr,
26509 + unsigned long len, unsigned long pgoff, unsigned long flags)
26510 +{
26511 + struct mm_struct *mm = current->mm;
26512 + struct vm_area_struct *vma;
26513 + unsigned long pax_task_size = TASK_SIZE;
26514 + struct vm_unmapped_area_info info;
26515 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26516 +
26517 +#ifdef CONFIG_PAX_SEGMEXEC
26518 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26519 + pax_task_size = SEGMEXEC_TASK_SIZE;
26520 +#endif
26521 +
26522 + pax_task_size -= PAGE_SIZE;
26523 +
26524 + if (len > pax_task_size)
26525 + return -ENOMEM;
26526 +
26527 + if (flags & MAP_FIXED)
26528 + return addr;
26529 +
26530 +#ifdef CONFIG_PAX_RANDMMAP
26531 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26532 +#endif
26533 +
26534 + if (addr) {
26535 + addr = PAGE_ALIGN(addr);
26536 + if (pax_task_size - len >= addr) {
26537 + vma = find_vma(mm, addr);
26538 + if (check_heap_stack_gap(vma, addr, len, offset))
26539 + return addr;
26540 + }
26541 + }
26542 +
26543 + info.flags = 0;
26544 + info.length = len;
26545 + info.align_mask = filp ? get_align_mask() : 0;
26546 + info.align_offset = pgoff << PAGE_SHIFT;
26547 + info.threadstack_offset = offset;
26548 +
26549 +#ifdef CONFIG_PAX_PAGEEXEC
26550 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE)) {
26551 + info.low_limit = 0x00110000UL;
26552 + info.high_limit = mm->start_code;
26553 +
26554 +#ifdef CONFIG_PAX_RANDMMAP
26555 + if (mm->pax_flags & MF_PAX_RANDMMAP)
26556 + info.low_limit += mm->delta_mmap & 0x03FFF000UL;
26557 +#endif
26558 +
26559 + if (info.low_limit < info.high_limit) {
26560 + addr = vm_unmapped_area(&info);
26561 + if (!IS_ERR_VALUE(addr))
26562 + return addr;
26563 + }
26564 + } else
26565 +#endif
26566 +
26567 + info.low_limit = mm->mmap_base;
26568 + info.high_limit = pax_task_size;
26569 +
26570 + return vm_unmapped_area(&info);
26571 +}
26572 +
26573 +unsigned long
26574 +arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26575 + const unsigned long len, const unsigned long pgoff,
26576 + const unsigned long flags)
26577 +{
26578 + struct vm_area_struct *vma;
26579 + struct mm_struct *mm = current->mm;
26580 + unsigned long addr = addr0, pax_task_size = TASK_SIZE;
26581 + struct vm_unmapped_area_info info;
26582 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26583 +
26584 +#ifdef CONFIG_PAX_SEGMEXEC
26585 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
26586 + pax_task_size = SEGMEXEC_TASK_SIZE;
26587 +#endif
26588 +
26589 + pax_task_size -= PAGE_SIZE;
26590 +
26591 + /* requested length too big for entire address space */
26592 + if (len > pax_task_size)
26593 + return -ENOMEM;
26594 +
26595 + if (flags & MAP_FIXED)
26596 + return addr;
26597 +
26598 +#ifdef CONFIG_PAX_PAGEEXEC
26599 + if (!(__supported_pte_mask & _PAGE_NX) && (mm->pax_flags & MF_PAX_PAGEEXEC) && (flags & MAP_EXECUTABLE))
26600 + goto bottomup;
26601 +#endif
26602 +
26603 +#ifdef CONFIG_PAX_RANDMMAP
26604 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26605 +#endif
26606 +
26607 + /* requesting a specific address */
26608 + if (addr) {
26609 + addr = PAGE_ALIGN(addr);
26610 + if (pax_task_size - len >= addr) {
26611 + vma = find_vma(mm, addr);
26612 + if (check_heap_stack_gap(vma, addr, len, offset))
26613 + return addr;
26614 + }
26615 + }
26616 +
26617 + info.flags = VM_UNMAPPED_AREA_TOPDOWN;
26618 + info.length = len;
26619 + info.low_limit = PAGE_SIZE;
26620 + info.high_limit = mm->mmap_base;
26621 + info.align_mask = filp ? get_align_mask() : 0;
26622 + info.align_offset = pgoff << PAGE_SHIFT;
26623 + info.threadstack_offset = offset;
26624 +
26625 + addr = vm_unmapped_area(&info);
26626 + if (!(addr & ~PAGE_MASK))
26627 + return addr;
26628 + VM_BUG_ON(addr != -ENOMEM);
26629 +
26630 +bottomup:
26631 + /*
26632 + * A failed mmap() very likely causes application failure,
26633 + * so fall back to the bottom-up function here. This scenario
26634 + * can happen with large stack limits and large mmap()
26635 + * allocations.
26636 + */
26637 + return arch_get_unmapped_area(filp, addr0, len, pgoff, flags);
26638 +}
26639 diff --git a/arch/x86/kernel/sys_x86_64.c b/arch/x86/kernel/sys_x86_64.c
26640 index 30277e2..5664a29 100644
26641 --- a/arch/x86/kernel/sys_x86_64.c
26642 +++ b/arch/x86/kernel/sys_x86_64.c
26643 @@ -81,8 +81,8 @@ out:
26644 return error;
26645 }
26646
26647 -static void find_start_end(unsigned long flags, unsigned long *begin,
26648 - unsigned long *end)
26649 +static void find_start_end(struct mm_struct *mm, unsigned long flags,
26650 + unsigned long *begin, unsigned long *end)
26651 {
26652 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT)) {
26653 unsigned long new_begin;
26654 @@ -101,7 +101,7 @@ static void find_start_end(unsigned long flags, unsigned long *begin,
26655 *begin = new_begin;
26656 }
26657 } else {
26658 - *begin = current->mm->mmap_legacy_base;
26659 + *begin = mm->mmap_legacy_base;
26660 *end = TASK_SIZE;
26661 }
26662 }
26663 @@ -114,20 +114,24 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
26664 struct vm_area_struct *vma;
26665 struct vm_unmapped_area_info info;
26666 unsigned long begin, end;
26667 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26668
26669 if (flags & MAP_FIXED)
26670 return addr;
26671
26672 - find_start_end(flags, &begin, &end);
26673 + find_start_end(mm, flags, &begin, &end);
26674
26675 if (len > end)
26676 return -ENOMEM;
26677
26678 +#ifdef CONFIG_PAX_RANDMMAP
26679 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26680 +#endif
26681 +
26682 if (addr) {
26683 addr = PAGE_ALIGN(addr);
26684 vma = find_vma(mm, addr);
26685 - if (end - len >= addr &&
26686 - (!vma || addr + len <= vma->vm_start))
26687 + if (end - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26688 return addr;
26689 }
26690
26691 @@ -137,6 +141,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
26692 info.high_limit = end;
26693 info.align_mask = filp ? get_align_mask() : 0;
26694 info.align_offset = pgoff << PAGE_SHIFT;
26695 + info.threadstack_offset = offset;
26696 return vm_unmapped_area(&info);
26697 }
26698
26699 @@ -149,6 +154,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26700 struct mm_struct *mm = current->mm;
26701 unsigned long addr = addr0;
26702 struct vm_unmapped_area_info info;
26703 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
26704
26705 /* requested length too big for entire address space */
26706 if (len > TASK_SIZE)
26707 @@ -161,12 +167,15 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26708 if (!test_thread_flag(TIF_ADDR32) && (flags & MAP_32BIT))
26709 goto bottomup;
26710
26711 +#ifdef CONFIG_PAX_RANDMMAP
26712 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
26713 +#endif
26714 +
26715 /* requesting a specific address */
26716 if (addr) {
26717 addr = PAGE_ALIGN(addr);
26718 vma = find_vma(mm, addr);
26719 - if (TASK_SIZE - len >= addr &&
26720 - (!vma || addr + len <= vma->vm_start))
26721 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
26722 return addr;
26723 }
26724
26725 @@ -176,6 +185,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
26726 info.high_limit = mm->mmap_base;
26727 info.align_mask = filp ? get_align_mask() : 0;
26728 info.align_offset = pgoff << PAGE_SHIFT;
26729 + info.threadstack_offset = offset;
26730 addr = vm_unmapped_area(&info);
26731 if (!(addr & ~PAGE_MASK))
26732 return addr;
26733 diff --git a/arch/x86/kernel/tboot.c b/arch/x86/kernel/tboot.c
26734 index 91a4496..bb87552 100644
26735 --- a/arch/x86/kernel/tboot.c
26736 +++ b/arch/x86/kernel/tboot.c
26737 @@ -221,7 +221,7 @@ static int tboot_setup_sleep(void)
26738
26739 void tboot_shutdown(u32 shutdown_type)
26740 {
26741 - void (*shutdown)(void);
26742 + void (* __noreturn shutdown)(void);
26743
26744 if (!tboot_enabled())
26745 return;
26746 @@ -243,7 +243,7 @@ void tboot_shutdown(u32 shutdown_type)
26747
26748 switch_to_tboot_pt();
26749
26750 - shutdown = (void(*)(void))(unsigned long)tboot->shutdown_entry;
26751 + shutdown = (void *)(unsigned long)tboot->shutdown_entry;
26752 shutdown();
26753
26754 /* should not reach here */
26755 @@ -310,7 +310,7 @@ static int tboot_extended_sleep(u8 sleep_state, u32 val_a, u32 val_b)
26756 return -ENODEV;
26757 }
26758
26759 -static atomic_t ap_wfs_count;
26760 +static atomic_unchecked_t ap_wfs_count;
26761
26762 static int tboot_wait_for_aps(int num_aps)
26763 {
26764 @@ -334,9 +334,9 @@ static int tboot_cpu_callback(struct notifier_block *nfb, unsigned long action,
26765 {
26766 switch (action) {
26767 case CPU_DYING:
26768 - atomic_inc(&ap_wfs_count);
26769 + atomic_inc_unchecked(&ap_wfs_count);
26770 if (num_online_cpus() == 1)
26771 - if (tboot_wait_for_aps(atomic_read(&ap_wfs_count)))
26772 + if (tboot_wait_for_aps(atomic_read_unchecked(&ap_wfs_count)))
26773 return NOTIFY_BAD;
26774 break;
26775 }
26776 @@ -422,7 +422,7 @@ static __init int tboot_late_init(void)
26777
26778 tboot_create_trampoline();
26779
26780 - atomic_set(&ap_wfs_count, 0);
26781 + atomic_set_unchecked(&ap_wfs_count, 0);
26782 register_hotcpu_notifier(&tboot_cpu_notifier);
26783
26784 #ifdef CONFIG_DEBUG_FS
26785 diff --git a/arch/x86/kernel/time.c b/arch/x86/kernel/time.c
26786 index 24d3c91..d06b473 100644
26787 --- a/arch/x86/kernel/time.c
26788 +++ b/arch/x86/kernel/time.c
26789 @@ -30,9 +30,9 @@ unsigned long profile_pc(struct pt_regs *regs)
26790 {
26791 unsigned long pc = instruction_pointer(regs);
26792
26793 - if (!user_mode_vm(regs) && in_lock_functions(pc)) {
26794 + if (!user_mode(regs) && in_lock_functions(pc)) {
26795 #ifdef CONFIG_FRAME_POINTER
26796 - return *(unsigned long *)(regs->bp + sizeof(long));
26797 + return ktla_ktva(*(unsigned long *)(regs->bp + sizeof(long)));
26798 #else
26799 unsigned long *sp =
26800 (unsigned long *)kernel_stack_pointer(regs);
26801 @@ -41,11 +41,17 @@ unsigned long profile_pc(struct pt_regs *regs)
26802 * or above a saved flags. Eflags has bits 22-31 zero,
26803 * kernel addresses don't.
26804 */
26805 +
26806 +#ifdef CONFIG_PAX_KERNEXEC
26807 + return ktla_ktva(sp[0]);
26808 +#else
26809 if (sp[0] >> 22)
26810 return sp[0];
26811 if (sp[1] >> 22)
26812 return sp[1];
26813 #endif
26814 +
26815 +#endif
26816 }
26817 return pc;
26818 }
26819 diff --git a/arch/x86/kernel/tls.c b/arch/x86/kernel/tls.c
26820 index f7fec09..9991981 100644
26821 --- a/arch/x86/kernel/tls.c
26822 +++ b/arch/x86/kernel/tls.c
26823 @@ -84,6 +84,11 @@ int do_set_thread_area(struct task_struct *p, int idx,
26824 if (idx < GDT_ENTRY_TLS_MIN || idx > GDT_ENTRY_TLS_MAX)
26825 return -EINVAL;
26826
26827 +#ifdef CONFIG_PAX_SEGMEXEC
26828 + if ((p->mm->pax_flags & MF_PAX_SEGMEXEC) && (info.contents & MODIFY_LDT_CONTENTS_CODE))
26829 + return -EINVAL;
26830 +#endif
26831 +
26832 set_tls_desc(p, idx, &info, 1);
26833
26834 return 0;
26835 @@ -200,7 +205,7 @@ int regset_tls_set(struct task_struct *target, const struct user_regset *regset,
26836
26837 if (kbuf)
26838 info = kbuf;
26839 - else if (__copy_from_user(infobuf, ubuf, count))
26840 + else if (count > sizeof infobuf || __copy_from_user(infobuf, ubuf, count))
26841 return -EFAULT;
26842 else
26843 info = infobuf;
26844 diff --git a/arch/x86/kernel/tracepoint.c b/arch/x86/kernel/tracepoint.c
26845 index 1c113db..287b42e 100644
26846 --- a/arch/x86/kernel/tracepoint.c
26847 +++ b/arch/x86/kernel/tracepoint.c
26848 @@ -9,11 +9,11 @@
26849 #include <linux/atomic.h>
26850
26851 atomic_t trace_idt_ctr = ATOMIC_INIT(0);
26852 -struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
26853 +const struct desc_ptr trace_idt_descr = { NR_VECTORS * 16 - 1,
26854 (unsigned long) trace_idt_table };
26855
26856 /* No need to be aligned, but done to keep all IDTs defined the same way. */
26857 -gate_desc trace_idt_table[NR_VECTORS] __page_aligned_bss;
26858 +gate_desc trace_idt_table[NR_VECTORS] __page_aligned_rodata;
26859
26860 static int trace_irq_vector_refcount;
26861 static DEFINE_MUTEX(irq_vector_mutex);
26862 diff --git a/arch/x86/kernel/traps.c b/arch/x86/kernel/traps.c
26863 index b857ed8..51ae4cb 100644
26864 --- a/arch/x86/kernel/traps.c
26865 +++ b/arch/x86/kernel/traps.c
26866 @@ -66,7 +66,7 @@
26867 #include <asm/proto.h>
26868
26869 /* No need to be aligned, but done to keep all IDTs defined the same way. */
26870 -gate_desc debug_idt_table[NR_VECTORS] __page_aligned_bss;
26871 +gate_desc debug_idt_table[NR_VECTORS] __page_aligned_rodata;
26872 #else
26873 #include <asm/processor-flags.h>
26874 #include <asm/setup.h>
26875 @@ -75,7 +75,7 @@ asmlinkage int system_call(void);
26876 #endif
26877
26878 /* Must be page-aligned because the real IDT is used in a fixmap. */
26879 -gate_desc idt_table[NR_VECTORS] __page_aligned_bss;
26880 +gate_desc idt_table[NR_VECTORS] __page_aligned_rodata;
26881
26882 DECLARE_BITMAP(used_vectors, NR_VECTORS);
26883 EXPORT_SYMBOL_GPL(used_vectors);
26884 @@ -107,11 +107,11 @@ static inline void preempt_conditional_cli(struct pt_regs *regs)
26885 }
26886
26887 static int __kprobes
26888 -do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26889 +do_trap_no_signal(struct task_struct *tsk, int trapnr, const char *str,
26890 struct pt_regs *regs, long error_code)
26891 {
26892 #ifdef CONFIG_X86_32
26893 - if (regs->flags & X86_VM_MASK) {
26894 + if (v8086_mode(regs)) {
26895 /*
26896 * Traps 0, 1, 3, 4, and 5 should be forwarded to vm86.
26897 * On nmi (interrupt 2), do_trap should not be called.
26898 @@ -124,12 +124,24 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26899 return -1;
26900 }
26901 #endif
26902 - if (!user_mode(regs)) {
26903 + if (!user_mode_novm(regs)) {
26904 if (!fixup_exception(regs)) {
26905 tsk->thread.error_code = error_code;
26906 tsk->thread.trap_nr = trapnr;
26907 +
26908 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26909 + if (trapnr == 12 && ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS))
26910 + str = "PAX: suspicious stack segment fault";
26911 +#endif
26912 +
26913 die(str, regs, error_code);
26914 }
26915 +
26916 +#ifdef CONFIG_PAX_REFCOUNT
26917 + if (trapnr == 4)
26918 + pax_report_refcount_overflow(regs);
26919 +#endif
26920 +
26921 return 0;
26922 }
26923
26924 @@ -137,7 +149,7 @@ do_trap_no_signal(struct task_struct *tsk, int trapnr, char *str,
26925 }
26926
26927 static void __kprobes
26928 -do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
26929 +do_trap(int trapnr, int signr, const char *str, struct pt_regs *regs,
26930 long error_code, siginfo_t *info)
26931 {
26932 struct task_struct *tsk = current;
26933 @@ -161,7 +173,7 @@ do_trap(int trapnr, int signr, char *str, struct pt_regs *regs,
26934 if (show_unhandled_signals && unhandled_signal(tsk, signr) &&
26935 printk_ratelimit()) {
26936 pr_info("%s[%d] trap %s ip:%lx sp:%lx error:%lx",
26937 - tsk->comm, tsk->pid, str,
26938 + tsk->comm, task_pid_nr(tsk), str,
26939 regs->ip, regs->sp, error_code);
26940 print_vma_addr(" in ", regs->ip);
26941 pr_cont("\n");
26942 @@ -277,7 +289,7 @@ do_general_protection(struct pt_regs *regs, long error_code)
26943 conditional_sti(regs);
26944
26945 #ifdef CONFIG_X86_32
26946 - if (regs->flags & X86_VM_MASK) {
26947 + if (v8086_mode(regs)) {
26948 local_irq_enable();
26949 handle_vm86_fault((struct kernel_vm86_regs *) regs, error_code);
26950 goto exit;
26951 @@ -285,18 +297,42 @@ do_general_protection(struct pt_regs *regs, long error_code)
26952 #endif
26953
26954 tsk = current;
26955 - if (!user_mode(regs)) {
26956 + if (!user_mode_novm(regs)) {
26957 if (fixup_exception(regs))
26958 goto exit;
26959
26960 tsk->thread.error_code = error_code;
26961 tsk->thread.trap_nr = X86_TRAP_GP;
26962 if (notify_die(DIE_GPF, "general protection fault", regs, error_code,
26963 - X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP)
26964 + X86_TRAP_GP, SIGSEGV) != NOTIFY_STOP) {
26965 +
26966 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
26967 + if ((regs->cs & 0xFFFF) == __KERNEL_CS || (regs->cs & 0xFFFF) == __KERNEXEC_KERNEL_CS)
26968 + die("PAX: suspicious general protection fault", regs, error_code);
26969 + else
26970 +#endif
26971 +
26972 die("general protection fault", regs, error_code);
26973 + }
26974 goto exit;
26975 }
26976
26977 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
26978 + if (!(__supported_pte_mask & _PAGE_NX) && tsk->mm && (tsk->mm->pax_flags & MF_PAX_PAGEEXEC)) {
26979 + struct mm_struct *mm = tsk->mm;
26980 + unsigned long limit;
26981 +
26982 + down_write(&mm->mmap_sem);
26983 + limit = mm->context.user_cs_limit;
26984 + if (limit < TASK_SIZE) {
26985 + track_exec_limit(mm, limit, TASK_SIZE, VM_EXEC);
26986 + up_write(&mm->mmap_sem);
26987 + return;
26988 + }
26989 + up_write(&mm->mmap_sem);
26990 + }
26991 +#endif
26992 +
26993 tsk->thread.error_code = error_code;
26994 tsk->thread.trap_nr = X86_TRAP_GP;
26995
26996 @@ -457,7 +493,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
26997 /* It's safe to allow irq's after DR6 has been saved */
26998 preempt_conditional_sti(regs);
26999
27000 - if (regs->flags & X86_VM_MASK) {
27001 + if (v8086_mode(regs)) {
27002 handle_vm86_trap((struct kernel_vm86_regs *) regs, error_code,
27003 X86_TRAP_DB);
27004 preempt_conditional_cli(regs);
27005 @@ -472,7 +508,7 @@ dotraplinkage void __kprobes do_debug(struct pt_regs *regs, long error_code)
27006 * We already checked v86 mode above, so we can check for kernel mode
27007 * by just checking the CPL of CS.
27008 */
27009 - if ((dr6 & DR_STEP) && !user_mode(regs)) {
27010 + if ((dr6 & DR_STEP) && !user_mode_novm(regs)) {
27011 tsk->thread.debugreg6 &= ~DR_STEP;
27012 set_tsk_thread_flag(tsk, TIF_SINGLESTEP);
27013 regs->flags &= ~X86_EFLAGS_TF;
27014 @@ -504,7 +540,7 @@ void math_error(struct pt_regs *regs, int error_code, int trapnr)
27015 return;
27016 conditional_sti(regs);
27017
27018 - if (!user_mode_vm(regs))
27019 + if (!user_mode(regs))
27020 {
27021 if (!fixup_exception(regs)) {
27022 task->thread.error_code = error_code;
27023 diff --git a/arch/x86/kernel/uprobes.c b/arch/x86/kernel/uprobes.c
27024 index 2ed8459..7cf329f 100644
27025 --- a/arch/x86/kernel/uprobes.c
27026 +++ b/arch/x86/kernel/uprobes.c
27027 @@ -629,7 +629,7 @@ int arch_uprobe_exception_notify(struct notifier_block *self, unsigned long val,
27028 int ret = NOTIFY_DONE;
27029
27030 /* We are only interested in userspace traps */
27031 - if (regs && !user_mode_vm(regs))
27032 + if (regs && !user_mode(regs))
27033 return NOTIFY_DONE;
27034
27035 switch (val) {
27036 @@ -719,7 +719,7 @@ arch_uretprobe_hijack_return_addr(unsigned long trampoline_vaddr, struct pt_regs
27037
27038 if (ncopied != rasize) {
27039 pr_err("uprobe: return address clobbered: pid=%d, %%sp=%#lx, "
27040 - "%%ip=%#lx\n", current->pid, regs->sp, regs->ip);
27041 + "%%ip=%#lx\n", task_pid_nr(current), regs->sp, regs->ip);
27042
27043 force_sig_info(SIGSEGV, SEND_SIG_FORCED, current);
27044 }
27045 diff --git a/arch/x86/kernel/verify_cpu.S b/arch/x86/kernel/verify_cpu.S
27046 index b9242ba..50c5edd 100644
27047 --- a/arch/x86/kernel/verify_cpu.S
27048 +++ b/arch/x86/kernel/verify_cpu.S
27049 @@ -20,6 +20,7 @@
27050 * arch/x86/boot/compressed/head_64.S: Boot cpu verification
27051 * arch/x86/kernel/trampoline_64.S: secondary processor verification
27052 * arch/x86/kernel/head_32.S: processor startup
27053 + * arch/x86/kernel/acpi/realmode/wakeup.S: 32bit processor resume
27054 *
27055 * verify_cpu, returns the status of longmode and SSE in register %eax.
27056 * 0: Success 1: Failure
27057 diff --git a/arch/x86/kernel/vm86_32.c b/arch/x86/kernel/vm86_32.c
27058 index e8edcf5..27f9344 100644
27059 --- a/arch/x86/kernel/vm86_32.c
27060 +++ b/arch/x86/kernel/vm86_32.c
27061 @@ -44,6 +44,7 @@
27062 #include <linux/ptrace.h>
27063 #include <linux/audit.h>
27064 #include <linux/stddef.h>
27065 +#include <linux/grsecurity.h>
27066
27067 #include <asm/uaccess.h>
27068 #include <asm/io.h>
27069 @@ -150,7 +151,7 @@ struct pt_regs *save_v86_state(struct kernel_vm86_regs *regs)
27070 do_exit(SIGSEGV);
27071 }
27072
27073 - tss = &per_cpu(init_tss, get_cpu());
27074 + tss = init_tss + get_cpu();
27075 current->thread.sp0 = current->thread.saved_sp0;
27076 current->thread.sysenter_cs = __KERNEL_CS;
27077 load_sp0(tss, &current->thread);
27078 @@ -214,6 +215,14 @@ SYSCALL_DEFINE1(vm86old, struct vm86_struct __user *, v86)
27079
27080 if (tsk->thread.saved_sp0)
27081 return -EPERM;
27082 +
27083 +#ifdef CONFIG_GRKERNSEC_VM86
27084 + if (!capable(CAP_SYS_RAWIO)) {
27085 + gr_handle_vm86();
27086 + return -EPERM;
27087 + }
27088 +#endif
27089 +
27090 tmp = copy_vm86_regs_from_user(&info.regs, &v86->regs,
27091 offsetof(struct kernel_vm86_struct, vm86plus) -
27092 sizeof(info.regs));
27093 @@ -238,6 +247,13 @@ SYSCALL_DEFINE2(vm86, unsigned long, cmd, unsigned long, arg)
27094 int tmp;
27095 struct vm86plus_struct __user *v86;
27096
27097 +#ifdef CONFIG_GRKERNSEC_VM86
27098 + if (!capable(CAP_SYS_RAWIO)) {
27099 + gr_handle_vm86();
27100 + return -EPERM;
27101 + }
27102 +#endif
27103 +
27104 tsk = current;
27105 switch (cmd) {
27106 case VM86_REQUEST_IRQ:
27107 @@ -318,7 +334,7 @@ static void do_sys_vm86(struct kernel_vm86_struct *info, struct task_struct *tsk
27108 tsk->thread.saved_fs = info->regs32->fs;
27109 tsk->thread.saved_gs = get_user_gs(info->regs32);
27110
27111 - tss = &per_cpu(init_tss, get_cpu());
27112 + tss = init_tss + get_cpu();
27113 tsk->thread.sp0 = (unsigned long) &info->VM86_TSS_ESP0;
27114 if (cpu_has_sep)
27115 tsk->thread.sysenter_cs = 0;
27116 @@ -525,7 +541,7 @@ static void do_int(struct kernel_vm86_regs *regs, int i,
27117 goto cannot_handle;
27118 if (i == 0x21 && is_revectored(AH(regs), &KVM86->int21_revectored))
27119 goto cannot_handle;
27120 - intr_ptr = (unsigned long __user *) (i << 2);
27121 + intr_ptr = (__force unsigned long __user *) (i << 2);
27122 if (get_user(segoffs, intr_ptr))
27123 goto cannot_handle;
27124 if ((segoffs >> 16) == BIOSSEG)
27125 diff --git a/arch/x86/kernel/vmlinux.lds.S b/arch/x86/kernel/vmlinux.lds.S
27126 index da6b35a..977e9cf 100644
27127 --- a/arch/x86/kernel/vmlinux.lds.S
27128 +++ b/arch/x86/kernel/vmlinux.lds.S
27129 @@ -26,6 +26,13 @@
27130 #include <asm/page_types.h>
27131 #include <asm/cache.h>
27132 #include <asm/boot.h>
27133 +#include <asm/segment.h>
27134 +
27135 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27136 +#define __KERNEL_TEXT_OFFSET (LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR)
27137 +#else
27138 +#define __KERNEL_TEXT_OFFSET 0
27139 +#endif
27140
27141 #undef i386 /* in case the preprocessor is a 32bit one */
27142
27143 @@ -69,30 +76,43 @@ jiffies_64 = jiffies;
27144
27145 PHDRS {
27146 text PT_LOAD FLAGS(5); /* R_E */
27147 +#ifdef CONFIG_X86_32
27148 + module PT_LOAD FLAGS(5); /* R_E */
27149 +#endif
27150 +#ifdef CONFIG_XEN
27151 + rodata PT_LOAD FLAGS(5); /* R_E */
27152 +#else
27153 + rodata PT_LOAD FLAGS(4); /* R__ */
27154 +#endif
27155 data PT_LOAD FLAGS(6); /* RW_ */
27156 -#ifdef CONFIG_X86_64
27157 + init.begin PT_LOAD FLAGS(6); /* RW_ */
27158 #ifdef CONFIG_SMP
27159 percpu PT_LOAD FLAGS(6); /* RW_ */
27160 #endif
27161 + text.init PT_LOAD FLAGS(5); /* R_E */
27162 + text.exit PT_LOAD FLAGS(5); /* R_E */
27163 init PT_LOAD FLAGS(7); /* RWE */
27164 -#endif
27165 note PT_NOTE FLAGS(0); /* ___ */
27166 }
27167
27168 SECTIONS
27169 {
27170 #ifdef CONFIG_X86_32
27171 - . = LOAD_OFFSET + LOAD_PHYSICAL_ADDR;
27172 - phys_startup_32 = startup_32 - LOAD_OFFSET;
27173 + . = LOAD_OFFSET + ____LOAD_PHYSICAL_ADDR;
27174 #else
27175 - . = __START_KERNEL;
27176 - phys_startup_64 = startup_64 - LOAD_OFFSET;
27177 + . = __START_KERNEL;
27178 #endif
27179
27180 /* Text and read-only data */
27181 - .text : AT(ADDR(.text) - LOAD_OFFSET) {
27182 - _text = .;
27183 + .text (. - __KERNEL_TEXT_OFFSET): AT(ADDR(.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27184 /* bootstrapping code */
27185 +#ifdef CONFIG_X86_32
27186 + phys_startup_32 = startup_32 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27187 +#else
27188 + phys_startup_64 = startup_64 - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27189 +#endif
27190 + __LOAD_PHYSICAL_ADDR = . - LOAD_OFFSET + __KERNEL_TEXT_OFFSET;
27191 + _text = .;
27192 HEAD_TEXT
27193 . = ALIGN(8);
27194 _stext = .;
27195 @@ -104,13 +124,47 @@ SECTIONS
27196 IRQENTRY_TEXT
27197 *(.fixup)
27198 *(.gnu.warning)
27199 - /* End of text section */
27200 - _etext = .;
27201 } :text = 0x9090
27202
27203 - NOTES :text :note
27204 + . += __KERNEL_TEXT_OFFSET;
27205
27206 - EXCEPTION_TABLE(16) :text = 0x9090
27207 +#ifdef CONFIG_X86_32
27208 + . = ALIGN(PAGE_SIZE);
27209 + .module.text : AT(ADDR(.module.text) - LOAD_OFFSET) {
27210 +
27211 +#ifdef CONFIG_PAX_KERNEXEC
27212 + MODULES_EXEC_VADDR = .;
27213 + BYTE(0)
27214 + . += (CONFIG_PAX_KERNEXEC_MODULE_TEXT * 1024 * 1024);
27215 + . = ALIGN(HPAGE_SIZE) - 1;
27216 + MODULES_EXEC_END = .;
27217 +#endif
27218 +
27219 + } :module
27220 +#endif
27221 +
27222 + .text.end : AT(ADDR(.text.end) - LOAD_OFFSET) {
27223 + /* End of text section */
27224 + BYTE(0)
27225 + _etext = . - __KERNEL_TEXT_OFFSET;
27226 + }
27227 +
27228 +#ifdef CONFIG_X86_32
27229 + . = ALIGN(PAGE_SIZE);
27230 + .rodata.page_aligned : AT(ADDR(.rodata.page_aligned) - LOAD_OFFSET) {
27231 + . = ALIGN(PAGE_SIZE);
27232 + *(.empty_zero_page)
27233 + *(.initial_pg_fixmap)
27234 + *(.initial_pg_pmd)
27235 + *(.initial_page_table)
27236 + *(.swapper_pg_dir)
27237 + } :rodata
27238 +#endif
27239 +
27240 + . = ALIGN(PAGE_SIZE);
27241 + NOTES :rodata :note
27242 +
27243 + EXCEPTION_TABLE(16) :rodata
27244
27245 #if defined(CONFIG_DEBUG_RODATA)
27246 /* .text should occupy whole number of pages */
27247 @@ -122,16 +176,20 @@ SECTIONS
27248
27249 /* Data */
27250 .data : AT(ADDR(.data) - LOAD_OFFSET) {
27251 +
27252 +#ifdef CONFIG_PAX_KERNEXEC
27253 + . = ALIGN(HPAGE_SIZE);
27254 +#else
27255 + . = ALIGN(PAGE_SIZE);
27256 +#endif
27257 +
27258 /* Start of data section */
27259 _sdata = .;
27260
27261 /* init_task */
27262 INIT_TASK_DATA(THREAD_SIZE)
27263
27264 -#ifdef CONFIG_X86_32
27265 - /* 32 bit has nosave before _edata */
27266 NOSAVE_DATA
27267 -#endif
27268
27269 PAGE_ALIGNED_DATA(PAGE_SIZE)
27270
27271 @@ -172,12 +230,19 @@ SECTIONS
27272 #endif /* CONFIG_X86_64 */
27273
27274 /* Init code and data - will be freed after init */
27275 - . = ALIGN(PAGE_SIZE);
27276 .init.begin : AT(ADDR(.init.begin) - LOAD_OFFSET) {
27277 + BYTE(0)
27278 +
27279 +#ifdef CONFIG_PAX_KERNEXEC
27280 + . = ALIGN(HPAGE_SIZE);
27281 +#else
27282 + . = ALIGN(PAGE_SIZE);
27283 +#endif
27284 +
27285 __init_begin = .; /* paired with __init_end */
27286 - }
27287 + } :init.begin
27288
27289 -#if defined(CONFIG_X86_64) && defined(CONFIG_SMP)
27290 +#ifdef CONFIG_SMP
27291 /*
27292 * percpu offsets are zero-based on SMP. PERCPU_VADDR() changes the
27293 * output PHDR, so the next output section - .init.text - should
27294 @@ -186,12 +251,27 @@ SECTIONS
27295 PERCPU_VADDR(INTERNODE_CACHE_BYTES, 0, :percpu)
27296 #endif
27297
27298 - INIT_TEXT_SECTION(PAGE_SIZE)
27299 -#ifdef CONFIG_X86_64
27300 - :init
27301 -#endif
27302 + . = ALIGN(PAGE_SIZE);
27303 + init_begin = .;
27304 + .init.text (. - __KERNEL_TEXT_OFFSET): AT(init_begin - LOAD_OFFSET) {
27305 + VMLINUX_SYMBOL(_sinittext) = .;
27306 + INIT_TEXT
27307 + VMLINUX_SYMBOL(_einittext) = .;
27308 + . = ALIGN(PAGE_SIZE);
27309 + } :text.init
27310
27311 - INIT_DATA_SECTION(16)
27312 + /*
27313 + * .exit.text is discard at runtime, not link time, to deal with
27314 + * references from .altinstructions and .eh_frame
27315 + */
27316 + .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET + __KERNEL_TEXT_OFFSET) {
27317 + EXIT_TEXT
27318 + . = ALIGN(16);
27319 + } :text.exit
27320 + . = init_begin + SIZEOF(.init.text) + SIZEOF(.exit.text);
27321 +
27322 + . = ALIGN(PAGE_SIZE);
27323 + INIT_DATA_SECTION(16) :init
27324
27325 .x86_cpu_dev.init : AT(ADDR(.x86_cpu_dev.init) - LOAD_OFFSET) {
27326 __x86_cpu_dev_start = .;
27327 @@ -262,19 +342,12 @@ SECTIONS
27328 }
27329
27330 . = ALIGN(8);
27331 - /*
27332 - * .exit.text is discard at runtime, not link time, to deal with
27333 - * references from .altinstructions and .eh_frame
27334 - */
27335 - .exit.text : AT(ADDR(.exit.text) - LOAD_OFFSET) {
27336 - EXIT_TEXT
27337 - }
27338
27339 .exit.data : AT(ADDR(.exit.data) - LOAD_OFFSET) {
27340 EXIT_DATA
27341 }
27342
27343 -#if !defined(CONFIG_X86_64) || !defined(CONFIG_SMP)
27344 +#ifndef CONFIG_SMP
27345 PERCPU_SECTION(INTERNODE_CACHE_BYTES)
27346 #endif
27347
27348 @@ -293,16 +366,10 @@ SECTIONS
27349 .smp_locks : AT(ADDR(.smp_locks) - LOAD_OFFSET) {
27350 __smp_locks = .;
27351 *(.smp_locks)
27352 - . = ALIGN(PAGE_SIZE);
27353 __smp_locks_end = .;
27354 + . = ALIGN(PAGE_SIZE);
27355 }
27356
27357 -#ifdef CONFIG_X86_64
27358 - .data_nosave : AT(ADDR(.data_nosave) - LOAD_OFFSET) {
27359 - NOSAVE_DATA
27360 - }
27361 -#endif
27362 -
27363 /* BSS */
27364 . = ALIGN(PAGE_SIZE);
27365 .bss : AT(ADDR(.bss) - LOAD_OFFSET) {
27366 @@ -318,6 +385,7 @@ SECTIONS
27367 __brk_base = .;
27368 . += 64 * 1024; /* 64k alignment slop space */
27369 *(.brk_reservation) /* areas brk users have reserved */
27370 + . = ALIGN(HPAGE_SIZE);
27371 __brk_limit = .;
27372 }
27373
27374 @@ -344,13 +412,12 @@ SECTIONS
27375 * for the boot processor.
27376 */
27377 #define INIT_PER_CPU(x) init_per_cpu__##x = x + __per_cpu_load
27378 -INIT_PER_CPU(gdt_page);
27379 INIT_PER_CPU(irq_stack_union);
27380
27381 /*
27382 * Build-time check on the image size:
27383 */
27384 -. = ASSERT((_end - _text <= KERNEL_IMAGE_SIZE),
27385 +. = ASSERT((_end - _text - __KERNEL_TEXT_OFFSET <= KERNEL_IMAGE_SIZE),
27386 "kernel image bigger than KERNEL_IMAGE_SIZE");
27387
27388 #ifdef CONFIG_SMP
27389 diff --git a/arch/x86/kernel/vsyscall_64.c b/arch/x86/kernel/vsyscall_64.c
27390 index 1f96f93..d5c8f7a 100644
27391 --- a/arch/x86/kernel/vsyscall_64.c
27392 +++ b/arch/x86/kernel/vsyscall_64.c
27393 @@ -56,15 +56,13 @@
27394 DEFINE_VVAR(int, vgetcpu_mode);
27395 DEFINE_VVAR(struct vsyscall_gtod_data, vsyscall_gtod_data);
27396
27397 -static enum { EMULATE, NATIVE, NONE } vsyscall_mode = EMULATE;
27398 +static enum { EMULATE, NONE } vsyscall_mode = EMULATE;
27399
27400 static int __init vsyscall_setup(char *str)
27401 {
27402 if (str) {
27403 if (!strcmp("emulate", str))
27404 vsyscall_mode = EMULATE;
27405 - else if (!strcmp("native", str))
27406 - vsyscall_mode = NATIVE;
27407 else if (!strcmp("none", str))
27408 vsyscall_mode = NONE;
27409 else
27410 @@ -323,8 +321,7 @@ do_ret:
27411 return true;
27412
27413 sigsegv:
27414 - force_sig(SIGSEGV, current);
27415 - return true;
27416 + do_group_exit(SIGKILL);
27417 }
27418
27419 /*
27420 @@ -377,10 +374,7 @@ void __init map_vsyscall(void)
27421 extern char __vvar_page;
27422 unsigned long physaddr_vvar_page = __pa_symbol(&__vvar_page);
27423
27424 - __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall,
27425 - vsyscall_mode == NATIVE
27426 - ? PAGE_KERNEL_VSYSCALL
27427 - : PAGE_KERNEL_VVAR);
27428 + __set_fixmap(VSYSCALL_FIRST_PAGE, physaddr_vsyscall, PAGE_KERNEL_VVAR);
27429 BUILD_BUG_ON((unsigned long)__fix_to_virt(VSYSCALL_FIRST_PAGE) !=
27430 (unsigned long)VSYSCALL_START);
27431
27432 diff --git a/arch/x86/kernel/x8664_ksyms_64.c b/arch/x86/kernel/x8664_ksyms_64.c
27433 index 04068192..4d75aa6 100644
27434 --- a/arch/x86/kernel/x8664_ksyms_64.c
27435 +++ b/arch/x86/kernel/x8664_ksyms_64.c
27436 @@ -34,8 +34,6 @@ EXPORT_SYMBOL(copy_user_generic_string);
27437 EXPORT_SYMBOL(copy_user_generic_unrolled);
27438 EXPORT_SYMBOL(copy_user_enhanced_fast_string);
27439 EXPORT_SYMBOL(__copy_user_nocache);
27440 -EXPORT_SYMBOL(_copy_from_user);
27441 -EXPORT_SYMBOL(_copy_to_user);
27442
27443 EXPORT_SYMBOL(copy_page);
27444 EXPORT_SYMBOL(clear_page);
27445 @@ -73,3 +71,7 @@ EXPORT_SYMBOL(___preempt_schedule);
27446 EXPORT_SYMBOL(___preempt_schedule_context);
27447 #endif
27448 #endif
27449 +
27450 +#ifdef CONFIG_PAX_PER_CPU_PGD
27451 +EXPORT_SYMBOL(cpu_pgd);
27452 +#endif
27453 diff --git a/arch/x86/kernel/x86_init.c b/arch/x86/kernel/x86_init.c
27454 index 021783b..6511282 100644
27455 --- a/arch/x86/kernel/x86_init.c
27456 +++ b/arch/x86/kernel/x86_init.c
27457 @@ -93,7 +93,7 @@ struct x86_cpuinit_ops x86_cpuinit = {
27458 static void default_nmi_init(void) { };
27459 static int default_i8042_detect(void) { return 1; };
27460
27461 -struct x86_platform_ops x86_platform = {
27462 +struct x86_platform_ops x86_platform __read_only = {
27463 .calibrate_tsc = native_calibrate_tsc,
27464 .get_wallclock = mach_get_cmos_time,
27465 .set_wallclock = mach_set_rtc_mmss,
27466 @@ -109,7 +109,7 @@ struct x86_platform_ops x86_platform = {
27467 EXPORT_SYMBOL_GPL(x86_platform);
27468
27469 #if defined(CONFIG_PCI_MSI)
27470 -struct x86_msi_ops x86_msi = {
27471 +struct x86_msi_ops x86_msi __read_only = {
27472 .setup_msi_irqs = native_setup_msi_irqs,
27473 .compose_msi_msg = native_compose_msi_msg,
27474 .teardown_msi_irq = native_teardown_msi_irq,
27475 @@ -150,7 +150,7 @@ u32 arch_msix_mask_irq(struct msi_desc *desc, u32 flag)
27476 }
27477 #endif
27478
27479 -struct x86_io_apic_ops x86_io_apic_ops = {
27480 +struct x86_io_apic_ops x86_io_apic_ops __read_only = {
27481 .init = native_io_apic_init_mappings,
27482 .read = native_io_apic_read,
27483 .write = native_io_apic_write,
27484 diff --git a/arch/x86/kernel/xsave.c b/arch/x86/kernel/xsave.c
27485 index 422fd82..b2d262e 100644
27486 --- a/arch/x86/kernel/xsave.c
27487 +++ b/arch/x86/kernel/xsave.c
27488 @@ -164,18 +164,18 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
27489
27490 /* Setup the bytes not touched by the [f]xsave and reserved for SW. */
27491 sw_bytes = ia32_frame ? &fx_sw_reserved_ia32 : &fx_sw_reserved;
27492 - err = __copy_to_user(&x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27493 + err = __copy_to_user(x->i387.sw_reserved, sw_bytes, sizeof(*sw_bytes));
27494
27495 if (!use_xsave())
27496 return err;
27497
27498 - err |= __put_user(FP_XSTATE_MAGIC2, (__u32 *)(buf + xstate_size));
27499 + err |= __put_user(FP_XSTATE_MAGIC2, (__u32 __user *)(buf + xstate_size));
27500
27501 /*
27502 * Read the xstate_bv which we copied (directly from the cpu or
27503 * from the state in task struct) to the user buffers.
27504 */
27505 - err |= __get_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
27506 + err |= __get_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
27507
27508 /*
27509 * For legacy compatible, we always set FP/SSE bits in the bit
27510 @@ -190,7 +190,7 @@ static inline int save_xstate_epilog(void __user *buf, int ia32_frame)
27511 */
27512 xstate_bv |= XSTATE_FPSSE;
27513
27514 - err |= __put_user(xstate_bv, (__u32 *)&x->xsave_hdr.xstate_bv);
27515 + err |= __put_user(xstate_bv, (__u32 __user *)&x->xsave_hdr.xstate_bv);
27516
27517 return err;
27518 }
27519 @@ -199,6 +199,7 @@ static inline int save_user_xstate(struct xsave_struct __user *buf)
27520 {
27521 int err;
27522
27523 + buf = (struct xsave_struct __user *)____m(buf);
27524 if (use_xsave())
27525 err = xsave_user(buf);
27526 else if (use_fxsr())
27527 @@ -311,6 +312,7 @@ sanitize_restored_xstate(struct task_struct *tsk,
27528 */
27529 static inline int restore_user_xstate(void __user *buf, u64 xbv, int fx_only)
27530 {
27531 + buf = (void __user *)____m(buf);
27532 if (use_xsave()) {
27533 if ((unsigned long)buf % 64 || fx_only) {
27534 u64 init_bv = pcntxt_mask & ~XSTATE_FPSSE;
27535 diff --git a/arch/x86/kvm/cpuid.c b/arch/x86/kvm/cpuid.c
27536 index c697625..a032162 100644
27537 --- a/arch/x86/kvm/cpuid.c
27538 +++ b/arch/x86/kvm/cpuid.c
27539 @@ -156,15 +156,20 @@ int kvm_vcpu_ioctl_set_cpuid2(struct kvm_vcpu *vcpu,
27540 struct kvm_cpuid2 *cpuid,
27541 struct kvm_cpuid_entry2 __user *entries)
27542 {
27543 - int r;
27544 + int r, i;
27545
27546 r = -E2BIG;
27547 if (cpuid->nent > KVM_MAX_CPUID_ENTRIES)
27548 goto out;
27549 r = -EFAULT;
27550 - if (copy_from_user(&vcpu->arch.cpuid_entries, entries,
27551 - cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
27552 + if (!access_ok(VERIFY_READ, entries, cpuid->nent * sizeof(struct kvm_cpuid_entry2)))
27553 goto out;
27554 + for (i = 0; i < cpuid->nent; ++i) {
27555 + struct kvm_cpuid_entry2 cpuid_entry;
27556 + if (__copy_from_user(&cpuid_entry, entries + i, sizeof(cpuid_entry)))
27557 + goto out;
27558 + vcpu->arch.cpuid_entries[i] = cpuid_entry;
27559 + }
27560 vcpu->arch.cpuid_nent = cpuid->nent;
27561 kvm_apic_set_version(vcpu);
27562 kvm_x86_ops->cpuid_update(vcpu);
27563 @@ -179,15 +184,19 @@ int kvm_vcpu_ioctl_get_cpuid2(struct kvm_vcpu *vcpu,
27564 struct kvm_cpuid2 *cpuid,
27565 struct kvm_cpuid_entry2 __user *entries)
27566 {
27567 - int r;
27568 + int r, i;
27569
27570 r = -E2BIG;
27571 if (cpuid->nent < vcpu->arch.cpuid_nent)
27572 goto out;
27573 r = -EFAULT;
27574 - if (copy_to_user(entries, &vcpu->arch.cpuid_entries,
27575 - vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
27576 + if (!access_ok(VERIFY_WRITE, entries, vcpu->arch.cpuid_nent * sizeof(struct kvm_cpuid_entry2)))
27577 goto out;
27578 + for (i = 0; i < vcpu->arch.cpuid_nent; ++i) {
27579 + struct kvm_cpuid_entry2 cpuid_entry = vcpu->arch.cpuid_entries[i];
27580 + if (__copy_to_user(entries + i, &cpuid_entry, sizeof(cpuid_entry)))
27581 + goto out;
27582 + }
27583 return 0;
27584
27585 out:
27586 diff --git a/arch/x86/kvm/lapic.c b/arch/x86/kvm/lapic.c
27587 index d86ff15..e77b023 100644
27588 --- a/arch/x86/kvm/lapic.c
27589 +++ b/arch/x86/kvm/lapic.c
27590 @@ -55,7 +55,7 @@
27591 #define APIC_BUS_CYCLE_NS 1
27592
27593 /* #define apic_debug(fmt,arg...) printk(KERN_WARNING fmt,##arg) */
27594 -#define apic_debug(fmt, arg...)
27595 +#define apic_debug(fmt, arg...) do {} while (0)
27596
27597 #define APIC_LVT_NUM 6
27598 /* 14 is the version for Xeon and Pentium 8.4.8*/
27599 diff --git a/arch/x86/kvm/paging_tmpl.h b/arch/x86/kvm/paging_tmpl.h
27600 index ad75d77..a679d32 100644
27601 --- a/arch/x86/kvm/paging_tmpl.h
27602 +++ b/arch/x86/kvm/paging_tmpl.h
27603 @@ -331,7 +331,7 @@ retry_walk:
27604 if (unlikely(kvm_is_error_hva(host_addr)))
27605 goto error;
27606
27607 - ptep_user = (pt_element_t __user *)((void *)host_addr + offset);
27608 + ptep_user = (pt_element_t __force_user *)((void *)host_addr + offset);
27609 if (unlikely(__copy_from_user(&pte, ptep_user, sizeof(pte))))
27610 goto error;
27611 walker->ptep_user[walker->level - 1] = ptep_user;
27612 diff --git a/arch/x86/kvm/svm.c b/arch/x86/kvm/svm.c
27613 index c7168a5..09070fc 100644
27614 --- a/arch/x86/kvm/svm.c
27615 +++ b/arch/x86/kvm/svm.c
27616 @@ -3497,7 +3497,11 @@ static void reload_tss(struct kvm_vcpu *vcpu)
27617 int cpu = raw_smp_processor_id();
27618
27619 struct svm_cpu_data *sd = per_cpu(svm_data, cpu);
27620 +
27621 + pax_open_kernel();
27622 sd->tss_desc->type = 9; /* available 32/64-bit TSS */
27623 + pax_close_kernel();
27624 +
27625 load_TR_desc();
27626 }
27627
27628 @@ -3898,6 +3902,10 @@ static void svm_vcpu_run(struct kvm_vcpu *vcpu)
27629 #endif
27630 #endif
27631
27632 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
27633 + __set_fs(current_thread_info()->addr_limit);
27634 +#endif
27635 +
27636 reload_tss(vcpu);
27637
27638 local_irq_disable();
27639 diff --git a/arch/x86/kvm/vmx.c b/arch/x86/kvm/vmx.c
27640 index da7837e..86c6ebf 100644
27641 --- a/arch/x86/kvm/vmx.c
27642 +++ b/arch/x86/kvm/vmx.c
27643 @@ -1316,12 +1316,12 @@ static void vmcs_write64(unsigned long field, u64 value)
27644 #endif
27645 }
27646
27647 -static void vmcs_clear_bits(unsigned long field, u32 mask)
27648 +static void vmcs_clear_bits(unsigned long field, unsigned long mask)
27649 {
27650 vmcs_writel(field, vmcs_readl(field) & ~mask);
27651 }
27652
27653 -static void vmcs_set_bits(unsigned long field, u32 mask)
27654 +static void vmcs_set_bits(unsigned long field, unsigned long mask)
27655 {
27656 vmcs_writel(field, vmcs_readl(field) | mask);
27657 }
27658 @@ -1522,7 +1522,11 @@ static void reload_tss(void)
27659 struct desc_struct *descs;
27660
27661 descs = (void *)gdt->address;
27662 +
27663 + pax_open_kernel();
27664 descs[GDT_ENTRY_TSS].type = 9; /* available TSS */
27665 + pax_close_kernel();
27666 +
27667 load_TR_desc();
27668 }
27669
27670 @@ -1746,6 +1750,10 @@ static void vmx_vcpu_load(struct kvm_vcpu *vcpu, int cpu)
27671 vmcs_writel(HOST_TR_BASE, kvm_read_tr_base()); /* 22.2.4 */
27672 vmcs_writel(HOST_GDTR_BASE, gdt->address); /* 22.2.4 */
27673
27674 +#ifdef CONFIG_PAX_PER_CPU_PGD
27675 + vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
27676 +#endif
27677 +
27678 rdmsrl(MSR_IA32_SYSENTER_ESP, sysenter_esp);
27679 vmcs_writel(HOST_IA32_SYSENTER_ESP, sysenter_esp); /* 22.2.3 */
27680 vmx->loaded_vmcs->cpu = cpu;
27681 @@ -2033,7 +2041,7 @@ static void setup_msrs(struct vcpu_vmx *vmx)
27682 * reads and returns guest's timestamp counter "register"
27683 * guest_tsc = host_tsc + tsc_offset -- 21.3
27684 */
27685 -static u64 guest_read_tsc(void)
27686 +static u64 __intentional_overflow(-1) guest_read_tsc(void)
27687 {
27688 u64 host_tsc, tsc_offset;
27689
27690 @@ -2987,8 +2995,11 @@ static __init int hardware_setup(void)
27691 if (!cpu_has_vmx_flexpriority())
27692 flexpriority_enabled = 0;
27693
27694 - if (!cpu_has_vmx_tpr_shadow())
27695 - kvm_x86_ops->update_cr8_intercept = NULL;
27696 + if (!cpu_has_vmx_tpr_shadow()) {
27697 + pax_open_kernel();
27698 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
27699 + pax_close_kernel();
27700 + }
27701
27702 if (enable_ept && !cpu_has_vmx_ept_2m_page())
27703 kvm_disable_largepages();
27704 @@ -2999,13 +3010,15 @@ static __init int hardware_setup(void)
27705 if (!cpu_has_vmx_apicv())
27706 enable_apicv = 0;
27707
27708 + pax_open_kernel();
27709 if (enable_apicv)
27710 - kvm_x86_ops->update_cr8_intercept = NULL;
27711 + *(void **)&kvm_x86_ops->update_cr8_intercept = NULL;
27712 else {
27713 - kvm_x86_ops->hwapic_irr_update = NULL;
27714 - kvm_x86_ops->deliver_posted_interrupt = NULL;
27715 - kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
27716 + *(void **)&kvm_x86_ops->hwapic_irr_update = NULL;
27717 + *(void **)&kvm_x86_ops->deliver_posted_interrupt = NULL;
27718 + *(void **)&kvm_x86_ops->sync_pir_to_irr = vmx_sync_pir_to_irr_dummy;
27719 }
27720 + pax_close_kernel();
27721
27722 if (nested)
27723 nested_vmx_setup_ctls_msrs();
27724 @@ -4134,7 +4147,10 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
27725
27726 vmcs_writel(HOST_CR0, read_cr0() & ~X86_CR0_TS); /* 22.2.3 */
27727 vmcs_writel(HOST_CR4, read_cr4()); /* 22.2.3, 22.2.5 */
27728 +
27729 +#ifndef CONFIG_PAX_PER_CPU_PGD
27730 vmcs_writel(HOST_CR3, read_cr3()); /* 22.2.3 FIXME: shadow tables */
27731 +#endif
27732
27733 vmcs_write16(HOST_CS_SELECTOR, __KERNEL_CS); /* 22.2.4 */
27734 #ifdef CONFIG_X86_64
27735 @@ -4156,7 +4172,7 @@ static void vmx_set_constant_host_state(struct vcpu_vmx *vmx)
27736 vmcs_writel(HOST_IDTR_BASE, dt.address); /* 22.2.4 */
27737 vmx->host_idt_base = dt.address;
27738
27739 - vmcs_writel(HOST_RIP, vmx_return); /* 22.2.5 */
27740 + vmcs_writel(HOST_RIP, ktla_ktva(vmx_return)); /* 22.2.5 */
27741
27742 rdmsr(MSR_IA32_SYSENTER_CS, low32, high32);
27743 vmcs_write32(HOST_IA32_SYSENTER_CS, low32);
27744 @@ -7219,6 +7235,12 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27745 "jmp 2f \n\t"
27746 "1: " __ex(ASM_VMX_VMRESUME) "\n\t"
27747 "2: "
27748 +
27749 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27750 + "ljmp %[cs],$3f\n\t"
27751 + "3: "
27752 +#endif
27753 +
27754 /* Save guest registers, load host registers, keep flags */
27755 "mov %0, %c[wordsize](%%" _ASM_SP ") \n\t"
27756 "pop %0 \n\t"
27757 @@ -7271,6 +7293,11 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27758 #endif
27759 [cr2]"i"(offsetof(struct vcpu_vmx, vcpu.arch.cr2)),
27760 [wordsize]"i"(sizeof(ulong))
27761 +
27762 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
27763 + ,[cs]"i"(__KERNEL_CS)
27764 +#endif
27765 +
27766 : "cc", "memory"
27767 #ifdef CONFIG_X86_64
27768 , "rax", "rbx", "rdi", "rsi"
27769 @@ -7284,7 +7311,7 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27770 if (debugctlmsr)
27771 update_debugctlmsr(debugctlmsr);
27772
27773 -#ifndef CONFIG_X86_64
27774 +#ifdef CONFIG_X86_32
27775 /*
27776 * The sysexit path does not restore ds/es, so we must set them to
27777 * a reasonable value ourselves.
27778 @@ -7293,8 +7320,18 @@ static void __noclone vmx_vcpu_run(struct kvm_vcpu *vcpu)
27779 * may be executed in interrupt context, which saves and restore segments
27780 * around it, nullifying its effect.
27781 */
27782 - loadsegment(ds, __USER_DS);
27783 - loadsegment(es, __USER_DS);
27784 + loadsegment(ds, __KERNEL_DS);
27785 + loadsegment(es, __KERNEL_DS);
27786 + loadsegment(ss, __KERNEL_DS);
27787 +
27788 +#ifdef CONFIG_PAX_KERNEXEC
27789 + loadsegment(fs, __KERNEL_PERCPU);
27790 +#endif
27791 +
27792 +#ifdef CONFIG_PAX_MEMORY_UDEREF
27793 + __set_fs(current_thread_info()->addr_limit);
27794 +#endif
27795 +
27796 #endif
27797
27798 vcpu->arch.regs_avail = ~((1 << VCPU_REGS_RIP) | (1 << VCPU_REGS_RSP)
27799 diff --git a/arch/x86/kvm/x86.c b/arch/x86/kvm/x86.c
27800 index d89d51b..f3c612a 100644
27801 --- a/arch/x86/kvm/x86.c
27802 +++ b/arch/x86/kvm/x86.c
27803 @@ -1791,8 +1791,8 @@ static int xen_hvm_config(struct kvm_vcpu *vcpu, u64 data)
27804 {
27805 struct kvm *kvm = vcpu->kvm;
27806 int lm = is_long_mode(vcpu);
27807 - u8 *blob_addr = lm ? (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_64
27808 - : (u8 *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
27809 + u8 __user *blob_addr = lm ? (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_64
27810 + : (u8 __user *)(long)kvm->arch.xen_hvm_config.blob_addr_32;
27811 u8 blob_size = lm ? kvm->arch.xen_hvm_config.blob_size_64
27812 : kvm->arch.xen_hvm_config.blob_size_32;
27813 u32 page_num = data & ~PAGE_MASK;
27814 @@ -2676,6 +2676,8 @@ long kvm_arch_dev_ioctl(struct file *filp,
27815 if (n < msr_list.nmsrs)
27816 goto out;
27817 r = -EFAULT;
27818 + if (num_msrs_to_save > ARRAY_SIZE(msrs_to_save))
27819 + goto out;
27820 if (copy_to_user(user_msr_list->indices, &msrs_to_save,
27821 num_msrs_to_save * sizeof(u32)))
27822 goto out;
27823 @@ -5485,7 +5487,7 @@ static struct notifier_block pvclock_gtod_notifier = {
27824 };
27825 #endif
27826
27827 -int kvm_arch_init(void *opaque)
27828 +int kvm_arch_init(const void *opaque)
27829 {
27830 int r;
27831 struct kvm_x86_ops *ops = opaque;
27832 diff --git a/arch/x86/lguest/boot.c b/arch/x86/lguest/boot.c
27833 index bdf8532..f63c587 100644
27834 --- a/arch/x86/lguest/boot.c
27835 +++ b/arch/x86/lguest/boot.c
27836 @@ -1206,9 +1206,10 @@ static __init int early_put_chars(u32 vtermno, const char *buf, int count)
27837 * Rebooting also tells the Host we're finished, but the RESTART flag tells the
27838 * Launcher to reboot us.
27839 */
27840 -static void lguest_restart(char *reason)
27841 +static __noreturn void lguest_restart(char *reason)
27842 {
27843 hcall(LHCALL_SHUTDOWN, __pa(reason), LGUEST_SHUTDOWN_RESTART, 0, 0);
27844 + BUG();
27845 }
27846
27847 /*G:050
27848 diff --git a/arch/x86/lib/atomic64_386_32.S b/arch/x86/lib/atomic64_386_32.S
27849 index 00933d5..3a64af9 100644
27850 --- a/arch/x86/lib/atomic64_386_32.S
27851 +++ b/arch/x86/lib/atomic64_386_32.S
27852 @@ -48,6 +48,10 @@ BEGIN(read)
27853 movl (v), %eax
27854 movl 4(v), %edx
27855 RET_ENDP
27856 +BEGIN(read_unchecked)
27857 + movl (v), %eax
27858 + movl 4(v), %edx
27859 +RET_ENDP
27860 #undef v
27861
27862 #define v %esi
27863 @@ -55,6 +59,10 @@ BEGIN(set)
27864 movl %ebx, (v)
27865 movl %ecx, 4(v)
27866 RET_ENDP
27867 +BEGIN(set_unchecked)
27868 + movl %ebx, (v)
27869 + movl %ecx, 4(v)
27870 +RET_ENDP
27871 #undef v
27872
27873 #define v %esi
27874 @@ -70,6 +78,20 @@ RET_ENDP
27875 BEGIN(add)
27876 addl %eax, (v)
27877 adcl %edx, 4(v)
27878 +
27879 +#ifdef CONFIG_PAX_REFCOUNT
27880 + jno 0f
27881 + subl %eax, (v)
27882 + sbbl %edx, 4(v)
27883 + int $4
27884 +0:
27885 + _ASM_EXTABLE(0b, 0b)
27886 +#endif
27887 +
27888 +RET_ENDP
27889 +BEGIN(add_unchecked)
27890 + addl %eax, (v)
27891 + adcl %edx, 4(v)
27892 RET_ENDP
27893 #undef v
27894
27895 @@ -77,6 +99,24 @@ RET_ENDP
27896 BEGIN(add_return)
27897 addl (v), %eax
27898 adcl 4(v), %edx
27899 +
27900 +#ifdef CONFIG_PAX_REFCOUNT
27901 + into
27902 +1234:
27903 + _ASM_EXTABLE(1234b, 2f)
27904 +#endif
27905 +
27906 + movl %eax, (v)
27907 + movl %edx, 4(v)
27908 +
27909 +#ifdef CONFIG_PAX_REFCOUNT
27910 +2:
27911 +#endif
27912 +
27913 +RET_ENDP
27914 +BEGIN(add_return_unchecked)
27915 + addl (v), %eax
27916 + adcl 4(v), %edx
27917 movl %eax, (v)
27918 movl %edx, 4(v)
27919 RET_ENDP
27920 @@ -86,6 +126,20 @@ RET_ENDP
27921 BEGIN(sub)
27922 subl %eax, (v)
27923 sbbl %edx, 4(v)
27924 +
27925 +#ifdef CONFIG_PAX_REFCOUNT
27926 + jno 0f
27927 + addl %eax, (v)
27928 + adcl %edx, 4(v)
27929 + int $4
27930 +0:
27931 + _ASM_EXTABLE(0b, 0b)
27932 +#endif
27933 +
27934 +RET_ENDP
27935 +BEGIN(sub_unchecked)
27936 + subl %eax, (v)
27937 + sbbl %edx, 4(v)
27938 RET_ENDP
27939 #undef v
27940
27941 @@ -96,6 +150,27 @@ BEGIN(sub_return)
27942 sbbl $0, %edx
27943 addl (v), %eax
27944 adcl 4(v), %edx
27945 +
27946 +#ifdef CONFIG_PAX_REFCOUNT
27947 + into
27948 +1234:
27949 + _ASM_EXTABLE(1234b, 2f)
27950 +#endif
27951 +
27952 + movl %eax, (v)
27953 + movl %edx, 4(v)
27954 +
27955 +#ifdef CONFIG_PAX_REFCOUNT
27956 +2:
27957 +#endif
27958 +
27959 +RET_ENDP
27960 +BEGIN(sub_return_unchecked)
27961 + negl %edx
27962 + negl %eax
27963 + sbbl $0, %edx
27964 + addl (v), %eax
27965 + adcl 4(v), %edx
27966 movl %eax, (v)
27967 movl %edx, 4(v)
27968 RET_ENDP
27969 @@ -105,6 +180,20 @@ RET_ENDP
27970 BEGIN(inc)
27971 addl $1, (v)
27972 adcl $0, 4(v)
27973 +
27974 +#ifdef CONFIG_PAX_REFCOUNT
27975 + jno 0f
27976 + subl $1, (v)
27977 + sbbl $0, 4(v)
27978 + int $4
27979 +0:
27980 + _ASM_EXTABLE(0b, 0b)
27981 +#endif
27982 +
27983 +RET_ENDP
27984 +BEGIN(inc_unchecked)
27985 + addl $1, (v)
27986 + adcl $0, 4(v)
27987 RET_ENDP
27988 #undef v
27989
27990 @@ -114,6 +203,26 @@ BEGIN(inc_return)
27991 movl 4(v), %edx
27992 addl $1, %eax
27993 adcl $0, %edx
27994 +
27995 +#ifdef CONFIG_PAX_REFCOUNT
27996 + into
27997 +1234:
27998 + _ASM_EXTABLE(1234b, 2f)
27999 +#endif
28000 +
28001 + movl %eax, (v)
28002 + movl %edx, 4(v)
28003 +
28004 +#ifdef CONFIG_PAX_REFCOUNT
28005 +2:
28006 +#endif
28007 +
28008 +RET_ENDP
28009 +BEGIN(inc_return_unchecked)
28010 + movl (v), %eax
28011 + movl 4(v), %edx
28012 + addl $1, %eax
28013 + adcl $0, %edx
28014 movl %eax, (v)
28015 movl %edx, 4(v)
28016 RET_ENDP
28017 @@ -123,6 +232,20 @@ RET_ENDP
28018 BEGIN(dec)
28019 subl $1, (v)
28020 sbbl $0, 4(v)
28021 +
28022 +#ifdef CONFIG_PAX_REFCOUNT
28023 + jno 0f
28024 + addl $1, (v)
28025 + adcl $0, 4(v)
28026 + int $4
28027 +0:
28028 + _ASM_EXTABLE(0b, 0b)
28029 +#endif
28030 +
28031 +RET_ENDP
28032 +BEGIN(dec_unchecked)
28033 + subl $1, (v)
28034 + sbbl $0, 4(v)
28035 RET_ENDP
28036 #undef v
28037
28038 @@ -132,6 +255,26 @@ BEGIN(dec_return)
28039 movl 4(v), %edx
28040 subl $1, %eax
28041 sbbl $0, %edx
28042 +
28043 +#ifdef CONFIG_PAX_REFCOUNT
28044 + into
28045 +1234:
28046 + _ASM_EXTABLE(1234b, 2f)
28047 +#endif
28048 +
28049 + movl %eax, (v)
28050 + movl %edx, 4(v)
28051 +
28052 +#ifdef CONFIG_PAX_REFCOUNT
28053 +2:
28054 +#endif
28055 +
28056 +RET_ENDP
28057 +BEGIN(dec_return_unchecked)
28058 + movl (v), %eax
28059 + movl 4(v), %edx
28060 + subl $1, %eax
28061 + sbbl $0, %edx
28062 movl %eax, (v)
28063 movl %edx, 4(v)
28064 RET_ENDP
28065 @@ -143,6 +286,13 @@ BEGIN(add_unless)
28066 adcl %edx, %edi
28067 addl (v), %eax
28068 adcl 4(v), %edx
28069 +
28070 +#ifdef CONFIG_PAX_REFCOUNT
28071 + into
28072 +1234:
28073 + _ASM_EXTABLE(1234b, 2f)
28074 +#endif
28075 +
28076 cmpl %eax, %ecx
28077 je 3f
28078 1:
28079 @@ -168,6 +318,13 @@ BEGIN(inc_not_zero)
28080 1:
28081 addl $1, %eax
28082 adcl $0, %edx
28083 +
28084 +#ifdef CONFIG_PAX_REFCOUNT
28085 + into
28086 +1234:
28087 + _ASM_EXTABLE(1234b, 2f)
28088 +#endif
28089 +
28090 movl %eax, (v)
28091 movl %edx, 4(v)
28092 movl $1, %eax
28093 @@ -186,6 +343,13 @@ BEGIN(dec_if_positive)
28094 movl 4(v), %edx
28095 subl $1, %eax
28096 sbbl $0, %edx
28097 +
28098 +#ifdef CONFIG_PAX_REFCOUNT
28099 + into
28100 +1234:
28101 + _ASM_EXTABLE(1234b, 1f)
28102 +#endif
28103 +
28104 js 1f
28105 movl %eax, (v)
28106 movl %edx, 4(v)
28107 diff --git a/arch/x86/lib/atomic64_cx8_32.S b/arch/x86/lib/atomic64_cx8_32.S
28108 index f5cc9eb..51fa319 100644
28109 --- a/arch/x86/lib/atomic64_cx8_32.S
28110 +++ b/arch/x86/lib/atomic64_cx8_32.S
28111 @@ -35,10 +35,20 @@ ENTRY(atomic64_read_cx8)
28112 CFI_STARTPROC
28113
28114 read64 %ecx
28115 + pax_force_retaddr
28116 ret
28117 CFI_ENDPROC
28118 ENDPROC(atomic64_read_cx8)
28119
28120 +ENTRY(atomic64_read_unchecked_cx8)
28121 + CFI_STARTPROC
28122 +
28123 + read64 %ecx
28124 + pax_force_retaddr
28125 + ret
28126 + CFI_ENDPROC
28127 +ENDPROC(atomic64_read_unchecked_cx8)
28128 +
28129 ENTRY(atomic64_set_cx8)
28130 CFI_STARTPROC
28131
28132 @@ -48,10 +58,25 @@ ENTRY(atomic64_set_cx8)
28133 cmpxchg8b (%esi)
28134 jne 1b
28135
28136 + pax_force_retaddr
28137 ret
28138 CFI_ENDPROC
28139 ENDPROC(atomic64_set_cx8)
28140
28141 +ENTRY(atomic64_set_unchecked_cx8)
28142 + CFI_STARTPROC
28143 +
28144 +1:
28145 +/* we don't need LOCK_PREFIX since aligned 64-bit writes
28146 + * are atomic on 586 and newer */
28147 + cmpxchg8b (%esi)
28148 + jne 1b
28149 +
28150 + pax_force_retaddr
28151 + ret
28152 + CFI_ENDPROC
28153 +ENDPROC(atomic64_set_unchecked_cx8)
28154 +
28155 ENTRY(atomic64_xchg_cx8)
28156 CFI_STARTPROC
28157
28158 @@ -60,12 +85,13 @@ ENTRY(atomic64_xchg_cx8)
28159 cmpxchg8b (%esi)
28160 jne 1b
28161
28162 + pax_force_retaddr
28163 ret
28164 CFI_ENDPROC
28165 ENDPROC(atomic64_xchg_cx8)
28166
28167 -.macro addsub_return func ins insc
28168 -ENTRY(atomic64_\func\()_return_cx8)
28169 +.macro addsub_return func ins insc unchecked=""
28170 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28171 CFI_STARTPROC
28172 SAVE ebp
28173 SAVE ebx
28174 @@ -82,27 +108,44 @@ ENTRY(atomic64_\func\()_return_cx8)
28175 movl %edx, %ecx
28176 \ins\()l %esi, %ebx
28177 \insc\()l %edi, %ecx
28178 +
28179 +.ifb \unchecked
28180 +#ifdef CONFIG_PAX_REFCOUNT
28181 + into
28182 +2:
28183 + _ASM_EXTABLE(2b, 3f)
28184 +#endif
28185 +.endif
28186 +
28187 LOCK_PREFIX
28188 cmpxchg8b (%ebp)
28189 jne 1b
28190 -
28191 -10:
28192 movl %ebx, %eax
28193 movl %ecx, %edx
28194 +
28195 +.ifb \unchecked
28196 +#ifdef CONFIG_PAX_REFCOUNT
28197 +3:
28198 +#endif
28199 +.endif
28200 +
28201 RESTORE edi
28202 RESTORE esi
28203 RESTORE ebx
28204 RESTORE ebp
28205 + pax_force_retaddr
28206 ret
28207 CFI_ENDPROC
28208 -ENDPROC(atomic64_\func\()_return_cx8)
28209 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28210 .endm
28211
28212 addsub_return add add adc
28213 addsub_return sub sub sbb
28214 +addsub_return add add adc _unchecked
28215 +addsub_return sub sub sbb _unchecked
28216
28217 -.macro incdec_return func ins insc
28218 -ENTRY(atomic64_\func\()_return_cx8)
28219 +.macro incdec_return func ins insc unchecked=""
28220 +ENTRY(atomic64_\func\()_return\unchecked\()_cx8)
28221 CFI_STARTPROC
28222 SAVE ebx
28223
28224 @@ -112,21 +155,39 @@ ENTRY(atomic64_\func\()_return_cx8)
28225 movl %edx, %ecx
28226 \ins\()l $1, %ebx
28227 \insc\()l $0, %ecx
28228 +
28229 +.ifb \unchecked
28230 +#ifdef CONFIG_PAX_REFCOUNT
28231 + into
28232 +2:
28233 + _ASM_EXTABLE(2b, 3f)
28234 +#endif
28235 +.endif
28236 +
28237 LOCK_PREFIX
28238 cmpxchg8b (%esi)
28239 jne 1b
28240
28241 -10:
28242 movl %ebx, %eax
28243 movl %ecx, %edx
28244 +
28245 +.ifb \unchecked
28246 +#ifdef CONFIG_PAX_REFCOUNT
28247 +3:
28248 +#endif
28249 +.endif
28250 +
28251 RESTORE ebx
28252 + pax_force_retaddr
28253 ret
28254 CFI_ENDPROC
28255 -ENDPROC(atomic64_\func\()_return_cx8)
28256 +ENDPROC(atomic64_\func\()_return\unchecked\()_cx8)
28257 .endm
28258
28259 incdec_return inc add adc
28260 incdec_return dec sub sbb
28261 +incdec_return inc add adc _unchecked
28262 +incdec_return dec sub sbb _unchecked
28263
28264 ENTRY(atomic64_dec_if_positive_cx8)
28265 CFI_STARTPROC
28266 @@ -138,6 +199,13 @@ ENTRY(atomic64_dec_if_positive_cx8)
28267 movl %edx, %ecx
28268 subl $1, %ebx
28269 sbb $0, %ecx
28270 +
28271 +#ifdef CONFIG_PAX_REFCOUNT
28272 + into
28273 +1234:
28274 + _ASM_EXTABLE(1234b, 2f)
28275 +#endif
28276 +
28277 js 2f
28278 LOCK_PREFIX
28279 cmpxchg8b (%esi)
28280 @@ -147,6 +215,7 @@ ENTRY(atomic64_dec_if_positive_cx8)
28281 movl %ebx, %eax
28282 movl %ecx, %edx
28283 RESTORE ebx
28284 + pax_force_retaddr
28285 ret
28286 CFI_ENDPROC
28287 ENDPROC(atomic64_dec_if_positive_cx8)
28288 @@ -171,6 +240,13 @@ ENTRY(atomic64_add_unless_cx8)
28289 movl %edx, %ecx
28290 addl %ebp, %ebx
28291 adcl %edi, %ecx
28292 +
28293 +#ifdef CONFIG_PAX_REFCOUNT
28294 + into
28295 +1234:
28296 + _ASM_EXTABLE(1234b, 3f)
28297 +#endif
28298 +
28299 LOCK_PREFIX
28300 cmpxchg8b (%esi)
28301 jne 1b
28302 @@ -181,6 +257,7 @@ ENTRY(atomic64_add_unless_cx8)
28303 CFI_ADJUST_CFA_OFFSET -8
28304 RESTORE ebx
28305 RESTORE ebp
28306 + pax_force_retaddr
28307 ret
28308 4:
28309 cmpl %edx, 4(%esp)
28310 @@ -203,6 +280,13 @@ ENTRY(atomic64_inc_not_zero_cx8)
28311 xorl %ecx, %ecx
28312 addl $1, %ebx
28313 adcl %edx, %ecx
28314 +
28315 +#ifdef CONFIG_PAX_REFCOUNT
28316 + into
28317 +1234:
28318 + _ASM_EXTABLE(1234b, 3f)
28319 +#endif
28320 +
28321 LOCK_PREFIX
28322 cmpxchg8b (%esi)
28323 jne 1b
28324 @@ -210,6 +294,7 @@ ENTRY(atomic64_inc_not_zero_cx8)
28325 movl $1, %eax
28326 3:
28327 RESTORE ebx
28328 + pax_force_retaddr
28329 ret
28330 CFI_ENDPROC
28331 ENDPROC(atomic64_inc_not_zero_cx8)
28332 diff --git a/arch/x86/lib/checksum_32.S b/arch/x86/lib/checksum_32.S
28333 index e78b8ee..7e173a8 100644
28334 --- a/arch/x86/lib/checksum_32.S
28335 +++ b/arch/x86/lib/checksum_32.S
28336 @@ -29,7 +29,8 @@
28337 #include <asm/dwarf2.h>
28338 #include <asm/errno.h>
28339 #include <asm/asm.h>
28340 -
28341 +#include <asm/segment.h>
28342 +
28343 /*
28344 * computes a partial checksum, e.g. for TCP/UDP fragments
28345 */
28346 @@ -293,9 +294,24 @@ unsigned int csum_partial_copy_generic (const char *src, char *dst,
28347
28348 #define ARGBASE 16
28349 #define FP 12
28350 -
28351 -ENTRY(csum_partial_copy_generic)
28352 +
28353 +ENTRY(csum_partial_copy_generic_to_user)
28354 CFI_STARTPROC
28355 +
28356 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28357 + pushl_cfi %gs
28358 + popl_cfi %es
28359 + jmp csum_partial_copy_generic
28360 +#endif
28361 +
28362 +ENTRY(csum_partial_copy_generic_from_user)
28363 +
28364 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28365 + pushl_cfi %gs
28366 + popl_cfi %ds
28367 +#endif
28368 +
28369 +ENTRY(csum_partial_copy_generic)
28370 subl $4,%esp
28371 CFI_ADJUST_CFA_OFFSET 4
28372 pushl_cfi %edi
28373 @@ -317,7 +333,7 @@ ENTRY(csum_partial_copy_generic)
28374 jmp 4f
28375 SRC(1: movw (%esi), %bx )
28376 addl $2, %esi
28377 -DST( movw %bx, (%edi) )
28378 +DST( movw %bx, %es:(%edi) )
28379 addl $2, %edi
28380 addw %bx, %ax
28381 adcl $0, %eax
28382 @@ -329,30 +345,30 @@ DST( movw %bx, (%edi) )
28383 SRC(1: movl (%esi), %ebx )
28384 SRC( movl 4(%esi), %edx )
28385 adcl %ebx, %eax
28386 -DST( movl %ebx, (%edi) )
28387 +DST( movl %ebx, %es:(%edi) )
28388 adcl %edx, %eax
28389 -DST( movl %edx, 4(%edi) )
28390 +DST( movl %edx, %es:4(%edi) )
28391
28392 SRC( movl 8(%esi), %ebx )
28393 SRC( movl 12(%esi), %edx )
28394 adcl %ebx, %eax
28395 -DST( movl %ebx, 8(%edi) )
28396 +DST( movl %ebx, %es:8(%edi) )
28397 adcl %edx, %eax
28398 -DST( movl %edx, 12(%edi) )
28399 +DST( movl %edx, %es:12(%edi) )
28400
28401 SRC( movl 16(%esi), %ebx )
28402 SRC( movl 20(%esi), %edx )
28403 adcl %ebx, %eax
28404 -DST( movl %ebx, 16(%edi) )
28405 +DST( movl %ebx, %es:16(%edi) )
28406 adcl %edx, %eax
28407 -DST( movl %edx, 20(%edi) )
28408 +DST( movl %edx, %es:20(%edi) )
28409
28410 SRC( movl 24(%esi), %ebx )
28411 SRC( movl 28(%esi), %edx )
28412 adcl %ebx, %eax
28413 -DST( movl %ebx, 24(%edi) )
28414 +DST( movl %ebx, %es:24(%edi) )
28415 adcl %edx, %eax
28416 -DST( movl %edx, 28(%edi) )
28417 +DST( movl %edx, %es:28(%edi) )
28418
28419 lea 32(%esi), %esi
28420 lea 32(%edi), %edi
28421 @@ -366,7 +382,7 @@ DST( movl %edx, 28(%edi) )
28422 shrl $2, %edx # This clears CF
28423 SRC(3: movl (%esi), %ebx )
28424 adcl %ebx, %eax
28425 -DST( movl %ebx, (%edi) )
28426 +DST( movl %ebx, %es:(%edi) )
28427 lea 4(%esi), %esi
28428 lea 4(%edi), %edi
28429 dec %edx
28430 @@ -378,12 +394,12 @@ DST( movl %ebx, (%edi) )
28431 jb 5f
28432 SRC( movw (%esi), %cx )
28433 leal 2(%esi), %esi
28434 -DST( movw %cx, (%edi) )
28435 +DST( movw %cx, %es:(%edi) )
28436 leal 2(%edi), %edi
28437 je 6f
28438 shll $16,%ecx
28439 SRC(5: movb (%esi), %cl )
28440 -DST( movb %cl, (%edi) )
28441 +DST( movb %cl, %es:(%edi) )
28442 6: addl %ecx, %eax
28443 adcl $0, %eax
28444 7:
28445 @@ -394,7 +410,7 @@ DST( movb %cl, (%edi) )
28446
28447 6001:
28448 movl ARGBASE+20(%esp), %ebx # src_err_ptr
28449 - movl $-EFAULT, (%ebx)
28450 + movl $-EFAULT, %ss:(%ebx)
28451
28452 # zero the complete destination - computing the rest
28453 # is too much work
28454 @@ -407,11 +423,15 @@ DST( movb %cl, (%edi) )
28455
28456 6002:
28457 movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28458 - movl $-EFAULT,(%ebx)
28459 + movl $-EFAULT,%ss:(%ebx)
28460 jmp 5000b
28461
28462 .previous
28463
28464 + pushl_cfi %ss
28465 + popl_cfi %ds
28466 + pushl_cfi %ss
28467 + popl_cfi %es
28468 popl_cfi %ebx
28469 CFI_RESTORE ebx
28470 popl_cfi %esi
28471 @@ -421,26 +441,43 @@ DST( movb %cl, (%edi) )
28472 popl_cfi %ecx # equivalent to addl $4,%esp
28473 ret
28474 CFI_ENDPROC
28475 -ENDPROC(csum_partial_copy_generic)
28476 +ENDPROC(csum_partial_copy_generic_to_user)
28477
28478 #else
28479
28480 /* Version for PentiumII/PPro */
28481
28482 #define ROUND1(x) \
28483 + nop; nop; nop; \
28484 SRC(movl x(%esi), %ebx ) ; \
28485 addl %ebx, %eax ; \
28486 - DST(movl %ebx, x(%edi) ) ;
28487 + DST(movl %ebx, %es:x(%edi)) ;
28488
28489 #define ROUND(x) \
28490 + nop; nop; nop; \
28491 SRC(movl x(%esi), %ebx ) ; \
28492 adcl %ebx, %eax ; \
28493 - DST(movl %ebx, x(%edi) ) ;
28494 + DST(movl %ebx, %es:x(%edi)) ;
28495
28496 #define ARGBASE 12
28497 -
28498 -ENTRY(csum_partial_copy_generic)
28499 +
28500 +ENTRY(csum_partial_copy_generic_to_user)
28501 CFI_STARTPROC
28502 +
28503 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28504 + pushl_cfi %gs
28505 + popl_cfi %es
28506 + jmp csum_partial_copy_generic
28507 +#endif
28508 +
28509 +ENTRY(csum_partial_copy_generic_from_user)
28510 +
28511 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28512 + pushl_cfi %gs
28513 + popl_cfi %ds
28514 +#endif
28515 +
28516 +ENTRY(csum_partial_copy_generic)
28517 pushl_cfi %ebx
28518 CFI_REL_OFFSET ebx, 0
28519 pushl_cfi %edi
28520 @@ -461,7 +498,7 @@ ENTRY(csum_partial_copy_generic)
28521 subl %ebx, %edi
28522 lea -1(%esi),%edx
28523 andl $-32,%edx
28524 - lea 3f(%ebx,%ebx), %ebx
28525 + lea 3f(%ebx,%ebx,2), %ebx
28526 testl %esi, %esi
28527 jmp *%ebx
28528 1: addl $64,%esi
28529 @@ -482,19 +519,19 @@ ENTRY(csum_partial_copy_generic)
28530 jb 5f
28531 SRC( movw (%esi), %dx )
28532 leal 2(%esi), %esi
28533 -DST( movw %dx, (%edi) )
28534 +DST( movw %dx, %es:(%edi) )
28535 leal 2(%edi), %edi
28536 je 6f
28537 shll $16,%edx
28538 5:
28539 SRC( movb (%esi), %dl )
28540 -DST( movb %dl, (%edi) )
28541 +DST( movb %dl, %es:(%edi) )
28542 6: addl %edx, %eax
28543 adcl $0, %eax
28544 7:
28545 .section .fixup, "ax"
28546 6001: movl ARGBASE+20(%esp), %ebx # src_err_ptr
28547 - movl $-EFAULT, (%ebx)
28548 + movl $-EFAULT, %ss:(%ebx)
28549 # zero the complete destination (computing the rest is too much work)
28550 movl ARGBASE+8(%esp),%edi # dst
28551 movl ARGBASE+12(%esp),%ecx # len
28552 @@ -502,10 +539,17 @@ DST( movb %dl, (%edi) )
28553 rep; stosb
28554 jmp 7b
28555 6002: movl ARGBASE+24(%esp), %ebx # dst_err_ptr
28556 - movl $-EFAULT, (%ebx)
28557 + movl $-EFAULT, %ss:(%ebx)
28558 jmp 7b
28559 .previous
28560
28561 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28562 + pushl_cfi %ss
28563 + popl_cfi %ds
28564 + pushl_cfi %ss
28565 + popl_cfi %es
28566 +#endif
28567 +
28568 popl_cfi %esi
28569 CFI_RESTORE esi
28570 popl_cfi %edi
28571 @@ -514,7 +558,7 @@ DST( movb %dl, (%edi) )
28572 CFI_RESTORE ebx
28573 ret
28574 CFI_ENDPROC
28575 -ENDPROC(csum_partial_copy_generic)
28576 +ENDPROC(csum_partial_copy_generic_to_user)
28577
28578 #undef ROUND
28579 #undef ROUND1
28580 diff --git a/arch/x86/lib/clear_page_64.S b/arch/x86/lib/clear_page_64.S
28581 index f2145cf..cea889d 100644
28582 --- a/arch/x86/lib/clear_page_64.S
28583 +++ b/arch/x86/lib/clear_page_64.S
28584 @@ -11,6 +11,7 @@ ENTRY(clear_page_c)
28585 movl $4096/8,%ecx
28586 xorl %eax,%eax
28587 rep stosq
28588 + pax_force_retaddr
28589 ret
28590 CFI_ENDPROC
28591 ENDPROC(clear_page_c)
28592 @@ -20,6 +21,7 @@ ENTRY(clear_page_c_e)
28593 movl $4096,%ecx
28594 xorl %eax,%eax
28595 rep stosb
28596 + pax_force_retaddr
28597 ret
28598 CFI_ENDPROC
28599 ENDPROC(clear_page_c_e)
28600 @@ -43,6 +45,7 @@ ENTRY(clear_page)
28601 leaq 64(%rdi),%rdi
28602 jnz .Lloop
28603 nop
28604 + pax_force_retaddr
28605 ret
28606 CFI_ENDPROC
28607 .Lclear_page_end:
28608 @@ -58,7 +61,7 @@ ENDPROC(clear_page)
28609
28610 #include <asm/cpufeature.h>
28611
28612 - .section .altinstr_replacement,"ax"
28613 + .section .altinstr_replacement,"a"
28614 1: .byte 0xeb /* jmp <disp8> */
28615 .byte (clear_page_c - clear_page) - (2f - 1b) /* offset */
28616 2: .byte 0xeb /* jmp <disp8> */
28617 diff --git a/arch/x86/lib/cmpxchg16b_emu.S b/arch/x86/lib/cmpxchg16b_emu.S
28618 index 1e572c5..2a162cd 100644
28619 --- a/arch/x86/lib/cmpxchg16b_emu.S
28620 +++ b/arch/x86/lib/cmpxchg16b_emu.S
28621 @@ -53,11 +53,13 @@ this_cpu_cmpxchg16b_emu:
28622
28623 popf
28624 mov $1, %al
28625 + pax_force_retaddr
28626 ret
28627
28628 not_same:
28629 popf
28630 xor %al,%al
28631 + pax_force_retaddr
28632 ret
28633
28634 CFI_ENDPROC
28635 diff --git a/arch/x86/lib/copy_page_64.S b/arch/x86/lib/copy_page_64.S
28636 index 176cca6..e0d658e 100644
28637 --- a/arch/x86/lib/copy_page_64.S
28638 +++ b/arch/x86/lib/copy_page_64.S
28639 @@ -9,6 +9,7 @@ copy_page_rep:
28640 CFI_STARTPROC
28641 movl $4096/8, %ecx
28642 rep movsq
28643 + pax_force_retaddr
28644 ret
28645 CFI_ENDPROC
28646 ENDPROC(copy_page_rep)
28647 @@ -24,8 +25,8 @@ ENTRY(copy_page)
28648 CFI_ADJUST_CFA_OFFSET 2*8
28649 movq %rbx, (%rsp)
28650 CFI_REL_OFFSET rbx, 0
28651 - movq %r12, 1*8(%rsp)
28652 - CFI_REL_OFFSET r12, 1*8
28653 + movq %r13, 1*8(%rsp)
28654 + CFI_REL_OFFSET r13, 1*8
28655
28656 movl $(4096/64)-5, %ecx
28657 .p2align 4
28658 @@ -38,7 +39,7 @@ ENTRY(copy_page)
28659 movq 0x8*4(%rsi), %r9
28660 movq 0x8*5(%rsi), %r10
28661 movq 0x8*6(%rsi), %r11
28662 - movq 0x8*7(%rsi), %r12
28663 + movq 0x8*7(%rsi), %r13
28664
28665 prefetcht0 5*64(%rsi)
28666
28667 @@ -49,7 +50,7 @@ ENTRY(copy_page)
28668 movq %r9, 0x8*4(%rdi)
28669 movq %r10, 0x8*5(%rdi)
28670 movq %r11, 0x8*6(%rdi)
28671 - movq %r12, 0x8*7(%rdi)
28672 + movq %r13, 0x8*7(%rdi)
28673
28674 leaq 64 (%rsi), %rsi
28675 leaq 64 (%rdi), %rdi
28676 @@ -68,7 +69,7 @@ ENTRY(copy_page)
28677 movq 0x8*4(%rsi), %r9
28678 movq 0x8*5(%rsi), %r10
28679 movq 0x8*6(%rsi), %r11
28680 - movq 0x8*7(%rsi), %r12
28681 + movq 0x8*7(%rsi), %r13
28682
28683 movq %rax, 0x8*0(%rdi)
28684 movq %rbx, 0x8*1(%rdi)
28685 @@ -77,7 +78,7 @@ ENTRY(copy_page)
28686 movq %r9, 0x8*4(%rdi)
28687 movq %r10, 0x8*5(%rdi)
28688 movq %r11, 0x8*6(%rdi)
28689 - movq %r12, 0x8*7(%rdi)
28690 + movq %r13, 0x8*7(%rdi)
28691
28692 leaq 64(%rdi), %rdi
28693 leaq 64(%rsi), %rsi
28694 @@ -85,10 +86,11 @@ ENTRY(copy_page)
28695
28696 movq (%rsp), %rbx
28697 CFI_RESTORE rbx
28698 - movq 1*8(%rsp), %r12
28699 - CFI_RESTORE r12
28700 + movq 1*8(%rsp), %r13
28701 + CFI_RESTORE r13
28702 addq $2*8, %rsp
28703 CFI_ADJUST_CFA_OFFSET -2*8
28704 + pax_force_retaddr
28705 ret
28706 .Lcopy_page_end:
28707 CFI_ENDPROC
28708 @@ -99,7 +101,7 @@ ENDPROC(copy_page)
28709
28710 #include <asm/cpufeature.h>
28711
28712 - .section .altinstr_replacement,"ax"
28713 + .section .altinstr_replacement,"a"
28714 1: .byte 0xeb /* jmp <disp8> */
28715 .byte (copy_page_rep - copy_page) - (2f - 1b) /* offset */
28716 2:
28717 diff --git a/arch/x86/lib/copy_user_64.S b/arch/x86/lib/copy_user_64.S
28718 index a30ca15..407412b 100644
28719 --- a/arch/x86/lib/copy_user_64.S
28720 +++ b/arch/x86/lib/copy_user_64.S
28721 @@ -18,31 +18,7 @@
28722 #include <asm/alternative-asm.h>
28723 #include <asm/asm.h>
28724 #include <asm/smap.h>
28725 -
28726 -/*
28727 - * By placing feature2 after feature1 in altinstructions section, we logically
28728 - * implement:
28729 - * If CPU has feature2, jmp to alt2 is used
28730 - * else if CPU has feature1, jmp to alt1 is used
28731 - * else jmp to orig is used.
28732 - */
28733 - .macro ALTERNATIVE_JUMP feature1,feature2,orig,alt1,alt2
28734 -0:
28735 - .byte 0xe9 /* 32bit jump */
28736 - .long \orig-1f /* by default jump to orig */
28737 -1:
28738 - .section .altinstr_replacement,"ax"
28739 -2: .byte 0xe9 /* near jump with 32bit immediate */
28740 - .long \alt1-1b /* offset */ /* or alternatively to alt1 */
28741 -3: .byte 0xe9 /* near jump with 32bit immediate */
28742 - .long \alt2-1b /* offset */ /* or alternatively to alt2 */
28743 - .previous
28744 -
28745 - .section .altinstructions,"a"
28746 - altinstruction_entry 0b,2b,\feature1,5,5
28747 - altinstruction_entry 0b,3b,\feature2,5,5
28748 - .previous
28749 - .endm
28750 +#include <asm/pgtable.h>
28751
28752 .macro ALIGN_DESTINATION
28753 #ifdef FIX_ALIGNMENT
28754 @@ -70,52 +46,6 @@
28755 #endif
28756 .endm
28757
28758 -/* Standard copy_to_user with segment limit checking */
28759 -ENTRY(_copy_to_user)
28760 - CFI_STARTPROC
28761 - GET_THREAD_INFO(%rax)
28762 - movq %rdi,%rcx
28763 - addq %rdx,%rcx
28764 - jc bad_to_user
28765 - cmpq TI_addr_limit(%rax),%rcx
28766 - ja bad_to_user
28767 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
28768 - copy_user_generic_unrolled,copy_user_generic_string, \
28769 - copy_user_enhanced_fast_string
28770 - CFI_ENDPROC
28771 -ENDPROC(_copy_to_user)
28772 -
28773 -/* Standard copy_from_user with segment limit checking */
28774 -ENTRY(_copy_from_user)
28775 - CFI_STARTPROC
28776 - GET_THREAD_INFO(%rax)
28777 - movq %rsi,%rcx
28778 - addq %rdx,%rcx
28779 - jc bad_from_user
28780 - cmpq TI_addr_limit(%rax),%rcx
28781 - ja bad_from_user
28782 - ALTERNATIVE_JUMP X86_FEATURE_REP_GOOD,X86_FEATURE_ERMS, \
28783 - copy_user_generic_unrolled,copy_user_generic_string, \
28784 - copy_user_enhanced_fast_string
28785 - CFI_ENDPROC
28786 -ENDPROC(_copy_from_user)
28787 -
28788 - .section .fixup,"ax"
28789 - /* must zero dest */
28790 -ENTRY(bad_from_user)
28791 -bad_from_user:
28792 - CFI_STARTPROC
28793 - movl %edx,%ecx
28794 - xorl %eax,%eax
28795 - rep
28796 - stosb
28797 -bad_to_user:
28798 - movl %edx,%eax
28799 - ret
28800 - CFI_ENDPROC
28801 -ENDPROC(bad_from_user)
28802 - .previous
28803 -
28804 /*
28805 * copy_user_generic_unrolled - memory copy with exception handling.
28806 * This version is for CPUs like P4 that don't have efficient micro
28807 @@ -131,6 +61,7 @@ ENDPROC(bad_from_user)
28808 */
28809 ENTRY(copy_user_generic_unrolled)
28810 CFI_STARTPROC
28811 + ASM_PAX_OPEN_USERLAND
28812 ASM_STAC
28813 cmpl $8,%edx
28814 jb 20f /* less then 8 bytes, go to byte copy loop */
28815 @@ -180,6 +111,8 @@ ENTRY(copy_user_generic_unrolled)
28816 jnz 21b
28817 23: xor %eax,%eax
28818 ASM_CLAC
28819 + ASM_PAX_CLOSE_USERLAND
28820 + pax_force_retaddr
28821 ret
28822
28823 .section .fixup,"ax"
28824 @@ -235,6 +168,7 @@ ENDPROC(copy_user_generic_unrolled)
28825 */
28826 ENTRY(copy_user_generic_string)
28827 CFI_STARTPROC
28828 + ASM_PAX_OPEN_USERLAND
28829 ASM_STAC
28830 andl %edx,%edx
28831 jz 4f
28832 @@ -251,6 +185,8 @@ ENTRY(copy_user_generic_string)
28833 movsb
28834 4: xorl %eax,%eax
28835 ASM_CLAC
28836 + ASM_PAX_CLOSE_USERLAND
28837 + pax_force_retaddr
28838 ret
28839
28840 .section .fixup,"ax"
28841 @@ -278,6 +214,7 @@ ENDPROC(copy_user_generic_string)
28842 */
28843 ENTRY(copy_user_enhanced_fast_string)
28844 CFI_STARTPROC
28845 + ASM_PAX_OPEN_USERLAND
28846 ASM_STAC
28847 andl %edx,%edx
28848 jz 2f
28849 @@ -286,6 +223,8 @@ ENTRY(copy_user_enhanced_fast_string)
28850 movsb
28851 2: xorl %eax,%eax
28852 ASM_CLAC
28853 + ASM_PAX_CLOSE_USERLAND
28854 + pax_force_retaddr
28855 ret
28856
28857 .section .fixup,"ax"
28858 diff --git a/arch/x86/lib/copy_user_nocache_64.S b/arch/x86/lib/copy_user_nocache_64.S
28859 index 6a4f43c..c70fb52 100644
28860 --- a/arch/x86/lib/copy_user_nocache_64.S
28861 +++ b/arch/x86/lib/copy_user_nocache_64.S
28862 @@ -8,6 +8,7 @@
28863
28864 #include <linux/linkage.h>
28865 #include <asm/dwarf2.h>
28866 +#include <asm/alternative-asm.h>
28867
28868 #define FIX_ALIGNMENT 1
28869
28870 @@ -16,6 +17,7 @@
28871 #include <asm/thread_info.h>
28872 #include <asm/asm.h>
28873 #include <asm/smap.h>
28874 +#include <asm/pgtable.h>
28875
28876 .macro ALIGN_DESTINATION
28877 #ifdef FIX_ALIGNMENT
28878 @@ -49,6 +51,16 @@
28879 */
28880 ENTRY(__copy_user_nocache)
28881 CFI_STARTPROC
28882 +
28883 +#ifdef CONFIG_PAX_MEMORY_UDEREF
28884 + mov pax_user_shadow_base,%rcx
28885 + cmp %rcx,%rsi
28886 + jae 1f
28887 + add %rcx,%rsi
28888 +1:
28889 +#endif
28890 +
28891 + ASM_PAX_OPEN_USERLAND
28892 ASM_STAC
28893 cmpl $8,%edx
28894 jb 20f /* less then 8 bytes, go to byte copy loop */
28895 @@ -98,7 +110,9 @@ ENTRY(__copy_user_nocache)
28896 jnz 21b
28897 23: xorl %eax,%eax
28898 ASM_CLAC
28899 + ASM_PAX_CLOSE_USERLAND
28900 sfence
28901 + pax_force_retaddr
28902 ret
28903
28904 .section .fixup,"ax"
28905 diff --git a/arch/x86/lib/csum-copy_64.S b/arch/x86/lib/csum-copy_64.S
28906 index 2419d5f..fe52d0e 100644
28907 --- a/arch/x86/lib/csum-copy_64.S
28908 +++ b/arch/x86/lib/csum-copy_64.S
28909 @@ -9,6 +9,7 @@
28910 #include <asm/dwarf2.h>
28911 #include <asm/errno.h>
28912 #include <asm/asm.h>
28913 +#include <asm/alternative-asm.h>
28914
28915 /*
28916 * Checksum copy with exception handling.
28917 @@ -56,8 +57,8 @@ ENTRY(csum_partial_copy_generic)
28918 CFI_ADJUST_CFA_OFFSET 7*8
28919 movq %rbx, 2*8(%rsp)
28920 CFI_REL_OFFSET rbx, 2*8
28921 - movq %r12, 3*8(%rsp)
28922 - CFI_REL_OFFSET r12, 3*8
28923 + movq %r15, 3*8(%rsp)
28924 + CFI_REL_OFFSET r15, 3*8
28925 movq %r14, 4*8(%rsp)
28926 CFI_REL_OFFSET r14, 4*8
28927 movq %r13, 5*8(%rsp)
28928 @@ -72,16 +73,16 @@ ENTRY(csum_partial_copy_generic)
28929 movl %edx, %ecx
28930
28931 xorl %r9d, %r9d
28932 - movq %rcx, %r12
28933 + movq %rcx, %r15
28934
28935 - shrq $6, %r12
28936 + shrq $6, %r15
28937 jz .Lhandle_tail /* < 64 */
28938
28939 clc
28940
28941 /* main loop. clear in 64 byte blocks */
28942 /* r9: zero, r8: temp2, rbx: temp1, rax: sum, rcx: saved length */
28943 - /* r11: temp3, rdx: temp4, r12 loopcnt */
28944 + /* r11: temp3, rdx: temp4, r15 loopcnt */
28945 /* r10: temp5, rbp: temp6, r14 temp7, r13 temp8 */
28946 .p2align 4
28947 .Lloop:
28948 @@ -115,7 +116,7 @@ ENTRY(csum_partial_copy_generic)
28949 adcq %r14, %rax
28950 adcq %r13, %rax
28951
28952 - decl %r12d
28953 + decl %r15d
28954
28955 dest
28956 movq %rbx, (%rsi)
28957 @@ -210,8 +211,8 @@ ENTRY(csum_partial_copy_generic)
28958 .Lende:
28959 movq 2*8(%rsp), %rbx
28960 CFI_RESTORE rbx
28961 - movq 3*8(%rsp), %r12
28962 - CFI_RESTORE r12
28963 + movq 3*8(%rsp), %r15
28964 + CFI_RESTORE r15
28965 movq 4*8(%rsp), %r14
28966 CFI_RESTORE r14
28967 movq 5*8(%rsp), %r13
28968 @@ -220,6 +221,7 @@ ENTRY(csum_partial_copy_generic)
28969 CFI_RESTORE rbp
28970 addq $7*8, %rsp
28971 CFI_ADJUST_CFA_OFFSET -7*8
28972 + pax_force_retaddr
28973 ret
28974 CFI_RESTORE_STATE
28975
28976 diff --git a/arch/x86/lib/csum-wrappers_64.c b/arch/x86/lib/csum-wrappers_64.c
28977 index 7609e0e..b449b98 100644
28978 --- a/arch/x86/lib/csum-wrappers_64.c
28979 +++ b/arch/x86/lib/csum-wrappers_64.c
28980 @@ -53,10 +53,12 @@ csum_partial_copy_from_user(const void __user *src, void *dst,
28981 len -= 2;
28982 }
28983 }
28984 + pax_open_userland();
28985 stac();
28986 - isum = csum_partial_copy_generic((__force const void *)src,
28987 + isum = csum_partial_copy_generic((const void __force_kernel *)____m(src),
28988 dst, len, isum, errp, NULL);
28989 clac();
28990 + pax_close_userland();
28991 if (unlikely(*errp))
28992 goto out_err;
28993
28994 @@ -110,10 +112,12 @@ csum_partial_copy_to_user(const void *src, void __user *dst,
28995 }
28996
28997 *errp = 0;
28998 + pax_open_userland();
28999 stac();
29000 - ret = csum_partial_copy_generic(src, (void __force *)dst,
29001 + ret = csum_partial_copy_generic(src, (void __force_kernel *)____m(dst),
29002 len, isum, NULL, errp);
29003 clac();
29004 + pax_close_userland();
29005 return ret;
29006 }
29007 EXPORT_SYMBOL(csum_partial_copy_to_user);
29008 diff --git a/arch/x86/lib/getuser.S b/arch/x86/lib/getuser.S
29009 index a451235..1daa956 100644
29010 --- a/arch/x86/lib/getuser.S
29011 +++ b/arch/x86/lib/getuser.S
29012 @@ -33,17 +33,40 @@
29013 #include <asm/thread_info.h>
29014 #include <asm/asm.h>
29015 #include <asm/smap.h>
29016 +#include <asm/segment.h>
29017 +#include <asm/pgtable.h>
29018 +#include <asm/alternative-asm.h>
29019 +
29020 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29021 +#define __copyuser_seg gs;
29022 +#else
29023 +#define __copyuser_seg
29024 +#endif
29025
29026 .text
29027 ENTRY(__get_user_1)
29028 CFI_STARTPROC
29029 +
29030 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29031 GET_THREAD_INFO(%_ASM_DX)
29032 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29033 jae bad_get_user
29034 ASM_STAC
29035 -1: movzbl (%_ASM_AX),%edx
29036 +
29037 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29038 + mov pax_user_shadow_base,%_ASM_DX
29039 + cmp %_ASM_DX,%_ASM_AX
29040 + jae 1234f
29041 + add %_ASM_DX,%_ASM_AX
29042 +1234:
29043 +#endif
29044 +
29045 +#endif
29046 +
29047 +1: __copyuser_seg movzbl (%_ASM_AX),%edx
29048 xor %eax,%eax
29049 ASM_CLAC
29050 + pax_force_retaddr
29051 ret
29052 CFI_ENDPROC
29053 ENDPROC(__get_user_1)
29054 @@ -51,14 +74,28 @@ ENDPROC(__get_user_1)
29055 ENTRY(__get_user_2)
29056 CFI_STARTPROC
29057 add $1,%_ASM_AX
29058 +
29059 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29060 jc bad_get_user
29061 GET_THREAD_INFO(%_ASM_DX)
29062 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29063 jae bad_get_user
29064 ASM_STAC
29065 -2: movzwl -1(%_ASM_AX),%edx
29066 +
29067 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29068 + mov pax_user_shadow_base,%_ASM_DX
29069 + cmp %_ASM_DX,%_ASM_AX
29070 + jae 1234f
29071 + add %_ASM_DX,%_ASM_AX
29072 +1234:
29073 +#endif
29074 +
29075 +#endif
29076 +
29077 +2: __copyuser_seg movzwl -1(%_ASM_AX),%edx
29078 xor %eax,%eax
29079 ASM_CLAC
29080 + pax_force_retaddr
29081 ret
29082 CFI_ENDPROC
29083 ENDPROC(__get_user_2)
29084 @@ -66,14 +103,28 @@ ENDPROC(__get_user_2)
29085 ENTRY(__get_user_4)
29086 CFI_STARTPROC
29087 add $3,%_ASM_AX
29088 +
29089 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29090 jc bad_get_user
29091 GET_THREAD_INFO(%_ASM_DX)
29092 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29093 jae bad_get_user
29094 ASM_STAC
29095 -3: movl -3(%_ASM_AX),%edx
29096 +
29097 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29098 + mov pax_user_shadow_base,%_ASM_DX
29099 + cmp %_ASM_DX,%_ASM_AX
29100 + jae 1234f
29101 + add %_ASM_DX,%_ASM_AX
29102 +1234:
29103 +#endif
29104 +
29105 +#endif
29106 +
29107 +3: __copyuser_seg movl -3(%_ASM_AX),%edx
29108 xor %eax,%eax
29109 ASM_CLAC
29110 + pax_force_retaddr
29111 ret
29112 CFI_ENDPROC
29113 ENDPROC(__get_user_4)
29114 @@ -86,10 +137,20 @@ ENTRY(__get_user_8)
29115 GET_THREAD_INFO(%_ASM_DX)
29116 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29117 jae bad_get_user
29118 +
29119 +#ifdef CONFIG_PAX_MEMORY_UDEREF
29120 + mov pax_user_shadow_base,%_ASM_DX
29121 + cmp %_ASM_DX,%_ASM_AX
29122 + jae 1234f
29123 + add %_ASM_DX,%_ASM_AX
29124 +1234:
29125 +#endif
29126 +
29127 ASM_STAC
29128 4: movq -7(%_ASM_AX),%rdx
29129 xor %eax,%eax
29130 ASM_CLAC
29131 + pax_force_retaddr
29132 ret
29133 #else
29134 add $7,%_ASM_AX
29135 @@ -98,10 +159,11 @@ ENTRY(__get_user_8)
29136 cmp TI_addr_limit(%_ASM_DX),%_ASM_AX
29137 jae bad_get_user_8
29138 ASM_STAC
29139 -4: movl -7(%_ASM_AX),%edx
29140 -5: movl -3(%_ASM_AX),%ecx
29141 +4: __copyuser_seg movl -7(%_ASM_AX),%edx
29142 +5: __copyuser_seg movl -3(%_ASM_AX),%ecx
29143 xor %eax,%eax
29144 ASM_CLAC
29145 + pax_force_retaddr
29146 ret
29147 #endif
29148 CFI_ENDPROC
29149 @@ -113,6 +175,7 @@ bad_get_user:
29150 xor %edx,%edx
29151 mov $(-EFAULT),%_ASM_AX
29152 ASM_CLAC
29153 + pax_force_retaddr
29154 ret
29155 CFI_ENDPROC
29156 END(bad_get_user)
29157 @@ -124,6 +187,7 @@ bad_get_user_8:
29158 xor %ecx,%ecx
29159 mov $(-EFAULT),%_ASM_AX
29160 ASM_CLAC
29161 + pax_force_retaddr
29162 ret
29163 CFI_ENDPROC
29164 END(bad_get_user_8)
29165 diff --git a/arch/x86/lib/insn.c b/arch/x86/lib/insn.c
29166 index 54fcffe..7be149e 100644
29167 --- a/arch/x86/lib/insn.c
29168 +++ b/arch/x86/lib/insn.c
29169 @@ -20,8 +20,10 @@
29170
29171 #ifdef __KERNEL__
29172 #include <linux/string.h>
29173 +#include <asm/pgtable_types.h>
29174 #else
29175 #include <string.h>
29176 +#define ktla_ktva(addr) addr
29177 #endif
29178 #include <asm/inat.h>
29179 #include <asm/insn.h>
29180 @@ -53,8 +55,8 @@
29181 void insn_init(struct insn *insn, const void *kaddr, int x86_64)
29182 {
29183 memset(insn, 0, sizeof(*insn));
29184 - insn->kaddr = kaddr;
29185 - insn->next_byte = kaddr;
29186 + insn->kaddr = ktla_ktva(kaddr);
29187 + insn->next_byte = ktla_ktva(kaddr);
29188 insn->x86_64 = x86_64 ? 1 : 0;
29189 insn->opnd_bytes = 4;
29190 if (x86_64)
29191 diff --git a/arch/x86/lib/iomap_copy_64.S b/arch/x86/lib/iomap_copy_64.S
29192 index 05a95e7..326f2fa 100644
29193 --- a/arch/x86/lib/iomap_copy_64.S
29194 +++ b/arch/x86/lib/iomap_copy_64.S
29195 @@ -17,6 +17,7 @@
29196
29197 #include <linux/linkage.h>
29198 #include <asm/dwarf2.h>
29199 +#include <asm/alternative-asm.h>
29200
29201 /*
29202 * override generic version in lib/iomap_copy.c
29203 @@ -25,6 +26,7 @@ ENTRY(__iowrite32_copy)
29204 CFI_STARTPROC
29205 movl %edx,%ecx
29206 rep movsd
29207 + pax_force_retaddr
29208 ret
29209 CFI_ENDPROC
29210 ENDPROC(__iowrite32_copy)
29211 diff --git a/arch/x86/lib/memcpy_64.S b/arch/x86/lib/memcpy_64.S
29212 index 56313a3..0db417e 100644
29213 --- a/arch/x86/lib/memcpy_64.S
29214 +++ b/arch/x86/lib/memcpy_64.S
29215 @@ -24,7 +24,7 @@
29216 * This gets patched over the unrolled variant (below) via the
29217 * alternative instructions framework:
29218 */
29219 - .section .altinstr_replacement, "ax", @progbits
29220 + .section .altinstr_replacement, "a", @progbits
29221 .Lmemcpy_c:
29222 movq %rdi, %rax
29223 movq %rdx, %rcx
29224 @@ -33,6 +33,7 @@
29225 rep movsq
29226 movl %edx, %ecx
29227 rep movsb
29228 + pax_force_retaddr
29229 ret
29230 .Lmemcpy_e:
29231 .previous
29232 @@ -44,11 +45,12 @@
29233 * This gets patched over the unrolled variant (below) via the
29234 * alternative instructions framework:
29235 */
29236 - .section .altinstr_replacement, "ax", @progbits
29237 + .section .altinstr_replacement, "a", @progbits
29238 .Lmemcpy_c_e:
29239 movq %rdi, %rax
29240 movq %rdx, %rcx
29241 rep movsb
29242 + pax_force_retaddr
29243 ret
29244 .Lmemcpy_e_e:
29245 .previous
29246 @@ -136,6 +138,7 @@ ENTRY(memcpy)
29247 movq %r9, 1*8(%rdi)
29248 movq %r10, -2*8(%rdi, %rdx)
29249 movq %r11, -1*8(%rdi, %rdx)
29250 + pax_force_retaddr
29251 retq
29252 .p2align 4
29253 .Lless_16bytes:
29254 @@ -148,6 +151,7 @@ ENTRY(memcpy)
29255 movq -1*8(%rsi, %rdx), %r9
29256 movq %r8, 0*8(%rdi)
29257 movq %r9, -1*8(%rdi, %rdx)
29258 + pax_force_retaddr
29259 retq
29260 .p2align 4
29261 .Lless_8bytes:
29262 @@ -161,6 +165,7 @@ ENTRY(memcpy)
29263 movl -4(%rsi, %rdx), %r8d
29264 movl %ecx, (%rdi)
29265 movl %r8d, -4(%rdi, %rdx)
29266 + pax_force_retaddr
29267 retq
29268 .p2align 4
29269 .Lless_3bytes:
29270 @@ -179,6 +184,7 @@ ENTRY(memcpy)
29271 movb %cl, (%rdi)
29272
29273 .Lend:
29274 + pax_force_retaddr
29275 retq
29276 CFI_ENDPROC
29277 ENDPROC(memcpy)
29278 diff --git a/arch/x86/lib/memmove_64.S b/arch/x86/lib/memmove_64.S
29279 index 65268a6..dd1de11 100644
29280 --- a/arch/x86/lib/memmove_64.S
29281 +++ b/arch/x86/lib/memmove_64.S
29282 @@ -202,14 +202,16 @@ ENTRY(memmove)
29283 movb (%rsi), %r11b
29284 movb %r11b, (%rdi)
29285 13:
29286 + pax_force_retaddr
29287 retq
29288 CFI_ENDPROC
29289
29290 - .section .altinstr_replacement,"ax"
29291 + .section .altinstr_replacement,"a"
29292 .Lmemmove_begin_forward_efs:
29293 /* Forward moving data. */
29294 movq %rdx, %rcx
29295 rep movsb
29296 + pax_force_retaddr
29297 retq
29298 .Lmemmove_end_forward_efs:
29299 .previous
29300 diff --git a/arch/x86/lib/memset_64.S b/arch/x86/lib/memset_64.S
29301 index 2dcb380..2eb79fe 100644
29302 --- a/arch/x86/lib/memset_64.S
29303 +++ b/arch/x86/lib/memset_64.S
29304 @@ -16,7 +16,7 @@
29305 *
29306 * rax original destination
29307 */
29308 - .section .altinstr_replacement, "ax", @progbits
29309 + .section .altinstr_replacement, "a", @progbits
29310 .Lmemset_c:
29311 movq %rdi,%r9
29312 movq %rdx,%rcx
29313 @@ -30,6 +30,7 @@
29314 movl %edx,%ecx
29315 rep stosb
29316 movq %r9,%rax
29317 + pax_force_retaddr
29318 ret
29319 .Lmemset_e:
29320 .previous
29321 @@ -45,13 +46,14 @@
29322 *
29323 * rax original destination
29324 */
29325 - .section .altinstr_replacement, "ax", @progbits
29326 + .section .altinstr_replacement, "a", @progbits
29327 .Lmemset_c_e:
29328 movq %rdi,%r9
29329 movb %sil,%al
29330 movq %rdx,%rcx
29331 rep stosb
29332 movq %r9,%rax
29333 + pax_force_retaddr
29334 ret
29335 .Lmemset_e_e:
29336 .previous
29337 @@ -118,6 +120,7 @@ ENTRY(__memset)
29338
29339 .Lende:
29340 movq %r10,%rax
29341 + pax_force_retaddr
29342 ret
29343
29344 CFI_RESTORE_STATE
29345 diff --git a/arch/x86/lib/mmx_32.c b/arch/x86/lib/mmx_32.c
29346 index c9f2d9b..e7fd2c0 100644
29347 --- a/arch/x86/lib/mmx_32.c
29348 +++ b/arch/x86/lib/mmx_32.c
29349 @@ -29,6 +29,7 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29350 {
29351 void *p;
29352 int i;
29353 + unsigned long cr0;
29354
29355 if (unlikely(in_interrupt()))
29356 return __memcpy(to, from, len);
29357 @@ -39,44 +40,72 @@ void *_mmx_memcpy(void *to, const void *from, size_t len)
29358 kernel_fpu_begin();
29359
29360 __asm__ __volatile__ (
29361 - "1: prefetch (%0)\n" /* This set is 28 bytes */
29362 - " prefetch 64(%0)\n"
29363 - " prefetch 128(%0)\n"
29364 - " prefetch 192(%0)\n"
29365 - " prefetch 256(%0)\n"
29366 + "1: prefetch (%1)\n" /* This set is 28 bytes */
29367 + " prefetch 64(%1)\n"
29368 + " prefetch 128(%1)\n"
29369 + " prefetch 192(%1)\n"
29370 + " prefetch 256(%1)\n"
29371 "2: \n"
29372 ".section .fixup, \"ax\"\n"
29373 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29374 + "3: \n"
29375 +
29376 +#ifdef CONFIG_PAX_KERNEXEC
29377 + " movl %%cr0, %0\n"
29378 + " movl %0, %%eax\n"
29379 + " andl $0xFFFEFFFF, %%eax\n"
29380 + " movl %%eax, %%cr0\n"
29381 +#endif
29382 +
29383 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29384 +
29385 +#ifdef CONFIG_PAX_KERNEXEC
29386 + " movl %0, %%cr0\n"
29387 +#endif
29388 +
29389 " jmp 2b\n"
29390 ".previous\n"
29391 _ASM_EXTABLE(1b, 3b)
29392 - : : "r" (from));
29393 + : "=&r" (cr0) : "r" (from) : "ax");
29394
29395 for ( ; i > 5; i--) {
29396 __asm__ __volatile__ (
29397 - "1: prefetch 320(%0)\n"
29398 - "2: movq (%0), %%mm0\n"
29399 - " movq 8(%0), %%mm1\n"
29400 - " movq 16(%0), %%mm2\n"
29401 - " movq 24(%0), %%mm3\n"
29402 - " movq %%mm0, (%1)\n"
29403 - " movq %%mm1, 8(%1)\n"
29404 - " movq %%mm2, 16(%1)\n"
29405 - " movq %%mm3, 24(%1)\n"
29406 - " movq 32(%0), %%mm0\n"
29407 - " movq 40(%0), %%mm1\n"
29408 - " movq 48(%0), %%mm2\n"
29409 - " movq 56(%0), %%mm3\n"
29410 - " movq %%mm0, 32(%1)\n"
29411 - " movq %%mm1, 40(%1)\n"
29412 - " movq %%mm2, 48(%1)\n"
29413 - " movq %%mm3, 56(%1)\n"
29414 + "1: prefetch 320(%1)\n"
29415 + "2: movq (%1), %%mm0\n"
29416 + " movq 8(%1), %%mm1\n"
29417 + " movq 16(%1), %%mm2\n"
29418 + " movq 24(%1), %%mm3\n"
29419 + " movq %%mm0, (%2)\n"
29420 + " movq %%mm1, 8(%2)\n"
29421 + " movq %%mm2, 16(%2)\n"
29422 + " movq %%mm3, 24(%2)\n"
29423 + " movq 32(%1), %%mm0\n"
29424 + " movq 40(%1), %%mm1\n"
29425 + " movq 48(%1), %%mm2\n"
29426 + " movq 56(%1), %%mm3\n"
29427 + " movq %%mm0, 32(%2)\n"
29428 + " movq %%mm1, 40(%2)\n"
29429 + " movq %%mm2, 48(%2)\n"
29430 + " movq %%mm3, 56(%2)\n"
29431 ".section .fixup, \"ax\"\n"
29432 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29433 + "3:\n"
29434 +
29435 +#ifdef CONFIG_PAX_KERNEXEC
29436 + " movl %%cr0, %0\n"
29437 + " movl %0, %%eax\n"
29438 + " andl $0xFFFEFFFF, %%eax\n"
29439 + " movl %%eax, %%cr0\n"
29440 +#endif
29441 +
29442 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29443 +
29444 +#ifdef CONFIG_PAX_KERNEXEC
29445 + " movl %0, %%cr0\n"
29446 +#endif
29447 +
29448 " jmp 2b\n"
29449 ".previous\n"
29450 _ASM_EXTABLE(1b, 3b)
29451 - : : "r" (from), "r" (to) : "memory");
29452 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29453
29454 from += 64;
29455 to += 64;
29456 @@ -158,6 +187,7 @@ static void fast_clear_page(void *page)
29457 static void fast_copy_page(void *to, void *from)
29458 {
29459 int i;
29460 + unsigned long cr0;
29461
29462 kernel_fpu_begin();
29463
29464 @@ -166,42 +196,70 @@ static void fast_copy_page(void *to, void *from)
29465 * but that is for later. -AV
29466 */
29467 __asm__ __volatile__(
29468 - "1: prefetch (%0)\n"
29469 - " prefetch 64(%0)\n"
29470 - " prefetch 128(%0)\n"
29471 - " prefetch 192(%0)\n"
29472 - " prefetch 256(%0)\n"
29473 + "1: prefetch (%1)\n"
29474 + " prefetch 64(%1)\n"
29475 + " prefetch 128(%1)\n"
29476 + " prefetch 192(%1)\n"
29477 + " prefetch 256(%1)\n"
29478 "2: \n"
29479 ".section .fixup, \"ax\"\n"
29480 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29481 + "3: \n"
29482 +
29483 +#ifdef CONFIG_PAX_KERNEXEC
29484 + " movl %%cr0, %0\n"
29485 + " movl %0, %%eax\n"
29486 + " andl $0xFFFEFFFF, %%eax\n"
29487 + " movl %%eax, %%cr0\n"
29488 +#endif
29489 +
29490 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29491 +
29492 +#ifdef CONFIG_PAX_KERNEXEC
29493 + " movl %0, %%cr0\n"
29494 +#endif
29495 +
29496 " jmp 2b\n"
29497 ".previous\n"
29498 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
29499 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
29500
29501 for (i = 0; i < (4096-320)/64; i++) {
29502 __asm__ __volatile__ (
29503 - "1: prefetch 320(%0)\n"
29504 - "2: movq (%0), %%mm0\n"
29505 - " movntq %%mm0, (%1)\n"
29506 - " movq 8(%0), %%mm1\n"
29507 - " movntq %%mm1, 8(%1)\n"
29508 - " movq 16(%0), %%mm2\n"
29509 - " movntq %%mm2, 16(%1)\n"
29510 - " movq 24(%0), %%mm3\n"
29511 - " movntq %%mm3, 24(%1)\n"
29512 - " movq 32(%0), %%mm4\n"
29513 - " movntq %%mm4, 32(%1)\n"
29514 - " movq 40(%0), %%mm5\n"
29515 - " movntq %%mm5, 40(%1)\n"
29516 - " movq 48(%0), %%mm6\n"
29517 - " movntq %%mm6, 48(%1)\n"
29518 - " movq 56(%0), %%mm7\n"
29519 - " movntq %%mm7, 56(%1)\n"
29520 + "1: prefetch 320(%1)\n"
29521 + "2: movq (%1), %%mm0\n"
29522 + " movntq %%mm0, (%2)\n"
29523 + " movq 8(%1), %%mm1\n"
29524 + " movntq %%mm1, 8(%2)\n"
29525 + " movq 16(%1), %%mm2\n"
29526 + " movntq %%mm2, 16(%2)\n"
29527 + " movq 24(%1), %%mm3\n"
29528 + " movntq %%mm3, 24(%2)\n"
29529 + " movq 32(%1), %%mm4\n"
29530 + " movntq %%mm4, 32(%2)\n"
29531 + " movq 40(%1), %%mm5\n"
29532 + " movntq %%mm5, 40(%2)\n"
29533 + " movq 48(%1), %%mm6\n"
29534 + " movntq %%mm6, 48(%2)\n"
29535 + " movq 56(%1), %%mm7\n"
29536 + " movntq %%mm7, 56(%2)\n"
29537 ".section .fixup, \"ax\"\n"
29538 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29539 + "3:\n"
29540 +
29541 +#ifdef CONFIG_PAX_KERNEXEC
29542 + " movl %%cr0, %0\n"
29543 + " movl %0, %%eax\n"
29544 + " andl $0xFFFEFFFF, %%eax\n"
29545 + " movl %%eax, %%cr0\n"
29546 +#endif
29547 +
29548 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29549 +
29550 +#ifdef CONFIG_PAX_KERNEXEC
29551 + " movl %0, %%cr0\n"
29552 +#endif
29553 +
29554 " jmp 2b\n"
29555 ".previous\n"
29556 - _ASM_EXTABLE(1b, 3b) : : "r" (from), "r" (to) : "memory");
29557 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29558
29559 from += 64;
29560 to += 64;
29561 @@ -280,47 +338,76 @@ static void fast_clear_page(void *page)
29562 static void fast_copy_page(void *to, void *from)
29563 {
29564 int i;
29565 + unsigned long cr0;
29566
29567 kernel_fpu_begin();
29568
29569 __asm__ __volatile__ (
29570 - "1: prefetch (%0)\n"
29571 - " prefetch 64(%0)\n"
29572 - " prefetch 128(%0)\n"
29573 - " prefetch 192(%0)\n"
29574 - " prefetch 256(%0)\n"
29575 + "1: prefetch (%1)\n"
29576 + " prefetch 64(%1)\n"
29577 + " prefetch 128(%1)\n"
29578 + " prefetch 192(%1)\n"
29579 + " prefetch 256(%1)\n"
29580 "2: \n"
29581 ".section .fixup, \"ax\"\n"
29582 - "3: movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29583 + "3: \n"
29584 +
29585 +#ifdef CONFIG_PAX_KERNEXEC
29586 + " movl %%cr0, %0\n"
29587 + " movl %0, %%eax\n"
29588 + " andl $0xFFFEFFFF, %%eax\n"
29589 + " movl %%eax, %%cr0\n"
29590 +#endif
29591 +
29592 + " movw $0x1AEB, 1b\n" /* jmp on 26 bytes */
29593 +
29594 +#ifdef CONFIG_PAX_KERNEXEC
29595 + " movl %0, %%cr0\n"
29596 +#endif
29597 +
29598 " jmp 2b\n"
29599 ".previous\n"
29600 - _ASM_EXTABLE(1b, 3b) : : "r" (from));
29601 + _ASM_EXTABLE(1b, 3b) : "=&r" (cr0) : "r" (from) : "ax");
29602
29603 for (i = 0; i < 4096/64; i++) {
29604 __asm__ __volatile__ (
29605 - "1: prefetch 320(%0)\n"
29606 - "2: movq (%0), %%mm0\n"
29607 - " movq 8(%0), %%mm1\n"
29608 - " movq 16(%0), %%mm2\n"
29609 - " movq 24(%0), %%mm3\n"
29610 - " movq %%mm0, (%1)\n"
29611 - " movq %%mm1, 8(%1)\n"
29612 - " movq %%mm2, 16(%1)\n"
29613 - " movq %%mm3, 24(%1)\n"
29614 - " movq 32(%0), %%mm0\n"
29615 - " movq 40(%0), %%mm1\n"
29616 - " movq 48(%0), %%mm2\n"
29617 - " movq 56(%0), %%mm3\n"
29618 - " movq %%mm0, 32(%1)\n"
29619 - " movq %%mm1, 40(%1)\n"
29620 - " movq %%mm2, 48(%1)\n"
29621 - " movq %%mm3, 56(%1)\n"
29622 + "1: prefetch 320(%1)\n"
29623 + "2: movq (%1), %%mm0\n"
29624 + " movq 8(%1), %%mm1\n"
29625 + " movq 16(%1), %%mm2\n"
29626 + " movq 24(%1), %%mm3\n"
29627 + " movq %%mm0, (%2)\n"
29628 + " movq %%mm1, 8(%2)\n"
29629 + " movq %%mm2, 16(%2)\n"
29630 + " movq %%mm3, 24(%2)\n"
29631 + " movq 32(%1), %%mm0\n"
29632 + " movq 40(%1), %%mm1\n"
29633 + " movq 48(%1), %%mm2\n"
29634 + " movq 56(%1), %%mm3\n"
29635 + " movq %%mm0, 32(%2)\n"
29636 + " movq %%mm1, 40(%2)\n"
29637 + " movq %%mm2, 48(%2)\n"
29638 + " movq %%mm3, 56(%2)\n"
29639 ".section .fixup, \"ax\"\n"
29640 - "3: movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29641 + "3:\n"
29642 +
29643 +#ifdef CONFIG_PAX_KERNEXEC
29644 + " movl %%cr0, %0\n"
29645 + " movl %0, %%eax\n"
29646 + " andl $0xFFFEFFFF, %%eax\n"
29647 + " movl %%eax, %%cr0\n"
29648 +#endif
29649 +
29650 + " movw $0x05EB, 1b\n" /* jmp on 5 bytes */
29651 +
29652 +#ifdef CONFIG_PAX_KERNEXEC
29653 + " movl %0, %%cr0\n"
29654 +#endif
29655 +
29656 " jmp 2b\n"
29657 ".previous\n"
29658 _ASM_EXTABLE(1b, 3b)
29659 - : : "r" (from), "r" (to) : "memory");
29660 + : "=&r" (cr0) : "r" (from), "r" (to) : "memory", "ax");
29661
29662 from += 64;
29663 to += 64;
29664 diff --git a/arch/x86/lib/msr-reg.S b/arch/x86/lib/msr-reg.S
29665 index f6d13ee..d789440 100644
29666 --- a/arch/x86/lib/msr-reg.S
29667 +++ b/arch/x86/lib/msr-reg.S
29668 @@ -3,6 +3,7 @@
29669 #include <asm/dwarf2.h>
29670 #include <asm/asm.h>
29671 #include <asm/msr.h>
29672 +#include <asm/alternative-asm.h>
29673
29674 #ifdef CONFIG_X86_64
29675 /*
29676 @@ -37,6 +38,7 @@ ENTRY(\op\()_safe_regs)
29677 movl %edi, 28(%r10)
29678 popq_cfi %rbp
29679 popq_cfi %rbx
29680 + pax_force_retaddr
29681 ret
29682 3:
29683 CFI_RESTORE_STATE
29684 diff --git a/arch/x86/lib/putuser.S b/arch/x86/lib/putuser.S
29685 index fc6ba17..d4d989d 100644
29686 --- a/arch/x86/lib/putuser.S
29687 +++ b/arch/x86/lib/putuser.S
29688 @@ -16,7 +16,9 @@
29689 #include <asm/errno.h>
29690 #include <asm/asm.h>
29691 #include <asm/smap.h>
29692 -
29693 +#include <asm/segment.h>
29694 +#include <asm/pgtable.h>
29695 +#include <asm/alternative-asm.h>
29696
29697 /*
29698 * __put_user_X
29699 @@ -30,57 +32,125 @@
29700 * as they get called from within inline assembly.
29701 */
29702
29703 -#define ENTER CFI_STARTPROC ; \
29704 - GET_THREAD_INFO(%_ASM_BX)
29705 -#define EXIT ASM_CLAC ; \
29706 - ret ; \
29707 +#define ENTER CFI_STARTPROC
29708 +#define EXIT ASM_CLAC ; \
29709 + pax_force_retaddr ; \
29710 + ret ; \
29711 CFI_ENDPROC
29712
29713 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29714 +#define _DEST %_ASM_CX,%_ASM_BX
29715 +#else
29716 +#define _DEST %_ASM_CX
29717 +#endif
29718 +
29719 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_MEMORY_UDEREF)
29720 +#define __copyuser_seg gs;
29721 +#else
29722 +#define __copyuser_seg
29723 +#endif
29724 +
29725 .text
29726 ENTRY(__put_user_1)
29727 ENTER
29728 +
29729 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29730 + GET_THREAD_INFO(%_ASM_BX)
29731 cmp TI_addr_limit(%_ASM_BX),%_ASM_CX
29732 jae bad_put_user
29733 ASM_STAC
29734 -1: movb %al,(%_ASM_CX)
29735 +
29736 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29737 + mov pax_user_shadow_base,%_ASM_BX
29738 + cmp %_ASM_BX,%_ASM_CX
29739 + jb 1234f
29740 + xor %ebx,%ebx
29741 +1234:
29742 +#endif
29743 +
29744 +#endif
29745 +
29746 +1: __copyuser_seg movb %al,(_DEST)
29747 xor %eax,%eax
29748 EXIT
29749 ENDPROC(__put_user_1)
29750
29751 ENTRY(__put_user_2)
29752 ENTER
29753 +
29754 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29755 + GET_THREAD_INFO(%_ASM_BX)
29756 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29757 sub $1,%_ASM_BX
29758 cmp %_ASM_BX,%_ASM_CX
29759 jae bad_put_user
29760 ASM_STAC
29761 -2: movw %ax,(%_ASM_CX)
29762 +
29763 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29764 + mov pax_user_shadow_base,%_ASM_BX
29765 + cmp %_ASM_BX,%_ASM_CX
29766 + jb 1234f
29767 + xor %ebx,%ebx
29768 +1234:
29769 +#endif
29770 +
29771 +#endif
29772 +
29773 +2: __copyuser_seg movw %ax,(_DEST)
29774 xor %eax,%eax
29775 EXIT
29776 ENDPROC(__put_user_2)
29777
29778 ENTRY(__put_user_4)
29779 ENTER
29780 +
29781 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29782 + GET_THREAD_INFO(%_ASM_BX)
29783 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29784 sub $3,%_ASM_BX
29785 cmp %_ASM_BX,%_ASM_CX
29786 jae bad_put_user
29787 ASM_STAC
29788 -3: movl %eax,(%_ASM_CX)
29789 +
29790 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29791 + mov pax_user_shadow_base,%_ASM_BX
29792 + cmp %_ASM_BX,%_ASM_CX
29793 + jb 1234f
29794 + xor %ebx,%ebx
29795 +1234:
29796 +#endif
29797 +
29798 +#endif
29799 +
29800 +3: __copyuser_seg movl %eax,(_DEST)
29801 xor %eax,%eax
29802 EXIT
29803 ENDPROC(__put_user_4)
29804
29805 ENTRY(__put_user_8)
29806 ENTER
29807 +
29808 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_MEMORY_UDEREF)
29809 + GET_THREAD_INFO(%_ASM_BX)
29810 mov TI_addr_limit(%_ASM_BX),%_ASM_BX
29811 sub $7,%_ASM_BX
29812 cmp %_ASM_BX,%_ASM_CX
29813 jae bad_put_user
29814 ASM_STAC
29815 -4: mov %_ASM_AX,(%_ASM_CX)
29816 +
29817 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
29818 + mov pax_user_shadow_base,%_ASM_BX
29819 + cmp %_ASM_BX,%_ASM_CX
29820 + jb 1234f
29821 + xor %ebx,%ebx
29822 +1234:
29823 +#endif
29824 +
29825 +#endif
29826 +
29827 +4: __copyuser_seg mov %_ASM_AX,(_DEST)
29828 #ifdef CONFIG_X86_32
29829 -5: movl %edx,4(%_ASM_CX)
29830 +5: __copyuser_seg movl %edx,4(_DEST)
29831 #endif
29832 xor %eax,%eax
29833 EXIT
29834 diff --git a/arch/x86/lib/rwlock.S b/arch/x86/lib/rwlock.S
29835 index 1cad221..de671ee 100644
29836 --- a/arch/x86/lib/rwlock.S
29837 +++ b/arch/x86/lib/rwlock.S
29838 @@ -16,13 +16,34 @@ ENTRY(__write_lock_failed)
29839 FRAME
29840 0: LOCK_PREFIX
29841 WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29842 +
29843 +#ifdef CONFIG_PAX_REFCOUNT
29844 + jno 1234f
29845 + LOCK_PREFIX
29846 + WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29847 + int $4
29848 +1234:
29849 + _ASM_EXTABLE(1234b, 1234b)
29850 +#endif
29851 +
29852 1: rep; nop
29853 cmpl $WRITE_LOCK_CMP, (%__lock_ptr)
29854 jne 1b
29855 LOCK_PREFIX
29856 WRITE_LOCK_SUB($RW_LOCK_BIAS) (%__lock_ptr)
29857 +
29858 +#ifdef CONFIG_PAX_REFCOUNT
29859 + jno 1234f
29860 + LOCK_PREFIX
29861 + WRITE_LOCK_ADD($RW_LOCK_BIAS) (%__lock_ptr)
29862 + int $4
29863 +1234:
29864 + _ASM_EXTABLE(1234b, 1234b)
29865 +#endif
29866 +
29867 jnz 0b
29868 ENDFRAME
29869 + pax_force_retaddr
29870 ret
29871 CFI_ENDPROC
29872 END(__write_lock_failed)
29873 @@ -32,13 +53,34 @@ ENTRY(__read_lock_failed)
29874 FRAME
29875 0: LOCK_PREFIX
29876 READ_LOCK_SIZE(inc) (%__lock_ptr)
29877 +
29878 +#ifdef CONFIG_PAX_REFCOUNT
29879 + jno 1234f
29880 + LOCK_PREFIX
29881 + READ_LOCK_SIZE(dec) (%__lock_ptr)
29882 + int $4
29883 +1234:
29884 + _ASM_EXTABLE(1234b, 1234b)
29885 +#endif
29886 +
29887 1: rep; nop
29888 READ_LOCK_SIZE(cmp) $1, (%__lock_ptr)
29889 js 1b
29890 LOCK_PREFIX
29891 READ_LOCK_SIZE(dec) (%__lock_ptr)
29892 +
29893 +#ifdef CONFIG_PAX_REFCOUNT
29894 + jno 1234f
29895 + LOCK_PREFIX
29896 + READ_LOCK_SIZE(inc) (%__lock_ptr)
29897 + int $4
29898 +1234:
29899 + _ASM_EXTABLE(1234b, 1234b)
29900 +#endif
29901 +
29902 js 0b
29903 ENDFRAME
29904 + pax_force_retaddr
29905 ret
29906 CFI_ENDPROC
29907 END(__read_lock_failed)
29908 diff --git a/arch/x86/lib/rwsem.S b/arch/x86/lib/rwsem.S
29909 index 5dff5f0..cadebf4 100644
29910 --- a/arch/x86/lib/rwsem.S
29911 +++ b/arch/x86/lib/rwsem.S
29912 @@ -94,6 +94,7 @@ ENTRY(call_rwsem_down_read_failed)
29913 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29914 CFI_RESTORE __ASM_REG(dx)
29915 restore_common_regs
29916 + pax_force_retaddr
29917 ret
29918 CFI_ENDPROC
29919 ENDPROC(call_rwsem_down_read_failed)
29920 @@ -104,6 +105,7 @@ ENTRY(call_rwsem_down_write_failed)
29921 movq %rax,%rdi
29922 call rwsem_down_write_failed
29923 restore_common_regs
29924 + pax_force_retaddr
29925 ret
29926 CFI_ENDPROC
29927 ENDPROC(call_rwsem_down_write_failed)
29928 @@ -117,7 +119,8 @@ ENTRY(call_rwsem_wake)
29929 movq %rax,%rdi
29930 call rwsem_wake
29931 restore_common_regs
29932 -1: ret
29933 +1: pax_force_retaddr
29934 + ret
29935 CFI_ENDPROC
29936 ENDPROC(call_rwsem_wake)
29937
29938 @@ -131,6 +134,7 @@ ENTRY(call_rwsem_downgrade_wake)
29939 __ASM_SIZE(pop,_cfi) %__ASM_REG(dx)
29940 CFI_RESTORE __ASM_REG(dx)
29941 restore_common_regs
29942 + pax_force_retaddr
29943 ret
29944 CFI_ENDPROC
29945 ENDPROC(call_rwsem_downgrade_wake)
29946 diff --git a/arch/x86/lib/thunk_64.S b/arch/x86/lib/thunk_64.S
29947 index a63efd6..8149fbe 100644
29948 --- a/arch/x86/lib/thunk_64.S
29949 +++ b/arch/x86/lib/thunk_64.S
29950 @@ -8,6 +8,7 @@
29951 #include <linux/linkage.h>
29952 #include <asm/dwarf2.h>
29953 #include <asm/calling.h>
29954 +#include <asm/alternative-asm.h>
29955
29956 /* rdi: arg1 ... normal C conventions. rax is saved/restored. */
29957 .macro THUNK name, func, put_ret_addr_in_rdi=0
29958 @@ -15,11 +16,11 @@
29959 \name:
29960 CFI_STARTPROC
29961
29962 - /* this one pushes 9 elems, the next one would be %rIP */
29963 - SAVE_ARGS
29964 + /* this one pushes 15+1 elems, the next one would be %rIP */
29965 + SAVE_ARGS 8
29966
29967 .if \put_ret_addr_in_rdi
29968 - movq_cfi_restore 9*8, rdi
29969 + movq_cfi_restore RIP, rdi
29970 .endif
29971
29972 call \func
29973 @@ -38,8 +39,9 @@
29974
29975 /* SAVE_ARGS below is used only for the .cfi directives it contains. */
29976 CFI_STARTPROC
29977 - SAVE_ARGS
29978 + SAVE_ARGS 8
29979 restore:
29980 - RESTORE_ARGS
29981 + RESTORE_ARGS 1,8
29982 + pax_force_retaddr
29983 ret
29984 CFI_ENDPROC
29985 diff --git a/arch/x86/lib/usercopy_32.c b/arch/x86/lib/usercopy_32.c
29986 index e2f5e21..4b22130 100644
29987 --- a/arch/x86/lib/usercopy_32.c
29988 +++ b/arch/x86/lib/usercopy_32.c
29989 @@ -42,11 +42,13 @@ do { \
29990 int __d0; \
29991 might_fault(); \
29992 __asm__ __volatile__( \
29993 + __COPYUSER_SET_ES \
29994 ASM_STAC "\n" \
29995 "0: rep; stosl\n" \
29996 " movl %2,%0\n" \
29997 "1: rep; stosb\n" \
29998 "2: " ASM_CLAC "\n" \
29999 + __COPYUSER_RESTORE_ES \
30000 ".section .fixup,\"ax\"\n" \
30001 "3: lea 0(%2,%0,4),%0\n" \
30002 " jmp 2b\n" \
30003 @@ -98,7 +100,7 @@ EXPORT_SYMBOL(__clear_user);
30004
30005 #ifdef CONFIG_X86_INTEL_USERCOPY
30006 static unsigned long
30007 -__copy_user_intel(void __user *to, const void *from, unsigned long size)
30008 +__generic_copy_to_user_intel(void __user *to, const void *from, unsigned long size)
30009 {
30010 int d0, d1;
30011 __asm__ __volatile__(
30012 @@ -110,36 +112,36 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30013 " .align 2,0x90\n"
30014 "3: movl 0(%4), %%eax\n"
30015 "4: movl 4(%4), %%edx\n"
30016 - "5: movl %%eax, 0(%3)\n"
30017 - "6: movl %%edx, 4(%3)\n"
30018 + "5: "__copyuser_seg" movl %%eax, 0(%3)\n"
30019 + "6: "__copyuser_seg" movl %%edx, 4(%3)\n"
30020 "7: movl 8(%4), %%eax\n"
30021 "8: movl 12(%4),%%edx\n"
30022 - "9: movl %%eax, 8(%3)\n"
30023 - "10: movl %%edx, 12(%3)\n"
30024 + "9: "__copyuser_seg" movl %%eax, 8(%3)\n"
30025 + "10: "__copyuser_seg" movl %%edx, 12(%3)\n"
30026 "11: movl 16(%4), %%eax\n"
30027 "12: movl 20(%4), %%edx\n"
30028 - "13: movl %%eax, 16(%3)\n"
30029 - "14: movl %%edx, 20(%3)\n"
30030 + "13: "__copyuser_seg" movl %%eax, 16(%3)\n"
30031 + "14: "__copyuser_seg" movl %%edx, 20(%3)\n"
30032 "15: movl 24(%4), %%eax\n"
30033 "16: movl 28(%4), %%edx\n"
30034 - "17: movl %%eax, 24(%3)\n"
30035 - "18: movl %%edx, 28(%3)\n"
30036 + "17: "__copyuser_seg" movl %%eax, 24(%3)\n"
30037 + "18: "__copyuser_seg" movl %%edx, 28(%3)\n"
30038 "19: movl 32(%4), %%eax\n"
30039 "20: movl 36(%4), %%edx\n"
30040 - "21: movl %%eax, 32(%3)\n"
30041 - "22: movl %%edx, 36(%3)\n"
30042 + "21: "__copyuser_seg" movl %%eax, 32(%3)\n"
30043 + "22: "__copyuser_seg" movl %%edx, 36(%3)\n"
30044 "23: movl 40(%4), %%eax\n"
30045 "24: movl 44(%4), %%edx\n"
30046 - "25: movl %%eax, 40(%3)\n"
30047 - "26: movl %%edx, 44(%3)\n"
30048 + "25: "__copyuser_seg" movl %%eax, 40(%3)\n"
30049 + "26: "__copyuser_seg" movl %%edx, 44(%3)\n"
30050 "27: movl 48(%4), %%eax\n"
30051 "28: movl 52(%4), %%edx\n"
30052 - "29: movl %%eax, 48(%3)\n"
30053 - "30: movl %%edx, 52(%3)\n"
30054 + "29: "__copyuser_seg" movl %%eax, 48(%3)\n"
30055 + "30: "__copyuser_seg" movl %%edx, 52(%3)\n"
30056 "31: movl 56(%4), %%eax\n"
30057 "32: movl 60(%4), %%edx\n"
30058 - "33: movl %%eax, 56(%3)\n"
30059 - "34: movl %%edx, 60(%3)\n"
30060 + "33: "__copyuser_seg" movl %%eax, 56(%3)\n"
30061 + "34: "__copyuser_seg" movl %%edx, 60(%3)\n"
30062 " addl $-64, %0\n"
30063 " addl $64, %4\n"
30064 " addl $64, %3\n"
30065 @@ -149,10 +151,116 @@ __copy_user_intel(void __user *to, const void *from, unsigned long size)
30066 " shrl $2, %0\n"
30067 " andl $3, %%eax\n"
30068 " cld\n"
30069 + __COPYUSER_SET_ES
30070 "99: rep; movsl\n"
30071 "36: movl %%eax, %0\n"
30072 "37: rep; movsb\n"
30073 "100:\n"
30074 + __COPYUSER_RESTORE_ES
30075 + ".section .fixup,\"ax\"\n"
30076 + "101: lea 0(%%eax,%0,4),%0\n"
30077 + " jmp 100b\n"
30078 + ".previous\n"
30079 + _ASM_EXTABLE(1b,100b)
30080 + _ASM_EXTABLE(2b,100b)
30081 + _ASM_EXTABLE(3b,100b)
30082 + _ASM_EXTABLE(4b,100b)
30083 + _ASM_EXTABLE(5b,100b)
30084 + _ASM_EXTABLE(6b,100b)
30085 + _ASM_EXTABLE(7b,100b)
30086 + _ASM_EXTABLE(8b,100b)
30087 + _ASM_EXTABLE(9b,100b)
30088 + _ASM_EXTABLE(10b,100b)
30089 + _ASM_EXTABLE(11b,100b)
30090 + _ASM_EXTABLE(12b,100b)
30091 + _ASM_EXTABLE(13b,100b)
30092 + _ASM_EXTABLE(14b,100b)
30093 + _ASM_EXTABLE(15b,100b)
30094 + _ASM_EXTABLE(16b,100b)
30095 + _ASM_EXTABLE(17b,100b)
30096 + _ASM_EXTABLE(18b,100b)
30097 + _ASM_EXTABLE(19b,100b)
30098 + _ASM_EXTABLE(20b,100b)
30099 + _ASM_EXTABLE(21b,100b)
30100 + _ASM_EXTABLE(22b,100b)
30101 + _ASM_EXTABLE(23b,100b)
30102 + _ASM_EXTABLE(24b,100b)
30103 + _ASM_EXTABLE(25b,100b)
30104 + _ASM_EXTABLE(26b,100b)
30105 + _ASM_EXTABLE(27b,100b)
30106 + _ASM_EXTABLE(28b,100b)
30107 + _ASM_EXTABLE(29b,100b)
30108 + _ASM_EXTABLE(30b,100b)
30109 + _ASM_EXTABLE(31b,100b)
30110 + _ASM_EXTABLE(32b,100b)
30111 + _ASM_EXTABLE(33b,100b)
30112 + _ASM_EXTABLE(34b,100b)
30113 + _ASM_EXTABLE(35b,100b)
30114 + _ASM_EXTABLE(36b,100b)
30115 + _ASM_EXTABLE(37b,100b)
30116 + _ASM_EXTABLE(99b,101b)
30117 + : "=&c"(size), "=&D" (d0), "=&S" (d1)
30118 + : "1"(to), "2"(from), "0"(size)
30119 + : "eax", "edx", "memory");
30120 + return size;
30121 +}
30122 +
30123 +static unsigned long
30124 +__generic_copy_from_user_intel(void *to, const void __user *from, unsigned long size)
30125 +{
30126 + int d0, d1;
30127 + __asm__ __volatile__(
30128 + " .align 2,0x90\n"
30129 + "1: "__copyuser_seg" movl 32(%4), %%eax\n"
30130 + " cmpl $67, %0\n"
30131 + " jbe 3f\n"
30132 + "2: "__copyuser_seg" movl 64(%4), %%eax\n"
30133 + " .align 2,0x90\n"
30134 + "3: "__copyuser_seg" movl 0(%4), %%eax\n"
30135 + "4: "__copyuser_seg" movl 4(%4), %%edx\n"
30136 + "5: movl %%eax, 0(%3)\n"
30137 + "6: movl %%edx, 4(%3)\n"
30138 + "7: "__copyuser_seg" movl 8(%4), %%eax\n"
30139 + "8: "__copyuser_seg" movl 12(%4),%%edx\n"
30140 + "9: movl %%eax, 8(%3)\n"
30141 + "10: movl %%edx, 12(%3)\n"
30142 + "11: "__copyuser_seg" movl 16(%4), %%eax\n"
30143 + "12: "__copyuser_seg" movl 20(%4), %%edx\n"
30144 + "13: movl %%eax, 16(%3)\n"
30145 + "14: movl %%edx, 20(%3)\n"
30146 + "15: "__copyuser_seg" movl 24(%4), %%eax\n"
30147 + "16: "__copyuser_seg" movl 28(%4), %%edx\n"
30148 + "17: movl %%eax, 24(%3)\n"
30149 + "18: movl %%edx, 28(%3)\n"
30150 + "19: "__copyuser_seg" movl 32(%4), %%eax\n"
30151 + "20: "__copyuser_seg" movl 36(%4), %%edx\n"
30152 + "21: movl %%eax, 32(%3)\n"
30153 + "22: movl %%edx, 36(%3)\n"
30154 + "23: "__copyuser_seg" movl 40(%4), %%eax\n"
30155 + "24: "__copyuser_seg" movl 44(%4), %%edx\n"
30156 + "25: movl %%eax, 40(%3)\n"
30157 + "26: movl %%edx, 44(%3)\n"
30158 + "27: "__copyuser_seg" movl 48(%4), %%eax\n"
30159 + "28: "__copyuser_seg" movl 52(%4), %%edx\n"
30160 + "29: movl %%eax, 48(%3)\n"
30161 + "30: movl %%edx, 52(%3)\n"
30162 + "31: "__copyuser_seg" movl 56(%4), %%eax\n"
30163 + "32: "__copyuser_seg" movl 60(%4), %%edx\n"
30164 + "33: movl %%eax, 56(%3)\n"
30165 + "34: movl %%edx, 60(%3)\n"
30166 + " addl $-64, %0\n"
30167 + " addl $64, %4\n"
30168 + " addl $64, %3\n"
30169 + " cmpl $63, %0\n"
30170 + " ja 1b\n"
30171 + "35: movl %0, %%eax\n"
30172 + " shrl $2, %0\n"
30173 + " andl $3, %%eax\n"
30174 + " cld\n"
30175 + "99: rep; "__copyuser_seg" movsl\n"
30176 + "36: movl %%eax, %0\n"
30177 + "37: rep; "__copyuser_seg" movsb\n"
30178 + "100:\n"
30179 ".section .fixup,\"ax\"\n"
30180 "101: lea 0(%%eax,%0,4),%0\n"
30181 " jmp 100b\n"
30182 @@ -207,41 +315,41 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30183 int d0, d1;
30184 __asm__ __volatile__(
30185 " .align 2,0x90\n"
30186 - "0: movl 32(%4), %%eax\n"
30187 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30188 " cmpl $67, %0\n"
30189 " jbe 2f\n"
30190 - "1: movl 64(%4), %%eax\n"
30191 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30192 " .align 2,0x90\n"
30193 - "2: movl 0(%4), %%eax\n"
30194 - "21: movl 4(%4), %%edx\n"
30195 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30196 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30197 " movl %%eax, 0(%3)\n"
30198 " movl %%edx, 4(%3)\n"
30199 - "3: movl 8(%4), %%eax\n"
30200 - "31: movl 12(%4),%%edx\n"
30201 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30202 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30203 " movl %%eax, 8(%3)\n"
30204 " movl %%edx, 12(%3)\n"
30205 - "4: movl 16(%4), %%eax\n"
30206 - "41: movl 20(%4), %%edx\n"
30207 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30208 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30209 " movl %%eax, 16(%3)\n"
30210 " movl %%edx, 20(%3)\n"
30211 - "10: movl 24(%4), %%eax\n"
30212 - "51: movl 28(%4), %%edx\n"
30213 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30214 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30215 " movl %%eax, 24(%3)\n"
30216 " movl %%edx, 28(%3)\n"
30217 - "11: movl 32(%4), %%eax\n"
30218 - "61: movl 36(%4), %%edx\n"
30219 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30220 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30221 " movl %%eax, 32(%3)\n"
30222 " movl %%edx, 36(%3)\n"
30223 - "12: movl 40(%4), %%eax\n"
30224 - "71: movl 44(%4), %%edx\n"
30225 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30226 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30227 " movl %%eax, 40(%3)\n"
30228 " movl %%edx, 44(%3)\n"
30229 - "13: movl 48(%4), %%eax\n"
30230 - "81: movl 52(%4), %%edx\n"
30231 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30232 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30233 " movl %%eax, 48(%3)\n"
30234 " movl %%edx, 52(%3)\n"
30235 - "14: movl 56(%4), %%eax\n"
30236 - "91: movl 60(%4), %%edx\n"
30237 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30238 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30239 " movl %%eax, 56(%3)\n"
30240 " movl %%edx, 60(%3)\n"
30241 " addl $-64, %0\n"
30242 @@ -253,9 +361,9 @@ __copy_user_zeroing_intel(void *to, const void __user *from, unsigned long size)
30243 " shrl $2, %0\n"
30244 " andl $3, %%eax\n"
30245 " cld\n"
30246 - "6: rep; movsl\n"
30247 + "6: rep; "__copyuser_seg" movsl\n"
30248 " movl %%eax,%0\n"
30249 - "7: rep; movsb\n"
30250 + "7: rep; "__copyuser_seg" movsb\n"
30251 "8:\n"
30252 ".section .fixup,\"ax\"\n"
30253 "9: lea 0(%%eax,%0,4),%0\n"
30254 @@ -305,41 +413,41 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30255
30256 __asm__ __volatile__(
30257 " .align 2,0x90\n"
30258 - "0: movl 32(%4), %%eax\n"
30259 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30260 " cmpl $67, %0\n"
30261 " jbe 2f\n"
30262 - "1: movl 64(%4), %%eax\n"
30263 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30264 " .align 2,0x90\n"
30265 - "2: movl 0(%4), %%eax\n"
30266 - "21: movl 4(%4), %%edx\n"
30267 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30268 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30269 " movnti %%eax, 0(%3)\n"
30270 " movnti %%edx, 4(%3)\n"
30271 - "3: movl 8(%4), %%eax\n"
30272 - "31: movl 12(%4),%%edx\n"
30273 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30274 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30275 " movnti %%eax, 8(%3)\n"
30276 " movnti %%edx, 12(%3)\n"
30277 - "4: movl 16(%4), %%eax\n"
30278 - "41: movl 20(%4), %%edx\n"
30279 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30280 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30281 " movnti %%eax, 16(%3)\n"
30282 " movnti %%edx, 20(%3)\n"
30283 - "10: movl 24(%4), %%eax\n"
30284 - "51: movl 28(%4), %%edx\n"
30285 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30286 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30287 " movnti %%eax, 24(%3)\n"
30288 " movnti %%edx, 28(%3)\n"
30289 - "11: movl 32(%4), %%eax\n"
30290 - "61: movl 36(%4), %%edx\n"
30291 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30292 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30293 " movnti %%eax, 32(%3)\n"
30294 " movnti %%edx, 36(%3)\n"
30295 - "12: movl 40(%4), %%eax\n"
30296 - "71: movl 44(%4), %%edx\n"
30297 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30298 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30299 " movnti %%eax, 40(%3)\n"
30300 " movnti %%edx, 44(%3)\n"
30301 - "13: movl 48(%4), %%eax\n"
30302 - "81: movl 52(%4), %%edx\n"
30303 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30304 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30305 " movnti %%eax, 48(%3)\n"
30306 " movnti %%edx, 52(%3)\n"
30307 - "14: movl 56(%4), %%eax\n"
30308 - "91: movl 60(%4), %%edx\n"
30309 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30310 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30311 " movnti %%eax, 56(%3)\n"
30312 " movnti %%edx, 60(%3)\n"
30313 " addl $-64, %0\n"
30314 @@ -352,9 +460,9 @@ static unsigned long __copy_user_zeroing_intel_nocache(void *to,
30315 " shrl $2, %0\n"
30316 " andl $3, %%eax\n"
30317 " cld\n"
30318 - "6: rep; movsl\n"
30319 + "6: rep; "__copyuser_seg" movsl\n"
30320 " movl %%eax,%0\n"
30321 - "7: rep; movsb\n"
30322 + "7: rep; "__copyuser_seg" movsb\n"
30323 "8:\n"
30324 ".section .fixup,\"ax\"\n"
30325 "9: lea 0(%%eax,%0,4),%0\n"
30326 @@ -399,41 +507,41 @@ static unsigned long __copy_user_intel_nocache(void *to,
30327
30328 __asm__ __volatile__(
30329 " .align 2,0x90\n"
30330 - "0: movl 32(%4), %%eax\n"
30331 + "0: "__copyuser_seg" movl 32(%4), %%eax\n"
30332 " cmpl $67, %0\n"
30333 " jbe 2f\n"
30334 - "1: movl 64(%4), %%eax\n"
30335 + "1: "__copyuser_seg" movl 64(%4), %%eax\n"
30336 " .align 2,0x90\n"
30337 - "2: movl 0(%4), %%eax\n"
30338 - "21: movl 4(%4), %%edx\n"
30339 + "2: "__copyuser_seg" movl 0(%4), %%eax\n"
30340 + "21: "__copyuser_seg" movl 4(%4), %%edx\n"
30341 " movnti %%eax, 0(%3)\n"
30342 " movnti %%edx, 4(%3)\n"
30343 - "3: movl 8(%4), %%eax\n"
30344 - "31: movl 12(%4),%%edx\n"
30345 + "3: "__copyuser_seg" movl 8(%4), %%eax\n"
30346 + "31: "__copyuser_seg" movl 12(%4),%%edx\n"
30347 " movnti %%eax, 8(%3)\n"
30348 " movnti %%edx, 12(%3)\n"
30349 - "4: movl 16(%4), %%eax\n"
30350 - "41: movl 20(%4), %%edx\n"
30351 + "4: "__copyuser_seg" movl 16(%4), %%eax\n"
30352 + "41: "__copyuser_seg" movl 20(%4), %%edx\n"
30353 " movnti %%eax, 16(%3)\n"
30354 " movnti %%edx, 20(%3)\n"
30355 - "10: movl 24(%4), %%eax\n"
30356 - "51: movl 28(%4), %%edx\n"
30357 + "10: "__copyuser_seg" movl 24(%4), %%eax\n"
30358 + "51: "__copyuser_seg" movl 28(%4), %%edx\n"
30359 " movnti %%eax, 24(%3)\n"
30360 " movnti %%edx, 28(%3)\n"
30361 - "11: movl 32(%4), %%eax\n"
30362 - "61: movl 36(%4), %%edx\n"
30363 + "11: "__copyuser_seg" movl 32(%4), %%eax\n"
30364 + "61: "__copyuser_seg" movl 36(%4), %%edx\n"
30365 " movnti %%eax, 32(%3)\n"
30366 " movnti %%edx, 36(%3)\n"
30367 - "12: movl 40(%4), %%eax\n"
30368 - "71: movl 44(%4), %%edx\n"
30369 + "12: "__copyuser_seg" movl 40(%4), %%eax\n"
30370 + "71: "__copyuser_seg" movl 44(%4), %%edx\n"
30371 " movnti %%eax, 40(%3)\n"
30372 " movnti %%edx, 44(%3)\n"
30373 - "13: movl 48(%4), %%eax\n"
30374 - "81: movl 52(%4), %%edx\n"
30375 + "13: "__copyuser_seg" movl 48(%4), %%eax\n"
30376 + "81: "__copyuser_seg" movl 52(%4), %%edx\n"
30377 " movnti %%eax, 48(%3)\n"
30378 " movnti %%edx, 52(%3)\n"
30379 - "14: movl 56(%4), %%eax\n"
30380 - "91: movl 60(%4), %%edx\n"
30381 + "14: "__copyuser_seg" movl 56(%4), %%eax\n"
30382 + "91: "__copyuser_seg" movl 60(%4), %%edx\n"
30383 " movnti %%eax, 56(%3)\n"
30384 " movnti %%edx, 60(%3)\n"
30385 " addl $-64, %0\n"
30386 @@ -446,9 +554,9 @@ static unsigned long __copy_user_intel_nocache(void *to,
30387 " shrl $2, %0\n"
30388 " andl $3, %%eax\n"
30389 " cld\n"
30390 - "6: rep; movsl\n"
30391 + "6: rep; "__copyuser_seg" movsl\n"
30392 " movl %%eax,%0\n"
30393 - "7: rep; movsb\n"
30394 + "7: rep; "__copyuser_seg" movsb\n"
30395 "8:\n"
30396 ".section .fixup,\"ax\"\n"
30397 "9: lea 0(%%eax,%0,4),%0\n"
30398 @@ -488,32 +596,36 @@ static unsigned long __copy_user_intel_nocache(void *to,
30399 */
30400 unsigned long __copy_user_zeroing_intel(void *to, const void __user *from,
30401 unsigned long size);
30402 -unsigned long __copy_user_intel(void __user *to, const void *from,
30403 +unsigned long __generic_copy_to_user_intel(void __user *to, const void *from,
30404 + unsigned long size);
30405 +unsigned long __generic_copy_from_user_intel(void *to, const void __user *from,
30406 unsigned long size);
30407 unsigned long __copy_user_zeroing_intel_nocache(void *to,
30408 const void __user *from, unsigned long size);
30409 #endif /* CONFIG_X86_INTEL_USERCOPY */
30410
30411 /* Generic arbitrary sized copy. */
30412 -#define __copy_user(to, from, size) \
30413 +#define __copy_user(to, from, size, prefix, set, restore) \
30414 do { \
30415 int __d0, __d1, __d2; \
30416 __asm__ __volatile__( \
30417 + set \
30418 " cmp $7,%0\n" \
30419 " jbe 1f\n" \
30420 " movl %1,%0\n" \
30421 " negl %0\n" \
30422 " andl $7,%0\n" \
30423 " subl %0,%3\n" \
30424 - "4: rep; movsb\n" \
30425 + "4: rep; "prefix"movsb\n" \
30426 " movl %3,%0\n" \
30427 " shrl $2,%0\n" \
30428 " andl $3,%3\n" \
30429 " .align 2,0x90\n" \
30430 - "0: rep; movsl\n" \
30431 + "0: rep; "prefix"movsl\n" \
30432 " movl %3,%0\n" \
30433 - "1: rep; movsb\n" \
30434 + "1: rep; "prefix"movsb\n" \
30435 "2:\n" \
30436 + restore \
30437 ".section .fixup,\"ax\"\n" \
30438 "5: addl %3,%0\n" \
30439 " jmp 2b\n" \
30440 @@ -538,14 +650,14 @@ do { \
30441 " negl %0\n" \
30442 " andl $7,%0\n" \
30443 " subl %0,%3\n" \
30444 - "4: rep; movsb\n" \
30445 + "4: rep; "__copyuser_seg"movsb\n" \
30446 " movl %3,%0\n" \
30447 " shrl $2,%0\n" \
30448 " andl $3,%3\n" \
30449 " .align 2,0x90\n" \
30450 - "0: rep; movsl\n" \
30451 + "0: rep; "__copyuser_seg"movsl\n" \
30452 " movl %3,%0\n" \
30453 - "1: rep; movsb\n" \
30454 + "1: rep; "__copyuser_seg"movsb\n" \
30455 "2:\n" \
30456 ".section .fixup,\"ax\"\n" \
30457 "5: addl %3,%0\n" \
30458 @@ -572,9 +684,9 @@ unsigned long __copy_to_user_ll(void __user *to, const void *from,
30459 {
30460 stac();
30461 if (movsl_is_ok(to, from, n))
30462 - __copy_user(to, from, n);
30463 + __copy_user(to, from, n, "", __COPYUSER_SET_ES, __COPYUSER_RESTORE_ES);
30464 else
30465 - n = __copy_user_intel(to, from, n);
30466 + n = __generic_copy_to_user_intel(to, from, n);
30467 clac();
30468 return n;
30469 }
30470 @@ -598,10 +710,9 @@ unsigned long __copy_from_user_ll_nozero(void *to, const void __user *from,
30471 {
30472 stac();
30473 if (movsl_is_ok(to, from, n))
30474 - __copy_user(to, from, n);
30475 + __copy_user(to, from, n, __copyuser_seg, "", "");
30476 else
30477 - n = __copy_user_intel((void __user *)to,
30478 - (const void *)from, n);
30479 + n = __generic_copy_from_user_intel(to, from, n);
30480 clac();
30481 return n;
30482 }
30483 @@ -632,58 +743,38 @@ unsigned long __copy_from_user_ll_nocache_nozero(void *to, const void __user *fr
30484 if (n > 64 && cpu_has_xmm2)
30485 n = __copy_user_intel_nocache(to, from, n);
30486 else
30487 - __copy_user(to, from, n);
30488 + __copy_user(to, from, n, __copyuser_seg, "", "");
30489 #else
30490 - __copy_user(to, from, n);
30491 + __copy_user(to, from, n, __copyuser_seg, "", "");
30492 #endif
30493 clac();
30494 return n;
30495 }
30496 EXPORT_SYMBOL(__copy_from_user_ll_nocache_nozero);
30497
30498 -/**
30499 - * copy_to_user: - Copy a block of data into user space.
30500 - * @to: Destination address, in user space.
30501 - * @from: Source address, in kernel space.
30502 - * @n: Number of bytes to copy.
30503 - *
30504 - * Context: User context only. This function may sleep.
30505 - *
30506 - * Copy data from kernel space to user space.
30507 - *
30508 - * Returns number of bytes that could not be copied.
30509 - * On success, this will be zero.
30510 - */
30511 -unsigned long _copy_to_user(void __user *to, const void *from, unsigned n)
30512 +#ifdef CONFIG_PAX_MEMORY_UDEREF
30513 +void __set_fs(mm_segment_t x)
30514 {
30515 - if (access_ok(VERIFY_WRITE, to, n))
30516 - n = __copy_to_user(to, from, n);
30517 - return n;
30518 + switch (x.seg) {
30519 + case 0:
30520 + loadsegment(gs, 0);
30521 + break;
30522 + case TASK_SIZE_MAX:
30523 + loadsegment(gs, __USER_DS);
30524 + break;
30525 + case -1UL:
30526 + loadsegment(gs, __KERNEL_DS);
30527 + break;
30528 + default:
30529 + BUG();
30530 + }
30531 }
30532 -EXPORT_SYMBOL(_copy_to_user);
30533 +EXPORT_SYMBOL(__set_fs);
30534
30535 -/**
30536 - * copy_from_user: - Copy a block of data from user space.
30537 - * @to: Destination address, in kernel space.
30538 - * @from: Source address, in user space.
30539 - * @n: Number of bytes to copy.
30540 - *
30541 - * Context: User context only. This function may sleep.
30542 - *
30543 - * Copy data from user space to kernel space.
30544 - *
30545 - * Returns number of bytes that could not be copied.
30546 - * On success, this will be zero.
30547 - *
30548 - * If some data could not be copied, this function will pad the copied
30549 - * data to the requested size using zero bytes.
30550 - */
30551 -unsigned long _copy_from_user(void *to, const void __user *from, unsigned n)
30552 +void set_fs(mm_segment_t x)
30553 {
30554 - if (access_ok(VERIFY_READ, from, n))
30555 - n = __copy_from_user(to, from, n);
30556 - else
30557 - memset(to, 0, n);
30558 - return n;
30559 + current_thread_info()->addr_limit = x;
30560 + __set_fs(x);
30561 }
30562 -EXPORT_SYMBOL(_copy_from_user);
30563 +EXPORT_SYMBOL(set_fs);
30564 +#endif
30565 diff --git a/arch/x86/lib/usercopy_64.c b/arch/x86/lib/usercopy_64.c
30566 index c905e89..01ab928 100644
30567 --- a/arch/x86/lib/usercopy_64.c
30568 +++ b/arch/x86/lib/usercopy_64.c
30569 @@ -18,6 +18,7 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
30570 might_fault();
30571 /* no memory constraint because it doesn't change any memory gcc knows
30572 about */
30573 + pax_open_userland();
30574 stac();
30575 asm volatile(
30576 " testq %[size8],%[size8]\n"
30577 @@ -39,9 +40,10 @@ unsigned long __clear_user(void __user *addr, unsigned long size)
30578 _ASM_EXTABLE(0b,3b)
30579 _ASM_EXTABLE(1b,2b)
30580 : [size8] "=&c"(size), [dst] "=&D" (__d0)
30581 - : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(addr),
30582 + : [size1] "r"(size & 7), "[size8]" (size / 8), "[dst]"(____m(addr)),
30583 [zero] "r" (0UL), [eight] "r" (8UL));
30584 clac();
30585 + pax_close_userland();
30586 return size;
30587 }
30588 EXPORT_SYMBOL(__clear_user);
30589 @@ -54,12 +56,11 @@ unsigned long clear_user(void __user *to, unsigned long n)
30590 }
30591 EXPORT_SYMBOL(clear_user);
30592
30593 -unsigned long copy_in_user(void __user *to, const void __user *from, unsigned len)
30594 +unsigned long copy_in_user(void __user *to, const void __user *from, unsigned long len)
30595 {
30596 - if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len)) {
30597 - return copy_user_generic((__force void *)to, (__force void *)from, len);
30598 - }
30599 - return len;
30600 + if (access_ok(VERIFY_WRITE, to, len) && access_ok(VERIFY_READ, from, len))
30601 + return copy_user_generic((void __force_kernel *)____m(to), (void __force_kernel *)____m(from), len);
30602 + return len;
30603 }
30604 EXPORT_SYMBOL(copy_in_user);
30605
30606 @@ -69,11 +70,13 @@ EXPORT_SYMBOL(copy_in_user);
30607 * it is not necessary to optimize tail handling.
30608 */
30609 __visible unsigned long
30610 -copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
30611 +copy_user_handle_tail(char __user *to, char __user *from, unsigned long len, unsigned zerorest)
30612 {
30613 char c;
30614 unsigned zero_len;
30615
30616 + clac();
30617 + pax_close_userland();
30618 for (; len; --len, to++) {
30619 if (__get_user_nocheck(c, from++, sizeof(char)))
30620 break;
30621 @@ -84,6 +87,5 @@ copy_user_handle_tail(char *to, char *from, unsigned len, unsigned zerorest)
30622 for (c = 0, zero_len = len; zerorest && zero_len; --zero_len)
30623 if (__put_user_nocheck(c, to++, sizeof(char)))
30624 break;
30625 - clac();
30626 return len;
30627 }
30628 diff --git a/arch/x86/mm/Makefile b/arch/x86/mm/Makefile
30629 index 6a19ad9..1c48f9a 100644
30630 --- a/arch/x86/mm/Makefile
30631 +++ b/arch/x86/mm/Makefile
30632 @@ -30,3 +30,7 @@ obj-$(CONFIG_ACPI_NUMA) += srat.o
30633 obj-$(CONFIG_NUMA_EMU) += numa_emulation.o
30634
30635 obj-$(CONFIG_MEMTEST) += memtest.o
30636 +
30637 +quote:="
30638 +obj-$(CONFIG_X86_64) += uderef_64.o
30639 +CFLAGS_uderef_64.o := $(subst $(quote),,$(CONFIG_ARCH_HWEIGHT_CFLAGS))
30640 diff --git a/arch/x86/mm/extable.c b/arch/x86/mm/extable.c
30641 index 903ec1e..c4166b2 100644
30642 --- a/arch/x86/mm/extable.c
30643 +++ b/arch/x86/mm/extable.c
30644 @@ -6,12 +6,24 @@
30645 static inline unsigned long
30646 ex_insn_addr(const struct exception_table_entry *x)
30647 {
30648 - return (unsigned long)&x->insn + x->insn;
30649 + unsigned long reloc = 0;
30650 +
30651 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30652 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30653 +#endif
30654 +
30655 + return (unsigned long)&x->insn + x->insn + reloc;
30656 }
30657 static inline unsigned long
30658 ex_fixup_addr(const struct exception_table_entry *x)
30659 {
30660 - return (unsigned long)&x->fixup + x->fixup;
30661 + unsigned long reloc = 0;
30662 +
30663 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30664 + reloc = ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30665 +#endif
30666 +
30667 + return (unsigned long)&x->fixup + x->fixup + reloc;
30668 }
30669
30670 int fixup_exception(struct pt_regs *regs)
30671 @@ -20,7 +32,7 @@ int fixup_exception(struct pt_regs *regs)
30672 unsigned long new_ip;
30673
30674 #ifdef CONFIG_PNPBIOS
30675 - if (unlikely(SEGMENT_IS_PNP_CODE(regs->cs))) {
30676 + if (unlikely(!v8086_mode(regs) && SEGMENT_IS_PNP_CODE(regs->cs))) {
30677 extern u32 pnp_bios_fault_eip, pnp_bios_fault_esp;
30678 extern u32 pnp_bios_is_utter_crap;
30679 pnp_bios_is_utter_crap = 1;
30680 @@ -145,6 +157,13 @@ void sort_extable(struct exception_table_entry *start,
30681 i += 4;
30682 p->fixup -= i;
30683 i += 4;
30684 +
30685 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
30686 + BUILD_BUG_ON(!IS_ENABLED(CONFIG_BUILDTIME_EXTABLE_SORT));
30687 + p->insn -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30688 + p->fixup -= ____LOAD_PHYSICAL_ADDR - LOAD_PHYSICAL_ADDR;
30689 +#endif
30690 +
30691 }
30692 }
30693
30694 diff --git a/arch/x86/mm/fault.c b/arch/x86/mm/fault.c
30695 index 9d591c8..2e61790 100644
30696 --- a/arch/x86/mm/fault.c
30697 +++ b/arch/x86/mm/fault.c
30698 @@ -14,11 +14,18 @@
30699 #include <linux/hugetlb.h> /* hstate_index_to_shift */
30700 #include <linux/prefetch.h> /* prefetchw */
30701 #include <linux/context_tracking.h> /* exception_enter(), ... */
30702 +#include <linux/unistd.h>
30703 +#include <linux/compiler.h>
30704
30705 #include <asm/traps.h> /* dotraplinkage, ... */
30706 #include <asm/pgalloc.h> /* pgd_*(), ... */
30707 #include <asm/kmemcheck.h> /* kmemcheck_*(), ... */
30708 #include <asm/fixmap.h> /* VSYSCALL_START */
30709 +#include <asm/tlbflush.h>
30710 +
30711 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
30712 +#include <asm/stacktrace.h>
30713 +#endif
30714
30715 #define CREATE_TRACE_POINTS
30716 #include <asm/trace/exceptions.h>
30717 @@ -59,7 +66,7 @@ static inline int __kprobes kprobes_fault(struct pt_regs *regs)
30718 int ret = 0;
30719
30720 /* kprobe_running() needs smp_processor_id() */
30721 - if (kprobes_built_in() && !user_mode_vm(regs)) {
30722 + if (kprobes_built_in() && !user_mode(regs)) {
30723 preempt_disable();
30724 if (kprobe_running() && kprobe_fault_handler(regs, 14))
30725 ret = 1;
30726 @@ -120,7 +127,10 @@ check_prefetch_opcode(struct pt_regs *regs, unsigned char *instr,
30727 return !instr_lo || (instr_lo>>1) == 1;
30728 case 0x00:
30729 /* Prefetch instruction is 0x0F0D or 0x0F18 */
30730 - if (probe_kernel_address(instr, opcode))
30731 + if (user_mode(regs)) {
30732 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
30733 + return 0;
30734 + } else if (probe_kernel_address(instr, opcode))
30735 return 0;
30736
30737 *prefetch = (instr_lo == 0xF) &&
30738 @@ -154,7 +164,10 @@ is_prefetch(struct pt_regs *regs, unsigned long error_code, unsigned long addr)
30739 while (instr < max_instr) {
30740 unsigned char opcode;
30741
30742 - if (probe_kernel_address(instr, opcode))
30743 + if (user_mode(regs)) {
30744 + if (__copy_from_user_inatomic(&opcode, (unsigned char __force_user *)(instr), 1))
30745 + break;
30746 + } else if (probe_kernel_address(instr, opcode))
30747 break;
30748
30749 instr++;
30750 @@ -185,6 +198,34 @@ force_sig_info_fault(int si_signo, int si_code, unsigned long address,
30751 force_sig_info(si_signo, &info, tsk);
30752 }
30753
30754 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30755 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address);
30756 +#endif
30757 +
30758 +#ifdef CONFIG_PAX_EMUTRAMP
30759 +static int pax_handle_fetch_fault(struct pt_regs *regs);
30760 +#endif
30761 +
30762 +#ifdef CONFIG_PAX_PAGEEXEC
30763 +static inline pmd_t * pax_get_pmd(struct mm_struct *mm, unsigned long address)
30764 +{
30765 + pgd_t *pgd;
30766 + pud_t *pud;
30767 + pmd_t *pmd;
30768 +
30769 + pgd = pgd_offset(mm, address);
30770 + if (!pgd_present(*pgd))
30771 + return NULL;
30772 + pud = pud_offset(pgd, address);
30773 + if (!pud_present(*pud))
30774 + return NULL;
30775 + pmd = pmd_offset(pud, address);
30776 + if (!pmd_present(*pmd))
30777 + return NULL;
30778 + return pmd;
30779 +}
30780 +#endif
30781 +
30782 DEFINE_SPINLOCK(pgd_lock);
30783 LIST_HEAD(pgd_list);
30784
30785 @@ -235,10 +276,27 @@ void vmalloc_sync_all(void)
30786 for (address = VMALLOC_START & PMD_MASK;
30787 address >= TASK_SIZE && address < FIXADDR_TOP;
30788 address += PMD_SIZE) {
30789 +
30790 +#ifdef CONFIG_PAX_PER_CPU_PGD
30791 + unsigned long cpu;
30792 +#else
30793 struct page *page;
30794 +#endif
30795
30796 spin_lock(&pgd_lock);
30797 +
30798 +#ifdef CONFIG_PAX_PER_CPU_PGD
30799 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
30800 + pgd_t *pgd = get_cpu_pgd(cpu, user);
30801 + pmd_t *ret;
30802 +
30803 + ret = vmalloc_sync_one(pgd, address);
30804 + if (!ret)
30805 + break;
30806 + pgd = get_cpu_pgd(cpu, kernel);
30807 +#else
30808 list_for_each_entry(page, &pgd_list, lru) {
30809 + pgd_t *pgd;
30810 spinlock_t *pgt_lock;
30811 pmd_t *ret;
30812
30813 @@ -246,8 +304,14 @@ void vmalloc_sync_all(void)
30814 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
30815
30816 spin_lock(pgt_lock);
30817 - ret = vmalloc_sync_one(page_address(page), address);
30818 + pgd = page_address(page);
30819 +#endif
30820 +
30821 + ret = vmalloc_sync_one(pgd, address);
30822 +
30823 +#ifndef CONFIG_PAX_PER_CPU_PGD
30824 spin_unlock(pgt_lock);
30825 +#endif
30826
30827 if (!ret)
30828 break;
30829 @@ -281,6 +345,12 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30830 * an interrupt in the middle of a task switch..
30831 */
30832 pgd_paddr = read_cr3();
30833 +
30834 +#ifdef CONFIG_PAX_PER_CPU_PGD
30835 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (pgd_paddr & __PHYSICAL_MASK));
30836 + vmalloc_sync_one(__va(pgd_paddr + PAGE_SIZE), address);
30837 +#endif
30838 +
30839 pmd_k = vmalloc_sync_one(__va(pgd_paddr), address);
30840 if (!pmd_k)
30841 return -1;
30842 @@ -376,11 +446,25 @@ static noinline __kprobes int vmalloc_fault(unsigned long address)
30843 * happen within a race in page table update. In the later
30844 * case just flush:
30845 */
30846 - pgd = pgd_offset(current->active_mm, address);
30847 +
30848 pgd_ref = pgd_offset_k(address);
30849 if (pgd_none(*pgd_ref))
30850 return -1;
30851
30852 +#ifdef CONFIG_PAX_PER_CPU_PGD
30853 + BUG_ON(__pa(get_cpu_pgd(smp_processor_id(), kernel)) != (read_cr3() & __PHYSICAL_MASK));
30854 + pgd = pgd_offset_cpu(smp_processor_id(), user, address);
30855 + if (pgd_none(*pgd)) {
30856 + set_pgd(pgd, *pgd_ref);
30857 + arch_flush_lazy_mmu_mode();
30858 + } else {
30859 + BUG_ON(pgd_page_vaddr(*pgd) != pgd_page_vaddr(*pgd_ref));
30860 + }
30861 + pgd = pgd_offset_cpu(smp_processor_id(), kernel, address);
30862 +#else
30863 + pgd = pgd_offset(current->active_mm, address);
30864 +#endif
30865 +
30866 if (pgd_none(*pgd)) {
30867 set_pgd(pgd, *pgd_ref);
30868 arch_flush_lazy_mmu_mode();
30869 @@ -546,7 +630,7 @@ static int is_errata93(struct pt_regs *regs, unsigned long address)
30870 static int is_errata100(struct pt_regs *regs, unsigned long address)
30871 {
30872 #ifdef CONFIG_X86_64
30873 - if ((regs->cs == __USER32_CS || (regs->cs & (1<<2))) && (address >> 32))
30874 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)) && (address >> 32))
30875 return 1;
30876 #endif
30877 return 0;
30878 @@ -573,7 +657,7 @@ static int is_f00f_bug(struct pt_regs *regs, unsigned long address)
30879 }
30880
30881 static const char nx_warning[] = KERN_CRIT
30882 -"kernel tried to execute NX-protected page - exploit attempt? (uid: %d)\n";
30883 +"kernel tried to execute NX-protected page - exploit attempt? (uid: %d, task: %s, pid: %d)\n";
30884
30885 static void
30886 show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30887 @@ -582,15 +666,27 @@ show_fault_oops(struct pt_regs *regs, unsigned long error_code,
30888 if (!oops_may_print())
30889 return;
30890
30891 - if (error_code & PF_INSTR) {
30892 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR)) {
30893 unsigned int level;
30894
30895 pte_t *pte = lookup_address(address, &level);
30896
30897 if (pte && pte_present(*pte) && !pte_exec(*pte))
30898 - printk(nx_warning, from_kuid(&init_user_ns, current_uid()));
30899 + printk(nx_warning, from_kuid_munged(&init_user_ns, current_uid()), current->comm, task_pid_nr(current));
30900 }
30901
30902 +#ifdef CONFIG_PAX_KERNEXEC
30903 + if (init_mm.start_code <= address && address < init_mm.end_code) {
30904 + if (current->signal->curr_ip)
30905 + printk(KERN_ERR "PAX: From %pI4: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n",
30906 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
30907 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30908 + else
30909 + printk(KERN_ERR "PAX: %s:%d, uid/euid: %u/%u, attempted to modify kernel code\n", current->comm, task_pid_nr(current),
30910 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
30911 + }
30912 +#endif
30913 +
30914 printk(KERN_ALERT "BUG: unable to handle kernel ");
30915 if (address < PAGE_SIZE)
30916 printk(KERN_CONT "NULL pointer dereference");
30917 @@ -771,6 +867,22 @@ __bad_area_nosemaphore(struct pt_regs *regs, unsigned long error_code,
30918 return;
30919 }
30920 #endif
30921 +
30922 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
30923 + if (pax_is_fetch_fault(regs, error_code, address)) {
30924 +
30925 +#ifdef CONFIG_PAX_EMUTRAMP
30926 + switch (pax_handle_fetch_fault(regs)) {
30927 + case 2:
30928 + return;
30929 + }
30930 +#endif
30931 +
30932 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30933 + do_group_exit(SIGKILL);
30934 + }
30935 +#endif
30936 +
30937 /* Kernel addresses are always protection faults: */
30938 if (address >= TASK_SIZE)
30939 error_code |= PF_PROT;
30940 @@ -856,7 +968,7 @@ do_sigbus(struct pt_regs *regs, unsigned long error_code, unsigned long address,
30941 if (fault & (VM_FAULT_HWPOISON|VM_FAULT_HWPOISON_LARGE)) {
30942 printk(KERN_ERR
30943 "MCE: Killing %s:%d due to hardware memory corruption fault at %lx\n",
30944 - tsk->comm, tsk->pid, address);
30945 + tsk->comm, task_pid_nr(tsk), address);
30946 code = BUS_MCEERR_AR;
30947 }
30948 #endif
30949 @@ -910,6 +1022,99 @@ static int spurious_fault_check(unsigned long error_code, pte_t *pte)
30950 return 1;
30951 }
30952
30953 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
30954 +static int pax_handle_pageexec_fault(struct pt_regs *regs, struct mm_struct *mm, unsigned long address, unsigned long error_code)
30955 +{
30956 + pte_t *pte;
30957 + pmd_t *pmd;
30958 + spinlock_t *ptl;
30959 + unsigned char pte_mask;
30960 +
30961 + if ((__supported_pte_mask & _PAGE_NX) || (error_code & (PF_PROT|PF_USER)) != (PF_PROT|PF_USER) || v8086_mode(regs) ||
30962 + !(mm->pax_flags & MF_PAX_PAGEEXEC))
30963 + return 0;
30964 +
30965 + /* PaX: it's our fault, let's handle it if we can */
30966 +
30967 + /* PaX: take a look at read faults before acquiring any locks */
30968 + if (unlikely(!(error_code & PF_WRITE) && (regs->ip == address))) {
30969 + /* instruction fetch attempt from a protected page in user mode */
30970 + up_read(&mm->mmap_sem);
30971 +
30972 +#ifdef CONFIG_PAX_EMUTRAMP
30973 + switch (pax_handle_fetch_fault(regs)) {
30974 + case 2:
30975 + return 1;
30976 + }
30977 +#endif
30978 +
30979 + pax_report_fault(regs, (void *)regs->ip, (void *)regs->sp);
30980 + do_group_exit(SIGKILL);
30981 + }
30982 +
30983 + pmd = pax_get_pmd(mm, address);
30984 + if (unlikely(!pmd))
30985 + return 0;
30986 +
30987 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
30988 + if (unlikely(!(pte_val(*pte) & _PAGE_PRESENT) || pte_user(*pte))) {
30989 + pte_unmap_unlock(pte, ptl);
30990 + return 0;
30991 + }
30992 +
30993 + if (unlikely((error_code & PF_WRITE) && !pte_write(*pte))) {
30994 + /* write attempt to a protected page in user mode */
30995 + pte_unmap_unlock(pte, ptl);
30996 + return 0;
30997 + }
30998 +
30999 +#ifdef CONFIG_SMP
31000 + if (likely(address > get_limit(regs->cs) && cpu_isset(smp_processor_id(), mm->context.cpu_user_cs_mask)))
31001 +#else
31002 + if (likely(address > get_limit(regs->cs)))
31003 +#endif
31004 + {
31005 + set_pte(pte, pte_mkread(*pte));
31006 + __flush_tlb_one(address);
31007 + pte_unmap_unlock(pte, ptl);
31008 + up_read(&mm->mmap_sem);
31009 + return 1;
31010 + }
31011 +
31012 + pte_mask = _PAGE_ACCESSED | _PAGE_USER | ((error_code & PF_WRITE) << (_PAGE_BIT_DIRTY-1));
31013 +
31014 + /*
31015 + * PaX: fill DTLB with user rights and retry
31016 + */
31017 + __asm__ __volatile__ (
31018 + "orb %2,(%1)\n"
31019 +#if defined(CONFIG_M586) || defined(CONFIG_M586TSC)
31020 +/*
31021 + * PaX: let this uncommented 'invlpg' remind us on the behaviour of Intel's
31022 + * (and AMD's) TLBs. namely, they do not cache PTEs that would raise *any*
31023 + * page fault when examined during a TLB load attempt. this is true not only
31024 + * for PTEs holding a non-present entry but also present entries that will
31025 + * raise a page fault (such as those set up by PaX, or the copy-on-write
31026 + * mechanism). in effect it means that we do *not* need to flush the TLBs
31027 + * for our target pages since their PTEs are simply not in the TLBs at all.
31028 +
31029 + * the best thing in omitting it is that we gain around 15-20% speed in the
31030 + * fast path of the page fault handler and can get rid of tracing since we
31031 + * can no longer flush unintended entries.
31032 + */
31033 + "invlpg (%0)\n"
31034 +#endif
31035 + __copyuser_seg"testb $0,(%0)\n"
31036 + "xorb %3,(%1)\n"
31037 + :
31038 + : "r" (address), "r" (pte), "q" (pte_mask), "i" (_PAGE_USER)
31039 + : "memory", "cc");
31040 + pte_unmap_unlock(pte, ptl);
31041 + up_read(&mm->mmap_sem);
31042 + return 1;
31043 +}
31044 +#endif
31045 +
31046 /*
31047 * Handle a spurious fault caused by a stale TLB entry.
31048 *
31049 @@ -976,6 +1181,9 @@ int show_unhandled_signals = 1;
31050 static inline int
31051 access_error(unsigned long error_code, struct vm_area_struct *vma)
31052 {
31053 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR) && !(vma->vm_flags & VM_EXEC))
31054 + return 1;
31055 +
31056 if (error_code & PF_WRITE) {
31057 /* write, present and write, not present: */
31058 if (unlikely(!(vma->vm_flags & VM_WRITE)))
31059 @@ -1004,7 +1212,7 @@ static inline bool smap_violation(int error_code, struct pt_regs *regs)
31060 if (error_code & PF_USER)
31061 return false;
31062
31063 - if (!user_mode_vm(regs) && (regs->flags & X86_EFLAGS_AC))
31064 + if (!user_mode(regs) && (regs->flags & X86_EFLAGS_AC))
31065 return false;
31066
31067 return true;
31068 @@ -1031,6 +1239,22 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
31069 /* Get the faulting address: */
31070 address = read_cr2();
31071
31072 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
31073 + if (!user_mode(regs) && address < 2 * pax_user_shadow_base) {
31074 + if (!search_exception_tables(regs->ip)) {
31075 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31076 + bad_area_nosemaphore(regs, error_code, address);
31077 + return;
31078 + }
31079 + if (address < pax_user_shadow_base) {
31080 + printk(KERN_ERR "PAX: please report this to pageexec@freemail.hu\n");
31081 + printk(KERN_ERR "PAX: faulting IP: %pS\n", (void *)regs->ip);
31082 + show_trace_log_lvl(NULL, NULL, (void *)regs->sp, regs->bp, KERN_ERR);
31083 + } else
31084 + address -= pax_user_shadow_base;
31085 + }
31086 +#endif
31087 +
31088 /*
31089 * Detect and handle instructions that would cause a page fault for
31090 * both a tracked kernel page and a userspace page.
31091 @@ -1110,7 +1334,7 @@ __do_page_fault(struct pt_regs *regs, unsigned long error_code)
31092 * User-mode registers count as a user access even for any
31093 * potential system fault or CPU buglet:
31094 */
31095 - if (user_mode_vm(regs)) {
31096 + if (user_mode(regs)) {
31097 local_irq_enable();
31098 error_code |= PF_USER;
31099 flags |= FAULT_FLAG_USER;
31100 @@ -1157,6 +1381,11 @@ retry:
31101 might_sleep();
31102 }
31103
31104 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_PAGEEXEC)
31105 + if (pax_handle_pageexec_fault(regs, mm, address, error_code))
31106 + return;
31107 +#endif
31108 +
31109 vma = find_vma(mm, address);
31110 if (unlikely(!vma)) {
31111 bad_area(regs, error_code, address);
31112 @@ -1168,18 +1397,24 @@ retry:
31113 bad_area(regs, error_code, address);
31114 return;
31115 }
31116 - if (error_code & PF_USER) {
31117 - /*
31118 - * Accessing the stack below %sp is always a bug.
31119 - * The large cushion allows instructions like enter
31120 - * and pusha to work. ("enter $65535, $31" pushes
31121 - * 32 pointers and then decrements %sp by 65535.)
31122 - */
31123 - if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < regs->sp)) {
31124 - bad_area(regs, error_code, address);
31125 - return;
31126 - }
31127 + /*
31128 + * Accessing the stack below %sp is always a bug.
31129 + * The large cushion allows instructions like enter
31130 + * and pusha to work. ("enter $65535, $31" pushes
31131 + * 32 pointers and then decrements %sp by 65535.)
31132 + */
31133 + if (unlikely(address + 65536 + 32 * sizeof(unsigned long) < task_pt_regs(tsk)->sp)) {
31134 + bad_area(regs, error_code, address);
31135 + return;
31136 }
31137 +
31138 +#ifdef CONFIG_PAX_SEGMEXEC
31139 + if (unlikely((mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end - SEGMEXEC_TASK_SIZE - 1 < address - SEGMEXEC_TASK_SIZE - 1)) {
31140 + bad_area(regs, error_code, address);
31141 + return;
31142 + }
31143 +#endif
31144 +
31145 if (unlikely(expand_stack(vma, address))) {
31146 bad_area(regs, error_code, address);
31147 return;
31148 @@ -1273,3 +1508,292 @@ trace_do_page_fault(struct pt_regs *regs, unsigned long error_code)
31149 __do_page_fault(regs, error_code);
31150 exception_exit(prev_state);
31151 }
31152 +
31153 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31154 +static bool pax_is_fetch_fault(struct pt_regs *regs, unsigned long error_code, unsigned long address)
31155 +{
31156 + struct mm_struct *mm = current->mm;
31157 + unsigned long ip = regs->ip;
31158 +
31159 + if (v8086_mode(regs))
31160 + ip = ((regs->cs & 0xffff) << 4) + (ip & 0xffff);
31161 +
31162 +#ifdef CONFIG_PAX_PAGEEXEC
31163 + if (mm->pax_flags & MF_PAX_PAGEEXEC) {
31164 + if ((__supported_pte_mask & _PAGE_NX) && (error_code & PF_INSTR))
31165 + return true;
31166 + if (!(error_code & (PF_PROT | PF_WRITE)) && ip == address)
31167 + return true;
31168 + return false;
31169 + }
31170 +#endif
31171 +
31172 +#ifdef CONFIG_PAX_SEGMEXEC
31173 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
31174 + if (!(error_code & (PF_PROT | PF_WRITE)) && (ip + SEGMEXEC_TASK_SIZE == address))
31175 + return true;
31176 + return false;
31177 + }
31178 +#endif
31179 +
31180 + return false;
31181 +}
31182 +#endif
31183 +
31184 +#ifdef CONFIG_PAX_EMUTRAMP
31185 +static int pax_handle_fetch_fault_32(struct pt_regs *regs)
31186 +{
31187 + int err;
31188 +
31189 + do { /* PaX: libffi trampoline emulation */
31190 + unsigned char mov, jmp;
31191 + unsigned int addr1, addr2;
31192 +
31193 +#ifdef CONFIG_X86_64
31194 + if ((regs->ip + 9) >> 32)
31195 + break;
31196 +#endif
31197 +
31198 + err = get_user(mov, (unsigned char __user *)regs->ip);
31199 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31200 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31201 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31202 +
31203 + if (err)
31204 + break;
31205 +
31206 + if (mov == 0xB8 && jmp == 0xE9) {
31207 + regs->ax = addr1;
31208 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31209 + return 2;
31210 + }
31211 + } while (0);
31212 +
31213 + do { /* PaX: gcc trampoline emulation #1 */
31214 + unsigned char mov1, mov2;
31215 + unsigned short jmp;
31216 + unsigned int addr1, addr2;
31217 +
31218 +#ifdef CONFIG_X86_64
31219 + if ((regs->ip + 11) >> 32)
31220 + break;
31221 +#endif
31222 +
31223 + err = get_user(mov1, (unsigned char __user *)regs->ip);
31224 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31225 + err |= get_user(mov2, (unsigned char __user *)(regs->ip + 5));
31226 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31227 + err |= get_user(jmp, (unsigned short __user *)(regs->ip + 10));
31228 +
31229 + if (err)
31230 + break;
31231 +
31232 + if (mov1 == 0xB9 && mov2 == 0xB8 && jmp == 0xE0FF) {
31233 + regs->cx = addr1;
31234 + regs->ax = addr2;
31235 + regs->ip = addr2;
31236 + return 2;
31237 + }
31238 + } while (0);
31239 +
31240 + do { /* PaX: gcc trampoline emulation #2 */
31241 + unsigned char mov, jmp;
31242 + unsigned int addr1, addr2;
31243 +
31244 +#ifdef CONFIG_X86_64
31245 + if ((regs->ip + 9) >> 32)
31246 + break;
31247 +#endif
31248 +
31249 + err = get_user(mov, (unsigned char __user *)regs->ip);
31250 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 1));
31251 + err |= get_user(jmp, (unsigned char __user *)(regs->ip + 5));
31252 + err |= get_user(addr2, (unsigned int __user *)(regs->ip + 6));
31253 +
31254 + if (err)
31255 + break;
31256 +
31257 + if (mov == 0xB9 && jmp == 0xE9) {
31258 + regs->cx = addr1;
31259 + regs->ip = (unsigned int)(regs->ip + addr2 + 10);
31260 + return 2;
31261 + }
31262 + } while (0);
31263 +
31264 + return 1; /* PaX in action */
31265 +}
31266 +
31267 +#ifdef CONFIG_X86_64
31268 +static int pax_handle_fetch_fault_64(struct pt_regs *regs)
31269 +{
31270 + int err;
31271 +
31272 + do { /* PaX: libffi trampoline emulation */
31273 + unsigned short mov1, mov2, jmp1;
31274 + unsigned char stcclc, jmp2;
31275 + unsigned long addr1, addr2;
31276 +
31277 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31278 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31279 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31280 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31281 + err |= get_user(stcclc, (unsigned char __user *)(regs->ip + 20));
31282 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 21));
31283 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 23));
31284 +
31285 + if (err)
31286 + break;
31287 +
31288 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && (stcclc == 0xF8 || stcclc == 0xF9) && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31289 + regs->r11 = addr1;
31290 + regs->r10 = addr2;
31291 + if (stcclc == 0xF8)
31292 + regs->flags &= ~X86_EFLAGS_CF;
31293 + else
31294 + regs->flags |= X86_EFLAGS_CF;
31295 + regs->ip = addr1;
31296 + return 2;
31297 + }
31298 + } while (0);
31299 +
31300 + do { /* PaX: gcc trampoline emulation #1 */
31301 + unsigned short mov1, mov2, jmp1;
31302 + unsigned char jmp2;
31303 + unsigned int addr1;
31304 + unsigned long addr2;
31305 +
31306 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31307 + err |= get_user(addr1, (unsigned int __user *)(regs->ip + 2));
31308 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 6));
31309 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 8));
31310 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 16));
31311 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 18));
31312 +
31313 + if (err)
31314 + break;
31315 +
31316 + if (mov1 == 0xBB41 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31317 + regs->r11 = addr1;
31318 + regs->r10 = addr2;
31319 + regs->ip = addr1;
31320 + return 2;
31321 + }
31322 + } while (0);
31323 +
31324 + do { /* PaX: gcc trampoline emulation #2 */
31325 + unsigned short mov1, mov2, jmp1;
31326 + unsigned char jmp2;
31327 + unsigned long addr1, addr2;
31328 +
31329 + err = get_user(mov1, (unsigned short __user *)regs->ip);
31330 + err |= get_user(addr1, (unsigned long __user *)(regs->ip + 2));
31331 + err |= get_user(mov2, (unsigned short __user *)(regs->ip + 10));
31332 + err |= get_user(addr2, (unsigned long __user *)(regs->ip + 12));
31333 + err |= get_user(jmp1, (unsigned short __user *)(regs->ip + 20));
31334 + err |= get_user(jmp2, (unsigned char __user *)(regs->ip + 22));
31335 +
31336 + if (err)
31337 + break;
31338 +
31339 + if (mov1 == 0xBB49 && mov2 == 0xBA49 && jmp1 == 0xFF49 && jmp2 == 0xE3) {
31340 + regs->r11 = addr1;
31341 + regs->r10 = addr2;
31342 + regs->ip = addr1;
31343 + return 2;
31344 + }
31345 + } while (0);
31346 +
31347 + return 1; /* PaX in action */
31348 +}
31349 +#endif
31350 +
31351 +/*
31352 + * PaX: decide what to do with offenders (regs->ip = fault address)
31353 + *
31354 + * returns 1 when task should be killed
31355 + * 2 when gcc trampoline was detected
31356 + */
31357 +static int pax_handle_fetch_fault(struct pt_regs *regs)
31358 +{
31359 + if (v8086_mode(regs))
31360 + return 1;
31361 +
31362 + if (!(current->mm->pax_flags & MF_PAX_EMUTRAMP))
31363 + return 1;
31364 +
31365 +#ifdef CONFIG_X86_32
31366 + return pax_handle_fetch_fault_32(regs);
31367 +#else
31368 + if (regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))
31369 + return pax_handle_fetch_fault_32(regs);
31370 + else
31371 + return pax_handle_fetch_fault_64(regs);
31372 +#endif
31373 +}
31374 +#endif
31375 +
31376 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31377 +void pax_report_insns(struct pt_regs *regs, void *pc, void *sp)
31378 +{
31379 + long i;
31380 +
31381 + printk(KERN_ERR "PAX: bytes at PC: ");
31382 + for (i = 0; i < 20; i++) {
31383 + unsigned char c;
31384 + if (get_user(c, (unsigned char __force_user *)pc+i))
31385 + printk(KERN_CONT "?? ");
31386 + else
31387 + printk(KERN_CONT "%02x ", c);
31388 + }
31389 + printk("\n");
31390 +
31391 + printk(KERN_ERR "PAX: bytes at SP-%lu: ", (unsigned long)sizeof(long));
31392 + for (i = -1; i < 80 / (long)sizeof(long); i++) {
31393 + unsigned long c;
31394 + if (get_user(c, (unsigned long __force_user *)sp+i)) {
31395 +#ifdef CONFIG_X86_32
31396 + printk(KERN_CONT "???????? ");
31397 +#else
31398 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT)))
31399 + printk(KERN_CONT "???????? ???????? ");
31400 + else
31401 + printk(KERN_CONT "???????????????? ");
31402 +#endif
31403 + } else {
31404 +#ifdef CONFIG_X86_64
31405 + if ((regs->cs == __USER32_CS || (regs->cs & SEGMENT_LDT))) {
31406 + printk(KERN_CONT "%08x ", (unsigned int)c);
31407 + printk(KERN_CONT "%08x ", (unsigned int)(c >> 32));
31408 + } else
31409 +#endif
31410 + printk(KERN_CONT "%0*lx ", 2 * (int)sizeof(long), c);
31411 + }
31412 + }
31413 + printk("\n");
31414 +}
31415 +#endif
31416 +
31417 +/**
31418 + * probe_kernel_write(): safely attempt to write to a location
31419 + * @dst: address to write to
31420 + * @src: pointer to the data that shall be written
31421 + * @size: size of the data chunk
31422 + *
31423 + * Safely write to address @dst from the buffer at @src. If a kernel fault
31424 + * happens, handle that and return -EFAULT.
31425 + */
31426 +long notrace probe_kernel_write(void *dst, const void *src, size_t size)
31427 +{
31428 + long ret;
31429 + mm_segment_t old_fs = get_fs();
31430 +
31431 + set_fs(KERNEL_DS);
31432 + pagefault_disable();
31433 + pax_open_kernel();
31434 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
31435 + pax_close_kernel();
31436 + pagefault_enable();
31437 + set_fs(old_fs);
31438 +
31439 + return ret ? -EFAULT : 0;
31440 +}
31441 diff --git a/arch/x86/mm/gup.c b/arch/x86/mm/gup.c
31442 index 0596e8e..9de0b1c 100644
31443 --- a/arch/x86/mm/gup.c
31444 +++ b/arch/x86/mm/gup.c
31445 @@ -268,7 +268,7 @@ int __get_user_pages_fast(unsigned long start, int nr_pages, int write,
31446 addr = start;
31447 len = (unsigned long) nr_pages << PAGE_SHIFT;
31448 end = start + len;
31449 - if (unlikely(!access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31450 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31451 (void __user *)start, len)))
31452 return 0;
31453
31454 @@ -344,6 +344,10 @@ int get_user_pages_fast(unsigned long start, int nr_pages, int write,
31455 goto slow_irqon;
31456 #endif
31457
31458 + if (unlikely(!__access_ok(write ? VERIFY_WRITE : VERIFY_READ,
31459 + (void __user *)start, len)))
31460 + return 0;
31461 +
31462 /*
31463 * XXX: batch / limit 'nr', to avoid large irq off latency
31464 * needs some instrumenting to determine the common sizes used by
31465 diff --git a/arch/x86/mm/highmem_32.c b/arch/x86/mm/highmem_32.c
31466 index 4500142..53a363c 100644
31467 --- a/arch/x86/mm/highmem_32.c
31468 +++ b/arch/x86/mm/highmem_32.c
31469 @@ -45,7 +45,11 @@ void *kmap_atomic_prot(struct page *page, pgprot_t prot)
31470 idx = type + KM_TYPE_NR*smp_processor_id();
31471 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
31472 BUG_ON(!pte_none(*(kmap_pte-idx)));
31473 +
31474 + pax_open_kernel();
31475 set_pte(kmap_pte-idx, mk_pte(page, prot));
31476 + pax_close_kernel();
31477 +
31478 arch_flush_lazy_mmu_mode();
31479
31480 return (void *)vaddr;
31481 diff --git a/arch/x86/mm/hugetlbpage.c b/arch/x86/mm/hugetlbpage.c
31482 index 9d980d8..6bbfacb 100644
31483 --- a/arch/x86/mm/hugetlbpage.c
31484 +++ b/arch/x86/mm/hugetlbpage.c
31485 @@ -92,23 +92,30 @@ int pmd_huge_support(void)
31486 #ifdef HAVE_ARCH_HUGETLB_UNMAPPED_AREA
31487 static unsigned long hugetlb_get_unmapped_area_bottomup(struct file *file,
31488 unsigned long addr, unsigned long len,
31489 - unsigned long pgoff, unsigned long flags)
31490 + unsigned long pgoff, unsigned long flags, unsigned long offset)
31491 {
31492 struct hstate *h = hstate_file(file);
31493 struct vm_unmapped_area_info info;
31494 -
31495 +
31496 info.flags = 0;
31497 info.length = len;
31498 info.low_limit = TASK_UNMAPPED_BASE;
31499 +
31500 +#ifdef CONFIG_PAX_RANDMMAP
31501 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
31502 + info.low_limit += current->mm->delta_mmap;
31503 +#endif
31504 +
31505 info.high_limit = TASK_SIZE;
31506 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31507 info.align_offset = 0;
31508 + info.threadstack_offset = offset;
31509 return vm_unmapped_area(&info);
31510 }
31511
31512 static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31513 unsigned long addr0, unsigned long len,
31514 - unsigned long pgoff, unsigned long flags)
31515 + unsigned long pgoff, unsigned long flags, unsigned long offset)
31516 {
31517 struct hstate *h = hstate_file(file);
31518 struct vm_unmapped_area_info info;
31519 @@ -120,6 +127,7 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31520 info.high_limit = current->mm->mmap_base;
31521 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
31522 info.align_offset = 0;
31523 + info.threadstack_offset = offset;
31524 addr = vm_unmapped_area(&info);
31525
31526 /*
31527 @@ -132,6 +140,12 @@ static unsigned long hugetlb_get_unmapped_area_topdown(struct file *file,
31528 VM_BUG_ON(addr != -ENOMEM);
31529 info.flags = 0;
31530 info.low_limit = TASK_UNMAPPED_BASE;
31531 +
31532 +#ifdef CONFIG_PAX_RANDMMAP
31533 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
31534 + info.low_limit += current->mm->delta_mmap;
31535 +#endif
31536 +
31537 info.high_limit = TASK_SIZE;
31538 addr = vm_unmapped_area(&info);
31539 }
31540 @@ -146,10 +160,20 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
31541 struct hstate *h = hstate_file(file);
31542 struct mm_struct *mm = current->mm;
31543 struct vm_area_struct *vma;
31544 + unsigned long pax_task_size = TASK_SIZE;
31545 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
31546
31547 if (len & ~huge_page_mask(h))
31548 return -EINVAL;
31549 - if (len > TASK_SIZE)
31550 +
31551 +#ifdef CONFIG_PAX_SEGMEXEC
31552 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
31553 + pax_task_size = SEGMEXEC_TASK_SIZE;
31554 +#endif
31555 +
31556 + pax_task_size -= PAGE_SIZE;
31557 +
31558 + if (len > pax_task_size)
31559 return -ENOMEM;
31560
31561 if (flags & MAP_FIXED) {
31562 @@ -158,19 +182,22 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
31563 return addr;
31564 }
31565
31566 +#ifdef CONFIG_PAX_RANDMMAP
31567 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
31568 +#endif
31569 +
31570 if (addr) {
31571 addr = ALIGN(addr, huge_page_size(h));
31572 vma = find_vma(mm, addr);
31573 - if (TASK_SIZE - len >= addr &&
31574 - (!vma || addr + len <= vma->vm_start))
31575 + if (pax_task_size - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
31576 return addr;
31577 }
31578 if (mm->get_unmapped_area == arch_get_unmapped_area)
31579 return hugetlb_get_unmapped_area_bottomup(file, addr, len,
31580 - pgoff, flags);
31581 + pgoff, flags, offset);
31582 else
31583 return hugetlb_get_unmapped_area_topdown(file, addr, len,
31584 - pgoff, flags);
31585 + pgoff, flags, offset);
31586 }
31587
31588 #endif /*HAVE_ARCH_HUGETLB_UNMAPPED_AREA*/
31589 diff --git a/arch/x86/mm/init.c b/arch/x86/mm/init.c
31590 index f971306..e83e0f6 100644
31591 --- a/arch/x86/mm/init.c
31592 +++ b/arch/x86/mm/init.c
31593 @@ -4,6 +4,7 @@
31594 #include <linux/swap.h>
31595 #include <linux/memblock.h>
31596 #include <linux/bootmem.h> /* for max_low_pfn */
31597 +#include <linux/tboot.h>
31598
31599 #include <asm/cacheflush.h>
31600 #include <asm/e820.h>
31601 @@ -17,6 +18,8 @@
31602 #include <asm/proto.h>
31603 #include <asm/dma.h> /* for MAX_DMA_PFN */
31604 #include <asm/microcode.h>
31605 +#include <asm/desc.h>
31606 +#include <asm/bios_ebda.h>
31607
31608 #include "mm_internal.h"
31609
31610 @@ -563,7 +566,18 @@ void __init init_mem_mapping(void)
31611 early_ioremap_page_table_range_init();
31612 #endif
31613
31614 +#ifdef CONFIG_PAX_PER_CPU_PGD
31615 + clone_pgd_range(get_cpu_pgd(0, kernel) + KERNEL_PGD_BOUNDARY,
31616 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
31617 + KERNEL_PGD_PTRS);
31618 + clone_pgd_range(get_cpu_pgd(0, user) + KERNEL_PGD_BOUNDARY,
31619 + swapper_pg_dir + KERNEL_PGD_BOUNDARY,
31620 + KERNEL_PGD_PTRS);
31621 + load_cr3(get_cpu_pgd(0, kernel));
31622 +#else
31623 load_cr3(swapper_pg_dir);
31624 +#endif
31625 +
31626 __flush_tlb_all();
31627
31628 early_memtest(0, max_pfn_mapped << PAGE_SHIFT);
31629 @@ -579,10 +593,40 @@ void __init init_mem_mapping(void)
31630 * Access has to be given to non-kernel-ram areas as well, these contain the PCI
31631 * mmio resources as well as potential bios/acpi data regions.
31632 */
31633 +
31634 +#ifdef CONFIG_GRKERNSEC_KMEM
31635 +static unsigned int ebda_start __read_only;
31636 +static unsigned int ebda_end __read_only;
31637 +#endif
31638 +
31639 int devmem_is_allowed(unsigned long pagenr)
31640 {
31641 - if (pagenr < 256)
31642 +#ifdef CONFIG_GRKERNSEC_KMEM
31643 + /* allow BDA */
31644 + if (!pagenr)
31645 return 1;
31646 + /* allow EBDA */
31647 + if (pagenr >= ebda_start && pagenr < ebda_end)
31648 + return 1;
31649 + /* if tboot is in use, allow access to its hardcoded serial log range */
31650 + if (tboot_enabled() && ((0x60000 >> PAGE_SHIFT) <= pagenr) && (pagenr < (0x68000 >> PAGE_SHIFT)))
31651 + return 1;
31652 +#else
31653 + if (!pagenr)
31654 + return 1;
31655 +#ifdef CONFIG_VM86
31656 + if (pagenr < (ISA_START_ADDRESS >> PAGE_SHIFT))
31657 + return 1;
31658 +#endif
31659 +#endif
31660 +
31661 + if ((ISA_START_ADDRESS >> PAGE_SHIFT) <= pagenr && pagenr < (ISA_END_ADDRESS >> PAGE_SHIFT))
31662 + return 1;
31663 +#ifdef CONFIG_GRKERNSEC_KMEM
31664 + /* throw out everything else below 1MB */
31665 + if (pagenr <= 256)
31666 + return 0;
31667 +#endif
31668 if (iomem_is_exclusive(pagenr << PAGE_SHIFT))
31669 return 0;
31670 if (!page_is_ram(pagenr))
31671 @@ -628,8 +672,117 @@ void free_init_pages(char *what, unsigned long begin, unsigned long end)
31672 #endif
31673 }
31674
31675 +#ifdef CONFIG_GRKERNSEC_KMEM
31676 +static inline void gr_init_ebda(void)
31677 +{
31678 + unsigned int ebda_addr;
31679 + unsigned int ebda_size = 0;
31680 +
31681 + ebda_addr = get_bios_ebda();
31682 + if (ebda_addr) {
31683 + ebda_size = *(unsigned char *)phys_to_virt(ebda_addr);
31684 + ebda_size <<= 10;
31685 + }
31686 + if (ebda_addr && ebda_size) {
31687 + ebda_start = ebda_addr >> PAGE_SHIFT;
31688 + ebda_end = min((unsigned int)PAGE_ALIGN(ebda_addr + ebda_size), (unsigned int)0xa0000) >> PAGE_SHIFT;
31689 + } else {
31690 + ebda_start = 0x9f000 >> PAGE_SHIFT;
31691 + ebda_end = 0xa0000 >> PAGE_SHIFT;
31692 + }
31693 +}
31694 +#else
31695 +static inline void gr_init_ebda(void) { }
31696 +#endif
31697 +
31698 void free_initmem(void)
31699 {
31700 +#ifdef CONFIG_PAX_KERNEXEC
31701 +#ifdef CONFIG_X86_32
31702 + /* PaX: limit KERNEL_CS to actual size */
31703 + unsigned long addr, limit;
31704 + struct desc_struct d;
31705 + int cpu;
31706 +#else
31707 + pgd_t *pgd;
31708 + pud_t *pud;
31709 + pmd_t *pmd;
31710 + unsigned long addr, end;
31711 +#endif
31712 +#endif
31713 +
31714 + gr_init_ebda();
31715 +
31716 +#ifdef CONFIG_PAX_KERNEXEC
31717 +#ifdef CONFIG_X86_32
31718 + limit = paravirt_enabled() ? ktva_ktla(0xffffffff) : (unsigned long)&_etext;
31719 + limit = (limit - 1UL) >> PAGE_SHIFT;
31720 +
31721 + memset(__LOAD_PHYSICAL_ADDR + PAGE_OFFSET, POISON_FREE_INITMEM, PAGE_SIZE);
31722 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
31723 + pack_descriptor(&d, get_desc_base(&get_cpu_gdt_table(cpu)[GDT_ENTRY_KERNEL_CS]), limit, 0x9B, 0xC);
31724 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEL_CS, &d, DESCTYPE_S);
31725 + write_gdt_entry(get_cpu_gdt_table(cpu), GDT_ENTRY_KERNEXEC_KERNEL_CS, &d, DESCTYPE_S);
31726 + }
31727 +
31728 + /* PaX: make KERNEL_CS read-only */
31729 + addr = PFN_ALIGN(ktla_ktva((unsigned long)&_text));
31730 + if (!paravirt_enabled())
31731 + set_memory_ro(addr, (PFN_ALIGN(_sdata) - addr) >> PAGE_SHIFT);
31732 +/*
31733 + for (addr = ktla_ktva((unsigned long)&_text); addr < (unsigned long)&_sdata; addr += PMD_SIZE) {
31734 + pgd = pgd_offset_k(addr);
31735 + pud = pud_offset(pgd, addr);
31736 + pmd = pmd_offset(pud, addr);
31737 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31738 + }
31739 +*/
31740 +#ifdef CONFIG_X86_PAE
31741 + set_memory_nx(PFN_ALIGN(__init_begin), (PFN_ALIGN(__init_end) - PFN_ALIGN(__init_begin)) >> PAGE_SHIFT);
31742 +/*
31743 + for (addr = (unsigned long)&__init_begin; addr < (unsigned long)&__init_end; addr += PMD_SIZE) {
31744 + pgd = pgd_offset_k(addr);
31745 + pud = pud_offset(pgd, addr);
31746 + pmd = pmd_offset(pud, addr);
31747 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
31748 + }
31749 +*/
31750 +#endif
31751 +
31752 +#ifdef CONFIG_MODULES
31753 + set_memory_4k((unsigned long)MODULES_EXEC_VADDR, (MODULES_EXEC_END - MODULES_EXEC_VADDR) >> PAGE_SHIFT);
31754 +#endif
31755 +
31756 +#else
31757 + /* PaX: make kernel code/rodata read-only, rest non-executable */
31758 + for (addr = __START_KERNEL_map; addr < __START_KERNEL_map + KERNEL_IMAGE_SIZE; addr += PMD_SIZE) {
31759 + pgd = pgd_offset_k(addr);
31760 + pud = pud_offset(pgd, addr);
31761 + pmd = pmd_offset(pud, addr);
31762 + if (!pmd_present(*pmd))
31763 + continue;
31764 + if ((unsigned long)_text <= addr && addr < (unsigned long)_sdata)
31765 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31766 + else
31767 + set_pmd(pmd, __pmd(pmd_val(*pmd) | (_PAGE_NX & __supported_pte_mask)));
31768 + }
31769 +
31770 + addr = (unsigned long)__va(__pa(__START_KERNEL_map));
31771 + end = addr + KERNEL_IMAGE_SIZE;
31772 + for (; addr < end; addr += PMD_SIZE) {
31773 + pgd = pgd_offset_k(addr);
31774 + pud = pud_offset(pgd, addr);
31775 + pmd = pmd_offset(pud, addr);
31776 + if (!pmd_present(*pmd))
31777 + continue;
31778 + if ((unsigned long)__va(__pa(_text)) <= addr && addr < (unsigned long)__va(__pa(_sdata)))
31779 + set_pmd(pmd, __pmd(pmd_val(*pmd) & ~_PAGE_RW));
31780 + }
31781 +#endif
31782 +
31783 + flush_tlb_all();
31784 +#endif
31785 +
31786 free_init_pages("unused kernel",
31787 (unsigned long)(&__init_begin),
31788 (unsigned long)(&__init_end));
31789 diff --git a/arch/x86/mm/init_32.c b/arch/x86/mm/init_32.c
31790 index 4287f1f..3b99c71 100644
31791 --- a/arch/x86/mm/init_32.c
31792 +++ b/arch/x86/mm/init_32.c
31793 @@ -62,33 +62,6 @@ static noinline int do_test_wp_bit(void);
31794 bool __read_mostly __vmalloc_start_set = false;
31795
31796 /*
31797 - * Creates a middle page table and puts a pointer to it in the
31798 - * given global directory entry. This only returns the gd entry
31799 - * in non-PAE compilation mode, since the middle layer is folded.
31800 - */
31801 -static pmd_t * __init one_md_table_init(pgd_t *pgd)
31802 -{
31803 - pud_t *pud;
31804 - pmd_t *pmd_table;
31805 -
31806 -#ifdef CONFIG_X86_PAE
31807 - if (!(pgd_val(*pgd) & _PAGE_PRESENT)) {
31808 - pmd_table = (pmd_t *)alloc_low_page();
31809 - paravirt_alloc_pmd(&init_mm, __pa(pmd_table) >> PAGE_SHIFT);
31810 - set_pgd(pgd, __pgd(__pa(pmd_table) | _PAGE_PRESENT));
31811 - pud = pud_offset(pgd, 0);
31812 - BUG_ON(pmd_table != pmd_offset(pud, 0));
31813 -
31814 - return pmd_table;
31815 - }
31816 -#endif
31817 - pud = pud_offset(pgd, 0);
31818 - pmd_table = pmd_offset(pud, 0);
31819 -
31820 - return pmd_table;
31821 -}
31822 -
31823 -/*
31824 * Create a page table and place a pointer to it in a middle page
31825 * directory entry:
31826 */
31827 @@ -98,13 +71,28 @@ static pte_t * __init one_page_table_init(pmd_t *pmd)
31828 pte_t *page_table = (pte_t *)alloc_low_page();
31829
31830 paravirt_alloc_pte(&init_mm, __pa(page_table) >> PAGE_SHIFT);
31831 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
31832 + set_pmd(pmd, __pmd(__pa(page_table) | _KERNPG_TABLE));
31833 +#else
31834 set_pmd(pmd, __pmd(__pa(page_table) | _PAGE_TABLE));
31835 +#endif
31836 BUG_ON(page_table != pte_offset_kernel(pmd, 0));
31837 }
31838
31839 return pte_offset_kernel(pmd, 0);
31840 }
31841
31842 +static pmd_t * __init one_md_table_init(pgd_t *pgd)
31843 +{
31844 + pud_t *pud;
31845 + pmd_t *pmd_table;
31846 +
31847 + pud = pud_offset(pgd, 0);
31848 + pmd_table = pmd_offset(pud, 0);
31849 +
31850 + return pmd_table;
31851 +}
31852 +
31853 pmd_t * __init populate_extra_pmd(unsigned long vaddr)
31854 {
31855 int pgd_idx = pgd_index(vaddr);
31856 @@ -208,6 +196,7 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31857 int pgd_idx, pmd_idx;
31858 unsigned long vaddr;
31859 pgd_t *pgd;
31860 + pud_t *pud;
31861 pmd_t *pmd;
31862 pte_t *pte = NULL;
31863 unsigned long count = page_table_range_init_count(start, end);
31864 @@ -222,8 +211,13 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31865 pgd = pgd_base + pgd_idx;
31866
31867 for ( ; (pgd_idx < PTRS_PER_PGD) && (vaddr != end); pgd++, pgd_idx++) {
31868 - pmd = one_md_table_init(pgd);
31869 - pmd = pmd + pmd_index(vaddr);
31870 + pud = pud_offset(pgd, vaddr);
31871 + pmd = pmd_offset(pud, vaddr);
31872 +
31873 +#ifdef CONFIG_X86_PAE
31874 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31875 +#endif
31876 +
31877 for (; (pmd_idx < PTRS_PER_PMD) && (vaddr != end);
31878 pmd++, pmd_idx++) {
31879 pte = page_table_kmap_check(one_page_table_init(pmd),
31880 @@ -235,11 +229,20 @@ page_table_range_init(unsigned long start, unsigned long end, pgd_t *pgd_base)
31881 }
31882 }
31883
31884 -static inline int is_kernel_text(unsigned long addr)
31885 +static inline int is_kernel_text(unsigned long start, unsigned long end)
31886 {
31887 - if (addr >= (unsigned long)_text && addr <= (unsigned long)__init_end)
31888 - return 1;
31889 - return 0;
31890 + if ((start > ktla_ktva((unsigned long)_etext) ||
31891 + end <= ktla_ktva((unsigned long)_stext)) &&
31892 + (start > ktla_ktva((unsigned long)_einittext) ||
31893 + end <= ktla_ktva((unsigned long)_sinittext)) &&
31894 +
31895 +#ifdef CONFIG_ACPI_SLEEP
31896 + (start > (unsigned long)__va(acpi_wakeup_address) + 0x4000 || end <= (unsigned long)__va(acpi_wakeup_address)) &&
31897 +#endif
31898 +
31899 + (start > (unsigned long)__va(0xfffff) || end <= (unsigned long)__va(0xc0000)))
31900 + return 0;
31901 + return 1;
31902 }
31903
31904 /*
31905 @@ -256,9 +259,10 @@ kernel_physical_mapping_init(unsigned long start,
31906 unsigned long last_map_addr = end;
31907 unsigned long start_pfn, end_pfn;
31908 pgd_t *pgd_base = swapper_pg_dir;
31909 - int pgd_idx, pmd_idx, pte_ofs;
31910 + unsigned int pgd_idx, pmd_idx, pte_ofs;
31911 unsigned long pfn;
31912 pgd_t *pgd;
31913 + pud_t *pud;
31914 pmd_t *pmd;
31915 pte_t *pte;
31916 unsigned pages_2m, pages_4k;
31917 @@ -291,8 +295,13 @@ repeat:
31918 pfn = start_pfn;
31919 pgd_idx = pgd_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31920 pgd = pgd_base + pgd_idx;
31921 - for (; pgd_idx < PTRS_PER_PGD; pgd++, pgd_idx++) {
31922 - pmd = one_md_table_init(pgd);
31923 + for (; pgd_idx < PTRS_PER_PGD && pfn < max_low_pfn; pgd++, pgd_idx++) {
31924 + pud = pud_offset(pgd, 0);
31925 + pmd = pmd_offset(pud, 0);
31926 +
31927 +#ifdef CONFIG_X86_PAE
31928 + paravirt_alloc_pmd(&init_mm, __pa(pmd) >> PAGE_SHIFT);
31929 +#endif
31930
31931 if (pfn >= end_pfn)
31932 continue;
31933 @@ -304,14 +313,13 @@ repeat:
31934 #endif
31935 for (; pmd_idx < PTRS_PER_PMD && pfn < end_pfn;
31936 pmd++, pmd_idx++) {
31937 - unsigned int addr = pfn * PAGE_SIZE + PAGE_OFFSET;
31938 + unsigned long address = pfn * PAGE_SIZE + PAGE_OFFSET;
31939
31940 /*
31941 * Map with big pages if possible, otherwise
31942 * create normal page tables:
31943 */
31944 if (use_pse) {
31945 - unsigned int addr2;
31946 pgprot_t prot = PAGE_KERNEL_LARGE;
31947 /*
31948 * first pass will use the same initial
31949 @@ -322,11 +330,7 @@ repeat:
31950 _PAGE_PSE);
31951
31952 pfn &= PMD_MASK >> PAGE_SHIFT;
31953 - addr2 = (pfn + PTRS_PER_PTE-1) * PAGE_SIZE +
31954 - PAGE_OFFSET + PAGE_SIZE-1;
31955 -
31956 - if (is_kernel_text(addr) ||
31957 - is_kernel_text(addr2))
31958 + if (is_kernel_text(address, address + PMD_SIZE))
31959 prot = PAGE_KERNEL_LARGE_EXEC;
31960
31961 pages_2m++;
31962 @@ -343,7 +347,7 @@ repeat:
31963 pte_ofs = pte_index((pfn<<PAGE_SHIFT) + PAGE_OFFSET);
31964 pte += pte_ofs;
31965 for (; pte_ofs < PTRS_PER_PTE && pfn < end_pfn;
31966 - pte++, pfn++, pte_ofs++, addr += PAGE_SIZE) {
31967 + pte++, pfn++, pte_ofs++, address += PAGE_SIZE) {
31968 pgprot_t prot = PAGE_KERNEL;
31969 /*
31970 * first pass will use the same initial
31971 @@ -351,7 +355,7 @@ repeat:
31972 */
31973 pgprot_t init_prot = __pgprot(PTE_IDENT_ATTR);
31974
31975 - if (is_kernel_text(addr))
31976 + if (is_kernel_text(address, address + PAGE_SIZE))
31977 prot = PAGE_KERNEL_EXEC;
31978
31979 pages_4k++;
31980 @@ -474,7 +478,7 @@ void __init native_pagetable_init(void)
31981
31982 pud = pud_offset(pgd, va);
31983 pmd = pmd_offset(pud, va);
31984 - if (!pmd_present(*pmd))
31985 + if (!pmd_present(*pmd)) // PAX TODO || pmd_large(*pmd))
31986 break;
31987
31988 /* should not be large page here */
31989 @@ -532,12 +536,10 @@ void __init early_ioremap_page_table_range_init(void)
31990
31991 static void __init pagetable_init(void)
31992 {
31993 - pgd_t *pgd_base = swapper_pg_dir;
31994 -
31995 - permanent_kmaps_init(pgd_base);
31996 + permanent_kmaps_init(swapper_pg_dir);
31997 }
31998
31999 -pteval_t __supported_pte_mask __read_mostly = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32000 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_GLOBAL | _PAGE_IOMAP);
32001 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32002
32003 /* user-defined highmem size */
32004 @@ -787,10 +789,10 @@ void __init mem_init(void)
32005 ((unsigned long)&__init_end -
32006 (unsigned long)&__init_begin) >> 10,
32007
32008 - (unsigned long)&_etext, (unsigned long)&_edata,
32009 - ((unsigned long)&_edata - (unsigned long)&_etext) >> 10,
32010 + (unsigned long)&_sdata, (unsigned long)&_edata,
32011 + ((unsigned long)&_edata - (unsigned long)&_sdata) >> 10,
32012
32013 - (unsigned long)&_text, (unsigned long)&_etext,
32014 + ktla_ktva((unsigned long)&_text), ktla_ktva((unsigned long)&_etext),
32015 ((unsigned long)&_etext - (unsigned long)&_text) >> 10);
32016
32017 /*
32018 @@ -880,6 +882,7 @@ void set_kernel_text_rw(void)
32019 if (!kernel_set_to_readonly)
32020 return;
32021
32022 + start = ktla_ktva(start);
32023 pr_debug("Set kernel text: %lx - %lx for read write\n",
32024 start, start+size);
32025
32026 @@ -894,6 +897,7 @@ void set_kernel_text_ro(void)
32027 if (!kernel_set_to_readonly)
32028 return;
32029
32030 + start = ktla_ktva(start);
32031 pr_debug("Set kernel text: %lx - %lx for read only\n",
32032 start, start+size);
32033
32034 @@ -922,6 +926,7 @@ void mark_rodata_ro(void)
32035 unsigned long start = PFN_ALIGN(_text);
32036 unsigned long size = PFN_ALIGN(_etext) - start;
32037
32038 + start = ktla_ktva(start);
32039 set_pages_ro(virt_to_page(start), size >> PAGE_SHIFT);
32040 printk(KERN_INFO "Write protecting the kernel text: %luk\n",
32041 size >> 10);
32042 diff --git a/arch/x86/mm/init_64.c b/arch/x86/mm/init_64.c
32043 index 104d56a..62ba13f1 100644
32044 --- a/arch/x86/mm/init_64.c
32045 +++ b/arch/x86/mm/init_64.c
32046 @@ -151,7 +151,7 @@ early_param("gbpages", parse_direct_gbpages_on);
32047 * around without checking the pgd every time.
32048 */
32049
32050 -pteval_t __supported_pte_mask __read_mostly = ~_PAGE_IOMAP;
32051 +pteval_t __supported_pte_mask __read_only = ~(_PAGE_NX | _PAGE_IOMAP);
32052 EXPORT_SYMBOL_GPL(__supported_pte_mask);
32053
32054 int force_personality32;
32055 @@ -184,12 +184,29 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32056
32057 for (address = start; address <= end; address += PGDIR_SIZE) {
32058 const pgd_t *pgd_ref = pgd_offset_k(address);
32059 +
32060 +#ifdef CONFIG_PAX_PER_CPU_PGD
32061 + unsigned long cpu;
32062 +#else
32063 struct page *page;
32064 +#endif
32065
32066 if (pgd_none(*pgd_ref))
32067 continue;
32068
32069 spin_lock(&pgd_lock);
32070 +
32071 +#ifdef CONFIG_PAX_PER_CPU_PGD
32072 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32073 + pgd_t *pgd = pgd_offset_cpu(cpu, user, address);
32074 +
32075 + if (pgd_none(*pgd))
32076 + set_pgd(pgd, *pgd_ref);
32077 + else
32078 + BUG_ON(pgd_page_vaddr(*pgd)
32079 + != pgd_page_vaddr(*pgd_ref));
32080 + pgd = pgd_offset_cpu(cpu, kernel, address);
32081 +#else
32082 list_for_each_entry(page, &pgd_list, lru) {
32083 pgd_t *pgd;
32084 spinlock_t *pgt_lock;
32085 @@ -198,6 +215,7 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32086 /* the pgt_lock only for Xen */
32087 pgt_lock = &pgd_page_get_mm(page)->page_table_lock;
32088 spin_lock(pgt_lock);
32089 +#endif
32090
32091 if (pgd_none(*pgd))
32092 set_pgd(pgd, *pgd_ref);
32093 @@ -205,7 +223,10 @@ void sync_global_pgds(unsigned long start, unsigned long end)
32094 BUG_ON(pgd_page_vaddr(*pgd)
32095 != pgd_page_vaddr(*pgd_ref));
32096
32097 +#ifndef CONFIG_PAX_PER_CPU_PGD
32098 spin_unlock(pgt_lock);
32099 +#endif
32100 +
32101 }
32102 spin_unlock(&pgd_lock);
32103 }
32104 @@ -238,7 +259,7 @@ static pud_t *fill_pud(pgd_t *pgd, unsigned long vaddr)
32105 {
32106 if (pgd_none(*pgd)) {
32107 pud_t *pud = (pud_t *)spp_getpage();
32108 - pgd_populate(&init_mm, pgd, pud);
32109 + pgd_populate_kernel(&init_mm, pgd, pud);
32110 if (pud != pud_offset(pgd, 0))
32111 printk(KERN_ERR "PAGETABLE BUG #00! %p <-> %p\n",
32112 pud, pud_offset(pgd, 0));
32113 @@ -250,7 +271,7 @@ static pmd_t *fill_pmd(pud_t *pud, unsigned long vaddr)
32114 {
32115 if (pud_none(*pud)) {
32116 pmd_t *pmd = (pmd_t *) spp_getpage();
32117 - pud_populate(&init_mm, pud, pmd);
32118 + pud_populate_kernel(&init_mm, pud, pmd);
32119 if (pmd != pmd_offset(pud, 0))
32120 printk(KERN_ERR "PAGETABLE BUG #01! %p <-> %p\n",
32121 pmd, pmd_offset(pud, 0));
32122 @@ -279,7 +300,9 @@ void set_pte_vaddr_pud(pud_t *pud_page, unsigned long vaddr, pte_t new_pte)
32123 pmd = fill_pmd(pud, vaddr);
32124 pte = fill_pte(pmd, vaddr);
32125
32126 + pax_open_kernel();
32127 set_pte(pte, new_pte);
32128 + pax_close_kernel();
32129
32130 /*
32131 * It's enough to flush this one mapping.
32132 @@ -338,14 +361,12 @@ static void __init __init_extra_mapping(unsigned long phys, unsigned long size,
32133 pgd = pgd_offset_k((unsigned long)__va(phys));
32134 if (pgd_none(*pgd)) {
32135 pud = (pud_t *) spp_getpage();
32136 - set_pgd(pgd, __pgd(__pa(pud) | _KERNPG_TABLE |
32137 - _PAGE_USER));
32138 + set_pgd(pgd, __pgd(__pa(pud) | _PAGE_TABLE));
32139 }
32140 pud = pud_offset(pgd, (unsigned long)__va(phys));
32141 if (pud_none(*pud)) {
32142 pmd = (pmd_t *) spp_getpage();
32143 - set_pud(pud, __pud(__pa(pmd) | _KERNPG_TABLE |
32144 - _PAGE_USER));
32145 + set_pud(pud, __pud(__pa(pmd) | _PAGE_TABLE));
32146 }
32147 pmd = pmd_offset(pud, phys);
32148 BUG_ON(!pmd_none(*pmd));
32149 @@ -586,7 +607,7 @@ phys_pud_init(pud_t *pud_page, unsigned long addr, unsigned long end,
32150 prot);
32151
32152 spin_lock(&init_mm.page_table_lock);
32153 - pud_populate(&init_mm, pud, pmd);
32154 + pud_populate_kernel(&init_mm, pud, pmd);
32155 spin_unlock(&init_mm.page_table_lock);
32156 }
32157 __flush_tlb_all();
32158 @@ -627,7 +648,7 @@ kernel_physical_mapping_init(unsigned long start,
32159 page_size_mask);
32160
32161 spin_lock(&init_mm.page_table_lock);
32162 - pgd_populate(&init_mm, pgd, pud);
32163 + pgd_populate_kernel(&init_mm, pgd, pud);
32164 spin_unlock(&init_mm.page_table_lock);
32165 pgd_changed = true;
32166 }
32167 @@ -1188,8 +1209,8 @@ int kern_addr_valid(unsigned long addr)
32168 static struct vm_area_struct gate_vma = {
32169 .vm_start = VSYSCALL_START,
32170 .vm_end = VSYSCALL_START + (VSYSCALL_MAPPED_PAGES * PAGE_SIZE),
32171 - .vm_page_prot = PAGE_READONLY_EXEC,
32172 - .vm_flags = VM_READ | VM_EXEC
32173 + .vm_page_prot = PAGE_READONLY,
32174 + .vm_flags = VM_READ
32175 };
32176
32177 struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
32178 @@ -1223,7 +1244,7 @@ int in_gate_area_no_mm(unsigned long addr)
32179
32180 const char *arch_vma_name(struct vm_area_struct *vma)
32181 {
32182 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
32183 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
32184 return "[vdso]";
32185 if (vma == &gate_vma)
32186 return "[vsyscall]";
32187 diff --git a/arch/x86/mm/iomap_32.c b/arch/x86/mm/iomap_32.c
32188 index 7b179b4..6bd17777 100644
32189 --- a/arch/x86/mm/iomap_32.c
32190 +++ b/arch/x86/mm/iomap_32.c
32191 @@ -64,7 +64,11 @@ void *kmap_atomic_prot_pfn(unsigned long pfn, pgprot_t prot)
32192 type = kmap_atomic_idx_push();
32193 idx = type + KM_TYPE_NR * smp_processor_id();
32194 vaddr = __fix_to_virt(FIX_KMAP_BEGIN + idx);
32195 +
32196 + pax_open_kernel();
32197 set_pte(kmap_pte - idx, pfn_pte(pfn, prot));
32198 + pax_close_kernel();
32199 +
32200 arch_flush_lazy_mmu_mode();
32201
32202 return (void *)vaddr;
32203 diff --git a/arch/x86/mm/ioremap.c b/arch/x86/mm/ioremap.c
32204 index 799580c..72f9fe0 100644
32205 --- a/arch/x86/mm/ioremap.c
32206 +++ b/arch/x86/mm/ioremap.c
32207 @@ -97,7 +97,7 @@ static void __iomem *__ioremap_caller(resource_size_t phys_addr,
32208 for (pfn = phys_addr >> PAGE_SHIFT; pfn <= last_pfn; pfn++) {
32209 int is_ram = page_is_ram(pfn);
32210
32211 - if (is_ram && pfn_valid(pfn) && !PageReserved(pfn_to_page(pfn)))
32212 + if (is_ram && pfn_valid(pfn) && (pfn >= 0x100 || !PageReserved(pfn_to_page(pfn))))
32213 return NULL;
32214 WARN_ON_ONCE(is_ram);
32215 }
32216 @@ -256,7 +256,7 @@ EXPORT_SYMBOL(ioremap_prot);
32217 *
32218 * Caller must ensure there is only one unmapping for the same pointer.
32219 */
32220 -void iounmap(volatile void __iomem *addr)
32221 +void iounmap(const volatile void __iomem *addr)
32222 {
32223 struct vm_struct *p, *o;
32224
32225 @@ -310,6 +310,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32226
32227 /* If page is RAM, we can use __va. Otherwise ioremap and unmap. */
32228 if (page_is_ram(start >> PAGE_SHIFT))
32229 +#ifdef CONFIG_HIGHMEM
32230 + if ((start >> PAGE_SHIFT) < max_low_pfn)
32231 +#endif
32232 return __va(phys);
32233
32234 addr = (void __force *)ioremap_cache(start, PAGE_SIZE);
32235 @@ -322,6 +325,9 @@ void *xlate_dev_mem_ptr(unsigned long phys)
32236 void unxlate_dev_mem_ptr(unsigned long phys, void *addr)
32237 {
32238 if (page_is_ram(phys >> PAGE_SHIFT))
32239 +#ifdef CONFIG_HIGHMEM
32240 + if ((phys >> PAGE_SHIFT) < max_low_pfn)
32241 +#endif
32242 return;
32243
32244 iounmap((void __iomem *)((unsigned long)addr & PAGE_MASK));
32245 @@ -339,7 +345,7 @@ static int __init early_ioremap_debug_setup(char *str)
32246 early_param("early_ioremap_debug", early_ioremap_debug_setup);
32247
32248 static __initdata int after_paging_init;
32249 -static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __page_aligned_bss;
32250 +static pte_t bm_pte[PAGE_SIZE/sizeof(pte_t)] __read_only __aligned(PAGE_SIZE);
32251
32252 static inline pmd_t * __init early_ioremap_pmd(unsigned long addr)
32253 {
32254 @@ -376,8 +382,7 @@ void __init early_ioremap_init(void)
32255 slot_virt[i] = __fix_to_virt(FIX_BTMAP_BEGIN - NR_FIX_BTMAPS*i);
32256
32257 pmd = early_ioremap_pmd(fix_to_virt(FIX_BTMAP_BEGIN));
32258 - memset(bm_pte, 0, sizeof(bm_pte));
32259 - pmd_populate_kernel(&init_mm, pmd, bm_pte);
32260 + pmd_populate_user(&init_mm, pmd, bm_pte);
32261
32262 /*
32263 * The boot-ioremap range spans multiple pmds, for which
32264 diff --git a/arch/x86/mm/kmemcheck/kmemcheck.c b/arch/x86/mm/kmemcheck/kmemcheck.c
32265 index d87dd6d..bf3fa66 100644
32266 --- a/arch/x86/mm/kmemcheck/kmemcheck.c
32267 +++ b/arch/x86/mm/kmemcheck/kmemcheck.c
32268 @@ -622,9 +622,9 @@ bool kmemcheck_fault(struct pt_regs *regs, unsigned long address,
32269 * memory (e.g. tracked pages)? For now, we need this to avoid
32270 * invoking kmemcheck for PnP BIOS calls.
32271 */
32272 - if (regs->flags & X86_VM_MASK)
32273 + if (v8086_mode(regs))
32274 return false;
32275 - if (regs->cs != __KERNEL_CS)
32276 + if (regs->cs != __KERNEL_CS && regs->cs != __KERNEXEC_KERNEL_CS)
32277 return false;
32278
32279 pte = kmemcheck_pte_lookup(address);
32280 diff --git a/arch/x86/mm/mmap.c b/arch/x86/mm/mmap.c
32281 index 25e7e13..1964579 100644
32282 --- a/arch/x86/mm/mmap.c
32283 +++ b/arch/x86/mm/mmap.c
32284 @@ -52,7 +52,7 @@ static unsigned int stack_maxrandom_size(void)
32285 * Leave an at least ~128 MB hole with possible stack randomization.
32286 */
32287 #define MIN_GAP (128*1024*1024UL + stack_maxrandom_size())
32288 -#define MAX_GAP (TASK_SIZE/6*5)
32289 +#define MAX_GAP (pax_task_size/6*5)
32290
32291 static int mmap_is_legacy(void)
32292 {
32293 @@ -82,27 +82,40 @@ static unsigned long mmap_rnd(void)
32294 return rnd << PAGE_SHIFT;
32295 }
32296
32297 -static unsigned long mmap_base(void)
32298 +static unsigned long mmap_base(struct mm_struct *mm)
32299 {
32300 unsigned long gap = rlimit(RLIMIT_STACK);
32301 + unsigned long pax_task_size = TASK_SIZE;
32302 +
32303 +#ifdef CONFIG_PAX_SEGMEXEC
32304 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32305 + pax_task_size = SEGMEXEC_TASK_SIZE;
32306 +#endif
32307
32308 if (gap < MIN_GAP)
32309 gap = MIN_GAP;
32310 else if (gap > MAX_GAP)
32311 gap = MAX_GAP;
32312
32313 - return PAGE_ALIGN(TASK_SIZE - gap - mmap_rnd());
32314 + return PAGE_ALIGN(pax_task_size - gap - mmap_rnd());
32315 }
32316
32317 /*
32318 * Bottom-up (legacy) layout on X86_32 did not support randomization, X86_64
32319 * does, but not when emulating X86_32
32320 */
32321 -static unsigned long mmap_legacy_base(void)
32322 +static unsigned long mmap_legacy_base(struct mm_struct *mm)
32323 {
32324 - if (mmap_is_ia32())
32325 + if (mmap_is_ia32()) {
32326 +
32327 +#ifdef CONFIG_PAX_SEGMEXEC
32328 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
32329 + return SEGMEXEC_TASK_UNMAPPED_BASE;
32330 + else
32331 +#endif
32332 +
32333 return TASK_UNMAPPED_BASE;
32334 - else
32335 + } else
32336 return TASK_UNMAPPED_BASE + mmap_rnd();
32337 }
32338
32339 @@ -112,8 +125,15 @@ static unsigned long mmap_legacy_base(void)
32340 */
32341 void arch_pick_mmap_layout(struct mm_struct *mm)
32342 {
32343 - mm->mmap_legacy_base = mmap_legacy_base();
32344 - mm->mmap_base = mmap_base();
32345 + mm->mmap_legacy_base = mmap_legacy_base(mm);
32346 + mm->mmap_base = mmap_base(mm);
32347 +
32348 +#ifdef CONFIG_PAX_RANDMMAP
32349 + if (mm->pax_flags & MF_PAX_RANDMMAP) {
32350 + mm->mmap_legacy_base += mm->delta_mmap;
32351 + mm->mmap_base -= mm->delta_mmap + mm->delta_stack;
32352 + }
32353 +#endif
32354
32355 if (mmap_is_legacy()) {
32356 mm->mmap_base = mm->mmap_legacy_base;
32357 diff --git a/arch/x86/mm/mmio-mod.c b/arch/x86/mm/mmio-mod.c
32358 index 0057a7a..95c7edd 100644
32359 --- a/arch/x86/mm/mmio-mod.c
32360 +++ b/arch/x86/mm/mmio-mod.c
32361 @@ -194,7 +194,7 @@ static void pre(struct kmmio_probe *p, struct pt_regs *regs,
32362 break;
32363 default:
32364 {
32365 - unsigned char *ip = (unsigned char *)instptr;
32366 + unsigned char *ip = (unsigned char *)ktla_ktva(instptr);
32367 my_trace->opcode = MMIO_UNKNOWN_OP;
32368 my_trace->width = 0;
32369 my_trace->value = (*ip) << 16 | *(ip + 1) << 8 |
32370 @@ -234,7 +234,7 @@ static void post(struct kmmio_probe *p, unsigned long condition,
32371 static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32372 void __iomem *addr)
32373 {
32374 - static atomic_t next_id;
32375 + static atomic_unchecked_t next_id;
32376 struct remap_trace *trace = kmalloc(sizeof(*trace), GFP_KERNEL);
32377 /* These are page-unaligned. */
32378 struct mmiotrace_map map = {
32379 @@ -258,7 +258,7 @@ static void ioremap_trace_core(resource_size_t offset, unsigned long size,
32380 .private = trace
32381 },
32382 .phys = offset,
32383 - .id = atomic_inc_return(&next_id)
32384 + .id = atomic_inc_return_unchecked(&next_id)
32385 };
32386 map.map_id = trace->id;
32387
32388 @@ -290,7 +290,7 @@ void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
32389 ioremap_trace_core(offset, size, addr);
32390 }
32391
32392 -static void iounmap_trace_core(volatile void __iomem *addr)
32393 +static void iounmap_trace_core(const volatile void __iomem *addr)
32394 {
32395 struct mmiotrace_map map = {
32396 .phys = 0,
32397 @@ -328,7 +328,7 @@ not_enabled:
32398 }
32399 }
32400
32401 -void mmiotrace_iounmap(volatile void __iomem *addr)
32402 +void mmiotrace_iounmap(const volatile void __iomem *addr)
32403 {
32404 might_sleep();
32405 if (is_enabled()) /* recheck and proper locking in *_core() */
32406 diff --git a/arch/x86/mm/numa.c b/arch/x86/mm/numa.c
32407 index 24aec58..c39fe8b 100644
32408 --- a/arch/x86/mm/numa.c
32409 +++ b/arch/x86/mm/numa.c
32410 @@ -474,7 +474,7 @@ static bool __init numa_meminfo_cover_memory(const struct numa_meminfo *mi)
32411 return true;
32412 }
32413
32414 -static int __init numa_register_memblks(struct numa_meminfo *mi)
32415 +static int __init __intentional_overflow(-1) numa_register_memblks(struct numa_meminfo *mi)
32416 {
32417 unsigned long uninitialized_var(pfn_align);
32418 int i, nid;
32419 diff --git a/arch/x86/mm/pageattr-test.c b/arch/x86/mm/pageattr-test.c
32420 index d0b1773..4c3327c 100644
32421 --- a/arch/x86/mm/pageattr-test.c
32422 +++ b/arch/x86/mm/pageattr-test.c
32423 @@ -36,7 +36,7 @@ enum {
32424
32425 static int pte_testbit(pte_t pte)
32426 {
32427 - return pte_flags(pte) & _PAGE_UNUSED1;
32428 + return pte_flags(pte) & _PAGE_CPA_TEST;
32429 }
32430
32431 struct split_state {
32432 diff --git a/arch/x86/mm/pageattr.c b/arch/x86/mm/pageattr.c
32433 index bb32480..75f2f5e 100644
32434 --- a/arch/x86/mm/pageattr.c
32435 +++ b/arch/x86/mm/pageattr.c
32436 @@ -261,7 +261,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32437 */
32438 #ifdef CONFIG_PCI_BIOS
32439 if (pcibios_enabled && within(pfn, BIOS_BEGIN >> PAGE_SHIFT, BIOS_END >> PAGE_SHIFT))
32440 - pgprot_val(forbidden) |= _PAGE_NX;
32441 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32442 #endif
32443
32444 /*
32445 @@ -269,9 +269,10 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32446 * Does not cover __inittext since that is gone later on. On
32447 * 64bit we do not enforce !NX on the low mapping
32448 */
32449 - if (within(address, (unsigned long)_text, (unsigned long)_etext))
32450 - pgprot_val(forbidden) |= _PAGE_NX;
32451 + if (within(address, ktla_ktva((unsigned long)_text), ktla_ktva((unsigned long)_etext)))
32452 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32453
32454 +#ifdef CONFIG_DEBUG_RODATA
32455 /*
32456 * The .rodata section needs to be read-only. Using the pfn
32457 * catches all aliases.
32458 @@ -279,6 +280,7 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32459 if (within(pfn, __pa_symbol(__start_rodata) >> PAGE_SHIFT,
32460 __pa_symbol(__end_rodata) >> PAGE_SHIFT))
32461 pgprot_val(forbidden) |= _PAGE_RW;
32462 +#endif
32463
32464 #if defined(CONFIG_X86_64) && defined(CONFIG_DEBUG_RODATA)
32465 /*
32466 @@ -317,6 +319,13 @@ static inline pgprot_t static_protections(pgprot_t prot, unsigned long address,
32467 }
32468 #endif
32469
32470 +#ifdef CONFIG_PAX_KERNEXEC
32471 + if (within(pfn, __pa(ktla_ktva((unsigned long)&_text)), __pa((unsigned long)&_sdata))) {
32472 + pgprot_val(forbidden) |= _PAGE_RW;
32473 + pgprot_val(forbidden) |= _PAGE_NX & __supported_pte_mask;
32474 + }
32475 +#endif
32476 +
32477 prot = __pgprot(pgprot_val(prot) & ~pgprot_val(forbidden));
32478
32479 return prot;
32480 @@ -400,23 +409,37 @@ EXPORT_SYMBOL_GPL(slow_virt_to_phys);
32481 static void __set_pmd_pte(pte_t *kpte, unsigned long address, pte_t pte)
32482 {
32483 /* change init_mm */
32484 + pax_open_kernel();
32485 set_pte_atomic(kpte, pte);
32486 +
32487 #ifdef CONFIG_X86_32
32488 if (!SHARED_KERNEL_PMD) {
32489 +
32490 +#ifdef CONFIG_PAX_PER_CPU_PGD
32491 + unsigned long cpu;
32492 +#else
32493 struct page *page;
32494 +#endif
32495
32496 +#ifdef CONFIG_PAX_PER_CPU_PGD
32497 + for (cpu = 0; cpu < nr_cpu_ids; ++cpu) {
32498 + pgd_t *pgd = get_cpu_pgd(cpu, kernel);
32499 +#else
32500 list_for_each_entry(page, &pgd_list, lru) {
32501 - pgd_t *pgd;
32502 + pgd_t *pgd = (pgd_t *)page_address(page);
32503 +#endif
32504 +
32505 pud_t *pud;
32506 pmd_t *pmd;
32507
32508 - pgd = (pgd_t *)page_address(page) + pgd_index(address);
32509 + pgd += pgd_index(address);
32510 pud = pud_offset(pgd, address);
32511 pmd = pmd_offset(pud, address);
32512 set_pte_atomic((pte_t *)pmd, pte);
32513 }
32514 }
32515 #endif
32516 + pax_close_kernel();
32517 }
32518
32519 static int
32520 diff --git a/arch/x86/mm/pat.c b/arch/x86/mm/pat.c
32521 index 6574388..87e9bef 100644
32522 --- a/arch/x86/mm/pat.c
32523 +++ b/arch/x86/mm/pat.c
32524 @@ -376,7 +376,7 @@ int free_memtype(u64 start, u64 end)
32525
32526 if (!entry) {
32527 printk(KERN_INFO "%s:%d freeing invalid memtype [mem %#010Lx-%#010Lx]\n",
32528 - current->comm, current->pid, start, end - 1);
32529 + current->comm, task_pid_nr(current), start, end - 1);
32530 return -EINVAL;
32531 }
32532
32533 @@ -506,8 +506,8 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
32534
32535 while (cursor < to) {
32536 if (!devmem_is_allowed(pfn)) {
32537 - printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx]\n",
32538 - current->comm, from, to - 1);
32539 + printk(KERN_INFO "Program %s tried to access /dev/mem between [mem %#010Lx-%#010Lx] (%#010Lx)\n",
32540 + current->comm, from, to - 1, cursor);
32541 return 0;
32542 }
32543 cursor += PAGE_SIZE;
32544 @@ -577,7 +577,7 @@ int kernel_map_sync_memtype(u64 base, unsigned long size, unsigned long flags)
32545 if (ioremap_change_attr((unsigned long)__va(base), id_sz, flags) < 0) {
32546 printk(KERN_INFO "%s:%d ioremap_change_attr failed %s "
32547 "for [mem %#010Lx-%#010Lx]\n",
32548 - current->comm, current->pid,
32549 + current->comm, task_pid_nr(current),
32550 cattr_name(flags),
32551 base, (unsigned long long)(base + size-1));
32552 return -EINVAL;
32553 @@ -612,7 +612,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
32554 flags = lookup_memtype(paddr);
32555 if (want_flags != flags) {
32556 printk(KERN_WARNING "%s:%d map pfn RAM range req %s for [mem %#010Lx-%#010Lx], got %s\n",
32557 - current->comm, current->pid,
32558 + current->comm, task_pid_nr(current),
32559 cattr_name(want_flags),
32560 (unsigned long long)paddr,
32561 (unsigned long long)(paddr + size - 1),
32562 @@ -634,7 +634,7 @@ static int reserve_pfn_range(u64 paddr, unsigned long size, pgprot_t *vma_prot,
32563 free_memtype(paddr, paddr + size);
32564 printk(KERN_ERR "%s:%d map pfn expected mapping type %s"
32565 " for [mem %#010Lx-%#010Lx], got %s\n",
32566 - current->comm, current->pid,
32567 + current->comm, task_pid_nr(current),
32568 cattr_name(want_flags),
32569 (unsigned long long)paddr,
32570 (unsigned long long)(paddr + size - 1),
32571 diff --git a/arch/x86/mm/pat_rbtree.c b/arch/x86/mm/pat_rbtree.c
32572 index 415f6c4..d319983 100644
32573 --- a/arch/x86/mm/pat_rbtree.c
32574 +++ b/arch/x86/mm/pat_rbtree.c
32575 @@ -160,7 +160,7 @@ success:
32576
32577 failure:
32578 printk(KERN_INFO "%s:%d conflicting memory types "
32579 - "%Lx-%Lx %s<->%s\n", current->comm, current->pid, start,
32580 + "%Lx-%Lx %s<->%s\n", current->comm, task_pid_nr(current), start,
32581 end, cattr_name(found_type), cattr_name(match->type));
32582 return -EBUSY;
32583 }
32584 diff --git a/arch/x86/mm/pf_in.c b/arch/x86/mm/pf_in.c
32585 index 9f0614d..92ae64a 100644
32586 --- a/arch/x86/mm/pf_in.c
32587 +++ b/arch/x86/mm/pf_in.c
32588 @@ -148,7 +148,7 @@ enum reason_type get_ins_type(unsigned long ins_addr)
32589 int i;
32590 enum reason_type rv = OTHERS;
32591
32592 - p = (unsigned char *)ins_addr;
32593 + p = (unsigned char *)ktla_ktva(ins_addr);
32594 p += skip_prefix(p, &prf);
32595 p += get_opcode(p, &opcode);
32596
32597 @@ -168,7 +168,7 @@ static unsigned int get_ins_reg_width(unsigned long ins_addr)
32598 struct prefix_bits prf;
32599 int i;
32600
32601 - p = (unsigned char *)ins_addr;
32602 + p = (unsigned char *)ktla_ktva(ins_addr);
32603 p += skip_prefix(p, &prf);
32604 p += get_opcode(p, &opcode);
32605
32606 @@ -191,7 +191,7 @@ unsigned int get_ins_mem_width(unsigned long ins_addr)
32607 struct prefix_bits prf;
32608 int i;
32609
32610 - p = (unsigned char *)ins_addr;
32611 + p = (unsigned char *)ktla_ktva(ins_addr);
32612 p += skip_prefix(p, &prf);
32613 p += get_opcode(p, &opcode);
32614
32615 @@ -415,7 +415,7 @@ unsigned long get_ins_reg_val(unsigned long ins_addr, struct pt_regs *regs)
32616 struct prefix_bits prf;
32617 int i;
32618
32619 - p = (unsigned char *)ins_addr;
32620 + p = (unsigned char *)ktla_ktva(ins_addr);
32621 p += skip_prefix(p, &prf);
32622 p += get_opcode(p, &opcode);
32623 for (i = 0; i < ARRAY_SIZE(reg_rop); i++)
32624 @@ -470,7 +470,7 @@ unsigned long get_ins_imm_val(unsigned long ins_addr)
32625 struct prefix_bits prf;
32626 int i;
32627
32628 - p = (unsigned char *)ins_addr;
32629 + p = (unsigned char *)ktla_ktva(ins_addr);
32630 p += skip_prefix(p, &prf);
32631 p += get_opcode(p, &opcode);
32632 for (i = 0; i < ARRAY_SIZE(imm_wop); i++)
32633 diff --git a/arch/x86/mm/pgtable.c b/arch/x86/mm/pgtable.c
32634 index c96314a..433b127 100644
32635 --- a/arch/x86/mm/pgtable.c
32636 +++ b/arch/x86/mm/pgtable.c
32637 @@ -97,10 +97,71 @@ static inline void pgd_list_del(pgd_t *pgd)
32638 list_del(&page->lru);
32639 }
32640
32641 -#define UNSHARED_PTRS_PER_PGD \
32642 - (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
32643 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32644 +pgdval_t clone_pgd_mask __read_only = ~_PAGE_PRESENT;
32645
32646 +void __shadow_user_pgds(pgd_t *dst, const pgd_t *src)
32647 +{
32648 + unsigned int count = USER_PGD_PTRS;
32649
32650 + if (!pax_user_shadow_base)
32651 + return;
32652 +
32653 + while (count--)
32654 + *dst++ = __pgd((pgd_val(*src++) | (_PAGE_NX & __supported_pte_mask)) & ~_PAGE_USER);
32655 +}
32656 +#endif
32657 +
32658 +#ifdef CONFIG_PAX_PER_CPU_PGD
32659 +void __clone_user_pgds(pgd_t *dst, const pgd_t *src)
32660 +{
32661 + unsigned int count = USER_PGD_PTRS;
32662 +
32663 + while (count--) {
32664 + pgd_t pgd;
32665 +
32666 +#ifdef CONFIG_X86_64
32667 + pgd = __pgd(pgd_val(*src++) | _PAGE_USER);
32668 +#else
32669 + pgd = *src++;
32670 +#endif
32671 +
32672 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
32673 + pgd = __pgd(pgd_val(pgd) & clone_pgd_mask);
32674 +#endif
32675 +
32676 + *dst++ = pgd;
32677 + }
32678 +
32679 +}
32680 +#endif
32681 +
32682 +#ifdef CONFIG_X86_64
32683 +#define pxd_t pud_t
32684 +#define pyd_t pgd_t
32685 +#define paravirt_release_pxd(pfn) paravirt_release_pud(pfn)
32686 +#define pgtable_pxd_page_ctor(page) true
32687 +#define pgtable_pxd_page_dtor(page)
32688 +#define pxd_free(mm, pud) pud_free((mm), (pud))
32689 +#define pyd_populate(mm, pgd, pud) pgd_populate((mm), (pgd), (pud))
32690 +#define pyd_offset(mm, address) pgd_offset((mm), (address))
32691 +#define PYD_SIZE PGDIR_SIZE
32692 +#else
32693 +#define pxd_t pmd_t
32694 +#define pyd_t pud_t
32695 +#define paravirt_release_pxd(pfn) paravirt_release_pmd(pfn)
32696 +#define pgtable_pxd_page_ctor(page) pgtable_pmd_page_ctor(page)
32697 +#define pgtable_pxd_page_dtor(page) pgtable_pmd_page_dtor(page)
32698 +#define pxd_free(mm, pud) pmd_free((mm), (pud))
32699 +#define pyd_populate(mm, pgd, pud) pud_populate((mm), (pgd), (pud))
32700 +#define pyd_offset(mm, address) pud_offset((mm), (address))
32701 +#define PYD_SIZE PUD_SIZE
32702 +#endif
32703 +
32704 +#ifdef CONFIG_PAX_PER_CPU_PGD
32705 +static inline void pgd_ctor(struct mm_struct *mm, pgd_t *pgd) {}
32706 +static inline void pgd_dtor(pgd_t *pgd) {}
32707 +#else
32708 static void pgd_set_mm(pgd_t *pgd, struct mm_struct *mm)
32709 {
32710 BUILD_BUG_ON(sizeof(virt_to_page(pgd)->index) < sizeof(mm));
32711 @@ -141,6 +202,7 @@ static void pgd_dtor(pgd_t *pgd)
32712 pgd_list_del(pgd);
32713 spin_unlock(&pgd_lock);
32714 }
32715 +#endif
32716
32717 /*
32718 * List of all pgd's needed for non-PAE so it can invalidate entries
32719 @@ -153,7 +215,7 @@ static void pgd_dtor(pgd_t *pgd)
32720 * -- nyc
32721 */
32722
32723 -#ifdef CONFIG_X86_PAE
32724 +#if defined(CONFIG_X86_32) && defined(CONFIG_X86_PAE)
32725 /*
32726 * In PAE mode, we need to do a cr3 reload (=tlb flush) when
32727 * updating the top-level pagetable entries to guarantee the
32728 @@ -165,7 +227,7 @@ static void pgd_dtor(pgd_t *pgd)
32729 * not shared between pagetables (!SHARED_KERNEL_PMDS), we allocate
32730 * and initialize the kernel pmds here.
32731 */
32732 -#define PREALLOCATED_PMDS UNSHARED_PTRS_PER_PGD
32733 +#define PREALLOCATED_PXDS (SHARED_KERNEL_PMD ? KERNEL_PGD_BOUNDARY : PTRS_PER_PGD)
32734
32735 void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
32736 {
32737 @@ -183,43 +245,45 @@ void pud_populate(struct mm_struct *mm, pud_t *pudp, pmd_t *pmd)
32738 */
32739 flush_tlb_mm(mm);
32740 }
32741 +#elif defined(CONFIG_X86_64) && defined(CONFIG_PAX_PER_CPU_PGD)
32742 +#define PREALLOCATED_PXDS USER_PGD_PTRS
32743 #else /* !CONFIG_X86_PAE */
32744
32745 /* No need to prepopulate any pagetable entries in non-PAE modes. */
32746 -#define PREALLOCATED_PMDS 0
32747 +#define PREALLOCATED_PXDS 0
32748
32749 #endif /* CONFIG_X86_PAE */
32750
32751 -static void free_pmds(pmd_t *pmds[])
32752 +static void free_pxds(pxd_t *pxds[])
32753 {
32754 int i;
32755
32756 - for(i = 0; i < PREALLOCATED_PMDS; i++)
32757 - if (pmds[i]) {
32758 - pgtable_pmd_page_dtor(virt_to_page(pmds[i]));
32759 - free_page((unsigned long)pmds[i]);
32760 + for(i = 0; i < PREALLOCATED_PXDS; i++)
32761 + if (pxds[i]) {
32762 + pgtable_pxd_page_dtor(virt_to_page(pxds[i]));
32763 + free_page((unsigned long)pxds[i]);
32764 }
32765 }
32766
32767 -static int preallocate_pmds(pmd_t *pmds[])
32768 +static int preallocate_pxds(pxd_t *pxds[])
32769 {
32770 int i;
32771 bool failed = false;
32772
32773 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
32774 - pmd_t *pmd = (pmd_t *)__get_free_page(PGALLOC_GFP);
32775 - if (!pmd)
32776 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
32777 + pxd_t *pxd = (pxd_t *)__get_free_page(PGALLOC_GFP);
32778 + if (!pxd)
32779 failed = true;
32780 - if (pmd && !pgtable_pmd_page_ctor(virt_to_page(pmd))) {
32781 - free_page((unsigned long)pmd);
32782 - pmd = NULL;
32783 + if (pxd && !pgtable_pxd_page_ctor(virt_to_page(pxd))) {
32784 + free_page((unsigned long)pxd);
32785 + pxd = NULL;
32786 failed = true;
32787 }
32788 - pmds[i] = pmd;
32789 + pxds[i] = pxd;
32790 }
32791
32792 if (failed) {
32793 - free_pmds(pmds);
32794 + free_pxds(pxds);
32795 return -ENOMEM;
32796 }
32797
32798 @@ -232,49 +296,52 @@ static int preallocate_pmds(pmd_t *pmds[])
32799 * preallocate which never got a corresponding vma will need to be
32800 * freed manually.
32801 */
32802 -static void pgd_mop_up_pmds(struct mm_struct *mm, pgd_t *pgdp)
32803 +static void pgd_mop_up_pxds(struct mm_struct *mm, pgd_t *pgdp)
32804 {
32805 int i;
32806
32807 - for(i = 0; i < PREALLOCATED_PMDS; i++) {
32808 + for(i = 0; i < PREALLOCATED_PXDS; i++) {
32809 pgd_t pgd = pgdp[i];
32810
32811 if (pgd_val(pgd) != 0) {
32812 - pmd_t *pmd = (pmd_t *)pgd_page_vaddr(pgd);
32813 + pxd_t *pxd = (pxd_t *)pgd_page_vaddr(pgd);
32814
32815 - pgdp[i] = native_make_pgd(0);
32816 + set_pgd(pgdp + i, native_make_pgd(0));
32817
32818 - paravirt_release_pmd(pgd_val(pgd) >> PAGE_SHIFT);
32819 - pmd_free(mm, pmd);
32820 + paravirt_release_pxd(pgd_val(pgd) >> PAGE_SHIFT);
32821 + pxd_free(mm, pxd);
32822 }
32823 }
32824 }
32825
32826 -static void pgd_prepopulate_pmd(struct mm_struct *mm, pgd_t *pgd, pmd_t *pmds[])
32827 +static void pgd_prepopulate_pxd(struct mm_struct *mm, pgd_t *pgd, pxd_t *pxds[])
32828 {
32829 - pud_t *pud;
32830 + pyd_t *pyd;
32831 int i;
32832
32833 - if (PREALLOCATED_PMDS == 0) /* Work around gcc-3.4.x bug */
32834 + if (PREALLOCATED_PXDS == 0) /* Work around gcc-3.4.x bug */
32835 return;
32836
32837 - pud = pud_offset(pgd, 0);
32838 -
32839 - for (i = 0; i < PREALLOCATED_PMDS; i++, pud++) {
32840 - pmd_t *pmd = pmds[i];
32841 +#ifdef CONFIG_X86_64
32842 + pyd = pyd_offset(mm, 0L);
32843 +#else
32844 + pyd = pyd_offset(pgd, 0L);
32845 +#endif
32846
32847 + for (i = 0; i < PREALLOCATED_PXDS; i++, pyd++) {
32848 + pxd_t *pxd = pxds[i];
32849 if (i >= KERNEL_PGD_BOUNDARY)
32850 - memcpy(pmd, (pmd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32851 - sizeof(pmd_t) * PTRS_PER_PMD);
32852 + memcpy(pxd, (pxd_t *)pgd_page_vaddr(swapper_pg_dir[i]),
32853 + sizeof(pxd_t) * PTRS_PER_PMD);
32854
32855 - pud_populate(mm, pud, pmd);
32856 + pyd_populate(mm, pyd, pxd);
32857 }
32858 }
32859
32860 pgd_t *pgd_alloc(struct mm_struct *mm)
32861 {
32862 pgd_t *pgd;
32863 - pmd_t *pmds[PREALLOCATED_PMDS];
32864 + pxd_t *pxds[PREALLOCATED_PXDS];
32865
32866 pgd = (pgd_t *)__get_free_page(PGALLOC_GFP);
32867
32868 @@ -283,11 +350,11 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32869
32870 mm->pgd = pgd;
32871
32872 - if (preallocate_pmds(pmds) != 0)
32873 + if (preallocate_pxds(pxds) != 0)
32874 goto out_free_pgd;
32875
32876 if (paravirt_pgd_alloc(mm) != 0)
32877 - goto out_free_pmds;
32878 + goto out_free_pxds;
32879
32880 /*
32881 * Make sure that pre-populating the pmds is atomic with
32882 @@ -297,14 +364,14 @@ pgd_t *pgd_alloc(struct mm_struct *mm)
32883 spin_lock(&pgd_lock);
32884
32885 pgd_ctor(mm, pgd);
32886 - pgd_prepopulate_pmd(mm, pgd, pmds);
32887 + pgd_prepopulate_pxd(mm, pgd, pxds);
32888
32889 spin_unlock(&pgd_lock);
32890
32891 return pgd;
32892
32893 -out_free_pmds:
32894 - free_pmds(pmds);
32895 +out_free_pxds:
32896 + free_pxds(pxds);
32897 out_free_pgd:
32898 free_page((unsigned long)pgd);
32899 out:
32900 @@ -313,7 +380,7 @@ out:
32901
32902 void pgd_free(struct mm_struct *mm, pgd_t *pgd)
32903 {
32904 - pgd_mop_up_pmds(mm, pgd);
32905 + pgd_mop_up_pxds(mm, pgd);
32906 pgd_dtor(pgd);
32907 paravirt_pgd_free(mm, pgd);
32908 free_page((unsigned long)pgd);
32909 diff --git a/arch/x86/mm/pgtable_32.c b/arch/x86/mm/pgtable_32.c
32910 index a69bcb8..19068ab 100644
32911 --- a/arch/x86/mm/pgtable_32.c
32912 +++ b/arch/x86/mm/pgtable_32.c
32913 @@ -47,10 +47,13 @@ void set_pte_vaddr(unsigned long vaddr, pte_t pteval)
32914 return;
32915 }
32916 pte = pte_offset_kernel(pmd, vaddr);
32917 +
32918 + pax_open_kernel();
32919 if (pte_val(pteval))
32920 set_pte_at(&init_mm, vaddr, pte, pteval);
32921 else
32922 pte_clear(&init_mm, vaddr, pte);
32923 + pax_close_kernel();
32924
32925 /*
32926 * It's enough to flush this one mapping.
32927 diff --git a/arch/x86/mm/physaddr.c b/arch/x86/mm/physaddr.c
32928 index e666cbb..61788c45 100644
32929 --- a/arch/x86/mm/physaddr.c
32930 +++ b/arch/x86/mm/physaddr.c
32931 @@ -10,7 +10,7 @@
32932 #ifdef CONFIG_X86_64
32933
32934 #ifdef CONFIG_DEBUG_VIRTUAL
32935 -unsigned long __phys_addr(unsigned long x)
32936 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32937 {
32938 unsigned long y = x - __START_KERNEL_map;
32939
32940 @@ -67,7 +67,7 @@ EXPORT_SYMBOL(__virt_addr_valid);
32941 #else
32942
32943 #ifdef CONFIG_DEBUG_VIRTUAL
32944 -unsigned long __phys_addr(unsigned long x)
32945 +unsigned long __intentional_overflow(-1) __phys_addr(unsigned long x)
32946 {
32947 unsigned long phys_addr = x - PAGE_OFFSET;
32948 /* VMALLOC_* aren't constants */
32949 diff --git a/arch/x86/mm/setup_nx.c b/arch/x86/mm/setup_nx.c
32950 index 90555bf..f5f1828 100644
32951 --- a/arch/x86/mm/setup_nx.c
32952 +++ b/arch/x86/mm/setup_nx.c
32953 @@ -5,8 +5,10 @@
32954 #include <asm/pgtable.h>
32955 #include <asm/proto.h>
32956
32957 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32958 static int disable_nx;
32959
32960 +#ifndef CONFIG_PAX_PAGEEXEC
32961 /*
32962 * noexec = on|off
32963 *
32964 @@ -28,12 +30,17 @@ static int __init noexec_setup(char *str)
32965 return 0;
32966 }
32967 early_param("noexec", noexec_setup);
32968 +#endif
32969 +
32970 +#endif
32971
32972 void x86_configure_nx(void)
32973 {
32974 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
32975 if (cpu_has_nx && !disable_nx)
32976 __supported_pte_mask |= _PAGE_NX;
32977 else
32978 +#endif
32979 __supported_pte_mask &= ~_PAGE_NX;
32980 }
32981
32982 diff --git a/arch/x86/mm/tlb.c b/arch/x86/mm/tlb.c
32983 index ae699b3..f1b2ad2 100644
32984 --- a/arch/x86/mm/tlb.c
32985 +++ b/arch/x86/mm/tlb.c
32986 @@ -48,7 +48,11 @@ void leave_mm(int cpu)
32987 BUG();
32988 if (cpumask_test_cpu(cpu, mm_cpumask(active_mm))) {
32989 cpumask_clear_cpu(cpu, mm_cpumask(active_mm));
32990 +
32991 +#ifndef CONFIG_PAX_PER_CPU_PGD
32992 load_cr3(swapper_pg_dir);
32993 +#endif
32994 +
32995 }
32996 }
32997 EXPORT_SYMBOL_GPL(leave_mm);
32998 diff --git a/arch/x86/mm/uderef_64.c b/arch/x86/mm/uderef_64.c
32999 new file mode 100644
33000 index 0000000..dace51c
33001 --- /dev/null
33002 +++ b/arch/x86/mm/uderef_64.c
33003 @@ -0,0 +1,37 @@
33004 +#include <linux/mm.h>
33005 +#include <asm/pgtable.h>
33006 +#include <asm/uaccess.h>
33007 +
33008 +#ifdef CONFIG_PAX_MEMORY_UDEREF
33009 +/* PaX: due to the special call convention these functions must
33010 + * - remain leaf functions under all configurations,
33011 + * - never be called directly, only dereferenced from the wrappers.
33012 + */
33013 +void __pax_open_userland(void)
33014 +{
33015 + unsigned int cpu;
33016 +
33017 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
33018 + return;
33019 +
33020 + cpu = raw_get_cpu();
33021 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_KERNEL);
33022 + write_cr3(__pa(get_cpu_pgd(cpu, user)) | PCID_USER | PCID_NOFLUSH);
33023 + raw_put_cpu_no_resched();
33024 +}
33025 +EXPORT_SYMBOL(__pax_open_userland);
33026 +
33027 +void __pax_close_userland(void)
33028 +{
33029 + unsigned int cpu;
33030 +
33031 + if (unlikely(!segment_eq(get_fs(), USER_DS)))
33032 + return;
33033 +
33034 + cpu = raw_get_cpu();
33035 + BUG_ON((read_cr3() & ~PAGE_MASK) != PCID_USER);
33036 + write_cr3(__pa(get_cpu_pgd(cpu, kernel)) | PCID_KERNEL | PCID_NOFLUSH);
33037 + raw_put_cpu_no_resched();
33038 +}
33039 +EXPORT_SYMBOL(__pax_close_userland);
33040 +#endif
33041 diff --git a/arch/x86/net/bpf_jit.S b/arch/x86/net/bpf_jit.S
33042 index 877b9a1..a8ecf42 100644
33043 --- a/arch/x86/net/bpf_jit.S
33044 +++ b/arch/x86/net/bpf_jit.S
33045 @@ -9,6 +9,7 @@
33046 */
33047 #include <linux/linkage.h>
33048 #include <asm/dwarf2.h>
33049 +#include <asm/alternative-asm.h>
33050
33051 /*
33052 * Calling convention :
33053 @@ -35,6 +36,7 @@ sk_load_word_positive_offset:
33054 jle bpf_slow_path_word
33055 mov (SKBDATA,%rsi),%eax
33056 bswap %eax /* ntohl() */
33057 + pax_force_retaddr
33058 ret
33059
33060 sk_load_half:
33061 @@ -52,6 +54,7 @@ sk_load_half_positive_offset:
33062 jle bpf_slow_path_half
33063 movzwl (SKBDATA,%rsi),%eax
33064 rol $8,%ax # ntohs()
33065 + pax_force_retaddr
33066 ret
33067
33068 sk_load_byte:
33069 @@ -66,6 +69,7 @@ sk_load_byte_positive_offset:
33070 cmp %esi,%r9d /* if (offset >= hlen) goto bpf_slow_path_byte */
33071 jle bpf_slow_path_byte
33072 movzbl (SKBDATA,%rsi),%eax
33073 + pax_force_retaddr
33074 ret
33075
33076 /**
33077 @@ -87,6 +91,7 @@ sk_load_byte_msh_positive_offset:
33078 movzbl (SKBDATA,%rsi),%ebx
33079 and $15,%bl
33080 shl $2,%bl
33081 + pax_force_retaddr
33082 ret
33083
33084 /* rsi contains offset and can be scratched */
33085 @@ -109,6 +114,7 @@ bpf_slow_path_word:
33086 js bpf_error
33087 mov -12(%rbp),%eax
33088 bswap %eax
33089 + pax_force_retaddr
33090 ret
33091
33092 bpf_slow_path_half:
33093 @@ -117,12 +123,14 @@ bpf_slow_path_half:
33094 mov -12(%rbp),%ax
33095 rol $8,%ax
33096 movzwl %ax,%eax
33097 + pax_force_retaddr
33098 ret
33099
33100 bpf_slow_path_byte:
33101 bpf_slow_path_common(1)
33102 js bpf_error
33103 movzbl -12(%rbp),%eax
33104 + pax_force_retaddr
33105 ret
33106
33107 bpf_slow_path_byte_msh:
33108 @@ -133,6 +141,7 @@ bpf_slow_path_byte_msh:
33109 and $15,%al
33110 shl $2,%al
33111 xchg %eax,%ebx
33112 + pax_force_retaddr
33113 ret
33114
33115 #define sk_negative_common(SIZE) \
33116 @@ -157,6 +166,7 @@ sk_load_word_negative_offset:
33117 sk_negative_common(4)
33118 mov (%rax), %eax
33119 bswap %eax
33120 + pax_force_retaddr
33121 ret
33122
33123 bpf_slow_path_half_neg:
33124 @@ -168,6 +178,7 @@ sk_load_half_negative_offset:
33125 mov (%rax),%ax
33126 rol $8,%ax
33127 movzwl %ax,%eax
33128 + pax_force_retaddr
33129 ret
33130
33131 bpf_slow_path_byte_neg:
33132 @@ -177,6 +188,7 @@ sk_load_byte_negative_offset:
33133 .globl sk_load_byte_negative_offset
33134 sk_negative_common(1)
33135 movzbl (%rax), %eax
33136 + pax_force_retaddr
33137 ret
33138
33139 bpf_slow_path_byte_msh_neg:
33140 @@ -190,6 +202,7 @@ sk_load_byte_msh_negative_offset:
33141 and $15,%al
33142 shl $2,%al
33143 xchg %eax,%ebx
33144 + pax_force_retaddr
33145 ret
33146
33147 bpf_error:
33148 @@ -197,4 +210,5 @@ bpf_error:
33149 xor %eax,%eax
33150 mov -8(%rbp),%rbx
33151 leaveq
33152 + pax_force_retaddr
33153 ret
33154 diff --git a/arch/x86/net/bpf_jit_comp.c b/arch/x86/net/bpf_jit_comp.c
33155 index 4ed75dd..8dfe0d5 100644
33156 --- a/arch/x86/net/bpf_jit_comp.c
33157 +++ b/arch/x86/net/bpf_jit_comp.c
33158 @@ -50,13 +50,90 @@ static inline u8 *emit_code(u8 *ptr, u32 bytes, unsigned int len)
33159 return ptr + len;
33160 }
33161
33162 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33163 +#define MAX_INSTR_CODE_SIZE 96
33164 +#else
33165 +#define MAX_INSTR_CODE_SIZE 64
33166 +#endif
33167 +
33168 #define EMIT(bytes, len) do { prog = emit_code(prog, bytes, len); } while (0)
33169
33170 #define EMIT1(b1) EMIT(b1, 1)
33171 #define EMIT2(b1, b2) EMIT((b1) + ((b2) << 8), 2)
33172 #define EMIT3(b1, b2, b3) EMIT((b1) + ((b2) << 8) + ((b3) << 16), 3)
33173 #define EMIT4(b1, b2, b3, b4) EMIT((b1) + ((b2) << 8) + ((b3) << 16) + ((b4) << 24), 4)
33174 +
33175 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33176 +/* original constant will appear in ecx */
33177 +#define DILUTE_CONST_SEQUENCE(_off, _key) \
33178 +do { \
33179 + /* mov ecx, randkey */ \
33180 + EMIT1(0xb9); \
33181 + EMIT(_key, 4); \
33182 + /* xor ecx, randkey ^ off */ \
33183 + EMIT2(0x81, 0xf1); \
33184 + EMIT((_key) ^ (_off), 4); \
33185 +} while (0)
33186 +
33187 +#define EMIT1_off32(b1, _off) \
33188 +do { \
33189 + switch (b1) { \
33190 + case 0x05: /* add eax, imm32 */ \
33191 + case 0x2d: /* sub eax, imm32 */ \
33192 + case 0x25: /* and eax, imm32 */ \
33193 + case 0x0d: /* or eax, imm32 */ \
33194 + case 0xb8: /* mov eax, imm32 */ \
33195 + case 0x35: /* xor eax, imm32 */ \
33196 + case 0x3d: /* cmp eax, imm32 */ \
33197 + case 0xa9: /* test eax, imm32 */ \
33198 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33199 + EMIT2((b1) - 4, 0xc8); /* convert imm instruction to eax, ecx */\
33200 + break; \
33201 + case 0xbb: /* mov ebx, imm32 */ \
33202 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33203 + /* mov ebx, ecx */ \
33204 + EMIT2(0x89, 0xcb); \
33205 + break; \
33206 + case 0xbe: /* mov esi, imm32 */ \
33207 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33208 + /* mov esi, ecx */ \
33209 + EMIT2(0x89, 0xce); \
33210 + break; \
33211 + case 0xe8: /* call rel imm32, always to known funcs */ \
33212 + EMIT1(b1); \
33213 + EMIT(_off, 4); \
33214 + break; \
33215 + case 0xe9: /* jmp rel imm32 */ \
33216 + EMIT1(b1); \
33217 + EMIT(_off, 4); \
33218 + /* prevent fall-through, we're not called if off = 0 */ \
33219 + EMIT(0xcccccccc, 4); \
33220 + EMIT(0xcccccccc, 4); \
33221 + break; \
33222 + default: \
33223 + BUILD_BUG(); \
33224 + } \
33225 +} while (0)
33226 +
33227 +#define EMIT2_off32(b1, b2, _off) \
33228 +do { \
33229 + if ((b1) == 0x8d && (b2) == 0xb3) { /* lea esi, [rbx+imm32] */ \
33230 + EMIT2(0x8d, 0xb3); /* lea esi, [rbx+randkey] */ \
33231 + EMIT(randkey, 4); \
33232 + EMIT2(0x8d, 0xb6); /* lea esi, [esi+off-randkey] */ \
33233 + EMIT((_off) - randkey, 4); \
33234 + } else if ((b1) == 0x69 && (b2) == 0xc0) { /* imul eax, imm32 */\
33235 + DILUTE_CONST_SEQUENCE(_off, randkey); \
33236 + /* imul eax, ecx */ \
33237 + EMIT3(0x0f, 0xaf, 0xc1); \
33238 + } else { \
33239 + BUILD_BUG(); \
33240 + } \
33241 +} while (0)
33242 +#else
33243 #define EMIT1_off32(b1, off) do { EMIT1(b1); EMIT(off, 4);} while (0)
33244 +#define EMIT2_off32(b1, b2, off) do { EMIT2(b1, b2); EMIT(off, 4);} while (0)
33245 +#endif
33246
33247 #define CLEAR_A() EMIT2(0x31, 0xc0) /* xor %eax,%eax */
33248 #define CLEAR_X() EMIT2(0x31, 0xdb) /* xor %ebx,%ebx */
33249 @@ -91,6 +168,24 @@ do { \
33250 #define X86_JBE 0x76
33251 #define X86_JA 0x77
33252
33253 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33254 +#define APPEND_FLOW_VERIFY() \
33255 +do { \
33256 + /* mov ecx, randkey */ \
33257 + EMIT1(0xb9); \
33258 + EMIT(randkey, 4); \
33259 + /* cmp ecx, randkey */ \
33260 + EMIT2(0x81, 0xf9); \
33261 + EMIT(randkey, 4); \
33262 + /* jz after 8 int 3s */ \
33263 + EMIT2(0x74, 0x08); \
33264 + EMIT(0xcccccccc, 4); \
33265 + EMIT(0xcccccccc, 4); \
33266 +} while (0)
33267 +#else
33268 +#define APPEND_FLOW_VERIFY() do { } while (0)
33269 +#endif
33270 +
33271 #define EMIT_COND_JMP(op, offset) \
33272 do { \
33273 if (is_near(offset)) \
33274 @@ -98,6 +193,7 @@ do { \
33275 else { \
33276 EMIT2(0x0f, op + 0x10); \
33277 EMIT(offset, 4); /* jxx .+off32 */ \
33278 + APPEND_FLOW_VERIFY(); \
33279 } \
33280 } while (0)
33281
33282 @@ -145,55 +241,54 @@ static int pkt_type_offset(void)
33283 return -1;
33284 }
33285
33286 -struct bpf_binary_header {
33287 - unsigned int pages;
33288 - /* Note : for security reasons, bpf code will follow a randomly
33289 - * sized amount of int3 instructions
33290 - */
33291 - u8 image[];
33292 -};
33293 -
33294 -static struct bpf_binary_header *bpf_alloc_binary(unsigned int proglen,
33295 +/* Note : for security reasons, bpf code will follow a randomly
33296 + * sized amount of int3 instructions
33297 + */
33298 +static u8 *bpf_alloc_binary(unsigned int proglen,
33299 u8 **image_ptr)
33300 {
33301 unsigned int sz, hole;
33302 - struct bpf_binary_header *header;
33303 + u8 *header;
33304
33305 /* Most of BPF filters are really small,
33306 * but if some of them fill a page, allow at least
33307 * 128 extra bytes to insert a random section of int3
33308 */
33309 - sz = round_up(proglen + sizeof(*header) + 128, PAGE_SIZE);
33310 - header = module_alloc(sz);
33311 + sz = round_up(proglen + 128, PAGE_SIZE);
33312 + header = module_alloc_exec(sz);
33313 if (!header)
33314 return NULL;
33315
33316 + pax_open_kernel();
33317 memset(header, 0xcc, sz); /* fill whole space with int3 instructions */
33318 + pax_close_kernel();
33319
33320 - header->pages = sz / PAGE_SIZE;
33321 - hole = sz - (proglen + sizeof(*header));
33322 + hole = PAGE_SIZE - (proglen & ~PAGE_MASK);
33323
33324 /* insert a random number of int3 instructions before BPF code */
33325 - *image_ptr = &header->image[prandom_u32() % hole];
33326 + *image_ptr = &header[prandom_u32() % hole];
33327 return header;
33328 }
33329
33330 void bpf_jit_compile(struct sk_filter *fp)
33331 {
33332 - u8 temp[64];
33333 + u8 temp[MAX_INSTR_CODE_SIZE];
33334 u8 *prog;
33335 unsigned int proglen, oldproglen = 0;
33336 int ilen, i;
33337 int t_offset, f_offset;
33338 u8 t_op, f_op, seen = 0, pass;
33339 u8 *image = NULL;
33340 - struct bpf_binary_header *header = NULL;
33341 + u8 *header = NULL;
33342 u8 *func;
33343 int pc_ret0 = -1; /* bpf index of first RET #0 instruction (if any) */
33344 unsigned int cleanup_addr; /* epilogue code offset */
33345 unsigned int *addrs;
33346 const struct sock_filter *filter = fp->insns;
33347 int flen = fp->len;
33348 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33349 + unsigned int randkey;
33350 +#endif
33351
33352 if (!bpf_jit_enable)
33353 return;
33354 @@ -202,11 +297,15 @@ void bpf_jit_compile(struct sk_filter *fp)
33355 if (addrs == NULL)
33356 return;
33357
33358 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33359 + randkey = get_random_int();
33360 +#endif
33361 +
33362 /* Before first pass, make a rough estimation of addrs[]
33363 - * each bpf instruction is translated to less than 64 bytes
33364 + * each bpf instruction is translated to less than MAX_INSTR_CODE_SIZE bytes
33365 */
33366 for (proglen = 0, i = 0; i < flen; i++) {
33367 - proglen += 64;
33368 + proglen += MAX_INSTR_CODE_SIZE;
33369 addrs[i] = proglen;
33370 }
33371 cleanup_addr = proglen; /* epilogue address */
33372 @@ -317,10 +416,8 @@ void bpf_jit_compile(struct sk_filter *fp)
33373 case BPF_S_ALU_MUL_K: /* A *= K */
33374 if (is_imm8(K))
33375 EMIT3(0x6b, 0xc0, K); /* imul imm8,%eax,%eax */
33376 - else {
33377 - EMIT2(0x69, 0xc0); /* imul imm32,%eax */
33378 - EMIT(K, 4);
33379 - }
33380 + else
33381 + EMIT2_off32(0x69, 0xc0, K); /* imul imm32,%eax */
33382 break;
33383 case BPF_S_ALU_DIV_X: /* A /= X; */
33384 seen |= SEEN_XREG;
33385 @@ -364,7 +461,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33386 break;
33387 }
33388 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33389 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33390 + DILUTE_CONST_SEQUENCE(K, randkey);
33391 +#else
33392 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33393 +#endif
33394 EMIT2(0xf7, 0xf1); /* div %ecx */
33395 EMIT2(0x89, 0xd0); /* mov %edx,%eax */
33396 break;
33397 @@ -372,7 +473,11 @@ void bpf_jit_compile(struct sk_filter *fp)
33398 if (K == 1)
33399 break;
33400 EMIT2(0x31, 0xd2); /* xor %edx,%edx */
33401 +#ifdef CONFIG_GRKERNSEC_JIT_HARDEN
33402 + DILUTE_CONST_SEQUENCE(K, randkey);
33403 +#else
33404 EMIT1(0xb9);EMIT(K, 4); /* mov imm32,%ecx */
33405 +#endif
33406 EMIT2(0xf7, 0xf1); /* div %ecx */
33407 break;
33408 case BPF_S_ALU_AND_X:
33409 @@ -643,8 +748,7 @@ common_load_ind: seen |= SEEN_DATAREF | SEEN_XREG;
33410 if (is_imm8(K)) {
33411 EMIT3(0x8d, 0x73, K); /* lea imm8(%rbx), %esi */
33412 } else {
33413 - EMIT2(0x8d, 0xb3); /* lea imm32(%rbx),%esi */
33414 - EMIT(K, 4);
33415 + EMIT2_off32(0x8d, 0xb3, K); /* lea imm32(%rbx),%esi */
33416 }
33417 } else {
33418 EMIT2(0x89,0xde); /* mov %ebx,%esi */
33419 @@ -734,10 +838,12 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33420 if (unlikely(proglen + ilen > oldproglen)) {
33421 pr_err("bpb_jit_compile fatal error\n");
33422 kfree(addrs);
33423 - module_free(NULL, header);
33424 + module_free_exec(NULL, image);
33425 return;
33426 }
33427 + pax_open_kernel();
33428 memcpy(image + proglen, temp, ilen);
33429 + pax_close_kernel();
33430 }
33431 proglen += ilen;
33432 addrs[i] = proglen;
33433 @@ -770,7 +876,6 @@ cond_branch: f_offset = addrs[i + filter[i].jf] - addrs[i];
33434
33435 if (image) {
33436 bpf_flush_icache(header, image + proglen);
33437 - set_memory_ro((unsigned long)header, header->pages);
33438 fp->bpf_func = (void *)image;
33439 }
33440 out:
33441 @@ -782,10 +887,9 @@ static void bpf_jit_free_deferred(struct work_struct *work)
33442 {
33443 struct sk_filter *fp = container_of(work, struct sk_filter, work);
33444 unsigned long addr = (unsigned long)fp->bpf_func & PAGE_MASK;
33445 - struct bpf_binary_header *header = (void *)addr;
33446
33447 - set_memory_rw(addr, header->pages);
33448 - module_free(NULL, header);
33449 + set_memory_rw(addr, 1);
33450 + module_free_exec(NULL, (void *)addr);
33451 kfree(fp);
33452 }
33453
33454 diff --git a/arch/x86/oprofile/backtrace.c b/arch/x86/oprofile/backtrace.c
33455 index 5d04be5..2beeaa2 100644
33456 --- a/arch/x86/oprofile/backtrace.c
33457 +++ b/arch/x86/oprofile/backtrace.c
33458 @@ -46,11 +46,11 @@ dump_user_backtrace_32(struct stack_frame_ia32 *head)
33459 struct stack_frame_ia32 *fp;
33460 unsigned long bytes;
33461
33462 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33463 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33464 if (bytes != 0)
33465 return NULL;
33466
33467 - fp = (struct stack_frame_ia32 *) compat_ptr(bufhead[0].next_frame);
33468 + fp = (struct stack_frame_ia32 __force_kernel *) compat_ptr(bufhead[0].next_frame);
33469
33470 oprofile_add_trace(bufhead[0].return_address);
33471
33472 @@ -92,7 +92,7 @@ static struct stack_frame *dump_user_backtrace(struct stack_frame *head)
33473 struct stack_frame bufhead[2];
33474 unsigned long bytes;
33475
33476 - bytes = copy_from_user_nmi(bufhead, head, sizeof(bufhead));
33477 + bytes = copy_from_user_nmi(bufhead, (const char __force_user *)head, sizeof(bufhead));
33478 if (bytes != 0)
33479 return NULL;
33480
33481 @@ -111,7 +111,7 @@ x86_backtrace(struct pt_regs * const regs, unsigned int depth)
33482 {
33483 struct stack_frame *head = (struct stack_frame *)frame_pointer(regs);
33484
33485 - if (!user_mode_vm(regs)) {
33486 + if (!user_mode(regs)) {
33487 unsigned long stack = kernel_stack_pointer(regs);
33488 if (depth)
33489 dump_trace(NULL, regs, (unsigned long *)stack, 0,
33490 diff --git a/arch/x86/oprofile/nmi_int.c b/arch/x86/oprofile/nmi_int.c
33491 index 6890d84..1dad1f1 100644
33492 --- a/arch/x86/oprofile/nmi_int.c
33493 +++ b/arch/x86/oprofile/nmi_int.c
33494 @@ -23,6 +23,7 @@
33495 #include <asm/nmi.h>
33496 #include <asm/msr.h>
33497 #include <asm/apic.h>
33498 +#include <asm/pgtable.h>
33499
33500 #include "op_counter.h"
33501 #include "op_x86_model.h"
33502 @@ -774,8 +775,11 @@ int __init op_nmi_init(struct oprofile_operations *ops)
33503 if (ret)
33504 return ret;
33505
33506 - if (!model->num_virt_counters)
33507 - model->num_virt_counters = model->num_counters;
33508 + if (!model->num_virt_counters) {
33509 + pax_open_kernel();
33510 + *(unsigned int *)&model->num_virt_counters = model->num_counters;
33511 + pax_close_kernel();
33512 + }
33513
33514 mux_init(ops);
33515
33516 diff --git a/arch/x86/oprofile/op_model_amd.c b/arch/x86/oprofile/op_model_amd.c
33517 index 50d86c0..7985318 100644
33518 --- a/arch/x86/oprofile/op_model_amd.c
33519 +++ b/arch/x86/oprofile/op_model_amd.c
33520 @@ -519,9 +519,11 @@ static int op_amd_init(struct oprofile_operations *ops)
33521 num_counters = AMD64_NUM_COUNTERS;
33522 }
33523
33524 - op_amd_spec.num_counters = num_counters;
33525 - op_amd_spec.num_controls = num_counters;
33526 - op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
33527 + pax_open_kernel();
33528 + *(unsigned int *)&op_amd_spec.num_counters = num_counters;
33529 + *(unsigned int *)&op_amd_spec.num_controls = num_counters;
33530 + *(unsigned int *)&op_amd_spec.num_virt_counters = max(num_counters, NUM_VIRT_COUNTERS);
33531 + pax_close_kernel();
33532
33533 return 0;
33534 }
33535 diff --git a/arch/x86/oprofile/op_model_ppro.c b/arch/x86/oprofile/op_model_ppro.c
33536 index d90528e..0127e2b 100644
33537 --- a/arch/x86/oprofile/op_model_ppro.c
33538 +++ b/arch/x86/oprofile/op_model_ppro.c
33539 @@ -19,6 +19,7 @@
33540 #include <asm/msr.h>
33541 #include <asm/apic.h>
33542 #include <asm/nmi.h>
33543 +#include <asm/pgtable.h>
33544
33545 #include "op_x86_model.h"
33546 #include "op_counter.h"
33547 @@ -221,8 +222,10 @@ static void arch_perfmon_setup_counters(void)
33548
33549 num_counters = min((int)eax.split.num_counters, OP_MAX_COUNTER);
33550
33551 - op_arch_perfmon_spec.num_counters = num_counters;
33552 - op_arch_perfmon_spec.num_controls = num_counters;
33553 + pax_open_kernel();
33554 + *(unsigned int *)&op_arch_perfmon_spec.num_counters = num_counters;
33555 + *(unsigned int *)&op_arch_perfmon_spec.num_controls = num_counters;
33556 + pax_close_kernel();
33557 }
33558
33559 static int arch_perfmon_init(struct oprofile_operations *ignore)
33560 diff --git a/arch/x86/oprofile/op_x86_model.h b/arch/x86/oprofile/op_x86_model.h
33561 index 71e8a67..6a313bb 100644
33562 --- a/arch/x86/oprofile/op_x86_model.h
33563 +++ b/arch/x86/oprofile/op_x86_model.h
33564 @@ -52,7 +52,7 @@ struct op_x86_model_spec {
33565 void (*switch_ctrl)(struct op_x86_model_spec const *model,
33566 struct op_msrs const * const msrs);
33567 #endif
33568 -};
33569 +} __do_const;
33570
33571 struct op_counter_config;
33572
33573 diff --git a/arch/x86/pci/intel_mid_pci.c b/arch/x86/pci/intel_mid_pci.c
33574 index 51384ca..a25f51e 100644
33575 --- a/arch/x86/pci/intel_mid_pci.c
33576 +++ b/arch/x86/pci/intel_mid_pci.c
33577 @@ -241,7 +241,7 @@ int __init intel_mid_pci_init(void)
33578 pr_info("Intel MID platform detected, using MID PCI ops\n");
33579 pci_mmcfg_late_init();
33580 pcibios_enable_irq = intel_mid_pci_irq_enable;
33581 - pci_root_ops = intel_mid_pci_ops;
33582 + memcpy((void *)&pci_root_ops, &intel_mid_pci_ops, sizeof pci_root_ops);
33583 pci_soc_mode = 1;
33584 /* Continue with standard init */
33585 return 1;
33586 diff --git a/arch/x86/pci/irq.c b/arch/x86/pci/irq.c
33587 index 372e9b8..e775a6c 100644
33588 --- a/arch/x86/pci/irq.c
33589 +++ b/arch/x86/pci/irq.c
33590 @@ -50,7 +50,7 @@ struct irq_router {
33591 struct irq_router_handler {
33592 u16 vendor;
33593 int (*probe)(struct irq_router *r, struct pci_dev *router, u16 device);
33594 -};
33595 +} __do_const;
33596
33597 int (*pcibios_enable_irq)(struct pci_dev *dev) = pirq_enable_irq;
33598 void (*pcibios_disable_irq)(struct pci_dev *dev) = NULL;
33599 @@ -794,7 +794,7 @@ static __init int pico_router_probe(struct irq_router *r, struct pci_dev *router
33600 return 0;
33601 }
33602
33603 -static __initdata struct irq_router_handler pirq_routers[] = {
33604 +static __initconst const struct irq_router_handler pirq_routers[] = {
33605 { PCI_VENDOR_ID_INTEL, intel_router_probe },
33606 { PCI_VENDOR_ID_AL, ali_router_probe },
33607 { PCI_VENDOR_ID_ITE, ite_router_probe },
33608 @@ -821,7 +821,7 @@ static struct pci_dev *pirq_router_dev;
33609 static void __init pirq_find_router(struct irq_router *r)
33610 {
33611 struct irq_routing_table *rt = pirq_table;
33612 - struct irq_router_handler *h;
33613 + const struct irq_router_handler *h;
33614
33615 #ifdef CONFIG_PCI_BIOS
33616 if (!rt->signature) {
33617 @@ -1094,7 +1094,7 @@ static int __init fix_acer_tm360_irqrouting(const struct dmi_system_id *d)
33618 return 0;
33619 }
33620
33621 -static struct dmi_system_id __initdata pciirq_dmi_table[] = {
33622 +static const struct dmi_system_id __initconst pciirq_dmi_table[] = {
33623 {
33624 .callback = fix_broken_hp_bios_irq9,
33625 .ident = "HP Pavilion N5400 Series Laptop",
33626 diff --git a/arch/x86/pci/pcbios.c b/arch/x86/pci/pcbios.c
33627 index c77b24a..c979855 100644
33628 --- a/arch/x86/pci/pcbios.c
33629 +++ b/arch/x86/pci/pcbios.c
33630 @@ -79,7 +79,7 @@ union bios32 {
33631 static struct {
33632 unsigned long address;
33633 unsigned short segment;
33634 -} bios32_indirect = { 0, __KERNEL_CS };
33635 +} bios32_indirect __read_only = { 0, __PCIBIOS_CS };
33636
33637 /*
33638 * Returns the entry point for the given service, NULL on error
33639 @@ -92,37 +92,80 @@ static unsigned long bios32_service(unsigned long service)
33640 unsigned long length; /* %ecx */
33641 unsigned long entry; /* %edx */
33642 unsigned long flags;
33643 + struct desc_struct d, *gdt;
33644
33645 local_irq_save(flags);
33646 - __asm__("lcall *(%%edi); cld"
33647 +
33648 + gdt = get_cpu_gdt_table(smp_processor_id());
33649 +
33650 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x9B, 0xC);
33651 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
33652 + pack_descriptor(&d, 0UL, 0xFFFFFUL, 0x93, 0xC);
33653 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
33654 +
33655 + __asm__("movw %w7, %%ds; lcall *(%%edi); push %%ss; pop %%ds; cld"
33656 : "=a" (return_code),
33657 "=b" (address),
33658 "=c" (length),
33659 "=d" (entry)
33660 : "0" (service),
33661 "1" (0),
33662 - "D" (&bios32_indirect));
33663 + "D" (&bios32_indirect),
33664 + "r"(__PCIBIOS_DS)
33665 + : "memory");
33666 +
33667 + pax_open_kernel();
33668 + gdt[GDT_ENTRY_PCIBIOS_CS].a = 0;
33669 + gdt[GDT_ENTRY_PCIBIOS_CS].b = 0;
33670 + gdt[GDT_ENTRY_PCIBIOS_DS].a = 0;
33671 + gdt[GDT_ENTRY_PCIBIOS_DS].b = 0;
33672 + pax_close_kernel();
33673 +
33674 local_irq_restore(flags);
33675
33676 switch (return_code) {
33677 - case 0:
33678 - return address + entry;
33679 - case 0x80: /* Not present */
33680 - printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
33681 - return 0;
33682 - default: /* Shouldn't happen */
33683 - printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
33684 - service, return_code);
33685 + case 0: {
33686 + int cpu;
33687 + unsigned char flags;
33688 +
33689 + printk(KERN_INFO "bios32_service: base:%08lx length:%08lx entry:%08lx\n", address, length, entry);
33690 + if (address >= 0xFFFF0 || length > 0x100000 - address || length <= entry) {
33691 + printk(KERN_WARNING "bios32_service: not valid\n");
33692 return 0;
33693 + }
33694 + address = address + PAGE_OFFSET;
33695 + length += 16UL; /* some BIOSs underreport this... */
33696 + flags = 4;
33697 + if (length >= 64*1024*1024) {
33698 + length >>= PAGE_SHIFT;
33699 + flags |= 8;
33700 + }
33701 +
33702 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
33703 + gdt = get_cpu_gdt_table(cpu);
33704 + pack_descriptor(&d, address, length, 0x9b, flags);
33705 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_CS, &d, DESCTYPE_S);
33706 + pack_descriptor(&d, address, length, 0x93, flags);
33707 + write_gdt_entry(gdt, GDT_ENTRY_PCIBIOS_DS, &d, DESCTYPE_S);
33708 + }
33709 + return entry;
33710 + }
33711 + case 0x80: /* Not present */
33712 + printk(KERN_WARNING "bios32_service(0x%lx): not present\n", service);
33713 + return 0;
33714 + default: /* Shouldn't happen */
33715 + printk(KERN_WARNING "bios32_service(0x%lx): returned 0x%x -- BIOS bug!\n",
33716 + service, return_code);
33717 + return 0;
33718 }
33719 }
33720
33721 static struct {
33722 unsigned long address;
33723 unsigned short segment;
33724 -} pci_indirect = { 0, __KERNEL_CS };
33725 +} pci_indirect __read_only = { 0, __PCIBIOS_CS };
33726
33727 -static int pci_bios_present;
33728 +static int pci_bios_present __read_only;
33729
33730 static int check_pcibios(void)
33731 {
33732 @@ -131,11 +174,13 @@ static int check_pcibios(void)
33733 unsigned long flags, pcibios_entry;
33734
33735 if ((pcibios_entry = bios32_service(PCI_SERVICE))) {
33736 - pci_indirect.address = pcibios_entry + PAGE_OFFSET;
33737 + pci_indirect.address = pcibios_entry;
33738
33739 local_irq_save(flags);
33740 - __asm__(
33741 - "lcall *(%%edi); cld\n\t"
33742 + __asm__("movw %w6, %%ds\n\t"
33743 + "lcall *%%ss:(%%edi); cld\n\t"
33744 + "push %%ss\n\t"
33745 + "pop %%ds\n\t"
33746 "jc 1f\n\t"
33747 "xor %%ah, %%ah\n"
33748 "1:"
33749 @@ -144,7 +189,8 @@ static int check_pcibios(void)
33750 "=b" (ebx),
33751 "=c" (ecx)
33752 : "1" (PCIBIOS_PCI_BIOS_PRESENT),
33753 - "D" (&pci_indirect)
33754 + "D" (&pci_indirect),
33755 + "r" (__PCIBIOS_DS)
33756 : "memory");
33757 local_irq_restore(flags);
33758
33759 @@ -189,7 +235,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33760
33761 switch (len) {
33762 case 1:
33763 - __asm__("lcall *(%%esi); cld\n\t"
33764 + __asm__("movw %w6, %%ds\n\t"
33765 + "lcall *%%ss:(%%esi); cld\n\t"
33766 + "push %%ss\n\t"
33767 + "pop %%ds\n\t"
33768 "jc 1f\n\t"
33769 "xor %%ah, %%ah\n"
33770 "1:"
33771 @@ -198,7 +247,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33772 : "1" (PCIBIOS_READ_CONFIG_BYTE),
33773 "b" (bx),
33774 "D" ((long)reg),
33775 - "S" (&pci_indirect));
33776 + "S" (&pci_indirect),
33777 + "r" (__PCIBIOS_DS));
33778 /*
33779 * Zero-extend the result beyond 8 bits, do not trust the
33780 * BIOS having done it:
33781 @@ -206,7 +256,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33782 *value &= 0xff;
33783 break;
33784 case 2:
33785 - __asm__("lcall *(%%esi); cld\n\t"
33786 + __asm__("movw %w6, %%ds\n\t"
33787 + "lcall *%%ss:(%%esi); cld\n\t"
33788 + "push %%ss\n\t"
33789 + "pop %%ds\n\t"
33790 "jc 1f\n\t"
33791 "xor %%ah, %%ah\n"
33792 "1:"
33793 @@ -215,7 +268,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33794 : "1" (PCIBIOS_READ_CONFIG_WORD),
33795 "b" (bx),
33796 "D" ((long)reg),
33797 - "S" (&pci_indirect));
33798 + "S" (&pci_indirect),
33799 + "r" (__PCIBIOS_DS));
33800 /*
33801 * Zero-extend the result beyond 16 bits, do not trust the
33802 * BIOS having done it:
33803 @@ -223,7 +277,10 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33804 *value &= 0xffff;
33805 break;
33806 case 4:
33807 - __asm__("lcall *(%%esi); cld\n\t"
33808 + __asm__("movw %w6, %%ds\n\t"
33809 + "lcall *%%ss:(%%esi); cld\n\t"
33810 + "push %%ss\n\t"
33811 + "pop %%ds\n\t"
33812 "jc 1f\n\t"
33813 "xor %%ah, %%ah\n"
33814 "1:"
33815 @@ -232,7 +289,8 @@ static int pci_bios_read(unsigned int seg, unsigned int bus,
33816 : "1" (PCIBIOS_READ_CONFIG_DWORD),
33817 "b" (bx),
33818 "D" ((long)reg),
33819 - "S" (&pci_indirect));
33820 + "S" (&pci_indirect),
33821 + "r" (__PCIBIOS_DS));
33822 break;
33823 }
33824
33825 @@ -256,7 +314,10 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33826
33827 switch (len) {
33828 case 1:
33829 - __asm__("lcall *(%%esi); cld\n\t"
33830 + __asm__("movw %w6, %%ds\n\t"
33831 + "lcall *%%ss:(%%esi); cld\n\t"
33832 + "push %%ss\n\t"
33833 + "pop %%ds\n\t"
33834 "jc 1f\n\t"
33835 "xor %%ah, %%ah\n"
33836 "1:"
33837 @@ -265,10 +326,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33838 "c" (value),
33839 "b" (bx),
33840 "D" ((long)reg),
33841 - "S" (&pci_indirect));
33842 + "S" (&pci_indirect),
33843 + "r" (__PCIBIOS_DS));
33844 break;
33845 case 2:
33846 - __asm__("lcall *(%%esi); cld\n\t"
33847 + __asm__("movw %w6, %%ds\n\t"
33848 + "lcall *%%ss:(%%esi); cld\n\t"
33849 + "push %%ss\n\t"
33850 + "pop %%ds\n\t"
33851 "jc 1f\n\t"
33852 "xor %%ah, %%ah\n"
33853 "1:"
33854 @@ -277,10 +342,14 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33855 "c" (value),
33856 "b" (bx),
33857 "D" ((long)reg),
33858 - "S" (&pci_indirect));
33859 + "S" (&pci_indirect),
33860 + "r" (__PCIBIOS_DS));
33861 break;
33862 case 4:
33863 - __asm__("lcall *(%%esi); cld\n\t"
33864 + __asm__("movw %w6, %%ds\n\t"
33865 + "lcall *%%ss:(%%esi); cld\n\t"
33866 + "push %%ss\n\t"
33867 + "pop %%ds\n\t"
33868 "jc 1f\n\t"
33869 "xor %%ah, %%ah\n"
33870 "1:"
33871 @@ -289,7 +358,8 @@ static int pci_bios_write(unsigned int seg, unsigned int bus,
33872 "c" (value),
33873 "b" (bx),
33874 "D" ((long)reg),
33875 - "S" (&pci_indirect));
33876 + "S" (&pci_indirect),
33877 + "r" (__PCIBIOS_DS));
33878 break;
33879 }
33880
33881 @@ -394,10 +464,13 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33882
33883 DBG("PCI: Fetching IRQ routing table... ");
33884 __asm__("push %%es\n\t"
33885 + "movw %w8, %%ds\n\t"
33886 "push %%ds\n\t"
33887 "pop %%es\n\t"
33888 - "lcall *(%%esi); cld\n\t"
33889 + "lcall *%%ss:(%%esi); cld\n\t"
33890 "pop %%es\n\t"
33891 + "push %%ss\n\t"
33892 + "pop %%ds\n"
33893 "jc 1f\n\t"
33894 "xor %%ah, %%ah\n"
33895 "1:"
33896 @@ -408,7 +481,8 @@ struct irq_routing_table * pcibios_get_irq_routing_table(void)
33897 "1" (0),
33898 "D" ((long) &opt),
33899 "S" (&pci_indirect),
33900 - "m" (opt)
33901 + "m" (opt),
33902 + "r" (__PCIBIOS_DS)
33903 : "memory");
33904 DBG("OK ret=%d, size=%d, map=%x\n", ret, opt.size, map);
33905 if (ret & 0xff00)
33906 @@ -432,7 +506,10 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33907 {
33908 int ret;
33909
33910 - __asm__("lcall *(%%esi); cld\n\t"
33911 + __asm__("movw %w5, %%ds\n\t"
33912 + "lcall *%%ss:(%%esi); cld\n\t"
33913 + "push %%ss\n\t"
33914 + "pop %%ds\n"
33915 "jc 1f\n\t"
33916 "xor %%ah, %%ah\n"
33917 "1:"
33918 @@ -440,7 +517,8 @@ int pcibios_set_irq_routing(struct pci_dev *dev, int pin, int irq)
33919 : "0" (PCIBIOS_SET_PCI_HW_INT),
33920 "b" ((dev->bus->number << 8) | dev->devfn),
33921 "c" ((irq << 8) | (pin + 10)),
33922 - "S" (&pci_indirect));
33923 + "S" (&pci_indirect),
33924 + "r" (__PCIBIOS_DS));
33925 return !(ret & 0xff00);
33926 }
33927 EXPORT_SYMBOL(pcibios_set_irq_routing);
33928 diff --git a/arch/x86/platform/efi/efi_32.c b/arch/x86/platform/efi/efi_32.c
33929 index 40e4469..d915bf9 100644
33930 --- a/arch/x86/platform/efi/efi_32.c
33931 +++ b/arch/x86/platform/efi/efi_32.c
33932 @@ -44,11 +44,22 @@ void efi_call_phys_prelog(void)
33933 {
33934 struct desc_ptr gdt_descr;
33935
33936 +#ifdef CONFIG_PAX_KERNEXEC
33937 + struct desc_struct d;
33938 +#endif
33939 +
33940 local_irq_save(efi_rt_eflags);
33941
33942 load_cr3(initial_page_table);
33943 __flush_tlb_all();
33944
33945 +#ifdef CONFIG_PAX_KERNEXEC
33946 + pack_descriptor(&d, 0, 0xFFFFF, 0x9B, 0xC);
33947 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33948 + pack_descriptor(&d, 0, 0xFFFFF, 0x93, 0xC);
33949 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33950 +#endif
33951 +
33952 gdt_descr.address = __pa(get_cpu_gdt_table(0));
33953 gdt_descr.size = GDT_SIZE - 1;
33954 load_gdt(&gdt_descr);
33955 @@ -58,11 +69,24 @@ void efi_call_phys_epilog(void)
33956 {
33957 struct desc_ptr gdt_descr;
33958
33959 +#ifdef CONFIG_PAX_KERNEXEC
33960 + struct desc_struct d;
33961 +
33962 + memset(&d, 0, sizeof d);
33963 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_CS, &d, DESCTYPE_S);
33964 + write_gdt_entry(get_cpu_gdt_table(0), GDT_ENTRY_KERNEXEC_EFI_DS, &d, DESCTYPE_S);
33965 +#endif
33966 +
33967 gdt_descr.address = (unsigned long)get_cpu_gdt_table(0);
33968 gdt_descr.size = GDT_SIZE - 1;
33969 load_gdt(&gdt_descr);
33970
33971 +#ifdef CONFIG_PAX_PER_CPU_PGD
33972 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
33973 +#else
33974 load_cr3(swapper_pg_dir);
33975 +#endif
33976 +
33977 __flush_tlb_all();
33978
33979 local_irq_restore(efi_rt_eflags);
33980 diff --git a/arch/x86/platform/efi/efi_64.c b/arch/x86/platform/efi/efi_64.c
33981 index 39a0e7f1..872396e 100644
33982 --- a/arch/x86/platform/efi/efi_64.c
33983 +++ b/arch/x86/platform/efi/efi_64.c
33984 @@ -76,6 +76,11 @@ void __init efi_call_phys_prelog(void)
33985 vaddress = (unsigned long)__va(pgd * PGDIR_SIZE);
33986 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), *pgd_offset_k(vaddress));
33987 }
33988 +
33989 +#ifdef CONFIG_PAX_PER_CPU_PGD
33990 + load_cr3(swapper_pg_dir);
33991 +#endif
33992 +
33993 __flush_tlb_all();
33994 }
33995
33996 @@ -89,6 +94,11 @@ void __init efi_call_phys_epilog(void)
33997 for (pgd = 0; pgd < n_pgds; pgd++)
33998 set_pgd(pgd_offset_k(pgd * PGDIR_SIZE), save_pgd[pgd]);
33999 kfree(save_pgd);
34000 +
34001 +#ifdef CONFIG_PAX_PER_CPU_PGD
34002 + load_cr3(get_cpu_pgd(smp_processor_id(), kernel));
34003 +#endif
34004 +
34005 __flush_tlb_all();
34006 local_irq_restore(efi_flags);
34007 early_code_mapping_set_exec(0);
34008 diff --git a/arch/x86/platform/efi/efi_stub_32.S b/arch/x86/platform/efi/efi_stub_32.S
34009 index fbe66e6..eae5e38 100644
34010 --- a/arch/x86/platform/efi/efi_stub_32.S
34011 +++ b/arch/x86/platform/efi/efi_stub_32.S
34012 @@ -6,7 +6,9 @@
34013 */
34014
34015 #include <linux/linkage.h>
34016 +#include <linux/init.h>
34017 #include <asm/page_types.h>
34018 +#include <asm/segment.h>
34019
34020 /*
34021 * efi_call_phys(void *, ...) is a function with variable parameters.
34022 @@ -20,7 +22,7 @@
34023 * service functions will comply with gcc calling convention, too.
34024 */
34025
34026 -.text
34027 +__INIT
34028 ENTRY(efi_call_phys)
34029 /*
34030 * 0. The function can only be called in Linux kernel. So CS has been
34031 @@ -36,10 +38,24 @@ ENTRY(efi_call_phys)
34032 * The mapping of lower virtual memory has been created in prelog and
34033 * epilog.
34034 */
34035 - movl $1f, %edx
34036 - subl $__PAGE_OFFSET, %edx
34037 - jmp *%edx
34038 +#ifdef CONFIG_PAX_KERNEXEC
34039 + movl $(__KERNEXEC_EFI_DS), %edx
34040 + mov %edx, %ds
34041 + mov %edx, %es
34042 + mov %edx, %ss
34043 + addl $2f,(1f)
34044 + ljmp *(1f)
34045 +
34046 +__INITDATA
34047 +1: .long __LOAD_PHYSICAL_ADDR, __KERNEXEC_EFI_CS
34048 +.previous
34049 +
34050 +2:
34051 + subl $2b,(1b)
34052 +#else
34053 + jmp 1f-__PAGE_OFFSET
34054 1:
34055 +#endif
34056
34057 /*
34058 * 2. Now on the top of stack is the return
34059 @@ -47,14 +63,8 @@ ENTRY(efi_call_phys)
34060 * parameter 2, ..., param n. To make things easy, we save the return
34061 * address of efi_call_phys in a global variable.
34062 */
34063 - popl %edx
34064 - movl %edx, saved_return_addr
34065 - /* get the function pointer into ECX*/
34066 - popl %ecx
34067 - movl %ecx, efi_rt_function_ptr
34068 - movl $2f, %edx
34069 - subl $__PAGE_OFFSET, %edx
34070 - pushl %edx
34071 + popl (saved_return_addr)
34072 + popl (efi_rt_function_ptr)
34073
34074 /*
34075 * 3. Clear PG bit in %CR0.
34076 @@ -73,9 +83,8 @@ ENTRY(efi_call_phys)
34077 /*
34078 * 5. Call the physical function.
34079 */
34080 - jmp *%ecx
34081 + call *(efi_rt_function_ptr-__PAGE_OFFSET)
34082
34083 -2:
34084 /*
34085 * 6. After EFI runtime service returns, control will return to
34086 * following instruction. We'd better readjust stack pointer first.
34087 @@ -88,35 +97,36 @@ ENTRY(efi_call_phys)
34088 movl %cr0, %edx
34089 orl $0x80000000, %edx
34090 movl %edx, %cr0
34091 - jmp 1f
34092 -1:
34093 +
34094 /*
34095 * 8. Now restore the virtual mode from flat mode by
34096 * adding EIP with PAGE_OFFSET.
34097 */
34098 - movl $1f, %edx
34099 - jmp *%edx
34100 +#ifdef CONFIG_PAX_KERNEXEC
34101 + movl $(__KERNEL_DS), %edx
34102 + mov %edx, %ds
34103 + mov %edx, %es
34104 + mov %edx, %ss
34105 + ljmp $(__KERNEL_CS),$1f
34106 +#else
34107 + jmp 1f+__PAGE_OFFSET
34108 +#endif
34109 1:
34110
34111 /*
34112 * 9. Balance the stack. And because EAX contain the return value,
34113 * we'd better not clobber it.
34114 */
34115 - leal efi_rt_function_ptr, %edx
34116 - movl (%edx), %ecx
34117 - pushl %ecx
34118 + pushl (efi_rt_function_ptr)
34119
34120 /*
34121 - * 10. Push the saved return address onto the stack and return.
34122 + * 10. Return to the saved return address.
34123 */
34124 - leal saved_return_addr, %edx
34125 - movl (%edx), %ecx
34126 - pushl %ecx
34127 - ret
34128 + jmpl *(saved_return_addr)
34129 ENDPROC(efi_call_phys)
34130 .previous
34131
34132 -.data
34133 +__INITDATA
34134 saved_return_addr:
34135 .long 0
34136 efi_rt_function_ptr:
34137 diff --git a/arch/x86/platform/efi/efi_stub_64.S b/arch/x86/platform/efi/efi_stub_64.S
34138 index 4c07cca..2c8427d 100644
34139 --- a/arch/x86/platform/efi/efi_stub_64.S
34140 +++ b/arch/x86/platform/efi/efi_stub_64.S
34141 @@ -7,6 +7,7 @@
34142 */
34143
34144 #include <linux/linkage.h>
34145 +#include <asm/alternative-asm.h>
34146
34147 #define SAVE_XMM \
34148 mov %rsp, %rax; \
34149 @@ -40,6 +41,7 @@ ENTRY(efi_call0)
34150 call *%rdi
34151 addq $32, %rsp
34152 RESTORE_XMM
34153 + pax_force_retaddr 0, 1
34154 ret
34155 ENDPROC(efi_call0)
34156
34157 @@ -50,6 +52,7 @@ ENTRY(efi_call1)
34158 call *%rdi
34159 addq $32, %rsp
34160 RESTORE_XMM
34161 + pax_force_retaddr 0, 1
34162 ret
34163 ENDPROC(efi_call1)
34164
34165 @@ -60,6 +63,7 @@ ENTRY(efi_call2)
34166 call *%rdi
34167 addq $32, %rsp
34168 RESTORE_XMM
34169 + pax_force_retaddr 0, 1
34170 ret
34171 ENDPROC(efi_call2)
34172
34173 @@ -71,6 +75,7 @@ ENTRY(efi_call3)
34174 call *%rdi
34175 addq $32, %rsp
34176 RESTORE_XMM
34177 + pax_force_retaddr 0, 1
34178 ret
34179 ENDPROC(efi_call3)
34180
34181 @@ -83,6 +88,7 @@ ENTRY(efi_call4)
34182 call *%rdi
34183 addq $32, %rsp
34184 RESTORE_XMM
34185 + pax_force_retaddr 0, 1
34186 ret
34187 ENDPROC(efi_call4)
34188
34189 @@ -96,6 +102,7 @@ ENTRY(efi_call5)
34190 call *%rdi
34191 addq $48, %rsp
34192 RESTORE_XMM
34193 + pax_force_retaddr 0, 1
34194 ret
34195 ENDPROC(efi_call5)
34196
34197 @@ -112,5 +119,6 @@ ENTRY(efi_call6)
34198 call *%rdi
34199 addq $48, %rsp
34200 RESTORE_XMM
34201 + pax_force_retaddr 0, 1
34202 ret
34203 ENDPROC(efi_call6)
34204 diff --git a/arch/x86/platform/intel-mid/intel-mid.c b/arch/x86/platform/intel-mid/intel-mid.c
34205 index f90e290..435f0dd 100644
34206 --- a/arch/x86/platform/intel-mid/intel-mid.c
34207 +++ b/arch/x86/platform/intel-mid/intel-mid.c
34208 @@ -65,9 +65,10 @@ static void intel_mid_power_off(void)
34209 {
34210 }
34211
34212 -static void intel_mid_reboot(void)
34213 +static void __noreturn intel_mid_reboot(void)
34214 {
34215 intel_scu_ipc_simple_command(IPCMSG_COLD_BOOT, 0);
34216 + BUG();
34217 }
34218
34219 static unsigned long __init intel_mid_calibrate_tsc(void)
34220 diff --git a/arch/x86/platform/olpc/olpc_dt.c b/arch/x86/platform/olpc/olpc_dt.c
34221 index d6ee929..3637cb5 100644
34222 --- a/arch/x86/platform/olpc/olpc_dt.c
34223 +++ b/arch/x86/platform/olpc/olpc_dt.c
34224 @@ -156,7 +156,7 @@ void * __init prom_early_alloc(unsigned long size)
34225 return res;
34226 }
34227
34228 -static struct of_pdt_ops prom_olpc_ops __initdata = {
34229 +static struct of_pdt_ops prom_olpc_ops __initconst = {
34230 .nextprop = olpc_dt_nextprop,
34231 .getproplen = olpc_dt_getproplen,
34232 .getproperty = olpc_dt_getproperty,
34233 diff --git a/arch/x86/power/cpu.c b/arch/x86/power/cpu.c
34234 index 424f4c9..f2a2988 100644
34235 --- a/arch/x86/power/cpu.c
34236 +++ b/arch/x86/power/cpu.c
34237 @@ -137,11 +137,8 @@ static void do_fpu_end(void)
34238 static void fix_processor_context(void)
34239 {
34240 int cpu = smp_processor_id();
34241 - struct tss_struct *t = &per_cpu(init_tss, cpu);
34242 -#ifdef CONFIG_X86_64
34243 - struct desc_struct *desc = get_cpu_gdt_table(cpu);
34244 - tss_desc tss;
34245 -#endif
34246 + struct tss_struct *t = init_tss + cpu;
34247 +
34248 set_tss_desc(cpu, t); /*
34249 * This just modifies memory; should not be
34250 * necessary. But... This is necessary, because
34251 @@ -150,10 +147,6 @@ static void fix_processor_context(void)
34252 */
34253
34254 #ifdef CONFIG_X86_64
34255 - memcpy(&tss, &desc[GDT_ENTRY_TSS], sizeof(tss_desc));
34256 - tss.type = 0x9; /* The available 64-bit TSS (see AMD vol 2, pg 91 */
34257 - write_gdt_entry(desc, GDT_ENTRY_TSS, &tss, DESC_TSS);
34258 -
34259 syscall_init(); /* This sets MSR_*STAR and related */
34260 #endif
34261 load_TR_desc(); /* This does ltr */
34262 diff --git a/arch/x86/realmode/init.c b/arch/x86/realmode/init.c
34263 index a44f457..9140171 100644
34264 --- a/arch/x86/realmode/init.c
34265 +++ b/arch/x86/realmode/init.c
34266 @@ -70,7 +70,13 @@ void __init setup_real_mode(void)
34267 __va(real_mode_header->trampoline_header);
34268
34269 #ifdef CONFIG_X86_32
34270 - trampoline_header->start = __pa_symbol(startup_32_smp);
34271 + trampoline_header->start = __pa_symbol(ktla_ktva(startup_32_smp));
34272 +
34273 +#ifdef CONFIG_PAX_KERNEXEC
34274 + trampoline_header->start -= LOAD_PHYSICAL_ADDR;
34275 +#endif
34276 +
34277 + trampoline_header->boot_cs = __BOOT_CS;
34278 trampoline_header->gdt_limit = __BOOT_DS + 7;
34279 trampoline_header->gdt_base = __pa_symbol(boot_gdt);
34280 #else
34281 @@ -86,7 +92,7 @@ void __init setup_real_mode(void)
34282 *trampoline_cr4_features = read_cr4();
34283
34284 trampoline_pgd = (u64 *) __va(real_mode_header->trampoline_pgd);
34285 - trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd;
34286 + trampoline_pgd[0] = init_level4_pgt[pgd_index(__PAGE_OFFSET)].pgd & ~_PAGE_NX;
34287 trampoline_pgd[511] = init_level4_pgt[511].pgd;
34288 #endif
34289 }
34290 diff --git a/arch/x86/realmode/rm/Makefile b/arch/x86/realmode/rm/Makefile
34291 index 9cac825..4890b25 100644
34292 --- a/arch/x86/realmode/rm/Makefile
34293 +++ b/arch/x86/realmode/rm/Makefile
34294 @@ -79,5 +79,8 @@ KBUILD_CFLAGS := $(LINUXINCLUDE) -m32 -g -Os -D_SETUP -D__KERNEL__ -D_WAKEUP \
34295 $(call cc-option, -fno-unit-at-a-time)) \
34296 $(call cc-option, -fno-stack-protector) \
34297 $(call cc-option, -mpreferred-stack-boundary=2)
34298 +ifdef CONSTIFY_PLUGIN
34299 +KBUILD_CFLAGS += -fplugin-arg-constify_plugin-no-constify
34300 +endif
34301 KBUILD_AFLAGS := $(KBUILD_CFLAGS) -D__ASSEMBLY__
34302 GCOV_PROFILE := n
34303 diff --git a/arch/x86/realmode/rm/header.S b/arch/x86/realmode/rm/header.S
34304 index a28221d..93c40f1 100644
34305 --- a/arch/x86/realmode/rm/header.S
34306 +++ b/arch/x86/realmode/rm/header.S
34307 @@ -30,7 +30,9 @@ GLOBAL(real_mode_header)
34308 #endif
34309 /* APM/BIOS reboot */
34310 .long pa_machine_real_restart_asm
34311 -#ifdef CONFIG_X86_64
34312 +#ifdef CONFIG_X86_32
34313 + .long __KERNEL_CS
34314 +#else
34315 .long __KERNEL32_CS
34316 #endif
34317 END(real_mode_header)
34318 diff --git a/arch/x86/realmode/rm/trampoline_32.S b/arch/x86/realmode/rm/trampoline_32.S
34319 index c1b2791..f9e31c7 100644
34320 --- a/arch/x86/realmode/rm/trampoline_32.S
34321 +++ b/arch/x86/realmode/rm/trampoline_32.S
34322 @@ -25,6 +25,12 @@
34323 #include <asm/page_types.h>
34324 #include "realmode.h"
34325
34326 +#ifdef CONFIG_PAX_KERNEXEC
34327 +#define ta(X) (X)
34328 +#else
34329 +#define ta(X) (pa_ ## X)
34330 +#endif
34331 +
34332 .text
34333 .code16
34334
34335 @@ -39,8 +45,6 @@ ENTRY(trampoline_start)
34336
34337 cli # We should be safe anyway
34338
34339 - movl tr_start, %eax # where we need to go
34340 -
34341 movl $0xA5A5A5A5, trampoline_status
34342 # write marker for master knows we're running
34343
34344 @@ -56,7 +60,7 @@ ENTRY(trampoline_start)
34345 movw $1, %dx # protected mode (PE) bit
34346 lmsw %dx # into protected mode
34347
34348 - ljmpl $__BOOT_CS, $pa_startup_32
34349 + ljmpl *(trampoline_header)
34350
34351 .section ".text32","ax"
34352 .code32
34353 @@ -67,7 +71,7 @@ ENTRY(startup_32) # note: also used from wakeup_asm.S
34354 .balign 8
34355 GLOBAL(trampoline_header)
34356 tr_start: .space 4
34357 - tr_gdt_pad: .space 2
34358 + tr_boot_cs: .space 2
34359 tr_gdt: .space 6
34360 END(trampoline_header)
34361
34362 diff --git a/arch/x86/realmode/rm/trampoline_64.S b/arch/x86/realmode/rm/trampoline_64.S
34363 index bb360dc..d0fd8f8 100644
34364 --- a/arch/x86/realmode/rm/trampoline_64.S
34365 +++ b/arch/x86/realmode/rm/trampoline_64.S
34366 @@ -94,6 +94,7 @@ ENTRY(startup_32)
34367 movl %edx, %gs
34368
34369 movl pa_tr_cr4, %eax
34370 + andl $~X86_CR4_PCIDE, %eax
34371 movl %eax, %cr4 # Enable PAE mode
34372
34373 # Setup trampoline 4 level pagetables
34374 @@ -107,7 +108,7 @@ ENTRY(startup_32)
34375 wrmsr
34376
34377 # Enable paging and in turn activate Long Mode
34378 - movl $(X86_CR0_PG | X86_CR0_WP | X86_CR0_PE), %eax
34379 + movl $(X86_CR0_PG | X86_CR0_PE), %eax
34380 movl %eax, %cr0
34381
34382 /*
34383 diff --git a/arch/x86/tools/Makefile b/arch/x86/tools/Makefile
34384 index e812034..c747134 100644
34385 --- a/arch/x86/tools/Makefile
34386 +++ b/arch/x86/tools/Makefile
34387 @@ -37,7 +37,7 @@ $(obj)/test_get_len.o: $(srctree)/arch/x86/lib/insn.c $(srctree)/arch/x86/lib/in
34388
34389 $(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
34390
34391 -HOST_EXTRACFLAGS += -I$(srctree)/tools/include
34392 +HOST_EXTRACFLAGS += -I$(srctree)/tools/include -ggdb
34393 hostprogs-y += relocs
34394 relocs-objs := relocs_32.o relocs_64.o relocs_common.o
34395 relocs: $(obj)/relocs
34396 diff --git a/arch/x86/tools/relocs.c b/arch/x86/tools/relocs.c
34397 index f7bab68..b6d9886 100644
34398 --- a/arch/x86/tools/relocs.c
34399 +++ b/arch/x86/tools/relocs.c
34400 @@ -1,5 +1,7 @@
34401 /* This is included from relocs_32/64.c */
34402
34403 +#include "../../../include/generated/autoconf.h"
34404 +
34405 #define ElfW(type) _ElfW(ELF_BITS, type)
34406 #define _ElfW(bits, type) __ElfW(bits, type)
34407 #define __ElfW(bits, type) Elf##bits##_##type
34408 @@ -11,6 +13,7 @@
34409 #define Elf_Sym ElfW(Sym)
34410
34411 static Elf_Ehdr ehdr;
34412 +static Elf_Phdr *phdr;
34413
34414 struct relocs {
34415 uint32_t *offset;
34416 @@ -383,9 +386,39 @@ static void read_ehdr(FILE *fp)
34417 }
34418 }
34419
34420 +static void read_phdrs(FILE *fp)
34421 +{
34422 + unsigned int i;
34423 +
34424 + phdr = calloc(ehdr.e_phnum, sizeof(Elf_Phdr));
34425 + if (!phdr) {
34426 + die("Unable to allocate %d program headers\n",
34427 + ehdr.e_phnum);
34428 + }
34429 + if (fseek(fp, ehdr.e_phoff, SEEK_SET) < 0) {
34430 + die("Seek to %d failed: %s\n",
34431 + ehdr.e_phoff, strerror(errno));
34432 + }
34433 + if (fread(phdr, sizeof(*phdr), ehdr.e_phnum, fp) != ehdr.e_phnum) {
34434 + die("Cannot read ELF program headers: %s\n",
34435 + strerror(errno));
34436 + }
34437 + for(i = 0; i < ehdr.e_phnum; i++) {
34438 + phdr[i].p_type = elf_word_to_cpu(phdr[i].p_type);
34439 + phdr[i].p_offset = elf_off_to_cpu(phdr[i].p_offset);
34440 + phdr[i].p_vaddr = elf_addr_to_cpu(phdr[i].p_vaddr);
34441 + phdr[i].p_paddr = elf_addr_to_cpu(phdr[i].p_paddr);
34442 + phdr[i].p_filesz = elf_word_to_cpu(phdr[i].p_filesz);
34443 + phdr[i].p_memsz = elf_word_to_cpu(phdr[i].p_memsz);
34444 + phdr[i].p_flags = elf_word_to_cpu(phdr[i].p_flags);
34445 + phdr[i].p_align = elf_word_to_cpu(phdr[i].p_align);
34446 + }
34447 +
34448 +}
34449 +
34450 static void read_shdrs(FILE *fp)
34451 {
34452 - int i;
34453 + unsigned int i;
34454 Elf_Shdr shdr;
34455
34456 secs = calloc(ehdr.e_shnum, sizeof(struct section));
34457 @@ -420,7 +453,7 @@ static void read_shdrs(FILE *fp)
34458
34459 static void read_strtabs(FILE *fp)
34460 {
34461 - int i;
34462 + unsigned int i;
34463 for (i = 0; i < ehdr.e_shnum; i++) {
34464 struct section *sec = &secs[i];
34465 if (sec->shdr.sh_type != SHT_STRTAB) {
34466 @@ -445,7 +478,7 @@ static void read_strtabs(FILE *fp)
34467
34468 static void read_symtabs(FILE *fp)
34469 {
34470 - int i,j;
34471 + unsigned int i,j;
34472 for (i = 0; i < ehdr.e_shnum; i++) {
34473 struct section *sec = &secs[i];
34474 if (sec->shdr.sh_type != SHT_SYMTAB) {
34475 @@ -476,9 +509,11 @@ static void read_symtabs(FILE *fp)
34476 }
34477
34478
34479 -static void read_relocs(FILE *fp)
34480 +static void read_relocs(FILE *fp, int use_real_mode)
34481 {
34482 - int i,j;
34483 + unsigned int i,j;
34484 + uint32_t base;
34485 +
34486 for (i = 0; i < ehdr.e_shnum; i++) {
34487 struct section *sec = &secs[i];
34488 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34489 @@ -498,9 +533,22 @@ static void read_relocs(FILE *fp)
34490 die("Cannot read symbol table: %s\n",
34491 strerror(errno));
34492 }
34493 + base = 0;
34494 +
34495 +#ifdef CONFIG_X86_32
34496 + for (j = 0; !use_real_mode && j < ehdr.e_phnum; j++) {
34497 + if (phdr[j].p_type != PT_LOAD )
34498 + continue;
34499 + 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)
34500 + continue;
34501 + base = CONFIG_PAGE_OFFSET + phdr[j].p_paddr - phdr[j].p_vaddr;
34502 + break;
34503 + }
34504 +#endif
34505 +
34506 for (j = 0; j < sec->shdr.sh_size/sizeof(Elf_Rel); j++) {
34507 Elf_Rel *rel = &sec->reltab[j];
34508 - rel->r_offset = elf_addr_to_cpu(rel->r_offset);
34509 + rel->r_offset = elf_addr_to_cpu(rel->r_offset) + base;
34510 rel->r_info = elf_xword_to_cpu(rel->r_info);
34511 #if (SHT_REL_TYPE == SHT_RELA)
34512 rel->r_addend = elf_xword_to_cpu(rel->r_addend);
34513 @@ -512,7 +560,7 @@ static void read_relocs(FILE *fp)
34514
34515 static void print_absolute_symbols(void)
34516 {
34517 - int i;
34518 + unsigned int i;
34519 const char *format;
34520
34521 if (ELF_BITS == 64)
34522 @@ -525,7 +573,7 @@ static void print_absolute_symbols(void)
34523 for (i = 0; i < ehdr.e_shnum; i++) {
34524 struct section *sec = &secs[i];
34525 char *sym_strtab;
34526 - int j;
34527 + unsigned int j;
34528
34529 if (sec->shdr.sh_type != SHT_SYMTAB) {
34530 continue;
34531 @@ -552,7 +600,7 @@ static void print_absolute_symbols(void)
34532
34533 static void print_absolute_relocs(void)
34534 {
34535 - int i, printed = 0;
34536 + unsigned int i, printed = 0;
34537 const char *format;
34538
34539 if (ELF_BITS == 64)
34540 @@ -565,7 +613,7 @@ static void print_absolute_relocs(void)
34541 struct section *sec_applies, *sec_symtab;
34542 char *sym_strtab;
34543 Elf_Sym *sh_symtab;
34544 - int j;
34545 + unsigned int j;
34546 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34547 continue;
34548 }
34549 @@ -642,13 +690,13 @@ static void add_reloc(struct relocs *r, uint32_t offset)
34550 static void walk_relocs(int (*process)(struct section *sec, Elf_Rel *rel,
34551 Elf_Sym *sym, const char *symname))
34552 {
34553 - int i;
34554 + unsigned int i;
34555 /* Walk through the relocations */
34556 for (i = 0; i < ehdr.e_shnum; i++) {
34557 char *sym_strtab;
34558 Elf_Sym *sh_symtab;
34559 struct section *sec_applies, *sec_symtab;
34560 - int j;
34561 + unsigned int j;
34562 struct section *sec = &secs[i];
34563
34564 if (sec->shdr.sh_type != SHT_REL_TYPE) {
34565 @@ -812,6 +860,23 @@ static int do_reloc32(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
34566 {
34567 unsigned r_type = ELF32_R_TYPE(rel->r_info);
34568 int shn_abs = (sym->st_shndx == SHN_ABS) && !is_reloc(S_REL, symname);
34569 + char *sym_strtab = sec->link->link->strtab;
34570 +
34571 + /* Don't relocate actual per-cpu variables, they are absolute indices, not addresses */
34572 + if (!strcmp(sec_name(sym->st_shndx), ".data..percpu") && strcmp(sym_name(sym_strtab, sym), "__per_cpu_load"))
34573 + return 0;
34574 +
34575 +#ifdef CONFIG_PAX_KERNEXEC
34576 + /* Don't relocate actual code, they are relocated implicitly by the base address of KERNEL_CS */
34577 + if (!strcmp(sec_name(sym->st_shndx), ".text.end") && !strcmp(sym_name(sym_strtab, sym), "_etext"))
34578 + return 0;
34579 + if (!strcmp(sec_name(sym->st_shndx), ".init.text"))
34580 + return 0;
34581 + if (!strcmp(sec_name(sym->st_shndx), ".exit.text"))
34582 + return 0;
34583 + if (!strcmp(sec_name(sym->st_shndx), ".text") && strcmp(sym_name(sym_strtab, sym), "__LOAD_PHYSICAL_ADDR"))
34584 + return 0;
34585 +#endif
34586
34587 switch (r_type) {
34588 case R_386_NONE:
34589 @@ -950,7 +1015,7 @@ static int write32_as_text(uint32_t v, FILE *f)
34590
34591 static void emit_relocs(int as_text, int use_real_mode)
34592 {
34593 - int i;
34594 + unsigned int i;
34595 int (*write_reloc)(uint32_t, FILE *) = write32;
34596 int (*do_reloc)(struct section *sec, Elf_Rel *rel, Elf_Sym *sym,
34597 const char *symname);
34598 @@ -1026,10 +1091,11 @@ void process(FILE *fp, int use_real_mode, int as_text,
34599 {
34600 regex_init(use_real_mode);
34601 read_ehdr(fp);
34602 + read_phdrs(fp);
34603 read_shdrs(fp);
34604 read_strtabs(fp);
34605 read_symtabs(fp);
34606 - read_relocs(fp);
34607 + read_relocs(fp, use_real_mode);
34608 if (ELF_BITS == 64)
34609 percpu_init();
34610 if (show_absolute_syms) {
34611 diff --git a/arch/x86/um/tls_32.c b/arch/x86/um/tls_32.c
34612 index 80ffa5b..a33bd15 100644
34613 --- a/arch/x86/um/tls_32.c
34614 +++ b/arch/x86/um/tls_32.c
34615 @@ -260,7 +260,7 @@ out:
34616 if (unlikely(task == current &&
34617 !t->arch.tls_array[idx - GDT_ENTRY_TLS_MIN].flushed)) {
34618 printk(KERN_ERR "get_tls_entry: task with pid %d got here "
34619 - "without flushed TLS.", current->pid);
34620 + "without flushed TLS.", task_pid_nr(current));
34621 }
34622
34623 return 0;
34624 diff --git a/arch/x86/vdso/Makefile b/arch/x86/vdso/Makefile
34625 index fd14be1..e3c79c0 100644
34626 --- a/arch/x86/vdso/Makefile
34627 +++ b/arch/x86/vdso/Makefile
34628 @@ -181,7 +181,7 @@ quiet_cmd_vdso = VDSO $@
34629 -Wl,-T,$(filter %.lds,$^) $(filter %.o,$^) && \
34630 sh $(srctree)/$(src)/checkundef.sh '$(NM)' '$@'
34631
34632 -VDSO_LDFLAGS = -fPIC -shared $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
34633 +VDSO_LDFLAGS = -fPIC -shared -Wl,--no-undefined $(call cc-ldoption, -Wl$(comma)--hash-style=sysv)
34634 GCOV_PROFILE := n
34635
34636 #
34637 diff --git a/arch/x86/vdso/vdso32-setup.c b/arch/x86/vdso/vdso32-setup.c
34638 index d6bfb87..876ee18 100644
34639 --- a/arch/x86/vdso/vdso32-setup.c
34640 +++ b/arch/x86/vdso/vdso32-setup.c
34641 @@ -25,6 +25,7 @@
34642 #include <asm/tlbflush.h>
34643 #include <asm/vdso.h>
34644 #include <asm/proto.h>
34645 +#include <asm/mman.h>
34646
34647 enum {
34648 VDSO_DISABLED = 0,
34649 @@ -226,7 +227,7 @@ static inline void map_compat_vdso(int map)
34650 void enable_sep_cpu(void)
34651 {
34652 int cpu = get_cpu();
34653 - struct tss_struct *tss = &per_cpu(init_tss, cpu);
34654 + struct tss_struct *tss = init_tss + cpu;
34655
34656 if (!boot_cpu_has(X86_FEATURE_SEP)) {
34657 put_cpu();
34658 @@ -249,7 +250,7 @@ static int __init gate_vma_init(void)
34659 gate_vma.vm_start = FIXADDR_USER_START;
34660 gate_vma.vm_end = FIXADDR_USER_END;
34661 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
34662 - gate_vma.vm_page_prot = __P101;
34663 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
34664
34665 return 0;
34666 }
34667 @@ -330,14 +331,14 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34668 if (compat)
34669 addr = VDSO_HIGH_BASE;
34670 else {
34671 - addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, 0);
34672 + addr = get_unmapped_area(NULL, 0, PAGE_SIZE, 0, MAP_EXECUTABLE);
34673 if (IS_ERR_VALUE(addr)) {
34674 ret = addr;
34675 goto up_fail;
34676 }
34677 }
34678
34679 - current->mm->context.vdso = (void *)addr;
34680 + current->mm->context.vdso = addr;
34681
34682 if (compat_uses_vma || !compat) {
34683 /*
34684 @@ -353,11 +354,11 @@ int arch_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34685 }
34686
34687 current_thread_info()->sysenter_return =
34688 - VDSO32_SYMBOL(addr, SYSENTER_RETURN);
34689 + (__force void __user *)VDSO32_SYMBOL(addr, SYSENTER_RETURN);
34690
34691 up_fail:
34692 if (ret)
34693 - current->mm->context.vdso = NULL;
34694 + current->mm->context.vdso = 0;
34695
34696 up_write(&mm->mmap_sem);
34697
34698 @@ -404,8 +405,14 @@ __initcall(ia32_binfmt_init);
34699
34700 const char *arch_vma_name(struct vm_area_struct *vma)
34701 {
34702 - if (vma->vm_mm && vma->vm_start == (long)vma->vm_mm->context.vdso)
34703 + if (vma->vm_mm && vma->vm_start == vma->vm_mm->context.vdso)
34704 return "[vdso]";
34705 +
34706 +#ifdef CONFIG_PAX_SEGMEXEC
34707 + if (vma->vm_mm && vma->vm_mirror && vma->vm_mirror->vm_start == vma->vm_mm->context.vdso)
34708 + return "[vdso]";
34709 +#endif
34710 +
34711 return NULL;
34712 }
34713
34714 @@ -415,7 +422,7 @@ struct vm_area_struct *get_gate_vma(struct mm_struct *mm)
34715 * Check to see if the corresponding task was created in compat vdso
34716 * mode.
34717 */
34718 - if (mm && mm->context.vdso == (void *)VDSO_HIGH_BASE)
34719 + if (mm && mm->context.vdso == VDSO_HIGH_BASE)
34720 return &gate_vma;
34721 return NULL;
34722 }
34723 diff --git a/arch/x86/vdso/vma.c b/arch/x86/vdso/vma.c
34724 index 431e875..cbb23f3 100644
34725 --- a/arch/x86/vdso/vma.c
34726 +++ b/arch/x86/vdso/vma.c
34727 @@ -16,8 +16,6 @@
34728 #include <asm/vdso.h>
34729 #include <asm/page.h>
34730
34731 -unsigned int __read_mostly vdso_enabled = 1;
34732 -
34733 extern char vdso_start[], vdso_end[];
34734 extern unsigned short vdso_sync_cpuid;
34735
34736 @@ -141,7 +139,6 @@ static unsigned long vdso_addr(unsigned long start, unsigned len)
34737 * unaligned here as a result of stack start randomization.
34738 */
34739 addr = PAGE_ALIGN(addr);
34740 - addr = align_vdso_addr(addr);
34741
34742 return addr;
34743 }
34744 @@ -154,30 +151,31 @@ static int setup_additional_pages(struct linux_binprm *bprm,
34745 unsigned size)
34746 {
34747 struct mm_struct *mm = current->mm;
34748 - unsigned long addr;
34749 + unsigned long addr = 0;
34750 int ret;
34751
34752 - if (!vdso_enabled)
34753 - return 0;
34754 -
34755 down_write(&mm->mmap_sem);
34756 +
34757 +#ifdef CONFIG_PAX_RANDMMAP
34758 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
34759 +#endif
34760 +
34761 addr = vdso_addr(mm->start_stack, size);
34762 + addr = align_vdso_addr(addr);
34763 addr = get_unmapped_area(NULL, addr, size, 0, 0);
34764 if (IS_ERR_VALUE(addr)) {
34765 ret = addr;
34766 goto up_fail;
34767 }
34768
34769 - current->mm->context.vdso = (void *)addr;
34770 + mm->context.vdso = addr;
34771
34772 ret = install_special_mapping(mm, addr, size,
34773 VM_READ|VM_EXEC|
34774 VM_MAYREAD|VM_MAYWRITE|VM_MAYEXEC,
34775 pages);
34776 - if (ret) {
34777 - current->mm->context.vdso = NULL;
34778 - goto up_fail;
34779 - }
34780 + if (ret)
34781 + mm->context.vdso = 0;
34782
34783 up_fail:
34784 up_write(&mm->mmap_sem);
34785 @@ -197,10 +195,3 @@ int x32_setup_additional_pages(struct linux_binprm *bprm, int uses_interp)
34786 vdsox32_size);
34787 }
34788 #endif
34789 -
34790 -static __init int vdso_setup(char *s)
34791 -{
34792 - vdso_enabled = simple_strtoul(s, NULL, 0);
34793 - return 0;
34794 -}
34795 -__setup("vdso=", vdso_setup);
34796 diff --git a/arch/x86/xen/Kconfig b/arch/x86/xen/Kconfig
34797 index 1a3c765..3d2e8d1 100644
34798 --- a/arch/x86/xen/Kconfig
34799 +++ b/arch/x86/xen/Kconfig
34800 @@ -9,6 +9,7 @@ config XEN
34801 select XEN_HAVE_PVMMU
34802 depends on X86_64 || (X86_32 && X86_PAE && !X86_VISWS)
34803 depends on X86_TSC
34804 + depends on !GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_VIRT_XEN
34805 help
34806 This is the Linux Xen port. Enabling this will allow the
34807 kernel to boot in a paravirtualized environment under the
34808 diff --git a/arch/x86/xen/enlighten.c b/arch/x86/xen/enlighten.c
34809 index fa6ade7..73da73a5 100644
34810 --- a/arch/x86/xen/enlighten.c
34811 +++ b/arch/x86/xen/enlighten.c
34812 @@ -123,8 +123,6 @@ EXPORT_SYMBOL_GPL(xen_start_info);
34813
34814 struct shared_info xen_dummy_shared_info;
34815
34816 -void *xen_initial_gdt;
34817 -
34818 RESERVE_BRK(shared_info_page_brk, PAGE_SIZE);
34819 __read_mostly int xen_have_vector_callback;
34820 EXPORT_SYMBOL_GPL(xen_have_vector_callback);
34821 @@ -541,8 +539,7 @@ static void xen_load_gdt(const struct desc_ptr *dtr)
34822 {
34823 unsigned long va = dtr->address;
34824 unsigned int size = dtr->size + 1;
34825 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
34826 - unsigned long frames[pages];
34827 + unsigned long frames[65536 / PAGE_SIZE];
34828 int f;
34829
34830 /*
34831 @@ -590,8 +587,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
34832 {
34833 unsigned long va = dtr->address;
34834 unsigned int size = dtr->size + 1;
34835 - unsigned pages = (size + PAGE_SIZE - 1) / PAGE_SIZE;
34836 - unsigned long frames[pages];
34837 + unsigned long frames[(GDT_SIZE + PAGE_SIZE - 1) / PAGE_SIZE];
34838 int f;
34839
34840 /*
34841 @@ -599,7 +595,7 @@ static void __init xen_load_gdt_boot(const struct desc_ptr *dtr)
34842 * 8-byte entries, or 16 4k pages..
34843 */
34844
34845 - BUG_ON(size > 65536);
34846 + BUG_ON(size > GDT_SIZE);
34847 BUG_ON(va & ~PAGE_MASK);
34848
34849 for (f = 0; va < dtr->address + size; va += PAGE_SIZE, f++) {
34850 @@ -988,7 +984,7 @@ static u32 xen_safe_apic_wait_icr_idle(void)
34851 return 0;
34852 }
34853
34854 -static void set_xen_basic_apic_ops(void)
34855 +static void __init set_xen_basic_apic_ops(void)
34856 {
34857 apic->read = xen_apic_read;
34858 apic->write = xen_apic_write;
34859 @@ -1293,30 +1289,30 @@ static const struct pv_apic_ops xen_apic_ops __initconst = {
34860 #endif
34861 };
34862
34863 -static void xen_reboot(int reason)
34864 +static __noreturn void xen_reboot(int reason)
34865 {
34866 struct sched_shutdown r = { .reason = reason };
34867
34868 - if (HYPERVISOR_sched_op(SCHEDOP_shutdown, &r))
34869 - BUG();
34870 + HYPERVISOR_sched_op(SCHEDOP_shutdown, &r);
34871 + BUG();
34872 }
34873
34874 -static void xen_restart(char *msg)
34875 +static __noreturn void xen_restart(char *msg)
34876 {
34877 xen_reboot(SHUTDOWN_reboot);
34878 }
34879
34880 -static void xen_emergency_restart(void)
34881 +static __noreturn void xen_emergency_restart(void)
34882 {
34883 xen_reboot(SHUTDOWN_reboot);
34884 }
34885
34886 -static void xen_machine_halt(void)
34887 +static __noreturn void xen_machine_halt(void)
34888 {
34889 xen_reboot(SHUTDOWN_poweroff);
34890 }
34891
34892 -static void xen_machine_power_off(void)
34893 +static __noreturn void xen_machine_power_off(void)
34894 {
34895 if (pm_power_off)
34896 pm_power_off();
34897 @@ -1467,7 +1463,17 @@ asmlinkage void __init xen_start_kernel(void)
34898 __userpte_alloc_gfp &= ~__GFP_HIGHMEM;
34899
34900 /* Work out if we support NX */
34901 - x86_configure_nx();
34902 +#if defined(CONFIG_X86_64) || defined(CONFIG_X86_PAE)
34903 + if ((cpuid_eax(0x80000000) & 0xffff0000) == 0x80000000 &&
34904 + (cpuid_edx(0x80000001) & (1U << (X86_FEATURE_NX & 31)))) {
34905 + unsigned l, h;
34906 +
34907 + __supported_pte_mask |= _PAGE_NX;
34908 + rdmsr(MSR_EFER, l, h);
34909 + l |= EFER_NX;
34910 + wrmsr(MSR_EFER, l, h);
34911 + }
34912 +#endif
34913
34914 xen_setup_features();
34915
34916 @@ -1498,13 +1504,6 @@ asmlinkage void __init xen_start_kernel(void)
34917
34918 machine_ops = xen_machine_ops;
34919
34920 - /*
34921 - * The only reliable way to retain the initial address of the
34922 - * percpu gdt_page is to remember it here, so we can go and
34923 - * mark it RW later, when the initial percpu area is freed.
34924 - */
34925 - xen_initial_gdt = &per_cpu(gdt_page, 0);
34926 -
34927 xen_smp_init();
34928
34929 #ifdef CONFIG_ACPI_NUMA
34930 diff --git a/arch/x86/xen/mmu.c b/arch/x86/xen/mmu.c
34931 index ce563be..7327d91 100644
34932 --- a/arch/x86/xen/mmu.c
34933 +++ b/arch/x86/xen/mmu.c
34934 @@ -379,7 +379,7 @@ static pteval_t pte_mfn_to_pfn(pteval_t val)
34935 return val;
34936 }
34937
34938 -static pteval_t pte_pfn_to_mfn(pteval_t val)
34939 +static pteval_t __intentional_overflow(-1) pte_pfn_to_mfn(pteval_t val)
34940 {
34941 if (val & _PAGE_PRESENT) {
34942 unsigned long pfn = (val & PTE_PFN_MASK) >> PAGE_SHIFT;
34943 @@ -1894,6 +1894,9 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34944 /* L3_k[510] -> level2_kernel_pgt
34945 * L3_i[511] -> level2_fixmap_pgt */
34946 convert_pfn_mfn(level3_kernel_pgt);
34947 + convert_pfn_mfn(level3_vmalloc_start_pgt);
34948 + convert_pfn_mfn(level3_vmalloc_end_pgt);
34949 + convert_pfn_mfn(level3_vmemmap_pgt);
34950
34951 /* We get [511][511] and have Xen's version of level2_kernel_pgt */
34952 l3 = m2v(pgd[pgd_index(__START_KERNEL_map)].pgd);
34953 @@ -1923,8 +1926,12 @@ void __init xen_setup_kernel_pagetable(pgd_t *pgd, unsigned long max_pfn)
34954 set_page_prot(init_level4_pgt, PAGE_KERNEL_RO);
34955 set_page_prot(level3_ident_pgt, PAGE_KERNEL_RO);
34956 set_page_prot(level3_kernel_pgt, PAGE_KERNEL_RO);
34957 + set_page_prot(level3_vmalloc_start_pgt, PAGE_KERNEL_RO);
34958 + set_page_prot(level3_vmalloc_end_pgt, PAGE_KERNEL_RO);
34959 + set_page_prot(level3_vmemmap_pgt, PAGE_KERNEL_RO);
34960 set_page_prot(level3_user_vsyscall, PAGE_KERNEL_RO);
34961 set_page_prot(level2_ident_pgt, PAGE_KERNEL_RO);
34962 + set_page_prot(level2_vmemmap_pgt, PAGE_KERNEL_RO);
34963 set_page_prot(level2_kernel_pgt, PAGE_KERNEL_RO);
34964 set_page_prot(level2_fixmap_pgt, PAGE_KERNEL_RO);
34965
34966 @@ -2108,6 +2115,7 @@ static void __init xen_post_allocator_init(void)
34967 pv_mmu_ops.set_pud = xen_set_pud;
34968 #if PAGETABLE_LEVELS == 4
34969 pv_mmu_ops.set_pgd = xen_set_pgd;
34970 + pv_mmu_ops.set_pgd_batched = xen_set_pgd;
34971 #endif
34972
34973 /* This will work as long as patching hasn't happened yet
34974 @@ -2186,6 +2194,7 @@ static const struct pv_mmu_ops xen_mmu_ops __initconst = {
34975 .pud_val = PV_CALLEE_SAVE(xen_pud_val),
34976 .make_pud = PV_CALLEE_SAVE(xen_make_pud),
34977 .set_pgd = xen_set_pgd_hyper,
34978 + .set_pgd_batched = xen_set_pgd_hyper,
34979
34980 .alloc_pud = xen_alloc_pmd_init,
34981 .release_pud = xen_release_pmd_init,
34982 diff --git a/arch/x86/xen/smp.c b/arch/x86/xen/smp.c
34983 index c36b325..b0f1518 100644
34984 --- a/arch/x86/xen/smp.c
34985 +++ b/arch/x86/xen/smp.c
34986 @@ -274,17 +274,13 @@ static void __init xen_smp_prepare_boot_cpu(void)
34987 native_smp_prepare_boot_cpu();
34988
34989 if (xen_pv_domain()) {
34990 - /* We've switched to the "real" per-cpu gdt, so make sure the
34991 - old memory can be recycled */
34992 - make_lowmem_page_readwrite(xen_initial_gdt);
34993 -
34994 #ifdef CONFIG_X86_32
34995 /*
34996 * Xen starts us with XEN_FLAT_RING1_DS, but linux code
34997 * expects __USER_DS
34998 */
34999 - loadsegment(ds, __USER_DS);
35000 - loadsegment(es, __USER_DS);
35001 + loadsegment(ds, __KERNEL_DS);
35002 + loadsegment(es, __KERNEL_DS);
35003 #endif
35004
35005 xen_filter_cpu_maps();
35006 @@ -364,7 +360,7 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35007 ctxt->user_regs.ss = __KERNEL_DS;
35008 #ifdef CONFIG_X86_32
35009 ctxt->user_regs.fs = __KERNEL_PERCPU;
35010 - ctxt->user_regs.gs = __KERNEL_STACK_CANARY;
35011 + savesegment(gs, ctxt->user_regs.gs);
35012 #else
35013 ctxt->gs_base_kernel = per_cpu_offset(cpu);
35014 #endif
35015 @@ -374,8 +370,8 @@ cpu_initialize_context(unsigned int cpu, struct task_struct *idle)
35016
35017 {
35018 ctxt->user_regs.eflags = 0x1000; /* IOPL_RING1 */
35019 - ctxt->user_regs.ds = __USER_DS;
35020 - ctxt->user_regs.es = __USER_DS;
35021 + ctxt->user_regs.ds = __KERNEL_DS;
35022 + ctxt->user_regs.es = __KERNEL_DS;
35023
35024 xen_copy_trap_info(ctxt->trap_ctxt);
35025
35026 @@ -420,13 +416,12 @@ static int xen_cpu_up(unsigned int cpu, struct task_struct *idle)
35027 int rc;
35028
35029 per_cpu(current_task, cpu) = idle;
35030 + per_cpu(current_tinfo, cpu) = &idle->tinfo;
35031 #ifdef CONFIG_X86_32
35032 irq_ctx_init(cpu);
35033 #else
35034 clear_tsk_thread_flag(idle, TIF_FORK);
35035 - per_cpu(kernel_stack, cpu) =
35036 - (unsigned long)task_stack_page(idle) -
35037 - KERNEL_STACK_OFFSET + THREAD_SIZE;
35038 + per_cpu(kernel_stack, cpu) = (unsigned long)task_stack_page(idle) - 16 + THREAD_SIZE;
35039 #endif
35040 xen_setup_runstate_info(cpu);
35041 xen_setup_timer(cpu);
35042 @@ -702,7 +697,7 @@ static const struct smp_ops xen_smp_ops __initconst = {
35043
35044 void __init xen_smp_init(void)
35045 {
35046 - smp_ops = xen_smp_ops;
35047 + memcpy((void *)&smp_ops, &xen_smp_ops, sizeof smp_ops);
35048 xen_fill_possible_map();
35049 }
35050
35051 diff --git a/arch/x86/xen/xen-asm_32.S b/arch/x86/xen/xen-asm_32.S
35052 index 33ca6e4..0ded929 100644
35053 --- a/arch/x86/xen/xen-asm_32.S
35054 +++ b/arch/x86/xen/xen-asm_32.S
35055 @@ -84,14 +84,14 @@ ENTRY(xen_iret)
35056 ESP_OFFSET=4 # bytes pushed onto stack
35057
35058 /*
35059 - * Store vcpu_info pointer for easy access. Do it this way to
35060 - * avoid having to reload %fs
35061 + * Store vcpu_info pointer for easy access.
35062 */
35063 #ifdef CONFIG_SMP
35064 - GET_THREAD_INFO(%eax)
35065 - movl %ss:TI_cpu(%eax), %eax
35066 - movl %ss:__per_cpu_offset(,%eax,4), %eax
35067 - mov %ss:xen_vcpu(%eax), %eax
35068 + push %fs
35069 + mov $(__KERNEL_PERCPU), %eax
35070 + mov %eax, %fs
35071 + mov PER_CPU_VAR(xen_vcpu), %eax
35072 + pop %fs
35073 #else
35074 movl %ss:xen_vcpu, %eax
35075 #endif
35076 diff --git a/arch/x86/xen/xen-head.S b/arch/x86/xen/xen-head.S
35077 index 7faed58..ba4427c 100644
35078 --- a/arch/x86/xen/xen-head.S
35079 +++ b/arch/x86/xen/xen-head.S
35080 @@ -19,6 +19,17 @@ ENTRY(startup_xen)
35081 #ifdef CONFIG_X86_32
35082 mov %esi,xen_start_info
35083 mov $init_thread_union+THREAD_SIZE,%esp
35084 +#ifdef CONFIG_SMP
35085 + movl $cpu_gdt_table,%edi
35086 + movl $__per_cpu_load,%eax
35087 + movw %ax,__KERNEL_PERCPU + 2(%edi)
35088 + rorl $16,%eax
35089 + movb %al,__KERNEL_PERCPU + 4(%edi)
35090 + movb %ah,__KERNEL_PERCPU + 7(%edi)
35091 + movl $__per_cpu_end - 1,%eax
35092 + subl $__per_cpu_start,%eax
35093 + movw %ax,__KERNEL_PERCPU + 0(%edi)
35094 +#endif
35095 #else
35096 mov %rsi,xen_start_info
35097 mov $init_thread_union+THREAD_SIZE,%rsp
35098 diff --git a/arch/x86/xen/xen-ops.h b/arch/x86/xen/xen-ops.h
35099 index 95f8c61..611d6e8 100644
35100 --- a/arch/x86/xen/xen-ops.h
35101 +++ b/arch/x86/xen/xen-ops.h
35102 @@ -10,8 +10,6 @@
35103 extern const char xen_hypervisor_callback[];
35104 extern const char xen_failsafe_callback[];
35105
35106 -extern void *xen_initial_gdt;
35107 -
35108 struct trap_info;
35109 void xen_copy_trap_info(struct trap_info *traps);
35110
35111 diff --git a/arch/xtensa/variants/dc232b/include/variant/core.h b/arch/xtensa/variants/dc232b/include/variant/core.h
35112 index 525bd3d..ef888b1 100644
35113 --- a/arch/xtensa/variants/dc232b/include/variant/core.h
35114 +++ b/arch/xtensa/variants/dc232b/include/variant/core.h
35115 @@ -119,9 +119,9 @@
35116 ----------------------------------------------------------------------*/
35117
35118 #define XCHAL_ICACHE_LINESIZE 32 /* I-cache line size in bytes */
35119 -#define XCHAL_DCACHE_LINESIZE 32 /* D-cache line size in bytes */
35120 #define XCHAL_ICACHE_LINEWIDTH 5 /* log2(I line size in bytes) */
35121 #define XCHAL_DCACHE_LINEWIDTH 5 /* log2(D line size in bytes) */
35122 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35123
35124 #define XCHAL_ICACHE_SIZE 16384 /* I-cache size in bytes or 0 */
35125 #define XCHAL_DCACHE_SIZE 16384 /* D-cache size in bytes or 0 */
35126 diff --git a/arch/xtensa/variants/fsf/include/variant/core.h b/arch/xtensa/variants/fsf/include/variant/core.h
35127 index 2f33760..835e50a 100644
35128 --- a/arch/xtensa/variants/fsf/include/variant/core.h
35129 +++ b/arch/xtensa/variants/fsf/include/variant/core.h
35130 @@ -11,6 +11,7 @@
35131 #ifndef _XTENSA_CORE_H
35132 #define _XTENSA_CORE_H
35133
35134 +#include <linux/const.h>
35135
35136 /****************************************************************************
35137 Parameters Useful for Any Code, USER or PRIVILEGED
35138 @@ -112,9 +113,9 @@
35139 ----------------------------------------------------------------------*/
35140
35141 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35142 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35143 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35144 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35145 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35146
35147 #define XCHAL_ICACHE_SIZE 8192 /* I-cache size in bytes or 0 */
35148 #define XCHAL_DCACHE_SIZE 8192 /* D-cache size in bytes or 0 */
35149 diff --git a/arch/xtensa/variants/s6000/include/variant/core.h b/arch/xtensa/variants/s6000/include/variant/core.h
35150 index af00795..2bb8105 100644
35151 --- a/arch/xtensa/variants/s6000/include/variant/core.h
35152 +++ b/arch/xtensa/variants/s6000/include/variant/core.h
35153 @@ -11,6 +11,7 @@
35154 #ifndef _XTENSA_CORE_CONFIGURATION_H
35155 #define _XTENSA_CORE_CONFIGURATION_H
35156
35157 +#include <linux/const.h>
35158
35159 /****************************************************************************
35160 Parameters Useful for Any Code, USER or PRIVILEGED
35161 @@ -118,9 +119,9 @@
35162 ----------------------------------------------------------------------*/
35163
35164 #define XCHAL_ICACHE_LINESIZE 16 /* I-cache line size in bytes */
35165 -#define XCHAL_DCACHE_LINESIZE 16 /* D-cache line size in bytes */
35166 #define XCHAL_ICACHE_LINEWIDTH 4 /* log2(I line size in bytes) */
35167 #define XCHAL_DCACHE_LINEWIDTH 4 /* log2(D line size in bytes) */
35168 +#define XCHAL_DCACHE_LINESIZE (_AC(1,UL) << XCHAL_DCACHE_LINEWIDTH) /* D-cache line size in bytes */
35169
35170 #define XCHAL_ICACHE_SIZE 32768 /* I-cache size in bytes or 0 */
35171 #define XCHAL_DCACHE_SIZE 32768 /* D-cache size in bytes or 0 */
35172 diff --git a/block/blk-cgroup.c b/block/blk-cgroup.c
35173 index 4e491d9..c8e18e4 100644
35174 --- a/block/blk-cgroup.c
35175 +++ b/block/blk-cgroup.c
35176 @@ -812,7 +812,7 @@ static void blkcg_css_free(struct cgroup_subsys_state *css)
35177 static struct cgroup_subsys_state *
35178 blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35179 {
35180 - static atomic64_t id_seq = ATOMIC64_INIT(0);
35181 + static atomic64_unchecked_t id_seq = ATOMIC64_INIT(0);
35182 struct blkcg *blkcg;
35183
35184 if (!parent_css) {
35185 @@ -826,7 +826,7 @@ blkcg_css_alloc(struct cgroup_subsys_state *parent_css)
35186
35187 blkcg->cfq_weight = CFQ_WEIGHT_DEFAULT;
35188 blkcg->cfq_leaf_weight = CFQ_WEIGHT_DEFAULT;
35189 - blkcg->id = atomic64_inc_return(&id_seq); /* root is 0, start from 1 */
35190 + blkcg->id = atomic64_inc_return_unchecked(&id_seq); /* root is 0, start from 1 */
35191 done:
35192 spin_lock_init(&blkcg->lock);
35193 INIT_RADIX_TREE(&blkcg->blkg_tree, GFP_ATOMIC);
35194 diff --git a/block/blk-iopoll.c b/block/blk-iopoll.c
35195 index 1855bf5..af12b06 100644
35196 --- a/block/blk-iopoll.c
35197 +++ b/block/blk-iopoll.c
35198 @@ -77,7 +77,7 @@ void blk_iopoll_complete(struct blk_iopoll *iopoll)
35199 }
35200 EXPORT_SYMBOL(blk_iopoll_complete);
35201
35202 -static void blk_iopoll_softirq(struct softirq_action *h)
35203 +static __latent_entropy void blk_iopoll_softirq(void)
35204 {
35205 struct list_head *list = this_cpu_ptr(&blk_cpu_iopoll);
35206 int rearm = 0, budget = blk_iopoll_budget;
35207 diff --git a/block/blk-map.c b/block/blk-map.c
35208 index 623e1cd..ca1e109 100644
35209 --- a/block/blk-map.c
35210 +++ b/block/blk-map.c
35211 @@ -302,7 +302,7 @@ int blk_rq_map_kern(struct request_queue *q, struct request *rq, void *kbuf,
35212 if (!len || !kbuf)
35213 return -EINVAL;
35214
35215 - do_copy = !blk_rq_aligned(q, addr, len) || object_is_on_stack(kbuf);
35216 + do_copy = !blk_rq_aligned(q, addr, len) || object_starts_on_stack(kbuf);
35217 if (do_copy)
35218 bio = bio_copy_kern(q, kbuf, len, gfp_mask, reading);
35219 else
35220 diff --git a/block/blk-softirq.c b/block/blk-softirq.c
35221 index 57790c1..5e988dd 100644
35222 --- a/block/blk-softirq.c
35223 +++ b/block/blk-softirq.c
35224 @@ -18,7 +18,7 @@ static DEFINE_PER_CPU(struct list_head, blk_cpu_done);
35225 * Softirq action handler - move entries to local list and loop over them
35226 * while passing them to the queue registered handler.
35227 */
35228 -static void blk_done_softirq(struct softirq_action *h)
35229 +static __latent_entropy void blk_done_softirq(void)
35230 {
35231 struct list_head *cpu_list, local_list;
35232
35233 diff --git a/block/bsg.c b/block/bsg.c
35234 index 420a5a9..23834aa 100644
35235 --- a/block/bsg.c
35236 +++ b/block/bsg.c
35237 @@ -176,16 +176,24 @@ static int blk_fill_sgv4_hdr_rq(struct request_queue *q, struct request *rq,
35238 struct sg_io_v4 *hdr, struct bsg_device *bd,
35239 fmode_t has_write_perm)
35240 {
35241 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35242 + unsigned char *cmdptr;
35243 +
35244 if (hdr->request_len > BLK_MAX_CDB) {
35245 rq->cmd = kzalloc(hdr->request_len, GFP_KERNEL);
35246 if (!rq->cmd)
35247 return -ENOMEM;
35248 - }
35249 + cmdptr = rq->cmd;
35250 + } else
35251 + cmdptr = tmpcmd;
35252
35253 - if (copy_from_user(rq->cmd, (void __user *)(unsigned long)hdr->request,
35254 + if (copy_from_user(cmdptr, (void __user *)(unsigned long)hdr->request,
35255 hdr->request_len))
35256 return -EFAULT;
35257
35258 + if (cmdptr != rq->cmd)
35259 + memcpy(rq->cmd, cmdptr, hdr->request_len);
35260 +
35261 if (hdr->subprotocol == BSG_SUB_PROTOCOL_SCSI_CMD) {
35262 if (blk_verify_command(rq->cmd, has_write_perm))
35263 return -EPERM;
35264 diff --git a/block/compat_ioctl.c b/block/compat_ioctl.c
35265 index fbd5a67..f24fd95 100644
35266 --- a/block/compat_ioctl.c
35267 +++ b/block/compat_ioctl.c
35268 @@ -156,7 +156,7 @@ static int compat_cdrom_generic_command(struct block_device *bdev, fmode_t mode,
35269 cgc = compat_alloc_user_space(sizeof(*cgc));
35270 cgc32 = compat_ptr(arg);
35271
35272 - if (copy_in_user(&cgc->cmd, &cgc32->cmd, sizeof(cgc->cmd)) ||
35273 + if (copy_in_user(cgc->cmd, cgc32->cmd, sizeof(cgc->cmd)) ||
35274 get_user(data, &cgc32->buffer) ||
35275 put_user(compat_ptr(data), &cgc->buffer) ||
35276 copy_in_user(&cgc->buflen, &cgc32->buflen,
35277 @@ -341,7 +341,7 @@ static int compat_fd_ioctl(struct block_device *bdev, fmode_t mode,
35278 err |= __get_user(f->spec1, &uf->spec1);
35279 err |= __get_user(f->fmt_gap, &uf->fmt_gap);
35280 err |= __get_user(name, &uf->name);
35281 - f->name = compat_ptr(name);
35282 + f->name = (void __force_kernel *)compat_ptr(name);
35283 if (err) {
35284 err = -EFAULT;
35285 goto out;
35286 diff --git a/block/genhd.c b/block/genhd.c
35287 index 791f419..89f21c4 100644
35288 --- a/block/genhd.c
35289 +++ b/block/genhd.c
35290 @@ -467,21 +467,24 @@ static char *bdevt_str(dev_t devt, char *buf)
35291
35292 /*
35293 * Register device numbers dev..(dev+range-1)
35294 - * range must be nonzero
35295 + * Noop if @range is zero.
35296 * The hash chain is sorted on range, so that subranges can override.
35297 */
35298 void blk_register_region(dev_t devt, unsigned long range, struct module *module,
35299 struct kobject *(*probe)(dev_t, int *, void *),
35300 int (*lock)(dev_t, void *), void *data)
35301 {
35302 - kobj_map(bdev_map, devt, range, module, probe, lock, data);
35303 + if (range)
35304 + kobj_map(bdev_map, devt, range, module, probe, lock, data);
35305 }
35306
35307 EXPORT_SYMBOL(blk_register_region);
35308
35309 +/* undo blk_register_region(), noop if @range is zero */
35310 void blk_unregister_region(dev_t devt, unsigned long range)
35311 {
35312 - kobj_unmap(bdev_map, devt, range);
35313 + if (range)
35314 + kobj_unmap(bdev_map, devt, range);
35315 }
35316
35317 EXPORT_SYMBOL(blk_unregister_region);
35318 diff --git a/block/partitions/efi.c b/block/partitions/efi.c
35319 index dc51f46..d5446a8 100644
35320 --- a/block/partitions/efi.c
35321 +++ b/block/partitions/efi.c
35322 @@ -293,14 +293,14 @@ static gpt_entry *alloc_read_gpt_entries(struct parsed_partitions *state,
35323 if (!gpt)
35324 return NULL;
35325
35326 + if (!le32_to_cpu(gpt->num_partition_entries))
35327 + return NULL;
35328 + pte = kcalloc(le32_to_cpu(gpt->num_partition_entries), le32_to_cpu(gpt->sizeof_partition_entry), GFP_KERNEL);
35329 + if (!pte)
35330 + return NULL;
35331 +
35332 count = le32_to_cpu(gpt->num_partition_entries) *
35333 le32_to_cpu(gpt->sizeof_partition_entry);
35334 - if (!count)
35335 - return NULL;
35336 - pte = kmalloc(count, GFP_KERNEL);
35337 - if (!pte)
35338 - return NULL;
35339 -
35340 if (read_lba(state, le64_to_cpu(gpt->partition_entry_lba),
35341 (u8 *) pte, count) < count) {
35342 kfree(pte);
35343 diff --git a/block/scsi_ioctl.c b/block/scsi_ioctl.c
35344 index 625e3e4..b5339f9 100644
35345 --- a/block/scsi_ioctl.c
35346 +++ b/block/scsi_ioctl.c
35347 @@ -67,7 +67,7 @@ static int scsi_get_bus(struct request_queue *q, int __user *p)
35348 return put_user(0, p);
35349 }
35350
35351 -static int sg_get_timeout(struct request_queue *q)
35352 +static int __intentional_overflow(-1) sg_get_timeout(struct request_queue *q)
35353 {
35354 return jiffies_to_clock_t(q->sg_timeout);
35355 }
35356 @@ -224,8 +224,20 @@ EXPORT_SYMBOL(blk_verify_command);
35357 static int blk_fill_sghdr_rq(struct request_queue *q, struct request *rq,
35358 struct sg_io_hdr *hdr, fmode_t mode)
35359 {
35360 - if (copy_from_user(rq->cmd, hdr->cmdp, hdr->cmd_len))
35361 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35362 + unsigned char *cmdptr;
35363 +
35364 + if (rq->cmd != rq->__cmd)
35365 + cmdptr = rq->cmd;
35366 + else
35367 + cmdptr = tmpcmd;
35368 +
35369 + if (copy_from_user(cmdptr, hdr->cmdp, hdr->cmd_len))
35370 return -EFAULT;
35371 +
35372 + if (cmdptr != rq->cmd)
35373 + memcpy(rq->cmd, cmdptr, hdr->cmd_len);
35374 +
35375 if (blk_verify_command(rq->cmd, mode & FMODE_WRITE))
35376 return -EPERM;
35377
35378 @@ -415,6 +427,8 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35379 int err;
35380 unsigned int in_len, out_len, bytes, opcode, cmdlen;
35381 char *buffer = NULL, sense[SCSI_SENSE_BUFFERSIZE];
35382 + unsigned char tmpcmd[sizeof(rq->__cmd)];
35383 + unsigned char *cmdptr;
35384
35385 if (!sic)
35386 return -EINVAL;
35387 @@ -448,9 +462,18 @@ int sg_scsi_ioctl(struct request_queue *q, struct gendisk *disk, fmode_t mode,
35388 */
35389 err = -EFAULT;
35390 rq->cmd_len = cmdlen;
35391 - if (copy_from_user(rq->cmd, sic->data, cmdlen))
35392 +
35393 + if (rq->cmd != rq->__cmd)
35394 + cmdptr = rq->cmd;
35395 + else
35396 + cmdptr = tmpcmd;
35397 +
35398 + if (copy_from_user(cmdptr, sic->data, cmdlen))
35399 goto error;
35400
35401 + if (rq->cmd != cmdptr)
35402 + memcpy(rq->cmd, cmdptr, cmdlen);
35403 +
35404 if (in_len && copy_from_user(buffer, sic->data + cmdlen, in_len))
35405 goto error;
35406
35407 diff --git a/crypto/cryptd.c b/crypto/cryptd.c
35408 index 7bdd61b..afec999 100644
35409 --- a/crypto/cryptd.c
35410 +++ b/crypto/cryptd.c
35411 @@ -63,7 +63,7 @@ struct cryptd_blkcipher_ctx {
35412
35413 struct cryptd_blkcipher_request_ctx {
35414 crypto_completion_t complete;
35415 -};
35416 +} __no_const;
35417
35418 struct cryptd_hash_ctx {
35419 struct crypto_shash *child;
35420 @@ -80,7 +80,7 @@ struct cryptd_aead_ctx {
35421
35422 struct cryptd_aead_request_ctx {
35423 crypto_completion_t complete;
35424 -};
35425 +} __no_const;
35426
35427 static void cryptd_queue_worker(struct work_struct *work);
35428
35429 diff --git a/crypto/pcrypt.c b/crypto/pcrypt.c
35430 index f8c920c..ab2cb5a 100644
35431 --- a/crypto/pcrypt.c
35432 +++ b/crypto/pcrypt.c
35433 @@ -440,7 +440,7 @@ static int pcrypt_sysfs_add(struct padata_instance *pinst, const char *name)
35434 int ret;
35435
35436 pinst->kobj.kset = pcrypt_kset;
35437 - ret = kobject_add(&pinst->kobj, NULL, name);
35438 + ret = kobject_add(&pinst->kobj, NULL, "%s", name);
35439 if (!ret)
35440 kobject_uevent(&pinst->kobj, KOBJ_ADD);
35441
35442 diff --git a/drivers/acpi/acpica/hwxfsleep.c b/drivers/acpi/acpica/hwxfsleep.c
35443 index 15dddc1..b61cf0c 100644
35444 --- a/drivers/acpi/acpica/hwxfsleep.c
35445 +++ b/drivers/acpi/acpica/hwxfsleep.c
35446 @@ -63,11 +63,12 @@ static acpi_status acpi_hw_sleep_dispatch(u8 sleep_state, u32 function_id);
35447 /* Legacy functions are optional, based upon ACPI_REDUCED_HARDWARE */
35448
35449 static struct acpi_sleep_functions acpi_sleep_dispatch[] = {
35450 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35451 - acpi_hw_extended_sleep},
35452 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35453 - acpi_hw_extended_wake_prep},
35454 - {ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake), acpi_hw_extended_wake}
35455 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_sleep),
35456 + .extended_function = acpi_hw_extended_sleep},
35457 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake_prep),
35458 + .extended_function = acpi_hw_extended_wake_prep},
35459 + {.legacy_function = ACPI_HW_OPTIONAL_FUNCTION(acpi_hw_legacy_wake),
35460 + .extended_function = acpi_hw_extended_wake}
35461 };
35462
35463 /*
35464 diff --git a/drivers/acpi/apei/apei-internal.h b/drivers/acpi/apei/apei-internal.h
35465 index 21ba34a..cb05966 100644
35466 --- a/drivers/acpi/apei/apei-internal.h
35467 +++ b/drivers/acpi/apei/apei-internal.h
35468 @@ -20,7 +20,7 @@ typedef int (*apei_exec_ins_func_t)(struct apei_exec_context *ctx,
35469 struct apei_exec_ins_type {
35470 u32 flags;
35471 apei_exec_ins_func_t run;
35472 -};
35473 +} __do_const;
35474
35475 struct apei_exec_context {
35476 u32 ip;
35477 diff --git a/drivers/acpi/apei/ghes.c b/drivers/acpi/apei/ghes.c
35478 index a30bc31..b91c4d5 100644
35479 --- a/drivers/acpi/apei/ghes.c
35480 +++ b/drivers/acpi/apei/ghes.c
35481 @@ -498,7 +498,7 @@ static void __ghes_print_estatus(const char *pfx,
35482 const struct acpi_hest_generic *generic,
35483 const struct acpi_generic_status *estatus)
35484 {
35485 - static atomic_t seqno;
35486 + static atomic_unchecked_t seqno;
35487 unsigned int curr_seqno;
35488 char pfx_seq[64];
35489
35490 @@ -509,7 +509,7 @@ static void __ghes_print_estatus(const char *pfx,
35491 else
35492 pfx = KERN_ERR;
35493 }
35494 - curr_seqno = atomic_inc_return(&seqno);
35495 + curr_seqno = atomic_inc_return_unchecked(&seqno);
35496 snprintf(pfx_seq, sizeof(pfx_seq), "%s{%u}" HW_ERR, pfx, curr_seqno);
35497 printk("%s""Hardware error from APEI Generic Hardware Error Source: %d\n",
35498 pfx_seq, generic->header.source_id);
35499 diff --git a/drivers/acpi/bgrt.c b/drivers/acpi/bgrt.c
35500 index a83e3c6..c3d617f 100644
35501 --- a/drivers/acpi/bgrt.c
35502 +++ b/drivers/acpi/bgrt.c
35503 @@ -86,8 +86,10 @@ static int __init bgrt_init(void)
35504 if (!bgrt_image)
35505 return -ENODEV;
35506
35507 - bin_attr_image.private = bgrt_image;
35508 - bin_attr_image.size = bgrt_image_size;
35509 + pax_open_kernel();
35510 + *(void **)&bin_attr_image.private = bgrt_image;
35511 + *(size_t *)&bin_attr_image.size = bgrt_image_size;
35512 + pax_close_kernel();
35513
35514 bgrt_kobj = kobject_create_and_add("bgrt", acpi_kobj);
35515 if (!bgrt_kobj)
35516 diff --git a/drivers/acpi/blacklist.c b/drivers/acpi/blacklist.c
35517 index 078c4f7..410e272 100644
35518 --- a/drivers/acpi/blacklist.c
35519 +++ b/drivers/acpi/blacklist.c
35520 @@ -52,7 +52,7 @@ struct acpi_blacklist_item {
35521 u32 is_critical_error;
35522 };
35523
35524 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata;
35525 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst;
35526
35527 /*
35528 * POLICY: If *anything* doesn't work, put it on the blacklist.
35529 @@ -164,7 +164,7 @@ static int __init dmi_disable_osi_win8(const struct dmi_system_id *d)
35530 return 0;
35531 }
35532
35533 -static struct dmi_system_id acpi_osi_dmi_table[] __initdata = {
35534 +static const struct dmi_system_id acpi_osi_dmi_table[] __initconst = {
35535 {
35536 .callback = dmi_disable_osi_vista,
35537 .ident = "Fujitsu Siemens",
35538 diff --git a/drivers/acpi/custom_method.c b/drivers/acpi/custom_method.c
35539 index 12b62f2..dc2aac8 100644
35540 --- a/drivers/acpi/custom_method.c
35541 +++ b/drivers/acpi/custom_method.c
35542 @@ -29,6 +29,10 @@ static ssize_t cm_write(struct file *file, const char __user * user_buf,
35543 struct acpi_table_header table;
35544 acpi_status status;
35545
35546 +#ifdef CONFIG_GRKERNSEC_KMEM
35547 + return -EPERM;
35548 +#endif
35549 +
35550 if (!(*ppos)) {
35551 /* parse the table header to get the table length */
35552 if (count <= sizeof(struct acpi_table_header))
35553 diff --git a/drivers/acpi/processor_idle.c b/drivers/acpi/processor_idle.c
35554 index 644516d..643937e 100644
35555 --- a/drivers/acpi/processor_idle.c
35556 +++ b/drivers/acpi/processor_idle.c
35557 @@ -963,7 +963,7 @@ static int acpi_processor_setup_cpuidle_states(struct acpi_processor *pr)
35558 {
35559 int i, count = CPUIDLE_DRIVER_STATE_START;
35560 struct acpi_processor_cx *cx;
35561 - struct cpuidle_state *state;
35562 + cpuidle_state_no_const *state;
35563 struct cpuidle_driver *drv = &acpi_idle_driver;
35564
35565 if (!pr->flags.power_setup_done)
35566 diff --git a/drivers/acpi/sysfs.c b/drivers/acpi/sysfs.c
35567 index 6dbc3ca..b8b59a0 100644
35568 --- a/drivers/acpi/sysfs.c
35569 +++ b/drivers/acpi/sysfs.c
35570 @@ -425,11 +425,11 @@ static u32 num_counters;
35571 static struct attribute **all_attrs;
35572 static u32 acpi_gpe_count;
35573
35574 -static struct attribute_group interrupt_stats_attr_group = {
35575 +static attribute_group_no_const interrupt_stats_attr_group = {
35576 .name = "interrupts",
35577 };
35578
35579 -static struct kobj_attribute *counter_attrs;
35580 +static kobj_attribute_no_const *counter_attrs;
35581
35582 static void delete_gpe_attr_array(void)
35583 {
35584 diff --git a/drivers/ata/libahci.c b/drivers/ata/libahci.c
35585 index c482f8c..c832240 100644
35586 --- a/drivers/ata/libahci.c
35587 +++ b/drivers/ata/libahci.c
35588 @@ -1239,7 +1239,7 @@ int ahci_kick_engine(struct ata_port *ap)
35589 }
35590 EXPORT_SYMBOL_GPL(ahci_kick_engine);
35591
35592 -static int ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
35593 +static int __intentional_overflow(-1) ahci_exec_polled_cmd(struct ata_port *ap, int pmp,
35594 struct ata_taskfile *tf, int is_cmd, u16 flags,
35595 unsigned long timeout_msec)
35596 {
35597 diff --git a/drivers/ata/libata-core.c b/drivers/ata/libata-core.c
35598 index 1a3dbd1..dfc6e5c 100644
35599 --- a/drivers/ata/libata-core.c
35600 +++ b/drivers/ata/libata-core.c
35601 @@ -98,7 +98,7 @@ static unsigned int ata_dev_set_xfermode(struct ata_device *dev);
35602 static void ata_dev_xfermask(struct ata_device *dev);
35603 static unsigned long ata_dev_blacklisted(const struct ata_device *dev);
35604
35605 -atomic_t ata_print_id = ATOMIC_INIT(0);
35606 +atomic_unchecked_t ata_print_id = ATOMIC_INIT(0);
35607
35608 struct ata_force_param {
35609 const char *name;
35610 @@ -4850,7 +4850,7 @@ void ata_qc_free(struct ata_queued_cmd *qc)
35611 struct ata_port *ap;
35612 unsigned int tag;
35613
35614 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35615 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35616 ap = qc->ap;
35617
35618 qc->flags = 0;
35619 @@ -4866,7 +4866,7 @@ void __ata_qc_complete(struct ata_queued_cmd *qc)
35620 struct ata_port *ap;
35621 struct ata_link *link;
35622
35623 - WARN_ON_ONCE(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35624 + BUG_ON(qc == NULL); /* ata_qc_from_tag _might_ return NULL */
35625 WARN_ON_ONCE(!(qc->flags & ATA_QCFLAG_ACTIVE));
35626 ap = qc->ap;
35627 link = qc->dev->link;
35628 @@ -5985,6 +5985,7 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
35629 return;
35630
35631 spin_lock(&lock);
35632 + pax_open_kernel();
35633
35634 for (cur = ops->inherits; cur; cur = cur->inherits) {
35635 void **inherit = (void **)cur;
35636 @@ -5998,8 +5999,9 @@ static void ata_finalize_port_ops(struct ata_port_operations *ops)
35637 if (IS_ERR(*pp))
35638 *pp = NULL;
35639
35640 - ops->inherits = NULL;
35641 + *(struct ata_port_operations **)&ops->inherits = NULL;
35642
35643 + pax_close_kernel();
35644 spin_unlock(&lock);
35645 }
35646
35647 @@ -6192,7 +6194,7 @@ int ata_host_register(struct ata_host *host, struct scsi_host_template *sht)
35648
35649 /* give ports names and add SCSI hosts */
35650 for (i = 0; i < host->n_ports; i++) {
35651 - host->ports[i]->print_id = atomic_inc_return(&ata_print_id);
35652 + host->ports[i]->print_id = atomic_inc_return_unchecked(&ata_print_id);
35653 host->ports[i]->local_port_no = i + 1;
35654 }
35655
35656 diff --git a/drivers/ata/libata-scsi.c b/drivers/ata/libata-scsi.c
35657 index ef8567d..8bdbd03 100644
35658 --- a/drivers/ata/libata-scsi.c
35659 +++ b/drivers/ata/libata-scsi.c
35660 @@ -4147,7 +4147,7 @@ int ata_sas_port_init(struct ata_port *ap)
35661
35662 if (rc)
35663 return rc;
35664 - ap->print_id = atomic_inc_return(&ata_print_id);
35665 + ap->print_id = atomic_inc_return_unchecked(&ata_print_id);
35666 return 0;
35667 }
35668 EXPORT_SYMBOL_GPL(ata_sas_port_init);
35669 diff --git a/drivers/ata/libata.h b/drivers/ata/libata.h
35670 index 45b5ab3..98446b8 100644
35671 --- a/drivers/ata/libata.h
35672 +++ b/drivers/ata/libata.h
35673 @@ -53,7 +53,7 @@ enum {
35674 ATA_DNXFER_QUIET = (1 << 31),
35675 };
35676
35677 -extern atomic_t ata_print_id;
35678 +extern atomic_unchecked_t ata_print_id;
35679 extern int atapi_passthru16;
35680 extern int libata_fua;
35681 extern int libata_noacpi;
35682 diff --git a/drivers/ata/pata_arasan_cf.c b/drivers/ata/pata_arasan_cf.c
35683 index 73492dd..ca2bff5 100644
35684 --- a/drivers/ata/pata_arasan_cf.c
35685 +++ b/drivers/ata/pata_arasan_cf.c
35686 @@ -865,7 +865,9 @@ static int arasan_cf_probe(struct platform_device *pdev)
35687 /* Handle platform specific quirks */
35688 if (quirk) {
35689 if (quirk & CF_BROKEN_PIO) {
35690 - ap->ops->set_piomode = NULL;
35691 + pax_open_kernel();
35692 + *(void **)&ap->ops->set_piomode = NULL;
35693 + pax_close_kernel();
35694 ap->pio_mask = 0;
35695 }
35696 if (quirk & CF_BROKEN_MWDMA)
35697 diff --git a/drivers/atm/adummy.c b/drivers/atm/adummy.c
35698 index f9b983a..887b9d8 100644
35699 --- a/drivers/atm/adummy.c
35700 +++ b/drivers/atm/adummy.c
35701 @@ -114,7 +114,7 @@ adummy_send(struct atm_vcc *vcc, struct sk_buff *skb)
35702 vcc->pop(vcc, skb);
35703 else
35704 dev_kfree_skb_any(skb);
35705 - atomic_inc(&vcc->stats->tx);
35706 + atomic_inc_unchecked(&vcc->stats->tx);
35707
35708 return 0;
35709 }
35710 diff --git a/drivers/atm/ambassador.c b/drivers/atm/ambassador.c
35711 index 62a7607..cc4be104 100644
35712 --- a/drivers/atm/ambassador.c
35713 +++ b/drivers/atm/ambassador.c
35714 @@ -454,7 +454,7 @@ static void tx_complete (amb_dev * dev, tx_out * tx) {
35715 PRINTD (DBG_FLOW|DBG_TX, "tx_complete %p %p", dev, tx);
35716
35717 // VC layer stats
35718 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35719 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35720
35721 // free the descriptor
35722 kfree (tx_descr);
35723 @@ -495,7 +495,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
35724 dump_skb ("<<<", vc, skb);
35725
35726 // VC layer stats
35727 - atomic_inc(&atm_vcc->stats->rx);
35728 + atomic_inc_unchecked(&atm_vcc->stats->rx);
35729 __net_timestamp(skb);
35730 // end of our responsibility
35731 atm_vcc->push (atm_vcc, skb);
35732 @@ -510,7 +510,7 @@ static void rx_complete (amb_dev * dev, rx_out * rx) {
35733 } else {
35734 PRINTK (KERN_INFO, "dropped over-size frame");
35735 // should we count this?
35736 - atomic_inc(&atm_vcc->stats->rx_drop);
35737 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35738 }
35739
35740 } else {
35741 @@ -1338,7 +1338,7 @@ static int amb_send (struct atm_vcc * atm_vcc, struct sk_buff * skb) {
35742 }
35743
35744 if (check_area (skb->data, skb->len)) {
35745 - atomic_inc(&atm_vcc->stats->tx_err);
35746 + atomic_inc_unchecked(&atm_vcc->stats->tx_err);
35747 return -ENOMEM; // ?
35748 }
35749
35750 diff --git a/drivers/atm/atmtcp.c b/drivers/atm/atmtcp.c
35751 index 0e3f8f9..765a7a5 100644
35752 --- a/drivers/atm/atmtcp.c
35753 +++ b/drivers/atm/atmtcp.c
35754 @@ -206,7 +206,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35755 if (vcc->pop) vcc->pop(vcc,skb);
35756 else dev_kfree_skb(skb);
35757 if (dev_data) return 0;
35758 - atomic_inc(&vcc->stats->tx_err);
35759 + atomic_inc_unchecked(&vcc->stats->tx_err);
35760 return -ENOLINK;
35761 }
35762 size = skb->len+sizeof(struct atmtcp_hdr);
35763 @@ -214,7 +214,7 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35764 if (!new_skb) {
35765 if (vcc->pop) vcc->pop(vcc,skb);
35766 else dev_kfree_skb(skb);
35767 - atomic_inc(&vcc->stats->tx_err);
35768 + atomic_inc_unchecked(&vcc->stats->tx_err);
35769 return -ENOBUFS;
35770 }
35771 hdr = (void *) skb_put(new_skb,sizeof(struct atmtcp_hdr));
35772 @@ -225,8 +225,8 @@ static int atmtcp_v_send(struct atm_vcc *vcc,struct sk_buff *skb)
35773 if (vcc->pop) vcc->pop(vcc,skb);
35774 else dev_kfree_skb(skb);
35775 out_vcc->push(out_vcc,new_skb);
35776 - atomic_inc(&vcc->stats->tx);
35777 - atomic_inc(&out_vcc->stats->rx);
35778 + atomic_inc_unchecked(&vcc->stats->tx);
35779 + atomic_inc_unchecked(&out_vcc->stats->rx);
35780 return 0;
35781 }
35782
35783 @@ -299,7 +299,7 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
35784 out_vcc = find_vcc(dev, ntohs(hdr->vpi), ntohs(hdr->vci));
35785 read_unlock(&vcc_sklist_lock);
35786 if (!out_vcc) {
35787 - atomic_inc(&vcc->stats->tx_err);
35788 + atomic_inc_unchecked(&vcc->stats->tx_err);
35789 goto done;
35790 }
35791 skb_pull(skb,sizeof(struct atmtcp_hdr));
35792 @@ -311,8 +311,8 @@ static int atmtcp_c_send(struct atm_vcc *vcc,struct sk_buff *skb)
35793 __net_timestamp(new_skb);
35794 skb_copy_from_linear_data(skb, skb_put(new_skb, skb->len), skb->len);
35795 out_vcc->push(out_vcc,new_skb);
35796 - atomic_inc(&vcc->stats->tx);
35797 - atomic_inc(&out_vcc->stats->rx);
35798 + atomic_inc_unchecked(&vcc->stats->tx);
35799 + atomic_inc_unchecked(&out_vcc->stats->rx);
35800 done:
35801 if (vcc->pop) vcc->pop(vcc,skb);
35802 else dev_kfree_skb(skb);
35803 diff --git a/drivers/atm/eni.c b/drivers/atm/eni.c
35804 index b1955ba..b179940 100644
35805 --- a/drivers/atm/eni.c
35806 +++ b/drivers/atm/eni.c
35807 @@ -522,7 +522,7 @@ static int rx_aal0(struct atm_vcc *vcc)
35808 DPRINTK(DEV_LABEL "(itf %d): trashing empty cell\n",
35809 vcc->dev->number);
35810 length = 0;
35811 - atomic_inc(&vcc->stats->rx_err);
35812 + atomic_inc_unchecked(&vcc->stats->rx_err);
35813 }
35814 else {
35815 length = ATM_CELL_SIZE-1; /* no HEC */
35816 @@ -577,7 +577,7 @@ static int rx_aal5(struct atm_vcc *vcc)
35817 size);
35818 }
35819 eff = length = 0;
35820 - atomic_inc(&vcc->stats->rx_err);
35821 + atomic_inc_unchecked(&vcc->stats->rx_err);
35822 }
35823 else {
35824 size = (descr & MID_RED_COUNT)*(ATM_CELL_PAYLOAD >> 2);
35825 @@ -594,7 +594,7 @@ static int rx_aal5(struct atm_vcc *vcc)
35826 "(VCI=%d,length=%ld,size=%ld (descr 0x%lx))\n",
35827 vcc->dev->number,vcc->vci,length,size << 2,descr);
35828 length = eff = 0;
35829 - atomic_inc(&vcc->stats->rx_err);
35830 + atomic_inc_unchecked(&vcc->stats->rx_err);
35831 }
35832 }
35833 skb = eff ? atm_alloc_charge(vcc,eff << 2,GFP_ATOMIC) : NULL;
35834 @@ -767,7 +767,7 @@ rx_dequeued++;
35835 vcc->push(vcc,skb);
35836 pushed++;
35837 }
35838 - atomic_inc(&vcc->stats->rx);
35839 + atomic_inc_unchecked(&vcc->stats->rx);
35840 }
35841 wake_up(&eni_dev->rx_wait);
35842 }
35843 @@ -1227,7 +1227,7 @@ static void dequeue_tx(struct atm_dev *dev)
35844 PCI_DMA_TODEVICE);
35845 if (vcc->pop) vcc->pop(vcc,skb);
35846 else dev_kfree_skb_irq(skb);
35847 - atomic_inc(&vcc->stats->tx);
35848 + atomic_inc_unchecked(&vcc->stats->tx);
35849 wake_up(&eni_dev->tx_wait);
35850 dma_complete++;
35851 }
35852 diff --git a/drivers/atm/firestream.c b/drivers/atm/firestream.c
35853 index b41c948..a002b17 100644
35854 --- a/drivers/atm/firestream.c
35855 +++ b/drivers/atm/firestream.c
35856 @@ -749,7 +749,7 @@ static void process_txdone_queue (struct fs_dev *dev, struct queue *q)
35857 }
35858 }
35859
35860 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
35861 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
35862
35863 fs_dprintk (FS_DEBUG_TXMEM, "i");
35864 fs_dprintk (FS_DEBUG_ALLOC, "Free t-skb: %p\n", skb);
35865 @@ -816,7 +816,7 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
35866 #endif
35867 skb_put (skb, qe->p1 & 0xffff);
35868 ATM_SKB(skb)->vcc = atm_vcc;
35869 - atomic_inc(&atm_vcc->stats->rx);
35870 + atomic_inc_unchecked(&atm_vcc->stats->rx);
35871 __net_timestamp(skb);
35872 fs_dprintk (FS_DEBUG_ALLOC, "Free rec-skb: %p (pushed)\n", skb);
35873 atm_vcc->push (atm_vcc, skb);
35874 @@ -837,12 +837,12 @@ static void process_incoming (struct fs_dev *dev, struct queue *q)
35875 kfree (pe);
35876 }
35877 if (atm_vcc)
35878 - atomic_inc(&atm_vcc->stats->rx_drop);
35879 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35880 break;
35881 case 0x1f: /* Reassembly abort: no buffers. */
35882 /* Silently increment error counter. */
35883 if (atm_vcc)
35884 - atomic_inc(&atm_vcc->stats->rx_drop);
35885 + atomic_inc_unchecked(&atm_vcc->stats->rx_drop);
35886 break;
35887 default: /* Hmm. Haven't written the code to handle the others yet... -- REW */
35888 printk (KERN_WARNING "Don't know what to do with RX status %x: %s.\n",
35889 diff --git a/drivers/atm/fore200e.c b/drivers/atm/fore200e.c
35890 index 204814e..cede831 100644
35891 --- a/drivers/atm/fore200e.c
35892 +++ b/drivers/atm/fore200e.c
35893 @@ -931,9 +931,9 @@ fore200e_tx_irq(struct fore200e* fore200e)
35894 #endif
35895 /* check error condition */
35896 if (*entry->status & STATUS_ERROR)
35897 - atomic_inc(&vcc->stats->tx_err);
35898 + atomic_inc_unchecked(&vcc->stats->tx_err);
35899 else
35900 - atomic_inc(&vcc->stats->tx);
35901 + atomic_inc_unchecked(&vcc->stats->tx);
35902 }
35903 }
35904
35905 @@ -1082,7 +1082,7 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35906 if (skb == NULL) {
35907 DPRINTK(2, "unable to alloc new skb, rx PDU length = %d\n", pdu_len);
35908
35909 - atomic_inc(&vcc->stats->rx_drop);
35910 + atomic_inc_unchecked(&vcc->stats->rx_drop);
35911 return -ENOMEM;
35912 }
35913
35914 @@ -1125,14 +1125,14 @@ fore200e_push_rpd(struct fore200e* fore200e, struct atm_vcc* vcc, struct rpd* rp
35915
35916 dev_kfree_skb_any(skb);
35917
35918 - atomic_inc(&vcc->stats->rx_drop);
35919 + atomic_inc_unchecked(&vcc->stats->rx_drop);
35920 return -ENOMEM;
35921 }
35922
35923 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35924
35925 vcc->push(vcc, skb);
35926 - atomic_inc(&vcc->stats->rx);
35927 + atomic_inc_unchecked(&vcc->stats->rx);
35928
35929 ASSERT(atomic_read(&sk_atm(vcc)->sk_wmem_alloc) >= 0);
35930
35931 @@ -1210,7 +1210,7 @@ fore200e_rx_irq(struct fore200e* fore200e)
35932 DPRINTK(2, "damaged PDU on %d.%d.%d\n",
35933 fore200e->atm_dev->number,
35934 entry->rpd->atm_header.vpi, entry->rpd->atm_header.vci);
35935 - atomic_inc(&vcc->stats->rx_err);
35936 + atomic_inc_unchecked(&vcc->stats->rx_err);
35937 }
35938 }
35939
35940 @@ -1655,7 +1655,7 @@ fore200e_send(struct atm_vcc *vcc, struct sk_buff *skb)
35941 goto retry_here;
35942 }
35943
35944 - atomic_inc(&vcc->stats->tx_err);
35945 + atomic_inc_unchecked(&vcc->stats->tx_err);
35946
35947 fore200e->tx_sat++;
35948 DPRINTK(2, "tx queue of device %s is saturated, PDU dropped - heartbeat is %08x\n",
35949 diff --git a/drivers/atm/he.c b/drivers/atm/he.c
35950 index 8557adc..3fb5d55 100644
35951 --- a/drivers/atm/he.c
35952 +++ b/drivers/atm/he.c
35953 @@ -1691,7 +1691,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35954
35955 if (RBRQ_HBUF_ERR(he_dev->rbrq_head)) {
35956 hprintk("HBUF_ERR! (cid 0x%x)\n", cid);
35957 - atomic_inc(&vcc->stats->rx_drop);
35958 + atomic_inc_unchecked(&vcc->stats->rx_drop);
35959 goto return_host_buffers;
35960 }
35961
35962 @@ -1718,7 +1718,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35963 RBRQ_LEN_ERR(he_dev->rbrq_head)
35964 ? "LEN_ERR" : "",
35965 vcc->vpi, vcc->vci);
35966 - atomic_inc(&vcc->stats->rx_err);
35967 + atomic_inc_unchecked(&vcc->stats->rx_err);
35968 goto return_host_buffers;
35969 }
35970
35971 @@ -1770,7 +1770,7 @@ he_service_rbrq(struct he_dev *he_dev, int group)
35972 vcc->push(vcc, skb);
35973 spin_lock(&he_dev->global_lock);
35974
35975 - atomic_inc(&vcc->stats->rx);
35976 + atomic_inc_unchecked(&vcc->stats->rx);
35977
35978 return_host_buffers:
35979 ++pdus_assembled;
35980 @@ -2096,7 +2096,7 @@ __enqueue_tpd(struct he_dev *he_dev, struct he_tpd *tpd, unsigned cid)
35981 tpd->vcc->pop(tpd->vcc, tpd->skb);
35982 else
35983 dev_kfree_skb_any(tpd->skb);
35984 - atomic_inc(&tpd->vcc->stats->tx_err);
35985 + atomic_inc_unchecked(&tpd->vcc->stats->tx_err);
35986 }
35987 pci_pool_free(he_dev->tpd_pool, tpd, TPD_ADDR(tpd->status));
35988 return;
35989 @@ -2508,7 +2508,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35990 vcc->pop(vcc, skb);
35991 else
35992 dev_kfree_skb_any(skb);
35993 - atomic_inc(&vcc->stats->tx_err);
35994 + atomic_inc_unchecked(&vcc->stats->tx_err);
35995 return -EINVAL;
35996 }
35997
35998 @@ -2519,7 +2519,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
35999 vcc->pop(vcc, skb);
36000 else
36001 dev_kfree_skb_any(skb);
36002 - atomic_inc(&vcc->stats->tx_err);
36003 + atomic_inc_unchecked(&vcc->stats->tx_err);
36004 return -EINVAL;
36005 }
36006 #endif
36007 @@ -2531,7 +2531,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36008 vcc->pop(vcc, skb);
36009 else
36010 dev_kfree_skb_any(skb);
36011 - atomic_inc(&vcc->stats->tx_err);
36012 + atomic_inc_unchecked(&vcc->stats->tx_err);
36013 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36014 return -ENOMEM;
36015 }
36016 @@ -2573,7 +2573,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36017 vcc->pop(vcc, skb);
36018 else
36019 dev_kfree_skb_any(skb);
36020 - atomic_inc(&vcc->stats->tx_err);
36021 + atomic_inc_unchecked(&vcc->stats->tx_err);
36022 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36023 return -ENOMEM;
36024 }
36025 @@ -2604,7 +2604,7 @@ he_send(struct atm_vcc *vcc, struct sk_buff *skb)
36026 __enqueue_tpd(he_dev, tpd, cid);
36027 spin_unlock_irqrestore(&he_dev->global_lock, flags);
36028
36029 - atomic_inc(&vcc->stats->tx);
36030 + atomic_inc_unchecked(&vcc->stats->tx);
36031
36032 return 0;
36033 }
36034 diff --git a/drivers/atm/horizon.c b/drivers/atm/horizon.c
36035 index 1dc0519..1aadaf7 100644
36036 --- a/drivers/atm/horizon.c
36037 +++ b/drivers/atm/horizon.c
36038 @@ -1034,7 +1034,7 @@ static void rx_schedule (hrz_dev * dev, int irq) {
36039 {
36040 struct atm_vcc * vcc = ATM_SKB(skb)->vcc;
36041 // VC layer stats
36042 - atomic_inc(&vcc->stats->rx);
36043 + atomic_inc_unchecked(&vcc->stats->rx);
36044 __net_timestamp(skb);
36045 // end of our responsibility
36046 vcc->push (vcc, skb);
36047 @@ -1186,7 +1186,7 @@ static void tx_schedule (hrz_dev * const dev, int irq) {
36048 dev->tx_iovec = NULL;
36049
36050 // VC layer stats
36051 - atomic_inc(&ATM_SKB(skb)->vcc->stats->tx);
36052 + atomic_inc_unchecked(&ATM_SKB(skb)->vcc->stats->tx);
36053
36054 // free the skb
36055 hrz_kfree_skb (skb);
36056 diff --git a/drivers/atm/idt77252.c b/drivers/atm/idt77252.c
36057 index 1bdf104..9dc44b1 100644
36058 --- a/drivers/atm/idt77252.c
36059 +++ b/drivers/atm/idt77252.c
36060 @@ -812,7 +812,7 @@ drain_scq(struct idt77252_dev *card, struct vc_map *vc)
36061 else
36062 dev_kfree_skb(skb);
36063
36064 - atomic_inc(&vcc->stats->tx);
36065 + atomic_inc_unchecked(&vcc->stats->tx);
36066 }
36067
36068 atomic_dec(&scq->used);
36069 @@ -1075,13 +1075,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36070 if ((sb = dev_alloc_skb(64)) == NULL) {
36071 printk("%s: Can't allocate buffers for aal0.\n",
36072 card->name);
36073 - atomic_add(i, &vcc->stats->rx_drop);
36074 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36075 break;
36076 }
36077 if (!atm_charge(vcc, sb->truesize)) {
36078 RXPRINTK("%s: atm_charge() dropped aal0 packets.\n",
36079 card->name);
36080 - atomic_add(i - 1, &vcc->stats->rx_drop);
36081 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop);
36082 dev_kfree_skb(sb);
36083 break;
36084 }
36085 @@ -1098,7 +1098,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36086 ATM_SKB(sb)->vcc = vcc;
36087 __net_timestamp(sb);
36088 vcc->push(vcc, sb);
36089 - atomic_inc(&vcc->stats->rx);
36090 + atomic_inc_unchecked(&vcc->stats->rx);
36091
36092 cell += ATM_CELL_PAYLOAD;
36093 }
36094 @@ -1135,13 +1135,13 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36095 "(CDC: %08x)\n",
36096 card->name, len, rpp->len, readl(SAR_REG_CDC));
36097 recycle_rx_pool_skb(card, rpp);
36098 - atomic_inc(&vcc->stats->rx_err);
36099 + atomic_inc_unchecked(&vcc->stats->rx_err);
36100 return;
36101 }
36102 if (stat & SAR_RSQE_CRC) {
36103 RXPRINTK("%s: AAL5 CRC error.\n", card->name);
36104 recycle_rx_pool_skb(card, rpp);
36105 - atomic_inc(&vcc->stats->rx_err);
36106 + atomic_inc_unchecked(&vcc->stats->rx_err);
36107 return;
36108 }
36109 if (skb_queue_len(&rpp->queue) > 1) {
36110 @@ -1152,7 +1152,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36111 RXPRINTK("%s: Can't alloc RX skb.\n",
36112 card->name);
36113 recycle_rx_pool_skb(card, rpp);
36114 - atomic_inc(&vcc->stats->rx_err);
36115 + atomic_inc_unchecked(&vcc->stats->rx_err);
36116 return;
36117 }
36118 if (!atm_charge(vcc, skb->truesize)) {
36119 @@ -1171,7 +1171,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36120 __net_timestamp(skb);
36121
36122 vcc->push(vcc, skb);
36123 - atomic_inc(&vcc->stats->rx);
36124 + atomic_inc_unchecked(&vcc->stats->rx);
36125
36126 return;
36127 }
36128 @@ -1193,7 +1193,7 @@ dequeue_rx(struct idt77252_dev *card, struct rsq_entry *rsqe)
36129 __net_timestamp(skb);
36130
36131 vcc->push(vcc, skb);
36132 - atomic_inc(&vcc->stats->rx);
36133 + atomic_inc_unchecked(&vcc->stats->rx);
36134
36135 if (skb->truesize > SAR_FB_SIZE_3)
36136 add_rx_skb(card, 3, SAR_FB_SIZE_3, 1);
36137 @@ -1304,14 +1304,14 @@ idt77252_rx_raw(struct idt77252_dev *card)
36138 if (vcc->qos.aal != ATM_AAL0) {
36139 RPRINTK("%s: raw cell for non AAL0 vc %u.%u\n",
36140 card->name, vpi, vci);
36141 - atomic_inc(&vcc->stats->rx_drop);
36142 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36143 goto drop;
36144 }
36145
36146 if ((sb = dev_alloc_skb(64)) == NULL) {
36147 printk("%s: Can't allocate buffers for AAL0.\n",
36148 card->name);
36149 - atomic_inc(&vcc->stats->rx_err);
36150 + atomic_inc_unchecked(&vcc->stats->rx_err);
36151 goto drop;
36152 }
36153
36154 @@ -1330,7 +1330,7 @@ idt77252_rx_raw(struct idt77252_dev *card)
36155 ATM_SKB(sb)->vcc = vcc;
36156 __net_timestamp(sb);
36157 vcc->push(vcc, sb);
36158 - atomic_inc(&vcc->stats->rx);
36159 + atomic_inc_unchecked(&vcc->stats->rx);
36160
36161 drop:
36162 skb_pull(queue, 64);
36163 @@ -1955,13 +1955,13 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36164
36165 if (vc == NULL) {
36166 printk("%s: NULL connection in send().\n", card->name);
36167 - atomic_inc(&vcc->stats->tx_err);
36168 + atomic_inc_unchecked(&vcc->stats->tx_err);
36169 dev_kfree_skb(skb);
36170 return -EINVAL;
36171 }
36172 if (!test_bit(VCF_TX, &vc->flags)) {
36173 printk("%s: Trying to transmit on a non-tx VC.\n", card->name);
36174 - atomic_inc(&vcc->stats->tx_err);
36175 + atomic_inc_unchecked(&vcc->stats->tx_err);
36176 dev_kfree_skb(skb);
36177 return -EINVAL;
36178 }
36179 @@ -1973,14 +1973,14 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36180 break;
36181 default:
36182 printk("%s: Unsupported AAL: %d\n", card->name, vcc->qos.aal);
36183 - atomic_inc(&vcc->stats->tx_err);
36184 + atomic_inc_unchecked(&vcc->stats->tx_err);
36185 dev_kfree_skb(skb);
36186 return -EINVAL;
36187 }
36188
36189 if (skb_shinfo(skb)->nr_frags != 0) {
36190 printk("%s: No scatter-gather yet.\n", card->name);
36191 - atomic_inc(&vcc->stats->tx_err);
36192 + atomic_inc_unchecked(&vcc->stats->tx_err);
36193 dev_kfree_skb(skb);
36194 return -EINVAL;
36195 }
36196 @@ -1988,7 +1988,7 @@ idt77252_send_skb(struct atm_vcc *vcc, struct sk_buff *skb, int oam)
36197
36198 err = queue_skb(card, vc, skb, oam);
36199 if (err) {
36200 - atomic_inc(&vcc->stats->tx_err);
36201 + atomic_inc_unchecked(&vcc->stats->tx_err);
36202 dev_kfree_skb(skb);
36203 return err;
36204 }
36205 @@ -2011,7 +2011,7 @@ idt77252_send_oam(struct atm_vcc *vcc, void *cell, int flags)
36206 skb = dev_alloc_skb(64);
36207 if (!skb) {
36208 printk("%s: Out of memory in send_oam().\n", card->name);
36209 - atomic_inc(&vcc->stats->tx_err);
36210 + atomic_inc_unchecked(&vcc->stats->tx_err);
36211 return -ENOMEM;
36212 }
36213 atomic_add(skb->truesize, &sk_atm(vcc)->sk_wmem_alloc);
36214 diff --git a/drivers/atm/iphase.c b/drivers/atm/iphase.c
36215 index 4217f29..88f547a 100644
36216 --- a/drivers/atm/iphase.c
36217 +++ b/drivers/atm/iphase.c
36218 @@ -1145,7 +1145,7 @@ static int rx_pkt(struct atm_dev *dev)
36219 status = (u_short) (buf_desc_ptr->desc_mode);
36220 if (status & (RX_CER | RX_PTE | RX_OFL))
36221 {
36222 - atomic_inc(&vcc->stats->rx_err);
36223 + atomic_inc_unchecked(&vcc->stats->rx_err);
36224 IF_ERR(printk("IA: bad packet, dropping it");)
36225 if (status & RX_CER) {
36226 IF_ERR(printk(" cause: packet CRC error\n");)
36227 @@ -1168,7 +1168,7 @@ static int rx_pkt(struct atm_dev *dev)
36228 len = dma_addr - buf_addr;
36229 if (len > iadev->rx_buf_sz) {
36230 printk("Over %d bytes sdu received, dropped!!!\n", iadev->rx_buf_sz);
36231 - atomic_inc(&vcc->stats->rx_err);
36232 + atomic_inc_unchecked(&vcc->stats->rx_err);
36233 goto out_free_desc;
36234 }
36235
36236 @@ -1318,7 +1318,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36237 ia_vcc = INPH_IA_VCC(vcc);
36238 if (ia_vcc == NULL)
36239 {
36240 - atomic_inc(&vcc->stats->rx_err);
36241 + atomic_inc_unchecked(&vcc->stats->rx_err);
36242 atm_return(vcc, skb->truesize);
36243 dev_kfree_skb_any(skb);
36244 goto INCR_DLE;
36245 @@ -1330,7 +1330,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36246 if ((length > iadev->rx_buf_sz) || (length >
36247 (skb->len - sizeof(struct cpcs_trailer))))
36248 {
36249 - atomic_inc(&vcc->stats->rx_err);
36250 + atomic_inc_unchecked(&vcc->stats->rx_err);
36251 IF_ERR(printk("rx_dle_intr: Bad AAL5 trailer %d (skb len %d)",
36252 length, skb->len);)
36253 atm_return(vcc, skb->truesize);
36254 @@ -1346,7 +1346,7 @@ static void rx_dle_intr(struct atm_dev *dev)
36255
36256 IF_RX(printk("rx_dle_intr: skb push");)
36257 vcc->push(vcc,skb);
36258 - atomic_inc(&vcc->stats->rx);
36259 + atomic_inc_unchecked(&vcc->stats->rx);
36260 iadev->rx_pkt_cnt++;
36261 }
36262 INCR_DLE:
36263 @@ -2826,15 +2826,15 @@ static int ia_ioctl(struct atm_dev *dev, unsigned int cmd, void __user *arg)
36264 {
36265 struct k_sonet_stats *stats;
36266 stats = &PRIV(_ia_dev[board])->sonet_stats;
36267 - printk("section_bip: %d\n", atomic_read(&stats->section_bip));
36268 - printk("line_bip : %d\n", atomic_read(&stats->line_bip));
36269 - printk("path_bip : %d\n", atomic_read(&stats->path_bip));
36270 - printk("line_febe : %d\n", atomic_read(&stats->line_febe));
36271 - printk("path_febe : %d\n", atomic_read(&stats->path_febe));
36272 - printk("corr_hcs : %d\n", atomic_read(&stats->corr_hcs));
36273 - printk("uncorr_hcs : %d\n", atomic_read(&stats->uncorr_hcs));
36274 - printk("tx_cells : %d\n", atomic_read(&stats->tx_cells));
36275 - printk("rx_cells : %d\n", atomic_read(&stats->rx_cells));
36276 + printk("section_bip: %d\n", atomic_read_unchecked(&stats->section_bip));
36277 + printk("line_bip : %d\n", atomic_read_unchecked(&stats->line_bip));
36278 + printk("path_bip : %d\n", atomic_read_unchecked(&stats->path_bip));
36279 + printk("line_febe : %d\n", atomic_read_unchecked(&stats->line_febe));
36280 + printk("path_febe : %d\n", atomic_read_unchecked(&stats->path_febe));
36281 + printk("corr_hcs : %d\n", atomic_read_unchecked(&stats->corr_hcs));
36282 + printk("uncorr_hcs : %d\n", atomic_read_unchecked(&stats->uncorr_hcs));
36283 + printk("tx_cells : %d\n", atomic_read_unchecked(&stats->tx_cells));
36284 + printk("rx_cells : %d\n", atomic_read_unchecked(&stats->rx_cells));
36285 }
36286 ia_cmds.status = 0;
36287 break;
36288 @@ -2939,7 +2939,7 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36289 if ((desc == 0) || (desc > iadev->num_tx_desc))
36290 {
36291 IF_ERR(printk(DEV_LABEL "invalid desc for send: %d\n", desc);)
36292 - atomic_inc(&vcc->stats->tx);
36293 + atomic_inc_unchecked(&vcc->stats->tx);
36294 if (vcc->pop)
36295 vcc->pop(vcc, skb);
36296 else
36297 @@ -3044,14 +3044,14 @@ static int ia_pkt_tx (struct atm_vcc *vcc, struct sk_buff *skb) {
36298 ATM_DESC(skb) = vcc->vci;
36299 skb_queue_tail(&iadev->tx_dma_q, skb);
36300
36301 - atomic_inc(&vcc->stats->tx);
36302 + atomic_inc_unchecked(&vcc->stats->tx);
36303 iadev->tx_pkt_cnt++;
36304 /* Increment transaction counter */
36305 writel(2, iadev->dma+IPHASE5575_TX_COUNTER);
36306
36307 #if 0
36308 /* add flow control logic */
36309 - if (atomic_read(&vcc->stats->tx) % 20 == 0) {
36310 + if (atomic_read_unchecked(&vcc->stats->tx) % 20 == 0) {
36311 if (iavcc->vc_desc_cnt > 10) {
36312 vcc->tx_quota = vcc->tx_quota * 3 / 4;
36313 printk("Tx1: vcc->tx_quota = %d \n", (u32)vcc->tx_quota );
36314 diff --git a/drivers/atm/lanai.c b/drivers/atm/lanai.c
36315 index fa7d701..1e404c7 100644
36316 --- a/drivers/atm/lanai.c
36317 +++ b/drivers/atm/lanai.c
36318 @@ -1303,7 +1303,7 @@ static void lanai_send_one_aal5(struct lanai_dev *lanai,
36319 vcc_tx_add_aal5_trailer(lvcc, skb->len, 0, 0);
36320 lanai_endtx(lanai, lvcc);
36321 lanai_free_skb(lvcc->tx.atmvcc, skb);
36322 - atomic_inc(&lvcc->tx.atmvcc->stats->tx);
36323 + atomic_inc_unchecked(&lvcc->tx.atmvcc->stats->tx);
36324 }
36325
36326 /* Try to fill the buffer - don't call unless there is backlog */
36327 @@ -1426,7 +1426,7 @@ static void vcc_rx_aal5(struct lanai_vcc *lvcc, int endptr)
36328 ATM_SKB(skb)->vcc = lvcc->rx.atmvcc;
36329 __net_timestamp(skb);
36330 lvcc->rx.atmvcc->push(lvcc->rx.atmvcc, skb);
36331 - atomic_inc(&lvcc->rx.atmvcc->stats->rx);
36332 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx);
36333 out:
36334 lvcc->rx.buf.ptr = end;
36335 cardvcc_write(lvcc, endptr, vcc_rxreadptr);
36336 @@ -1667,7 +1667,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36337 DPRINTK("(itf %d) got RX service entry 0x%X for non-AAL5 "
36338 "vcc %d\n", lanai->number, (unsigned int) s, vci);
36339 lanai->stats.service_rxnotaal5++;
36340 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36341 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36342 return 0;
36343 }
36344 if (likely(!(s & (SERVICE_TRASH | SERVICE_STREAM | SERVICE_CRCERR)))) {
36345 @@ -1679,7 +1679,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36346 int bytes;
36347 read_unlock(&vcc_sklist_lock);
36348 DPRINTK("got trashed rx pdu on vci %d\n", vci);
36349 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36350 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36351 lvcc->stats.x.aal5.service_trash++;
36352 bytes = (SERVICE_GET_END(s) * 16) -
36353 (((unsigned long) lvcc->rx.buf.ptr) -
36354 @@ -1691,7 +1691,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36355 }
36356 if (s & SERVICE_STREAM) {
36357 read_unlock(&vcc_sklist_lock);
36358 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36359 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36360 lvcc->stats.x.aal5.service_stream++;
36361 printk(KERN_ERR DEV_LABEL "(itf %d): Got AAL5 stream "
36362 "PDU on VCI %d!\n", lanai->number, vci);
36363 @@ -1699,7 +1699,7 @@ static int handle_service(struct lanai_dev *lanai, u32 s)
36364 return 0;
36365 }
36366 DPRINTK("got rx crc error on vci %d\n", vci);
36367 - atomic_inc(&lvcc->rx.atmvcc->stats->rx_err);
36368 + atomic_inc_unchecked(&lvcc->rx.atmvcc->stats->rx_err);
36369 lvcc->stats.x.aal5.service_rxcrc++;
36370 lvcc->rx.buf.ptr = &lvcc->rx.buf.start[SERVICE_GET_END(s) * 4];
36371 cardvcc_write(lvcc, SERVICE_GET_END(s), vcc_rxreadptr);
36372 diff --git a/drivers/atm/nicstar.c b/drivers/atm/nicstar.c
36373 index 5aca5f4..ce3a6b0 100644
36374 --- a/drivers/atm/nicstar.c
36375 +++ b/drivers/atm/nicstar.c
36376 @@ -1640,7 +1640,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36377 if ((vc = (vc_map *) vcc->dev_data) == NULL) {
36378 printk("nicstar%d: vcc->dev_data == NULL on ns_send().\n",
36379 card->index);
36380 - atomic_inc(&vcc->stats->tx_err);
36381 + atomic_inc_unchecked(&vcc->stats->tx_err);
36382 dev_kfree_skb_any(skb);
36383 return -EINVAL;
36384 }
36385 @@ -1648,7 +1648,7 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36386 if (!vc->tx) {
36387 printk("nicstar%d: Trying to transmit on a non-tx VC.\n",
36388 card->index);
36389 - atomic_inc(&vcc->stats->tx_err);
36390 + atomic_inc_unchecked(&vcc->stats->tx_err);
36391 dev_kfree_skb_any(skb);
36392 return -EINVAL;
36393 }
36394 @@ -1656,14 +1656,14 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36395 if (vcc->qos.aal != ATM_AAL5 && vcc->qos.aal != ATM_AAL0) {
36396 printk("nicstar%d: Only AAL0 and AAL5 are supported.\n",
36397 card->index);
36398 - atomic_inc(&vcc->stats->tx_err);
36399 + atomic_inc_unchecked(&vcc->stats->tx_err);
36400 dev_kfree_skb_any(skb);
36401 return -EINVAL;
36402 }
36403
36404 if (skb_shinfo(skb)->nr_frags != 0) {
36405 printk("nicstar%d: No scatter-gather yet.\n", card->index);
36406 - atomic_inc(&vcc->stats->tx_err);
36407 + atomic_inc_unchecked(&vcc->stats->tx_err);
36408 dev_kfree_skb_any(skb);
36409 return -EINVAL;
36410 }
36411 @@ -1711,11 +1711,11 @@ static int ns_send(struct atm_vcc *vcc, struct sk_buff *skb)
36412 }
36413
36414 if (push_scqe(card, vc, scq, &scqe, skb) != 0) {
36415 - atomic_inc(&vcc->stats->tx_err);
36416 + atomic_inc_unchecked(&vcc->stats->tx_err);
36417 dev_kfree_skb_any(skb);
36418 return -EIO;
36419 }
36420 - atomic_inc(&vcc->stats->tx);
36421 + atomic_inc_unchecked(&vcc->stats->tx);
36422
36423 return 0;
36424 }
36425 @@ -2032,14 +2032,14 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36426 printk
36427 ("nicstar%d: Can't allocate buffers for aal0.\n",
36428 card->index);
36429 - atomic_add(i, &vcc->stats->rx_drop);
36430 + atomic_add_unchecked(i, &vcc->stats->rx_drop);
36431 break;
36432 }
36433 if (!atm_charge(vcc, sb->truesize)) {
36434 RXPRINTK
36435 ("nicstar%d: atm_charge() dropped aal0 packets.\n",
36436 card->index);
36437 - atomic_add(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36438 + atomic_add_unchecked(i - 1, &vcc->stats->rx_drop); /* already increased by 1 */
36439 dev_kfree_skb_any(sb);
36440 break;
36441 }
36442 @@ -2054,7 +2054,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36443 ATM_SKB(sb)->vcc = vcc;
36444 __net_timestamp(sb);
36445 vcc->push(vcc, sb);
36446 - atomic_inc(&vcc->stats->rx);
36447 + atomic_inc_unchecked(&vcc->stats->rx);
36448 cell += ATM_CELL_PAYLOAD;
36449 }
36450
36451 @@ -2071,7 +2071,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36452 if (iovb == NULL) {
36453 printk("nicstar%d: Out of iovec buffers.\n",
36454 card->index);
36455 - atomic_inc(&vcc->stats->rx_drop);
36456 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36457 recycle_rx_buf(card, skb);
36458 return;
36459 }
36460 @@ -2095,7 +2095,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36461 small or large buffer itself. */
36462 } else if (NS_PRV_IOVCNT(iovb) >= NS_MAX_IOVECS) {
36463 printk("nicstar%d: received too big AAL5 SDU.\n", card->index);
36464 - atomic_inc(&vcc->stats->rx_err);
36465 + atomic_inc_unchecked(&vcc->stats->rx_err);
36466 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36467 NS_MAX_IOVECS);
36468 NS_PRV_IOVCNT(iovb) = 0;
36469 @@ -2115,7 +2115,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36470 ("nicstar%d: Expected a small buffer, and this is not one.\n",
36471 card->index);
36472 which_list(card, skb);
36473 - atomic_inc(&vcc->stats->rx_err);
36474 + atomic_inc_unchecked(&vcc->stats->rx_err);
36475 recycle_rx_buf(card, skb);
36476 vc->rx_iov = NULL;
36477 recycle_iov_buf(card, iovb);
36478 @@ -2128,7 +2128,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36479 ("nicstar%d: Expected a large buffer, and this is not one.\n",
36480 card->index);
36481 which_list(card, skb);
36482 - atomic_inc(&vcc->stats->rx_err);
36483 + atomic_inc_unchecked(&vcc->stats->rx_err);
36484 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36485 NS_PRV_IOVCNT(iovb));
36486 vc->rx_iov = NULL;
36487 @@ -2151,7 +2151,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36488 printk(" - PDU size mismatch.\n");
36489 else
36490 printk(".\n");
36491 - atomic_inc(&vcc->stats->rx_err);
36492 + atomic_inc_unchecked(&vcc->stats->rx_err);
36493 recycle_iovec_rx_bufs(card, (struct iovec *)iovb->data,
36494 NS_PRV_IOVCNT(iovb));
36495 vc->rx_iov = NULL;
36496 @@ -2165,7 +2165,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36497 /* skb points to a small buffer */
36498 if (!atm_charge(vcc, skb->truesize)) {
36499 push_rxbufs(card, skb);
36500 - atomic_inc(&vcc->stats->rx_drop);
36501 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36502 } else {
36503 skb_put(skb, len);
36504 dequeue_sm_buf(card, skb);
36505 @@ -2175,7 +2175,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36506 ATM_SKB(skb)->vcc = vcc;
36507 __net_timestamp(skb);
36508 vcc->push(vcc, skb);
36509 - atomic_inc(&vcc->stats->rx);
36510 + atomic_inc_unchecked(&vcc->stats->rx);
36511 }
36512 } else if (NS_PRV_IOVCNT(iovb) == 2) { /* One small plus one large buffer */
36513 struct sk_buff *sb;
36514 @@ -2186,7 +2186,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36515 if (len <= NS_SMBUFSIZE) {
36516 if (!atm_charge(vcc, sb->truesize)) {
36517 push_rxbufs(card, sb);
36518 - atomic_inc(&vcc->stats->rx_drop);
36519 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36520 } else {
36521 skb_put(sb, len);
36522 dequeue_sm_buf(card, sb);
36523 @@ -2196,7 +2196,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36524 ATM_SKB(sb)->vcc = vcc;
36525 __net_timestamp(sb);
36526 vcc->push(vcc, sb);
36527 - atomic_inc(&vcc->stats->rx);
36528 + atomic_inc_unchecked(&vcc->stats->rx);
36529 }
36530
36531 push_rxbufs(card, skb);
36532 @@ -2205,7 +2205,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36533
36534 if (!atm_charge(vcc, skb->truesize)) {
36535 push_rxbufs(card, skb);
36536 - atomic_inc(&vcc->stats->rx_drop);
36537 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36538 } else {
36539 dequeue_lg_buf(card, skb);
36540 #ifdef NS_USE_DESTRUCTORS
36541 @@ -2218,7 +2218,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36542 ATM_SKB(skb)->vcc = vcc;
36543 __net_timestamp(skb);
36544 vcc->push(vcc, skb);
36545 - atomic_inc(&vcc->stats->rx);
36546 + atomic_inc_unchecked(&vcc->stats->rx);
36547 }
36548
36549 push_rxbufs(card, sb);
36550 @@ -2239,7 +2239,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36551 printk
36552 ("nicstar%d: Out of huge buffers.\n",
36553 card->index);
36554 - atomic_inc(&vcc->stats->rx_drop);
36555 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36556 recycle_iovec_rx_bufs(card,
36557 (struct iovec *)
36558 iovb->data,
36559 @@ -2290,7 +2290,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36560 card->hbpool.count++;
36561 } else
36562 dev_kfree_skb_any(hb);
36563 - atomic_inc(&vcc->stats->rx_drop);
36564 + atomic_inc_unchecked(&vcc->stats->rx_drop);
36565 } else {
36566 /* Copy the small buffer to the huge buffer */
36567 sb = (struct sk_buff *)iov->iov_base;
36568 @@ -2327,7 +2327,7 @@ static void dequeue_rx(ns_dev * card, ns_rsqe * rsqe)
36569 #endif /* NS_USE_DESTRUCTORS */
36570 __net_timestamp(hb);
36571 vcc->push(vcc, hb);
36572 - atomic_inc(&vcc->stats->rx);
36573 + atomic_inc_unchecked(&vcc->stats->rx);
36574 }
36575 }
36576
36577 diff --git a/drivers/atm/solos-pci.c b/drivers/atm/solos-pci.c
36578 index 32784d1..4a8434a 100644
36579 --- a/drivers/atm/solos-pci.c
36580 +++ b/drivers/atm/solos-pci.c
36581 @@ -838,7 +838,7 @@ void solos_bh(unsigned long card_arg)
36582 }
36583 atm_charge(vcc, skb->truesize);
36584 vcc->push(vcc, skb);
36585 - atomic_inc(&vcc->stats->rx);
36586 + atomic_inc_unchecked(&vcc->stats->rx);
36587 break;
36588
36589 case PKT_STATUS:
36590 @@ -1116,7 +1116,7 @@ static uint32_t fpga_tx(struct solos_card *card)
36591 vcc = SKB_CB(oldskb)->vcc;
36592
36593 if (vcc) {
36594 - atomic_inc(&vcc->stats->tx);
36595 + atomic_inc_unchecked(&vcc->stats->tx);
36596 solos_pop(vcc, oldskb);
36597 } else {
36598 dev_kfree_skb_irq(oldskb);
36599 diff --git a/drivers/atm/suni.c b/drivers/atm/suni.c
36600 index 0215934..ce9f5b1 100644
36601 --- a/drivers/atm/suni.c
36602 +++ b/drivers/atm/suni.c
36603 @@ -49,8 +49,8 @@ static DEFINE_SPINLOCK(sunis_lock);
36604
36605
36606 #define ADD_LIMITED(s,v) \
36607 - atomic_add((v),&stats->s); \
36608 - if (atomic_read(&stats->s) < 0) atomic_set(&stats->s,INT_MAX);
36609 + atomic_add_unchecked((v),&stats->s); \
36610 + if (atomic_read_unchecked(&stats->s) < 0) atomic_set_unchecked(&stats->s,INT_MAX);
36611
36612
36613 static void suni_hz(unsigned long from_timer)
36614 diff --git a/drivers/atm/uPD98402.c b/drivers/atm/uPD98402.c
36615 index 5120a96..e2572bd 100644
36616 --- a/drivers/atm/uPD98402.c
36617 +++ b/drivers/atm/uPD98402.c
36618 @@ -42,7 +42,7 @@ static int fetch_stats(struct atm_dev *dev,struct sonet_stats __user *arg,int ze
36619 struct sonet_stats tmp;
36620 int error = 0;
36621
36622 - atomic_add(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
36623 + atomic_add_unchecked(GET(HECCT),&PRIV(dev)->sonet_stats.uncorr_hcs);
36624 sonet_copy_stats(&PRIV(dev)->sonet_stats,&tmp);
36625 if (arg) error = copy_to_user(arg,&tmp,sizeof(tmp));
36626 if (zero && !error) {
36627 @@ -161,9 +161,9 @@ static int uPD98402_ioctl(struct atm_dev *dev,unsigned int cmd,void __user *arg)
36628
36629
36630 #define ADD_LIMITED(s,v) \
36631 - { atomic_add(GET(v),&PRIV(dev)->sonet_stats.s); \
36632 - if (atomic_read(&PRIV(dev)->sonet_stats.s) < 0) \
36633 - atomic_set(&PRIV(dev)->sonet_stats.s,INT_MAX); }
36634 + { atomic_add_unchecked(GET(v),&PRIV(dev)->sonet_stats.s); \
36635 + if (atomic_read_unchecked(&PRIV(dev)->sonet_stats.s) < 0) \
36636 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.s,INT_MAX); }
36637
36638
36639 static void stat_event(struct atm_dev *dev)
36640 @@ -194,7 +194,7 @@ static void uPD98402_int(struct atm_dev *dev)
36641 if (reason & uPD98402_INT_PFM) stat_event(dev);
36642 if (reason & uPD98402_INT_PCO) {
36643 (void) GET(PCOCR); /* clear interrupt cause */
36644 - atomic_add(GET(HECCT),
36645 + atomic_add_unchecked(GET(HECCT),
36646 &PRIV(dev)->sonet_stats.uncorr_hcs);
36647 }
36648 if ((reason & uPD98402_INT_RFO) &&
36649 @@ -222,9 +222,9 @@ static int uPD98402_start(struct atm_dev *dev)
36650 PUT(~(uPD98402_INT_PFM | uPD98402_INT_ALM | uPD98402_INT_RFO |
36651 uPD98402_INT_LOS),PIMR); /* enable them */
36652 (void) fetch_stats(dev,NULL,1); /* clear kernel counters */
36653 - atomic_set(&PRIV(dev)->sonet_stats.corr_hcs,-1);
36654 - atomic_set(&PRIV(dev)->sonet_stats.tx_cells,-1);
36655 - atomic_set(&PRIV(dev)->sonet_stats.rx_cells,-1);
36656 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.corr_hcs,-1);
36657 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.tx_cells,-1);
36658 + atomic_set_unchecked(&PRIV(dev)->sonet_stats.rx_cells,-1);
36659 return 0;
36660 }
36661
36662 diff --git a/drivers/atm/zatm.c b/drivers/atm/zatm.c
36663 index 969c3c2..9b72956 100644
36664 --- a/drivers/atm/zatm.c
36665 +++ b/drivers/atm/zatm.c
36666 @@ -459,7 +459,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
36667 }
36668 if (!size) {
36669 dev_kfree_skb_irq(skb);
36670 - if (vcc) atomic_inc(&vcc->stats->rx_err);
36671 + if (vcc) atomic_inc_unchecked(&vcc->stats->rx_err);
36672 continue;
36673 }
36674 if (!atm_charge(vcc,skb->truesize)) {
36675 @@ -469,7 +469,7 @@ printk("dummy: 0x%08lx, 0x%08lx\n",dummy[0],dummy[1]);
36676 skb->len = size;
36677 ATM_SKB(skb)->vcc = vcc;
36678 vcc->push(vcc,skb);
36679 - atomic_inc(&vcc->stats->rx);
36680 + atomic_inc_unchecked(&vcc->stats->rx);
36681 }
36682 zout(pos & 0xffff,MTA(mbx));
36683 #if 0 /* probably a stupid idea */
36684 @@ -733,7 +733,7 @@ if (*ZATM_PRV_DSC(skb) != (uPD98401_TXPD_V | uPD98401_TXPD_DP |
36685 skb_queue_head(&zatm_vcc->backlog,skb);
36686 break;
36687 }
36688 - atomic_inc(&vcc->stats->tx);
36689 + atomic_inc_unchecked(&vcc->stats->tx);
36690 wake_up(&zatm_vcc->tx_wait);
36691 }
36692
36693 diff --git a/drivers/base/bus.c b/drivers/base/bus.c
36694 index 73f6c29..b0c0e13 100644
36695 --- a/drivers/base/bus.c
36696 +++ b/drivers/base/bus.c
36697 @@ -1115,7 +1115,7 @@ int subsys_interface_register(struct subsys_interface *sif)
36698 return -EINVAL;
36699
36700 mutex_lock(&subsys->p->mutex);
36701 - list_add_tail(&sif->node, &subsys->p->interfaces);
36702 + pax_list_add_tail((struct list_head *)&sif->node, &subsys->p->interfaces);
36703 if (sif->add_dev) {
36704 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
36705 while ((dev = subsys_dev_iter_next(&iter)))
36706 @@ -1140,7 +1140,7 @@ void subsys_interface_unregister(struct subsys_interface *sif)
36707 subsys = sif->subsys;
36708
36709 mutex_lock(&subsys->p->mutex);
36710 - list_del_init(&sif->node);
36711 + pax_list_del_init((struct list_head *)&sif->node);
36712 if (sif->remove_dev) {
36713 subsys_dev_iter_init(&iter, subsys, NULL, NULL);
36714 while ((dev = subsys_dev_iter_next(&iter)))
36715 diff --git a/drivers/base/devtmpfs.c b/drivers/base/devtmpfs.c
36716 index 0f38201..6c2b444 100644
36717 --- a/drivers/base/devtmpfs.c
36718 +++ b/drivers/base/devtmpfs.c
36719 @@ -354,7 +354,7 @@ int devtmpfs_mount(const char *mntdir)
36720 if (!thread)
36721 return 0;
36722
36723 - err = sys_mount("devtmpfs", (char *)mntdir, "devtmpfs", MS_SILENT, NULL);
36724 + err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)mntdir, (char __force_user *)"devtmpfs", MS_SILENT, NULL);
36725 if (err)
36726 printk(KERN_INFO "devtmpfs: error mounting %i\n", err);
36727 else
36728 @@ -380,11 +380,11 @@ static int devtmpfsd(void *p)
36729 *err = sys_unshare(CLONE_NEWNS);
36730 if (*err)
36731 goto out;
36732 - *err = sys_mount("devtmpfs", "/", "devtmpfs", MS_SILENT, options);
36733 + *err = sys_mount((char __force_user *)"devtmpfs", (char __force_user *)"/", (char __force_user *)"devtmpfs", MS_SILENT, (char __force_user *)options);
36734 if (*err)
36735 goto out;
36736 - sys_chdir("/.."); /* will traverse into overmounted root */
36737 - sys_chroot(".");
36738 + sys_chdir((char __force_user *)"/.."); /* will traverse into overmounted root */
36739 + sys_chroot((char __force_user *)".");
36740 complete(&setup_done);
36741 while (1) {
36742 spin_lock(&req_lock);
36743 diff --git a/drivers/base/node.c b/drivers/base/node.c
36744 index bc9f43b..29703b8 100644
36745 --- a/drivers/base/node.c
36746 +++ b/drivers/base/node.c
36747 @@ -620,7 +620,7 @@ static ssize_t print_nodes_state(enum node_states state, char *buf)
36748 struct node_attr {
36749 struct device_attribute attr;
36750 enum node_states state;
36751 -};
36752 +} __do_const;
36753
36754 static ssize_t show_node_state(struct device *dev,
36755 struct device_attribute *attr, char *buf)
36756 diff --git a/drivers/base/power/domain.c b/drivers/base/power/domain.c
36757 index bfb8955..42c9b9a 100644
36758 --- a/drivers/base/power/domain.c
36759 +++ b/drivers/base/power/domain.c
36760 @@ -1850,7 +1850,7 @@ int pm_genpd_attach_cpuidle(struct generic_pm_domain *genpd, int state)
36761 {
36762 struct cpuidle_driver *cpuidle_drv;
36763 struct gpd_cpu_data *cpu_data;
36764 - struct cpuidle_state *idle_state;
36765 + cpuidle_state_no_const *idle_state;
36766 int ret = 0;
36767
36768 if (IS_ERR_OR_NULL(genpd) || state < 0)
36769 @@ -1918,7 +1918,7 @@ int pm_genpd_name_attach_cpuidle(const char *name, int state)
36770 int pm_genpd_detach_cpuidle(struct generic_pm_domain *genpd)
36771 {
36772 struct gpd_cpu_data *cpu_data;
36773 - struct cpuidle_state *idle_state;
36774 + cpuidle_state_no_const *idle_state;
36775 int ret = 0;
36776
36777 if (IS_ERR_OR_NULL(genpd))
36778 diff --git a/drivers/base/power/sysfs.c b/drivers/base/power/sysfs.c
36779 index 03e089a..0e9560c 100644
36780 --- a/drivers/base/power/sysfs.c
36781 +++ b/drivers/base/power/sysfs.c
36782 @@ -185,7 +185,7 @@ static ssize_t rtpm_status_show(struct device *dev,
36783 return -EIO;
36784 }
36785 }
36786 - return sprintf(buf, p);
36787 + return sprintf(buf, "%s", p);
36788 }
36789
36790 static DEVICE_ATTR(runtime_status, 0444, rtpm_status_show, NULL);
36791 diff --git a/drivers/base/power/wakeup.c b/drivers/base/power/wakeup.c
36792 index 2d56f41..8830f19 100644
36793 --- a/drivers/base/power/wakeup.c
36794 +++ b/drivers/base/power/wakeup.c
36795 @@ -29,14 +29,14 @@ bool events_check_enabled __read_mostly;
36796 * They need to be modified together atomically, so it's better to use one
36797 * atomic variable to hold them both.
36798 */
36799 -static atomic_t combined_event_count = ATOMIC_INIT(0);
36800 +static atomic_unchecked_t combined_event_count = ATOMIC_INIT(0);
36801
36802 #define IN_PROGRESS_BITS (sizeof(int) * 4)
36803 #define MAX_IN_PROGRESS ((1 << IN_PROGRESS_BITS) - 1)
36804
36805 static void split_counters(unsigned int *cnt, unsigned int *inpr)
36806 {
36807 - unsigned int comb = atomic_read(&combined_event_count);
36808 + unsigned int comb = atomic_read_unchecked(&combined_event_count);
36809
36810 *cnt = (comb >> IN_PROGRESS_BITS);
36811 *inpr = comb & MAX_IN_PROGRESS;
36812 @@ -395,7 +395,7 @@ static void wakeup_source_activate(struct wakeup_source *ws)
36813 ws->start_prevent_time = ws->last_time;
36814
36815 /* Increment the counter of events in progress. */
36816 - cec = atomic_inc_return(&combined_event_count);
36817 + cec = atomic_inc_return_unchecked(&combined_event_count);
36818
36819 trace_wakeup_source_activate(ws->name, cec);
36820 }
36821 @@ -521,7 +521,7 @@ static void wakeup_source_deactivate(struct wakeup_source *ws)
36822 * Increment the counter of registered wakeup events and decrement the
36823 * couter of wakeup events in progress simultaneously.
36824 */
36825 - cec = atomic_add_return(MAX_IN_PROGRESS, &combined_event_count);
36826 + cec = atomic_add_return_unchecked(MAX_IN_PROGRESS, &combined_event_count);
36827 trace_wakeup_source_deactivate(ws->name, cec);
36828
36829 split_counters(&cnt, &inpr);
36830 diff --git a/drivers/base/syscore.c b/drivers/base/syscore.c
36831 index e8d11b6..7b1b36f 100644
36832 --- a/drivers/base/syscore.c
36833 +++ b/drivers/base/syscore.c
36834 @@ -21,7 +21,7 @@ static DEFINE_MUTEX(syscore_ops_lock);
36835 void register_syscore_ops(struct syscore_ops *ops)
36836 {
36837 mutex_lock(&syscore_ops_lock);
36838 - list_add_tail(&ops->node, &syscore_ops_list);
36839 + pax_list_add_tail((struct list_head *)&ops->node, &syscore_ops_list);
36840 mutex_unlock(&syscore_ops_lock);
36841 }
36842 EXPORT_SYMBOL_GPL(register_syscore_ops);
36843 @@ -33,7 +33,7 @@ EXPORT_SYMBOL_GPL(register_syscore_ops);
36844 void unregister_syscore_ops(struct syscore_ops *ops)
36845 {
36846 mutex_lock(&syscore_ops_lock);
36847 - list_del(&ops->node);
36848 + pax_list_del((struct list_head *)&ops->node);
36849 mutex_unlock(&syscore_ops_lock);
36850 }
36851 EXPORT_SYMBOL_GPL(unregister_syscore_ops);
36852 diff --git a/drivers/block/cciss.c b/drivers/block/cciss.c
36853 index b35fc4f..c902870 100644
36854 --- a/drivers/block/cciss.c
36855 +++ b/drivers/block/cciss.c
36856 @@ -3011,7 +3011,7 @@ static void start_io(ctlr_info_t *h)
36857 while (!list_empty(&h->reqQ)) {
36858 c = list_entry(h->reqQ.next, CommandList_struct, list);
36859 /* can't do anything if fifo is full */
36860 - if ((h->access.fifo_full(h))) {
36861 + if ((h->access->fifo_full(h))) {
36862 dev_warn(&h->pdev->dev, "fifo full\n");
36863 break;
36864 }
36865 @@ -3021,7 +3021,7 @@ static void start_io(ctlr_info_t *h)
36866 h->Qdepth--;
36867
36868 /* Tell the controller execute command */
36869 - h->access.submit_command(h, c);
36870 + h->access->submit_command(h, c);
36871
36872 /* Put job onto the completed Q */
36873 addQ(&h->cmpQ, c);
36874 @@ -3447,17 +3447,17 @@ startio:
36875
36876 static inline unsigned long get_next_completion(ctlr_info_t *h)
36877 {
36878 - return h->access.command_completed(h);
36879 + return h->access->command_completed(h);
36880 }
36881
36882 static inline int interrupt_pending(ctlr_info_t *h)
36883 {
36884 - return h->access.intr_pending(h);
36885 + return h->access->intr_pending(h);
36886 }
36887
36888 static inline long interrupt_not_for_us(ctlr_info_t *h)
36889 {
36890 - return ((h->access.intr_pending(h) == 0) ||
36891 + return ((h->access->intr_pending(h) == 0) ||
36892 (h->interrupts_enabled == 0));
36893 }
36894
36895 @@ -3490,7 +3490,7 @@ static inline u32 next_command(ctlr_info_t *h)
36896 u32 a;
36897
36898 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
36899 - return h->access.command_completed(h);
36900 + return h->access->command_completed(h);
36901
36902 if ((*(h->reply_pool_head) & 1) == (h->reply_pool_wraparound)) {
36903 a = *(h->reply_pool_head); /* Next cmd in ring buffer */
36904 @@ -4047,7 +4047,7 @@ static void cciss_put_controller_into_performant_mode(ctlr_info_t *h)
36905 trans_support & CFGTBL_Trans_use_short_tags);
36906
36907 /* Change the access methods to the performant access methods */
36908 - h->access = SA5_performant_access;
36909 + h->access = &SA5_performant_access;
36910 h->transMethod = CFGTBL_Trans_Performant;
36911
36912 return;
36913 @@ -4327,7 +4327,7 @@ static int cciss_pci_init(ctlr_info_t *h)
36914 if (prod_index < 0)
36915 return -ENODEV;
36916 h->product_name = products[prod_index].product_name;
36917 - h->access = *(products[prod_index].access);
36918 + h->access = products[prod_index].access;
36919
36920 if (cciss_board_disabled(h)) {
36921 dev_warn(&h->pdev->dev, "controller appears to be disabled\n");
36922 @@ -5059,7 +5059,7 @@ reinit_after_soft_reset:
36923 }
36924
36925 /* make sure the board interrupts are off */
36926 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
36927 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
36928 rc = cciss_request_irq(h, do_cciss_msix_intr, do_cciss_intx);
36929 if (rc)
36930 goto clean2;
36931 @@ -5109,7 +5109,7 @@ reinit_after_soft_reset:
36932 * fake ones to scoop up any residual completions.
36933 */
36934 spin_lock_irqsave(&h->lock, flags);
36935 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
36936 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
36937 spin_unlock_irqrestore(&h->lock, flags);
36938 free_irq(h->intr[h->intr_mode], h);
36939 rc = cciss_request_irq(h, cciss_msix_discard_completions,
36940 @@ -5129,9 +5129,9 @@ reinit_after_soft_reset:
36941 dev_info(&h->pdev->dev, "Board READY.\n");
36942 dev_info(&h->pdev->dev,
36943 "Waiting for stale completions to drain.\n");
36944 - h->access.set_intr_mask(h, CCISS_INTR_ON);
36945 + h->access->set_intr_mask(h, CCISS_INTR_ON);
36946 msleep(10000);
36947 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
36948 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
36949
36950 rc = controller_reset_failed(h->cfgtable);
36951 if (rc)
36952 @@ -5154,7 +5154,7 @@ reinit_after_soft_reset:
36953 cciss_scsi_setup(h);
36954
36955 /* Turn the interrupts on so we can service requests */
36956 - h->access.set_intr_mask(h, CCISS_INTR_ON);
36957 + h->access->set_intr_mask(h, CCISS_INTR_ON);
36958
36959 /* Get the firmware version */
36960 inq_buff = kzalloc(sizeof(InquiryData_struct), GFP_KERNEL);
36961 @@ -5226,7 +5226,7 @@ static void cciss_shutdown(struct pci_dev *pdev)
36962 kfree(flush_buf);
36963 if (return_code != IO_OK)
36964 dev_warn(&h->pdev->dev, "Error flushing cache\n");
36965 - h->access.set_intr_mask(h, CCISS_INTR_OFF);
36966 + h->access->set_intr_mask(h, CCISS_INTR_OFF);
36967 free_irq(h->intr[h->intr_mode], h);
36968 }
36969
36970 diff --git a/drivers/block/cciss.h b/drivers/block/cciss.h
36971 index 7fda30e..2f27946 100644
36972 --- a/drivers/block/cciss.h
36973 +++ b/drivers/block/cciss.h
36974 @@ -101,7 +101,7 @@ struct ctlr_info
36975 /* information about each logical volume */
36976 drive_info_struct *drv[CISS_MAX_LUN];
36977
36978 - struct access_method access;
36979 + struct access_method *access;
36980
36981 /* queue and queue Info */
36982 struct list_head reqQ;
36983 @@ -402,27 +402,27 @@ static bool SA5_performant_intr_pending(ctlr_info_t *h)
36984 }
36985
36986 static struct access_method SA5_access = {
36987 - SA5_submit_command,
36988 - SA5_intr_mask,
36989 - SA5_fifo_full,
36990 - SA5_intr_pending,
36991 - SA5_completed,
36992 + .submit_command = SA5_submit_command,
36993 + .set_intr_mask = SA5_intr_mask,
36994 + .fifo_full = SA5_fifo_full,
36995 + .intr_pending = SA5_intr_pending,
36996 + .command_completed = SA5_completed,
36997 };
36998
36999 static struct access_method SA5B_access = {
37000 - SA5_submit_command,
37001 - SA5B_intr_mask,
37002 - SA5_fifo_full,
37003 - SA5B_intr_pending,
37004 - SA5_completed,
37005 + .submit_command = SA5_submit_command,
37006 + .set_intr_mask = SA5B_intr_mask,
37007 + .fifo_full = SA5_fifo_full,
37008 + .intr_pending = SA5B_intr_pending,
37009 + .command_completed = SA5_completed,
37010 };
37011
37012 static struct access_method SA5_performant_access = {
37013 - SA5_submit_command,
37014 - SA5_performant_intr_mask,
37015 - SA5_fifo_full,
37016 - SA5_performant_intr_pending,
37017 - SA5_performant_completed,
37018 + .submit_command = SA5_submit_command,
37019 + .set_intr_mask = SA5_performant_intr_mask,
37020 + .fifo_full = SA5_fifo_full,
37021 + .intr_pending = SA5_performant_intr_pending,
37022 + .command_completed = SA5_performant_completed,
37023 };
37024
37025 struct board_type {
37026 diff --git a/drivers/block/cpqarray.c b/drivers/block/cpqarray.c
37027 index 2b94403..fd6ad1f 100644
37028 --- a/drivers/block/cpqarray.c
37029 +++ b/drivers/block/cpqarray.c
37030 @@ -404,7 +404,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37031 if (register_blkdev(COMPAQ_SMART2_MAJOR+i, hba[i]->devname)) {
37032 goto Enomem4;
37033 }
37034 - hba[i]->access.set_intr_mask(hba[i], 0);
37035 + hba[i]->access->set_intr_mask(hba[i], 0);
37036 if (request_irq(hba[i]->intr, do_ida_intr,
37037 IRQF_DISABLED|IRQF_SHARED, hba[i]->devname, hba[i]))
37038 {
37039 @@ -459,7 +459,7 @@ static int cpqarray_register_ctlr(int i, struct pci_dev *pdev)
37040 add_timer(&hba[i]->timer);
37041
37042 /* Enable IRQ now that spinlock and rate limit timer are set up */
37043 - hba[i]->access.set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37044 + hba[i]->access->set_intr_mask(hba[i], FIFO_NOT_EMPTY);
37045
37046 for(j=0; j<NWD; j++) {
37047 struct gendisk *disk = ida_gendisk[i][j];
37048 @@ -694,7 +694,7 @@ DBGINFO(
37049 for(i=0; i<NR_PRODUCTS; i++) {
37050 if (board_id == products[i].board_id) {
37051 c->product_name = products[i].product_name;
37052 - c->access = *(products[i].access);
37053 + c->access = products[i].access;
37054 break;
37055 }
37056 }
37057 @@ -792,7 +792,7 @@ static int cpqarray_eisa_detect(void)
37058 hba[ctlr]->intr = intr;
37059 sprintf(hba[ctlr]->devname, "ida%d", nr_ctlr);
37060 hba[ctlr]->product_name = products[j].product_name;
37061 - hba[ctlr]->access = *(products[j].access);
37062 + hba[ctlr]->access = products[j].access;
37063 hba[ctlr]->ctlr = ctlr;
37064 hba[ctlr]->board_id = board_id;
37065 hba[ctlr]->pci_dev = NULL; /* not PCI */
37066 @@ -978,7 +978,7 @@ static void start_io(ctlr_info_t *h)
37067
37068 while((c = h->reqQ) != NULL) {
37069 /* Can't do anything if we're busy */
37070 - if (h->access.fifo_full(h) == 0)
37071 + if (h->access->fifo_full(h) == 0)
37072 return;
37073
37074 /* Get the first entry from the request Q */
37075 @@ -986,7 +986,7 @@ static void start_io(ctlr_info_t *h)
37076 h->Qdepth--;
37077
37078 /* Tell the controller to do our bidding */
37079 - h->access.submit_command(h, c);
37080 + h->access->submit_command(h, c);
37081
37082 /* Get onto the completion Q */
37083 addQ(&h->cmpQ, c);
37084 @@ -1048,7 +1048,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37085 unsigned long flags;
37086 __u32 a,a1;
37087
37088 - istat = h->access.intr_pending(h);
37089 + istat = h->access->intr_pending(h);
37090 /* Is this interrupt for us? */
37091 if (istat == 0)
37092 return IRQ_NONE;
37093 @@ -1059,7 +1059,7 @@ static irqreturn_t do_ida_intr(int irq, void *dev_id)
37094 */
37095 spin_lock_irqsave(IDA_LOCK(h->ctlr), flags);
37096 if (istat & FIFO_NOT_EMPTY) {
37097 - while((a = h->access.command_completed(h))) {
37098 + while((a = h->access->command_completed(h))) {
37099 a1 = a; a &= ~3;
37100 if ((c = h->cmpQ) == NULL)
37101 {
37102 @@ -1448,11 +1448,11 @@ static int sendcmd(
37103 /*
37104 * Disable interrupt
37105 */
37106 - info_p->access.set_intr_mask(info_p, 0);
37107 + info_p->access->set_intr_mask(info_p, 0);
37108 /* Make sure there is room in the command FIFO */
37109 /* Actually it should be completely empty at this time. */
37110 for (i = 200000; i > 0; i--) {
37111 - temp = info_p->access.fifo_full(info_p);
37112 + temp = info_p->access->fifo_full(info_p);
37113 if (temp != 0) {
37114 break;
37115 }
37116 @@ -1465,7 +1465,7 @@ DBG(
37117 /*
37118 * Send the cmd
37119 */
37120 - info_p->access.submit_command(info_p, c);
37121 + info_p->access->submit_command(info_p, c);
37122 complete = pollcomplete(ctlr);
37123
37124 pci_unmap_single(info_p->pci_dev, (dma_addr_t) c->req.sg[0].addr,
37125 @@ -1548,9 +1548,9 @@ static int revalidate_allvol(ctlr_info_t *host)
37126 * we check the new geometry. Then turn interrupts back on when
37127 * we're done.
37128 */
37129 - host->access.set_intr_mask(host, 0);
37130 + host->access->set_intr_mask(host, 0);
37131 getgeometry(ctlr);
37132 - host->access.set_intr_mask(host, FIFO_NOT_EMPTY);
37133 + host->access->set_intr_mask(host, FIFO_NOT_EMPTY);
37134
37135 for(i=0; i<NWD; i++) {
37136 struct gendisk *disk = ida_gendisk[ctlr][i];
37137 @@ -1590,7 +1590,7 @@ static int pollcomplete(int ctlr)
37138 /* Wait (up to 2 seconds) for a command to complete */
37139
37140 for (i = 200000; i > 0; i--) {
37141 - done = hba[ctlr]->access.command_completed(hba[ctlr]);
37142 + done = hba[ctlr]->access->command_completed(hba[ctlr]);
37143 if (done == 0) {
37144 udelay(10); /* a short fixed delay */
37145 } else
37146 diff --git a/drivers/block/cpqarray.h b/drivers/block/cpqarray.h
37147 index be73e9d..7fbf140 100644
37148 --- a/drivers/block/cpqarray.h
37149 +++ b/drivers/block/cpqarray.h
37150 @@ -99,7 +99,7 @@ struct ctlr_info {
37151 drv_info_t drv[NWD];
37152 struct proc_dir_entry *proc;
37153
37154 - struct access_method access;
37155 + struct access_method *access;
37156
37157 cmdlist_t *reqQ;
37158 cmdlist_t *cmpQ;
37159 diff --git a/drivers/block/drbd/drbd_int.h b/drivers/block/drbd/drbd_int.h
37160 index 0e06f0c..c47b81d 100644
37161 --- a/drivers/block/drbd/drbd_int.h
37162 +++ b/drivers/block/drbd/drbd_int.h
37163 @@ -582,7 +582,7 @@ struct drbd_epoch {
37164 struct drbd_tconn *tconn;
37165 struct list_head list;
37166 unsigned int barrier_nr;
37167 - atomic_t epoch_size; /* increased on every request added. */
37168 + atomic_unchecked_t epoch_size; /* increased on every request added. */
37169 atomic_t active; /* increased on every req. added, and dec on every finished. */
37170 unsigned long flags;
37171 };
37172 @@ -1022,7 +1022,7 @@ struct drbd_conf {
37173 unsigned int al_tr_number;
37174 int al_tr_cycle;
37175 wait_queue_head_t seq_wait;
37176 - atomic_t packet_seq;
37177 + atomic_unchecked_t packet_seq;
37178 unsigned int peer_seq;
37179 spinlock_t peer_seq_lock;
37180 unsigned int minor;
37181 @@ -1573,7 +1573,7 @@ static inline int drbd_setsockopt(struct socket *sock, int level, int optname,
37182 char __user *uoptval;
37183 int err;
37184
37185 - uoptval = (char __user __force *)optval;
37186 + uoptval = (char __force_user *)optval;
37187
37188 set_fs(KERNEL_DS);
37189 if (level == SOL_SOCKET)
37190 diff --git a/drivers/block/drbd/drbd_interval.c b/drivers/block/drbd/drbd_interval.c
37191 index 89c497c..9c736ae 100644
37192 --- a/drivers/block/drbd/drbd_interval.c
37193 +++ b/drivers/block/drbd/drbd_interval.c
37194 @@ -67,9 +67,9 @@ static void augment_rotate(struct rb_node *rb_old, struct rb_node *rb_new)
37195 }
37196
37197 static const struct rb_augment_callbacks augment_callbacks = {
37198 - augment_propagate,
37199 - augment_copy,
37200 - augment_rotate,
37201 + .propagate = augment_propagate,
37202 + .copy = augment_copy,
37203 + .rotate = augment_rotate,
37204 };
37205
37206 /**
37207 diff --git a/drivers/block/drbd/drbd_main.c b/drivers/block/drbd/drbd_main.c
37208 index 9e3818b..7b64c92 100644
37209 --- a/drivers/block/drbd/drbd_main.c
37210 +++ b/drivers/block/drbd/drbd_main.c
37211 @@ -1317,7 +1317,7 @@ static int _drbd_send_ack(struct drbd_conf *mdev, enum drbd_packet cmd,
37212 p->sector = sector;
37213 p->block_id = block_id;
37214 p->blksize = blksize;
37215 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37216 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37217 return drbd_send_command(mdev, sock, cmd, sizeof(*p), NULL, 0);
37218 }
37219
37220 @@ -1619,7 +1619,7 @@ int drbd_send_dblock(struct drbd_conf *mdev, struct drbd_request *req)
37221 return -EIO;
37222 p->sector = cpu_to_be64(req->i.sector);
37223 p->block_id = (unsigned long)req;
37224 - p->seq_num = cpu_to_be32(atomic_inc_return(&mdev->packet_seq));
37225 + p->seq_num = cpu_to_be32(atomic_inc_return_unchecked(&mdev->packet_seq));
37226 dp_flags = bio_flags_to_wire(mdev, req->master_bio->bi_rw);
37227 if (mdev->state.conn >= C_SYNC_SOURCE &&
37228 mdev->state.conn <= C_PAUSED_SYNC_T)
37229 @@ -2574,8 +2574,8 @@ void conn_destroy(struct kref *kref)
37230 {
37231 struct drbd_tconn *tconn = container_of(kref, struct drbd_tconn, kref);
37232
37233 - if (atomic_read(&tconn->current_epoch->epoch_size) != 0)
37234 - conn_err(tconn, "epoch_size:%d\n", atomic_read(&tconn->current_epoch->epoch_size));
37235 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size) != 0)
37236 + conn_err(tconn, "epoch_size:%d\n", atomic_read_unchecked(&tconn->current_epoch->epoch_size));
37237 kfree(tconn->current_epoch);
37238
37239 idr_destroy(&tconn->volumes);
37240 diff --git a/drivers/block/drbd/drbd_nl.c b/drivers/block/drbd/drbd_nl.c
37241 index c706d50..5e1b472 100644
37242 --- a/drivers/block/drbd/drbd_nl.c
37243 +++ b/drivers/block/drbd/drbd_nl.c
37244 @@ -3440,7 +3440,7 @@ out:
37245
37246 void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37247 {
37248 - static atomic_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37249 + static atomic_unchecked_t drbd_genl_seq = ATOMIC_INIT(2); /* two. */
37250 struct sk_buff *msg;
37251 struct drbd_genlmsghdr *d_out;
37252 unsigned seq;
37253 @@ -3453,7 +3453,7 @@ void drbd_bcast_event(struct drbd_conf *mdev, const struct sib_info *sib)
37254 return;
37255 }
37256
37257 - seq = atomic_inc_return(&drbd_genl_seq);
37258 + seq = atomic_inc_return_unchecked(&drbd_genl_seq);
37259 msg = genlmsg_new(NLMSG_GOODSIZE, GFP_NOIO);
37260 if (!msg)
37261 goto failed;
37262 diff --git a/drivers/block/drbd/drbd_receiver.c b/drivers/block/drbd/drbd_receiver.c
37263 index 6fa6673..b7f97e9 100644
37264 --- a/drivers/block/drbd/drbd_receiver.c
37265 +++ b/drivers/block/drbd/drbd_receiver.c
37266 @@ -834,7 +834,7 @@ int drbd_connected(struct drbd_conf *mdev)
37267 {
37268 int err;
37269
37270 - atomic_set(&mdev->packet_seq, 0);
37271 + atomic_set_unchecked(&mdev->packet_seq, 0);
37272 mdev->peer_seq = 0;
37273
37274 mdev->state_mutex = mdev->tconn->agreed_pro_version < 100 ?
37275 @@ -1193,7 +1193,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37276 do {
37277 next_epoch = NULL;
37278
37279 - epoch_size = atomic_read(&epoch->epoch_size);
37280 + epoch_size = atomic_read_unchecked(&epoch->epoch_size);
37281
37282 switch (ev & ~EV_CLEANUP) {
37283 case EV_PUT:
37284 @@ -1233,7 +1233,7 @@ static enum finish_epoch drbd_may_finish_epoch(struct drbd_tconn *tconn,
37285 rv = FE_DESTROYED;
37286 } else {
37287 epoch->flags = 0;
37288 - atomic_set(&epoch->epoch_size, 0);
37289 + atomic_set_unchecked(&epoch->epoch_size, 0);
37290 /* atomic_set(&epoch->active, 0); is already zero */
37291 if (rv == FE_STILL_LIVE)
37292 rv = FE_RECYCLED;
37293 @@ -1451,7 +1451,7 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37294 conn_wait_active_ee_empty(tconn);
37295 drbd_flush(tconn);
37296
37297 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
37298 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37299 epoch = kmalloc(sizeof(struct drbd_epoch), GFP_NOIO);
37300 if (epoch)
37301 break;
37302 @@ -1464,11 +1464,11 @@ static int receive_Barrier(struct drbd_tconn *tconn, struct packet_info *pi)
37303 }
37304
37305 epoch->flags = 0;
37306 - atomic_set(&epoch->epoch_size, 0);
37307 + atomic_set_unchecked(&epoch->epoch_size, 0);
37308 atomic_set(&epoch->active, 0);
37309
37310 spin_lock(&tconn->epoch_lock);
37311 - if (atomic_read(&tconn->current_epoch->epoch_size)) {
37312 + if (atomic_read_unchecked(&tconn->current_epoch->epoch_size)) {
37313 list_add(&epoch->list, &tconn->current_epoch->list);
37314 tconn->current_epoch = epoch;
37315 tconn->epochs++;
37316 @@ -2163,7 +2163,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37317
37318 err = wait_for_and_update_peer_seq(mdev, peer_seq);
37319 drbd_send_ack_dp(mdev, P_NEG_ACK, p, pi->size);
37320 - atomic_inc(&tconn->current_epoch->epoch_size);
37321 + atomic_inc_unchecked(&tconn->current_epoch->epoch_size);
37322 err2 = drbd_drain_block(mdev, pi->size);
37323 if (!err)
37324 err = err2;
37325 @@ -2197,7 +2197,7 @@ static int receive_Data(struct drbd_tconn *tconn, struct packet_info *pi)
37326
37327 spin_lock(&tconn->epoch_lock);
37328 peer_req->epoch = tconn->current_epoch;
37329 - atomic_inc(&peer_req->epoch->epoch_size);
37330 + atomic_inc_unchecked(&peer_req->epoch->epoch_size);
37331 atomic_inc(&peer_req->epoch->active);
37332 spin_unlock(&tconn->epoch_lock);
37333
37334 @@ -4344,7 +4344,7 @@ struct data_cmd {
37335 int expect_payload;
37336 size_t pkt_size;
37337 int (*fn)(struct drbd_tconn *, struct packet_info *);
37338 -};
37339 +} __do_const;
37340
37341 static struct data_cmd drbd_cmd_handler[] = {
37342 [P_DATA] = { 1, sizeof(struct p_data), receive_Data },
37343 @@ -4464,7 +4464,7 @@ static void conn_disconnect(struct drbd_tconn *tconn)
37344 if (!list_empty(&tconn->current_epoch->list))
37345 conn_err(tconn, "ASSERTION FAILED: tconn->current_epoch->list not empty\n");
37346 /* ok, no more ee's on the fly, it is safe to reset the epoch_size */
37347 - atomic_set(&tconn->current_epoch->epoch_size, 0);
37348 + atomic_set_unchecked(&tconn->current_epoch->epoch_size, 0);
37349 tconn->send.seen_any_write_yet = false;
37350
37351 conn_info(tconn, "Connection closed\n");
37352 @@ -5220,7 +5220,7 @@ static int tconn_finish_peer_reqs(struct drbd_tconn *tconn)
37353 struct asender_cmd {
37354 size_t pkt_size;
37355 int (*fn)(struct drbd_tconn *tconn, struct packet_info *);
37356 -};
37357 +} __do_const;
37358
37359 static struct asender_cmd asender_tbl[] = {
37360 [P_PING] = { 0, got_Ping },
37361 diff --git a/drivers/block/loop.c b/drivers/block/loop.c
37362 index c8dac73..1800093 100644
37363 --- a/drivers/block/loop.c
37364 +++ b/drivers/block/loop.c
37365 @@ -232,7 +232,7 @@ static int __do_lo_send_write(struct file *file,
37366
37367 file_start_write(file);
37368 set_fs(get_ds());
37369 - bw = file->f_op->write(file, buf, len, &pos);
37370 + bw = file->f_op->write(file, (const char __force_user *)buf, len, &pos);
37371 set_fs(old_fs);
37372 file_end_write(file);
37373 if (likely(bw == len))
37374 diff --git a/drivers/block/null_blk.c b/drivers/block/null_blk.c
37375 index 83a598e..2de5ce3 100644
37376 --- a/drivers/block/null_blk.c
37377 +++ b/drivers/block/null_blk.c
37378 @@ -407,14 +407,24 @@ static int null_init_hctx(struct blk_mq_hw_ctx *hctx, void *data,
37379 return 0;
37380 }
37381
37382 -static struct blk_mq_ops null_mq_ops = {
37383 - .queue_rq = null_queue_rq,
37384 - .map_queue = blk_mq_map_queue,
37385 +static struct blk_mq_ops null_mq_single_ops = {
37386 + .queue_rq = null_queue_rq,
37387 + .map_queue = blk_mq_map_queue,
37388 .init_hctx = null_init_hctx,
37389 + .alloc_hctx = blk_mq_alloc_single_hw_queue,
37390 + .free_hctx = blk_mq_free_single_hw_queue,
37391 +};
37392 +
37393 +static struct blk_mq_ops null_mq_per_node_ops = {
37394 + .queue_rq = null_queue_rq,
37395 + .map_queue = blk_mq_map_queue,
37396 + .init_hctx = null_init_hctx,
37397 + .alloc_hctx = null_alloc_hctx,
37398 + .free_hctx = null_free_hctx,
37399 };
37400
37401 static struct blk_mq_reg null_mq_reg = {
37402 - .ops = &null_mq_ops,
37403 + .ops = &null_mq_single_ops,
37404 .queue_depth = 64,
37405 .cmd_size = sizeof(struct nullb_cmd),
37406 .flags = BLK_MQ_F_SHOULD_MERGE,
37407 @@ -545,13 +555,8 @@ static int null_add_dev(void)
37408 null_mq_reg.queue_depth = hw_queue_depth;
37409 null_mq_reg.nr_hw_queues = submit_queues;
37410
37411 - if (use_per_node_hctx) {
37412 - null_mq_reg.ops->alloc_hctx = null_alloc_hctx;
37413 - null_mq_reg.ops->free_hctx = null_free_hctx;
37414 - } else {
37415 - null_mq_reg.ops->alloc_hctx = blk_mq_alloc_single_hw_queue;
37416 - null_mq_reg.ops->free_hctx = blk_mq_free_single_hw_queue;
37417 - }
37418 + if (use_per_node_hctx)
37419 + null_mq_reg.ops = &null_mq_per_node_ops;
37420
37421 nullb->q = blk_mq_init_queue(&null_mq_reg, nullb);
37422 } else if (queue_mode == NULL_Q_BIO) {
37423 diff --git a/drivers/block/pktcdvd.c b/drivers/block/pktcdvd.c
37424 index ff8668c..f62167a 100644
37425 --- a/drivers/block/pktcdvd.c
37426 +++ b/drivers/block/pktcdvd.c
37427 @@ -108,7 +108,7 @@ static int pkt_seq_show(struct seq_file *m, void *p);
37428
37429 static sector_t get_zone(sector_t sector, struct pktcdvd_device *pd)
37430 {
37431 - return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1);
37432 + return (sector + pd->offset) & ~(sector_t)(pd->settings.size - 1UL);
37433 }
37434
37435 /*
37436 @@ -1883,7 +1883,7 @@ static noinline_for_stack int pkt_probe_settings(struct pktcdvd_device *pd)
37437 return -EROFS;
37438 }
37439 pd->settings.fp = ti.fp;
37440 - pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1);
37441 + pd->offset = (be32_to_cpu(ti.track_start) << 2) & (pd->settings.size - 1UL);
37442
37443 if (ti.nwa_v) {
37444 pd->nwa = be32_to_cpu(ti.next_writable);
37445 diff --git a/drivers/block/smart1,2.h b/drivers/block/smart1,2.h
37446 index e5565fb..71be10b4 100644
37447 --- a/drivers/block/smart1,2.h
37448 +++ b/drivers/block/smart1,2.h
37449 @@ -108,11 +108,11 @@ static unsigned long smart4_intr_pending(ctlr_info_t *h)
37450 }
37451
37452 static struct access_method smart4_access = {
37453 - smart4_submit_command,
37454 - smart4_intr_mask,
37455 - smart4_fifo_full,
37456 - smart4_intr_pending,
37457 - smart4_completed,
37458 + .submit_command = smart4_submit_command,
37459 + .set_intr_mask = smart4_intr_mask,
37460 + .fifo_full = smart4_fifo_full,
37461 + .intr_pending = smart4_intr_pending,
37462 + .command_completed = smart4_completed,
37463 };
37464
37465 /*
37466 @@ -144,11 +144,11 @@ static unsigned long smart2_intr_pending(ctlr_info_t *h)
37467 }
37468
37469 static struct access_method smart2_access = {
37470 - smart2_submit_command,
37471 - smart2_intr_mask,
37472 - smart2_fifo_full,
37473 - smart2_intr_pending,
37474 - smart2_completed,
37475 + .submit_command = smart2_submit_command,
37476 + .set_intr_mask = smart2_intr_mask,
37477 + .fifo_full = smart2_fifo_full,
37478 + .intr_pending = smart2_intr_pending,
37479 + .command_completed = smart2_completed,
37480 };
37481
37482 /*
37483 @@ -180,11 +180,11 @@ static unsigned long smart2e_intr_pending(ctlr_info_t *h)
37484 }
37485
37486 static struct access_method smart2e_access = {
37487 - smart2e_submit_command,
37488 - smart2e_intr_mask,
37489 - smart2e_fifo_full,
37490 - smart2e_intr_pending,
37491 - smart2e_completed,
37492 + .submit_command = smart2e_submit_command,
37493 + .set_intr_mask = smart2e_intr_mask,
37494 + .fifo_full = smart2e_fifo_full,
37495 + .intr_pending = smart2e_intr_pending,
37496 + .command_completed = smart2e_completed,
37497 };
37498
37499 /*
37500 @@ -270,9 +270,9 @@ static unsigned long smart1_intr_pending(ctlr_info_t *h)
37501 }
37502
37503 static struct access_method smart1_access = {
37504 - smart1_submit_command,
37505 - smart1_intr_mask,
37506 - smart1_fifo_full,
37507 - smart1_intr_pending,
37508 - smart1_completed,
37509 + .submit_command = smart1_submit_command,
37510 + .set_intr_mask = smart1_intr_mask,
37511 + .fifo_full = smart1_fifo_full,
37512 + .intr_pending = smart1_intr_pending,
37513 + .command_completed = smart1_completed,
37514 };
37515 diff --git a/drivers/bluetooth/btwilink.c b/drivers/bluetooth/btwilink.c
37516 index f038dba..bb74c08 100644
37517 --- a/drivers/bluetooth/btwilink.c
37518 +++ b/drivers/bluetooth/btwilink.c
37519 @@ -288,7 +288,7 @@ static int ti_st_send_frame(struct hci_dev *hdev, struct sk_buff *skb)
37520
37521 static int bt_ti_probe(struct platform_device *pdev)
37522 {
37523 - static struct ti_st *hst;
37524 + struct ti_st *hst;
37525 struct hci_dev *hdev;
37526 int err;
37527
37528 diff --git a/drivers/bus/arm-cci.c b/drivers/bus/arm-cci.c
37529 index b6739cb..962fd35 100644
37530 --- a/drivers/bus/arm-cci.c
37531 +++ b/drivers/bus/arm-cci.c
37532 @@ -979,7 +979,7 @@ static int cci_probe(void)
37533
37534 nb_cci_ports = cci_config->nb_ace + cci_config->nb_ace_lite;
37535
37536 - ports = kcalloc(sizeof(*ports), nb_cci_ports, GFP_KERNEL);
37537 + ports = kcalloc(nb_cci_ports, sizeof(*ports), GFP_KERNEL);
37538 if (!ports)
37539 return -ENOMEM;
37540
37541 diff --git a/drivers/cdrom/cdrom.c b/drivers/cdrom/cdrom.c
37542 index 8a3aff7..d7538c2 100644
37543 --- a/drivers/cdrom/cdrom.c
37544 +++ b/drivers/cdrom/cdrom.c
37545 @@ -416,7 +416,6 @@ int register_cdrom(struct cdrom_device_info *cdi)
37546 ENSURE(reset, CDC_RESET);
37547 ENSURE(generic_packet, CDC_GENERIC_PACKET);
37548 cdi->mc_flags = 0;
37549 - cdo->n_minors = 0;
37550 cdi->options = CDO_USE_FFLAGS;
37551
37552 if (autoclose==1 && CDROM_CAN(CDC_CLOSE_TRAY))
37553 @@ -436,8 +435,11 @@ int register_cdrom(struct cdrom_device_info *cdi)
37554 else
37555 cdi->cdda_method = CDDA_OLD;
37556
37557 - if (!cdo->generic_packet)
37558 - cdo->generic_packet = cdrom_dummy_generic_packet;
37559 + if (!cdo->generic_packet) {
37560 + pax_open_kernel();
37561 + *(void **)&cdo->generic_packet = cdrom_dummy_generic_packet;
37562 + pax_close_kernel();
37563 + }
37564
37565 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" registered\n", cdi->name);
37566 mutex_lock(&cdrom_mutex);
37567 @@ -458,7 +460,6 @@ void unregister_cdrom(struct cdrom_device_info *cdi)
37568 if (cdi->exit)
37569 cdi->exit(cdi);
37570
37571 - cdi->ops->n_minors--;
37572 cdinfo(CD_REG_UNREG, "drive \"/dev/%s\" unregistered\n", cdi->name);
37573 }
37574
37575 @@ -2107,7 +2108,7 @@ static int cdrom_read_cdda_old(struct cdrom_device_info *cdi, __u8 __user *ubuf,
37576 */
37577 nr = nframes;
37578 do {
37579 - cgc.buffer = kmalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
37580 + cgc.buffer = kzalloc(CD_FRAMESIZE_RAW * nr, GFP_KERNEL);
37581 if (cgc.buffer)
37582 break;
37583
37584 @@ -3429,7 +3430,7 @@ static int cdrom_print_info(const char *header, int val, char *info,
37585 struct cdrom_device_info *cdi;
37586 int ret;
37587
37588 - ret = scnprintf(info + *pos, max_size - *pos, header);
37589 + ret = scnprintf(info + *pos, max_size - *pos, "%s", header);
37590 if (!ret)
37591 return 1;
37592
37593 diff --git a/drivers/cdrom/gdrom.c b/drivers/cdrom/gdrom.c
37594 index 5980cb9..6d7bd7e 100644
37595 --- a/drivers/cdrom/gdrom.c
37596 +++ b/drivers/cdrom/gdrom.c
37597 @@ -491,7 +491,6 @@ static struct cdrom_device_ops gdrom_ops = {
37598 .audio_ioctl = gdrom_audio_ioctl,
37599 .capability = CDC_MULTI_SESSION | CDC_MEDIA_CHANGED |
37600 CDC_RESET | CDC_DRIVE_STATUS | CDC_CD_R,
37601 - .n_minors = 1,
37602 };
37603
37604 static int gdrom_bdops_open(struct block_device *bdev, fmode_t mode)
37605 diff --git a/drivers/char/Kconfig b/drivers/char/Kconfig
37606 index fa3243d..8c98297 100644
37607 --- a/drivers/char/Kconfig
37608 +++ b/drivers/char/Kconfig
37609 @@ -8,7 +8,8 @@ source "drivers/tty/Kconfig"
37610
37611 config DEVKMEM
37612 bool "/dev/kmem virtual device support"
37613 - default y
37614 + default n
37615 + depends on !GRKERNSEC_KMEM
37616 help
37617 Say Y here if you want to support the /dev/kmem device. The
37618 /dev/kmem device is rarely used, but can be used for certain
37619 @@ -576,6 +577,7 @@ config DEVPORT
37620 bool
37621 depends on !M68K
37622 depends on ISA || PCI
37623 + depends on !GRKERNSEC_KMEM
37624 default y
37625
37626 source "drivers/s390/char/Kconfig"
37627 diff --git a/drivers/char/agp/compat_ioctl.c b/drivers/char/agp/compat_ioctl.c
37628 index a48e05b..6bac831 100644
37629 --- a/drivers/char/agp/compat_ioctl.c
37630 +++ b/drivers/char/agp/compat_ioctl.c
37631 @@ -108,7 +108,7 @@ static int compat_agpioc_reserve_wrap(struct agp_file_private *priv, void __user
37632 return -ENOMEM;
37633 }
37634
37635 - if (copy_from_user(usegment, (void __user *) ureserve.seg_list,
37636 + if (copy_from_user(usegment, (void __force_user *) ureserve.seg_list,
37637 sizeof(*usegment) * ureserve.seg_count)) {
37638 kfree(usegment);
37639 kfree(ksegment);
37640 diff --git a/drivers/char/agp/frontend.c b/drivers/char/agp/frontend.c
37641 index 1b19239..b87b143 100644
37642 --- a/drivers/char/agp/frontend.c
37643 +++ b/drivers/char/agp/frontend.c
37644 @@ -819,7 +819,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
37645 if (copy_from_user(&reserve, arg, sizeof(struct agp_region)))
37646 return -EFAULT;
37647
37648 - if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment))
37649 + if ((unsigned) reserve.seg_count >= ~0U/sizeof(struct agp_segment_priv))
37650 return -EFAULT;
37651
37652 client = agp_find_client_by_pid(reserve.pid);
37653 @@ -849,7 +849,7 @@ static int agpioc_reserve_wrap(struct agp_file_private *priv, void __user *arg)
37654 if (segment == NULL)
37655 return -ENOMEM;
37656
37657 - if (copy_from_user(segment, (void __user *) reserve.seg_list,
37658 + if (copy_from_user(segment, (void __force_user *) reserve.seg_list,
37659 sizeof(struct agp_segment) * reserve.seg_count)) {
37660 kfree(segment);
37661 return -EFAULT;
37662 diff --git a/drivers/char/genrtc.c b/drivers/char/genrtc.c
37663 index 4f94375..413694e 100644
37664 --- a/drivers/char/genrtc.c
37665 +++ b/drivers/char/genrtc.c
37666 @@ -273,6 +273,7 @@ static int gen_rtc_ioctl(struct file *file,
37667 switch (cmd) {
37668
37669 case RTC_PLL_GET:
37670 + memset(&pll, 0, sizeof(pll));
37671 if (get_rtc_pll(&pll))
37672 return -EINVAL;
37673 else
37674 diff --git a/drivers/char/hpet.c b/drivers/char/hpet.c
37675 index 5d9c31d..c94ccb5 100644
37676 --- a/drivers/char/hpet.c
37677 +++ b/drivers/char/hpet.c
37678 @@ -578,7 +578,7 @@ static inline unsigned long hpet_time_div(struct hpets *hpets,
37679 }
37680
37681 static int
37682 -hpet_ioctl_common(struct hpet_dev *devp, int cmd, unsigned long arg,
37683 +hpet_ioctl_common(struct hpet_dev *devp, unsigned int cmd, unsigned long arg,
37684 struct hpet_info *info)
37685 {
37686 struct hpet_timer __iomem *timer;
37687 diff --git a/drivers/char/hw_random/intel-rng.c b/drivers/char/hw_random/intel-rng.c
37688 index 86fe45c..c0ea948 100644
37689 --- a/drivers/char/hw_random/intel-rng.c
37690 +++ b/drivers/char/hw_random/intel-rng.c
37691 @@ -314,7 +314,7 @@ PFX "RNG, try using the 'no_fwh_detect' option.\n";
37692
37693 if (no_fwh_detect)
37694 return -ENODEV;
37695 - printk(warning);
37696 + printk("%s", warning);
37697 return -EBUSY;
37698 }
37699
37700 diff --git a/drivers/char/ipmi/ipmi_msghandler.c b/drivers/char/ipmi/ipmi_msghandler.c
37701 index ec4e10f..f2a763b 100644
37702 --- a/drivers/char/ipmi/ipmi_msghandler.c
37703 +++ b/drivers/char/ipmi/ipmi_msghandler.c
37704 @@ -420,7 +420,7 @@ struct ipmi_smi {
37705 struct proc_dir_entry *proc_dir;
37706 char proc_dir_name[10];
37707
37708 - atomic_t stats[IPMI_NUM_STATS];
37709 + atomic_unchecked_t stats[IPMI_NUM_STATS];
37710
37711 /*
37712 * run_to_completion duplicate of smb_info, smi_info
37713 @@ -453,9 +453,9 @@ static DEFINE_MUTEX(smi_watchers_mutex);
37714
37715
37716 #define ipmi_inc_stat(intf, stat) \
37717 - atomic_inc(&(intf)->stats[IPMI_STAT_ ## stat])
37718 + atomic_inc_unchecked(&(intf)->stats[IPMI_STAT_ ## stat])
37719 #define ipmi_get_stat(intf, stat) \
37720 - ((unsigned int) atomic_read(&(intf)->stats[IPMI_STAT_ ## stat]))
37721 + ((unsigned int) atomic_read_unchecked(&(intf)->stats[IPMI_STAT_ ## stat]))
37722
37723 static int is_lan_addr(struct ipmi_addr *addr)
37724 {
37725 @@ -2883,7 +2883,7 @@ int ipmi_register_smi(struct ipmi_smi_handlers *handlers,
37726 INIT_LIST_HEAD(&intf->cmd_rcvrs);
37727 init_waitqueue_head(&intf->waitq);
37728 for (i = 0; i < IPMI_NUM_STATS; i++)
37729 - atomic_set(&intf->stats[i], 0);
37730 + atomic_set_unchecked(&intf->stats[i], 0);
37731
37732 intf->proc_dir = NULL;
37733
37734 diff --git a/drivers/char/ipmi/ipmi_si_intf.c b/drivers/char/ipmi/ipmi_si_intf.c
37735 index 15e4a60..b046093 100644
37736 --- a/drivers/char/ipmi/ipmi_si_intf.c
37737 +++ b/drivers/char/ipmi/ipmi_si_intf.c
37738 @@ -280,7 +280,7 @@ struct smi_info {
37739 unsigned char slave_addr;
37740
37741 /* Counters and things for the proc filesystem. */
37742 - atomic_t stats[SI_NUM_STATS];
37743 + atomic_unchecked_t stats[SI_NUM_STATS];
37744
37745 struct task_struct *thread;
37746
37747 @@ -289,9 +289,9 @@ struct smi_info {
37748 };
37749
37750 #define smi_inc_stat(smi, stat) \
37751 - atomic_inc(&(smi)->stats[SI_STAT_ ## stat])
37752 + atomic_inc_unchecked(&(smi)->stats[SI_STAT_ ## stat])
37753 #define smi_get_stat(smi, stat) \
37754 - ((unsigned int) atomic_read(&(smi)->stats[SI_STAT_ ## stat]))
37755 + ((unsigned int) atomic_read_unchecked(&(smi)->stats[SI_STAT_ ## stat]))
37756
37757 #define SI_MAX_PARMS 4
37758
37759 @@ -3324,7 +3324,7 @@ static int try_smi_init(struct smi_info *new_smi)
37760 atomic_set(&new_smi->req_events, 0);
37761 new_smi->run_to_completion = 0;
37762 for (i = 0; i < SI_NUM_STATS; i++)
37763 - atomic_set(&new_smi->stats[i], 0);
37764 + atomic_set_unchecked(&new_smi->stats[i], 0);
37765
37766 new_smi->interrupt_disabled = 1;
37767 atomic_set(&new_smi->stop_operation, 0);
37768 diff --git a/drivers/char/mem.c b/drivers/char/mem.c
37769 index f895a8c..2bc9147 100644
37770 --- a/drivers/char/mem.c
37771 +++ b/drivers/char/mem.c
37772 @@ -18,6 +18,7 @@
37773 #include <linux/raw.h>
37774 #include <linux/tty.h>
37775 #include <linux/capability.h>
37776 +#include <linux/security.h>
37777 #include <linux/ptrace.h>
37778 #include <linux/device.h>
37779 #include <linux/highmem.h>
37780 @@ -37,6 +38,10 @@
37781
37782 #define DEVPORT_MINOR 4
37783
37784 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
37785 +extern const struct file_operations grsec_fops;
37786 +#endif
37787 +
37788 static inline unsigned long size_inside_page(unsigned long start,
37789 unsigned long size)
37790 {
37791 @@ -68,9 +73,13 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37792
37793 while (cursor < to) {
37794 if (!devmem_is_allowed(pfn)) {
37795 +#ifdef CONFIG_GRKERNSEC_KMEM
37796 + gr_handle_mem_readwrite(from, to);
37797 +#else
37798 printk(KERN_INFO
37799 "Program %s tried to access /dev/mem between %Lx->%Lx.\n",
37800 current->comm, from, to);
37801 +#endif
37802 return 0;
37803 }
37804 cursor += PAGE_SIZE;
37805 @@ -78,6 +87,11 @@ static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37806 }
37807 return 1;
37808 }
37809 +#elif defined(CONFIG_GRKERNSEC_KMEM)
37810 +static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37811 +{
37812 + return 0;
37813 +}
37814 #else
37815 static inline int range_is_allowed(unsigned long pfn, unsigned long size)
37816 {
37817 @@ -120,6 +134,7 @@ static ssize_t read_mem(struct file *file, char __user *buf,
37818
37819 while (count > 0) {
37820 unsigned long remaining;
37821 + char *temp;
37822
37823 sz = size_inside_page(p, count);
37824
37825 @@ -135,7 +150,23 @@ static ssize_t read_mem(struct file *file, char __user *buf,
37826 if (!ptr)
37827 return -EFAULT;
37828
37829 - remaining = copy_to_user(buf, ptr, sz);
37830 +#ifdef CONFIG_PAX_USERCOPY
37831 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
37832 + if (!temp) {
37833 + unxlate_dev_mem_ptr(p, ptr);
37834 + return -ENOMEM;
37835 + }
37836 + memcpy(temp, ptr, sz);
37837 +#else
37838 + temp = ptr;
37839 +#endif
37840 +
37841 + remaining = copy_to_user(buf, temp, sz);
37842 +
37843 +#ifdef CONFIG_PAX_USERCOPY
37844 + kfree(temp);
37845 +#endif
37846 +
37847 unxlate_dev_mem_ptr(p, ptr);
37848 if (remaining)
37849 return -EFAULT;
37850 @@ -364,9 +395,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37851 size_t count, loff_t *ppos)
37852 {
37853 unsigned long p = *ppos;
37854 - ssize_t low_count, read, sz;
37855 + ssize_t low_count, read, sz, err = 0;
37856 char *kbuf; /* k-addr because vread() takes vmlist_lock rwlock */
37857 - int err = 0;
37858
37859 read = 0;
37860 if (p < (unsigned long) high_memory) {
37861 @@ -388,6 +418,8 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37862 }
37863 #endif
37864 while (low_count > 0) {
37865 + char *temp;
37866 +
37867 sz = size_inside_page(p, low_count);
37868
37869 /*
37870 @@ -397,7 +429,22 @@ static ssize_t read_kmem(struct file *file, char __user *buf,
37871 */
37872 kbuf = xlate_dev_kmem_ptr((char *)p);
37873
37874 - if (copy_to_user(buf, kbuf, sz))
37875 +#ifdef CONFIG_PAX_USERCOPY
37876 + temp = kmalloc(sz, GFP_KERNEL|GFP_USERCOPY);
37877 + if (!temp)
37878 + return -ENOMEM;
37879 + memcpy(temp, kbuf, sz);
37880 +#else
37881 + temp = kbuf;
37882 +#endif
37883 +
37884 + err = copy_to_user(buf, temp, sz);
37885 +
37886 +#ifdef CONFIG_PAX_USERCOPY
37887 + kfree(temp);
37888 +#endif
37889 +
37890 + if (err)
37891 return -EFAULT;
37892 buf += sz;
37893 p += sz;
37894 @@ -822,6 +869,9 @@ static const struct memdev {
37895 #ifdef CONFIG_PRINTK
37896 [11] = { "kmsg", 0644, &kmsg_fops, NULL },
37897 #endif
37898 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
37899 + [13] = { "grsec",S_IRUSR | S_IWUGO, &grsec_fops, NULL },
37900 +#endif
37901 };
37902
37903 static int memory_open(struct inode *inode, struct file *filp)
37904 @@ -893,7 +943,7 @@ static int __init chr_dev_init(void)
37905 continue;
37906
37907 device_create(mem_class, NULL, MKDEV(MEM_MAJOR, minor),
37908 - NULL, devlist[minor].name);
37909 + NULL, "%s", devlist[minor].name);
37910 }
37911
37912 return tty_init();
37913 diff --git a/drivers/char/nvram.c b/drivers/char/nvram.c
37914 index 9df78e2..01ba9ae 100644
37915 --- a/drivers/char/nvram.c
37916 +++ b/drivers/char/nvram.c
37917 @@ -247,7 +247,7 @@ static ssize_t nvram_read(struct file *file, char __user *buf,
37918
37919 spin_unlock_irq(&rtc_lock);
37920
37921 - if (copy_to_user(buf, contents, tmp - contents))
37922 + if (tmp - contents > sizeof(contents) || copy_to_user(buf, contents, tmp - contents))
37923 return -EFAULT;
37924
37925 *ppos = i;
37926 diff --git a/drivers/char/pcmcia/synclink_cs.c b/drivers/char/pcmcia/synclink_cs.c
37927 index d39cca6..8c1e269 100644
37928 --- a/drivers/char/pcmcia/synclink_cs.c
37929 +++ b/drivers/char/pcmcia/synclink_cs.c
37930 @@ -2345,9 +2345,9 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
37931
37932 if (debug_level >= DEBUG_LEVEL_INFO)
37933 printk("%s(%d):mgslpc_close(%s) entry, count=%d\n",
37934 - __FILE__, __LINE__, info->device_name, port->count);
37935 + __FILE__, __LINE__, info->device_name, atomic_read(&port->count));
37936
37937 - WARN_ON(!port->count);
37938 + WARN_ON(!atomic_read(&port->count));
37939
37940 if (tty_port_close_start(port, tty, filp) == 0)
37941 goto cleanup;
37942 @@ -2365,7 +2365,7 @@ static void mgslpc_close(struct tty_struct *tty, struct file * filp)
37943 cleanup:
37944 if (debug_level >= DEBUG_LEVEL_INFO)
37945 printk("%s(%d):mgslpc_close(%s) exit, count=%d\n", __FILE__, __LINE__,
37946 - tty->driver->name, port->count);
37947 + tty->driver->name, atomic_read(&port->count));
37948 }
37949
37950 /* Wait until the transmitter is empty.
37951 @@ -2507,7 +2507,7 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
37952
37953 if (debug_level >= DEBUG_LEVEL_INFO)
37954 printk("%s(%d):mgslpc_open(%s), old ref count = %d\n",
37955 - __FILE__, __LINE__, tty->driver->name, port->count);
37956 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
37957
37958 /* If port is closing, signal caller to try again */
37959 if (tty_hung_up_p(filp) || port->flags & ASYNC_CLOSING){
37960 @@ -2527,11 +2527,11 @@ static int mgslpc_open(struct tty_struct *tty, struct file * filp)
37961 goto cleanup;
37962 }
37963 spin_lock(&port->lock);
37964 - port->count++;
37965 + atomic_inc(&port->count);
37966 spin_unlock(&port->lock);
37967 spin_unlock_irqrestore(&info->netlock, flags);
37968
37969 - if (port->count == 1) {
37970 + if (atomic_read(&port->count) == 1) {
37971 /* 1st open on this device, init hardware */
37972 retval = startup(info, tty);
37973 if (retval < 0)
37974 @@ -3920,7 +3920,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
37975 unsigned short new_crctype;
37976
37977 /* return error if TTY interface open */
37978 - if (info->port.count)
37979 + if (atomic_read(&info->port.count))
37980 return -EBUSY;
37981
37982 switch (encoding)
37983 @@ -4024,7 +4024,7 @@ static int hdlcdev_open(struct net_device *dev)
37984
37985 /* arbitrate between network and tty opens */
37986 spin_lock_irqsave(&info->netlock, flags);
37987 - if (info->port.count != 0 || info->netcount != 0) {
37988 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
37989 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
37990 spin_unlock_irqrestore(&info->netlock, flags);
37991 return -EBUSY;
37992 @@ -4114,7 +4114,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
37993 printk("%s:hdlcdev_ioctl(%s)\n", __FILE__, dev->name);
37994
37995 /* return error if TTY interface open */
37996 - if (info->port.count)
37997 + if (atomic_read(&info->port.count))
37998 return -EBUSY;
37999
38000 if (cmd != SIOCWANDEV)
38001 diff --git a/drivers/char/random.c b/drivers/char/random.c
38002 index 429b75b..a4f540d 100644
38003 --- a/drivers/char/random.c
38004 +++ b/drivers/char/random.c
38005 @@ -270,10 +270,17 @@
38006 /*
38007 * Configuration information
38008 */
38009 +#ifdef CONFIG_GRKERNSEC_RANDNET
38010 +#define INPUT_POOL_SHIFT 14
38011 +#define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38012 +#define OUTPUT_POOL_SHIFT 12
38013 +#define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38014 +#else
38015 #define INPUT_POOL_SHIFT 12
38016 #define INPUT_POOL_WORDS (1 << (INPUT_POOL_SHIFT-5))
38017 #define OUTPUT_POOL_SHIFT 10
38018 #define OUTPUT_POOL_WORDS (1 << (OUTPUT_POOL_SHIFT-5))
38019 +#endif
38020 #define SEC_XFER_SIZE 512
38021 #define EXTRACT_SIZE 10
38022
38023 @@ -284,9 +291,6 @@
38024 /*
38025 * To allow fractional bits to be tracked, the entropy_count field is
38026 * denominated in units of 1/8th bits.
38027 - *
38028 - * 2*(ENTROPY_SHIFT + log2(poolbits)) must <= 31, or the multiply in
38029 - * credit_entropy_bits() needs to be 64 bits wide.
38030 */
38031 #define ENTROPY_SHIFT 3
38032 #define ENTROPY_BITS(r) ((r)->entropy_count >> ENTROPY_SHIFT)
38033 @@ -361,12 +365,19 @@ static struct poolinfo {
38034 #define S(x) ilog2(x)+5, (x), (x)*4, (x)*32, (x) << (ENTROPY_SHIFT+5)
38035 int tap1, tap2, tap3, tap4, tap5;
38036 } poolinfo_table[] = {
38037 +#ifdef CONFIG_GRKERNSEC_RANDNET
38038 + /* x^512 + x^411 + x^308 + x^208 +x^104 + x + 1 -- 225 */
38039 + { S(512), 411, 308, 208, 104, 1 },
38040 + /* x^128 + x^104 + x^76 + x^51 + x^25 + x + 1 -- 105 */
38041 + { S(128), 104, 76, 51, 25, 1 },
38042 +#else
38043 /* was: x^128 + x^103 + x^76 + x^51 +x^25 + x + 1 */
38044 /* x^128 + x^104 + x^76 + x^51 +x^25 + x + 1 */
38045 { S(128), 104, 76, 51, 25, 1 },
38046 /* was: x^32 + x^26 + x^20 + x^14 + x^7 + x + 1 */
38047 /* x^32 + x^26 + x^19 + x^14 + x^7 + x + 1 */
38048 { S(32), 26, 19, 14, 7, 1 },
38049 +#endif
38050 #if 0
38051 /* x^2048 + x^1638 + x^1231 + x^819 + x^411 + x + 1 -- 115 */
38052 { S(2048), 1638, 1231, 819, 411, 1 },
38053 @@ -524,8 +535,8 @@ static void _mix_pool_bytes(struct entropy_store *r, const void *in,
38054 input_rotate = (input_rotate + (i ? 7 : 14)) & 31;
38055 }
38056
38057 - ACCESS_ONCE(r->input_rotate) = input_rotate;
38058 - ACCESS_ONCE(r->add_ptr) = i;
38059 + ACCESS_ONCE_RW(r->input_rotate) = input_rotate;
38060 + ACCESS_ONCE_RW(r->add_ptr) = i;
38061 smp_wmb();
38062
38063 if (out)
38064 @@ -632,7 +643,7 @@ retry:
38065 /* The +2 corresponds to the /4 in the denominator */
38066
38067 do {
38068 - unsigned int anfrac = min(pnfrac, pool_size/2);
38069 + u64 anfrac = min(pnfrac, pool_size/2);
38070 unsigned int add =
38071 ((pool_size - entropy_count)*anfrac*3) >> s;
38072
38073 @@ -1151,7 +1162,7 @@ static ssize_t extract_entropy_user(struct entropy_store *r, void __user *buf,
38074
38075 extract_buf(r, tmp);
38076 i = min_t(int, nbytes, EXTRACT_SIZE);
38077 - if (copy_to_user(buf, tmp, i)) {
38078 + if (i > sizeof(tmp) || copy_to_user(buf, tmp, i)) {
38079 ret = -EFAULT;
38080 break;
38081 }
38082 @@ -1507,7 +1518,7 @@ EXPORT_SYMBOL(generate_random_uuid);
38083 #include <linux/sysctl.h>
38084
38085 static int min_read_thresh = 8, min_write_thresh;
38086 -static int max_read_thresh = INPUT_POOL_WORDS * 32;
38087 +static int max_read_thresh = OUTPUT_POOL_WORDS * 32;
38088 static int max_write_thresh = INPUT_POOL_WORDS * 32;
38089 static char sysctl_bootid[16];
38090
38091 @@ -1523,7 +1534,7 @@ static char sysctl_bootid[16];
38092 static int proc_do_uuid(struct ctl_table *table, int write,
38093 void __user *buffer, size_t *lenp, loff_t *ppos)
38094 {
38095 - struct ctl_table fake_table;
38096 + ctl_table_no_const fake_table;
38097 unsigned char buf[64], tmp_uuid[16], *uuid;
38098
38099 uuid = table->data;
38100 @@ -1553,7 +1564,7 @@ static int proc_do_uuid(struct ctl_table *table, int write,
38101 static int proc_do_entropy(ctl_table *table, int write,
38102 void __user *buffer, size_t *lenp, loff_t *ppos)
38103 {
38104 - ctl_table fake_table;
38105 + ctl_table_no_const fake_table;
38106 int entropy_count;
38107
38108 entropy_count = *(int *)table->data >> ENTROPY_SHIFT;
38109 diff --git a/drivers/char/sonypi.c b/drivers/char/sonypi.c
38110 index 7cc1fe22..b602d6b 100644
38111 --- a/drivers/char/sonypi.c
38112 +++ b/drivers/char/sonypi.c
38113 @@ -54,6 +54,7 @@
38114
38115 #include <asm/uaccess.h>
38116 #include <asm/io.h>
38117 +#include <asm/local.h>
38118
38119 #include <linux/sonypi.h>
38120
38121 @@ -490,7 +491,7 @@ static struct sonypi_device {
38122 spinlock_t fifo_lock;
38123 wait_queue_head_t fifo_proc_list;
38124 struct fasync_struct *fifo_async;
38125 - int open_count;
38126 + local_t open_count;
38127 int model;
38128 struct input_dev *input_jog_dev;
38129 struct input_dev *input_key_dev;
38130 @@ -892,7 +893,7 @@ static int sonypi_misc_fasync(int fd, struct file *filp, int on)
38131 static int sonypi_misc_release(struct inode *inode, struct file *file)
38132 {
38133 mutex_lock(&sonypi_device.lock);
38134 - sonypi_device.open_count--;
38135 + local_dec(&sonypi_device.open_count);
38136 mutex_unlock(&sonypi_device.lock);
38137 return 0;
38138 }
38139 @@ -901,9 +902,9 @@ static int sonypi_misc_open(struct inode *inode, struct file *file)
38140 {
38141 mutex_lock(&sonypi_device.lock);
38142 /* Flush input queue on first open */
38143 - if (!sonypi_device.open_count)
38144 + if (!local_read(&sonypi_device.open_count))
38145 kfifo_reset(&sonypi_device.fifo);
38146 - sonypi_device.open_count++;
38147 + local_inc(&sonypi_device.open_count);
38148 mutex_unlock(&sonypi_device.lock);
38149
38150 return 0;
38151 diff --git a/drivers/char/tpm/tpm_acpi.c b/drivers/char/tpm/tpm_acpi.c
38152 index 64420b3..5c40b56 100644
38153 --- a/drivers/char/tpm/tpm_acpi.c
38154 +++ b/drivers/char/tpm/tpm_acpi.c
38155 @@ -98,11 +98,12 @@ int read_log(struct tpm_bios_log *log)
38156 virt = acpi_os_map_memory(start, len);
38157 if (!virt) {
38158 kfree(log->bios_event_log);
38159 + log->bios_event_log = NULL;
38160 printk("%s: ERROR - Unable to map memory\n", __func__);
38161 return -EIO;
38162 }
38163
38164 - memcpy_fromio(log->bios_event_log, virt, len);
38165 + memcpy_fromio(log->bios_event_log, (const char __force_kernel *)virt, len);
38166
38167 acpi_os_unmap_memory(virt, len);
38168 return 0;
38169 diff --git a/drivers/char/tpm/tpm_eventlog.c b/drivers/char/tpm/tpm_eventlog.c
38170 index 59f7cb2..bac8b6d 100644
38171 --- a/drivers/char/tpm/tpm_eventlog.c
38172 +++ b/drivers/char/tpm/tpm_eventlog.c
38173 @@ -95,7 +95,7 @@ static void *tpm_bios_measurements_start(struct seq_file *m, loff_t *pos)
38174 event = addr;
38175
38176 if ((event->event_type == 0 && event->event_size == 0) ||
38177 - ((addr + sizeof(struct tcpa_event) + event->event_size) >= limit))
38178 + (event->event_size >= limit - addr - sizeof(struct tcpa_event)))
38179 return NULL;
38180
38181 return addr;
38182 @@ -120,7 +120,7 @@ static void *tpm_bios_measurements_next(struct seq_file *m, void *v,
38183 return NULL;
38184
38185 if ((event->event_type == 0 && event->event_size == 0) ||
38186 - ((v + sizeof(struct tcpa_event) + event->event_size) >= limit))
38187 + (event->event_size >= limit - v - sizeof(struct tcpa_event)))
38188 return NULL;
38189
38190 (*pos)++;
38191 @@ -213,7 +213,8 @@ static int tpm_binary_bios_measurements_show(struct seq_file *m, void *v)
38192 int i;
38193
38194 for (i = 0; i < sizeof(struct tcpa_event) + event->event_size; i++)
38195 - seq_putc(m, data[i]);
38196 + if (!seq_putc(m, data[i]))
38197 + return -EFAULT;
38198
38199 return 0;
38200 }
38201 diff --git a/drivers/char/virtio_console.c b/drivers/char/virtio_console.c
38202 index feea87c..18aefff 100644
38203 --- a/drivers/char/virtio_console.c
38204 +++ b/drivers/char/virtio_console.c
38205 @@ -684,7 +684,7 @@ static ssize_t fill_readbuf(struct port *port, char *out_buf, size_t out_count,
38206 if (to_user) {
38207 ssize_t ret;
38208
38209 - ret = copy_to_user(out_buf, buf->buf + buf->offset, out_count);
38210 + ret = copy_to_user((char __force_user *)out_buf, buf->buf + buf->offset, out_count);
38211 if (ret)
38212 return -EFAULT;
38213 } else {
38214 @@ -787,7 +787,7 @@ static ssize_t port_fops_read(struct file *filp, char __user *ubuf,
38215 if (!port_has_data(port) && !port->host_connected)
38216 return 0;
38217
38218 - return fill_readbuf(port, ubuf, count, true);
38219 + return fill_readbuf(port, (char __force_kernel *)ubuf, count, true);
38220 }
38221
38222 static int wait_port_writable(struct port *port, bool nonblock)
38223 diff --git a/drivers/clk/clk-composite.c b/drivers/clk/clk-composite.c
38224 index a33f46f..a720eed 100644
38225 --- a/drivers/clk/clk-composite.c
38226 +++ b/drivers/clk/clk-composite.c
38227 @@ -122,7 +122,7 @@ struct clk *clk_register_composite(struct device *dev, const char *name,
38228 struct clk *clk;
38229 struct clk_init_data init;
38230 struct clk_composite *composite;
38231 - struct clk_ops *clk_composite_ops;
38232 + clk_ops_no_const *clk_composite_ops;
38233
38234 composite = kzalloc(sizeof(*composite), GFP_KERNEL);
38235 if (!composite) {
38236 diff --git a/drivers/clk/socfpga/clk.c b/drivers/clk/socfpga/clk.c
38237 index 81dd31a..ef5c542 100644
38238 --- a/drivers/clk/socfpga/clk.c
38239 +++ b/drivers/clk/socfpga/clk.c
38240 @@ -22,6 +22,7 @@
38241 #include <linux/clk-provider.h>
38242 #include <linux/io.h>
38243 #include <linux/of.h>
38244 +#include <asm/pgtable.h>
38245
38246 /* Clock Manager offsets */
38247 #define CLKMGR_CTRL 0x0
38248 @@ -152,8 +153,10 @@ static __init struct clk *socfpga_clk_init(struct device_node *node,
38249 streq(clk_name, "periph_pll") ||
38250 streq(clk_name, "sdram_pll")) {
38251 socfpga_clk->hw.bit_idx = SOCFPGA_PLL_EXT_ENA;
38252 - clk_pll_ops.enable = clk_gate_ops.enable;
38253 - clk_pll_ops.disable = clk_gate_ops.disable;
38254 + pax_open_kernel();
38255 + *(void **)&clk_pll_ops.enable = clk_gate_ops.enable;
38256 + *(void **)&clk_pll_ops.disable = clk_gate_ops.disable;
38257 + pax_close_kernel();
38258 }
38259
38260 clk = clk_register(NULL, &socfpga_clk->hw.hw);
38261 @@ -244,7 +247,7 @@ static unsigned long socfpga_clk_recalc_rate(struct clk_hw *hwclk,
38262 return parent_rate / div;
38263 }
38264
38265 -static struct clk_ops gateclk_ops = {
38266 +static clk_ops_no_const gateclk_ops __read_only = {
38267 .recalc_rate = socfpga_clk_recalc_rate,
38268 .get_parent = socfpga_clk_get_parent,
38269 .set_parent = socfpga_clk_set_parent,
38270 diff --git a/drivers/cpufreq/acpi-cpufreq.c b/drivers/cpufreq/acpi-cpufreq.c
38271 index caf41eb..223d27a 100644
38272 --- a/drivers/cpufreq/acpi-cpufreq.c
38273 +++ b/drivers/cpufreq/acpi-cpufreq.c
38274 @@ -172,7 +172,7 @@ static ssize_t show_global_boost(struct kobject *kobj,
38275 return sprintf(buf, "%u\n", boost_enabled);
38276 }
38277
38278 -static struct global_attr global_boost = __ATTR(boost, 0644,
38279 +static global_attr_no_const global_boost = __ATTR(boost, 0644,
38280 show_global_boost,
38281 store_global_boost);
38282
38283 @@ -693,8 +693,11 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38284 data->acpi_data = per_cpu_ptr(acpi_perf_data, cpu);
38285 per_cpu(acfreq_data, cpu) = data;
38286
38287 - if (cpu_has(c, X86_FEATURE_CONSTANT_TSC))
38288 - acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38289 + if (cpu_has(c, X86_FEATURE_CONSTANT_TSC)) {
38290 + pax_open_kernel();
38291 + *(u8 *)&acpi_cpufreq_driver.flags |= CPUFREQ_CONST_LOOPS;
38292 + pax_close_kernel();
38293 + }
38294
38295 result = acpi_processor_register_performance(data->acpi_data, cpu);
38296 if (result)
38297 @@ -827,7 +830,9 @@ static int acpi_cpufreq_cpu_init(struct cpufreq_policy *policy)
38298 policy->cur = acpi_cpufreq_guess_freq(data, policy->cpu);
38299 break;
38300 case ACPI_ADR_SPACE_FIXED_HARDWARE:
38301 - acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38302 + pax_open_kernel();
38303 + *(void **)&acpi_cpufreq_driver.get = get_cur_freq_on_cpu;
38304 + pax_close_kernel();
38305 break;
38306 default:
38307 break;
38308 diff --git a/drivers/cpufreq/cpufreq.c b/drivers/cpufreq/cpufreq.c
38309 index 8d19f7c..6bc2daa 100644
38310 --- a/drivers/cpufreq/cpufreq.c
38311 +++ b/drivers/cpufreq/cpufreq.c
38312 @@ -1885,7 +1885,7 @@ void cpufreq_unregister_governor(struct cpufreq_governor *governor)
38313 #endif
38314
38315 mutex_lock(&cpufreq_governor_mutex);
38316 - list_del(&governor->governor_list);
38317 + pax_list_del(&governor->governor_list);
38318 mutex_unlock(&cpufreq_governor_mutex);
38319 return;
38320 }
38321 @@ -2115,7 +2115,7 @@ static int cpufreq_cpu_callback(struct notifier_block *nfb,
38322 return NOTIFY_OK;
38323 }
38324
38325 -static struct notifier_block __refdata cpufreq_cpu_notifier = {
38326 +static struct notifier_block cpufreq_cpu_notifier = {
38327 .notifier_call = cpufreq_cpu_callback,
38328 };
38329
38330 @@ -2148,8 +2148,11 @@ int cpufreq_register_driver(struct cpufreq_driver *driver_data)
38331
38332 pr_debug("trying to register driver %s\n", driver_data->name);
38333
38334 - if (driver_data->setpolicy)
38335 - driver_data->flags |= CPUFREQ_CONST_LOOPS;
38336 + if (driver_data->setpolicy) {
38337 + pax_open_kernel();
38338 + *(u8 *)&driver_data->flags |= CPUFREQ_CONST_LOOPS;
38339 + pax_close_kernel();
38340 + }
38341
38342 write_lock_irqsave(&cpufreq_driver_lock, flags);
38343 if (cpufreq_driver) {
38344 diff --git a/drivers/cpufreq/cpufreq_governor.c b/drivers/cpufreq/cpufreq_governor.c
38345 index e6be635..f8a90dc 100644
38346 --- a/drivers/cpufreq/cpufreq_governor.c
38347 +++ b/drivers/cpufreq/cpufreq_governor.c
38348 @@ -187,7 +187,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38349 struct dbs_data *dbs_data;
38350 struct od_cpu_dbs_info_s *od_dbs_info = NULL;
38351 struct cs_cpu_dbs_info_s *cs_dbs_info = NULL;
38352 - struct od_ops *od_ops = NULL;
38353 + const struct od_ops *od_ops = NULL;
38354 struct od_dbs_tuners *od_tuners = NULL;
38355 struct cs_dbs_tuners *cs_tuners = NULL;
38356 struct cpu_dbs_common_info *cpu_cdbs;
38357 @@ -253,7 +253,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38358
38359 if ((cdata->governor == GOV_CONSERVATIVE) &&
38360 (!policy->governor->initialized)) {
38361 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38362 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38363
38364 cpufreq_register_notifier(cs_ops->notifier_block,
38365 CPUFREQ_TRANSITION_NOTIFIER);
38366 @@ -273,7 +273,7 @@ int cpufreq_governor_dbs(struct cpufreq_policy *policy,
38367
38368 if ((dbs_data->cdata->governor == GOV_CONSERVATIVE) &&
38369 (policy->governor->initialized == 1)) {
38370 - struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38371 + const struct cs_ops *cs_ops = dbs_data->cdata->gov_ops;
38372
38373 cpufreq_unregister_notifier(cs_ops->notifier_block,
38374 CPUFREQ_TRANSITION_NOTIFIER);
38375 diff --git a/drivers/cpufreq/cpufreq_governor.h b/drivers/cpufreq/cpufreq_governor.h
38376 index b5f2b86..daa801b 100644
38377 --- a/drivers/cpufreq/cpufreq_governor.h
38378 +++ b/drivers/cpufreq/cpufreq_governor.h
38379 @@ -205,7 +205,7 @@ struct common_dbs_data {
38380 void (*exit)(struct dbs_data *dbs_data);
38381
38382 /* Governor specific ops, see below */
38383 - void *gov_ops;
38384 + const void *gov_ops;
38385 };
38386
38387 /* Governor Per policy data */
38388 @@ -225,7 +225,7 @@ struct od_ops {
38389 unsigned int (*powersave_bias_target)(struct cpufreq_policy *policy,
38390 unsigned int freq_next, unsigned int relation);
38391 void (*freq_increase)(struct cpufreq_policy *policy, unsigned int freq);
38392 -};
38393 +} __no_const;
38394
38395 struct cs_ops {
38396 struct notifier_block *notifier_block;
38397 diff --git a/drivers/cpufreq/cpufreq_ondemand.c b/drivers/cpufreq/cpufreq_ondemand.c
38398 index 18d4091..434be15 100644
38399 --- a/drivers/cpufreq/cpufreq_ondemand.c
38400 +++ b/drivers/cpufreq/cpufreq_ondemand.c
38401 @@ -521,7 +521,7 @@ static void od_exit(struct dbs_data *dbs_data)
38402
38403 define_get_cpu_dbs_routines(od_cpu_dbs_info);
38404
38405 -static struct od_ops od_ops = {
38406 +static struct od_ops od_ops __read_only = {
38407 .powersave_bias_init_cpu = ondemand_powersave_bias_init_cpu,
38408 .powersave_bias_target = generic_powersave_bias_target,
38409 .freq_increase = dbs_freq_increase,
38410 @@ -576,14 +576,18 @@ void od_register_powersave_bias_handler(unsigned int (*f)
38411 (struct cpufreq_policy *, unsigned int, unsigned int),
38412 unsigned int powersave_bias)
38413 {
38414 - od_ops.powersave_bias_target = f;
38415 + pax_open_kernel();
38416 + *(void **)&od_ops.powersave_bias_target = f;
38417 + pax_close_kernel();
38418 od_set_powersave_bias(powersave_bias);
38419 }
38420 EXPORT_SYMBOL_GPL(od_register_powersave_bias_handler);
38421
38422 void od_unregister_powersave_bias_handler(void)
38423 {
38424 - od_ops.powersave_bias_target = generic_powersave_bias_target;
38425 + pax_open_kernel();
38426 + *(void **)&od_ops.powersave_bias_target = generic_powersave_bias_target;
38427 + pax_close_kernel();
38428 od_set_powersave_bias(0);
38429 }
38430 EXPORT_SYMBOL_GPL(od_unregister_powersave_bias_handler);
38431 diff --git a/drivers/cpufreq/cpufreq_stats.c b/drivers/cpufreq/cpufreq_stats.c
38432 index 4cf0d28..5830372 100644
38433 --- a/drivers/cpufreq/cpufreq_stats.c
38434 +++ b/drivers/cpufreq/cpufreq_stats.c
38435 @@ -352,7 +352,7 @@ static int cpufreq_stat_cpu_callback(struct notifier_block *nfb,
38436 }
38437
38438 /* priority=1 so this will get called before cpufreq_remove_dev */
38439 -static struct notifier_block cpufreq_stat_cpu_notifier __refdata = {
38440 +static struct notifier_block cpufreq_stat_cpu_notifier = {
38441 .notifier_call = cpufreq_stat_cpu_callback,
38442 .priority = 1,
38443 };
38444 diff --git a/drivers/cpufreq/intel_pstate.c b/drivers/cpufreq/intel_pstate.c
38445 index d51f17ed..9f43b15 100644
38446 --- a/drivers/cpufreq/intel_pstate.c
38447 +++ b/drivers/cpufreq/intel_pstate.c
38448 @@ -112,10 +112,10 @@ struct pstate_funcs {
38449 struct cpu_defaults {
38450 struct pstate_adjust_policy pid_policy;
38451 struct pstate_funcs funcs;
38452 -};
38453 +} __do_const;
38454
38455 static struct pstate_adjust_policy pid_params;
38456 -static struct pstate_funcs pstate_funcs;
38457 +static struct pstate_funcs *pstate_funcs;
38458
38459 struct perf_limits {
38460 int no_turbo;
38461 @@ -462,7 +462,7 @@ static void intel_pstate_set_pstate(struct cpudata *cpu, int pstate)
38462
38463 cpu->pstate.current_pstate = pstate;
38464
38465 - pstate_funcs.set(pstate);
38466 + pstate_funcs->set(pstate);
38467 }
38468
38469 static inline void intel_pstate_pstate_increase(struct cpudata *cpu, int steps)
38470 @@ -484,9 +484,9 @@ static void intel_pstate_get_cpu_pstates(struct cpudata *cpu)
38471 {
38472 sprintf(cpu->name, "Intel 2nd generation core");
38473
38474 - cpu->pstate.min_pstate = pstate_funcs.get_min();
38475 - cpu->pstate.max_pstate = pstate_funcs.get_max();
38476 - cpu->pstate.turbo_pstate = pstate_funcs.get_turbo();
38477 + cpu->pstate.min_pstate = pstate_funcs->get_min();
38478 + cpu->pstate.max_pstate = pstate_funcs->get_max();
38479 + cpu->pstate.turbo_pstate = pstate_funcs->get_turbo();
38480
38481 /*
38482 * goto max pstate so we don't slow up boot if we are built-in if we are
38483 @@ -750,9 +750,9 @@ static int intel_pstate_msrs_not_valid(void)
38484 rdmsrl(MSR_IA32_APERF, aperf);
38485 rdmsrl(MSR_IA32_MPERF, mperf);
38486
38487 - if (!pstate_funcs.get_max() ||
38488 - !pstate_funcs.get_min() ||
38489 - !pstate_funcs.get_turbo())
38490 + if (!pstate_funcs->get_max() ||
38491 + !pstate_funcs->get_min() ||
38492 + !pstate_funcs->get_turbo())
38493 return -ENODEV;
38494
38495 rdmsrl(MSR_IA32_APERF, tmp);
38496 @@ -766,7 +766,7 @@ static int intel_pstate_msrs_not_valid(void)
38497 return 0;
38498 }
38499
38500 -static void copy_pid_params(struct pstate_adjust_policy *policy)
38501 +static void copy_pid_params(const struct pstate_adjust_policy *policy)
38502 {
38503 pid_params.sample_rate_ms = policy->sample_rate_ms;
38504 pid_params.p_gain_pct = policy->p_gain_pct;
38505 @@ -778,10 +778,7 @@ static void copy_pid_params(struct pstate_adjust_policy *policy)
38506
38507 static void copy_cpu_funcs(struct pstate_funcs *funcs)
38508 {
38509 - pstate_funcs.get_max = funcs->get_max;
38510 - pstate_funcs.get_min = funcs->get_min;
38511 - pstate_funcs.get_turbo = funcs->get_turbo;
38512 - pstate_funcs.set = funcs->set;
38513 + pstate_funcs = funcs;
38514 }
38515
38516 #if IS_ENABLED(CONFIG_ACPI)
38517 diff --git a/drivers/cpufreq/p4-clockmod.c b/drivers/cpufreq/p4-clockmod.c
38518 index 3d1cba9..0ab21d2 100644
38519 --- a/drivers/cpufreq/p4-clockmod.c
38520 +++ b/drivers/cpufreq/p4-clockmod.c
38521 @@ -134,10 +134,14 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
38522 case 0x0F: /* Core Duo */
38523 case 0x16: /* Celeron Core */
38524 case 0x1C: /* Atom */
38525 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38526 + pax_open_kernel();
38527 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38528 + pax_close_kernel();
38529 return speedstep_get_frequency(SPEEDSTEP_CPU_PCORE);
38530 case 0x0D: /* Pentium M (Dothan) */
38531 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38532 + pax_open_kernel();
38533 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38534 + pax_close_kernel();
38535 /* fall through */
38536 case 0x09: /* Pentium M (Banias) */
38537 return speedstep_get_frequency(SPEEDSTEP_CPU_PM);
38538 @@ -149,7 +153,9 @@ static unsigned int cpufreq_p4_get_frequency(struct cpuinfo_x86 *c)
38539
38540 /* on P-4s, the TSC runs with constant frequency independent whether
38541 * throttling is active or not. */
38542 - p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38543 + pax_open_kernel();
38544 + *(u8 *)&p4clockmod_driver.flags |= CPUFREQ_CONST_LOOPS;
38545 + pax_close_kernel();
38546
38547 if (speedstep_detect_processor() == SPEEDSTEP_CPU_P4M) {
38548 printk(KERN_WARNING PFX "Warning: Pentium 4-M detected. "
38549 diff --git a/drivers/cpufreq/sparc-us3-cpufreq.c b/drivers/cpufreq/sparc-us3-cpufreq.c
38550 index 724ffbd..ad83692 100644
38551 --- a/drivers/cpufreq/sparc-us3-cpufreq.c
38552 +++ b/drivers/cpufreq/sparc-us3-cpufreq.c
38553 @@ -18,14 +18,12 @@
38554 #include <asm/head.h>
38555 #include <asm/timer.h>
38556
38557 -static struct cpufreq_driver *cpufreq_us3_driver;
38558 -
38559 struct us3_freq_percpu_info {
38560 struct cpufreq_frequency_table table[4];
38561 };
38562
38563 /* Indexed by cpu number. */
38564 -static struct us3_freq_percpu_info *us3_freq_table;
38565 +static struct us3_freq_percpu_info us3_freq_table[NR_CPUS];
38566
38567 /* UltraSPARC-III has three dividers: 1, 2, and 32. These are controlled
38568 * in the Safari config register.
38569 @@ -156,14 +154,26 @@ static int __init us3_freq_cpu_init(struct cpufreq_policy *policy)
38570
38571 static int us3_freq_cpu_exit(struct cpufreq_policy *policy)
38572 {
38573 - if (cpufreq_us3_driver) {
38574 - cpufreq_frequency_table_put_attr(policy->cpu);
38575 - us3_freq_target(policy, 0);
38576 - }
38577 + cpufreq_frequency_table_put_attr(policy->cpu);
38578 + us3_freq_target(policy, 0);
38579
38580 return 0;
38581 }
38582
38583 +static int __init us3_freq_init(void);
38584 +static void __exit us3_freq_exit(void);
38585 +
38586 +static struct cpufreq_driver cpufreq_us3_driver = {
38587 + .init = us3_freq_cpu_init,
38588 + .verify = cpufreq_generic_frequency_table_verify,
38589 + .target_index = us3_freq_target,
38590 + .get = us3_freq_get,
38591 + .exit = us3_freq_cpu_exit,
38592 + .owner = THIS_MODULE,
38593 + .name = "UltraSPARC-III",
38594 +
38595 +};
38596 +
38597 static int __init us3_freq_init(void)
38598 {
38599 unsigned long manuf, impl, ver;
38600 @@ -180,55 +190,15 @@ static int __init us3_freq_init(void)
38601 (impl == CHEETAH_IMPL ||
38602 impl == CHEETAH_PLUS_IMPL ||
38603 impl == JAGUAR_IMPL ||
38604 - impl == PANTHER_IMPL)) {
38605 - struct cpufreq_driver *driver;
38606 -
38607 - ret = -ENOMEM;
38608 - driver = kzalloc(sizeof(*driver), GFP_KERNEL);
38609 - if (!driver)
38610 - goto err_out;
38611 -
38612 - us3_freq_table = kzalloc((NR_CPUS * sizeof(*us3_freq_table)),
38613 - GFP_KERNEL);
38614 - if (!us3_freq_table)
38615 - goto err_out;
38616 -
38617 - driver->init = us3_freq_cpu_init;
38618 - driver->verify = cpufreq_generic_frequency_table_verify;
38619 - driver->target_index = us3_freq_target;
38620 - driver->get = us3_freq_get;
38621 - driver->exit = us3_freq_cpu_exit;
38622 - strcpy(driver->name, "UltraSPARC-III");
38623 -
38624 - cpufreq_us3_driver = driver;
38625 - ret = cpufreq_register_driver(driver);
38626 - if (ret)
38627 - goto err_out;
38628 -
38629 - return 0;
38630 -
38631 -err_out:
38632 - if (driver) {
38633 - kfree(driver);
38634 - cpufreq_us3_driver = NULL;
38635 - }
38636 - kfree(us3_freq_table);
38637 - us3_freq_table = NULL;
38638 - return ret;
38639 - }
38640 + impl == PANTHER_IMPL))
38641 + return cpufreq_register_driver(&cpufreq_us3_driver);
38642
38643 return -ENODEV;
38644 }
38645
38646 static void __exit us3_freq_exit(void)
38647 {
38648 - if (cpufreq_us3_driver) {
38649 - cpufreq_unregister_driver(cpufreq_us3_driver);
38650 - kfree(cpufreq_us3_driver);
38651 - cpufreq_us3_driver = NULL;
38652 - kfree(us3_freq_table);
38653 - us3_freq_table = NULL;
38654 - }
38655 + cpufreq_unregister_driver(&cpufreq_us3_driver);
38656 }
38657
38658 MODULE_AUTHOR("David S. Miller <davem@redhat.com>");
38659 diff --git a/drivers/cpufreq/speedstep-centrino.c b/drivers/cpufreq/speedstep-centrino.c
38660 index 4e1daca..e707b61 100644
38661 --- a/drivers/cpufreq/speedstep-centrino.c
38662 +++ b/drivers/cpufreq/speedstep-centrino.c
38663 @@ -351,8 +351,11 @@ static int centrino_cpu_init(struct cpufreq_policy *policy)
38664 !cpu_has(cpu, X86_FEATURE_EST))
38665 return -ENODEV;
38666
38667 - if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC))
38668 - centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
38669 + if (cpu_has(cpu, X86_FEATURE_CONSTANT_TSC)) {
38670 + pax_open_kernel();
38671 + *(u8 *)&centrino_driver.flags |= CPUFREQ_CONST_LOOPS;
38672 + pax_close_kernel();
38673 + }
38674
38675 if (policy->cpu != 0)
38676 return -ENODEV;
38677 diff --git a/drivers/cpuidle/driver.c b/drivers/cpuidle/driver.c
38678 index 06dbe7c..c2c8671 100644
38679 --- a/drivers/cpuidle/driver.c
38680 +++ b/drivers/cpuidle/driver.c
38681 @@ -202,7 +202,7 @@ static int poll_idle(struct cpuidle_device *dev,
38682
38683 static void poll_idle_init(struct cpuidle_driver *drv)
38684 {
38685 - struct cpuidle_state *state = &drv->states[0];
38686 + cpuidle_state_no_const *state = &drv->states[0];
38687
38688 snprintf(state->name, CPUIDLE_NAME_LEN, "POLL");
38689 snprintf(state->desc, CPUIDLE_DESC_LEN, "CPUIDLE CORE POLL IDLE");
38690 diff --git a/drivers/cpuidle/governor.c b/drivers/cpuidle/governor.c
38691 index ca89412..a7b9c49 100644
38692 --- a/drivers/cpuidle/governor.c
38693 +++ b/drivers/cpuidle/governor.c
38694 @@ -87,7 +87,7 @@ int cpuidle_register_governor(struct cpuidle_governor *gov)
38695 mutex_lock(&cpuidle_lock);
38696 if (__cpuidle_find_governor(gov->name) == NULL) {
38697 ret = 0;
38698 - list_add_tail(&gov->governor_list, &cpuidle_governors);
38699 + pax_list_add_tail((struct list_head *)&gov->governor_list, &cpuidle_governors);
38700 if (!cpuidle_curr_governor ||
38701 cpuidle_curr_governor->rating < gov->rating)
38702 cpuidle_switch_governor(gov);
38703 diff --git a/drivers/cpuidle/sysfs.c b/drivers/cpuidle/sysfs.c
38704 index e918b6d..f87ea80 100644
38705 --- a/drivers/cpuidle/sysfs.c
38706 +++ b/drivers/cpuidle/sysfs.c
38707 @@ -135,7 +135,7 @@ static struct attribute *cpuidle_switch_attrs[] = {
38708 NULL
38709 };
38710
38711 -static struct attribute_group cpuidle_attr_group = {
38712 +static attribute_group_no_const cpuidle_attr_group = {
38713 .attrs = cpuidle_default_attrs,
38714 .name = "cpuidle",
38715 };
38716 diff --git a/drivers/crypto/hifn_795x.c b/drivers/crypto/hifn_795x.c
38717 index 12fea3e..1e28f47 100644
38718 --- a/drivers/crypto/hifn_795x.c
38719 +++ b/drivers/crypto/hifn_795x.c
38720 @@ -51,7 +51,7 @@ module_param_string(hifn_pll_ref, hifn_pll_ref, sizeof(hifn_pll_ref), 0444);
38721 MODULE_PARM_DESC(hifn_pll_ref,
38722 "PLL reference clock (pci[freq] or ext[freq], default ext)");
38723
38724 -static atomic_t hifn_dev_number;
38725 +static atomic_unchecked_t hifn_dev_number;
38726
38727 #define ACRYPTO_OP_DECRYPT 0
38728 #define ACRYPTO_OP_ENCRYPT 1
38729 @@ -2577,7 +2577,7 @@ static int hifn_probe(struct pci_dev *pdev, const struct pci_device_id *id)
38730 goto err_out_disable_pci_device;
38731
38732 snprintf(name, sizeof(name), "hifn%d",
38733 - atomic_inc_return(&hifn_dev_number)-1);
38734 + atomic_inc_return_unchecked(&hifn_dev_number)-1);
38735
38736 err = pci_request_regions(pdev, name);
38737 if (err)
38738 diff --git a/drivers/devfreq/devfreq.c b/drivers/devfreq/devfreq.c
38739 index a0b2f7e..1b6f028 100644
38740 --- a/drivers/devfreq/devfreq.c
38741 +++ b/drivers/devfreq/devfreq.c
38742 @@ -607,7 +607,7 @@ int devfreq_add_governor(struct devfreq_governor *governor)
38743 goto err_out;
38744 }
38745
38746 - list_add(&governor->node, &devfreq_governor_list);
38747 + pax_list_add((struct list_head *)&governor->node, &devfreq_governor_list);
38748
38749 list_for_each_entry(devfreq, &devfreq_list, node) {
38750 int ret = 0;
38751 @@ -695,7 +695,7 @@ int devfreq_remove_governor(struct devfreq_governor *governor)
38752 }
38753 }
38754
38755 - list_del(&governor->node);
38756 + pax_list_del((struct list_head *)&governor->node);
38757 err_out:
38758 mutex_unlock(&devfreq_list_lock);
38759
38760 diff --git a/drivers/dma/sh/shdmac.c b/drivers/dma/sh/shdmac.c
38761 index 0d765c0..60b7480 100644
38762 --- a/drivers/dma/sh/shdmac.c
38763 +++ b/drivers/dma/sh/shdmac.c
38764 @@ -511,7 +511,7 @@ static int sh_dmae_nmi_handler(struct notifier_block *self,
38765 return ret;
38766 }
38767
38768 -static struct notifier_block sh_dmae_nmi_notifier __read_mostly = {
38769 +static struct notifier_block sh_dmae_nmi_notifier = {
38770 .notifier_call = sh_dmae_nmi_handler,
38771
38772 /* Run before NMI debug handler and KGDB */
38773 diff --git a/drivers/edac/edac_device.c b/drivers/edac/edac_device.c
38774 index 1026743..80b081c 100644
38775 --- a/drivers/edac/edac_device.c
38776 +++ b/drivers/edac/edac_device.c
38777 @@ -474,9 +474,9 @@ void edac_device_reset_delay_period(struct edac_device_ctl_info *edac_dev,
38778 */
38779 int edac_device_alloc_index(void)
38780 {
38781 - static atomic_t device_indexes = ATOMIC_INIT(0);
38782 + static atomic_unchecked_t device_indexes = ATOMIC_INIT(0);
38783
38784 - return atomic_inc_return(&device_indexes) - 1;
38785 + return atomic_inc_return_unchecked(&device_indexes) - 1;
38786 }
38787 EXPORT_SYMBOL_GPL(edac_device_alloc_index);
38788
38789 diff --git a/drivers/edac/edac_mc_sysfs.c b/drivers/edac/edac_mc_sysfs.c
38790 index 9f7e0e60..348c875 100644
38791 --- a/drivers/edac/edac_mc_sysfs.c
38792 +++ b/drivers/edac/edac_mc_sysfs.c
38793 @@ -150,7 +150,7 @@ static const char * const edac_caps[] = {
38794 struct dev_ch_attribute {
38795 struct device_attribute attr;
38796 int channel;
38797 -};
38798 +} __do_const;
38799
38800 #define DEVICE_CHANNEL(_name, _mode, _show, _store, _var) \
38801 struct dev_ch_attribute dev_attr_legacy_##_name = \
38802 @@ -1007,14 +1007,16 @@ int edac_create_sysfs_mci_device(struct mem_ctl_info *mci)
38803 }
38804
38805 if (mci->set_sdram_scrub_rate || mci->get_sdram_scrub_rate) {
38806 + pax_open_kernel();
38807 if (mci->get_sdram_scrub_rate) {
38808 - dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
38809 - dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
38810 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IRUGO;
38811 + *(void **)&dev_attr_sdram_scrub_rate.show = &mci_sdram_scrub_rate_show;
38812 }
38813 if (mci->set_sdram_scrub_rate) {
38814 - dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
38815 - dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
38816 + *(umode_t *)&dev_attr_sdram_scrub_rate.attr.mode |= S_IWUSR;
38817 + *(void **)&dev_attr_sdram_scrub_rate.store = &mci_sdram_scrub_rate_store;
38818 }
38819 + pax_close_kernel();
38820 err = device_create_file(&mci->dev,
38821 &dev_attr_sdram_scrub_rate);
38822 if (err) {
38823 diff --git a/drivers/edac/edac_pci.c b/drivers/edac/edac_pci.c
38824 index 2cf44b4d..6dd2dc7 100644
38825 --- a/drivers/edac/edac_pci.c
38826 +++ b/drivers/edac/edac_pci.c
38827 @@ -29,7 +29,7 @@
38828
38829 static DEFINE_MUTEX(edac_pci_ctls_mutex);
38830 static LIST_HEAD(edac_pci_list);
38831 -static atomic_t pci_indexes = ATOMIC_INIT(0);
38832 +static atomic_unchecked_t pci_indexes = ATOMIC_INIT(0);
38833
38834 /*
38835 * edac_pci_alloc_ctl_info
38836 @@ -315,7 +315,7 @@ EXPORT_SYMBOL_GPL(edac_pci_reset_delay_period);
38837 */
38838 int edac_pci_alloc_index(void)
38839 {
38840 - return atomic_inc_return(&pci_indexes) - 1;
38841 + return atomic_inc_return_unchecked(&pci_indexes) - 1;
38842 }
38843 EXPORT_SYMBOL_GPL(edac_pci_alloc_index);
38844
38845 diff --git a/drivers/edac/edac_pci_sysfs.c b/drivers/edac/edac_pci_sysfs.c
38846 index e8658e4..22746d6 100644
38847 --- a/drivers/edac/edac_pci_sysfs.c
38848 +++ b/drivers/edac/edac_pci_sysfs.c
38849 @@ -26,8 +26,8 @@ static int edac_pci_log_pe = 1; /* log PCI parity errors */
38850 static int edac_pci_log_npe = 1; /* log PCI non-parity error errors */
38851 static int edac_pci_poll_msec = 1000; /* one second workq period */
38852
38853 -static atomic_t pci_parity_count = ATOMIC_INIT(0);
38854 -static atomic_t pci_nonparity_count = ATOMIC_INIT(0);
38855 +static atomic_unchecked_t pci_parity_count = ATOMIC_INIT(0);
38856 +static atomic_unchecked_t pci_nonparity_count = ATOMIC_INIT(0);
38857
38858 static struct kobject *edac_pci_top_main_kobj;
38859 static atomic_t edac_pci_sysfs_refcount = ATOMIC_INIT(0);
38860 @@ -235,7 +235,7 @@ struct edac_pci_dev_attribute {
38861 void *value;
38862 ssize_t(*show) (void *, char *);
38863 ssize_t(*store) (void *, const char *, size_t);
38864 -};
38865 +} __do_const;
38866
38867 /* Set of show/store abstract level functions for PCI Parity object */
38868 static ssize_t edac_pci_dev_show(struct kobject *kobj, struct attribute *attr,
38869 @@ -579,7 +579,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38870 edac_printk(KERN_CRIT, EDAC_PCI,
38871 "Signaled System Error on %s\n",
38872 pci_name(dev));
38873 - atomic_inc(&pci_nonparity_count);
38874 + atomic_inc_unchecked(&pci_nonparity_count);
38875 }
38876
38877 if (status & (PCI_STATUS_PARITY)) {
38878 @@ -587,7 +587,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38879 "Master Data Parity Error on %s\n",
38880 pci_name(dev));
38881
38882 - atomic_inc(&pci_parity_count);
38883 + atomic_inc_unchecked(&pci_parity_count);
38884 }
38885
38886 if (status & (PCI_STATUS_DETECTED_PARITY)) {
38887 @@ -595,7 +595,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38888 "Detected Parity Error on %s\n",
38889 pci_name(dev));
38890
38891 - atomic_inc(&pci_parity_count);
38892 + atomic_inc_unchecked(&pci_parity_count);
38893 }
38894 }
38895
38896 @@ -618,7 +618,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38897 edac_printk(KERN_CRIT, EDAC_PCI, "Bridge "
38898 "Signaled System Error on %s\n",
38899 pci_name(dev));
38900 - atomic_inc(&pci_nonparity_count);
38901 + atomic_inc_unchecked(&pci_nonparity_count);
38902 }
38903
38904 if (status & (PCI_STATUS_PARITY)) {
38905 @@ -626,7 +626,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38906 "Master Data Parity Error on "
38907 "%s\n", pci_name(dev));
38908
38909 - atomic_inc(&pci_parity_count);
38910 + atomic_inc_unchecked(&pci_parity_count);
38911 }
38912
38913 if (status & (PCI_STATUS_DETECTED_PARITY)) {
38914 @@ -634,7 +634,7 @@ static void edac_pci_dev_parity_test(struct pci_dev *dev)
38915 "Detected Parity Error on %s\n",
38916 pci_name(dev));
38917
38918 - atomic_inc(&pci_parity_count);
38919 + atomic_inc_unchecked(&pci_parity_count);
38920 }
38921 }
38922 }
38923 @@ -672,7 +672,7 @@ void edac_pci_do_parity_check(void)
38924 if (!check_pci_errors)
38925 return;
38926
38927 - before_count = atomic_read(&pci_parity_count);
38928 + before_count = atomic_read_unchecked(&pci_parity_count);
38929
38930 /* scan all PCI devices looking for a Parity Error on devices and
38931 * bridges.
38932 @@ -684,7 +684,7 @@ void edac_pci_do_parity_check(void)
38933 /* Only if operator has selected panic on PCI Error */
38934 if (edac_pci_get_panic_on_pe()) {
38935 /* If the count is different 'after' from 'before' */
38936 - if (before_count != atomic_read(&pci_parity_count))
38937 + if (before_count != atomic_read_unchecked(&pci_parity_count))
38938 panic("EDAC: PCI Parity Error");
38939 }
38940 }
38941 diff --git a/drivers/edac/mce_amd.h b/drivers/edac/mce_amd.h
38942 index 51b7e3a..aa8a3e8 100644
38943 --- a/drivers/edac/mce_amd.h
38944 +++ b/drivers/edac/mce_amd.h
38945 @@ -77,7 +77,7 @@ struct amd_decoder_ops {
38946 bool (*mc0_mce)(u16, u8);
38947 bool (*mc1_mce)(u16, u8);
38948 bool (*mc2_mce)(u16, u8);
38949 -};
38950 +} __no_const;
38951
38952 void amd_report_gart_errors(bool);
38953 void amd_register_ecc_decoder(void (*f)(int, struct mce *));
38954 diff --git a/drivers/firewire/core-card.c b/drivers/firewire/core-card.c
38955 index 57ea7f4..af06b76 100644
38956 --- a/drivers/firewire/core-card.c
38957 +++ b/drivers/firewire/core-card.c
38958 @@ -528,9 +528,9 @@ void fw_card_initialize(struct fw_card *card,
38959 const struct fw_card_driver *driver,
38960 struct device *device)
38961 {
38962 - static atomic_t index = ATOMIC_INIT(-1);
38963 + static atomic_unchecked_t index = ATOMIC_INIT(-1);
38964
38965 - card->index = atomic_inc_return(&index);
38966 + card->index = atomic_inc_return_unchecked(&index);
38967 card->driver = driver;
38968 card->device = device;
38969 card->current_tlabel = 0;
38970 @@ -680,7 +680,7 @@ EXPORT_SYMBOL_GPL(fw_card_release);
38971
38972 void fw_core_remove_card(struct fw_card *card)
38973 {
38974 - struct fw_card_driver dummy_driver = dummy_driver_template;
38975 + fw_card_driver_no_const dummy_driver = dummy_driver_template;
38976
38977 card->driver->update_phy_reg(card, 4,
38978 PHY_LINK_ACTIVE | PHY_CONTENDER, 0);
38979 diff --git a/drivers/firewire/core-device.c b/drivers/firewire/core-device.c
38980 index de4aa40..49ab1f2 100644
38981 --- a/drivers/firewire/core-device.c
38982 +++ b/drivers/firewire/core-device.c
38983 @@ -253,7 +253,7 @@ EXPORT_SYMBOL(fw_device_enable_phys_dma);
38984 struct config_rom_attribute {
38985 struct device_attribute attr;
38986 u32 key;
38987 -};
38988 +} __do_const;
38989
38990 static ssize_t show_immediate(struct device *dev,
38991 struct device_attribute *dattr, char *buf)
38992 diff --git a/drivers/firewire/core-transaction.c b/drivers/firewire/core-transaction.c
38993 index 0e79951..b180217 100644
38994 --- a/drivers/firewire/core-transaction.c
38995 +++ b/drivers/firewire/core-transaction.c
38996 @@ -38,6 +38,7 @@
38997 #include <linux/timer.h>
38998 #include <linux/types.h>
38999 #include <linux/workqueue.h>
39000 +#include <linux/sched.h>
39001
39002 #include <asm/byteorder.h>
39003
39004 diff --git a/drivers/firewire/core.h b/drivers/firewire/core.h
39005 index 515a42c..5ecf3ba 100644
39006 --- a/drivers/firewire/core.h
39007 +++ b/drivers/firewire/core.h
39008 @@ -111,6 +111,7 @@ struct fw_card_driver {
39009
39010 int (*stop_iso)(struct fw_iso_context *ctx);
39011 };
39012 +typedef struct fw_card_driver __no_const fw_card_driver_no_const;
39013
39014 void fw_card_initialize(struct fw_card *card,
39015 const struct fw_card_driver *driver, struct device *device);
39016 diff --git a/drivers/firmware/dmi-id.c b/drivers/firmware/dmi-id.c
39017 index 94a58a0..f5eba42 100644
39018 --- a/drivers/firmware/dmi-id.c
39019 +++ b/drivers/firmware/dmi-id.c
39020 @@ -16,7 +16,7 @@
39021 struct dmi_device_attribute{
39022 struct device_attribute dev_attr;
39023 int field;
39024 -};
39025 +} __do_const;
39026 #define to_dmi_dev_attr(_dev_attr) \
39027 container_of(_dev_attr, struct dmi_device_attribute, dev_attr)
39028
39029 diff --git a/drivers/firmware/dmi_scan.c b/drivers/firmware/dmi_scan.c
39030 index c7e81ff..94a7401 100644
39031 --- a/drivers/firmware/dmi_scan.c
39032 +++ b/drivers/firmware/dmi_scan.c
39033 @@ -835,7 +835,7 @@ int dmi_walk(void (*decode)(const struct dmi_header *, void *),
39034 if (buf == NULL)
39035 return -1;
39036
39037 - dmi_table(buf, dmi_len, dmi_num, decode, private_data);
39038 + dmi_table((char __force_kernel *)buf, dmi_len, dmi_num, decode, private_data);
39039
39040 iounmap(buf);
39041 return 0;
39042 diff --git a/drivers/firmware/efi/cper.c b/drivers/firmware/efi/cper.c
39043 index 1491dd4..aa910db 100644
39044 --- a/drivers/firmware/efi/cper.c
39045 +++ b/drivers/firmware/efi/cper.c
39046 @@ -41,12 +41,12 @@
39047 */
39048 u64 cper_next_record_id(void)
39049 {
39050 - static atomic64_t seq;
39051 + static atomic64_unchecked_t seq;
39052
39053 - if (!atomic64_read(&seq))
39054 - atomic64_set(&seq, ((u64)get_seconds()) << 32);
39055 + if (!atomic64_read_unchecked(&seq))
39056 + atomic64_set_unchecked(&seq, ((u64)get_seconds()) << 32);
39057
39058 - return atomic64_inc_return(&seq);
39059 + return atomic64_inc_return_unchecked(&seq);
39060 }
39061 EXPORT_SYMBOL_GPL(cper_next_record_id);
39062
39063 diff --git a/drivers/firmware/efi/efi.c b/drivers/firmware/efi/efi.c
39064 index 2e2fbde..7676c8b 100644
39065 --- a/drivers/firmware/efi/efi.c
39066 +++ b/drivers/firmware/efi/efi.c
39067 @@ -81,14 +81,16 @@ static struct attribute_group efi_subsys_attr_group = {
39068 };
39069
39070 static struct efivars generic_efivars;
39071 -static struct efivar_operations generic_ops;
39072 +static efivar_operations_no_const generic_ops __read_only;
39073
39074 static int generic_ops_register(void)
39075 {
39076 - generic_ops.get_variable = efi.get_variable;
39077 - generic_ops.set_variable = efi.set_variable;
39078 - generic_ops.get_next_variable = efi.get_next_variable;
39079 - generic_ops.query_variable_store = efi_query_variable_store;
39080 + pax_open_kernel();
39081 + *(void **)&generic_ops.get_variable = efi.get_variable;
39082 + *(void **)&generic_ops.set_variable = efi.set_variable;
39083 + *(void **)&generic_ops.get_next_variable = efi.get_next_variable;
39084 + *(void **)&generic_ops.query_variable_store = efi_query_variable_store;
39085 + pax_close_kernel();
39086
39087 return efivars_register(&generic_efivars, &generic_ops, efi_kobj);
39088 }
39089 diff --git a/drivers/firmware/efi/efivars.c b/drivers/firmware/efi/efivars.c
39090 index 3dc2482..7bd2f61 100644
39091 --- a/drivers/firmware/efi/efivars.c
39092 +++ b/drivers/firmware/efi/efivars.c
39093 @@ -456,7 +456,7 @@ efivar_create_sysfs_entry(struct efivar_entry *new_var)
39094 static int
39095 create_efivars_bin_attributes(void)
39096 {
39097 - struct bin_attribute *attr;
39098 + bin_attribute_no_const *attr;
39099 int error;
39100
39101 /* new_var */
39102 diff --git a/drivers/firmware/google/memconsole.c b/drivers/firmware/google/memconsole.c
39103 index 2a90ba6..07f3733 100644
39104 --- a/drivers/firmware/google/memconsole.c
39105 +++ b/drivers/firmware/google/memconsole.c
39106 @@ -147,7 +147,9 @@ static int __init memconsole_init(void)
39107 if (!found_memconsole())
39108 return -ENODEV;
39109
39110 - memconsole_bin_attr.size = memconsole_length;
39111 + pax_open_kernel();
39112 + *(size_t *)&memconsole_bin_attr.size = memconsole_length;
39113 + pax_close_kernel();
39114
39115 ret = sysfs_create_bin_file(firmware_kobj, &memconsole_bin_attr);
39116
39117 diff --git a/drivers/gpio/gpio-ich.c b/drivers/gpio/gpio-ich.c
39118 index 814addb..0937d7f 100644
39119 --- a/drivers/gpio/gpio-ich.c
39120 +++ b/drivers/gpio/gpio-ich.c
39121 @@ -71,7 +71,7 @@ struct ichx_desc {
39122 /* Some chipsets have quirks, let these use their own request/get */
39123 int (*request)(struct gpio_chip *chip, unsigned offset);
39124 int (*get)(struct gpio_chip *chip, unsigned offset);
39125 -};
39126 +} __do_const;
39127
39128 static struct {
39129 spinlock_t lock;
39130 diff --git a/drivers/gpio/gpio-vr41xx.c b/drivers/gpio/gpio-vr41xx.c
39131 index 9902732..64b62dd 100644
39132 --- a/drivers/gpio/gpio-vr41xx.c
39133 +++ b/drivers/gpio/gpio-vr41xx.c
39134 @@ -204,7 +204,7 @@ static int giu_get_irq(unsigned int irq)
39135 printk(KERN_ERR "spurious GIU interrupt: %04x(%04x),%04x(%04x)\n",
39136 maskl, pendl, maskh, pendh);
39137
39138 - atomic_inc(&irq_err_count);
39139 + atomic_inc_unchecked(&irq_err_count);
39140
39141 return -EINVAL;
39142 }
39143 diff --git a/drivers/gpu/drm/armada/armada_drv.c b/drivers/gpu/drm/armada/armada_drv.c
39144 index 62d0ff3..073dbf3 100644
39145 --- a/drivers/gpu/drm/armada/armada_drv.c
39146 +++ b/drivers/gpu/drm/armada/armada_drv.c
39147 @@ -68,15 +68,7 @@ void __armada_drm_queue_unref_work(struct drm_device *dev,
39148 {
39149 struct armada_private *priv = dev->dev_private;
39150
39151 - /*
39152 - * Yes, we really must jump through these hoops just to store a
39153 - * _pointer_ to something into the kfifo. This is utterly insane
39154 - * and idiotic, because it kfifo requires the _data_ pointed to by
39155 - * the pointer const, not the pointer itself. Not only that, but
39156 - * you have to pass a pointer _to_ the pointer you want stored.
39157 - */
39158 - const struct drm_framebuffer *silly_api_alert = fb;
39159 - WARN_ON(!kfifo_put(&priv->fb_unref, &silly_api_alert));
39160 + WARN_ON(!kfifo_put(&priv->fb_unref, fb));
39161 schedule_work(&priv->fb_unref_work);
39162 }
39163
39164 diff --git a/drivers/gpu/drm/drm_crtc.c b/drivers/gpu/drm/drm_crtc.c
39165 index d6cf77c..2842146 100644
39166 --- a/drivers/gpu/drm/drm_crtc.c
39167 +++ b/drivers/gpu/drm/drm_crtc.c
39168 @@ -3102,7 +3102,7 @@ int drm_mode_getproperty_ioctl(struct drm_device *dev,
39169 goto done;
39170 }
39171
39172 - if (copy_to_user(&enum_ptr[copied].name,
39173 + if (copy_to_user(enum_ptr[copied].name,
39174 &prop_enum->name, DRM_PROP_NAME_LEN)) {
39175 ret = -EFAULT;
39176 goto done;
39177 diff --git a/drivers/gpu/drm/drm_crtc_helper.c b/drivers/gpu/drm/drm_crtc_helper.c
39178 index 01361ab..891e821 100644
39179 --- a/drivers/gpu/drm/drm_crtc_helper.c
39180 +++ b/drivers/gpu/drm/drm_crtc_helper.c
39181 @@ -338,7 +338,7 @@ static bool drm_encoder_crtc_ok(struct drm_encoder *encoder,
39182 struct drm_crtc *tmp;
39183 int crtc_mask = 1;
39184
39185 - WARN(!crtc, "checking null crtc?\n");
39186 + BUG_ON(!crtc);
39187
39188 dev = crtc->dev;
39189
39190 diff --git a/drivers/gpu/drm/drm_drv.c b/drivers/gpu/drm/drm_drv.c
39191 index d9137e4..69b73a0 100644
39192 --- a/drivers/gpu/drm/drm_drv.c
39193 +++ b/drivers/gpu/drm/drm_drv.c
39194 @@ -233,7 +233,7 @@ module_exit(drm_core_exit);
39195 /**
39196 * Copy and IOCTL return string to user space
39197 */
39198 -static int drm_copy_field(char *buf, size_t *buf_len, const char *value)
39199 +static int drm_copy_field(char __user *buf, size_t *buf_len, const char *value)
39200 {
39201 int len;
39202
39203 @@ -303,7 +303,7 @@ long drm_ioctl(struct file *filp,
39204 struct drm_file *file_priv = filp->private_data;
39205 struct drm_device *dev;
39206 const struct drm_ioctl_desc *ioctl = NULL;
39207 - drm_ioctl_t *func;
39208 + drm_ioctl_no_const_t func;
39209 unsigned int nr = DRM_IOCTL_NR(cmd);
39210 int retcode = -EINVAL;
39211 char stack_kdata[128];
39212 diff --git a/drivers/gpu/drm/drm_fops.c b/drivers/gpu/drm/drm_fops.c
39213 index c5b929c..8a3b8be 100644
39214 --- a/drivers/gpu/drm/drm_fops.c
39215 +++ b/drivers/gpu/drm/drm_fops.c
39216 @@ -97,7 +97,7 @@ int drm_open(struct inode *inode, struct file *filp)
39217 if (drm_device_is_unplugged(dev))
39218 return -ENODEV;
39219
39220 - if (!dev->open_count++)
39221 + if (local_inc_return(&dev->open_count) == 1)
39222 need_setup = 1;
39223 mutex_lock(&dev->struct_mutex);
39224 old_imapping = inode->i_mapping;
39225 @@ -127,7 +127,7 @@ err_undo:
39226 iput(container_of(dev->dev_mapping, struct inode, i_data));
39227 dev->dev_mapping = old_mapping;
39228 mutex_unlock(&dev->struct_mutex);
39229 - dev->open_count--;
39230 + local_dec(&dev->open_count);
39231 return retcode;
39232 }
39233 EXPORT_SYMBOL(drm_open);
39234 @@ -467,7 +467,7 @@ int drm_release(struct inode *inode, struct file *filp)
39235
39236 mutex_lock(&drm_global_mutex);
39237
39238 - DRM_DEBUG("open_count = %d\n", dev->open_count);
39239 + DRM_DEBUG("open_count = %ld\n", local_read(&dev->open_count));
39240
39241 if (dev->driver->preclose)
39242 dev->driver->preclose(dev, file_priv);
39243 @@ -476,10 +476,10 @@ int drm_release(struct inode *inode, struct file *filp)
39244 * Begin inline drm_release
39245 */
39246
39247 - DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %d\n",
39248 + DRM_DEBUG("pid = %d, device = 0x%lx, open_count = %ld\n",
39249 task_pid_nr(current),
39250 (long)old_encode_dev(file_priv->minor->device),
39251 - dev->open_count);
39252 + local_read(&dev->open_count));
39253
39254 /* Release any auth tokens that might point to this file_priv,
39255 (do that under the drm_global_mutex) */
39256 @@ -577,7 +577,7 @@ int drm_release(struct inode *inode, struct file *filp)
39257 * End inline drm_release
39258 */
39259
39260 - if (!--dev->open_count) {
39261 + if (local_dec_and_test(&dev->open_count)) {
39262 if (atomic_read(&dev->ioctl_count)) {
39263 DRM_ERROR("Device busy: %d\n",
39264 atomic_read(&dev->ioctl_count));
39265 diff --git a/drivers/gpu/drm/drm_global.c b/drivers/gpu/drm/drm_global.c
39266 index 3d2e91c..d31c4c9 100644
39267 --- a/drivers/gpu/drm/drm_global.c
39268 +++ b/drivers/gpu/drm/drm_global.c
39269 @@ -36,7 +36,7 @@
39270 struct drm_global_item {
39271 struct mutex mutex;
39272 void *object;
39273 - int refcount;
39274 + atomic_t refcount;
39275 };
39276
39277 static struct drm_global_item glob[DRM_GLOBAL_NUM];
39278 @@ -49,7 +49,7 @@ void drm_global_init(void)
39279 struct drm_global_item *item = &glob[i];
39280 mutex_init(&item->mutex);
39281 item->object = NULL;
39282 - item->refcount = 0;
39283 + atomic_set(&item->refcount, 0);
39284 }
39285 }
39286
39287 @@ -59,7 +59,7 @@ void drm_global_release(void)
39288 for (i = 0; i < DRM_GLOBAL_NUM; ++i) {
39289 struct drm_global_item *item = &glob[i];
39290 BUG_ON(item->object != NULL);
39291 - BUG_ON(item->refcount != 0);
39292 + BUG_ON(atomic_read(&item->refcount) != 0);
39293 }
39294 }
39295
39296 @@ -69,7 +69,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39297 struct drm_global_item *item = &glob[ref->global_type];
39298
39299 mutex_lock(&item->mutex);
39300 - if (item->refcount == 0) {
39301 + if (atomic_read(&item->refcount) == 0) {
39302 item->object = kzalloc(ref->size, GFP_KERNEL);
39303 if (unlikely(item->object == NULL)) {
39304 ret = -ENOMEM;
39305 @@ -82,7 +82,7 @@ int drm_global_item_ref(struct drm_global_reference *ref)
39306 goto out_err;
39307
39308 }
39309 - ++item->refcount;
39310 + atomic_inc(&item->refcount);
39311 ref->object = item->object;
39312 mutex_unlock(&item->mutex);
39313 return 0;
39314 @@ -98,9 +98,9 @@ void drm_global_item_unref(struct drm_global_reference *ref)
39315 struct drm_global_item *item = &glob[ref->global_type];
39316
39317 mutex_lock(&item->mutex);
39318 - BUG_ON(item->refcount == 0);
39319 + BUG_ON(atomic_read(&item->refcount) == 0);
39320 BUG_ON(ref->object != item->object);
39321 - if (--item->refcount == 0) {
39322 + if (atomic_dec_and_test(&item->refcount)) {
39323 ref->release(ref);
39324 item->object = NULL;
39325 }
39326 diff --git a/drivers/gpu/drm/drm_info.c b/drivers/gpu/drm/drm_info.c
39327 index 7d5a152..d7186da 100644
39328 --- a/drivers/gpu/drm/drm_info.c
39329 +++ b/drivers/gpu/drm/drm_info.c
39330 @@ -75,10 +75,14 @@ int drm_vm_info(struct seq_file *m, void *data)
39331 struct drm_local_map *map;
39332 struct drm_map_list *r_list;
39333
39334 - /* Hardcoded from _DRM_FRAME_BUFFER,
39335 - _DRM_REGISTERS, _DRM_SHM, _DRM_AGP, and
39336 - _DRM_SCATTER_GATHER and _DRM_CONSISTENT */
39337 - const char *types[] = { "FB", "REG", "SHM", "AGP", "SG", "PCI" };
39338 + static const char * const types[] = {
39339 + [_DRM_FRAME_BUFFER] = "FB",
39340 + [_DRM_REGISTERS] = "REG",
39341 + [_DRM_SHM] = "SHM",
39342 + [_DRM_AGP] = "AGP",
39343 + [_DRM_SCATTER_GATHER] = "SG",
39344 + [_DRM_CONSISTENT] = "PCI",
39345 + [_DRM_GEM] = "GEM" };
39346 const char *type;
39347 int i;
39348
39349 @@ -89,7 +93,7 @@ int drm_vm_info(struct seq_file *m, void *data)
39350 map = r_list->map;
39351 if (!map)
39352 continue;
39353 - if (map->type < 0 || map->type > 5)
39354 + if (map->type >= ARRAY_SIZE(types))
39355 type = "??";
39356 else
39357 type = types[map->type];
39358 @@ -257,7 +261,11 @@ int drm_vma_info(struct seq_file *m, void *data)
39359 vma->vm_flags & VM_MAYSHARE ? 's' : 'p',
39360 vma->vm_flags & VM_LOCKED ? 'l' : '-',
39361 vma->vm_flags & VM_IO ? 'i' : '-',
39362 +#ifdef CONFIG_GRKERNSEC_HIDESYM
39363 + 0);
39364 +#else
39365 vma->vm_pgoff);
39366 +#endif
39367
39368 #if defined(__i386__)
39369 pgprot = pgprot_val(vma->vm_page_prot);
39370 diff --git a/drivers/gpu/drm/drm_ioc32.c b/drivers/gpu/drm/drm_ioc32.c
39371 index 2f4c434..dd12cd2 100644
39372 --- a/drivers/gpu/drm/drm_ioc32.c
39373 +++ b/drivers/gpu/drm/drm_ioc32.c
39374 @@ -457,7 +457,7 @@ static int compat_drm_infobufs(struct file *file, unsigned int cmd,
39375 request = compat_alloc_user_space(nbytes);
39376 if (!access_ok(VERIFY_WRITE, request, nbytes))
39377 return -EFAULT;
39378 - list = (struct drm_buf_desc *) (request + 1);
39379 + list = (struct drm_buf_desc __user *) (request + 1);
39380
39381 if (__put_user(count, &request->count)
39382 || __put_user(list, &request->list))
39383 @@ -518,7 +518,7 @@ static int compat_drm_mapbufs(struct file *file, unsigned int cmd,
39384 request = compat_alloc_user_space(nbytes);
39385 if (!access_ok(VERIFY_WRITE, request, nbytes))
39386 return -EFAULT;
39387 - list = (struct drm_buf_pub *) (request + 1);
39388 + list = (struct drm_buf_pub __user *) (request + 1);
39389
39390 if (__put_user(count, &request->count)
39391 || __put_user(list, &request->list))
39392 @@ -1016,7 +1016,7 @@ static int compat_drm_wait_vblank(struct file *file, unsigned int cmd,
39393 return 0;
39394 }
39395
39396 -drm_ioctl_compat_t *drm_compat_ioctls[] = {
39397 +drm_ioctl_compat_t drm_compat_ioctls[] = {
39398 [DRM_IOCTL_NR(DRM_IOCTL_VERSION32)] = compat_drm_version,
39399 [DRM_IOCTL_NR(DRM_IOCTL_GET_UNIQUE32)] = compat_drm_getunique,
39400 [DRM_IOCTL_NR(DRM_IOCTL_GET_MAP32)] = compat_drm_getmap,
39401 @@ -1062,7 +1062,6 @@ drm_ioctl_compat_t *drm_compat_ioctls[] = {
39402 long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39403 {
39404 unsigned int nr = DRM_IOCTL_NR(cmd);
39405 - drm_ioctl_compat_t *fn;
39406 int ret;
39407
39408 /* Assume that ioctls without an explicit compat routine will just
39409 @@ -1072,10 +1071,8 @@ long drm_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39410 if (nr >= ARRAY_SIZE(drm_compat_ioctls))
39411 return drm_ioctl(filp, cmd, arg);
39412
39413 - fn = drm_compat_ioctls[nr];
39414 -
39415 - if (fn != NULL)
39416 - ret = (*fn) (filp, cmd, arg);
39417 + if (drm_compat_ioctls[nr] != NULL)
39418 + ret = (*drm_compat_ioctls[nr]) (filp, cmd, arg);
39419 else
39420 ret = drm_ioctl(filp, cmd, arg);
39421
39422 diff --git a/drivers/gpu/drm/drm_stub.c b/drivers/gpu/drm/drm_stub.c
39423 index 66dd3a0..3bed6c4 100644
39424 --- a/drivers/gpu/drm/drm_stub.c
39425 +++ b/drivers/gpu/drm/drm_stub.c
39426 @@ -403,7 +403,7 @@ void drm_unplug_dev(struct drm_device *dev)
39427
39428 drm_device_set_unplugged(dev);
39429
39430 - if (dev->open_count == 0) {
39431 + if (local_read(&dev->open_count) == 0) {
39432 drm_put_dev(dev);
39433 }
39434 mutex_unlock(&drm_global_mutex);
39435 diff --git a/drivers/gpu/drm/drm_sysfs.c b/drivers/gpu/drm/drm_sysfs.c
39436 index c22c309..ae758c3 100644
39437 --- a/drivers/gpu/drm/drm_sysfs.c
39438 +++ b/drivers/gpu/drm/drm_sysfs.c
39439 @@ -505,7 +505,7 @@ static void drm_sysfs_release(struct device *dev)
39440 */
39441 int drm_sysfs_device_add(struct drm_minor *minor)
39442 {
39443 - char *minor_str;
39444 + const char *minor_str;
39445 int r;
39446
39447 if (minor->type == DRM_MINOR_CONTROL)
39448 diff --git a/drivers/gpu/drm/i810/i810_drv.h b/drivers/gpu/drm/i810/i810_drv.h
39449 index d4d16ed..8fb0b51 100644
39450 --- a/drivers/gpu/drm/i810/i810_drv.h
39451 +++ b/drivers/gpu/drm/i810/i810_drv.h
39452 @@ -108,8 +108,8 @@ typedef struct drm_i810_private {
39453 int page_flipping;
39454
39455 wait_queue_head_t irq_queue;
39456 - atomic_t irq_received;
39457 - atomic_t irq_emitted;
39458 + atomic_unchecked_t irq_received;
39459 + atomic_unchecked_t irq_emitted;
39460
39461 int front_offset;
39462 } drm_i810_private_t;
39463 diff --git a/drivers/gpu/drm/i915/i915_debugfs.c b/drivers/gpu/drm/i915/i915_debugfs.c
39464 index 6ed45a9..eb6dc41 100644
39465 --- a/drivers/gpu/drm/i915/i915_debugfs.c
39466 +++ b/drivers/gpu/drm/i915/i915_debugfs.c
39467 @@ -702,7 +702,7 @@ static int i915_interrupt_info(struct seq_file *m, void *data)
39468 I915_READ(GTIMR));
39469 }
39470 seq_printf(m, "Interrupts received: %d\n",
39471 - atomic_read(&dev_priv->irq_received));
39472 + atomic_read_unchecked(&dev_priv->irq_received));
39473 for_each_ring(ring, dev_priv, i) {
39474 if (INTEL_INFO(dev)->gen >= 6) {
39475 seq_printf(m,
39476 diff --git a/drivers/gpu/drm/i915/i915_dma.c b/drivers/gpu/drm/i915/i915_dma.c
39477 index e02266a..e3411aa 100644
39478 --- a/drivers/gpu/drm/i915/i915_dma.c
39479 +++ b/drivers/gpu/drm/i915/i915_dma.c
39480 @@ -1271,7 +1271,7 @@ static bool i915_switcheroo_can_switch(struct pci_dev *pdev)
39481 bool can_switch;
39482
39483 spin_lock(&dev->count_lock);
39484 - can_switch = (dev->open_count == 0);
39485 + can_switch = (local_read(&dev->open_count) == 0);
39486 spin_unlock(&dev->count_lock);
39487 return can_switch;
39488 }
39489 diff --git a/drivers/gpu/drm/i915/i915_drv.h b/drivers/gpu/drm/i915/i915_drv.h
39490 index 221ac62..f56acc8 100644
39491 --- a/drivers/gpu/drm/i915/i915_drv.h
39492 +++ b/drivers/gpu/drm/i915/i915_drv.h
39493 @@ -1326,7 +1326,7 @@ typedef struct drm_i915_private {
39494 drm_dma_handle_t *status_page_dmah;
39495 struct resource mch_res;
39496
39497 - atomic_t irq_received;
39498 + atomic_unchecked_t irq_received;
39499
39500 /* protects the irq masks */
39501 spinlock_t irq_lock;
39502 diff --git a/drivers/gpu/drm/i915/i915_gem_execbuffer.c b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
39503 index a3ba9a8..ee52ddd 100644
39504 --- a/drivers/gpu/drm/i915/i915_gem_execbuffer.c
39505 +++ b/drivers/gpu/drm/i915/i915_gem_execbuffer.c
39506 @@ -861,9 +861,9 @@ i915_gem_check_execbuffer(struct drm_i915_gem_execbuffer2 *exec)
39507
39508 static int
39509 validate_exec_list(struct drm_i915_gem_exec_object2 *exec,
39510 - int count)
39511 + unsigned int count)
39512 {
39513 - int i;
39514 + unsigned int i;
39515 unsigned relocs_total = 0;
39516 unsigned relocs_max = UINT_MAX / sizeof(struct drm_i915_gem_relocation_entry);
39517
39518 diff --git a/drivers/gpu/drm/i915/i915_ioc32.c b/drivers/gpu/drm/i915/i915_ioc32.c
39519 index 3c59584..500f2e9 100644
39520 --- a/drivers/gpu/drm/i915/i915_ioc32.c
39521 +++ b/drivers/gpu/drm/i915/i915_ioc32.c
39522 @@ -181,7 +181,7 @@ static int compat_i915_alloc(struct file *file, unsigned int cmd,
39523 (unsigned long)request);
39524 }
39525
39526 -static drm_ioctl_compat_t *i915_compat_ioctls[] = {
39527 +static drm_ioctl_compat_t i915_compat_ioctls[] = {
39528 [DRM_I915_BATCHBUFFER] = compat_i915_batchbuffer,
39529 [DRM_I915_CMDBUFFER] = compat_i915_cmdbuffer,
39530 [DRM_I915_GETPARAM] = compat_i915_getparam,
39531 @@ -202,18 +202,15 @@ static drm_ioctl_compat_t *i915_compat_ioctls[] = {
39532 long i915_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39533 {
39534 unsigned int nr = DRM_IOCTL_NR(cmd);
39535 - drm_ioctl_compat_t *fn = NULL;
39536 int ret;
39537
39538 if (nr < DRM_COMMAND_BASE)
39539 return drm_compat_ioctl(filp, cmd, arg);
39540
39541 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls))
39542 - fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
39543 -
39544 - if (fn != NULL)
39545 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(i915_compat_ioctls)) {
39546 + drm_ioctl_compat_t fn = i915_compat_ioctls[nr - DRM_COMMAND_BASE];
39547 ret = (*fn) (filp, cmd, arg);
39548 - else
39549 + } else
39550 ret = drm_ioctl(filp, cmd, arg);
39551
39552 return ret;
39553 diff --git a/drivers/gpu/drm/i915/i915_irq.c b/drivers/gpu/drm/i915/i915_irq.c
39554 index f13d5ed..8e6f36d 100644
39555 --- a/drivers/gpu/drm/i915/i915_irq.c
39556 +++ b/drivers/gpu/drm/i915/i915_irq.c
39557 @@ -1420,7 +1420,7 @@ static irqreturn_t valleyview_irq_handler(int irq, void *arg)
39558 int pipe;
39559 u32 pipe_stats[I915_MAX_PIPES];
39560
39561 - atomic_inc(&dev_priv->irq_received);
39562 + atomic_inc_unchecked(&dev_priv->irq_received);
39563
39564 while (true) {
39565 iir = I915_READ(VLV_IIR);
39566 @@ -1730,7 +1730,7 @@ static irqreturn_t ironlake_irq_handler(int irq, void *arg)
39567 u32 de_iir, gt_iir, de_ier, sde_ier = 0;
39568 irqreturn_t ret = IRQ_NONE;
39569
39570 - atomic_inc(&dev_priv->irq_received);
39571 + atomic_inc_unchecked(&dev_priv->irq_received);
39572
39573 /* We get interrupts on unclaimed registers, so check for this before we
39574 * do any I915_{READ,WRITE}. */
39575 @@ -1800,7 +1800,7 @@ static irqreturn_t gen8_irq_handler(int irq, void *arg)
39576 uint32_t tmp = 0;
39577 enum pipe pipe;
39578
39579 - atomic_inc(&dev_priv->irq_received);
39580 + atomic_inc_unchecked(&dev_priv->irq_received);
39581
39582 master_ctl = I915_READ(GEN8_MASTER_IRQ);
39583 master_ctl &= ~GEN8_MASTER_IRQ_CONTROL;
39584 @@ -2624,7 +2624,7 @@ static void ironlake_irq_preinstall(struct drm_device *dev)
39585 {
39586 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39587
39588 - atomic_set(&dev_priv->irq_received, 0);
39589 + atomic_set_unchecked(&dev_priv->irq_received, 0);
39590
39591 I915_WRITE(HWSTAM, 0xeffe);
39592
39593 @@ -2642,7 +2642,7 @@ static void valleyview_irq_preinstall(struct drm_device *dev)
39594 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39595 int pipe;
39596
39597 - atomic_set(&dev_priv->irq_received, 0);
39598 + atomic_set_unchecked(&dev_priv->irq_received, 0);
39599
39600 /* VLV magic */
39601 I915_WRITE(VLV_IMR, 0);
39602 @@ -2673,7 +2673,7 @@ static void gen8_irq_preinstall(struct drm_device *dev)
39603 struct drm_i915_private *dev_priv = dev->dev_private;
39604 int pipe;
39605
39606 - atomic_set(&dev_priv->irq_received, 0);
39607 + atomic_set_unchecked(&dev_priv->irq_received, 0);
39608
39609 I915_WRITE(GEN8_MASTER_IRQ, 0);
39610 POSTING_READ(GEN8_MASTER_IRQ);
39611 @@ -2999,7 +2999,7 @@ static void gen8_irq_uninstall(struct drm_device *dev)
39612 if (!dev_priv)
39613 return;
39614
39615 - atomic_set(&dev_priv->irq_received, 0);
39616 + atomic_set_unchecked(&dev_priv->irq_received, 0);
39617
39618 I915_WRITE(GEN8_MASTER_IRQ, 0);
39619
39620 @@ -3093,7 +3093,7 @@ static void i8xx_irq_preinstall(struct drm_device * dev)
39621 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39622 int pipe;
39623
39624 - atomic_set(&dev_priv->irq_received, 0);
39625 + atomic_set_unchecked(&dev_priv->irq_received, 0);
39626
39627 for_each_pipe(pipe)
39628 I915_WRITE(PIPESTAT(pipe), 0);
39629 @@ -3179,7 +3179,7 @@ static irqreturn_t i8xx_irq_handler(int irq, void *arg)
39630 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
39631 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39632
39633 - atomic_inc(&dev_priv->irq_received);
39634 + atomic_inc_unchecked(&dev_priv->irq_received);
39635
39636 iir = I915_READ16(IIR);
39637 if (iir == 0)
39638 @@ -3254,7 +3254,7 @@ static void i915_irq_preinstall(struct drm_device * dev)
39639 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39640 int pipe;
39641
39642 - atomic_set(&dev_priv->irq_received, 0);
39643 + atomic_set_unchecked(&dev_priv->irq_received, 0);
39644
39645 if (I915_HAS_HOTPLUG(dev)) {
39646 I915_WRITE(PORT_HOTPLUG_EN, 0);
39647 @@ -3361,7 +3361,7 @@ static irqreturn_t i915_irq_handler(int irq, void *arg)
39648 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39649 int pipe, ret = IRQ_NONE;
39650
39651 - atomic_inc(&dev_priv->irq_received);
39652 + atomic_inc_unchecked(&dev_priv->irq_received);
39653
39654 iir = I915_READ(IIR);
39655 do {
39656 @@ -3488,7 +3488,7 @@ static void i965_irq_preinstall(struct drm_device * dev)
39657 drm_i915_private_t *dev_priv = (drm_i915_private_t *) dev->dev_private;
39658 int pipe;
39659
39660 - atomic_set(&dev_priv->irq_received, 0);
39661 + atomic_set_unchecked(&dev_priv->irq_received, 0);
39662
39663 I915_WRITE(PORT_HOTPLUG_EN, 0);
39664 I915_WRITE(PORT_HOTPLUG_STAT, I915_READ(PORT_HOTPLUG_STAT));
39665 @@ -3604,7 +3604,7 @@ static irqreturn_t i965_irq_handler(int irq, void *arg)
39666 I915_DISPLAY_PLANE_A_FLIP_PENDING_INTERRUPT |
39667 I915_DISPLAY_PLANE_B_FLIP_PENDING_INTERRUPT;
39668
39669 - atomic_inc(&dev_priv->irq_received);
39670 + atomic_inc_unchecked(&dev_priv->irq_received);
39671
39672 iir = I915_READ(IIR);
39673
39674 diff --git a/drivers/gpu/drm/i915/intel_display.c b/drivers/gpu/drm/i915/intel_display.c
39675 index 2bde35d..529646c 100644
39676 --- a/drivers/gpu/drm/i915/intel_display.c
39677 +++ b/drivers/gpu/drm/i915/intel_display.c
39678 @@ -10492,13 +10492,13 @@ struct intel_quirk {
39679 int subsystem_vendor;
39680 int subsystem_device;
39681 void (*hook)(struct drm_device *dev);
39682 -};
39683 +} __do_const;
39684
39685 /* For systems that don't have a meaningful PCI subdevice/subvendor ID */
39686 struct intel_dmi_quirk {
39687 void (*hook)(struct drm_device *dev);
39688 const struct dmi_system_id (*dmi_id_list)[];
39689 -};
39690 +} __do_const;
39691
39692 static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
39693 {
39694 @@ -10506,18 +10506,20 @@ static int intel_dmi_reverse_brightness(const struct dmi_system_id *id)
39695 return 1;
39696 }
39697
39698 -static const struct intel_dmi_quirk intel_dmi_quirks[] = {
39699 +static const struct dmi_system_id intel_dmi_quirks_table[] = {
39700 {
39701 - .dmi_id_list = &(const struct dmi_system_id[]) {
39702 - {
39703 - .callback = intel_dmi_reverse_brightness,
39704 - .ident = "NCR Corporation",
39705 - .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
39706 - DMI_MATCH(DMI_PRODUCT_NAME, ""),
39707 - },
39708 - },
39709 - { } /* terminating entry */
39710 + .callback = intel_dmi_reverse_brightness,
39711 + .ident = "NCR Corporation",
39712 + .matches = {DMI_MATCH(DMI_SYS_VENDOR, "NCR Corporation"),
39713 + DMI_MATCH(DMI_PRODUCT_NAME, ""),
39714 },
39715 + },
39716 + { } /* terminating entry */
39717 +};
39718 +
39719 +static const struct intel_dmi_quirk intel_dmi_quirks[] = {
39720 + {
39721 + .dmi_id_list = &intel_dmi_quirks_table,
39722 .hook = quirk_invert_brightness,
39723 },
39724 };
39725 diff --git a/drivers/gpu/drm/mga/mga_drv.h b/drivers/gpu/drm/mga/mga_drv.h
39726 index ca4bc54..ee598a2 100644
39727 --- a/drivers/gpu/drm/mga/mga_drv.h
39728 +++ b/drivers/gpu/drm/mga/mga_drv.h
39729 @@ -120,9 +120,9 @@ typedef struct drm_mga_private {
39730 u32 clear_cmd;
39731 u32 maccess;
39732
39733 - atomic_t vbl_received; /**< Number of vblanks received. */
39734 + atomic_unchecked_t vbl_received; /**< Number of vblanks received. */
39735 wait_queue_head_t fence_queue;
39736 - atomic_t last_fence_retired;
39737 + atomic_unchecked_t last_fence_retired;
39738 u32 next_fence_to_post;
39739
39740 unsigned int fb_cpp;
39741 diff --git a/drivers/gpu/drm/mga/mga_ioc32.c b/drivers/gpu/drm/mga/mga_ioc32.c
39742 index 709e90d..89a1c0d 100644
39743 --- a/drivers/gpu/drm/mga/mga_ioc32.c
39744 +++ b/drivers/gpu/drm/mga/mga_ioc32.c
39745 @@ -189,7 +189,7 @@ static int compat_mga_dma_bootstrap(struct file *file, unsigned int cmd,
39746 return 0;
39747 }
39748
39749 -drm_ioctl_compat_t *mga_compat_ioctls[] = {
39750 +drm_ioctl_compat_t mga_compat_ioctls[] = {
39751 [DRM_MGA_INIT] = compat_mga_init,
39752 [DRM_MGA_GETPARAM] = compat_mga_getparam,
39753 [DRM_MGA_DMA_BOOTSTRAP] = compat_mga_dma_bootstrap,
39754 @@ -207,18 +207,15 @@ drm_ioctl_compat_t *mga_compat_ioctls[] = {
39755 long mga_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
39756 {
39757 unsigned int nr = DRM_IOCTL_NR(cmd);
39758 - drm_ioctl_compat_t *fn = NULL;
39759 int ret;
39760
39761 if (nr < DRM_COMMAND_BASE)
39762 return drm_compat_ioctl(filp, cmd, arg);
39763
39764 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls))
39765 - fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
39766 -
39767 - if (fn != NULL)
39768 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(mga_compat_ioctls)) {
39769 + drm_ioctl_compat_t fn = mga_compat_ioctls[nr - DRM_COMMAND_BASE];
39770 ret = (*fn) (filp, cmd, arg);
39771 - else
39772 + } else
39773 ret = drm_ioctl(filp, cmd, arg);
39774
39775 return ret;
39776 diff --git a/drivers/gpu/drm/mga/mga_irq.c b/drivers/gpu/drm/mga/mga_irq.c
39777 index 2b0ceb8..517e99e 100644
39778 --- a/drivers/gpu/drm/mga/mga_irq.c
39779 +++ b/drivers/gpu/drm/mga/mga_irq.c
39780 @@ -43,7 +43,7 @@ u32 mga_get_vblank_counter(struct drm_device *dev, int crtc)
39781 if (crtc != 0)
39782 return 0;
39783
39784 - return atomic_read(&dev_priv->vbl_received);
39785 + return atomic_read_unchecked(&dev_priv->vbl_received);
39786 }
39787
39788
39789 @@ -59,7 +59,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
39790 /* VBLANK interrupt */
39791 if (status & MGA_VLINEPEN) {
39792 MGA_WRITE(MGA_ICLEAR, MGA_VLINEICLR);
39793 - atomic_inc(&dev_priv->vbl_received);
39794 + atomic_inc_unchecked(&dev_priv->vbl_received);
39795 drm_handle_vblank(dev, 0);
39796 handled = 1;
39797 }
39798 @@ -78,7 +78,7 @@ irqreturn_t mga_driver_irq_handler(DRM_IRQ_ARGS)
39799 if ((prim_start & ~0x03) != (prim_end & ~0x03))
39800 MGA_WRITE(MGA_PRIMEND, prim_end);
39801
39802 - atomic_inc(&dev_priv->last_fence_retired);
39803 + atomic_inc_unchecked(&dev_priv->last_fence_retired);
39804 DRM_WAKEUP(&dev_priv->fence_queue);
39805 handled = 1;
39806 }
39807 @@ -129,7 +129,7 @@ int mga_driver_fence_wait(struct drm_device *dev, unsigned int *sequence)
39808 * using fences.
39809 */
39810 DRM_WAIT_ON(ret, dev_priv->fence_queue, 3 * DRM_HZ,
39811 - (((cur_fence = atomic_read(&dev_priv->last_fence_retired))
39812 + (((cur_fence = atomic_read_unchecked(&dev_priv->last_fence_retired))
39813 - *sequence) <= (1 << 23)));
39814
39815 *sequence = cur_fence;
39816 diff --git a/drivers/gpu/drm/nouveau/nouveau_bios.c b/drivers/gpu/drm/nouveau/nouveau_bios.c
39817 index 4c3feaa..26391ce 100644
39818 --- a/drivers/gpu/drm/nouveau/nouveau_bios.c
39819 +++ b/drivers/gpu/drm/nouveau/nouveau_bios.c
39820 @@ -965,7 +965,7 @@ static int parse_bit_tmds_tbl_entry(struct drm_device *dev, struct nvbios *bios,
39821 struct bit_table {
39822 const char id;
39823 int (* const parse_fn)(struct drm_device *, struct nvbios *, struct bit_entry *);
39824 -};
39825 +} __no_const;
39826
39827 #define BIT_TABLE(id, funcid) ((struct bit_table){ id, parse_bit_##funcid##_tbl_entry })
39828
39829 diff --git a/drivers/gpu/drm/nouveau/nouveau_drm.h b/drivers/gpu/drm/nouveau/nouveau_drm.h
39830 index 4b0fb6c..67667a9 100644
39831 --- a/drivers/gpu/drm/nouveau/nouveau_drm.h
39832 +++ b/drivers/gpu/drm/nouveau/nouveau_drm.h
39833 @@ -96,7 +96,6 @@ struct nouveau_drm {
39834 struct drm_global_reference mem_global_ref;
39835 struct ttm_bo_global_ref bo_global_ref;
39836 struct ttm_bo_device bdev;
39837 - atomic_t validate_sequence;
39838 int (*move)(struct nouveau_channel *,
39839 struct ttm_buffer_object *,
39840 struct ttm_mem_reg *, struct ttm_mem_reg *);
39841 diff --git a/drivers/gpu/drm/nouveau/nouveau_ioc32.c b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39842 index c1a7e5a..38b8539 100644
39843 --- a/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39844 +++ b/drivers/gpu/drm/nouveau/nouveau_ioc32.c
39845 @@ -50,7 +50,7 @@ long nouveau_compat_ioctl(struct file *filp, unsigned int cmd,
39846 unsigned long arg)
39847 {
39848 unsigned int nr = DRM_IOCTL_NR(cmd);
39849 - drm_ioctl_compat_t *fn = NULL;
39850 + drm_ioctl_compat_t fn = NULL;
39851 int ret;
39852
39853 if (nr < DRM_COMMAND_BASE)
39854 diff --git a/drivers/gpu/drm/nouveau/nouveau_ttm.c b/drivers/gpu/drm/nouveau/nouveau_ttm.c
39855 index 19e3757..ad16478 100644
39856 --- a/drivers/gpu/drm/nouveau/nouveau_ttm.c
39857 +++ b/drivers/gpu/drm/nouveau/nouveau_ttm.c
39858 @@ -130,11 +130,11 @@ nouveau_vram_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
39859 }
39860
39861 const struct ttm_mem_type_manager_func nouveau_vram_manager = {
39862 - nouveau_vram_manager_init,
39863 - nouveau_vram_manager_fini,
39864 - nouveau_vram_manager_new,
39865 - nouveau_vram_manager_del,
39866 - nouveau_vram_manager_debug
39867 + .init = nouveau_vram_manager_init,
39868 + .takedown = nouveau_vram_manager_fini,
39869 + .get_node = nouveau_vram_manager_new,
39870 + .put_node = nouveau_vram_manager_del,
39871 + .debug = nouveau_vram_manager_debug
39872 };
39873
39874 static int
39875 @@ -198,11 +198,11 @@ nouveau_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
39876 }
39877
39878 const struct ttm_mem_type_manager_func nouveau_gart_manager = {
39879 - nouveau_gart_manager_init,
39880 - nouveau_gart_manager_fini,
39881 - nouveau_gart_manager_new,
39882 - nouveau_gart_manager_del,
39883 - nouveau_gart_manager_debug
39884 + .init = nouveau_gart_manager_init,
39885 + .takedown = nouveau_gart_manager_fini,
39886 + .get_node = nouveau_gart_manager_new,
39887 + .put_node = nouveau_gart_manager_del,
39888 + .debug = nouveau_gart_manager_debug
39889 };
39890
39891 #include <core/subdev/vm/nv04.h>
39892 @@ -270,11 +270,11 @@ nv04_gart_manager_debug(struct ttm_mem_type_manager *man, const char *prefix)
39893 }
39894
39895 const struct ttm_mem_type_manager_func nv04_gart_manager = {
39896 - nv04_gart_manager_init,
39897 - nv04_gart_manager_fini,
39898 - nv04_gart_manager_new,
39899 - nv04_gart_manager_del,
39900 - nv04_gart_manager_debug
39901 + .init = nv04_gart_manager_init,
39902 + .takedown = nv04_gart_manager_fini,
39903 + .get_node = nv04_gart_manager_new,
39904 + .put_node = nv04_gart_manager_del,
39905 + .debug = nv04_gart_manager_debug
39906 };
39907
39908 int
39909 diff --git a/drivers/gpu/drm/nouveau/nouveau_vga.c b/drivers/gpu/drm/nouveau/nouveau_vga.c
39910 index 81638d7..2e45854 100644
39911 --- a/drivers/gpu/drm/nouveau/nouveau_vga.c
39912 +++ b/drivers/gpu/drm/nouveau/nouveau_vga.c
39913 @@ -65,7 +65,7 @@ nouveau_switcheroo_can_switch(struct pci_dev *pdev)
39914 bool can_switch;
39915
39916 spin_lock(&dev->count_lock);
39917 - can_switch = (dev->open_count == 0);
39918 + can_switch = (local_read(&dev->open_count) == 0);
39919 spin_unlock(&dev->count_lock);
39920 return can_switch;
39921 }
39922 diff --git a/drivers/gpu/drm/qxl/qxl_cmd.c b/drivers/gpu/drm/qxl/qxl_cmd.c
39923 index eb89653..613cf71 100644
39924 --- a/drivers/gpu/drm/qxl/qxl_cmd.c
39925 +++ b/drivers/gpu/drm/qxl/qxl_cmd.c
39926 @@ -285,27 +285,27 @@ static int wait_for_io_cmd_user(struct qxl_device *qdev, uint8_t val, long port,
39927 int ret;
39928
39929 mutex_lock(&qdev->async_io_mutex);
39930 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
39931 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
39932 if (qdev->last_sent_io_cmd > irq_num) {
39933 if (intr)
39934 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
39935 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39936 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39937 else
39938 ret = wait_event_timeout(qdev->io_cmd_event,
39939 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39940 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39941 /* 0 is timeout, just bail the "hw" has gone away */
39942 if (ret <= 0)
39943 goto out;
39944 - irq_num = atomic_read(&qdev->irq_received_io_cmd);
39945 + irq_num = atomic_read_unchecked(&qdev->irq_received_io_cmd);
39946 }
39947 outb(val, addr);
39948 qdev->last_sent_io_cmd = irq_num + 1;
39949 if (intr)
39950 ret = wait_event_interruptible_timeout(qdev->io_cmd_event,
39951 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39952 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39953 else
39954 ret = wait_event_timeout(qdev->io_cmd_event,
39955 - atomic_read(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39956 + atomic_read_unchecked(&qdev->irq_received_io_cmd) > irq_num, 5*HZ);
39957 out:
39958 if (ret > 0)
39959 ret = 0;
39960 diff --git a/drivers/gpu/drm/qxl/qxl_debugfs.c b/drivers/gpu/drm/qxl/qxl_debugfs.c
39961 index c3c2bbd..bc3c0fb 100644
39962 --- a/drivers/gpu/drm/qxl/qxl_debugfs.c
39963 +++ b/drivers/gpu/drm/qxl/qxl_debugfs.c
39964 @@ -42,10 +42,10 @@ qxl_debugfs_irq_received(struct seq_file *m, void *data)
39965 struct drm_info_node *node = (struct drm_info_node *) m->private;
39966 struct qxl_device *qdev = node->minor->dev->dev_private;
39967
39968 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received));
39969 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_display));
39970 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_cursor));
39971 - seq_printf(m, "%d\n", atomic_read(&qdev->irq_received_io_cmd));
39972 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received));
39973 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_display));
39974 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_cursor));
39975 + seq_printf(m, "%d\n", atomic_read_unchecked(&qdev->irq_received_io_cmd));
39976 seq_printf(m, "%d\n", qdev->irq_received_error);
39977 return 0;
39978 }
39979 diff --git a/drivers/gpu/drm/qxl/qxl_drv.h b/drivers/gpu/drm/qxl/qxl_drv.h
39980 index 7bda32f..dd98fc5 100644
39981 --- a/drivers/gpu/drm/qxl/qxl_drv.h
39982 +++ b/drivers/gpu/drm/qxl/qxl_drv.h
39983 @@ -290,10 +290,10 @@ struct qxl_device {
39984 unsigned int last_sent_io_cmd;
39985
39986 /* interrupt handling */
39987 - atomic_t irq_received;
39988 - atomic_t irq_received_display;
39989 - atomic_t irq_received_cursor;
39990 - atomic_t irq_received_io_cmd;
39991 + atomic_unchecked_t irq_received;
39992 + atomic_unchecked_t irq_received_display;
39993 + atomic_unchecked_t irq_received_cursor;
39994 + atomic_unchecked_t irq_received_io_cmd;
39995 unsigned irq_received_error;
39996 wait_queue_head_t display_event;
39997 wait_queue_head_t cursor_event;
39998 diff --git a/drivers/gpu/drm/qxl/qxl_ioctl.c b/drivers/gpu/drm/qxl/qxl_ioctl.c
39999 index 7b95c75..9cffb4f 100644
40000 --- a/drivers/gpu/drm/qxl/qxl_ioctl.c
40001 +++ b/drivers/gpu/drm/qxl/qxl_ioctl.c
40002 @@ -181,7 +181,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40003
40004 /* TODO copy slow path code from i915 */
40005 fb_cmd = qxl_bo_kmap_atomic_page(qdev, cmd_bo, (release->release_offset & PAGE_SIZE));
40006 - 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);
40007 + 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);
40008
40009 {
40010 struct qxl_drawable *draw = fb_cmd;
40011 @@ -201,7 +201,7 @@ static int qxl_process_single_command(struct qxl_device *qdev,
40012 struct drm_qxl_reloc reloc;
40013
40014 if (DRM_COPY_FROM_USER(&reloc,
40015 - &((struct drm_qxl_reloc *)(uintptr_t)cmd->relocs)[i],
40016 + &((struct drm_qxl_reloc __force_user *)(uintptr_t)cmd->relocs)[i],
40017 sizeof(reloc))) {
40018 ret = -EFAULT;
40019 goto out_free_bos;
40020 @@ -297,7 +297,7 @@ static int qxl_execbuffer_ioctl(struct drm_device *dev, void *data,
40021 struct drm_qxl_command *commands =
40022 (struct drm_qxl_command *)(uintptr_t)execbuffer->commands;
40023
40024 - if (DRM_COPY_FROM_USER(&user_cmd, &commands[cmd_num],
40025 + if (DRM_COPY_FROM_USER(&user_cmd, (struct drm_qxl_command __force_user *)&commands[cmd_num],
40026 sizeof(user_cmd)))
40027 return -EFAULT;
40028
40029 diff --git a/drivers/gpu/drm/qxl/qxl_irq.c b/drivers/gpu/drm/qxl/qxl_irq.c
40030 index 21393dc..329f3a9 100644
40031 --- a/drivers/gpu/drm/qxl/qxl_irq.c
40032 +++ b/drivers/gpu/drm/qxl/qxl_irq.c
40033 @@ -33,19 +33,19 @@ irqreturn_t qxl_irq_handler(DRM_IRQ_ARGS)
40034
40035 pending = xchg(&qdev->ram_header->int_pending, 0);
40036
40037 - atomic_inc(&qdev->irq_received);
40038 + atomic_inc_unchecked(&qdev->irq_received);
40039
40040 if (pending & QXL_INTERRUPT_DISPLAY) {
40041 - atomic_inc(&qdev->irq_received_display);
40042 + atomic_inc_unchecked(&qdev->irq_received_display);
40043 wake_up_all(&qdev->display_event);
40044 qxl_queue_garbage_collect(qdev, false);
40045 }
40046 if (pending & QXL_INTERRUPT_CURSOR) {
40047 - atomic_inc(&qdev->irq_received_cursor);
40048 + atomic_inc_unchecked(&qdev->irq_received_cursor);
40049 wake_up_all(&qdev->cursor_event);
40050 }
40051 if (pending & QXL_INTERRUPT_IO_CMD) {
40052 - atomic_inc(&qdev->irq_received_io_cmd);
40053 + atomic_inc_unchecked(&qdev->irq_received_io_cmd);
40054 wake_up_all(&qdev->io_cmd_event);
40055 }
40056 if (pending & QXL_INTERRUPT_ERROR) {
40057 @@ -82,10 +82,10 @@ int qxl_irq_init(struct qxl_device *qdev)
40058 init_waitqueue_head(&qdev->io_cmd_event);
40059 INIT_WORK(&qdev->client_monitors_config_work,
40060 qxl_client_monitors_config_work_func);
40061 - atomic_set(&qdev->irq_received, 0);
40062 - atomic_set(&qdev->irq_received_display, 0);
40063 - atomic_set(&qdev->irq_received_cursor, 0);
40064 - atomic_set(&qdev->irq_received_io_cmd, 0);
40065 + atomic_set_unchecked(&qdev->irq_received, 0);
40066 + atomic_set_unchecked(&qdev->irq_received_display, 0);
40067 + atomic_set_unchecked(&qdev->irq_received_cursor, 0);
40068 + atomic_set_unchecked(&qdev->irq_received_io_cmd, 0);
40069 qdev->irq_received_error = 0;
40070 ret = drm_irq_install(qdev->ddev);
40071 qdev->ram_header->int_mask = QXL_INTERRUPT_MASK;
40072 diff --git a/drivers/gpu/drm/qxl/qxl_ttm.c b/drivers/gpu/drm/qxl/qxl_ttm.c
40073 index c7e7e65..7dddd4d 100644
40074 --- a/drivers/gpu/drm/qxl/qxl_ttm.c
40075 +++ b/drivers/gpu/drm/qxl/qxl_ttm.c
40076 @@ -103,7 +103,7 @@ static void qxl_ttm_global_fini(struct qxl_device *qdev)
40077 }
40078 }
40079
40080 -static struct vm_operations_struct qxl_ttm_vm_ops;
40081 +static vm_operations_struct_no_const qxl_ttm_vm_ops __read_only;
40082 static const struct vm_operations_struct *ttm_vm_ops;
40083
40084 static int qxl_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40085 @@ -147,8 +147,10 @@ int qxl_mmap(struct file *filp, struct vm_area_struct *vma)
40086 return r;
40087 if (unlikely(ttm_vm_ops == NULL)) {
40088 ttm_vm_ops = vma->vm_ops;
40089 + pax_open_kernel();
40090 qxl_ttm_vm_ops = *ttm_vm_ops;
40091 qxl_ttm_vm_ops.fault = &qxl_ttm_fault;
40092 + pax_close_kernel();
40093 }
40094 vma->vm_ops = &qxl_ttm_vm_ops;
40095 return 0;
40096 @@ -560,25 +562,23 @@ static int qxl_mm_dump_table(struct seq_file *m, void *data)
40097 static int qxl_ttm_debugfs_init(struct qxl_device *qdev)
40098 {
40099 #if defined(CONFIG_DEBUG_FS)
40100 - static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES];
40101 - static char qxl_mem_types_names[QXL_DEBUGFS_MEM_TYPES][32];
40102 - unsigned i;
40103 + static struct drm_info_list qxl_mem_types_list[QXL_DEBUGFS_MEM_TYPES] = {
40104 + {
40105 + .name = "qxl_mem_mm",
40106 + .show = &qxl_mm_dump_table,
40107 + },
40108 + {
40109 + .name = "qxl_surf_mm",
40110 + .show = &qxl_mm_dump_table,
40111 + }
40112 + };
40113
40114 - for (i = 0; i < QXL_DEBUGFS_MEM_TYPES; i++) {
40115 - if (i == 0)
40116 - sprintf(qxl_mem_types_names[i], "qxl_mem_mm");
40117 - else
40118 - sprintf(qxl_mem_types_names[i], "qxl_surf_mm");
40119 - qxl_mem_types_list[i].name = qxl_mem_types_names[i];
40120 - qxl_mem_types_list[i].show = &qxl_mm_dump_table;
40121 - qxl_mem_types_list[i].driver_features = 0;
40122 - if (i == 0)
40123 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40124 - else
40125 - qxl_mem_types_list[i].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40126 + pax_open_kernel();
40127 + *(void **)&qxl_mem_types_list[0].data = qdev->mman.bdev.man[TTM_PL_VRAM].priv;
40128 + *(void **)&qxl_mem_types_list[1].data = qdev->mman.bdev.man[TTM_PL_PRIV0].priv;
40129 + pax_close_kernel();
40130
40131 - }
40132 - return qxl_debugfs_add_files(qdev, qxl_mem_types_list, i);
40133 + return qxl_debugfs_add_files(qdev, qxl_mem_types_list, QXL_DEBUGFS_MEM_TYPES);
40134 #else
40135 return 0;
40136 #endif
40137 diff --git a/drivers/gpu/drm/r128/r128_cce.c b/drivers/gpu/drm/r128/r128_cce.c
40138 index c451257..0ad2134 100644
40139 --- a/drivers/gpu/drm/r128/r128_cce.c
40140 +++ b/drivers/gpu/drm/r128/r128_cce.c
40141 @@ -377,7 +377,7 @@ static int r128_do_init_cce(struct drm_device *dev, drm_r128_init_t *init)
40142
40143 /* GH: Simple idle check.
40144 */
40145 - atomic_set(&dev_priv->idle_count, 0);
40146 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40147
40148 /* We don't support anything other than bus-mastering ring mode,
40149 * but the ring can be in either AGP or PCI space for the ring
40150 diff --git a/drivers/gpu/drm/r128/r128_drv.h b/drivers/gpu/drm/r128/r128_drv.h
40151 index 56eb5e3..c4ec43d 100644
40152 --- a/drivers/gpu/drm/r128/r128_drv.h
40153 +++ b/drivers/gpu/drm/r128/r128_drv.h
40154 @@ -90,14 +90,14 @@ typedef struct drm_r128_private {
40155 int is_pci;
40156 unsigned long cce_buffers_offset;
40157
40158 - atomic_t idle_count;
40159 + atomic_unchecked_t idle_count;
40160
40161 int page_flipping;
40162 int current_page;
40163 u32 crtc_offset;
40164 u32 crtc_offset_cntl;
40165
40166 - atomic_t vbl_received;
40167 + atomic_unchecked_t vbl_received;
40168
40169 u32 color_fmt;
40170 unsigned int front_offset;
40171 diff --git a/drivers/gpu/drm/r128/r128_ioc32.c b/drivers/gpu/drm/r128/r128_ioc32.c
40172 index a954c54..9cc595c 100644
40173 --- a/drivers/gpu/drm/r128/r128_ioc32.c
40174 +++ b/drivers/gpu/drm/r128/r128_ioc32.c
40175 @@ -177,7 +177,7 @@ static int compat_r128_getparam(struct file *file, unsigned int cmd,
40176 return drm_ioctl(file, DRM_IOCTL_R128_GETPARAM, (unsigned long)getparam);
40177 }
40178
40179 -drm_ioctl_compat_t *r128_compat_ioctls[] = {
40180 +drm_ioctl_compat_t r128_compat_ioctls[] = {
40181 [DRM_R128_INIT] = compat_r128_init,
40182 [DRM_R128_DEPTH] = compat_r128_depth,
40183 [DRM_R128_STIPPLE] = compat_r128_stipple,
40184 @@ -196,18 +196,15 @@ drm_ioctl_compat_t *r128_compat_ioctls[] = {
40185 long r128_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40186 {
40187 unsigned int nr = DRM_IOCTL_NR(cmd);
40188 - drm_ioctl_compat_t *fn = NULL;
40189 int ret;
40190
40191 if (nr < DRM_COMMAND_BASE)
40192 return drm_compat_ioctl(filp, cmd, arg);
40193
40194 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls))
40195 - fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40196 -
40197 - if (fn != NULL)
40198 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(r128_compat_ioctls)) {
40199 + drm_ioctl_compat_t fn = r128_compat_ioctls[nr - DRM_COMMAND_BASE];
40200 ret = (*fn) (filp, cmd, arg);
40201 - else
40202 + } else
40203 ret = drm_ioctl(filp, cmd, arg);
40204
40205 return ret;
40206 diff --git a/drivers/gpu/drm/r128/r128_irq.c b/drivers/gpu/drm/r128/r128_irq.c
40207 index 2ea4f09..d391371 100644
40208 --- a/drivers/gpu/drm/r128/r128_irq.c
40209 +++ b/drivers/gpu/drm/r128/r128_irq.c
40210 @@ -41,7 +41,7 @@ u32 r128_get_vblank_counter(struct drm_device *dev, int crtc)
40211 if (crtc != 0)
40212 return 0;
40213
40214 - return atomic_read(&dev_priv->vbl_received);
40215 + return atomic_read_unchecked(&dev_priv->vbl_received);
40216 }
40217
40218 irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
40219 @@ -55,7 +55,7 @@ irqreturn_t r128_driver_irq_handler(DRM_IRQ_ARGS)
40220 /* VBLANK interrupt */
40221 if (status & R128_CRTC_VBLANK_INT) {
40222 R128_WRITE(R128_GEN_INT_STATUS, R128_CRTC_VBLANK_INT_AK);
40223 - atomic_inc(&dev_priv->vbl_received);
40224 + atomic_inc_unchecked(&dev_priv->vbl_received);
40225 drm_handle_vblank(dev, 0);
40226 return IRQ_HANDLED;
40227 }
40228 diff --git a/drivers/gpu/drm/r128/r128_state.c b/drivers/gpu/drm/r128/r128_state.c
40229 index 01dd9ae..6352f04 100644
40230 --- a/drivers/gpu/drm/r128/r128_state.c
40231 +++ b/drivers/gpu/drm/r128/r128_state.c
40232 @@ -320,10 +320,10 @@ static void r128_clear_box(drm_r128_private_t *dev_priv,
40233
40234 static void r128_cce_performance_boxes(drm_r128_private_t *dev_priv)
40235 {
40236 - if (atomic_read(&dev_priv->idle_count) == 0)
40237 + if (atomic_read_unchecked(&dev_priv->idle_count) == 0)
40238 r128_clear_box(dev_priv, 64, 4, 8, 8, 0, 255, 0);
40239 else
40240 - atomic_set(&dev_priv->idle_count, 0);
40241 + atomic_set_unchecked(&dev_priv->idle_count, 0);
40242 }
40243
40244 #endif
40245 diff --git a/drivers/gpu/drm/radeon/mkregtable.c b/drivers/gpu/drm/radeon/mkregtable.c
40246 index af85299..ed9ac8d 100644
40247 --- a/drivers/gpu/drm/radeon/mkregtable.c
40248 +++ b/drivers/gpu/drm/radeon/mkregtable.c
40249 @@ -624,14 +624,14 @@ static int parser_auth(struct table *t, const char *filename)
40250 regex_t mask_rex;
40251 regmatch_t match[4];
40252 char buf[1024];
40253 - size_t end;
40254 + long end;
40255 int len;
40256 int done = 0;
40257 int r;
40258 unsigned o;
40259 struct offset *offset;
40260 char last_reg_s[10];
40261 - int last_reg;
40262 + unsigned long last_reg;
40263
40264 if (regcomp
40265 (&mask_rex, "(0x[0-9a-fA-F]*) *([_a-zA-Z0-9]*)", REG_EXTENDED)) {
40266 diff --git a/drivers/gpu/drm/radeon/radeon_device.c b/drivers/gpu/drm/radeon/radeon_device.c
40267 index 39b033b..6efc056 100644
40268 --- a/drivers/gpu/drm/radeon/radeon_device.c
40269 +++ b/drivers/gpu/drm/radeon/radeon_device.c
40270 @@ -1120,7 +1120,7 @@ static bool radeon_switcheroo_can_switch(struct pci_dev *pdev)
40271 bool can_switch;
40272
40273 spin_lock(&dev->count_lock);
40274 - can_switch = (dev->open_count == 0);
40275 + can_switch = (local_read(&dev->open_count) == 0);
40276 spin_unlock(&dev->count_lock);
40277 return can_switch;
40278 }
40279 diff --git a/drivers/gpu/drm/radeon/radeon_drv.h b/drivers/gpu/drm/radeon/radeon_drv.h
40280 index 00e0d44..08381a4 100644
40281 --- a/drivers/gpu/drm/radeon/radeon_drv.h
40282 +++ b/drivers/gpu/drm/radeon/radeon_drv.h
40283 @@ -262,7 +262,7 @@ typedef struct drm_radeon_private {
40284
40285 /* SW interrupt */
40286 wait_queue_head_t swi_queue;
40287 - atomic_t swi_emitted;
40288 + atomic_unchecked_t swi_emitted;
40289 int vblank_crtc;
40290 uint32_t irq_enable_reg;
40291 uint32_t r500_disp_irq_reg;
40292 diff --git a/drivers/gpu/drm/radeon/radeon_ioc32.c b/drivers/gpu/drm/radeon/radeon_ioc32.c
40293 index bdb0f93..5ff558f 100644
40294 --- a/drivers/gpu/drm/radeon/radeon_ioc32.c
40295 +++ b/drivers/gpu/drm/radeon/radeon_ioc32.c
40296 @@ -358,7 +358,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40297 request = compat_alloc_user_space(sizeof(*request));
40298 if (!access_ok(VERIFY_WRITE, request, sizeof(*request))
40299 || __put_user(req32.param, &request->param)
40300 - || __put_user((void __user *)(unsigned long)req32.value,
40301 + || __put_user((unsigned long)req32.value,
40302 &request->value))
40303 return -EFAULT;
40304
40305 @@ -368,7 +368,7 @@ static int compat_radeon_cp_setparam(struct file *file, unsigned int cmd,
40306 #define compat_radeon_cp_setparam NULL
40307 #endif /* X86_64 || IA64 */
40308
40309 -static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40310 +static drm_ioctl_compat_t radeon_compat_ioctls[] = {
40311 [DRM_RADEON_CP_INIT] = compat_radeon_cp_init,
40312 [DRM_RADEON_CLEAR] = compat_radeon_cp_clear,
40313 [DRM_RADEON_STIPPLE] = compat_radeon_cp_stipple,
40314 @@ -393,18 +393,15 @@ static drm_ioctl_compat_t *radeon_compat_ioctls[] = {
40315 long radeon_compat_ioctl(struct file *filp, unsigned int cmd, unsigned long arg)
40316 {
40317 unsigned int nr = DRM_IOCTL_NR(cmd);
40318 - drm_ioctl_compat_t *fn = NULL;
40319 int ret;
40320
40321 if (nr < DRM_COMMAND_BASE)
40322 return drm_compat_ioctl(filp, cmd, arg);
40323
40324 - if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls))
40325 - fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40326 -
40327 - if (fn != NULL)
40328 + if (nr < DRM_COMMAND_BASE + DRM_ARRAY_SIZE(radeon_compat_ioctls)) {
40329 + drm_ioctl_compat_t fn = radeon_compat_ioctls[nr - DRM_COMMAND_BASE];
40330 ret = (*fn) (filp, cmd, arg);
40331 - else
40332 + } else
40333 ret = drm_ioctl(filp, cmd, arg);
40334
40335 return ret;
40336 diff --git a/drivers/gpu/drm/radeon/radeon_irq.c b/drivers/gpu/drm/radeon/radeon_irq.c
40337 index 8d68e97..9dcfed8 100644
40338 --- a/drivers/gpu/drm/radeon/radeon_irq.c
40339 +++ b/drivers/gpu/drm/radeon/radeon_irq.c
40340 @@ -226,8 +226,8 @@ static int radeon_emit_irq(struct drm_device * dev)
40341 unsigned int ret;
40342 RING_LOCALS;
40343
40344 - atomic_inc(&dev_priv->swi_emitted);
40345 - ret = atomic_read(&dev_priv->swi_emitted);
40346 + atomic_inc_unchecked(&dev_priv->swi_emitted);
40347 + ret = atomic_read_unchecked(&dev_priv->swi_emitted);
40348
40349 BEGIN_RING(4);
40350 OUT_RING_REG(RADEON_LAST_SWI_REG, ret);
40351 @@ -353,7 +353,7 @@ int radeon_driver_irq_postinstall(struct drm_device *dev)
40352 drm_radeon_private_t *dev_priv =
40353 (drm_radeon_private_t *) dev->dev_private;
40354
40355 - atomic_set(&dev_priv->swi_emitted, 0);
40356 + atomic_set_unchecked(&dev_priv->swi_emitted, 0);
40357 DRM_INIT_WAITQUEUE(&dev_priv->swi_queue);
40358
40359 dev->max_vblank_count = 0x001fffff;
40360 diff --git a/drivers/gpu/drm/radeon/radeon_state.c b/drivers/gpu/drm/radeon/radeon_state.c
40361 index 4d20910..6726b6d 100644
40362 --- a/drivers/gpu/drm/radeon/radeon_state.c
40363 +++ b/drivers/gpu/drm/radeon/radeon_state.c
40364 @@ -2168,7 +2168,7 @@ static int radeon_cp_clear(struct drm_device *dev, void *data, struct drm_file *
40365 if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS)
40366 sarea_priv->nbox = RADEON_NR_SAREA_CLIPRECTS;
40367
40368 - if (DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
40369 + if (sarea_priv->nbox > RADEON_NR_SAREA_CLIPRECTS || DRM_COPY_FROM_USER(&depth_boxes, clear->depth_boxes,
40370 sarea_priv->nbox * sizeof(depth_boxes[0])))
40371 return -EFAULT;
40372
40373 @@ -3031,7 +3031,7 @@ static int radeon_cp_getparam(struct drm_device *dev, void *data, struct drm_fil
40374 {
40375 drm_radeon_private_t *dev_priv = dev->dev_private;
40376 drm_radeon_getparam_t *param = data;
40377 - int value;
40378 + int value = 0;
40379
40380 DRM_DEBUG("pid=%d\n", DRM_CURRENTPID);
40381
40382 diff --git a/drivers/gpu/drm/radeon/radeon_ttm.c b/drivers/gpu/drm/radeon/radeon_ttm.c
40383 index 71245d6..94c556d 100644
40384 --- a/drivers/gpu/drm/radeon/radeon_ttm.c
40385 +++ b/drivers/gpu/drm/radeon/radeon_ttm.c
40386 @@ -784,7 +784,7 @@ void radeon_ttm_set_active_vram_size(struct radeon_device *rdev, u64 size)
40387 man->size = size >> PAGE_SHIFT;
40388 }
40389
40390 -static struct vm_operations_struct radeon_ttm_vm_ops;
40391 +static vm_operations_struct_no_const radeon_ttm_vm_ops __read_only;
40392 static const struct vm_operations_struct *ttm_vm_ops = NULL;
40393
40394 static int radeon_ttm_fault(struct vm_area_struct *vma, struct vm_fault *vmf)
40395 @@ -825,8 +825,10 @@ int radeon_mmap(struct file *filp, struct vm_area_struct *vma)
40396 }
40397 if (unlikely(ttm_vm_ops == NULL)) {
40398 ttm_vm_ops = vma->vm_ops;
40399 + pax_open_kernel();
40400 radeon_ttm_vm_ops = *ttm_vm_ops;
40401 radeon_ttm_vm_ops.fault = &radeon_ttm_fault;
40402 + pax_close_kernel();
40403 }
40404 vma->vm_ops = &radeon_ttm_vm_ops;
40405 return 0;
40406 @@ -855,38 +857,33 @@ static int radeon_mm_dump_table(struct seq_file *m, void *data)
40407 static int radeon_ttm_debugfs_init(struct radeon_device *rdev)
40408 {
40409 #if defined(CONFIG_DEBUG_FS)
40410 - static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2];
40411 - static char radeon_mem_types_names[RADEON_DEBUGFS_MEM_TYPES+2][32];
40412 - unsigned i;
40413 + static struct drm_info_list radeon_mem_types_list[RADEON_DEBUGFS_MEM_TYPES+2] = {
40414 + {
40415 + .name = "radeon_vram_mm",
40416 + .show = &radeon_mm_dump_table,
40417 + },
40418 + {
40419 + .name = "radeon_gtt_mm",
40420 + .show = &radeon_mm_dump_table,
40421 + },
40422 + {
40423 + .name = "ttm_page_pool",
40424 + .show = &ttm_page_alloc_debugfs,
40425 + },
40426 + {
40427 + .name = "ttm_dma_page_pool",
40428 + .show = &ttm_dma_page_alloc_debugfs,
40429 + },
40430 + };
40431 + unsigned i = RADEON_DEBUGFS_MEM_TYPES + 1;
40432
40433 - for (i = 0; i < RADEON_DEBUGFS_MEM_TYPES; i++) {
40434 - if (i == 0)
40435 - sprintf(radeon_mem_types_names[i], "radeon_vram_mm");
40436 - else
40437 - sprintf(radeon_mem_types_names[i], "radeon_gtt_mm");
40438 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40439 - radeon_mem_types_list[i].show = &radeon_mm_dump_table;
40440 - radeon_mem_types_list[i].driver_features = 0;
40441 - if (i == 0)
40442 - radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
40443 - else
40444 - radeon_mem_types_list[i].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
40445 -
40446 - }
40447 - /* Add ttm page pool to debugfs */
40448 - sprintf(radeon_mem_types_names[i], "ttm_page_pool");
40449 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40450 - radeon_mem_types_list[i].show = &ttm_page_alloc_debugfs;
40451 - radeon_mem_types_list[i].driver_features = 0;
40452 - radeon_mem_types_list[i++].data = NULL;
40453 + pax_open_kernel();
40454 + *(void **)&radeon_mem_types_list[0].data = rdev->mman.bdev.man[TTM_PL_VRAM].priv;
40455 + *(void **)&radeon_mem_types_list[1].data = rdev->mman.bdev.man[TTM_PL_TT].priv;
40456 + pax_close_kernel();
40457 #ifdef CONFIG_SWIOTLB
40458 - if (swiotlb_nr_tbl()) {
40459 - sprintf(radeon_mem_types_names[i], "ttm_dma_page_pool");
40460 - radeon_mem_types_list[i].name = radeon_mem_types_names[i];
40461 - radeon_mem_types_list[i].show = &ttm_dma_page_alloc_debugfs;
40462 - radeon_mem_types_list[i].driver_features = 0;
40463 - radeon_mem_types_list[i++].data = NULL;
40464 - }
40465 + if (swiotlb_nr_tbl())
40466 + i++;
40467 #endif
40468 return radeon_debugfs_add_files(rdev, radeon_mem_types_list, i);
40469
40470 diff --git a/drivers/gpu/drm/tegra/dc.c b/drivers/gpu/drm/tegra/dc.c
40471 index ae1cb31..5b5b6b7c 100644
40472 --- a/drivers/gpu/drm/tegra/dc.c
40473 +++ b/drivers/gpu/drm/tegra/dc.c
40474 @@ -1064,7 +1064,7 @@ static int tegra_dc_debugfs_init(struct tegra_dc *dc, struct drm_minor *minor)
40475 }
40476
40477 for (i = 0; i < ARRAY_SIZE(debugfs_files); i++)
40478 - dc->debugfs_files[i].data = dc;
40479 + *(void **)&dc->debugfs_files[i].data = dc;
40480
40481 err = drm_debugfs_create_files(dc->debugfs_files,
40482 ARRAY_SIZE(debugfs_files),
40483 diff --git a/drivers/gpu/drm/tegra/hdmi.c b/drivers/gpu/drm/tegra/hdmi.c
40484 index 0cd9bc2..9759be4 100644
40485 --- a/drivers/gpu/drm/tegra/hdmi.c
40486 +++ b/drivers/gpu/drm/tegra/hdmi.c
40487 @@ -57,7 +57,7 @@ struct tegra_hdmi {
40488 bool stereo;
40489 bool dvi;
40490
40491 - struct drm_info_list *debugfs_files;
40492 + drm_info_list_no_const *debugfs_files;
40493 struct drm_minor *minor;
40494 struct dentry *debugfs;
40495 };
40496 diff --git a/drivers/gpu/drm/ttm/ttm_bo_manager.c b/drivers/gpu/drm/ttm/ttm_bo_manager.c
40497 index c58eba33..83c2728 100644
40498 --- a/drivers/gpu/drm/ttm/ttm_bo_manager.c
40499 +++ b/drivers/gpu/drm/ttm/ttm_bo_manager.c
40500 @@ -141,10 +141,10 @@ static void ttm_bo_man_debug(struct ttm_mem_type_manager *man,
40501 }
40502
40503 const struct ttm_mem_type_manager_func ttm_bo_manager_func = {
40504 - ttm_bo_man_init,
40505 - ttm_bo_man_takedown,
40506 - ttm_bo_man_get_node,
40507 - ttm_bo_man_put_node,
40508 - ttm_bo_man_debug
40509 + .init = ttm_bo_man_init,
40510 + .takedown = ttm_bo_man_takedown,
40511 + .get_node = ttm_bo_man_get_node,
40512 + .put_node = ttm_bo_man_put_node,
40513 + .debug = ttm_bo_man_debug
40514 };
40515 EXPORT_SYMBOL(ttm_bo_manager_func);
40516 diff --git a/drivers/gpu/drm/ttm/ttm_memory.c b/drivers/gpu/drm/ttm/ttm_memory.c
40517 index dbc2def..0a9f710 100644
40518 --- a/drivers/gpu/drm/ttm/ttm_memory.c
40519 +++ b/drivers/gpu/drm/ttm/ttm_memory.c
40520 @@ -264,7 +264,7 @@ static int ttm_mem_init_kernel_zone(struct ttm_mem_global *glob,
40521 zone->glob = glob;
40522 glob->zone_kernel = zone;
40523 ret = kobject_init_and_add(
40524 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
40525 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
40526 if (unlikely(ret != 0)) {
40527 kobject_put(&zone->kobj);
40528 return ret;
40529 @@ -347,7 +347,7 @@ static int ttm_mem_init_dma32_zone(struct ttm_mem_global *glob,
40530 zone->glob = glob;
40531 glob->zone_dma32 = zone;
40532 ret = kobject_init_and_add(
40533 - &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, zone->name);
40534 + &zone->kobj, &ttm_mem_zone_kobj_type, &glob->kobj, "%s", zone->name);
40535 if (unlikely(ret != 0)) {
40536 kobject_put(&zone->kobj);
40537 return ret;
40538 diff --git a/drivers/gpu/drm/ttm/ttm_page_alloc.c b/drivers/gpu/drm/ttm/ttm_page_alloc.c
40539 index 863bef9..cba15cf 100644
40540 --- a/drivers/gpu/drm/ttm/ttm_page_alloc.c
40541 +++ b/drivers/gpu/drm/ttm/ttm_page_alloc.c
40542 @@ -391,9 +391,9 @@ out:
40543 static unsigned long
40544 ttm_pool_shrink_scan(struct shrinker *shrink, struct shrink_control *sc)
40545 {
40546 - static atomic_t start_pool = ATOMIC_INIT(0);
40547 + static atomic_unchecked_t start_pool = ATOMIC_INIT(0);
40548 unsigned i;
40549 - unsigned pool_offset = atomic_add_return(1, &start_pool);
40550 + unsigned pool_offset = atomic_add_return_unchecked(1, &start_pool);
40551 struct ttm_page_pool *pool;
40552 int shrink_pages = sc->nr_to_scan;
40553 unsigned long freed = 0;
40554 diff --git a/drivers/gpu/drm/udl/udl_fb.c b/drivers/gpu/drm/udl/udl_fb.c
40555 index 97e9d61..bf23c461 100644
40556 --- a/drivers/gpu/drm/udl/udl_fb.c
40557 +++ b/drivers/gpu/drm/udl/udl_fb.c
40558 @@ -367,7 +367,6 @@ static int udl_fb_release(struct fb_info *info, int user)
40559 fb_deferred_io_cleanup(info);
40560 kfree(info->fbdefio);
40561 info->fbdefio = NULL;
40562 - info->fbops->fb_mmap = udl_fb_mmap;
40563 }
40564
40565 pr_warn("released /dev/fb%d user=%d count=%d\n",
40566 diff --git a/drivers/gpu/drm/via/via_drv.h b/drivers/gpu/drm/via/via_drv.h
40567 index a811ef2..ff99b05 100644
40568 --- a/drivers/gpu/drm/via/via_drv.h
40569 +++ b/drivers/gpu/drm/via/via_drv.h
40570 @@ -51,7 +51,7 @@ typedef struct drm_via_ring_buffer {
40571 typedef uint32_t maskarray_t[5];
40572
40573 typedef struct drm_via_irq {
40574 - atomic_t irq_received;
40575 + atomic_unchecked_t irq_received;
40576 uint32_t pending_mask;
40577 uint32_t enable_mask;
40578 wait_queue_head_t irq_queue;
40579 @@ -75,7 +75,7 @@ typedef struct drm_via_private {
40580 struct timeval last_vblank;
40581 int last_vblank_valid;
40582 unsigned usec_per_vblank;
40583 - atomic_t vbl_received;
40584 + atomic_unchecked_t vbl_received;
40585 drm_via_state_t hc_state;
40586 char pci_buf[VIA_PCI_BUF_SIZE];
40587 const uint32_t *fire_offsets[VIA_FIRE_BUF_SIZE];
40588 diff --git a/drivers/gpu/drm/via/via_irq.c b/drivers/gpu/drm/via/via_irq.c
40589 index ac98964..5dbf512 100644
40590 --- a/drivers/gpu/drm/via/via_irq.c
40591 +++ b/drivers/gpu/drm/via/via_irq.c
40592 @@ -101,7 +101,7 @@ u32 via_get_vblank_counter(struct drm_device *dev, int crtc)
40593 if (crtc != 0)
40594 return 0;
40595
40596 - return atomic_read(&dev_priv->vbl_received);
40597 + return atomic_read_unchecked(&dev_priv->vbl_received);
40598 }
40599
40600 irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40601 @@ -116,8 +116,8 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40602
40603 status = VIA_READ(VIA_REG_INTERRUPT);
40604 if (status & VIA_IRQ_VBLANK_PENDING) {
40605 - atomic_inc(&dev_priv->vbl_received);
40606 - if (!(atomic_read(&dev_priv->vbl_received) & 0x0F)) {
40607 + atomic_inc_unchecked(&dev_priv->vbl_received);
40608 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0x0F)) {
40609 do_gettimeofday(&cur_vblank);
40610 if (dev_priv->last_vblank_valid) {
40611 dev_priv->usec_per_vblank =
40612 @@ -127,7 +127,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40613 dev_priv->last_vblank = cur_vblank;
40614 dev_priv->last_vblank_valid = 1;
40615 }
40616 - if (!(atomic_read(&dev_priv->vbl_received) & 0xFF)) {
40617 + if (!(atomic_read_unchecked(&dev_priv->vbl_received) & 0xFF)) {
40618 DRM_DEBUG("US per vblank is: %u\n",
40619 dev_priv->usec_per_vblank);
40620 }
40621 @@ -137,7 +137,7 @@ irqreturn_t via_driver_irq_handler(DRM_IRQ_ARGS)
40622
40623 for (i = 0; i < dev_priv->num_irqs; ++i) {
40624 if (status & cur_irq->pending_mask) {
40625 - atomic_inc(&cur_irq->irq_received);
40626 + atomic_inc_unchecked(&cur_irq->irq_received);
40627 DRM_WAKEUP(&cur_irq->irq_queue);
40628 handled = 1;
40629 if (dev_priv->irq_map[drm_via_irq_dma0_td] == i)
40630 @@ -242,11 +242,11 @@ via_driver_irq_wait(struct drm_device *dev, unsigned int irq, int force_sequence
40631 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
40632 ((VIA_READ(masks[irq][2]) & masks[irq][3]) ==
40633 masks[irq][4]));
40634 - cur_irq_sequence = atomic_read(&cur_irq->irq_received);
40635 + cur_irq_sequence = atomic_read_unchecked(&cur_irq->irq_received);
40636 } else {
40637 DRM_WAIT_ON(ret, cur_irq->irq_queue, 3 * DRM_HZ,
40638 (((cur_irq_sequence =
40639 - atomic_read(&cur_irq->irq_received)) -
40640 + atomic_read_unchecked(&cur_irq->irq_received)) -
40641 *sequence) <= (1 << 23)));
40642 }
40643 *sequence = cur_irq_sequence;
40644 @@ -284,7 +284,7 @@ void via_driver_irq_preinstall(struct drm_device *dev)
40645 }
40646
40647 for (i = 0; i < dev_priv->num_irqs; ++i) {
40648 - atomic_set(&cur_irq->irq_received, 0);
40649 + atomic_set_unchecked(&cur_irq->irq_received, 0);
40650 cur_irq->enable_mask = dev_priv->irq_masks[i][0];
40651 cur_irq->pending_mask = dev_priv->irq_masks[i][1];
40652 DRM_INIT_WAITQUEUE(&cur_irq->irq_queue);
40653 @@ -366,7 +366,7 @@ int via_wait_irq(struct drm_device *dev, void *data, struct drm_file *file_priv)
40654 switch (irqwait->request.type & ~VIA_IRQ_FLAGS_MASK) {
40655 case VIA_IRQ_RELATIVE:
40656 irqwait->request.sequence +=
40657 - atomic_read(&cur_irq->irq_received);
40658 + atomic_read_unchecked(&cur_irq->irq_received);
40659 irqwait->request.type &= ~_DRM_VBLANK_RELATIVE;
40660 case VIA_IRQ_ABSOLUTE:
40661 break;
40662 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
40663 index c0b73b9..f6f7f34 100644
40664 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
40665 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_drv.h
40666 @@ -341,7 +341,7 @@ struct vmw_private {
40667 * Fencing and IRQs.
40668 */
40669
40670 - atomic_t marker_seq;
40671 + atomic_unchecked_t marker_seq;
40672 wait_queue_head_t fence_queue;
40673 wait_queue_head_t fifo_queue;
40674 int fence_queue_waiters; /* Protected by hw_mutex */
40675 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
40676 index 3eb1486..0a47ee9 100644
40677 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
40678 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_fifo.c
40679 @@ -137,7 +137,7 @@ int vmw_fifo_init(struct vmw_private *dev_priv, struct vmw_fifo_state *fifo)
40680 (unsigned int) min,
40681 (unsigned int) fifo->capabilities);
40682
40683 - atomic_set(&dev_priv->marker_seq, dev_priv->last_read_seqno);
40684 + atomic_set_unchecked(&dev_priv->marker_seq, dev_priv->last_read_seqno);
40685 iowrite32(dev_priv->last_read_seqno, fifo_mem + SVGA_FIFO_FENCE);
40686 vmw_marker_queue_init(&fifo->marker_queue);
40687 return vmw_fifo_send_fence(dev_priv, &dummy);
40688 @@ -355,7 +355,7 @@ void *vmw_fifo_reserve(struct vmw_private *dev_priv, uint32_t bytes)
40689 if (reserveable)
40690 iowrite32(bytes, fifo_mem +
40691 SVGA_FIFO_RESERVED);
40692 - return fifo_mem + (next_cmd >> 2);
40693 + return (__le32 __force_kernel *)fifo_mem + (next_cmd >> 2);
40694 } else {
40695 need_bounce = true;
40696 }
40697 @@ -475,7 +475,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
40698
40699 fm = vmw_fifo_reserve(dev_priv, bytes);
40700 if (unlikely(fm == NULL)) {
40701 - *seqno = atomic_read(&dev_priv->marker_seq);
40702 + *seqno = atomic_read_unchecked(&dev_priv->marker_seq);
40703 ret = -ENOMEM;
40704 (void)vmw_fallback_wait(dev_priv, false, true, *seqno,
40705 false, 3*HZ);
40706 @@ -483,7 +483,7 @@ int vmw_fifo_send_fence(struct vmw_private *dev_priv, uint32_t *seqno)
40707 }
40708
40709 do {
40710 - *seqno = atomic_add_return(1, &dev_priv->marker_seq);
40711 + *seqno = atomic_add_return_unchecked(1, &dev_priv->marker_seq);
40712 } while (*seqno == 0);
40713
40714 if (!(fifo_state->capabilities & SVGA_FIFO_CAP_FENCE)) {
40715 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
40716 index c5c054a..46f0548 100644
40717 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
40718 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_gmrid_manager.c
40719 @@ -153,9 +153,9 @@ static void vmw_gmrid_man_debug(struct ttm_mem_type_manager *man,
40720 }
40721
40722 const struct ttm_mem_type_manager_func vmw_gmrid_manager_func = {
40723 - vmw_gmrid_man_init,
40724 - vmw_gmrid_man_takedown,
40725 - vmw_gmrid_man_get_node,
40726 - vmw_gmrid_man_put_node,
40727 - vmw_gmrid_man_debug
40728 + .init = vmw_gmrid_man_init,
40729 + .takedown = vmw_gmrid_man_takedown,
40730 + .get_node = vmw_gmrid_man_get_node,
40731 + .put_node = vmw_gmrid_man_put_node,
40732 + .debug = vmw_gmrid_man_debug
40733 };
40734 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
40735 index 45d5b5a..f3f5e4e 100644
40736 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
40737 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_ioctl.c
40738 @@ -141,7 +141,7 @@ int vmw_present_ioctl(struct drm_device *dev, void *data,
40739 int ret;
40740
40741 num_clips = arg->num_clips;
40742 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
40743 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
40744
40745 if (unlikely(num_clips == 0))
40746 return 0;
40747 @@ -225,7 +225,7 @@ int vmw_present_readback_ioctl(struct drm_device *dev, void *data,
40748 int ret;
40749
40750 num_clips = arg->num_clips;
40751 - clips_ptr = (struct drm_vmw_rect *)(unsigned long)arg->clips_ptr;
40752 + clips_ptr = (struct drm_vmw_rect __user *)(unsigned long)arg->clips_ptr;
40753
40754 if (unlikely(num_clips == 0))
40755 return 0;
40756 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
40757 index 4640adb..e1384ed 100644
40758 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
40759 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_irq.c
40760 @@ -107,7 +107,7 @@ bool vmw_seqno_passed(struct vmw_private *dev_priv,
40761 * emitted. Then the fence is stale and signaled.
40762 */
40763
40764 - ret = ((atomic_read(&dev_priv->marker_seq) - seqno)
40765 + ret = ((atomic_read_unchecked(&dev_priv->marker_seq) - seqno)
40766 > VMW_FENCE_WRAP);
40767
40768 return ret;
40769 @@ -138,7 +138,7 @@ int vmw_fallback_wait(struct vmw_private *dev_priv,
40770
40771 if (fifo_idle)
40772 down_read(&fifo_state->rwsem);
40773 - signal_seq = atomic_read(&dev_priv->marker_seq);
40774 + signal_seq = atomic_read_unchecked(&dev_priv->marker_seq);
40775 ret = 0;
40776
40777 for (;;) {
40778 diff --git a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
40779 index 8a8725c2..afed796 100644
40780 --- a/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
40781 +++ b/drivers/gpu/drm/vmwgfx/vmwgfx_marker.c
40782 @@ -151,7 +151,7 @@ int vmw_wait_lag(struct vmw_private *dev_priv,
40783 while (!vmw_lag_lt(queue, us)) {
40784 spin_lock(&queue->lock);
40785 if (list_empty(&queue->head))
40786 - seqno = atomic_read(&dev_priv->marker_seq);
40787 + seqno = atomic_read_unchecked(&dev_priv->marker_seq);
40788 else {
40789 marker = list_first_entry(&queue->head,
40790 struct vmw_marker, head);
40791 diff --git a/drivers/gpu/vga/vga_switcheroo.c b/drivers/gpu/vga/vga_switcheroo.c
40792 index ec0ae2d..dc0780b 100644
40793 --- a/drivers/gpu/vga/vga_switcheroo.c
40794 +++ b/drivers/gpu/vga/vga_switcheroo.c
40795 @@ -643,7 +643,7 @@ static int vga_switcheroo_runtime_resume(struct device *dev)
40796
40797 /* this version is for the case where the power switch is separate
40798 to the device being powered down. */
40799 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain)
40800 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain)
40801 {
40802 /* copy over all the bus versions */
40803 if (dev->bus && dev->bus->pm) {
40804 @@ -688,7 +688,7 @@ static int vga_switcheroo_runtime_resume_hdmi_audio(struct device *dev)
40805 return ret;
40806 }
40807
40808 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain)
40809 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain)
40810 {
40811 /* copy over all the bus versions */
40812 if (dev->bus && dev->bus->pm) {
40813 diff --git a/drivers/hid/hid-core.c b/drivers/hid/hid-core.c
40814 index 253fe23..0dfec5f 100644
40815 --- a/drivers/hid/hid-core.c
40816 +++ b/drivers/hid/hid-core.c
40817 @@ -2416,7 +2416,7 @@ EXPORT_SYMBOL_GPL(hid_ignore);
40818
40819 int hid_add_device(struct hid_device *hdev)
40820 {
40821 - static atomic_t id = ATOMIC_INIT(0);
40822 + static atomic_unchecked_t id = ATOMIC_INIT(0);
40823 int ret;
40824
40825 if (WARN_ON(hdev->status & HID_STAT_ADDED))
40826 @@ -2450,7 +2450,7 @@ int hid_add_device(struct hid_device *hdev)
40827 /* XXX hack, any other cleaner solution after the driver core
40828 * is converted to allow more than 20 bytes as the device name? */
40829 dev_set_name(&hdev->dev, "%04X:%04X:%04X.%04X", hdev->bus,
40830 - hdev->vendor, hdev->product, atomic_inc_return(&id));
40831 + hdev->vendor, hdev->product, atomic_inc_return_unchecked(&id));
40832
40833 hid_debug_register(hdev, dev_name(&hdev->dev));
40834 ret = device_add(&hdev->dev);
40835 diff --git a/drivers/hid/hid-wiimote-debug.c b/drivers/hid/hid-wiimote-debug.c
40836 index c13fb5b..55a3802 100644
40837 --- a/drivers/hid/hid-wiimote-debug.c
40838 +++ b/drivers/hid/hid-wiimote-debug.c
40839 @@ -66,7 +66,7 @@ static ssize_t wiidebug_eeprom_read(struct file *f, char __user *u, size_t s,
40840 else if (size == 0)
40841 return -EIO;
40842
40843 - if (copy_to_user(u, buf, size))
40844 + if (size > sizeof(buf) || copy_to_user(u, buf, size))
40845 return -EFAULT;
40846
40847 *off += size;
40848 diff --git a/drivers/hid/uhid.c b/drivers/hid/uhid.c
40849 index cedc6da..2c3da2a 100644
40850 --- a/drivers/hid/uhid.c
40851 +++ b/drivers/hid/uhid.c
40852 @@ -47,7 +47,7 @@ struct uhid_device {
40853 struct mutex report_lock;
40854 wait_queue_head_t report_wait;
40855 atomic_t report_done;
40856 - atomic_t report_id;
40857 + atomic_unchecked_t report_id;
40858 struct uhid_event report_buf;
40859 };
40860
40861 @@ -163,7 +163,7 @@ static int uhid_hid_get_raw(struct hid_device *hid, unsigned char rnum,
40862
40863 spin_lock_irqsave(&uhid->qlock, flags);
40864 ev->type = UHID_FEATURE;
40865 - ev->u.feature.id = atomic_inc_return(&uhid->report_id);
40866 + ev->u.feature.id = atomic_inc_return_unchecked(&uhid->report_id);
40867 ev->u.feature.rnum = rnum;
40868 ev->u.feature.rtype = report_type;
40869
40870 @@ -446,7 +446,7 @@ static int uhid_dev_feature_answer(struct uhid_device *uhid,
40871 spin_lock_irqsave(&uhid->qlock, flags);
40872
40873 /* id for old report; drop it silently */
40874 - if (atomic_read(&uhid->report_id) != ev->u.feature_answer.id)
40875 + if (atomic_read_unchecked(&uhid->report_id) != ev->u.feature_answer.id)
40876 goto unlock;
40877 if (atomic_read(&uhid->report_done))
40878 goto unlock;
40879 diff --git a/drivers/hv/channel.c b/drivers/hv/channel.c
40880 index cea623c..73011b0 100644
40881 --- a/drivers/hv/channel.c
40882 +++ b/drivers/hv/channel.c
40883 @@ -362,8 +362,8 @@ int vmbus_establish_gpadl(struct vmbus_channel *channel, void *kbuffer,
40884 int ret = 0;
40885 int t;
40886
40887 - next_gpadl_handle = atomic_read(&vmbus_connection.next_gpadl_handle);
40888 - atomic_inc(&vmbus_connection.next_gpadl_handle);
40889 + next_gpadl_handle = atomic_read_unchecked(&vmbus_connection.next_gpadl_handle);
40890 + atomic_inc_unchecked(&vmbus_connection.next_gpadl_handle);
40891
40892 ret = create_gpadl_header(kbuffer, size, &msginfo, &msgcount);
40893 if (ret)
40894 diff --git a/drivers/hv/hv.c b/drivers/hv/hv.c
40895 index f0c5e07..399256e 100644
40896 --- a/drivers/hv/hv.c
40897 +++ b/drivers/hv/hv.c
40898 @@ -112,7 +112,7 @@ static u64 do_hypercall(u64 control, void *input, void *output)
40899 u64 output_address = (output) ? virt_to_phys(output) : 0;
40900 u32 output_address_hi = output_address >> 32;
40901 u32 output_address_lo = output_address & 0xFFFFFFFF;
40902 - void *hypercall_page = hv_context.hypercall_page;
40903 + void *hypercall_page = ktva_ktla(hv_context.hypercall_page);
40904
40905 __asm__ __volatile__ ("call *%8" : "=d"(hv_status_hi),
40906 "=a"(hv_status_lo) : "d" (control_hi),
40907 diff --git a/drivers/hv/hv_balloon.c b/drivers/hv/hv_balloon.c
40908 index 7e17a54..a50a33d 100644
40909 --- a/drivers/hv/hv_balloon.c
40910 +++ b/drivers/hv/hv_balloon.c
40911 @@ -464,7 +464,7 @@ MODULE_PARM_DESC(hot_add, "If set attempt memory hot_add");
40912
40913 module_param(pressure_report_delay, uint, (S_IRUGO | S_IWUSR));
40914 MODULE_PARM_DESC(pressure_report_delay, "Delay in secs in reporting pressure");
40915 -static atomic_t trans_id = ATOMIC_INIT(0);
40916 +static atomic_unchecked_t trans_id = ATOMIC_INIT(0);
40917
40918 static int dm_ring_size = (5 * PAGE_SIZE);
40919
40920 @@ -886,7 +886,7 @@ static void hot_add_req(struct work_struct *dummy)
40921 pr_info("Memory hot add failed\n");
40922
40923 dm->state = DM_INITIALIZED;
40924 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
40925 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40926 vmbus_sendpacket(dm->dev->channel, &resp,
40927 sizeof(struct dm_hot_add_response),
40928 (unsigned long)NULL,
40929 @@ -960,7 +960,7 @@ static void post_status(struct hv_dynmem_device *dm)
40930 memset(&status, 0, sizeof(struct dm_status));
40931 status.hdr.type = DM_STATUS_REPORT;
40932 status.hdr.size = sizeof(struct dm_status);
40933 - status.hdr.trans_id = atomic_inc_return(&trans_id);
40934 + status.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40935
40936 /*
40937 * The host expects the guest to report free memory.
40938 @@ -980,7 +980,7 @@ static void post_status(struct hv_dynmem_device *dm)
40939 * send the status. This can happen if we were interrupted
40940 * after we picked our transaction ID.
40941 */
40942 - if (status.hdr.trans_id != atomic_read(&trans_id))
40943 + if (status.hdr.trans_id != atomic_read_unchecked(&trans_id))
40944 return;
40945
40946 vmbus_sendpacket(dm->dev->channel, &status,
40947 @@ -1108,7 +1108,7 @@ static void balloon_up(struct work_struct *dummy)
40948 */
40949
40950 do {
40951 - bl_resp->hdr.trans_id = atomic_inc_return(&trans_id);
40952 + bl_resp->hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40953 ret = vmbus_sendpacket(dm_device.dev->channel,
40954 bl_resp,
40955 bl_resp->hdr.size,
40956 @@ -1152,7 +1152,7 @@ static void balloon_down(struct hv_dynmem_device *dm,
40957
40958 memset(&resp, 0, sizeof(struct dm_unballoon_response));
40959 resp.hdr.type = DM_UNBALLOON_RESPONSE;
40960 - resp.hdr.trans_id = atomic_inc_return(&trans_id);
40961 + resp.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40962 resp.hdr.size = sizeof(struct dm_unballoon_response);
40963
40964 vmbus_sendpacket(dm_device.dev->channel, &resp,
40965 @@ -1215,7 +1215,7 @@ static void version_resp(struct hv_dynmem_device *dm,
40966 memset(&version_req, 0, sizeof(struct dm_version_request));
40967 version_req.hdr.type = DM_VERSION_REQUEST;
40968 version_req.hdr.size = sizeof(struct dm_version_request);
40969 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
40970 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40971 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN7;
40972 version_req.is_last_attempt = 1;
40973
40974 @@ -1385,7 +1385,7 @@ static int balloon_probe(struct hv_device *dev,
40975 memset(&version_req, 0, sizeof(struct dm_version_request));
40976 version_req.hdr.type = DM_VERSION_REQUEST;
40977 version_req.hdr.size = sizeof(struct dm_version_request);
40978 - version_req.hdr.trans_id = atomic_inc_return(&trans_id);
40979 + version_req.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40980 version_req.version.version = DYNMEM_PROTOCOL_VERSION_WIN8;
40981 version_req.is_last_attempt = 0;
40982
40983 @@ -1416,7 +1416,7 @@ static int balloon_probe(struct hv_device *dev,
40984 memset(&cap_msg, 0, sizeof(struct dm_capabilities));
40985 cap_msg.hdr.type = DM_CAPABILITIES_REPORT;
40986 cap_msg.hdr.size = sizeof(struct dm_capabilities);
40987 - cap_msg.hdr.trans_id = atomic_inc_return(&trans_id);
40988 + cap_msg.hdr.trans_id = atomic_inc_return_unchecked(&trans_id);
40989
40990 cap_msg.caps.cap_bits.balloon = 1;
40991 cap_msg.caps.cap_bits.hot_add = 1;
40992 diff --git a/drivers/hv/hyperv_vmbus.h b/drivers/hv/hyperv_vmbus.h
40993 index e055176..c22ff1f 100644
40994 --- a/drivers/hv/hyperv_vmbus.h
40995 +++ b/drivers/hv/hyperv_vmbus.h
40996 @@ -602,7 +602,7 @@ enum vmbus_connect_state {
40997 struct vmbus_connection {
40998 enum vmbus_connect_state conn_state;
40999
41000 - atomic_t next_gpadl_handle;
41001 + atomic_unchecked_t next_gpadl_handle;
41002
41003 /*
41004 * Represents channel interrupts. Each bit position represents a
41005 diff --git a/drivers/hv/vmbus_drv.c b/drivers/hv/vmbus_drv.c
41006 index 48aad4f..c768fb2 100644
41007 --- a/drivers/hv/vmbus_drv.c
41008 +++ b/drivers/hv/vmbus_drv.c
41009 @@ -846,10 +846,10 @@ int vmbus_device_register(struct hv_device *child_device_obj)
41010 {
41011 int ret = 0;
41012
41013 - static atomic_t device_num = ATOMIC_INIT(0);
41014 + static atomic_unchecked_t device_num = ATOMIC_INIT(0);
41015
41016 dev_set_name(&child_device_obj->device, "vmbus_0_%d",
41017 - atomic_inc_return(&device_num));
41018 + atomic_inc_return_unchecked(&device_num));
41019
41020 child_device_obj->device.bus = &hv_bus;
41021 child_device_obj->device.parent = &hv_acpi_dev->dev;
41022 diff --git a/drivers/hwmon/acpi_power_meter.c b/drivers/hwmon/acpi_power_meter.c
41023 index 6a34f7f..aa4c3a6 100644
41024 --- a/drivers/hwmon/acpi_power_meter.c
41025 +++ b/drivers/hwmon/acpi_power_meter.c
41026 @@ -117,7 +117,7 @@ struct sensor_template {
41027 struct device_attribute *devattr,
41028 const char *buf, size_t count);
41029 int index;
41030 -};
41031 +} __do_const;
41032
41033 /* Averaging interval */
41034 static int update_avg_interval(struct acpi_power_meter_resource *resource)
41035 @@ -632,7 +632,7 @@ static int register_attrs(struct acpi_power_meter_resource *resource,
41036 struct sensor_template *attrs)
41037 {
41038 struct device *dev = &resource->acpi_dev->dev;
41039 - struct sensor_device_attribute *sensors =
41040 + sensor_device_attribute_no_const *sensors =
41041 &resource->sensors[resource->num_sensors];
41042 int res = 0;
41043
41044 diff --git a/drivers/hwmon/applesmc.c b/drivers/hwmon/applesmc.c
41045 index 3288f13..71cfb4e 100644
41046 --- a/drivers/hwmon/applesmc.c
41047 +++ b/drivers/hwmon/applesmc.c
41048 @@ -1106,7 +1106,7 @@ static int applesmc_create_nodes(struct applesmc_node_group *groups, int num)
41049 {
41050 struct applesmc_node_group *grp;
41051 struct applesmc_dev_attr *node;
41052 - struct attribute *attr;
41053 + attribute_no_const *attr;
41054 int ret, i;
41055
41056 for (grp = groups; grp->format; grp++) {
41057 diff --git a/drivers/hwmon/asus_atk0110.c b/drivers/hwmon/asus_atk0110.c
41058 index dafc63c..4abb96c 100644
41059 --- a/drivers/hwmon/asus_atk0110.c
41060 +++ b/drivers/hwmon/asus_atk0110.c
41061 @@ -151,10 +151,10 @@ MODULE_DEVICE_TABLE(acpi, atk_ids);
41062 struct atk_sensor_data {
41063 struct list_head list;
41064 struct atk_data *data;
41065 - struct device_attribute label_attr;
41066 - struct device_attribute input_attr;
41067 - struct device_attribute limit1_attr;
41068 - struct device_attribute limit2_attr;
41069 + device_attribute_no_const label_attr;
41070 + device_attribute_no_const input_attr;
41071 + device_attribute_no_const limit1_attr;
41072 + device_attribute_no_const limit2_attr;
41073 char label_attr_name[ATTR_NAME_SIZE];
41074 char input_attr_name[ATTR_NAME_SIZE];
41075 char limit1_attr_name[ATTR_NAME_SIZE];
41076 @@ -274,7 +274,7 @@ static ssize_t atk_name_show(struct device *dev,
41077 static struct device_attribute atk_name_attr =
41078 __ATTR(name, 0444, atk_name_show, NULL);
41079
41080 -static void atk_init_attribute(struct device_attribute *attr, char *name,
41081 +static void atk_init_attribute(device_attribute_no_const *attr, char *name,
41082 sysfs_show_func show)
41083 {
41084 sysfs_attr_init(&attr->attr);
41085 diff --git a/drivers/hwmon/coretemp.c b/drivers/hwmon/coretemp.c
41086 index 9425098..7646cc5 100644
41087 --- a/drivers/hwmon/coretemp.c
41088 +++ b/drivers/hwmon/coretemp.c
41089 @@ -797,7 +797,7 @@ static int coretemp_cpu_callback(struct notifier_block *nfb,
41090 return NOTIFY_OK;
41091 }
41092
41093 -static struct notifier_block coretemp_cpu_notifier __refdata = {
41094 +static struct notifier_block coretemp_cpu_notifier = {
41095 .notifier_call = coretemp_cpu_callback,
41096 };
41097
41098 diff --git a/drivers/hwmon/ibmaem.c b/drivers/hwmon/ibmaem.c
41099 index 632f1dc..57e6a58 100644
41100 --- a/drivers/hwmon/ibmaem.c
41101 +++ b/drivers/hwmon/ibmaem.c
41102 @@ -926,7 +926,7 @@ static int aem_register_sensors(struct aem_data *data,
41103 struct aem_rw_sensor_template *rw)
41104 {
41105 struct device *dev = &data->pdev->dev;
41106 - struct sensor_device_attribute *sensors = data->sensors;
41107 + sensor_device_attribute_no_const *sensors = data->sensors;
41108 int err;
41109
41110 /* Set up read-only sensors */
41111 diff --git a/drivers/hwmon/iio_hwmon.c b/drivers/hwmon/iio_hwmon.c
41112 index 708081b..fe2d4ab 100644
41113 --- a/drivers/hwmon/iio_hwmon.c
41114 +++ b/drivers/hwmon/iio_hwmon.c
41115 @@ -73,7 +73,7 @@ static int iio_hwmon_probe(struct platform_device *pdev)
41116 {
41117 struct device *dev = &pdev->dev;
41118 struct iio_hwmon_state *st;
41119 - struct sensor_device_attribute *a;
41120 + sensor_device_attribute_no_const *a;
41121 int ret, i;
41122 int in_i = 1, temp_i = 1, curr_i = 1;
41123 enum iio_chan_type type;
41124 diff --git a/drivers/hwmon/nct6775.c b/drivers/hwmon/nct6775.c
41125 index cf811c1..4c17110 100644
41126 --- a/drivers/hwmon/nct6775.c
41127 +++ b/drivers/hwmon/nct6775.c
41128 @@ -944,10 +944,10 @@ static struct attribute_group *
41129 nct6775_create_attr_group(struct device *dev, struct sensor_template_group *tg,
41130 int repeat)
41131 {
41132 - struct attribute_group *group;
41133 + attribute_group_no_const *group;
41134 struct sensor_device_attr_u *su;
41135 - struct sensor_device_attribute *a;
41136 - struct sensor_device_attribute_2 *a2;
41137 + sensor_device_attribute_no_const *a;
41138 + sensor_device_attribute_2_no_const *a2;
41139 struct attribute **attrs;
41140 struct sensor_device_template **t;
41141 int i, count;
41142 diff --git a/drivers/hwmon/pmbus/pmbus_core.c b/drivers/hwmon/pmbus/pmbus_core.c
41143 index 3cbf66e..8c5cc2a 100644
41144 --- a/drivers/hwmon/pmbus/pmbus_core.c
41145 +++ b/drivers/hwmon/pmbus/pmbus_core.c
41146 @@ -782,7 +782,7 @@ static int pmbus_add_attribute(struct pmbus_data *data, struct attribute *attr)
41147 return 0;
41148 }
41149
41150 -static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41151 +static void pmbus_dev_attr_init(device_attribute_no_const *dev_attr,
41152 const char *name,
41153 umode_t mode,
41154 ssize_t (*show)(struct device *dev,
41155 @@ -799,7 +799,7 @@ static void pmbus_dev_attr_init(struct device_attribute *dev_attr,
41156 dev_attr->store = store;
41157 }
41158
41159 -static void pmbus_attr_init(struct sensor_device_attribute *a,
41160 +static void pmbus_attr_init(sensor_device_attribute_no_const *a,
41161 const char *name,
41162 umode_t mode,
41163 ssize_t (*show)(struct device *dev,
41164 @@ -821,7 +821,7 @@ static int pmbus_add_boolean(struct pmbus_data *data,
41165 u16 reg, u8 mask)
41166 {
41167 struct pmbus_boolean *boolean;
41168 - struct sensor_device_attribute *a;
41169 + sensor_device_attribute_no_const *a;
41170
41171 boolean = devm_kzalloc(data->dev, sizeof(*boolean), GFP_KERNEL);
41172 if (!boolean)
41173 @@ -846,7 +846,7 @@ static struct pmbus_sensor *pmbus_add_sensor(struct pmbus_data *data,
41174 bool update, bool readonly)
41175 {
41176 struct pmbus_sensor *sensor;
41177 - struct device_attribute *a;
41178 + device_attribute_no_const *a;
41179
41180 sensor = devm_kzalloc(data->dev, sizeof(*sensor), GFP_KERNEL);
41181 if (!sensor)
41182 @@ -877,7 +877,7 @@ static int pmbus_add_label(struct pmbus_data *data,
41183 const char *lstring, int index)
41184 {
41185 struct pmbus_label *label;
41186 - struct device_attribute *a;
41187 + device_attribute_no_const *a;
41188
41189 label = devm_kzalloc(data->dev, sizeof(*label), GFP_KERNEL);
41190 if (!label)
41191 diff --git a/drivers/hwmon/sht15.c b/drivers/hwmon/sht15.c
41192 index 97cd45a..ac54d8b 100644
41193 --- a/drivers/hwmon/sht15.c
41194 +++ b/drivers/hwmon/sht15.c
41195 @@ -169,7 +169,7 @@ struct sht15_data {
41196 int supply_uv;
41197 bool supply_uv_valid;
41198 struct work_struct update_supply_work;
41199 - atomic_t interrupt_handled;
41200 + atomic_unchecked_t interrupt_handled;
41201 };
41202
41203 /**
41204 @@ -542,13 +542,13 @@ static int sht15_measurement(struct sht15_data *data,
41205 ret = gpio_direction_input(data->pdata->gpio_data);
41206 if (ret)
41207 return ret;
41208 - atomic_set(&data->interrupt_handled, 0);
41209 + atomic_set_unchecked(&data->interrupt_handled, 0);
41210
41211 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41212 if (gpio_get_value(data->pdata->gpio_data) == 0) {
41213 disable_irq_nosync(gpio_to_irq(data->pdata->gpio_data));
41214 /* Only relevant if the interrupt hasn't occurred. */
41215 - if (!atomic_read(&data->interrupt_handled))
41216 + if (!atomic_read_unchecked(&data->interrupt_handled))
41217 schedule_work(&data->read_work);
41218 }
41219 ret = wait_event_timeout(data->wait_queue,
41220 @@ -820,7 +820,7 @@ static irqreturn_t sht15_interrupt_fired(int irq, void *d)
41221
41222 /* First disable the interrupt */
41223 disable_irq_nosync(irq);
41224 - atomic_inc(&data->interrupt_handled);
41225 + atomic_inc_unchecked(&data->interrupt_handled);
41226 /* Then schedule a reading work struct */
41227 if (data->state != SHT15_READING_NOTHING)
41228 schedule_work(&data->read_work);
41229 @@ -842,11 +842,11 @@ static void sht15_bh_read_data(struct work_struct *work_s)
41230 * If not, then start the interrupt again - care here as could
41231 * have gone low in meantime so verify it hasn't!
41232 */
41233 - atomic_set(&data->interrupt_handled, 0);
41234 + atomic_set_unchecked(&data->interrupt_handled, 0);
41235 enable_irq(gpio_to_irq(data->pdata->gpio_data));
41236 /* If still not occurred or another handler was scheduled */
41237 if (gpio_get_value(data->pdata->gpio_data)
41238 - || atomic_read(&data->interrupt_handled))
41239 + || atomic_read_unchecked(&data->interrupt_handled))
41240 return;
41241 }
41242
41243 diff --git a/drivers/hwmon/via-cputemp.c b/drivers/hwmon/via-cputemp.c
41244 index 38944e9..ae9e5ed 100644
41245 --- a/drivers/hwmon/via-cputemp.c
41246 +++ b/drivers/hwmon/via-cputemp.c
41247 @@ -296,7 +296,7 @@ static int via_cputemp_cpu_callback(struct notifier_block *nfb,
41248 return NOTIFY_OK;
41249 }
41250
41251 -static struct notifier_block via_cputemp_cpu_notifier __refdata = {
41252 +static struct notifier_block via_cputemp_cpu_notifier = {
41253 .notifier_call = via_cputemp_cpu_callback,
41254 };
41255
41256 diff --git a/drivers/i2c/busses/i2c-amd756-s4882.c b/drivers/i2c/busses/i2c-amd756-s4882.c
41257 index 07f01ac..d79ad3d 100644
41258 --- a/drivers/i2c/busses/i2c-amd756-s4882.c
41259 +++ b/drivers/i2c/busses/i2c-amd756-s4882.c
41260 @@ -43,7 +43,7 @@
41261 extern struct i2c_adapter amd756_smbus;
41262
41263 static struct i2c_adapter *s4882_adapter;
41264 -static struct i2c_algorithm *s4882_algo;
41265 +static i2c_algorithm_no_const *s4882_algo;
41266
41267 /* Wrapper access functions for multiplexed SMBus */
41268 static DEFINE_MUTEX(amd756_lock);
41269 diff --git a/drivers/i2c/busses/i2c-diolan-u2c.c b/drivers/i2c/busses/i2c-diolan-u2c.c
41270 index 721f7eb..0fd2a09 100644
41271 --- a/drivers/i2c/busses/i2c-diolan-u2c.c
41272 +++ b/drivers/i2c/busses/i2c-diolan-u2c.c
41273 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(frequency, "I2C clock frequency in hertz");
41274 /* usb layer */
41275
41276 /* Send command to device, and get response. */
41277 -static int diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41278 +static int __intentional_overflow(-1) diolan_usb_transfer(struct i2c_diolan_u2c *dev)
41279 {
41280 int ret = 0;
41281 int actual;
41282 diff --git a/drivers/i2c/busses/i2c-nforce2-s4985.c b/drivers/i2c/busses/i2c-nforce2-s4985.c
41283 index 2ca268d..c6acbdf 100644
41284 --- a/drivers/i2c/busses/i2c-nforce2-s4985.c
41285 +++ b/drivers/i2c/busses/i2c-nforce2-s4985.c
41286 @@ -41,7 +41,7 @@
41287 extern struct i2c_adapter *nforce2_smbus;
41288
41289 static struct i2c_adapter *s4985_adapter;
41290 -static struct i2c_algorithm *s4985_algo;
41291 +static i2c_algorithm_no_const *s4985_algo;
41292
41293 /* Wrapper access functions for multiplexed SMBus */
41294 static DEFINE_MUTEX(nforce2_lock);
41295 diff --git a/drivers/i2c/i2c-dev.c b/drivers/i2c/i2c-dev.c
41296 index 80b47e8..1a6040d9 100644
41297 --- a/drivers/i2c/i2c-dev.c
41298 +++ b/drivers/i2c/i2c-dev.c
41299 @@ -277,7 +277,7 @@ static noinline int i2cdev_ioctl_rdrw(struct i2c_client *client,
41300 break;
41301 }
41302
41303 - data_ptrs[i] = (u8 __user *)rdwr_pa[i].buf;
41304 + data_ptrs[i] = (u8 __force_user *)rdwr_pa[i].buf;
41305 rdwr_pa[i].buf = memdup_user(data_ptrs[i], rdwr_pa[i].len);
41306 if (IS_ERR(rdwr_pa[i].buf)) {
41307 res = PTR_ERR(rdwr_pa[i].buf);
41308 diff --git a/drivers/ide/ide-cd.c b/drivers/ide/ide-cd.c
41309 index 0b510ba..4fbb5085 100644
41310 --- a/drivers/ide/ide-cd.c
41311 +++ b/drivers/ide/ide-cd.c
41312 @@ -768,7 +768,7 @@ static void cdrom_do_block_pc(ide_drive_t *drive, struct request *rq)
41313 alignment = queue_dma_alignment(q) | q->dma_pad_mask;
41314 if ((unsigned long)buf & alignment
41315 || blk_rq_bytes(rq) & q->dma_pad_mask
41316 - || object_is_on_stack(buf))
41317 + || object_starts_on_stack(buf))
41318 drive->dma = 0;
41319 }
41320 }
41321 diff --git a/drivers/iio/industrialio-core.c b/drivers/iio/industrialio-core.c
41322 index 18f72e3..3722327 100644
41323 --- a/drivers/iio/industrialio-core.c
41324 +++ b/drivers/iio/industrialio-core.c
41325 @@ -521,7 +521,7 @@ static ssize_t iio_write_channel_info(struct device *dev,
41326 }
41327
41328 static
41329 -int __iio_device_attr_init(struct device_attribute *dev_attr,
41330 +int __iio_device_attr_init(device_attribute_no_const *dev_attr,
41331 const char *postfix,
41332 struct iio_chan_spec const *chan,
41333 ssize_t (*readfunc)(struct device *dev,
41334 diff --git a/drivers/infiniband/core/cm.c b/drivers/infiniband/core/cm.c
41335 index f2ef7ef..743d02f 100644
41336 --- a/drivers/infiniband/core/cm.c
41337 +++ b/drivers/infiniband/core/cm.c
41338 @@ -114,7 +114,7 @@ static char const counter_group_names[CM_COUNTER_GROUPS]
41339
41340 struct cm_counter_group {
41341 struct kobject obj;
41342 - atomic_long_t counter[CM_ATTR_COUNT];
41343 + atomic_long_unchecked_t counter[CM_ATTR_COUNT];
41344 };
41345
41346 struct cm_counter_attribute {
41347 @@ -1392,7 +1392,7 @@ static void cm_dup_req_handler(struct cm_work *work,
41348 struct ib_mad_send_buf *msg = NULL;
41349 int ret;
41350
41351 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41352 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41353 counter[CM_REQ_COUNTER]);
41354
41355 /* Quick state check to discard duplicate REQs. */
41356 @@ -1776,7 +1776,7 @@ static void cm_dup_rep_handler(struct cm_work *work)
41357 if (!cm_id_priv)
41358 return;
41359
41360 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41361 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41362 counter[CM_REP_COUNTER]);
41363 ret = cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg);
41364 if (ret)
41365 @@ -1943,7 +1943,7 @@ static int cm_rtu_handler(struct cm_work *work)
41366 if (cm_id_priv->id.state != IB_CM_REP_SENT &&
41367 cm_id_priv->id.state != IB_CM_MRA_REP_RCVD) {
41368 spin_unlock_irq(&cm_id_priv->lock);
41369 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41370 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41371 counter[CM_RTU_COUNTER]);
41372 goto out;
41373 }
41374 @@ -2126,7 +2126,7 @@ static int cm_dreq_handler(struct cm_work *work)
41375 cm_id_priv = cm_acquire_id(dreq_msg->remote_comm_id,
41376 dreq_msg->local_comm_id);
41377 if (!cm_id_priv) {
41378 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41379 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41380 counter[CM_DREQ_COUNTER]);
41381 cm_issue_drep(work->port, work->mad_recv_wc);
41382 return -EINVAL;
41383 @@ -2151,7 +2151,7 @@ static int cm_dreq_handler(struct cm_work *work)
41384 case IB_CM_MRA_REP_RCVD:
41385 break;
41386 case IB_CM_TIMEWAIT:
41387 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41388 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41389 counter[CM_DREQ_COUNTER]);
41390 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41391 goto unlock;
41392 @@ -2165,7 +2165,7 @@ static int cm_dreq_handler(struct cm_work *work)
41393 cm_free_msg(msg);
41394 goto deref;
41395 case IB_CM_DREQ_RCVD:
41396 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41397 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41398 counter[CM_DREQ_COUNTER]);
41399 goto unlock;
41400 default:
41401 @@ -2532,7 +2532,7 @@ static int cm_mra_handler(struct cm_work *work)
41402 ib_modify_mad(cm_id_priv->av.port->mad_agent,
41403 cm_id_priv->msg, timeout)) {
41404 if (cm_id_priv->id.lap_state == IB_CM_MRA_LAP_RCVD)
41405 - atomic_long_inc(&work->port->
41406 + atomic_long_inc_unchecked(&work->port->
41407 counter_group[CM_RECV_DUPLICATES].
41408 counter[CM_MRA_COUNTER]);
41409 goto out;
41410 @@ -2541,7 +2541,7 @@ static int cm_mra_handler(struct cm_work *work)
41411 break;
41412 case IB_CM_MRA_REQ_RCVD:
41413 case IB_CM_MRA_REP_RCVD:
41414 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41415 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41416 counter[CM_MRA_COUNTER]);
41417 /* fall through */
41418 default:
41419 @@ -2703,7 +2703,7 @@ static int cm_lap_handler(struct cm_work *work)
41420 case IB_CM_LAP_IDLE:
41421 break;
41422 case IB_CM_MRA_LAP_SENT:
41423 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41424 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41425 counter[CM_LAP_COUNTER]);
41426 if (cm_alloc_response_msg(work->port, work->mad_recv_wc, &msg))
41427 goto unlock;
41428 @@ -2719,7 +2719,7 @@ static int cm_lap_handler(struct cm_work *work)
41429 cm_free_msg(msg);
41430 goto deref;
41431 case IB_CM_LAP_RCVD:
41432 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41433 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41434 counter[CM_LAP_COUNTER]);
41435 goto unlock;
41436 default:
41437 @@ -3003,7 +3003,7 @@ static int cm_sidr_req_handler(struct cm_work *work)
41438 cur_cm_id_priv = cm_insert_remote_sidr(cm_id_priv);
41439 if (cur_cm_id_priv) {
41440 spin_unlock_irq(&cm.lock);
41441 - atomic_long_inc(&work->port->counter_group[CM_RECV_DUPLICATES].
41442 + atomic_long_inc_unchecked(&work->port->counter_group[CM_RECV_DUPLICATES].
41443 counter[CM_SIDR_REQ_COUNTER]);
41444 goto out; /* Duplicate message. */
41445 }
41446 @@ -3215,10 +3215,10 @@ static void cm_send_handler(struct ib_mad_agent *mad_agent,
41447 if (!msg->context[0] && (attr_index != CM_REJ_COUNTER))
41448 msg->retries = 1;
41449
41450 - atomic_long_add(1 + msg->retries,
41451 + atomic_long_add_unchecked(1 + msg->retries,
41452 &port->counter_group[CM_XMIT].counter[attr_index]);
41453 if (msg->retries)
41454 - atomic_long_add(msg->retries,
41455 + atomic_long_add_unchecked(msg->retries,
41456 &port->counter_group[CM_XMIT_RETRIES].
41457 counter[attr_index]);
41458
41459 @@ -3428,7 +3428,7 @@ static void cm_recv_handler(struct ib_mad_agent *mad_agent,
41460 }
41461
41462 attr_id = be16_to_cpu(mad_recv_wc->recv_buf.mad->mad_hdr.attr_id);
41463 - atomic_long_inc(&port->counter_group[CM_RECV].
41464 + atomic_long_inc_unchecked(&port->counter_group[CM_RECV].
41465 counter[attr_id - CM_ATTR_ID_OFFSET]);
41466
41467 work = kmalloc(sizeof *work + sizeof(struct ib_sa_path_rec) * paths,
41468 @@ -3633,7 +3633,7 @@ static ssize_t cm_show_counter(struct kobject *obj, struct attribute *attr,
41469 cm_attr = container_of(attr, struct cm_counter_attribute, attr);
41470
41471 return sprintf(buf, "%ld\n",
41472 - atomic_long_read(&group->counter[cm_attr->index]));
41473 + atomic_long_read_unchecked(&group->counter[cm_attr->index]));
41474 }
41475
41476 static const struct sysfs_ops cm_counter_ops = {
41477 diff --git a/drivers/infiniband/core/fmr_pool.c b/drivers/infiniband/core/fmr_pool.c
41478 index 9f5ad7c..588cd84 100644
41479 --- a/drivers/infiniband/core/fmr_pool.c
41480 +++ b/drivers/infiniband/core/fmr_pool.c
41481 @@ -98,8 +98,8 @@ struct ib_fmr_pool {
41482
41483 struct task_struct *thread;
41484
41485 - atomic_t req_ser;
41486 - atomic_t flush_ser;
41487 + atomic_unchecked_t req_ser;
41488 + atomic_unchecked_t flush_ser;
41489
41490 wait_queue_head_t force_wait;
41491 };
41492 @@ -179,10 +179,10 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
41493 struct ib_fmr_pool *pool = pool_ptr;
41494
41495 do {
41496 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) < 0) {
41497 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) < 0) {
41498 ib_fmr_batch_release(pool);
41499
41500 - atomic_inc(&pool->flush_ser);
41501 + atomic_inc_unchecked(&pool->flush_ser);
41502 wake_up_interruptible(&pool->force_wait);
41503
41504 if (pool->flush_function)
41505 @@ -190,7 +190,7 @@ static int ib_fmr_cleanup_thread(void *pool_ptr)
41506 }
41507
41508 set_current_state(TASK_INTERRUPTIBLE);
41509 - if (atomic_read(&pool->flush_ser) - atomic_read(&pool->req_ser) >= 0 &&
41510 + if (atomic_read_unchecked(&pool->flush_ser) - atomic_read_unchecked(&pool->req_ser) >= 0 &&
41511 !kthread_should_stop())
41512 schedule();
41513 __set_current_state(TASK_RUNNING);
41514 @@ -282,8 +282,8 @@ struct ib_fmr_pool *ib_create_fmr_pool(struct ib_pd *pd,
41515 pool->dirty_watermark = params->dirty_watermark;
41516 pool->dirty_len = 0;
41517 spin_lock_init(&pool->pool_lock);
41518 - atomic_set(&pool->req_ser, 0);
41519 - atomic_set(&pool->flush_ser, 0);
41520 + atomic_set_unchecked(&pool->req_ser, 0);
41521 + atomic_set_unchecked(&pool->flush_ser, 0);
41522 init_waitqueue_head(&pool->force_wait);
41523
41524 pool->thread = kthread_run(ib_fmr_cleanup_thread,
41525 @@ -411,11 +411,11 @@ int ib_flush_fmr_pool(struct ib_fmr_pool *pool)
41526 }
41527 spin_unlock_irq(&pool->pool_lock);
41528
41529 - serial = atomic_inc_return(&pool->req_ser);
41530 + serial = atomic_inc_return_unchecked(&pool->req_ser);
41531 wake_up_process(pool->thread);
41532
41533 if (wait_event_interruptible(pool->force_wait,
41534 - atomic_read(&pool->flush_ser) - serial >= 0))
41535 + atomic_read_unchecked(&pool->flush_ser) - serial >= 0))
41536 return -EINTR;
41537
41538 return 0;
41539 @@ -525,7 +525,7 @@ int ib_fmr_pool_unmap(struct ib_pool_fmr *fmr)
41540 } else {
41541 list_add_tail(&fmr->list, &pool->dirty_list);
41542 if (++pool->dirty_len >= pool->dirty_watermark) {
41543 - atomic_inc(&pool->req_ser);
41544 + atomic_inc_unchecked(&pool->req_ser);
41545 wake_up_process(pool->thread);
41546 }
41547 }
41548 diff --git a/drivers/infiniband/hw/cxgb4/mem.c b/drivers/infiniband/hw/cxgb4/mem.c
41549 index 84e4500..2c9beeb 100644
41550 --- a/drivers/infiniband/hw/cxgb4/mem.c
41551 +++ b/drivers/infiniband/hw/cxgb4/mem.c
41552 @@ -249,7 +249,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
41553 int err;
41554 struct fw_ri_tpte tpt;
41555 u32 stag_idx;
41556 - static atomic_t key;
41557 + static atomic_unchecked_t key;
41558
41559 if (c4iw_fatal_error(rdev))
41560 return -EIO;
41561 @@ -266,7 +266,7 @@ static int write_tpt_entry(struct c4iw_rdev *rdev, u32 reset_tpt_entry,
41562 if (rdev->stats.stag.cur > rdev->stats.stag.max)
41563 rdev->stats.stag.max = rdev->stats.stag.cur;
41564 mutex_unlock(&rdev->stats.lock);
41565 - *stag = (stag_idx << 8) | (atomic_inc_return(&key) & 0xff);
41566 + *stag = (stag_idx << 8) | (atomic_inc_return_unchecked(&key) & 0xff);
41567 }
41568 PDBG("%s stag_state 0x%0x type 0x%0x pdid 0x%0x, stag_idx 0x%x\n",
41569 __func__, stag_state, type, pdid, stag_idx);
41570 diff --git a/drivers/infiniband/hw/ipath/ipath_dma.c b/drivers/infiniband/hw/ipath/ipath_dma.c
41571 index 644c2c7..ecf0879 100644
41572 --- a/drivers/infiniband/hw/ipath/ipath_dma.c
41573 +++ b/drivers/infiniband/hw/ipath/ipath_dma.c
41574 @@ -176,17 +176,17 @@ static void ipath_dma_free_coherent(struct ib_device *dev, size_t size,
41575 }
41576
41577 struct ib_dma_mapping_ops ipath_dma_mapping_ops = {
41578 - ipath_mapping_error,
41579 - ipath_dma_map_single,
41580 - ipath_dma_unmap_single,
41581 - ipath_dma_map_page,
41582 - ipath_dma_unmap_page,
41583 - ipath_map_sg,
41584 - ipath_unmap_sg,
41585 - ipath_sg_dma_address,
41586 - ipath_sg_dma_len,
41587 - ipath_sync_single_for_cpu,
41588 - ipath_sync_single_for_device,
41589 - ipath_dma_alloc_coherent,
41590 - ipath_dma_free_coherent
41591 + .mapping_error = ipath_mapping_error,
41592 + .map_single = ipath_dma_map_single,
41593 + .unmap_single = ipath_dma_unmap_single,
41594 + .map_page = ipath_dma_map_page,
41595 + .unmap_page = ipath_dma_unmap_page,
41596 + .map_sg = ipath_map_sg,
41597 + .unmap_sg = ipath_unmap_sg,
41598 + .dma_address = ipath_sg_dma_address,
41599 + .dma_len = ipath_sg_dma_len,
41600 + .sync_single_for_cpu = ipath_sync_single_for_cpu,
41601 + .sync_single_for_device = ipath_sync_single_for_device,
41602 + .alloc_coherent = ipath_dma_alloc_coherent,
41603 + .free_coherent = ipath_dma_free_coherent
41604 };
41605 diff --git a/drivers/infiniband/hw/ipath/ipath_rc.c b/drivers/infiniband/hw/ipath/ipath_rc.c
41606 index 79b3dbc..96e5fcc 100644
41607 --- a/drivers/infiniband/hw/ipath/ipath_rc.c
41608 +++ b/drivers/infiniband/hw/ipath/ipath_rc.c
41609 @@ -1868,7 +1868,7 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
41610 struct ib_atomic_eth *ateth;
41611 struct ipath_ack_entry *e;
41612 u64 vaddr;
41613 - atomic64_t *maddr;
41614 + atomic64_unchecked_t *maddr;
41615 u64 sdata;
41616 u32 rkey;
41617 u8 next;
41618 @@ -1903,11 +1903,11 @@ void ipath_rc_rcv(struct ipath_ibdev *dev, struct ipath_ib_header *hdr,
41619 IB_ACCESS_REMOTE_ATOMIC)))
41620 goto nack_acc_unlck;
41621 /* Perform atomic OP and save result. */
41622 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
41623 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
41624 sdata = be64_to_cpu(ateth->swap_data);
41625 e = &qp->s_ack_queue[qp->r_head_ack_queue];
41626 e->atomic_data = (opcode == OP(FETCH_ADD)) ?
41627 - (u64) atomic64_add_return(sdata, maddr) - sdata :
41628 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
41629 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
41630 be64_to_cpu(ateth->compare_data),
41631 sdata);
41632 diff --git a/drivers/infiniband/hw/ipath/ipath_ruc.c b/drivers/infiniband/hw/ipath/ipath_ruc.c
41633 index 1f95bba..9530f87 100644
41634 --- a/drivers/infiniband/hw/ipath/ipath_ruc.c
41635 +++ b/drivers/infiniband/hw/ipath/ipath_ruc.c
41636 @@ -266,7 +266,7 @@ static void ipath_ruc_loopback(struct ipath_qp *sqp)
41637 unsigned long flags;
41638 struct ib_wc wc;
41639 u64 sdata;
41640 - atomic64_t *maddr;
41641 + atomic64_unchecked_t *maddr;
41642 enum ib_wc_status send_status;
41643
41644 /*
41645 @@ -382,11 +382,11 @@ again:
41646 IB_ACCESS_REMOTE_ATOMIC)))
41647 goto acc_err;
41648 /* Perform atomic OP and save result. */
41649 - maddr = (atomic64_t *) qp->r_sge.sge.vaddr;
41650 + maddr = (atomic64_unchecked_t *) qp->r_sge.sge.vaddr;
41651 sdata = wqe->wr.wr.atomic.compare_add;
41652 *(u64 *) sqp->s_sge.sge.vaddr =
41653 (wqe->wr.opcode == IB_WR_ATOMIC_FETCH_AND_ADD) ?
41654 - (u64) atomic64_add_return(sdata, maddr) - sdata :
41655 + (u64) atomic64_add_return_unchecked(sdata, maddr) - sdata :
41656 (u64) cmpxchg((u64 *) qp->r_sge.sge.vaddr,
41657 sdata, wqe->wr.wr.atomic.swap);
41658 goto send_comp;
41659 diff --git a/drivers/infiniband/hw/mlx4/mad.c b/drivers/infiniband/hw/mlx4/mad.c
41660 index f2a3f48..673ec79 100644
41661 --- a/drivers/infiniband/hw/mlx4/mad.c
41662 +++ b/drivers/infiniband/hw/mlx4/mad.c
41663 @@ -98,7 +98,7 @@ __be64 mlx4_ib_gen_node_guid(void)
41664
41665 __be64 mlx4_ib_get_new_demux_tid(struct mlx4_ib_demux_ctx *ctx)
41666 {
41667 - return cpu_to_be64(atomic_inc_return(&ctx->tid)) |
41668 + return cpu_to_be64(atomic_inc_return_unchecked(&ctx->tid)) |
41669 cpu_to_be64(0xff00000000000000LL);
41670 }
41671
41672 diff --git a/drivers/infiniband/hw/mlx4/mcg.c b/drivers/infiniband/hw/mlx4/mcg.c
41673 index 25b2cdf..099ff97 100644
41674 --- a/drivers/infiniband/hw/mlx4/mcg.c
41675 +++ b/drivers/infiniband/hw/mlx4/mcg.c
41676 @@ -1040,7 +1040,7 @@ int mlx4_ib_mcg_port_init(struct mlx4_ib_demux_ctx *ctx)
41677 {
41678 char name[20];
41679
41680 - atomic_set(&ctx->tid, 0);
41681 + atomic_set_unchecked(&ctx->tid, 0);
41682 sprintf(name, "mlx4_ib_mcg%d", ctx->port);
41683 ctx->mcg_wq = create_singlethread_workqueue(name);
41684 if (!ctx->mcg_wq)
41685 diff --git a/drivers/infiniband/hw/mlx4/mlx4_ib.h b/drivers/infiniband/hw/mlx4/mlx4_ib.h
41686 index 036b663..c9a8c73 100644
41687 --- a/drivers/infiniband/hw/mlx4/mlx4_ib.h
41688 +++ b/drivers/infiniband/hw/mlx4/mlx4_ib.h
41689 @@ -404,7 +404,7 @@ struct mlx4_ib_demux_ctx {
41690 struct list_head mcg_mgid0_list;
41691 struct workqueue_struct *mcg_wq;
41692 struct mlx4_ib_demux_pv_ctx **tun;
41693 - atomic_t tid;
41694 + atomic_unchecked_t tid;
41695 int flushing; /* flushing the work queue */
41696 };
41697
41698 diff --git a/drivers/infiniband/hw/mthca/mthca_cmd.c b/drivers/infiniband/hw/mthca/mthca_cmd.c
41699 index 9d3e5c1..6f166df 100644
41700 --- a/drivers/infiniband/hw/mthca/mthca_cmd.c
41701 +++ b/drivers/infiniband/hw/mthca/mthca_cmd.c
41702 @@ -772,7 +772,7 @@ static void mthca_setup_cmd_doorbells(struct mthca_dev *dev, u64 base)
41703 mthca_dbg(dev, "Mapped doorbell page for posting FW commands\n");
41704 }
41705
41706 -int mthca_QUERY_FW(struct mthca_dev *dev)
41707 +int __intentional_overflow(-1) mthca_QUERY_FW(struct mthca_dev *dev)
41708 {
41709 struct mthca_mailbox *mailbox;
41710 u32 *outbox;
41711 @@ -1612,7 +1612,7 @@ int mthca_HW2SW_MPT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41712 CMD_TIME_CLASS_B);
41713 }
41714
41715 -int mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41716 +int __intentional_overflow(-1) mthca_WRITE_MTT(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41717 int num_mtt)
41718 {
41719 return mthca_cmd(dev, mailbox->dma, num_mtt, 0, CMD_WRITE_MTT,
41720 @@ -1634,7 +1634,7 @@ int mthca_MAP_EQ(struct mthca_dev *dev, u64 event_mask, int unmap,
41721 0, CMD_MAP_EQ, CMD_TIME_CLASS_B);
41722 }
41723
41724 -int mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41725 +int __intentional_overflow(-1) mthca_SW2HW_EQ(struct mthca_dev *dev, struct mthca_mailbox *mailbox,
41726 int eq_num)
41727 {
41728 return mthca_cmd(dev, mailbox->dma, eq_num, 0, CMD_SW2HW_EQ,
41729 @@ -1857,7 +1857,7 @@ int mthca_CONF_SPECIAL_QP(struct mthca_dev *dev, int type, u32 qpn)
41730 CMD_TIME_CLASS_B);
41731 }
41732
41733 -int mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
41734 +int __intentional_overflow(-1) mthca_MAD_IFC(struct mthca_dev *dev, int ignore_mkey, int ignore_bkey,
41735 int port, struct ib_wc *in_wc, struct ib_grh *in_grh,
41736 void *in_mad, void *response_mad)
41737 {
41738 diff --git a/drivers/infiniband/hw/mthca/mthca_main.c b/drivers/infiniband/hw/mthca/mthca_main.c
41739 index 87897b9..7e79542 100644
41740 --- a/drivers/infiniband/hw/mthca/mthca_main.c
41741 +++ b/drivers/infiniband/hw/mthca/mthca_main.c
41742 @@ -692,7 +692,7 @@ err_close:
41743 return err;
41744 }
41745
41746 -static int mthca_setup_hca(struct mthca_dev *dev)
41747 +static int __intentional_overflow(-1) mthca_setup_hca(struct mthca_dev *dev)
41748 {
41749 int err;
41750
41751 diff --git a/drivers/infiniband/hw/mthca/mthca_mr.c b/drivers/infiniband/hw/mthca/mthca_mr.c
41752 index ed9a989..6aa5dc2 100644
41753 --- a/drivers/infiniband/hw/mthca/mthca_mr.c
41754 +++ b/drivers/infiniband/hw/mthca/mthca_mr.c
41755 @@ -81,7 +81,7 @@ struct mthca_mpt_entry {
41756 * through the bitmaps)
41757 */
41758
41759 -static u32 mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
41760 +static u32 __intentional_overflow(-1) mthca_buddy_alloc(struct mthca_buddy *buddy, int order)
41761 {
41762 int o;
41763 int m;
41764 @@ -426,7 +426,7 @@ static inline u32 adjust_key(struct mthca_dev *dev, u32 key)
41765 return key;
41766 }
41767
41768 -int mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
41769 +int __intentional_overflow(-1) mthca_mr_alloc(struct mthca_dev *dev, u32 pd, int buffer_size_shift,
41770 u64 iova, u64 total_size, u32 access, struct mthca_mr *mr)
41771 {
41772 struct mthca_mailbox *mailbox;
41773 @@ -516,7 +516,7 @@ int mthca_mr_alloc_notrans(struct mthca_dev *dev, u32 pd,
41774 return mthca_mr_alloc(dev, pd, 12, 0, ~0ULL, access, mr);
41775 }
41776
41777 -int mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
41778 +int __intentional_overflow(-1) mthca_mr_alloc_phys(struct mthca_dev *dev, u32 pd,
41779 u64 *buffer_list, int buffer_size_shift,
41780 int list_len, u64 iova, u64 total_size,
41781 u32 access, struct mthca_mr *mr)
41782 diff --git a/drivers/infiniband/hw/mthca/mthca_provider.c b/drivers/infiniband/hw/mthca/mthca_provider.c
41783 index 5b71d43..35a9e14 100644
41784 --- a/drivers/infiniband/hw/mthca/mthca_provider.c
41785 +++ b/drivers/infiniband/hw/mthca/mthca_provider.c
41786 @@ -763,7 +763,7 @@ unlock:
41787 return 0;
41788 }
41789
41790 -static int mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
41791 +static int __intentional_overflow(-1) mthca_resize_cq(struct ib_cq *ibcq, int entries, struct ib_udata *udata)
41792 {
41793 struct mthca_dev *dev = to_mdev(ibcq->device);
41794 struct mthca_cq *cq = to_mcq(ibcq);
41795 diff --git a/drivers/infiniband/hw/nes/nes.c b/drivers/infiniband/hw/nes/nes.c
41796 index 4291410..d2ab1fb 100644
41797 --- a/drivers/infiniband/hw/nes/nes.c
41798 +++ b/drivers/infiniband/hw/nes/nes.c
41799 @@ -98,7 +98,7 @@ MODULE_PARM_DESC(limit_maxrdreqsz, "Limit max read request size to 256 Bytes");
41800 LIST_HEAD(nes_adapter_list);
41801 static LIST_HEAD(nes_dev_list);
41802
41803 -atomic_t qps_destroyed;
41804 +atomic_unchecked_t qps_destroyed;
41805
41806 static unsigned int ee_flsh_adapter;
41807 static unsigned int sysfs_nonidx_addr;
41808 @@ -269,7 +269,7 @@ static void nes_cqp_rem_ref_callback(struct nes_device *nesdev, struct nes_cqp_r
41809 struct nes_qp *nesqp = cqp_request->cqp_callback_pointer;
41810 struct nes_adapter *nesadapter = nesdev->nesadapter;
41811
41812 - atomic_inc(&qps_destroyed);
41813 + atomic_inc_unchecked(&qps_destroyed);
41814
41815 /* Free the control structures */
41816
41817 diff --git a/drivers/infiniband/hw/nes/nes.h b/drivers/infiniband/hw/nes/nes.h
41818 index 33cc589..3bd6538 100644
41819 --- a/drivers/infiniband/hw/nes/nes.h
41820 +++ b/drivers/infiniband/hw/nes/nes.h
41821 @@ -177,17 +177,17 @@ extern unsigned int nes_debug_level;
41822 extern unsigned int wqm_quanta;
41823 extern struct list_head nes_adapter_list;
41824
41825 -extern atomic_t cm_connects;
41826 -extern atomic_t cm_accepts;
41827 -extern atomic_t cm_disconnects;
41828 -extern atomic_t cm_closes;
41829 -extern atomic_t cm_connecteds;
41830 -extern atomic_t cm_connect_reqs;
41831 -extern atomic_t cm_rejects;
41832 -extern atomic_t mod_qp_timouts;
41833 -extern atomic_t qps_created;
41834 -extern atomic_t qps_destroyed;
41835 -extern atomic_t sw_qps_destroyed;
41836 +extern atomic_unchecked_t cm_connects;
41837 +extern atomic_unchecked_t cm_accepts;
41838 +extern atomic_unchecked_t cm_disconnects;
41839 +extern atomic_unchecked_t cm_closes;
41840 +extern atomic_unchecked_t cm_connecteds;
41841 +extern atomic_unchecked_t cm_connect_reqs;
41842 +extern atomic_unchecked_t cm_rejects;
41843 +extern atomic_unchecked_t mod_qp_timouts;
41844 +extern atomic_unchecked_t qps_created;
41845 +extern atomic_unchecked_t qps_destroyed;
41846 +extern atomic_unchecked_t sw_qps_destroyed;
41847 extern u32 mh_detected;
41848 extern u32 mh_pauses_sent;
41849 extern u32 cm_packets_sent;
41850 @@ -196,16 +196,16 @@ extern u32 cm_packets_created;
41851 extern u32 cm_packets_received;
41852 extern u32 cm_packets_dropped;
41853 extern u32 cm_packets_retrans;
41854 -extern atomic_t cm_listens_created;
41855 -extern atomic_t cm_listens_destroyed;
41856 +extern atomic_unchecked_t cm_listens_created;
41857 +extern atomic_unchecked_t cm_listens_destroyed;
41858 extern u32 cm_backlog_drops;
41859 -extern atomic_t cm_loopbacks;
41860 -extern atomic_t cm_nodes_created;
41861 -extern atomic_t cm_nodes_destroyed;
41862 -extern atomic_t cm_accel_dropped_pkts;
41863 -extern atomic_t cm_resets_recvd;
41864 -extern atomic_t pau_qps_created;
41865 -extern atomic_t pau_qps_destroyed;
41866 +extern atomic_unchecked_t cm_loopbacks;
41867 +extern atomic_unchecked_t cm_nodes_created;
41868 +extern atomic_unchecked_t cm_nodes_destroyed;
41869 +extern atomic_unchecked_t cm_accel_dropped_pkts;
41870 +extern atomic_unchecked_t cm_resets_recvd;
41871 +extern atomic_unchecked_t pau_qps_created;
41872 +extern atomic_unchecked_t pau_qps_destroyed;
41873
41874 extern u32 int_mod_timer_init;
41875 extern u32 int_mod_cq_depth_256;
41876 diff --git a/drivers/infiniband/hw/nes/nes_cm.c b/drivers/infiniband/hw/nes/nes_cm.c
41877 index 6b29249..461d143 100644
41878 --- a/drivers/infiniband/hw/nes/nes_cm.c
41879 +++ b/drivers/infiniband/hw/nes/nes_cm.c
41880 @@ -68,14 +68,14 @@ u32 cm_packets_dropped;
41881 u32 cm_packets_retrans;
41882 u32 cm_packets_created;
41883 u32 cm_packets_received;
41884 -atomic_t cm_listens_created;
41885 -atomic_t cm_listens_destroyed;
41886 +atomic_unchecked_t cm_listens_created;
41887 +atomic_unchecked_t cm_listens_destroyed;
41888 u32 cm_backlog_drops;
41889 -atomic_t cm_loopbacks;
41890 -atomic_t cm_nodes_created;
41891 -atomic_t cm_nodes_destroyed;
41892 -atomic_t cm_accel_dropped_pkts;
41893 -atomic_t cm_resets_recvd;
41894 +atomic_unchecked_t cm_loopbacks;
41895 +atomic_unchecked_t cm_nodes_created;
41896 +atomic_unchecked_t cm_nodes_destroyed;
41897 +atomic_unchecked_t cm_accel_dropped_pkts;
41898 +atomic_unchecked_t cm_resets_recvd;
41899
41900 static inline int mini_cm_accelerated(struct nes_cm_core *, struct nes_cm_node *);
41901 static struct nes_cm_listener *mini_cm_listen(struct nes_cm_core *, struct nes_vnic *, struct nes_cm_info *);
41902 @@ -133,28 +133,28 @@ static void print_core(struct nes_cm_core *core);
41903 /* instance of function pointers for client API */
41904 /* set address of this instance to cm_core->cm_ops at cm_core alloc */
41905 static struct nes_cm_ops nes_cm_api = {
41906 - mini_cm_accelerated,
41907 - mini_cm_listen,
41908 - mini_cm_del_listen,
41909 - mini_cm_connect,
41910 - mini_cm_close,
41911 - mini_cm_accept,
41912 - mini_cm_reject,
41913 - mini_cm_recv_pkt,
41914 - mini_cm_dealloc_core,
41915 - mini_cm_get,
41916 - mini_cm_set
41917 + .accelerated = mini_cm_accelerated,
41918 + .listen = mini_cm_listen,
41919 + .stop_listener = mini_cm_del_listen,
41920 + .connect = mini_cm_connect,
41921 + .close = mini_cm_close,
41922 + .accept = mini_cm_accept,
41923 + .reject = mini_cm_reject,
41924 + .recv_pkt = mini_cm_recv_pkt,
41925 + .destroy_cm_core = mini_cm_dealloc_core,
41926 + .get = mini_cm_get,
41927 + .set = mini_cm_set
41928 };
41929
41930 static struct nes_cm_core *g_cm_core;
41931
41932 -atomic_t cm_connects;
41933 -atomic_t cm_accepts;
41934 -atomic_t cm_disconnects;
41935 -atomic_t cm_closes;
41936 -atomic_t cm_connecteds;
41937 -atomic_t cm_connect_reqs;
41938 -atomic_t cm_rejects;
41939 +atomic_unchecked_t cm_connects;
41940 +atomic_unchecked_t cm_accepts;
41941 +atomic_unchecked_t cm_disconnects;
41942 +atomic_unchecked_t cm_closes;
41943 +atomic_unchecked_t cm_connecteds;
41944 +atomic_unchecked_t cm_connect_reqs;
41945 +atomic_unchecked_t cm_rejects;
41946
41947 int nes_add_ref_cm_node(struct nes_cm_node *cm_node)
41948 {
41949 @@ -1272,7 +1272,7 @@ static int mini_cm_dec_refcnt_listen(struct nes_cm_core *cm_core,
41950 kfree(listener);
41951 listener = NULL;
41952 ret = 0;
41953 - atomic_inc(&cm_listens_destroyed);
41954 + atomic_inc_unchecked(&cm_listens_destroyed);
41955 } else {
41956 spin_unlock_irqrestore(&cm_core->listen_list_lock, flags);
41957 }
41958 @@ -1466,7 +1466,7 @@ static struct nes_cm_node *make_cm_node(struct nes_cm_core *cm_core,
41959 cm_node->rem_mac);
41960
41961 add_hte_node(cm_core, cm_node);
41962 - atomic_inc(&cm_nodes_created);
41963 + atomic_inc_unchecked(&cm_nodes_created);
41964
41965 return cm_node;
41966 }
41967 @@ -1524,7 +1524,7 @@ static int rem_ref_cm_node(struct nes_cm_core *cm_core,
41968 }
41969
41970 atomic_dec(&cm_core->node_cnt);
41971 - atomic_inc(&cm_nodes_destroyed);
41972 + atomic_inc_unchecked(&cm_nodes_destroyed);
41973 nesqp = cm_node->nesqp;
41974 if (nesqp) {
41975 nesqp->cm_node = NULL;
41976 @@ -1588,7 +1588,7 @@ static int process_options(struct nes_cm_node *cm_node, u8 *optionsloc,
41977
41978 static void drop_packet(struct sk_buff *skb)
41979 {
41980 - atomic_inc(&cm_accel_dropped_pkts);
41981 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
41982 dev_kfree_skb_any(skb);
41983 }
41984
41985 @@ -1651,7 +1651,7 @@ static void handle_rst_pkt(struct nes_cm_node *cm_node, struct sk_buff *skb,
41986 {
41987
41988 int reset = 0; /* whether to send reset in case of err.. */
41989 - atomic_inc(&cm_resets_recvd);
41990 + atomic_inc_unchecked(&cm_resets_recvd);
41991 nes_debug(NES_DBG_CM, "Received Reset, cm_node = %p, state = %u."
41992 " refcnt=%d\n", cm_node, cm_node->state,
41993 atomic_read(&cm_node->ref_count));
41994 @@ -2292,7 +2292,7 @@ static struct nes_cm_node *mini_cm_connect(struct nes_cm_core *cm_core,
41995 rem_ref_cm_node(cm_node->cm_core, cm_node);
41996 return NULL;
41997 }
41998 - atomic_inc(&cm_loopbacks);
41999 + atomic_inc_unchecked(&cm_loopbacks);
42000 loopbackremotenode->loopbackpartner = cm_node;
42001 loopbackremotenode->tcp_cntxt.rcv_wscale =
42002 NES_CM_DEFAULT_RCV_WND_SCALE;
42003 @@ -2567,7 +2567,7 @@ static int mini_cm_recv_pkt(struct nes_cm_core *cm_core,
42004 nes_queue_mgt_skbs(skb, nesvnic, cm_node->nesqp);
42005 else {
42006 rem_ref_cm_node(cm_core, cm_node);
42007 - atomic_inc(&cm_accel_dropped_pkts);
42008 + atomic_inc_unchecked(&cm_accel_dropped_pkts);
42009 dev_kfree_skb_any(skb);
42010 }
42011 break;
42012 @@ -2875,7 +2875,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42013
42014 if ((cm_id) && (cm_id->event_handler)) {
42015 if (issue_disconn) {
42016 - atomic_inc(&cm_disconnects);
42017 + atomic_inc_unchecked(&cm_disconnects);
42018 cm_event.event = IW_CM_EVENT_DISCONNECT;
42019 cm_event.status = disconn_status;
42020 cm_event.local_addr = cm_id->local_addr;
42021 @@ -2897,7 +2897,7 @@ static int nes_cm_disconn_true(struct nes_qp *nesqp)
42022 }
42023
42024 if (issue_close) {
42025 - atomic_inc(&cm_closes);
42026 + atomic_inc_unchecked(&cm_closes);
42027 nes_disconnect(nesqp, 1);
42028
42029 cm_id->provider_data = nesqp;
42030 @@ -3035,7 +3035,7 @@ int nes_accept(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42031
42032 nes_debug(NES_DBG_CM, "QP%u, cm_node=%p, jiffies = %lu listener = %p\n",
42033 nesqp->hwqp.qp_id, cm_node, jiffies, cm_node->listener);
42034 - atomic_inc(&cm_accepts);
42035 + atomic_inc_unchecked(&cm_accepts);
42036
42037 nes_debug(NES_DBG_CM, "netdev refcnt = %u.\n",
42038 netdev_refcnt_read(nesvnic->netdev));
42039 @@ -3224,7 +3224,7 @@ int nes_reject(struct iw_cm_id *cm_id, const void *pdata, u8 pdata_len)
42040 struct nes_cm_core *cm_core;
42041 u8 *start_buff;
42042
42043 - atomic_inc(&cm_rejects);
42044 + atomic_inc_unchecked(&cm_rejects);
42045 cm_node = (struct nes_cm_node *)cm_id->provider_data;
42046 loopback = cm_node->loopbackpartner;
42047 cm_core = cm_node->cm_core;
42048 @@ -3286,7 +3286,7 @@ int nes_connect(struct iw_cm_id *cm_id, struct iw_cm_conn_param *conn_param)
42049 ntohs(raddr->sin_port), ntohl(laddr->sin_addr.s_addr),
42050 ntohs(laddr->sin_port));
42051
42052 - atomic_inc(&cm_connects);
42053 + atomic_inc_unchecked(&cm_connects);
42054 nesqp->active_conn = 1;
42055
42056 /* cache the cm_id in the qp */
42057 @@ -3398,7 +3398,7 @@ int nes_create_listen(struct iw_cm_id *cm_id, int backlog)
42058 g_cm_core->api->stop_listener(g_cm_core, (void *)cm_node);
42059 return err;
42060 }
42061 - atomic_inc(&cm_listens_created);
42062 + atomic_inc_unchecked(&cm_listens_created);
42063 }
42064
42065 cm_id->add_ref(cm_id);
42066 @@ -3505,7 +3505,7 @@ static void cm_event_connected(struct nes_cm_event *event)
42067
42068 if (nesqp->destroyed)
42069 return;
42070 - atomic_inc(&cm_connecteds);
42071 + atomic_inc_unchecked(&cm_connecteds);
42072 nes_debug(NES_DBG_CM, "QP%u attempting to connect to 0x%08X:0x%04X on"
42073 " local port 0x%04X. jiffies = %lu.\n",
42074 nesqp->hwqp.qp_id, ntohl(raddr->sin_addr.s_addr),
42075 @@ -3686,7 +3686,7 @@ static void cm_event_reset(struct nes_cm_event *event)
42076
42077 cm_id->add_ref(cm_id);
42078 ret = cm_id->event_handler(cm_id, &cm_event);
42079 - atomic_inc(&cm_closes);
42080 + atomic_inc_unchecked(&cm_closes);
42081 cm_event.event = IW_CM_EVENT_CLOSE;
42082 cm_event.status = 0;
42083 cm_event.provider_data = cm_id->provider_data;
42084 @@ -3726,7 +3726,7 @@ static void cm_event_mpa_req(struct nes_cm_event *event)
42085 return;
42086 cm_id = cm_node->cm_id;
42087
42088 - atomic_inc(&cm_connect_reqs);
42089 + atomic_inc_unchecked(&cm_connect_reqs);
42090 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42091 cm_node, cm_id, jiffies);
42092
42093 @@ -3770,7 +3770,7 @@ static void cm_event_mpa_reject(struct nes_cm_event *event)
42094 return;
42095 cm_id = cm_node->cm_id;
42096
42097 - atomic_inc(&cm_connect_reqs);
42098 + atomic_inc_unchecked(&cm_connect_reqs);
42099 nes_debug(NES_DBG_CM, "cm_node = %p - cm_id = %p, jiffies = %lu\n",
42100 cm_node, cm_id, jiffies);
42101
42102 diff --git a/drivers/infiniband/hw/nes/nes_mgt.c b/drivers/infiniband/hw/nes/nes_mgt.c
42103 index 4166452..fc952c3 100644
42104 --- a/drivers/infiniband/hw/nes/nes_mgt.c
42105 +++ b/drivers/infiniband/hw/nes/nes_mgt.c
42106 @@ -40,8 +40,8 @@
42107 #include "nes.h"
42108 #include "nes_mgt.h"
42109
42110 -atomic_t pau_qps_created;
42111 -atomic_t pau_qps_destroyed;
42112 +atomic_unchecked_t pau_qps_created;
42113 +atomic_unchecked_t pau_qps_destroyed;
42114
42115 static void nes_replenish_mgt_rq(struct nes_vnic_mgt *mgtvnic)
42116 {
42117 @@ -621,7 +621,7 @@ void nes_destroy_pau_qp(struct nes_device *nesdev, struct nes_qp *nesqp)
42118 {
42119 struct sk_buff *skb;
42120 unsigned long flags;
42121 - atomic_inc(&pau_qps_destroyed);
42122 + atomic_inc_unchecked(&pau_qps_destroyed);
42123
42124 /* Free packets that have not yet been forwarded */
42125 /* Lock is acquired by skb_dequeue when removing the skb */
42126 @@ -810,7 +810,7 @@ static void nes_mgt_ce_handler(struct nes_device *nesdev, struct nes_hw_nic_cq *
42127 cq->cq_vbase[head].cqe_words[NES_NIC_CQE_HASH_RCVNXT]);
42128 skb_queue_head_init(&nesqp->pau_list);
42129 spin_lock_init(&nesqp->pau_lock);
42130 - atomic_inc(&pau_qps_created);
42131 + atomic_inc_unchecked(&pau_qps_created);
42132 nes_change_quad_hash(nesdev, mgtvnic->nesvnic, nesqp);
42133 }
42134
42135 diff --git a/drivers/infiniband/hw/nes/nes_nic.c b/drivers/infiniband/hw/nes/nes_nic.c
42136 index 49eb511..a774366 100644
42137 --- a/drivers/infiniband/hw/nes/nes_nic.c
42138 +++ b/drivers/infiniband/hw/nes/nes_nic.c
42139 @@ -1273,39 +1273,39 @@ static void nes_netdev_get_ethtool_stats(struct net_device *netdev,
42140 target_stat_values[++index] = mh_detected;
42141 target_stat_values[++index] = mh_pauses_sent;
42142 target_stat_values[++index] = nesvnic->endnode_ipv4_tcp_retransmits;
42143 - target_stat_values[++index] = atomic_read(&cm_connects);
42144 - target_stat_values[++index] = atomic_read(&cm_accepts);
42145 - target_stat_values[++index] = atomic_read(&cm_disconnects);
42146 - target_stat_values[++index] = atomic_read(&cm_connecteds);
42147 - target_stat_values[++index] = atomic_read(&cm_connect_reqs);
42148 - target_stat_values[++index] = atomic_read(&cm_rejects);
42149 - target_stat_values[++index] = atomic_read(&mod_qp_timouts);
42150 - target_stat_values[++index] = atomic_read(&qps_created);
42151 - target_stat_values[++index] = atomic_read(&sw_qps_destroyed);
42152 - target_stat_values[++index] = atomic_read(&qps_destroyed);
42153 - target_stat_values[++index] = atomic_read(&cm_closes);
42154 + target_stat_values[++index] = atomic_read_unchecked(&cm_connects);
42155 + target_stat_values[++index] = atomic_read_unchecked(&cm_accepts);
42156 + target_stat_values[++index] = atomic_read_unchecked(&cm_disconnects);
42157 + target_stat_values[++index] = atomic_read_unchecked(&cm_connecteds);
42158 + target_stat_values[++index] = atomic_read_unchecked(&cm_connect_reqs);
42159 + target_stat_values[++index] = atomic_read_unchecked(&cm_rejects);
42160 + target_stat_values[++index] = atomic_read_unchecked(&mod_qp_timouts);
42161 + target_stat_values[++index] = atomic_read_unchecked(&qps_created);
42162 + target_stat_values[++index] = atomic_read_unchecked(&sw_qps_destroyed);
42163 + target_stat_values[++index] = atomic_read_unchecked(&qps_destroyed);
42164 + target_stat_values[++index] = atomic_read_unchecked(&cm_closes);
42165 target_stat_values[++index] = cm_packets_sent;
42166 target_stat_values[++index] = cm_packets_bounced;
42167 target_stat_values[++index] = cm_packets_created;
42168 target_stat_values[++index] = cm_packets_received;
42169 target_stat_values[++index] = cm_packets_dropped;
42170 target_stat_values[++index] = cm_packets_retrans;
42171 - target_stat_values[++index] = atomic_read(&cm_listens_created);
42172 - target_stat_values[++index] = atomic_read(&cm_listens_destroyed);
42173 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_created);
42174 + target_stat_values[++index] = atomic_read_unchecked(&cm_listens_destroyed);
42175 target_stat_values[++index] = cm_backlog_drops;
42176 - target_stat_values[++index] = atomic_read(&cm_loopbacks);
42177 - target_stat_values[++index] = atomic_read(&cm_nodes_created);
42178 - target_stat_values[++index] = atomic_read(&cm_nodes_destroyed);
42179 - target_stat_values[++index] = atomic_read(&cm_accel_dropped_pkts);
42180 - target_stat_values[++index] = atomic_read(&cm_resets_recvd);
42181 + target_stat_values[++index] = atomic_read_unchecked(&cm_loopbacks);
42182 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_created);
42183 + target_stat_values[++index] = atomic_read_unchecked(&cm_nodes_destroyed);
42184 + target_stat_values[++index] = atomic_read_unchecked(&cm_accel_dropped_pkts);
42185 + target_stat_values[++index] = atomic_read_unchecked(&cm_resets_recvd);
42186 target_stat_values[++index] = nesadapter->free_4kpbl;
42187 target_stat_values[++index] = nesadapter->free_256pbl;
42188 target_stat_values[++index] = int_mod_timer_init;
42189 target_stat_values[++index] = nesvnic->lro_mgr.stats.aggregated;
42190 target_stat_values[++index] = nesvnic->lro_mgr.stats.flushed;
42191 target_stat_values[++index] = nesvnic->lro_mgr.stats.no_desc;
42192 - target_stat_values[++index] = atomic_read(&pau_qps_created);
42193 - target_stat_values[++index] = atomic_read(&pau_qps_destroyed);
42194 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_created);
42195 + target_stat_values[++index] = atomic_read_unchecked(&pau_qps_destroyed);
42196 }
42197
42198 /**
42199 diff --git a/drivers/infiniband/hw/nes/nes_verbs.c b/drivers/infiniband/hw/nes/nes_verbs.c
42200 index 8308e36..ae0d3b5 100644
42201 --- a/drivers/infiniband/hw/nes/nes_verbs.c
42202 +++ b/drivers/infiniband/hw/nes/nes_verbs.c
42203 @@ -46,9 +46,9 @@
42204
42205 #include <rdma/ib_umem.h>
42206
42207 -atomic_t mod_qp_timouts;
42208 -atomic_t qps_created;
42209 -atomic_t sw_qps_destroyed;
42210 +atomic_unchecked_t mod_qp_timouts;
42211 +atomic_unchecked_t qps_created;
42212 +atomic_unchecked_t sw_qps_destroyed;
42213
42214 static void nes_unregister_ofa_device(struct nes_ib_device *nesibdev);
42215
42216 @@ -1134,7 +1134,7 @@ static struct ib_qp *nes_create_qp(struct ib_pd *ibpd,
42217 if (init_attr->create_flags)
42218 return ERR_PTR(-EINVAL);
42219
42220 - atomic_inc(&qps_created);
42221 + atomic_inc_unchecked(&qps_created);
42222 switch (init_attr->qp_type) {
42223 case IB_QPT_RC:
42224 if (nes_drv_opt & NES_DRV_OPT_NO_INLINE_DATA) {
42225 @@ -1466,7 +1466,7 @@ static int nes_destroy_qp(struct ib_qp *ibqp)
42226 struct iw_cm_event cm_event;
42227 int ret = 0;
42228
42229 - atomic_inc(&sw_qps_destroyed);
42230 + atomic_inc_unchecked(&sw_qps_destroyed);
42231 nesqp->destroyed = 1;
42232
42233 /* Blow away the connection if it exists. */
42234 diff --git a/drivers/infiniband/hw/qib/qib.h b/drivers/infiniband/hw/qib/qib.h
42235 index 1946101..09766d2 100644
42236 --- a/drivers/infiniband/hw/qib/qib.h
42237 +++ b/drivers/infiniband/hw/qib/qib.h
42238 @@ -52,6 +52,7 @@
42239 #include <linux/kref.h>
42240 #include <linux/sched.h>
42241 #include <linux/kthread.h>
42242 +#include <linux/slab.h>
42243
42244 #include "qib_common.h"
42245 #include "qib_verbs.h"
42246 diff --git a/drivers/input/gameport/gameport.c b/drivers/input/gameport/gameport.c
42247 index 24c41ba..102d71f 100644
42248 --- a/drivers/input/gameport/gameport.c
42249 +++ b/drivers/input/gameport/gameport.c
42250 @@ -490,14 +490,14 @@ EXPORT_SYMBOL(gameport_set_phys);
42251 */
42252 static void gameport_init_port(struct gameport *gameport)
42253 {
42254 - static atomic_t gameport_no = ATOMIC_INIT(0);
42255 + static atomic_unchecked_t gameport_no = ATOMIC_INIT(0);
42256
42257 __module_get(THIS_MODULE);
42258
42259 mutex_init(&gameport->drv_mutex);
42260 device_initialize(&gameport->dev);
42261 dev_set_name(&gameport->dev, "gameport%lu",
42262 - (unsigned long)atomic_inc_return(&gameport_no) - 1);
42263 + (unsigned long)atomic_inc_return_unchecked(&gameport_no) - 1);
42264 gameport->dev.bus = &gameport_bus;
42265 gameport->dev.release = gameport_release_port;
42266 if (gameport->parent)
42267 diff --git a/drivers/input/input.c b/drivers/input/input.c
42268 index d2965e4..f52b7d7 100644
42269 --- a/drivers/input/input.c
42270 +++ b/drivers/input/input.c
42271 @@ -1734,7 +1734,7 @@ EXPORT_SYMBOL_GPL(input_class);
42272 */
42273 struct input_dev *input_allocate_device(void)
42274 {
42275 - static atomic_t input_no = ATOMIC_INIT(0);
42276 + static atomic_unchecked_t input_no = ATOMIC_INIT(0);
42277 struct input_dev *dev;
42278
42279 dev = kzalloc(sizeof(struct input_dev), GFP_KERNEL);
42280 @@ -1749,7 +1749,7 @@ struct input_dev *input_allocate_device(void)
42281 INIT_LIST_HEAD(&dev->node);
42282
42283 dev_set_name(&dev->dev, "input%ld",
42284 - (unsigned long) atomic_inc_return(&input_no) - 1);
42285 + (unsigned long) atomic_inc_return_unchecked(&input_no) - 1);
42286
42287 __module_get(THIS_MODULE);
42288 }
42289 diff --git a/drivers/input/joystick/sidewinder.c b/drivers/input/joystick/sidewinder.c
42290 index 04c69af..5f92d00 100644
42291 --- a/drivers/input/joystick/sidewinder.c
42292 +++ b/drivers/input/joystick/sidewinder.c
42293 @@ -30,6 +30,7 @@
42294 #include <linux/kernel.h>
42295 #include <linux/module.h>
42296 #include <linux/slab.h>
42297 +#include <linux/sched.h>
42298 #include <linux/init.h>
42299 #include <linux/input.h>
42300 #include <linux/gameport.h>
42301 diff --git a/drivers/input/joystick/xpad.c b/drivers/input/joystick/xpad.c
42302 index 75e3b10..fb390fd 100644
42303 --- a/drivers/input/joystick/xpad.c
42304 +++ b/drivers/input/joystick/xpad.c
42305 @@ -736,7 +736,7 @@ static void xpad_led_set(struct led_classdev *led_cdev,
42306
42307 static int xpad_led_probe(struct usb_xpad *xpad)
42308 {
42309 - static atomic_t led_seq = ATOMIC_INIT(0);
42310 + static atomic_unchecked_t led_seq = ATOMIC_INIT(0);
42311 long led_no;
42312 struct xpad_led *led;
42313 struct led_classdev *led_cdev;
42314 @@ -749,7 +749,7 @@ static int xpad_led_probe(struct usb_xpad *xpad)
42315 if (!led)
42316 return -ENOMEM;
42317
42318 - led_no = (long)atomic_inc_return(&led_seq) - 1;
42319 + led_no = (long)atomic_inc_return_unchecked(&led_seq) - 1;
42320
42321 snprintf(led->name, sizeof(led->name), "xpad%ld", led_no);
42322 led->xpad = xpad;
42323 diff --git a/drivers/input/misc/ims-pcu.c b/drivers/input/misc/ims-pcu.c
42324 index e204f26..8459f15 100644
42325 --- a/drivers/input/misc/ims-pcu.c
42326 +++ b/drivers/input/misc/ims-pcu.c
42327 @@ -1621,7 +1621,7 @@ static int ims_pcu_identify_type(struct ims_pcu *pcu, u8 *device_id)
42328
42329 static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42330 {
42331 - static atomic_t device_no = ATOMIC_INIT(0);
42332 + static atomic_unchecked_t device_no = ATOMIC_INIT(0);
42333
42334 const struct ims_pcu_device_info *info;
42335 u8 device_id;
42336 @@ -1653,7 +1653,7 @@ static int ims_pcu_init_application_mode(struct ims_pcu *pcu)
42337 }
42338
42339 /* Device appears to be operable, complete initialization */
42340 - pcu->device_no = atomic_inc_return(&device_no) - 1;
42341 + pcu->device_no = atomic_inc_return_unchecked(&device_no) - 1;
42342
42343 error = ims_pcu_setup_backlight(pcu);
42344 if (error)
42345 diff --git a/drivers/input/mouse/psmouse.h b/drivers/input/mouse/psmouse.h
42346 index 2f0b39d..7370f13 100644
42347 --- a/drivers/input/mouse/psmouse.h
42348 +++ b/drivers/input/mouse/psmouse.h
42349 @@ -116,7 +116,7 @@ struct psmouse_attribute {
42350 ssize_t (*set)(struct psmouse *psmouse, void *data,
42351 const char *buf, size_t count);
42352 bool protect;
42353 -};
42354 +} __do_const;
42355 #define to_psmouse_attr(a) container_of((a), struct psmouse_attribute, dattr)
42356
42357 ssize_t psmouse_attr_show_helper(struct device *dev, struct device_attribute *attr,
42358 diff --git a/drivers/input/mousedev.c b/drivers/input/mousedev.c
42359 index 4c842c3..590b0bf 100644
42360 --- a/drivers/input/mousedev.c
42361 +++ b/drivers/input/mousedev.c
42362 @@ -738,7 +738,7 @@ static ssize_t mousedev_read(struct file *file, char __user *buffer,
42363
42364 spin_unlock_irq(&client->packet_lock);
42365
42366 - if (copy_to_user(buffer, data, count))
42367 + if (count > sizeof(data) || copy_to_user(buffer, data, count))
42368 return -EFAULT;
42369
42370 return count;
42371 diff --git a/drivers/input/serio/serio.c b/drivers/input/serio/serio.c
42372 index 8f4c4ab..5fc8a45 100644
42373 --- a/drivers/input/serio/serio.c
42374 +++ b/drivers/input/serio/serio.c
42375 @@ -505,7 +505,7 @@ static void serio_release_port(struct device *dev)
42376 */
42377 static void serio_init_port(struct serio *serio)
42378 {
42379 - static atomic_t serio_no = ATOMIC_INIT(0);
42380 + static atomic_unchecked_t serio_no = ATOMIC_INIT(0);
42381
42382 __module_get(THIS_MODULE);
42383
42384 @@ -516,7 +516,7 @@ static void serio_init_port(struct serio *serio)
42385 mutex_init(&serio->drv_mutex);
42386 device_initialize(&serio->dev);
42387 dev_set_name(&serio->dev, "serio%ld",
42388 - (long)atomic_inc_return(&serio_no) - 1);
42389 + (long)atomic_inc_return_unchecked(&serio_no) - 1);
42390 serio->dev.bus = &serio_bus;
42391 serio->dev.release = serio_release_port;
42392 serio->dev.groups = serio_device_attr_groups;
42393 diff --git a/drivers/input/serio/serio_raw.c b/drivers/input/serio/serio_raw.c
42394 index 59df2e7..8f1cafb 100644
42395 --- a/drivers/input/serio/serio_raw.c
42396 +++ b/drivers/input/serio/serio_raw.c
42397 @@ -293,7 +293,7 @@ static irqreturn_t serio_raw_interrupt(struct serio *serio, unsigned char data,
42398
42399 static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42400 {
42401 - static atomic_t serio_raw_no = ATOMIC_INIT(0);
42402 + static atomic_unchecked_t serio_raw_no = ATOMIC_INIT(0);
42403 struct serio_raw *serio_raw;
42404 int err;
42405
42406 @@ -304,7 +304,7 @@ static int serio_raw_connect(struct serio *serio, struct serio_driver *drv)
42407 }
42408
42409 snprintf(serio_raw->name, sizeof(serio_raw->name),
42410 - "serio_raw%ld", (long)atomic_inc_return(&serio_raw_no) - 1);
42411 + "serio_raw%ld", (long)atomic_inc_return_unchecked(&serio_raw_no) - 1);
42412 kref_init(&serio_raw->kref);
42413 INIT_LIST_HEAD(&serio_raw->client_list);
42414 init_waitqueue_head(&serio_raw->wait);
42415 diff --git a/drivers/iommu/iommu.c b/drivers/iommu/iommu.c
42416 index e5555fc..937986d 100644
42417 --- a/drivers/iommu/iommu.c
42418 +++ b/drivers/iommu/iommu.c
42419 @@ -588,7 +588,7 @@ static struct notifier_block iommu_bus_nb = {
42420 static void iommu_bus_init(struct bus_type *bus, struct iommu_ops *ops)
42421 {
42422 bus_register_notifier(bus, &iommu_bus_nb);
42423 - bus_for_each_dev(bus, NULL, ops, add_iommu_group);
42424 + bus_for_each_dev(bus, NULL, (void *)ops, add_iommu_group);
42425 }
42426
42427 /**
42428 diff --git a/drivers/iommu/irq_remapping.c b/drivers/iommu/irq_remapping.c
42429 index 39f81ae..2660096 100644
42430 --- a/drivers/iommu/irq_remapping.c
42431 +++ b/drivers/iommu/irq_remapping.c
42432 @@ -356,7 +356,7 @@ int setup_hpet_msi_remapped(unsigned int irq, unsigned int id)
42433 void panic_if_irq_remap(const char *msg)
42434 {
42435 if (irq_remapping_enabled)
42436 - panic(msg);
42437 + panic("%s", msg);
42438 }
42439
42440 static void ir_ack_apic_edge(struct irq_data *data)
42441 @@ -377,10 +377,12 @@ static void ir_print_prefix(struct irq_data *data, struct seq_file *p)
42442
42443 void irq_remap_modify_chip_defaults(struct irq_chip *chip)
42444 {
42445 - chip->irq_print_chip = ir_print_prefix;
42446 - chip->irq_ack = ir_ack_apic_edge;
42447 - chip->irq_eoi = ir_ack_apic_level;
42448 - chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
42449 + pax_open_kernel();
42450 + *(void **)&chip->irq_print_chip = ir_print_prefix;
42451 + *(void **)&chip->irq_ack = ir_ack_apic_edge;
42452 + *(void **)&chip->irq_eoi = ir_ack_apic_level;
42453 + *(void **)&chip->irq_set_affinity = x86_io_apic_ops.set_affinity;
42454 + pax_close_kernel();
42455 }
42456
42457 bool setup_remapped_irq(int irq, struct irq_cfg *cfg, struct irq_chip *chip)
42458 diff --git a/drivers/irqchip/irq-gic.c b/drivers/irqchip/irq-gic.c
42459 index 341c601..e5f407e 100644
42460 --- a/drivers/irqchip/irq-gic.c
42461 +++ b/drivers/irqchip/irq-gic.c
42462 @@ -84,7 +84,7 @@ static u8 gic_cpu_map[NR_GIC_CPU_IF] __read_mostly;
42463 * Supported arch specific GIC irq extension.
42464 * Default make them NULL.
42465 */
42466 -struct irq_chip gic_arch_extn = {
42467 +irq_chip_no_const gic_arch_extn = {
42468 .irq_eoi = NULL,
42469 .irq_mask = NULL,
42470 .irq_unmask = NULL,
42471 @@ -332,7 +332,7 @@ static void gic_handle_cascade_irq(unsigned int irq, struct irq_desc *desc)
42472 chained_irq_exit(chip, desc);
42473 }
42474
42475 -static struct irq_chip gic_chip = {
42476 +static irq_chip_no_const gic_chip __read_only = {
42477 .name = "GIC",
42478 .irq_mask = gic_mask_irq,
42479 .irq_unmask = gic_unmask_irq,
42480 diff --git a/drivers/isdn/capi/capi.c b/drivers/isdn/capi/capi.c
42481 index ac6f72b..81150f2 100644
42482 --- a/drivers/isdn/capi/capi.c
42483 +++ b/drivers/isdn/capi/capi.c
42484 @@ -81,8 +81,8 @@ struct capiminor {
42485
42486 struct capi20_appl *ap;
42487 u32 ncci;
42488 - atomic_t datahandle;
42489 - atomic_t msgid;
42490 + atomic_unchecked_t datahandle;
42491 + atomic_unchecked_t msgid;
42492
42493 struct tty_port port;
42494 int ttyinstop;
42495 @@ -391,7 +391,7 @@ gen_data_b3_resp_for(struct capiminor *mp, struct sk_buff *skb)
42496 capimsg_setu16(s, 2, mp->ap->applid);
42497 capimsg_setu8 (s, 4, CAPI_DATA_B3);
42498 capimsg_setu8 (s, 5, CAPI_RESP);
42499 - capimsg_setu16(s, 6, atomic_inc_return(&mp->msgid));
42500 + capimsg_setu16(s, 6, atomic_inc_return_unchecked(&mp->msgid));
42501 capimsg_setu32(s, 8, mp->ncci);
42502 capimsg_setu16(s, 12, datahandle);
42503 }
42504 @@ -512,14 +512,14 @@ static void handle_minor_send(struct capiminor *mp)
42505 mp->outbytes -= len;
42506 spin_unlock_bh(&mp->outlock);
42507
42508 - datahandle = atomic_inc_return(&mp->datahandle);
42509 + datahandle = atomic_inc_return_unchecked(&mp->datahandle);
42510 skb_push(skb, CAPI_DATA_B3_REQ_LEN);
42511 memset(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
42512 capimsg_setu16(skb->data, 0, CAPI_DATA_B3_REQ_LEN);
42513 capimsg_setu16(skb->data, 2, mp->ap->applid);
42514 capimsg_setu8 (skb->data, 4, CAPI_DATA_B3);
42515 capimsg_setu8 (skb->data, 5, CAPI_REQ);
42516 - capimsg_setu16(skb->data, 6, atomic_inc_return(&mp->msgid));
42517 + capimsg_setu16(skb->data, 6, atomic_inc_return_unchecked(&mp->msgid));
42518 capimsg_setu32(skb->data, 8, mp->ncci); /* NCCI */
42519 capimsg_setu32(skb->data, 12, (u32)(long)skb->data);/* Data32 */
42520 capimsg_setu16(skb->data, 16, len); /* Data length */
42521 diff --git a/drivers/isdn/gigaset/bas-gigaset.c b/drivers/isdn/gigaset/bas-gigaset.c
42522 index c44950d..10ac276 100644
42523 --- a/drivers/isdn/gigaset/bas-gigaset.c
42524 +++ b/drivers/isdn/gigaset/bas-gigaset.c
42525 @@ -2564,22 +2564,22 @@ static int gigaset_post_reset(struct usb_interface *intf)
42526
42527
42528 static const struct gigaset_ops gigops = {
42529 - gigaset_write_cmd,
42530 - gigaset_write_room,
42531 - gigaset_chars_in_buffer,
42532 - gigaset_brkchars,
42533 - gigaset_init_bchannel,
42534 - gigaset_close_bchannel,
42535 - gigaset_initbcshw,
42536 - gigaset_freebcshw,
42537 - gigaset_reinitbcshw,
42538 - gigaset_initcshw,
42539 - gigaset_freecshw,
42540 - gigaset_set_modem_ctrl,
42541 - gigaset_baud_rate,
42542 - gigaset_set_line_ctrl,
42543 - gigaset_isoc_send_skb,
42544 - gigaset_isoc_input,
42545 + .write_cmd = gigaset_write_cmd,
42546 + .write_room = gigaset_write_room,
42547 + .chars_in_buffer = gigaset_chars_in_buffer,
42548 + .brkchars = gigaset_brkchars,
42549 + .init_bchannel = gigaset_init_bchannel,
42550 + .close_bchannel = gigaset_close_bchannel,
42551 + .initbcshw = gigaset_initbcshw,
42552 + .freebcshw = gigaset_freebcshw,
42553 + .reinitbcshw = gigaset_reinitbcshw,
42554 + .initcshw = gigaset_initcshw,
42555 + .freecshw = gigaset_freecshw,
42556 + .set_modem_ctrl = gigaset_set_modem_ctrl,
42557 + .baud_rate = gigaset_baud_rate,
42558 + .set_line_ctrl = gigaset_set_line_ctrl,
42559 + .send_skb = gigaset_isoc_send_skb,
42560 + .handle_input = gigaset_isoc_input,
42561 };
42562
42563 /* bas_gigaset_init
42564 diff --git a/drivers/isdn/gigaset/interface.c b/drivers/isdn/gigaset/interface.c
42565 index 600c79b..3752bab 100644
42566 --- a/drivers/isdn/gigaset/interface.c
42567 +++ b/drivers/isdn/gigaset/interface.c
42568 @@ -130,9 +130,9 @@ static int if_open(struct tty_struct *tty, struct file *filp)
42569 }
42570 tty->driver_data = cs;
42571
42572 - ++cs->port.count;
42573 + atomic_inc(&cs->port.count);
42574
42575 - if (cs->port.count == 1) {
42576 + if (atomic_read(&cs->port.count) == 1) {
42577 tty_port_tty_set(&cs->port, tty);
42578 cs->port.low_latency = 1;
42579 }
42580 @@ -156,9 +156,9 @@ static void if_close(struct tty_struct *tty, struct file *filp)
42581
42582 if (!cs->connected)
42583 gig_dbg(DEBUG_IF, "not connected"); /* nothing to do */
42584 - else if (!cs->port.count)
42585 + else if (!atomic_read(&cs->port.count))
42586 dev_warn(cs->dev, "%s: device not opened\n", __func__);
42587 - else if (!--cs->port.count)
42588 + else if (!atomic_dec_return(&cs->port.count))
42589 tty_port_tty_set(&cs->port, NULL);
42590
42591 mutex_unlock(&cs->mutex);
42592 diff --git a/drivers/isdn/gigaset/ser-gigaset.c b/drivers/isdn/gigaset/ser-gigaset.c
42593 index 8c91fd5..14f13ce 100644
42594 --- a/drivers/isdn/gigaset/ser-gigaset.c
42595 +++ b/drivers/isdn/gigaset/ser-gigaset.c
42596 @@ -453,22 +453,22 @@ static int gigaset_set_line_ctrl(struct cardstate *cs, unsigned cflag)
42597 }
42598
42599 static const struct gigaset_ops ops = {
42600 - gigaset_write_cmd,
42601 - gigaset_write_room,
42602 - gigaset_chars_in_buffer,
42603 - gigaset_brkchars,
42604 - gigaset_init_bchannel,
42605 - gigaset_close_bchannel,
42606 - gigaset_initbcshw,
42607 - gigaset_freebcshw,
42608 - gigaset_reinitbcshw,
42609 - gigaset_initcshw,
42610 - gigaset_freecshw,
42611 - gigaset_set_modem_ctrl,
42612 - gigaset_baud_rate,
42613 - gigaset_set_line_ctrl,
42614 - gigaset_m10x_send_skb, /* asyncdata.c */
42615 - gigaset_m10x_input, /* asyncdata.c */
42616 + .write_cmd = gigaset_write_cmd,
42617 + .write_room = gigaset_write_room,
42618 + .chars_in_buffer = gigaset_chars_in_buffer,
42619 + .brkchars = gigaset_brkchars,
42620 + .init_bchannel = gigaset_init_bchannel,
42621 + .close_bchannel = gigaset_close_bchannel,
42622 + .initbcshw = gigaset_initbcshw,
42623 + .freebcshw = gigaset_freebcshw,
42624 + .reinitbcshw = gigaset_reinitbcshw,
42625 + .initcshw = gigaset_initcshw,
42626 + .freecshw = gigaset_freecshw,
42627 + .set_modem_ctrl = gigaset_set_modem_ctrl,
42628 + .baud_rate = gigaset_baud_rate,
42629 + .set_line_ctrl = gigaset_set_line_ctrl,
42630 + .send_skb = gigaset_m10x_send_skb, /* asyncdata.c */
42631 + .handle_input = gigaset_m10x_input, /* asyncdata.c */
42632 };
42633
42634
42635 diff --git a/drivers/isdn/gigaset/usb-gigaset.c b/drivers/isdn/gigaset/usb-gigaset.c
42636 index d0a41cb..b953e50 100644
42637 --- a/drivers/isdn/gigaset/usb-gigaset.c
42638 +++ b/drivers/isdn/gigaset/usb-gigaset.c
42639 @@ -547,7 +547,7 @@ static int gigaset_brkchars(struct cardstate *cs, const unsigned char buf[6])
42640 gigaset_dbg_buffer(DEBUG_USBREQ, "brkchars", 6, buf);
42641 memcpy(cs->hw.usb->bchars, buf, 6);
42642 return usb_control_msg(udev, usb_sndctrlpipe(udev, 0), 0x19, 0x41,
42643 - 0, 0, &buf, 6, 2000);
42644 + 0, 0, buf, 6, 2000);
42645 }
42646
42647 static void gigaset_freebcshw(struct bc_state *bcs)
42648 @@ -869,22 +869,22 @@ static int gigaset_pre_reset(struct usb_interface *intf)
42649 }
42650
42651 static const struct gigaset_ops ops = {
42652 - gigaset_write_cmd,
42653 - gigaset_write_room,
42654 - gigaset_chars_in_buffer,
42655 - gigaset_brkchars,
42656 - gigaset_init_bchannel,
42657 - gigaset_close_bchannel,
42658 - gigaset_initbcshw,
42659 - gigaset_freebcshw,
42660 - gigaset_reinitbcshw,
42661 - gigaset_initcshw,
42662 - gigaset_freecshw,
42663 - gigaset_set_modem_ctrl,
42664 - gigaset_baud_rate,
42665 - gigaset_set_line_ctrl,
42666 - gigaset_m10x_send_skb,
42667 - gigaset_m10x_input,
42668 + .write_cmd = gigaset_write_cmd,
42669 + .write_room = gigaset_write_room,
42670 + .chars_in_buffer = gigaset_chars_in_buffer,
42671 + .brkchars = gigaset_brkchars,
42672 + .init_bchannel = gigaset_init_bchannel,
42673 + .close_bchannel = gigaset_close_bchannel,
42674 + .initbcshw = gigaset_initbcshw,
42675 + .freebcshw = gigaset_freebcshw,
42676 + .reinitbcshw = gigaset_reinitbcshw,
42677 + .initcshw = gigaset_initcshw,
42678 + .freecshw = gigaset_freecshw,
42679 + .set_modem_ctrl = gigaset_set_modem_ctrl,
42680 + .baud_rate = gigaset_baud_rate,
42681 + .set_line_ctrl = gigaset_set_line_ctrl,
42682 + .send_skb = gigaset_m10x_send_skb,
42683 + .handle_input = gigaset_m10x_input,
42684 };
42685
42686 /*
42687 diff --git a/drivers/isdn/hardware/avm/b1.c b/drivers/isdn/hardware/avm/b1.c
42688 index 4d9b195..455075c 100644
42689 --- a/drivers/isdn/hardware/avm/b1.c
42690 +++ b/drivers/isdn/hardware/avm/b1.c
42691 @@ -176,7 +176,7 @@ int b1_load_t4file(avmcard *card, capiloaddatapart *t4file)
42692 }
42693 if (left) {
42694 if (t4file->user) {
42695 - if (copy_from_user(buf, dp, left))
42696 + if (left > sizeof buf || copy_from_user(buf, dp, left))
42697 return -EFAULT;
42698 } else {
42699 memcpy(buf, dp, left);
42700 @@ -224,7 +224,7 @@ int b1_load_config(avmcard *card, capiloaddatapart *config)
42701 }
42702 if (left) {
42703 if (config->user) {
42704 - if (copy_from_user(buf, dp, left))
42705 + if (left > sizeof buf || copy_from_user(buf, dp, left))
42706 return -EFAULT;
42707 } else {
42708 memcpy(buf, dp, left);
42709 diff --git a/drivers/isdn/i4l/isdn_common.c b/drivers/isdn/i4l/isdn_common.c
42710 index 9bb12ba..d4262f7 100644
42711 --- a/drivers/isdn/i4l/isdn_common.c
42712 +++ b/drivers/isdn/i4l/isdn_common.c
42713 @@ -1651,6 +1651,8 @@ isdn_ioctl(struct file *file, uint cmd, ulong arg)
42714 } else
42715 return -EINVAL;
42716 case IIOCDBGVAR:
42717 + if (!capable(CAP_SYS_RAWIO))
42718 + return -EPERM;
42719 if (arg) {
42720 if (copy_to_user(argp, &dev, sizeof(ulong)))
42721 return -EFAULT;
42722 diff --git a/drivers/isdn/i4l/isdn_concap.c b/drivers/isdn/i4l/isdn_concap.c
42723 index 91d5730..336523e 100644
42724 --- a/drivers/isdn/i4l/isdn_concap.c
42725 +++ b/drivers/isdn/i4l/isdn_concap.c
42726 @@ -80,9 +80,9 @@ static int isdn_concap_dl_disconn_req(struct concap_proto *concap)
42727 }
42728
42729 struct concap_device_ops isdn_concap_reliable_dl_dops = {
42730 - &isdn_concap_dl_data_req,
42731 - &isdn_concap_dl_connect_req,
42732 - &isdn_concap_dl_disconn_req
42733 + .data_req = &isdn_concap_dl_data_req,
42734 + .connect_req = &isdn_concap_dl_connect_req,
42735 + .disconn_req = &isdn_concap_dl_disconn_req
42736 };
42737
42738 /* The following should better go into a dedicated source file such that
42739 diff --git a/drivers/isdn/i4l/isdn_tty.c b/drivers/isdn/i4l/isdn_tty.c
42740 index 3c5f249..5fac4d0 100644
42741 --- a/drivers/isdn/i4l/isdn_tty.c
42742 +++ b/drivers/isdn/i4l/isdn_tty.c
42743 @@ -1508,9 +1508,9 @@ isdn_tty_open(struct tty_struct *tty, struct file *filp)
42744
42745 #ifdef ISDN_DEBUG_MODEM_OPEN
42746 printk(KERN_DEBUG "isdn_tty_open %s, count = %d\n", tty->name,
42747 - port->count);
42748 + atomic_read(&port->count));
42749 #endif
42750 - port->count++;
42751 + atomic_inc(&port->count);
42752 port->tty = tty;
42753 /*
42754 * Start up serial port
42755 @@ -1554,7 +1554,7 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42756 #endif
42757 return;
42758 }
42759 - if ((tty->count == 1) && (port->count != 1)) {
42760 + if ((tty->count == 1) && (atomic_read(&port->count) != 1)) {
42761 /*
42762 * Uh, oh. tty->count is 1, which means that the tty
42763 * structure will be freed. Info->count should always
42764 @@ -1563,15 +1563,15 @@ isdn_tty_close(struct tty_struct *tty, struct file *filp)
42765 * serial port won't be shutdown.
42766 */
42767 printk(KERN_ERR "isdn_tty_close: bad port count; tty->count is 1, "
42768 - "info->count is %d\n", port->count);
42769 - port->count = 1;
42770 + "info->count is %d\n", atomic_read(&port->count));
42771 + atomic_set(&port->count, 1);
42772 }
42773 - if (--port->count < 0) {
42774 + if (atomic_dec_return(&port->count) < 0) {
42775 printk(KERN_ERR "isdn_tty_close: bad port count for ttyi%d: %d\n",
42776 - info->line, port->count);
42777 - port->count = 0;
42778 + info->line, atomic_read(&port->count));
42779 + atomic_set(&port->count, 0);
42780 }
42781 - if (port->count) {
42782 + if (atomic_read(&port->count)) {
42783 #ifdef ISDN_DEBUG_MODEM_OPEN
42784 printk(KERN_DEBUG "isdn_tty_close after info->count != 0\n");
42785 #endif
42786 @@ -1625,7 +1625,7 @@ isdn_tty_hangup(struct tty_struct *tty)
42787 if (isdn_tty_paranoia_check(info, tty->name, "isdn_tty_hangup"))
42788 return;
42789 isdn_tty_shutdown(info);
42790 - port->count = 0;
42791 + atomic_set(&port->count, 0);
42792 port->flags &= ~ASYNC_NORMAL_ACTIVE;
42793 port->tty = NULL;
42794 wake_up_interruptible(&port->open_wait);
42795 @@ -1970,7 +1970,7 @@ isdn_tty_find_icall(int di, int ch, setup_parm *setup)
42796 for (i = 0; i < ISDN_MAX_CHANNELS; i++) {
42797 modem_info *info = &dev->mdm.info[i];
42798
42799 - if (info->port.count == 0)
42800 + if (atomic_read(&info->port.count) == 0)
42801 continue;
42802 if ((info->emu.mdmreg[REG_SI1] & si2bit[si1]) && /* SI1 is matching */
42803 (info->emu.mdmreg[REG_SI2] == si2)) { /* SI2 is matching */
42804 diff --git a/drivers/isdn/i4l/isdn_x25iface.c b/drivers/isdn/i4l/isdn_x25iface.c
42805 index e2d4e58..40cd045 100644
42806 --- a/drivers/isdn/i4l/isdn_x25iface.c
42807 +++ b/drivers/isdn/i4l/isdn_x25iface.c
42808 @@ -53,14 +53,14 @@ static int isdn_x25iface_disconn_ind(struct concap_proto *);
42809
42810
42811 static struct concap_proto_ops ix25_pops = {
42812 - &isdn_x25iface_proto_new,
42813 - &isdn_x25iface_proto_del,
42814 - &isdn_x25iface_proto_restart,
42815 - &isdn_x25iface_proto_close,
42816 - &isdn_x25iface_xmit,
42817 - &isdn_x25iface_receive,
42818 - &isdn_x25iface_connect_ind,
42819 - &isdn_x25iface_disconn_ind
42820 + .proto_new = &isdn_x25iface_proto_new,
42821 + .proto_del = &isdn_x25iface_proto_del,
42822 + .restart = &isdn_x25iface_proto_restart,
42823 + .close = &isdn_x25iface_proto_close,
42824 + .encap_and_xmit = &isdn_x25iface_xmit,
42825 + .data_ind = &isdn_x25iface_receive,
42826 + .connect_ind = &isdn_x25iface_connect_ind,
42827 + .disconn_ind = &isdn_x25iface_disconn_ind
42828 };
42829
42830 /* error message helper function */
42831 diff --git a/drivers/isdn/icn/icn.c b/drivers/isdn/icn/icn.c
42832 index 53d487f..f020f41 100644
42833 --- a/drivers/isdn/icn/icn.c
42834 +++ b/drivers/isdn/icn/icn.c
42835 @@ -1045,7 +1045,7 @@ icn_writecmd(const u_char *buf, int len, int user, icn_card *card)
42836 if (count > len)
42837 count = len;
42838 if (user) {
42839 - if (copy_from_user(msg, buf, count))
42840 + if (count > sizeof msg || copy_from_user(msg, buf, count))
42841 return -EFAULT;
42842 } else
42843 memcpy(msg, buf, count);
42844 diff --git a/drivers/isdn/mISDN/dsp_cmx.c b/drivers/isdn/mISDN/dsp_cmx.c
42845 index a4f05c5..1433bc5 100644
42846 --- a/drivers/isdn/mISDN/dsp_cmx.c
42847 +++ b/drivers/isdn/mISDN/dsp_cmx.c
42848 @@ -1628,7 +1628,7 @@ unsigned long dsp_spl_jiffies; /* calculate the next time to fire */
42849 static u16 dsp_count; /* last sample count */
42850 static int dsp_count_valid; /* if we have last sample count */
42851
42852 -void
42853 +void __intentional_overflow(-1)
42854 dsp_cmx_send(void *arg)
42855 {
42856 struct dsp_conf *conf;
42857 diff --git a/drivers/leds/leds-clevo-mail.c b/drivers/leds/leds-clevo-mail.c
42858 index d93e245..e7ece6b 100644
42859 --- a/drivers/leds/leds-clevo-mail.c
42860 +++ b/drivers/leds/leds-clevo-mail.c
42861 @@ -40,7 +40,7 @@ static int __init clevo_mail_led_dmi_callback(const struct dmi_system_id *id)
42862 * detected as working, but in reality it is not) as low as
42863 * possible.
42864 */
42865 -static struct dmi_system_id clevo_mail_led_dmi_table[] __initdata = {
42866 +static struct dmi_system_id clevo_mail_led_dmi_table[] __initconst = {
42867 {
42868 .callback = clevo_mail_led_dmi_callback,
42869 .ident = "Clevo D410J",
42870 diff --git a/drivers/leds/leds-ss4200.c b/drivers/leds/leds-ss4200.c
42871 index 5b8f938..b73d657 100644
42872 --- a/drivers/leds/leds-ss4200.c
42873 +++ b/drivers/leds/leds-ss4200.c
42874 @@ -91,7 +91,7 @@ MODULE_PARM_DESC(nodetect, "Skip DMI-based hardware detection");
42875 * detected as working, but in reality it is not) as low as
42876 * possible.
42877 */
42878 -static struct dmi_system_id nas_led_whitelist[] __initdata = {
42879 +static struct dmi_system_id nas_led_whitelist[] __initconst = {
42880 {
42881 .callback = ss4200_led_dmi_callback,
42882 .ident = "Intel SS4200-E",
42883 diff --git a/drivers/lguest/core.c b/drivers/lguest/core.c
42884 index 0bf1e4e..b4bf44e 100644
42885 --- a/drivers/lguest/core.c
42886 +++ b/drivers/lguest/core.c
42887 @@ -97,9 +97,17 @@ static __init int map_switcher(void)
42888 * The end address needs +1 because __get_vm_area allocates an
42889 * extra guard page, so we need space for that.
42890 */
42891 +
42892 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
42893 + switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42894 + VM_ALLOC | VM_KERNEXEC, switcher_addr, switcher_addr
42895 + + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42896 +#else
42897 switcher_vma = __get_vm_area(TOTAL_SWITCHER_PAGES * PAGE_SIZE,
42898 VM_ALLOC, switcher_addr, switcher_addr
42899 + (TOTAL_SWITCHER_PAGES+1) * PAGE_SIZE);
42900 +#endif
42901 +
42902 if (!switcher_vma) {
42903 err = -ENOMEM;
42904 printk("lguest: could not map switcher pages high\n");
42905 @@ -124,7 +132,7 @@ static __init int map_switcher(void)
42906 * Now the Switcher is mapped at the right address, we can't fail!
42907 * Copy in the compiled-in Switcher code (from x86/switcher_32.S).
42908 */
42909 - memcpy(switcher_vma->addr, start_switcher_text,
42910 + memcpy(switcher_vma->addr, ktla_ktva(start_switcher_text),
42911 end_switcher_text - start_switcher_text);
42912
42913 printk(KERN_INFO "lguest: mapped switcher at %p\n",
42914 diff --git a/drivers/lguest/page_tables.c b/drivers/lguest/page_tables.c
42915 index bfb39bb..08a603b 100644
42916 --- a/drivers/lguest/page_tables.c
42917 +++ b/drivers/lguest/page_tables.c
42918 @@ -559,7 +559,7 @@ void pin_page(struct lg_cpu *cpu, unsigned long vaddr)
42919 /*:*/
42920
42921 #ifdef CONFIG_X86_PAE
42922 -static void release_pmd(pmd_t *spmd)
42923 +static void __intentional_overflow(-1) release_pmd(pmd_t *spmd)
42924 {
42925 /* If the entry's not present, there's nothing to release. */
42926 if (pmd_flags(*spmd) & _PAGE_PRESENT) {
42927 diff --git a/drivers/lguest/x86/core.c b/drivers/lguest/x86/core.c
42928 index 922a1ac..9dd0c2a 100644
42929 --- a/drivers/lguest/x86/core.c
42930 +++ b/drivers/lguest/x86/core.c
42931 @@ -59,7 +59,7 @@ static struct {
42932 /* Offset from where switcher.S was compiled to where we've copied it */
42933 static unsigned long switcher_offset(void)
42934 {
42935 - return switcher_addr - (unsigned long)start_switcher_text;
42936 + return switcher_addr - (unsigned long)ktla_ktva(start_switcher_text);
42937 }
42938
42939 /* This cpu's struct lguest_pages (after the Switcher text page) */
42940 @@ -99,7 +99,13 @@ static void copy_in_guest_info(struct lg_cpu *cpu, struct lguest_pages *pages)
42941 * These copies are pretty cheap, so we do them unconditionally: */
42942 /* Save the current Host top-level page directory.
42943 */
42944 +
42945 +#ifdef CONFIG_PAX_PER_CPU_PGD
42946 + pages->state.host_cr3 = read_cr3();
42947 +#else
42948 pages->state.host_cr3 = __pa(current->mm->pgd);
42949 +#endif
42950 +
42951 /*
42952 * Set up the Guest's page tables to see this CPU's pages (and no
42953 * other CPU's pages).
42954 @@ -477,7 +483,7 @@ void __init lguest_arch_host_init(void)
42955 * compiled-in switcher code and the high-mapped copy we just made.
42956 */
42957 for (i = 0; i < IDT_ENTRIES; i++)
42958 - default_idt_entries[i] += switcher_offset();
42959 + default_idt_entries[i] = ktla_ktva(default_idt_entries[i]) + switcher_offset();
42960
42961 /*
42962 * Set up the Switcher's per-cpu areas.
42963 @@ -560,7 +566,7 @@ void __init lguest_arch_host_init(void)
42964 * it will be undisturbed when we switch. To change %cs and jump we
42965 * need this structure to feed to Intel's "lcall" instruction.
42966 */
42967 - lguest_entry.offset = (long)switch_to_guest + switcher_offset();
42968 + lguest_entry.offset = (long)ktla_ktva(switch_to_guest) + switcher_offset();
42969 lguest_entry.segment = LGUEST_CS;
42970
42971 /*
42972 diff --git a/drivers/lguest/x86/switcher_32.S b/drivers/lguest/x86/switcher_32.S
42973 index 40634b0..4f5855e 100644
42974 --- a/drivers/lguest/x86/switcher_32.S
42975 +++ b/drivers/lguest/x86/switcher_32.S
42976 @@ -87,6 +87,7 @@
42977 #include <asm/page.h>
42978 #include <asm/segment.h>
42979 #include <asm/lguest.h>
42980 +#include <asm/processor-flags.h>
42981
42982 // We mark the start of the code to copy
42983 // It's placed in .text tho it's never run here
42984 @@ -149,6 +150,13 @@ ENTRY(switch_to_guest)
42985 // Changes type when we load it: damn Intel!
42986 // For after we switch over our page tables
42987 // That entry will be read-only: we'd crash.
42988 +
42989 +#ifdef CONFIG_PAX_KERNEXEC
42990 + mov %cr0, %edx
42991 + xor $X86_CR0_WP, %edx
42992 + mov %edx, %cr0
42993 +#endif
42994 +
42995 movl $(GDT_ENTRY_TSS*8), %edx
42996 ltr %dx
42997
42998 @@ -157,9 +165,15 @@ ENTRY(switch_to_guest)
42999 // Let's clear it again for our return.
43000 // The GDT descriptor of the Host
43001 // Points to the table after two "size" bytes
43002 - movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %edx
43003 + movl (LGUEST_PAGES_host_gdt_desc+2)(%eax), %eax
43004 // Clear "used" from type field (byte 5, bit 2)
43005 - andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%edx)
43006 + andb $0xFD, (GDT_ENTRY_TSS*8 + 5)(%eax)
43007 +
43008 +#ifdef CONFIG_PAX_KERNEXEC
43009 + mov %cr0, %eax
43010 + xor $X86_CR0_WP, %eax
43011 + mov %eax, %cr0
43012 +#endif
43013
43014 // Once our page table's switched, the Guest is live!
43015 // The Host fades as we run this final step.
43016 @@ -295,13 +309,12 @@ deliver_to_host:
43017 // I consulted gcc, and it gave
43018 // These instructions, which I gladly credit:
43019 leal (%edx,%ebx,8), %eax
43020 - movzwl (%eax),%edx
43021 - movl 4(%eax), %eax
43022 - xorw %ax, %ax
43023 - orl %eax, %edx
43024 + movl 4(%eax), %edx
43025 + movw (%eax), %dx
43026 // Now the address of the handler's in %edx
43027 // We call it now: its "iret" drops us home.
43028 - jmp *%edx
43029 + ljmp $__KERNEL_CS, $1f
43030 +1: jmp *%edx
43031
43032 // Every interrupt can come to us here
43033 // But we must truly tell each apart.
43034 diff --git a/drivers/md/bcache/closure.h b/drivers/md/bcache/closure.h
43035 index 9762f1b..3e79734 100644
43036 --- a/drivers/md/bcache/closure.h
43037 +++ b/drivers/md/bcache/closure.h
43038 @@ -483,7 +483,7 @@ static inline void closure_queue(struct closure *cl)
43039 static inline void set_closure_fn(struct closure *cl, closure_fn *fn,
43040 struct workqueue_struct *wq)
43041 {
43042 - BUG_ON(object_is_on_stack(cl));
43043 + BUG_ON(object_starts_on_stack(cl));
43044 closure_set_ip(cl);
43045 cl->fn = fn;
43046 cl->wq = wq;
43047 diff --git a/drivers/md/bitmap.c b/drivers/md/bitmap.c
43048 index 12dc29b..1596277 100644
43049 --- a/drivers/md/bitmap.c
43050 +++ b/drivers/md/bitmap.c
43051 @@ -1779,7 +1779,7 @@ void bitmap_status(struct seq_file *seq, struct bitmap *bitmap)
43052 chunk_kb ? "KB" : "B");
43053 if (bitmap->storage.file) {
43054 seq_printf(seq, ", file: ");
43055 - seq_path(seq, &bitmap->storage.file->f_path, " \t\n");
43056 + seq_path(seq, &bitmap->storage.file->f_path, " \t\n\\");
43057 }
43058
43059 seq_printf(seq, "\n");
43060 diff --git a/drivers/md/dm-ioctl.c b/drivers/md/dm-ioctl.c
43061 index 5152142..623d141 100644
43062 --- a/drivers/md/dm-ioctl.c
43063 +++ b/drivers/md/dm-ioctl.c
43064 @@ -1769,7 +1769,7 @@ static int validate_params(uint cmd, struct dm_ioctl *param)
43065 cmd == DM_LIST_VERSIONS_CMD)
43066 return 0;
43067
43068 - if ((cmd == DM_DEV_CREATE_CMD)) {
43069 + if (cmd == DM_DEV_CREATE_CMD) {
43070 if (!*param->name) {
43071 DMWARN("name not supplied when creating device");
43072 return -EINVAL;
43073 diff --git a/drivers/md/dm-raid1.c b/drivers/md/dm-raid1.c
43074 index 9584443..9fc9ac9 100644
43075 --- a/drivers/md/dm-raid1.c
43076 +++ b/drivers/md/dm-raid1.c
43077 @@ -40,7 +40,7 @@ enum dm_raid1_error {
43078
43079 struct mirror {
43080 struct mirror_set *ms;
43081 - atomic_t error_count;
43082 + atomic_unchecked_t error_count;
43083 unsigned long error_type;
43084 struct dm_dev *dev;
43085 sector_t offset;
43086 @@ -186,7 +186,7 @@ static struct mirror *get_valid_mirror(struct mirror_set *ms)
43087 struct mirror *m;
43088
43089 for (m = ms->mirror; m < ms->mirror + ms->nr_mirrors; m++)
43090 - if (!atomic_read(&m->error_count))
43091 + if (!atomic_read_unchecked(&m->error_count))
43092 return m;
43093
43094 return NULL;
43095 @@ -218,7 +218,7 @@ static void fail_mirror(struct mirror *m, enum dm_raid1_error error_type)
43096 * simple way to tell if a device has encountered
43097 * errors.
43098 */
43099 - atomic_inc(&m->error_count);
43100 + atomic_inc_unchecked(&m->error_count);
43101
43102 if (test_and_set_bit(error_type, &m->error_type))
43103 return;
43104 @@ -409,7 +409,7 @@ static struct mirror *choose_mirror(struct mirror_set *ms, sector_t sector)
43105 struct mirror *m = get_default_mirror(ms);
43106
43107 do {
43108 - if (likely(!atomic_read(&m->error_count)))
43109 + if (likely(!atomic_read_unchecked(&m->error_count)))
43110 return m;
43111
43112 if (m-- == ms->mirror)
43113 @@ -423,7 +423,7 @@ static int default_ok(struct mirror *m)
43114 {
43115 struct mirror *default_mirror = get_default_mirror(m->ms);
43116
43117 - return !atomic_read(&default_mirror->error_count);
43118 + return !atomic_read_unchecked(&default_mirror->error_count);
43119 }
43120
43121 static int mirror_available(struct mirror_set *ms, struct bio *bio)
43122 @@ -560,7 +560,7 @@ static void do_reads(struct mirror_set *ms, struct bio_list *reads)
43123 */
43124 if (likely(region_in_sync(ms, region, 1)))
43125 m = choose_mirror(ms, bio->bi_sector);
43126 - else if (m && atomic_read(&m->error_count))
43127 + else if (m && atomic_read_unchecked(&m->error_count))
43128 m = NULL;
43129
43130 if (likely(m))
43131 @@ -927,7 +927,7 @@ static int get_mirror(struct mirror_set *ms, struct dm_target *ti,
43132 }
43133
43134 ms->mirror[mirror].ms = ms;
43135 - atomic_set(&(ms->mirror[mirror].error_count), 0);
43136 + atomic_set_unchecked(&(ms->mirror[mirror].error_count), 0);
43137 ms->mirror[mirror].error_type = 0;
43138 ms->mirror[mirror].offset = offset;
43139
43140 @@ -1339,7 +1339,7 @@ static void mirror_resume(struct dm_target *ti)
43141 */
43142 static char device_status_char(struct mirror *m)
43143 {
43144 - if (!atomic_read(&(m->error_count)))
43145 + if (!atomic_read_unchecked(&(m->error_count)))
43146 return 'A';
43147
43148 return (test_bit(DM_RAID1_FLUSH_ERROR, &(m->error_type))) ? 'F' :
43149 diff --git a/drivers/md/dm-stats.c b/drivers/md/dm-stats.c
43150 index 28a9012..9c0f6a5 100644
43151 --- a/drivers/md/dm-stats.c
43152 +++ b/drivers/md/dm-stats.c
43153 @@ -382,7 +382,7 @@ do_sync_free:
43154 synchronize_rcu_expedited();
43155 dm_stat_free(&s->rcu_head);
43156 } else {
43157 - ACCESS_ONCE(dm_stat_need_rcu_barrier) = 1;
43158 + ACCESS_ONCE_RW(dm_stat_need_rcu_barrier) = 1;
43159 call_rcu(&s->rcu_head, dm_stat_free);
43160 }
43161 return 0;
43162 @@ -554,8 +554,8 @@ void dm_stats_account_io(struct dm_stats *stats, unsigned long bi_rw,
43163 ((bi_rw & (REQ_WRITE | REQ_DISCARD)) ==
43164 (ACCESS_ONCE(last->last_rw) & (REQ_WRITE | REQ_DISCARD)))
43165 ));
43166 - ACCESS_ONCE(last->last_sector) = end_sector;
43167 - ACCESS_ONCE(last->last_rw) = bi_rw;
43168 + ACCESS_ONCE_RW(last->last_sector) = end_sector;
43169 + ACCESS_ONCE_RW(last->last_rw) = bi_rw;
43170 }
43171
43172 rcu_read_lock();
43173 diff --git a/drivers/md/dm-stripe.c b/drivers/md/dm-stripe.c
43174 index 73c1712..7347292 100644
43175 --- a/drivers/md/dm-stripe.c
43176 +++ b/drivers/md/dm-stripe.c
43177 @@ -21,7 +21,7 @@ struct stripe {
43178 struct dm_dev *dev;
43179 sector_t physical_start;
43180
43181 - atomic_t error_count;
43182 + atomic_unchecked_t error_count;
43183 };
43184
43185 struct stripe_c {
43186 @@ -186,7 +186,7 @@ static int stripe_ctr(struct dm_target *ti, unsigned int argc, char **argv)
43187 kfree(sc);
43188 return r;
43189 }
43190 - atomic_set(&(sc->stripe[i].error_count), 0);
43191 + atomic_set_unchecked(&(sc->stripe[i].error_count), 0);
43192 }
43193
43194 ti->private = sc;
43195 @@ -327,7 +327,7 @@ static void stripe_status(struct dm_target *ti, status_type_t type,
43196 DMEMIT("%d ", sc->stripes);
43197 for (i = 0; i < sc->stripes; i++) {
43198 DMEMIT("%s ", sc->stripe[i].dev->name);
43199 - buffer[i] = atomic_read(&(sc->stripe[i].error_count)) ?
43200 + buffer[i] = atomic_read_unchecked(&(sc->stripe[i].error_count)) ?
43201 'D' : 'A';
43202 }
43203 buffer[i] = '\0';
43204 @@ -372,8 +372,8 @@ static int stripe_end_io(struct dm_target *ti, struct bio *bio, int error)
43205 */
43206 for (i = 0; i < sc->stripes; i++)
43207 if (!strcmp(sc->stripe[i].dev->name, major_minor)) {
43208 - atomic_inc(&(sc->stripe[i].error_count));
43209 - if (atomic_read(&(sc->stripe[i].error_count)) <
43210 + atomic_inc_unchecked(&(sc->stripe[i].error_count));
43211 + if (atomic_read_unchecked(&(sc->stripe[i].error_count)) <
43212 DM_IO_ERROR_THRESHOLD)
43213 schedule_work(&sc->trigger_event);
43214 }
43215 diff --git a/drivers/md/dm-table.c b/drivers/md/dm-table.c
43216 index 3ba6a38..b0fa9b0 100644
43217 --- a/drivers/md/dm-table.c
43218 +++ b/drivers/md/dm-table.c
43219 @@ -291,7 +291,7 @@ static struct dm_dev_internal *find_device(struct list_head *l, dev_t dev)
43220 static int open_dev(struct dm_dev_internal *d, dev_t dev,
43221 struct mapped_device *md)
43222 {
43223 - static char *_claim_ptr = "I belong to device-mapper";
43224 + static char _claim_ptr[] = "I belong to device-mapper";
43225 struct block_device *bdev;
43226
43227 int r;
43228 @@ -359,7 +359,7 @@ static int device_area_is_invalid(struct dm_target *ti, struct dm_dev *dev,
43229 if (!dev_size)
43230 return 0;
43231
43232 - if ((start >= dev_size) || (start + len > dev_size)) {
43233 + if ((start >= dev_size) || (len > dev_size - start)) {
43234 DMWARN("%s: %s too small for target: "
43235 "start=%llu, len=%llu, dev_size=%llu",
43236 dm_device_name(ti->table->md), bdevname(bdev, b),
43237 diff --git a/drivers/md/dm-thin-metadata.c b/drivers/md/dm-thin-metadata.c
43238 index 7da3476..f75839e 100644
43239 --- a/drivers/md/dm-thin-metadata.c
43240 +++ b/drivers/md/dm-thin-metadata.c
43241 @@ -397,7 +397,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43242 {
43243 pmd->info.tm = pmd->tm;
43244 pmd->info.levels = 2;
43245 - pmd->info.value_type.context = pmd->data_sm;
43246 + pmd->info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43247 pmd->info.value_type.size = sizeof(__le64);
43248 pmd->info.value_type.inc = data_block_inc;
43249 pmd->info.value_type.dec = data_block_dec;
43250 @@ -416,7 +416,7 @@ static void __setup_btree_details(struct dm_pool_metadata *pmd)
43251
43252 pmd->bl_info.tm = pmd->tm;
43253 pmd->bl_info.levels = 1;
43254 - pmd->bl_info.value_type.context = pmd->data_sm;
43255 + pmd->bl_info.value_type.context = (dm_space_map_no_const *)pmd->data_sm;
43256 pmd->bl_info.value_type.size = sizeof(__le64);
43257 pmd->bl_info.value_type.inc = data_block_inc;
43258 pmd->bl_info.value_type.dec = data_block_dec;
43259 diff --git a/drivers/md/dm.c b/drivers/md/dm.c
43260 index b49c762..c9503cf 100644
43261 --- a/drivers/md/dm.c
43262 +++ b/drivers/md/dm.c
43263 @@ -185,9 +185,9 @@ struct mapped_device {
43264 /*
43265 * Event handling.
43266 */
43267 - atomic_t event_nr;
43268 + atomic_unchecked_t event_nr;
43269 wait_queue_head_t eventq;
43270 - atomic_t uevent_seq;
43271 + atomic_unchecked_t uevent_seq;
43272 struct list_head uevent_list;
43273 spinlock_t uevent_lock; /* Protect access to uevent_list */
43274
43275 @@ -2021,8 +2021,8 @@ static struct mapped_device *alloc_dev(int minor)
43276 spin_lock_init(&md->deferred_lock);
43277 atomic_set(&md->holders, 1);
43278 atomic_set(&md->open_count, 0);
43279 - atomic_set(&md->event_nr, 0);
43280 - atomic_set(&md->uevent_seq, 0);
43281 + atomic_set_unchecked(&md->event_nr, 0);
43282 + atomic_set_unchecked(&md->uevent_seq, 0);
43283 INIT_LIST_HEAD(&md->uevent_list);
43284 spin_lock_init(&md->uevent_lock);
43285
43286 @@ -2176,7 +2176,7 @@ static void event_callback(void *context)
43287
43288 dm_send_uevents(&uevents, &disk_to_dev(md->disk)->kobj);
43289
43290 - atomic_inc(&md->event_nr);
43291 + atomic_inc_unchecked(&md->event_nr);
43292 wake_up(&md->eventq);
43293 }
43294
43295 @@ -2869,18 +2869,18 @@ int dm_kobject_uevent(struct mapped_device *md, enum kobject_action action,
43296
43297 uint32_t dm_next_uevent_seq(struct mapped_device *md)
43298 {
43299 - return atomic_add_return(1, &md->uevent_seq);
43300 + return atomic_add_return_unchecked(1, &md->uevent_seq);
43301 }
43302
43303 uint32_t dm_get_event_nr(struct mapped_device *md)
43304 {
43305 - return atomic_read(&md->event_nr);
43306 + return atomic_read_unchecked(&md->event_nr);
43307 }
43308
43309 int dm_wait_event(struct mapped_device *md, int event_nr)
43310 {
43311 return wait_event_interruptible(md->eventq,
43312 - (event_nr != atomic_read(&md->event_nr)));
43313 + (event_nr != atomic_read_unchecked(&md->event_nr)));
43314 }
43315
43316 void dm_uevent_add(struct mapped_device *md, struct list_head *elist)
43317 diff --git a/drivers/md/md.c b/drivers/md/md.c
43318 index 369d919..ba7049c 100644
43319 --- a/drivers/md/md.c
43320 +++ b/drivers/md/md.c
43321 @@ -194,10 +194,10 @@ EXPORT_SYMBOL_GPL(bio_clone_mddev);
43322 * start build, activate spare
43323 */
43324 static DECLARE_WAIT_QUEUE_HEAD(md_event_waiters);
43325 -static atomic_t md_event_count;
43326 +static atomic_unchecked_t md_event_count;
43327 void md_new_event(struct mddev *mddev)
43328 {
43329 - atomic_inc(&md_event_count);
43330 + atomic_inc_unchecked(&md_event_count);
43331 wake_up(&md_event_waiters);
43332 }
43333 EXPORT_SYMBOL_GPL(md_new_event);
43334 @@ -207,7 +207,7 @@ EXPORT_SYMBOL_GPL(md_new_event);
43335 */
43336 static void md_new_event_inintr(struct mddev *mddev)
43337 {
43338 - atomic_inc(&md_event_count);
43339 + atomic_inc_unchecked(&md_event_count);
43340 wake_up(&md_event_waiters);
43341 }
43342
43343 @@ -1463,7 +1463,7 @@ static int super_1_load(struct md_rdev *rdev, struct md_rdev *refdev, int minor_
43344 if ((le32_to_cpu(sb->feature_map) & MD_FEATURE_RESHAPE_ACTIVE) &&
43345 (le32_to_cpu(sb->feature_map) & MD_FEATURE_NEW_OFFSET))
43346 rdev->new_data_offset += (s32)le32_to_cpu(sb->new_offset);
43347 - atomic_set(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43348 + atomic_set_unchecked(&rdev->corrected_errors, le32_to_cpu(sb->cnt_corrected_read));
43349
43350 rdev->sb_size = le32_to_cpu(sb->max_dev) * 2 + 256;
43351 bmask = queue_logical_block_size(rdev->bdev->bd_disk->queue)-1;
43352 @@ -1710,7 +1710,7 @@ static void super_1_sync(struct mddev *mddev, struct md_rdev *rdev)
43353 else
43354 sb->resync_offset = cpu_to_le64(0);
43355
43356 - sb->cnt_corrected_read = cpu_to_le32(atomic_read(&rdev->corrected_errors));
43357 + sb->cnt_corrected_read = cpu_to_le32(atomic_read_unchecked(&rdev->corrected_errors));
43358
43359 sb->raid_disks = cpu_to_le32(mddev->raid_disks);
43360 sb->size = cpu_to_le64(mddev->dev_sectors);
43361 @@ -2715,7 +2715,7 @@ __ATTR(state, S_IRUGO|S_IWUSR, state_show, state_store);
43362 static ssize_t
43363 errors_show(struct md_rdev *rdev, char *page)
43364 {
43365 - return sprintf(page, "%d\n", atomic_read(&rdev->corrected_errors));
43366 + return sprintf(page, "%d\n", atomic_read_unchecked(&rdev->corrected_errors));
43367 }
43368
43369 static ssize_t
43370 @@ -2724,7 +2724,7 @@ errors_store(struct md_rdev *rdev, const char *buf, size_t len)
43371 char *e;
43372 unsigned long n = simple_strtoul(buf, &e, 10);
43373 if (*buf && (*e == 0 || *e == '\n')) {
43374 - atomic_set(&rdev->corrected_errors, n);
43375 + atomic_set_unchecked(&rdev->corrected_errors, n);
43376 return len;
43377 }
43378 return -EINVAL;
43379 @@ -3173,8 +3173,8 @@ int md_rdev_init(struct md_rdev *rdev)
43380 rdev->sb_loaded = 0;
43381 rdev->bb_page = NULL;
43382 atomic_set(&rdev->nr_pending, 0);
43383 - atomic_set(&rdev->read_errors, 0);
43384 - atomic_set(&rdev->corrected_errors, 0);
43385 + atomic_set_unchecked(&rdev->read_errors, 0);
43386 + atomic_set_unchecked(&rdev->corrected_errors, 0);
43387
43388 INIT_LIST_HEAD(&rdev->same_set);
43389 init_waitqueue_head(&rdev->blocked_wait);
43390 @@ -7038,7 +7038,7 @@ static int md_seq_show(struct seq_file *seq, void *v)
43391
43392 spin_unlock(&pers_lock);
43393 seq_printf(seq, "\n");
43394 - seq->poll_event = atomic_read(&md_event_count);
43395 + seq->poll_event = atomic_read_unchecked(&md_event_count);
43396 return 0;
43397 }
43398 if (v == (void*)2) {
43399 @@ -7141,7 +7141,7 @@ static int md_seq_open(struct inode *inode, struct file *file)
43400 return error;
43401
43402 seq = file->private_data;
43403 - seq->poll_event = atomic_read(&md_event_count);
43404 + seq->poll_event = atomic_read_unchecked(&md_event_count);
43405 return error;
43406 }
43407
43408 @@ -7155,7 +7155,7 @@ static unsigned int mdstat_poll(struct file *filp, poll_table *wait)
43409 /* always allow read */
43410 mask = POLLIN | POLLRDNORM;
43411
43412 - if (seq->poll_event != atomic_read(&md_event_count))
43413 + if (seq->poll_event != atomic_read_unchecked(&md_event_count))
43414 mask |= POLLERR | POLLPRI;
43415 return mask;
43416 }
43417 @@ -7199,7 +7199,7 @@ static int is_mddev_idle(struct mddev *mddev, int init)
43418 struct gendisk *disk = rdev->bdev->bd_contains->bd_disk;
43419 curr_events = (int)part_stat_read(&disk->part0, sectors[0]) +
43420 (int)part_stat_read(&disk->part0, sectors[1]) -
43421 - atomic_read(&disk->sync_io);
43422 + atomic_read_unchecked(&disk->sync_io);
43423 /* sync IO will cause sync_io to increase before the disk_stats
43424 * as sync_io is counted when a request starts, and
43425 * disk_stats is counted when it completes.
43426 diff --git a/drivers/md/md.h b/drivers/md/md.h
43427 index 0095ec8..c89277a 100644
43428 --- a/drivers/md/md.h
43429 +++ b/drivers/md/md.h
43430 @@ -94,13 +94,13 @@ struct md_rdev {
43431 * only maintained for arrays that
43432 * support hot removal
43433 */
43434 - atomic_t read_errors; /* number of consecutive read errors that
43435 + atomic_unchecked_t read_errors; /* number of consecutive read errors that
43436 * we have tried to ignore.
43437 */
43438 struct timespec last_read_error; /* monotonic time since our
43439 * last read error
43440 */
43441 - atomic_t corrected_errors; /* number of corrected read errors,
43442 + atomic_unchecked_t corrected_errors; /* number of corrected read errors,
43443 * for reporting to userspace and storing
43444 * in superblock.
43445 */
43446 @@ -449,7 +449,7 @@ static inline void rdev_dec_pending(struct md_rdev *rdev, struct mddev *mddev)
43447
43448 static inline void md_sync_acct(struct block_device *bdev, unsigned long nr_sectors)
43449 {
43450 - atomic_add(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
43451 + atomic_add_unchecked(nr_sectors, &bdev->bd_contains->bd_disk->sync_io);
43452 }
43453
43454 struct md_personality
43455 diff --git a/drivers/md/persistent-data/dm-space-map.h b/drivers/md/persistent-data/dm-space-map.h
43456 index 3e6d115..ffecdeb 100644
43457 --- a/drivers/md/persistent-data/dm-space-map.h
43458 +++ b/drivers/md/persistent-data/dm-space-map.h
43459 @@ -71,6 +71,7 @@ struct dm_space_map {
43460 dm_sm_threshold_fn fn,
43461 void *context);
43462 };
43463 +typedef struct dm_space_map __no_const dm_space_map_no_const;
43464
43465 /*----------------------------------------------------------------*/
43466
43467 diff --git a/drivers/md/raid1.c b/drivers/md/raid1.c
43468 index a49cfcc..20b9a65 100644
43469 --- a/drivers/md/raid1.c
43470 +++ b/drivers/md/raid1.c
43471 @@ -1921,7 +1921,7 @@ static int fix_sync_read_error(struct r1bio *r1_bio)
43472 if (r1_sync_page_io(rdev, sect, s,
43473 bio->bi_io_vec[idx].bv_page,
43474 READ) != 0)
43475 - atomic_add(s, &rdev->corrected_errors);
43476 + atomic_add_unchecked(s, &rdev->corrected_errors);
43477 }
43478 sectors -= s;
43479 sect += s;
43480 @@ -2148,7 +2148,7 @@ static void fix_read_error(struct r1conf *conf, int read_disk,
43481 test_bit(In_sync, &rdev->flags)) {
43482 if (r1_sync_page_io(rdev, sect, s,
43483 conf->tmppage, READ)) {
43484 - atomic_add(s, &rdev->corrected_errors);
43485 + atomic_add_unchecked(s, &rdev->corrected_errors);
43486 printk(KERN_INFO
43487 "md/raid1:%s: read error corrected "
43488 "(%d sectors at %llu on %s)\n",
43489 diff --git a/drivers/md/raid10.c b/drivers/md/raid10.c
43490 index 06eeb99..770613e 100644
43491 --- a/drivers/md/raid10.c
43492 +++ b/drivers/md/raid10.c
43493 @@ -1963,7 +1963,7 @@ static void end_sync_read(struct bio *bio, int error)
43494 /* The write handler will notice the lack of
43495 * R10BIO_Uptodate and record any errors etc
43496 */
43497 - atomic_add(r10_bio->sectors,
43498 + atomic_add_unchecked(r10_bio->sectors,
43499 &conf->mirrors[d].rdev->corrected_errors);
43500
43501 /* for reconstruct, we always reschedule after a read.
43502 @@ -2321,7 +2321,7 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
43503 {
43504 struct timespec cur_time_mon;
43505 unsigned long hours_since_last;
43506 - unsigned int read_errors = atomic_read(&rdev->read_errors);
43507 + unsigned int read_errors = atomic_read_unchecked(&rdev->read_errors);
43508
43509 ktime_get_ts(&cur_time_mon);
43510
43511 @@ -2343,9 +2343,9 @@ static void check_decay_read_errors(struct mddev *mddev, struct md_rdev *rdev)
43512 * overflowing the shift of read_errors by hours_since_last.
43513 */
43514 if (hours_since_last >= 8 * sizeof(read_errors))
43515 - atomic_set(&rdev->read_errors, 0);
43516 + atomic_set_unchecked(&rdev->read_errors, 0);
43517 else
43518 - atomic_set(&rdev->read_errors, read_errors >> hours_since_last);
43519 + atomic_set_unchecked(&rdev->read_errors, read_errors >> hours_since_last);
43520 }
43521
43522 static int r10_sync_page_io(struct md_rdev *rdev, sector_t sector,
43523 @@ -2399,8 +2399,8 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
43524 return;
43525
43526 check_decay_read_errors(mddev, rdev);
43527 - atomic_inc(&rdev->read_errors);
43528 - if (atomic_read(&rdev->read_errors) > max_read_errors) {
43529 + atomic_inc_unchecked(&rdev->read_errors);
43530 + if (atomic_read_unchecked(&rdev->read_errors) > max_read_errors) {
43531 char b[BDEVNAME_SIZE];
43532 bdevname(rdev->bdev, b);
43533
43534 @@ -2408,7 +2408,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
43535 "md/raid10:%s: %s: Raid device exceeded "
43536 "read_error threshold [cur %d:max %d]\n",
43537 mdname(mddev), b,
43538 - atomic_read(&rdev->read_errors), max_read_errors);
43539 + atomic_read_unchecked(&rdev->read_errors), max_read_errors);
43540 printk(KERN_NOTICE
43541 "md/raid10:%s: %s: Failing raid device\n",
43542 mdname(mddev), b);
43543 @@ -2563,7 +2563,7 @@ static void fix_read_error(struct r10conf *conf, struct mddev *mddev, struct r10
43544 sect +
43545 choose_data_offset(r10_bio, rdev)),
43546 bdevname(rdev->bdev, b));
43547 - atomic_add(s, &rdev->corrected_errors);
43548 + atomic_add_unchecked(s, &rdev->corrected_errors);
43549 }
43550
43551 rdev_dec_pending(rdev, mddev);
43552 diff --git a/drivers/md/raid5.c b/drivers/md/raid5.c
43553 index 03f82ab..374bb38 100644
43554 --- a/drivers/md/raid5.c
43555 +++ b/drivers/md/raid5.c
43556 @@ -1991,21 +1991,21 @@ static void raid5_end_read_request(struct bio * bi, int error)
43557 mdname(conf->mddev), STRIPE_SECTORS,
43558 (unsigned long long)s,
43559 bdevname(rdev->bdev, b));
43560 - atomic_add(STRIPE_SECTORS, &rdev->corrected_errors);
43561 + atomic_add_unchecked(STRIPE_SECTORS, &rdev->corrected_errors);
43562 clear_bit(R5_ReadError, &sh->dev[i].flags);
43563 clear_bit(R5_ReWrite, &sh->dev[i].flags);
43564 } else if (test_bit(R5_ReadNoMerge, &sh->dev[i].flags))
43565 clear_bit(R5_ReadNoMerge, &sh->dev[i].flags);
43566
43567 - if (atomic_read(&rdev->read_errors))
43568 - atomic_set(&rdev->read_errors, 0);
43569 + if (atomic_read_unchecked(&rdev->read_errors))
43570 + atomic_set_unchecked(&rdev->read_errors, 0);
43571 } else {
43572 const char *bdn = bdevname(rdev->bdev, b);
43573 int retry = 0;
43574 int set_bad = 0;
43575
43576 clear_bit(R5_UPTODATE, &sh->dev[i].flags);
43577 - atomic_inc(&rdev->read_errors);
43578 + atomic_inc_unchecked(&rdev->read_errors);
43579 if (test_bit(R5_ReadRepl, &sh->dev[i].flags))
43580 printk_ratelimited(
43581 KERN_WARNING
43582 @@ -2033,7 +2033,7 @@ static void raid5_end_read_request(struct bio * bi, int error)
43583 mdname(conf->mddev),
43584 (unsigned long long)s,
43585 bdn);
43586 - } else if (atomic_read(&rdev->read_errors)
43587 + } else if (atomic_read_unchecked(&rdev->read_errors)
43588 > conf->max_nr_stripes)
43589 printk(KERN_WARNING
43590 "md/raid:%s: Too many read errors, failing device %s.\n",
43591 diff --git a/drivers/media/dvb-core/dvbdev.c b/drivers/media/dvb-core/dvbdev.c
43592 index 983db75..ef9248c 100644
43593 --- a/drivers/media/dvb-core/dvbdev.c
43594 +++ b/drivers/media/dvb-core/dvbdev.c
43595 @@ -185,7 +185,7 @@ int dvb_register_device(struct dvb_adapter *adap, struct dvb_device **pdvbdev,
43596 const struct dvb_device *template, void *priv, int type)
43597 {
43598 struct dvb_device *dvbdev;
43599 - struct file_operations *dvbdevfops;
43600 + file_operations_no_const *dvbdevfops;
43601 struct device *clsdev;
43602 int minor;
43603 int id;
43604 diff --git a/drivers/media/dvb-frontends/dib3000.h b/drivers/media/dvb-frontends/dib3000.h
43605 index 9b6c3bb..baeb5c7 100644
43606 --- a/drivers/media/dvb-frontends/dib3000.h
43607 +++ b/drivers/media/dvb-frontends/dib3000.h
43608 @@ -39,7 +39,7 @@ struct dib_fe_xfer_ops
43609 int (*fifo_ctrl)(struct dvb_frontend *fe, int onoff);
43610 int (*pid_ctrl)(struct dvb_frontend *fe, int index, int pid, int onoff);
43611 int (*tuner_pass_ctrl)(struct dvb_frontend *fe, int onoff, u8 pll_ctrl);
43612 -};
43613 +} __no_const;
43614
43615 #if IS_ENABLED(CONFIG_DVB_DIB3000MB)
43616 extern struct dvb_frontend* dib3000mb_attach(const struct dib3000_config* config,
43617 diff --git a/drivers/media/pci/cx88/cx88-video.c b/drivers/media/pci/cx88/cx88-video.c
43618 index ed8cb90..5ef7f79 100644
43619 --- a/drivers/media/pci/cx88/cx88-video.c
43620 +++ b/drivers/media/pci/cx88/cx88-video.c
43621 @@ -50,9 +50,9 @@ MODULE_VERSION(CX88_VERSION);
43622
43623 /* ------------------------------------------------------------------ */
43624
43625 -static unsigned int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43626 -static unsigned int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43627 -static unsigned int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43628 +static int video_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43629 +static int vbi_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43630 +static int radio_nr[] = {[0 ... (CX88_MAXBOARDS - 1)] = UNSET };
43631
43632 module_param_array(video_nr, int, NULL, 0444);
43633 module_param_array(vbi_nr, int, NULL, 0444);
43634 diff --git a/drivers/media/pci/ivtv/ivtv-driver.c b/drivers/media/pci/ivtv/ivtv-driver.c
43635 index 802642d..5534900 100644
43636 --- a/drivers/media/pci/ivtv/ivtv-driver.c
43637 +++ b/drivers/media/pci/ivtv/ivtv-driver.c
43638 @@ -83,7 +83,7 @@ static struct pci_device_id ivtv_pci_tbl[] = {
43639 MODULE_DEVICE_TABLE(pci,ivtv_pci_tbl);
43640
43641 /* ivtv instance counter */
43642 -static atomic_t ivtv_instance = ATOMIC_INIT(0);
43643 +static atomic_unchecked_t ivtv_instance = ATOMIC_INIT(0);
43644
43645 /* Parameter declarations */
43646 static int cardtype[IVTV_MAX_CARDS];
43647 diff --git a/drivers/media/platform/omap/omap_vout.c b/drivers/media/platform/omap/omap_vout.c
43648 index dfd0a21..6bbb465 100644
43649 --- a/drivers/media/platform/omap/omap_vout.c
43650 +++ b/drivers/media/platform/omap/omap_vout.c
43651 @@ -63,7 +63,6 @@ enum omap_vout_channels {
43652 OMAP_VIDEO2,
43653 };
43654
43655 -static struct videobuf_queue_ops video_vbq_ops;
43656 /* Variables configurable through module params*/
43657 static u32 video1_numbuffers = 3;
43658 static u32 video2_numbuffers = 3;
43659 @@ -1014,6 +1013,12 @@ static int omap_vout_open(struct file *file)
43660 {
43661 struct videobuf_queue *q;
43662 struct omap_vout_device *vout = NULL;
43663 + static struct videobuf_queue_ops video_vbq_ops = {
43664 + .buf_setup = omap_vout_buffer_setup,
43665 + .buf_prepare = omap_vout_buffer_prepare,
43666 + .buf_release = omap_vout_buffer_release,
43667 + .buf_queue = omap_vout_buffer_queue,
43668 + };
43669
43670 vout = video_drvdata(file);
43671 v4l2_dbg(1, debug, &vout->vid_dev->v4l2_dev, "Entering %s\n", __func__);
43672 @@ -1031,10 +1036,6 @@ static int omap_vout_open(struct file *file)
43673 vout->type = V4L2_BUF_TYPE_VIDEO_OUTPUT;
43674
43675 q = &vout->vbq;
43676 - video_vbq_ops.buf_setup = omap_vout_buffer_setup;
43677 - video_vbq_ops.buf_prepare = omap_vout_buffer_prepare;
43678 - video_vbq_ops.buf_release = omap_vout_buffer_release;
43679 - video_vbq_ops.buf_queue = omap_vout_buffer_queue;
43680 spin_lock_init(&vout->vbq_lock);
43681
43682 videobuf_queue_dma_contig_init(q, &video_vbq_ops, q->dev,
43683 diff --git a/drivers/media/platform/s5p-tv/mixer.h b/drivers/media/platform/s5p-tv/mixer.h
43684 index fb2acc5..a2fcbdc4 100644
43685 --- a/drivers/media/platform/s5p-tv/mixer.h
43686 +++ b/drivers/media/platform/s5p-tv/mixer.h
43687 @@ -156,7 +156,7 @@ struct mxr_layer {
43688 /** layer index (unique identifier) */
43689 int idx;
43690 /** callbacks for layer methods */
43691 - struct mxr_layer_ops ops;
43692 + struct mxr_layer_ops *ops;
43693 /** format array */
43694 const struct mxr_format **fmt_array;
43695 /** size of format array */
43696 diff --git a/drivers/media/platform/s5p-tv/mixer_grp_layer.c b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
43697 index 74344c7..a39e70e 100644
43698 --- a/drivers/media/platform/s5p-tv/mixer_grp_layer.c
43699 +++ b/drivers/media/platform/s5p-tv/mixer_grp_layer.c
43700 @@ -235,7 +235,7 @@ struct mxr_layer *mxr_graph_layer_create(struct mxr_device *mdev, int idx)
43701 {
43702 struct mxr_layer *layer;
43703 int ret;
43704 - struct mxr_layer_ops ops = {
43705 + static struct mxr_layer_ops ops = {
43706 .release = mxr_graph_layer_release,
43707 .buffer_set = mxr_graph_buffer_set,
43708 .stream_set = mxr_graph_stream_set,
43709 diff --git a/drivers/media/platform/s5p-tv/mixer_reg.c b/drivers/media/platform/s5p-tv/mixer_reg.c
43710 index b713403..53cb5ad 100644
43711 --- a/drivers/media/platform/s5p-tv/mixer_reg.c
43712 +++ b/drivers/media/platform/s5p-tv/mixer_reg.c
43713 @@ -276,7 +276,7 @@ static void mxr_irq_layer_handle(struct mxr_layer *layer)
43714 layer->update_buf = next;
43715 }
43716
43717 - layer->ops.buffer_set(layer, layer->update_buf);
43718 + layer->ops->buffer_set(layer, layer->update_buf);
43719
43720 if (done && done != layer->shadow_buf)
43721 vb2_buffer_done(&done->vb, VB2_BUF_STATE_DONE);
43722 diff --git a/drivers/media/platform/s5p-tv/mixer_video.c b/drivers/media/platform/s5p-tv/mixer_video.c
43723 index 81b97db..b089ccd 100644
43724 --- a/drivers/media/platform/s5p-tv/mixer_video.c
43725 +++ b/drivers/media/platform/s5p-tv/mixer_video.c
43726 @@ -210,7 +210,7 @@ static void mxr_layer_default_geo(struct mxr_layer *layer)
43727 layer->geo.src.height = layer->geo.src.full_height;
43728
43729 mxr_geometry_dump(mdev, &layer->geo);
43730 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43731 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43732 mxr_geometry_dump(mdev, &layer->geo);
43733 }
43734
43735 @@ -228,7 +228,7 @@ static void mxr_layer_update_output(struct mxr_layer *layer)
43736 layer->geo.dst.full_width = mbus_fmt.width;
43737 layer->geo.dst.full_height = mbus_fmt.height;
43738 layer->geo.dst.field = mbus_fmt.field;
43739 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43740 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SINK, 0);
43741
43742 mxr_geometry_dump(mdev, &layer->geo);
43743 }
43744 @@ -334,7 +334,7 @@ static int mxr_s_fmt(struct file *file, void *priv,
43745 /* set source size to highest accepted value */
43746 geo->src.full_width = max(geo->dst.full_width, pix->width);
43747 geo->src.full_height = max(geo->dst.full_height, pix->height);
43748 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43749 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43750 mxr_geometry_dump(mdev, &layer->geo);
43751 /* set cropping to total visible screen */
43752 geo->src.width = pix->width;
43753 @@ -342,12 +342,12 @@ static int mxr_s_fmt(struct file *file, void *priv,
43754 geo->src.x_offset = 0;
43755 geo->src.y_offset = 0;
43756 /* assure consistency of geometry */
43757 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
43758 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_CROP, MXR_NO_OFFSET);
43759 mxr_geometry_dump(mdev, &layer->geo);
43760 /* set full size to lowest possible value */
43761 geo->src.full_width = 0;
43762 geo->src.full_height = 0;
43763 - layer->ops.fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43764 + layer->ops->fix_geometry(layer, MXR_GEOMETRY_SOURCE, 0);
43765 mxr_geometry_dump(mdev, &layer->geo);
43766
43767 /* returning results */
43768 @@ -474,7 +474,7 @@ static int mxr_s_selection(struct file *file, void *fh,
43769 target->width = s->r.width;
43770 target->height = s->r.height;
43771
43772 - layer->ops.fix_geometry(layer, stage, s->flags);
43773 + layer->ops->fix_geometry(layer, stage, s->flags);
43774
43775 /* retrieve update selection rectangle */
43776 res.left = target->x_offset;
43777 @@ -955,13 +955,13 @@ static int start_streaming(struct vb2_queue *vq, unsigned int count)
43778 mxr_output_get(mdev);
43779
43780 mxr_layer_update_output(layer);
43781 - layer->ops.format_set(layer);
43782 + layer->ops->format_set(layer);
43783 /* enabling layer in hardware */
43784 spin_lock_irqsave(&layer->enq_slock, flags);
43785 layer->state = MXR_LAYER_STREAMING;
43786 spin_unlock_irqrestore(&layer->enq_slock, flags);
43787
43788 - layer->ops.stream_set(layer, MXR_ENABLE);
43789 + layer->ops->stream_set(layer, MXR_ENABLE);
43790 mxr_streamer_get(mdev);
43791
43792 return 0;
43793 @@ -1031,7 +1031,7 @@ static int stop_streaming(struct vb2_queue *vq)
43794 spin_unlock_irqrestore(&layer->enq_slock, flags);
43795
43796 /* disabling layer in hardware */
43797 - layer->ops.stream_set(layer, MXR_DISABLE);
43798 + layer->ops->stream_set(layer, MXR_DISABLE);
43799 /* remove one streamer */
43800 mxr_streamer_put(mdev);
43801 /* allow changes in output configuration */
43802 @@ -1070,8 +1070,8 @@ void mxr_base_layer_unregister(struct mxr_layer *layer)
43803
43804 void mxr_layer_release(struct mxr_layer *layer)
43805 {
43806 - if (layer->ops.release)
43807 - layer->ops.release(layer);
43808 + if (layer->ops->release)
43809 + layer->ops->release(layer);
43810 }
43811
43812 void mxr_base_layer_release(struct mxr_layer *layer)
43813 @@ -1097,7 +1097,7 @@ struct mxr_layer *mxr_base_layer_create(struct mxr_device *mdev,
43814
43815 layer->mdev = mdev;
43816 layer->idx = idx;
43817 - layer->ops = *ops;
43818 + layer->ops = ops;
43819
43820 spin_lock_init(&layer->enq_slock);
43821 INIT_LIST_HEAD(&layer->enq_list);
43822 diff --git a/drivers/media/platform/s5p-tv/mixer_vp_layer.c b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43823 index c9388c4..ce71ece 100644
43824 --- a/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43825 +++ b/drivers/media/platform/s5p-tv/mixer_vp_layer.c
43826 @@ -206,7 +206,7 @@ struct mxr_layer *mxr_vp_layer_create(struct mxr_device *mdev, int idx)
43827 {
43828 struct mxr_layer *layer;
43829 int ret;
43830 - struct mxr_layer_ops ops = {
43831 + static struct mxr_layer_ops ops = {
43832 .release = mxr_vp_layer_release,
43833 .buffer_set = mxr_vp_buffer_set,
43834 .stream_set = mxr_vp_stream_set,
43835 diff --git a/drivers/media/platform/vivi.c b/drivers/media/platform/vivi.c
43836 index 2d4e73b..8b4d5b6 100644
43837 --- a/drivers/media/platform/vivi.c
43838 +++ b/drivers/media/platform/vivi.c
43839 @@ -58,8 +58,8 @@ MODULE_AUTHOR("Mauro Carvalho Chehab, Ted Walther and John Sokol");
43840 MODULE_LICENSE("Dual BSD/GPL");
43841 MODULE_VERSION(VIVI_VERSION);
43842
43843 -static unsigned video_nr = -1;
43844 -module_param(video_nr, uint, 0644);
43845 +static int video_nr = -1;
43846 +module_param(video_nr, int, 0644);
43847 MODULE_PARM_DESC(video_nr, "videoX start number, -1 is autodetect");
43848
43849 static unsigned n_devs = 1;
43850 diff --git a/drivers/media/radio/radio-cadet.c b/drivers/media/radio/radio-cadet.c
43851 index 545c04c..a14bded 100644
43852 --- a/drivers/media/radio/radio-cadet.c
43853 +++ b/drivers/media/radio/radio-cadet.c
43854 @@ -324,6 +324,8 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43855 unsigned char readbuf[RDS_BUFFER];
43856 int i = 0;
43857
43858 + if (count > RDS_BUFFER)
43859 + return -EFAULT;
43860 mutex_lock(&dev->lock);
43861 if (dev->rdsstat == 0)
43862 cadet_start_rds(dev);
43863 @@ -339,7 +341,7 @@ static ssize_t cadet_read(struct file *file, char __user *data, size_t count, lo
43864 while (i < count && dev->rdsin != dev->rdsout)
43865 readbuf[i++] = dev->rdsbuf[dev->rdsout++];
43866
43867 - if (i && copy_to_user(data, readbuf, i))
43868 + if (i > sizeof(readbuf) || copy_to_user(data, readbuf, i))
43869 i = -EFAULT;
43870 unlock:
43871 mutex_unlock(&dev->lock);
43872 diff --git a/drivers/media/radio/radio-maxiradio.c b/drivers/media/radio/radio-maxiradio.c
43873 index 5236035..c622c74 100644
43874 --- a/drivers/media/radio/radio-maxiradio.c
43875 +++ b/drivers/media/radio/radio-maxiradio.c
43876 @@ -61,7 +61,7 @@ MODULE_PARM_DESC(radio_nr, "Radio device number");
43877 /* TEA5757 pin mappings */
43878 static const int clk = 1, data = 2, wren = 4, mo_st = 8, power = 16;
43879
43880 -static atomic_t maxiradio_instance = ATOMIC_INIT(0);
43881 +static atomic_unchecked_t maxiradio_instance = ATOMIC_INIT(0);
43882
43883 #define PCI_VENDOR_ID_GUILLEMOT 0x5046
43884 #define PCI_DEVICE_ID_GUILLEMOT_MAXIRADIO 0x1001
43885 diff --git a/drivers/media/radio/radio-shark.c b/drivers/media/radio/radio-shark.c
43886 index 050b3bb..79f62b9 100644
43887 --- a/drivers/media/radio/radio-shark.c
43888 +++ b/drivers/media/radio/radio-shark.c
43889 @@ -79,7 +79,7 @@ struct shark_device {
43890 u32 last_val;
43891 };
43892
43893 -static atomic_t shark_instance = ATOMIC_INIT(0);
43894 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43895
43896 static void shark_write_val(struct snd_tea575x *tea, u32 val)
43897 {
43898 diff --git a/drivers/media/radio/radio-shark2.c b/drivers/media/radio/radio-shark2.c
43899 index 8654e0d..0608a64 100644
43900 --- a/drivers/media/radio/radio-shark2.c
43901 +++ b/drivers/media/radio/radio-shark2.c
43902 @@ -74,7 +74,7 @@ struct shark_device {
43903 u8 *transfer_buffer;
43904 };
43905
43906 -static atomic_t shark_instance = ATOMIC_INIT(0);
43907 +static atomic_unchecked_t shark_instance = ATOMIC_INIT(0);
43908
43909 static int shark_write_reg(struct radio_tea5777 *tea, u64 reg)
43910 {
43911 diff --git a/drivers/media/radio/radio-si476x.c b/drivers/media/radio/radio-si476x.c
43912 index 2fd9009..278cc1e 100644
43913 --- a/drivers/media/radio/radio-si476x.c
43914 +++ b/drivers/media/radio/radio-si476x.c
43915 @@ -1445,7 +1445,7 @@ static int si476x_radio_probe(struct platform_device *pdev)
43916 struct si476x_radio *radio;
43917 struct v4l2_ctrl *ctrl;
43918
43919 - static atomic_t instance = ATOMIC_INIT(0);
43920 + static atomic_unchecked_t instance = ATOMIC_INIT(0);
43921
43922 radio = devm_kzalloc(&pdev->dev, sizeof(*radio), GFP_KERNEL);
43923 if (!radio)
43924 diff --git a/drivers/media/rc/rc-main.c b/drivers/media/rc/rc-main.c
43925 index 46da365..3ba4206 100644
43926 --- a/drivers/media/rc/rc-main.c
43927 +++ b/drivers/media/rc/rc-main.c
43928 @@ -1065,7 +1065,7 @@ EXPORT_SYMBOL_GPL(rc_free_device);
43929 int rc_register_device(struct rc_dev *dev)
43930 {
43931 static bool raw_init = false; /* raw decoders loaded? */
43932 - static atomic_t devno = ATOMIC_INIT(0);
43933 + static atomic_unchecked_t devno = ATOMIC_INIT(0);
43934 struct rc_map *rc_map;
43935 const char *path;
43936 int rc;
43937 @@ -1096,7 +1096,7 @@ int rc_register_device(struct rc_dev *dev)
43938 */
43939 mutex_lock(&dev->lock);
43940
43941 - dev->devno = (unsigned long)(atomic_inc_return(&devno) - 1);
43942 + dev->devno = (unsigned long)(atomic_inc_return_unchecked(&devno) - 1);
43943 dev_set_name(&dev->dev, "rc%ld", dev->devno);
43944 dev_set_drvdata(&dev->dev, dev);
43945 rc = device_add(&dev->dev);
43946 diff --git a/drivers/media/usb/dvb-usb/cxusb.c b/drivers/media/usb/dvb-usb/cxusb.c
43947 index 20e345d..da56fe4 100644
43948 --- a/drivers/media/usb/dvb-usb/cxusb.c
43949 +++ b/drivers/media/usb/dvb-usb/cxusb.c
43950 @@ -1101,7 +1101,7 @@ static struct dib0070_config dib7070p_dib0070_config = {
43951
43952 struct dib0700_adapter_state {
43953 int (*set_param_save) (struct dvb_frontend *);
43954 -};
43955 +} __no_const;
43956
43957 static int dib7070_set_param_override(struct dvb_frontend *fe)
43958 {
43959 diff --git a/drivers/media/usb/dvb-usb/dw2102.c b/drivers/media/usb/dvb-usb/dw2102.c
43960 index c1a63b2..dbcbfb6 100644
43961 --- a/drivers/media/usb/dvb-usb/dw2102.c
43962 +++ b/drivers/media/usb/dvb-usb/dw2102.c
43963 @@ -121,7 +121,7 @@ struct su3000_state {
43964
43965 struct s6x0_state {
43966 int (*old_set_voltage)(struct dvb_frontend *f, fe_sec_voltage_t v);
43967 -};
43968 +} __no_const;
43969
43970 /* debug */
43971 static int dvb_usb_dw2102_debug;
43972 diff --git a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43973 index 8f7a6a4..eb0e1d4 100644
43974 --- a/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43975 +++ b/drivers/media/v4l2-core/v4l2-compat-ioctl32.c
43976 @@ -326,7 +326,7 @@ struct v4l2_buffer32 {
43977 __u32 reserved;
43978 };
43979
43980 -static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43981 +static int get_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43982 enum v4l2_memory memory)
43983 {
43984 void __user *up_pln;
43985 @@ -355,7 +355,7 @@ static int get_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43986 return 0;
43987 }
43988
43989 -static int put_v4l2_plane32(struct v4l2_plane *up, struct v4l2_plane32 *up32,
43990 +static int put_v4l2_plane32(struct v4l2_plane __user *up, struct v4l2_plane32 __user *up32,
43991 enum v4l2_memory memory)
43992 {
43993 if (copy_in_user(up32, up, 2 * sizeof(__u32)) ||
43994 @@ -425,7 +425,7 @@ static int get_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
43995 * by passing a very big num_planes value */
43996 uplane = compat_alloc_user_space(num_planes *
43997 sizeof(struct v4l2_plane));
43998 - kp->m.planes = uplane;
43999 + kp->m.planes = (struct v4l2_plane __force_kernel *)uplane;
44000
44001 while (--num_planes >= 0) {
44002 ret = get_v4l2_plane32(uplane, uplane32, kp->memory);
44003 @@ -496,7 +496,7 @@ static int put_v4l2_buffer32(struct v4l2_buffer *kp, struct v4l2_buffer32 __user
44004 if (num_planes == 0)
44005 return 0;
44006
44007 - uplane = kp->m.planes;
44008 + uplane = (struct v4l2_plane __force_user *)kp->m.planes;
44009 if (get_user(p, &up->m.planes))
44010 return -EFAULT;
44011 uplane32 = compat_ptr(p);
44012 @@ -550,7 +550,7 @@ static int get_v4l2_framebuffer32(struct v4l2_framebuffer *kp, struct v4l2_frame
44013 get_user(kp->capability, &up->capability) ||
44014 get_user(kp->flags, &up->flags))
44015 return -EFAULT;
44016 - kp->base = compat_ptr(tmp);
44017 + kp->base = (void __force_kernel *)compat_ptr(tmp);
44018 get_v4l2_pix_format(&kp->fmt, &up->fmt);
44019 return 0;
44020 }
44021 @@ -656,7 +656,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44022 n * sizeof(struct v4l2_ext_control32)))
44023 return -EFAULT;
44024 kcontrols = compat_alloc_user_space(n * sizeof(struct v4l2_ext_control));
44025 - kp->controls = kcontrols;
44026 + kp->controls = (struct v4l2_ext_control __force_kernel *)kcontrols;
44027 while (--n >= 0) {
44028 if (copy_in_user(kcontrols, ucontrols, sizeof(*ucontrols)))
44029 return -EFAULT;
44030 @@ -678,7 +678,7 @@ static int get_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext
44031 static int put_v4l2_ext_controls32(struct v4l2_ext_controls *kp, struct v4l2_ext_controls32 __user *up)
44032 {
44033 struct v4l2_ext_control32 __user *ucontrols;
44034 - struct v4l2_ext_control __user *kcontrols = kp->controls;
44035 + struct v4l2_ext_control __user *kcontrols = (struct v4l2_ext_control __force_user *)kp->controls;
44036 int n = kp->count;
44037 compat_caddr_t p;
44038
44039 @@ -772,7 +772,7 @@ static int put_v4l2_subdev_edid32(struct v4l2_subdev_edid *kp, struct v4l2_subde
44040 put_user(kp->start_block, &up->start_block) ||
44041 put_user(kp->blocks, &up->blocks) ||
44042 put_user(tmp, &up->edid) ||
44043 - copy_to_user(kp->reserved, up->reserved, sizeof(kp->reserved)))
44044 + copy_to_user(up->reserved, kp->reserved, sizeof(kp->reserved)))
44045 return -EFAULT;
44046 return 0;
44047 }
44048 diff --git a/drivers/media/v4l2-core/v4l2-ctrls.c b/drivers/media/v4l2-core/v4l2-ctrls.c
44049 index fb46790..ae1f8fa 100644
44050 --- a/drivers/media/v4l2-core/v4l2-ctrls.c
44051 +++ b/drivers/media/v4l2-core/v4l2-ctrls.c
44052 @@ -1396,8 +1396,8 @@ static int validate_new(const struct v4l2_ctrl *ctrl,
44053 return 0;
44054
44055 case V4L2_CTRL_TYPE_STRING:
44056 - len = strlen(c->string);
44057 - if (len < ctrl->minimum)
44058 + len = strlen_user(c->string);
44059 + if (!len || len < ctrl->minimum)
44060 return -ERANGE;
44061 if ((len - ctrl->minimum) % ctrl->step)
44062 return -ERANGE;
44063 diff --git a/drivers/media/v4l2-core/v4l2-device.c b/drivers/media/v4l2-core/v4l2-device.c
44064 index 02d1b63..5fd6b16 100644
44065 --- a/drivers/media/v4l2-core/v4l2-device.c
44066 +++ b/drivers/media/v4l2-core/v4l2-device.c
44067 @@ -75,9 +75,9 @@ int v4l2_device_put(struct v4l2_device *v4l2_dev)
44068 EXPORT_SYMBOL_GPL(v4l2_device_put);
44069
44070 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
44071 - atomic_t *instance)
44072 + atomic_unchecked_t *instance)
44073 {
44074 - int num = atomic_inc_return(instance) - 1;
44075 + int num = atomic_inc_return_unchecked(instance) - 1;
44076 int len = strlen(basename);
44077
44078 if (basename[len - 1] >= '0' && basename[len - 1] <= '9')
44079 diff --git a/drivers/media/v4l2-core/v4l2-ioctl.c b/drivers/media/v4l2-core/v4l2-ioctl.c
44080 index 68e6b5e..8eb2aec 100644
44081 --- a/drivers/media/v4l2-core/v4l2-ioctl.c
44082 +++ b/drivers/media/v4l2-core/v4l2-ioctl.c
44083 @@ -1939,7 +1939,8 @@ struct v4l2_ioctl_info {
44084 struct file *file, void *fh, void *p);
44085 } u;
44086 void (*debug)(const void *arg, bool write_only);
44087 -};
44088 +} __do_const;
44089 +typedef struct v4l2_ioctl_info __no_const v4l2_ioctl_info_no_const;
44090
44091 /* This control needs a priority check */
44092 #define INFO_FL_PRIO (1 << 0)
44093 @@ -2120,7 +2121,7 @@ static long __video_do_ioctl(struct file *file,
44094 struct video_device *vfd = video_devdata(file);
44095 const struct v4l2_ioctl_ops *ops = vfd->ioctl_ops;
44096 bool write_only = false;
44097 - struct v4l2_ioctl_info default_info;
44098 + v4l2_ioctl_info_no_const default_info;
44099 const struct v4l2_ioctl_info *info;
44100 void *fh = file->private_data;
44101 struct v4l2_fh *vfh = NULL;
44102 @@ -2194,7 +2195,7 @@ done:
44103 }
44104
44105 static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44106 - void * __user *user_ptr, void ***kernel_ptr)
44107 + void __user **user_ptr, void ***kernel_ptr)
44108 {
44109 int ret = 0;
44110
44111 @@ -2210,7 +2211,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44112 ret = -EINVAL;
44113 break;
44114 }
44115 - *user_ptr = (void __user *)buf->m.planes;
44116 + *user_ptr = (void __force_user *)buf->m.planes;
44117 *kernel_ptr = (void *)&buf->m.planes;
44118 *array_size = sizeof(struct v4l2_plane) * buf->length;
44119 ret = 1;
44120 @@ -2245,7 +2246,7 @@ static int check_array_args(unsigned int cmd, void *parg, size_t *array_size,
44121 ret = -EINVAL;
44122 break;
44123 }
44124 - *user_ptr = (void __user *)ctrls->controls;
44125 + *user_ptr = (void __force_user *)ctrls->controls;
44126 *kernel_ptr = (void *)&ctrls->controls;
44127 *array_size = sizeof(struct v4l2_ext_control)
44128 * ctrls->count;
44129 @@ -2340,7 +2341,7 @@ video_usercopy(struct file *file, unsigned int cmd, unsigned long arg,
44130 err = -ENOTTY;
44131
44132 if (has_array_args) {
44133 - *kernel_ptr = user_ptr;
44134 + *kernel_ptr = (void __force_kernel *)user_ptr;
44135 if (copy_to_user(user_ptr, mbuf, array_size))
44136 err = -EFAULT;
44137 goto out_array_args;
44138 diff --git a/drivers/message/fusion/mptbase.c b/drivers/message/fusion/mptbase.c
44139 index 767ff4d..c69d259 100644
44140 --- a/drivers/message/fusion/mptbase.c
44141 +++ b/drivers/message/fusion/mptbase.c
44142 @@ -6755,8 +6755,13 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44143 seq_printf(m, " MaxChainDepth = 0x%02x frames\n", ioc->facts.MaxChainDepth);
44144 seq_printf(m, " MinBlockSize = 0x%02x bytes\n", 4*ioc->facts.BlockSize);
44145
44146 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44147 + seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n", NULL, NULL);
44148 +#else
44149 seq_printf(m, " RequestFrames @ 0x%p (Dma @ 0x%p)\n",
44150 (void *)ioc->req_frames, (void *)(ulong)ioc->req_frames_dma);
44151 +#endif
44152 +
44153 /*
44154 * Rounding UP to nearest 4-kB boundary here...
44155 */
44156 @@ -6769,7 +6774,11 @@ static int mpt_iocinfo_proc_show(struct seq_file *m, void *v)
44157 ioc->facts.GlobalCredits);
44158
44159 seq_printf(m, " Frames @ 0x%p (Dma @ 0x%p)\n",
44160 +#ifdef CONFIG_GRKERNSEC_HIDESYM
44161 + NULL, NULL);
44162 +#else
44163 (void *)ioc->alloc, (void *)(ulong)ioc->alloc_dma);
44164 +#endif
44165 sz = (ioc->reply_sz * ioc->reply_depth) + 128;
44166 seq_printf(m, " {CurRepSz=%d} x {CurRepDepth=%d} = %d bytes ^= 0x%x\n",
44167 ioc->reply_sz, ioc->reply_depth, ioc->reply_sz*ioc->reply_depth, sz);
44168 diff --git a/drivers/message/fusion/mptsas.c b/drivers/message/fusion/mptsas.c
44169 index dd239bd..689c4f7 100644
44170 --- a/drivers/message/fusion/mptsas.c
44171 +++ b/drivers/message/fusion/mptsas.c
44172 @@ -446,6 +446,23 @@ mptsas_is_end_device(struct mptsas_devinfo * attached)
44173 return 0;
44174 }
44175
44176 +static inline void
44177 +mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44178 +{
44179 + if (phy_info->port_details) {
44180 + phy_info->port_details->rphy = rphy;
44181 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44182 + ioc->name, rphy));
44183 + }
44184 +
44185 + if (rphy) {
44186 + dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44187 + &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44188 + dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44189 + ioc->name, rphy, rphy->dev.release));
44190 + }
44191 +}
44192 +
44193 /* no mutex */
44194 static void
44195 mptsas_port_delete(MPT_ADAPTER *ioc, struct mptsas_portinfo_details * port_details)
44196 @@ -484,23 +501,6 @@ mptsas_get_rphy(struct mptsas_phyinfo *phy_info)
44197 return NULL;
44198 }
44199
44200 -static inline void
44201 -mptsas_set_rphy(MPT_ADAPTER *ioc, struct mptsas_phyinfo *phy_info, struct sas_rphy *rphy)
44202 -{
44203 - if (phy_info->port_details) {
44204 - phy_info->port_details->rphy = rphy;
44205 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "sas_rphy_add: rphy=%p\n",
44206 - ioc->name, rphy));
44207 - }
44208 -
44209 - if (rphy) {
44210 - dsaswideprintk(ioc, dev_printk(KERN_DEBUG,
44211 - &rphy->dev, MYIOC_s_FMT "add:", ioc->name));
44212 - dsaswideprintk(ioc, printk(MYIOC_s_DEBUG_FMT "rphy=%p release=%p\n",
44213 - ioc->name, rphy, rphy->dev.release));
44214 - }
44215 -}
44216 -
44217 static inline struct sas_port *
44218 mptsas_get_port(struct mptsas_phyinfo *phy_info)
44219 {
44220 diff --git a/drivers/message/fusion/mptscsih.c b/drivers/message/fusion/mptscsih.c
44221 index 727819c..ad74694 100644
44222 --- a/drivers/message/fusion/mptscsih.c
44223 +++ b/drivers/message/fusion/mptscsih.c
44224 @@ -1271,15 +1271,16 @@ mptscsih_info(struct Scsi_Host *SChost)
44225
44226 h = shost_priv(SChost);
44227
44228 - if (h) {
44229 - if (h->info_kbuf == NULL)
44230 - if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44231 - return h->info_kbuf;
44232 - h->info_kbuf[0] = '\0';
44233 + if (!h)
44234 + return NULL;
44235
44236 - mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44237 - h->info_kbuf[size-1] = '\0';
44238 - }
44239 + if (h->info_kbuf == NULL)
44240 + if ((h->info_kbuf = kmalloc(0x1000 /* 4Kb */, GFP_KERNEL)) == NULL)
44241 + return h->info_kbuf;
44242 + h->info_kbuf[0] = '\0';
44243 +
44244 + mpt_print_ioc_summary(h->ioc, h->info_kbuf, &size, 0, 0);
44245 + h->info_kbuf[size-1] = '\0';
44246
44247 return h->info_kbuf;
44248 }
44249 diff --git a/drivers/message/i2o/i2o_proc.c b/drivers/message/i2o/i2o_proc.c
44250 index b7d87cd..3fb36da 100644
44251 --- a/drivers/message/i2o/i2o_proc.c
44252 +++ b/drivers/message/i2o/i2o_proc.c
44253 @@ -255,12 +255,6 @@ static char *scsi_devices[] = {
44254 "Array Controller Device"
44255 };
44256
44257 -static char *chtostr(char *tmp, u8 *chars, int n)
44258 -{
44259 - tmp[0] = 0;
44260 - return strncat(tmp, (char *)chars, n);
44261 -}
44262 -
44263 static int i2o_report_query_status(struct seq_file *seq, int block_status,
44264 char *group)
44265 {
44266 @@ -707,9 +701,9 @@ static int i2o_seq_show_status(struct seq_file *seq, void *v)
44267 static int i2o_seq_show_hw(struct seq_file *seq, void *v)
44268 {
44269 struct i2o_controller *c = (struct i2o_controller *)seq->private;
44270 - static u32 work32[5];
44271 - static u8 *work8 = (u8 *) work32;
44272 - static u16 *work16 = (u16 *) work32;
44273 + u32 work32[5];
44274 + u8 *work8 = (u8 *) work32;
44275 + u16 *work16 = (u16 *) work32;
44276 int token;
44277 u32 hwcap;
44278
44279 @@ -790,7 +784,6 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44280 } *result;
44281
44282 i2o_exec_execute_ddm_table ddm_table;
44283 - char tmp[28 + 1];
44284
44285 result = kmalloc(sizeof(*result), GFP_KERNEL);
44286 if (!result)
44287 @@ -825,8 +818,7 @@ static int i2o_seq_show_ddm_table(struct seq_file *seq, void *v)
44288
44289 seq_printf(seq, "%-#7x", ddm_table.i2o_vendor_id);
44290 seq_printf(seq, "%-#8x", ddm_table.module_id);
44291 - seq_printf(seq, "%-29s",
44292 - chtostr(tmp, ddm_table.module_name_version, 28));
44293 + seq_printf(seq, "%-.28s", ddm_table.module_name_version);
44294 seq_printf(seq, "%9d ", ddm_table.data_size);
44295 seq_printf(seq, "%8d", ddm_table.code_size);
44296
44297 @@ -893,7 +885,6 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44298
44299 i2o_driver_result_table *result;
44300 i2o_driver_store_table *dst;
44301 - char tmp[28 + 1];
44302
44303 result = kmalloc(sizeof(i2o_driver_result_table), GFP_KERNEL);
44304 if (result == NULL)
44305 @@ -928,9 +919,8 @@ static int i2o_seq_show_drivers_stored(struct seq_file *seq, void *v)
44306
44307 seq_printf(seq, "%-#7x", dst->i2o_vendor_id);
44308 seq_printf(seq, "%-#8x", dst->module_id);
44309 - seq_printf(seq, "%-29s",
44310 - chtostr(tmp, dst->module_name_version, 28));
44311 - seq_printf(seq, "%-9s", chtostr(tmp, dst->date, 8));
44312 + seq_printf(seq, "%-.28s", dst->module_name_version);
44313 + seq_printf(seq, "%-.8s", dst->date);
44314 seq_printf(seq, "%8d ", dst->module_size);
44315 seq_printf(seq, "%8d ", dst->mpb_size);
44316 seq_printf(seq, "0x%04x", dst->module_flags);
44317 @@ -1246,11 +1236,10 @@ static int i2o_seq_show_authorized_users(struct seq_file *seq, void *v)
44318 static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44319 {
44320 struct i2o_device *d = (struct i2o_device *)seq->private;
44321 - static u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44322 + u32 work32[128]; // allow for "stuff" + up to 256 byte (max) serial number
44323 // == (allow) 512d bytes (max)
44324 - static u16 *work16 = (u16 *) work32;
44325 + u16 *work16 = (u16 *) work32;
44326 int token;
44327 - char tmp[16 + 1];
44328
44329 token = i2o_parm_field_get(d, 0xF100, -1, &work32, sizeof(work32));
44330
44331 @@ -1262,14 +1251,10 @@ static int i2o_seq_show_dev_identity(struct seq_file *seq, void *v)
44332 seq_printf(seq, "Device Class : %s\n", i2o_get_class_name(work16[0]));
44333 seq_printf(seq, "Owner TID : %0#5x\n", work16[2]);
44334 seq_printf(seq, "Parent TID : %0#5x\n", work16[3]);
44335 - seq_printf(seq, "Vendor info : %s\n",
44336 - chtostr(tmp, (u8 *) (work32 + 2), 16));
44337 - seq_printf(seq, "Product info : %s\n",
44338 - chtostr(tmp, (u8 *) (work32 + 6), 16));
44339 - seq_printf(seq, "Description : %s\n",
44340 - chtostr(tmp, (u8 *) (work32 + 10), 16));
44341 - seq_printf(seq, "Product rev. : %s\n",
44342 - chtostr(tmp, (u8 *) (work32 + 14), 8));
44343 + seq_printf(seq, "Vendor info : %.16s\n", (u8 *) (work32 + 2));
44344 + seq_printf(seq, "Product info : %.16s\n", (u8 *) (work32 + 6));
44345 + seq_printf(seq, "Description : %.16s\n", (u8 *) (work32 + 10));
44346 + seq_printf(seq, "Product rev. : %.8s\n", (u8 *) (work32 + 14));
44347
44348 seq_printf(seq, "Serial number : ");
44349 print_serial_number(seq, (u8 *) (work32 + 16),
44350 @@ -1306,8 +1291,6 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44351 u8 pad[256]; // allow up to 256 byte (max) serial number
44352 } result;
44353
44354 - char tmp[24 + 1];
44355 -
44356 token = i2o_parm_field_get(d, 0xF101, -1, &result, sizeof(result));
44357
44358 if (token < 0) {
44359 @@ -1316,10 +1299,8 @@ static int i2o_seq_show_ddm_identity(struct seq_file *seq, void *v)
44360 }
44361
44362 seq_printf(seq, "Registering DDM TID : 0x%03x\n", result.ddm_tid);
44363 - seq_printf(seq, "Module name : %s\n",
44364 - chtostr(tmp, result.module_name, 24));
44365 - seq_printf(seq, "Module revision : %s\n",
44366 - chtostr(tmp, result.module_rev, 8));
44367 + seq_printf(seq, "Module name : %.24s\n", result.module_name);
44368 + seq_printf(seq, "Module revision : %.8s\n", result.module_rev);
44369
44370 seq_printf(seq, "Serial number : ");
44371 print_serial_number(seq, result.serial_number, sizeof(result) - 36);
44372 @@ -1343,8 +1324,6 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44373 u8 instance_number[4];
44374 } result;
44375
44376 - char tmp[64 + 1];
44377 -
44378 token = i2o_parm_field_get(d, 0xF102, -1, &result, sizeof(result));
44379
44380 if (token < 0) {
44381 @@ -1352,14 +1331,10 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44382 return 0;
44383 }
44384
44385 - seq_printf(seq, "Device name : %s\n",
44386 - chtostr(tmp, result.device_name, 64));
44387 - seq_printf(seq, "Service name : %s\n",
44388 - chtostr(tmp, result.service_name, 64));
44389 - seq_printf(seq, "Physical name : %s\n",
44390 - chtostr(tmp, result.physical_location, 64));
44391 - seq_printf(seq, "Instance number : %s\n",
44392 - chtostr(tmp, result.instance_number, 4));
44393 + seq_printf(seq, "Device name : %.64s\n", result.device_name);
44394 + seq_printf(seq, "Service name : %.64s\n", result.service_name);
44395 + seq_printf(seq, "Physical name : %.64s\n", result.physical_location);
44396 + seq_printf(seq, "Instance number : %.4s\n", result.instance_number);
44397
44398 return 0;
44399 }
44400 @@ -1368,9 +1343,9 @@ static int i2o_seq_show_uinfo(struct seq_file *seq, void *v)
44401 static int i2o_seq_show_sgl_limits(struct seq_file *seq, void *v)
44402 {
44403 struct i2o_device *d = (struct i2o_device *)seq->private;
44404 - static u32 work32[12];
44405 - static u16 *work16 = (u16 *) work32;
44406 - static u8 *work8 = (u8 *) work32;
44407 + u32 work32[12];
44408 + u16 *work16 = (u16 *) work32;
44409 + u8 *work8 = (u8 *) work32;
44410 int token;
44411
44412 token = i2o_parm_field_get(d, 0xF103, -1, &work32, sizeof(work32));
44413 diff --git a/drivers/message/i2o/iop.c b/drivers/message/i2o/iop.c
44414 index a8c08f3..155fe3d 100644
44415 --- a/drivers/message/i2o/iop.c
44416 +++ b/drivers/message/i2o/iop.c
44417 @@ -111,10 +111,10 @@ u32 i2o_cntxt_list_add(struct i2o_controller * c, void *ptr)
44418
44419 spin_lock_irqsave(&c->context_list_lock, flags);
44420
44421 - if (unlikely(atomic_inc_and_test(&c->context_list_counter)))
44422 - atomic_inc(&c->context_list_counter);
44423 + if (unlikely(atomic_inc_and_test_unchecked(&c->context_list_counter)))
44424 + atomic_inc_unchecked(&c->context_list_counter);
44425
44426 - entry->context = atomic_read(&c->context_list_counter);
44427 + entry->context = atomic_read_unchecked(&c->context_list_counter);
44428
44429 list_add(&entry->list, &c->context_list);
44430
44431 @@ -1077,7 +1077,7 @@ struct i2o_controller *i2o_iop_alloc(void)
44432
44433 #if BITS_PER_LONG == 64
44434 spin_lock_init(&c->context_list_lock);
44435 - atomic_set(&c->context_list_counter, 0);
44436 + atomic_set_unchecked(&c->context_list_counter, 0);
44437 INIT_LIST_HEAD(&c->context_list);
44438 #endif
44439
44440 diff --git a/drivers/mfd/janz-cmodio.c b/drivers/mfd/janz-cmodio.c
44441 index fcbb2e9..2635e11 100644
44442 --- a/drivers/mfd/janz-cmodio.c
44443 +++ b/drivers/mfd/janz-cmodio.c
44444 @@ -13,6 +13,7 @@
44445
44446 #include <linux/kernel.h>
44447 #include <linux/module.h>
44448 +#include <linux/slab.h>
44449 #include <linux/init.h>
44450 #include <linux/pci.h>
44451 #include <linux/interrupt.h>
44452 diff --git a/drivers/mfd/max8925-i2c.c b/drivers/mfd/max8925-i2c.c
44453 index 176aa26..27811b2 100644
44454 --- a/drivers/mfd/max8925-i2c.c
44455 +++ b/drivers/mfd/max8925-i2c.c
44456 @@ -152,7 +152,7 @@ static int max8925_probe(struct i2c_client *client,
44457 const struct i2c_device_id *id)
44458 {
44459 struct max8925_platform_data *pdata = dev_get_platdata(&client->dev);
44460 - static struct max8925_chip *chip;
44461 + struct max8925_chip *chip;
44462 struct device_node *node = client->dev.of_node;
44463
44464 if (node && !pdata) {
44465 diff --git a/drivers/mfd/tps65910.c b/drivers/mfd/tps65910.c
44466 index c0f608e..286f8ec 100644
44467 --- a/drivers/mfd/tps65910.c
44468 +++ b/drivers/mfd/tps65910.c
44469 @@ -230,7 +230,7 @@ static int tps65910_irq_init(struct tps65910 *tps65910, int irq,
44470 struct tps65910_platform_data *pdata)
44471 {
44472 int ret = 0;
44473 - static struct regmap_irq_chip *tps6591x_irqs_chip;
44474 + struct regmap_irq_chip *tps6591x_irqs_chip;
44475
44476 if (!irq) {
44477 dev_warn(tps65910->dev, "No interrupt support, no core IRQ\n");
44478 diff --git a/drivers/mfd/twl4030-irq.c b/drivers/mfd/twl4030-irq.c
44479 index 9aa6d1e..1631bfc 100644
44480 --- a/drivers/mfd/twl4030-irq.c
44481 +++ b/drivers/mfd/twl4030-irq.c
44482 @@ -35,6 +35,7 @@
44483 #include <linux/of.h>
44484 #include <linux/irqdomain.h>
44485 #include <linux/i2c/twl.h>
44486 +#include <asm/pgtable.h>
44487
44488 #include "twl-core.h"
44489
44490 @@ -726,10 +727,12 @@ int twl4030_init_irq(struct device *dev, int irq_num)
44491 * Install an irq handler for each of the SIH modules;
44492 * clone dummy irq_chip since PIH can't *do* anything
44493 */
44494 - twl4030_irq_chip = dummy_irq_chip;
44495 - twl4030_irq_chip.name = "twl4030";
44496 + pax_open_kernel();
44497 + memcpy((void *)&twl4030_irq_chip, &dummy_irq_chip, sizeof twl4030_irq_chip);
44498 + *(const char **)&twl4030_irq_chip.name = "twl4030";
44499
44500 - twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
44501 + *(void **)&twl4030_sih_irq_chip.irq_ack = dummy_irq_chip.irq_ack;
44502 + pax_close_kernel();
44503
44504 for (i = irq_base; i < irq_end; i++) {
44505 irq_set_chip_and_handler(i, &twl4030_irq_chip,
44506 diff --git a/drivers/misc/c2port/core.c b/drivers/misc/c2port/core.c
44507 index 464419b..64bae8d 100644
44508 --- a/drivers/misc/c2port/core.c
44509 +++ b/drivers/misc/c2port/core.c
44510 @@ -922,7 +922,9 @@ struct c2port_device *c2port_device_register(char *name,
44511 goto error_idr_alloc;
44512 c2dev->id = ret;
44513
44514 - bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
44515 + pax_open_kernel();
44516 + *(size_t *)&bin_attr_flash_data.size = ops->blocks_num * ops->block_size;
44517 + pax_close_kernel();
44518
44519 c2dev->dev = device_create(c2port_class, NULL, 0, c2dev,
44520 "c2port%d", c2dev->id);
44521 diff --git a/drivers/misc/eeprom/sunxi_sid.c b/drivers/misc/eeprom/sunxi_sid.c
44522 index 9c34e57..b981cda 100644
44523 --- a/drivers/misc/eeprom/sunxi_sid.c
44524 +++ b/drivers/misc/eeprom/sunxi_sid.c
44525 @@ -127,7 +127,9 @@ static int sunxi_sid_probe(struct platform_device *pdev)
44526
44527 platform_set_drvdata(pdev, sid_data);
44528
44529 - sid_bin_attr.size = sid_data->keysize;
44530 + pax_open_kernel();
44531 + *(size_t *)&sid_bin_attr.size = sid_data->keysize;
44532 + pax_close_kernel();
44533 if (device_create_bin_file(&pdev->dev, &sid_bin_attr))
44534 return -ENODEV;
44535
44536 diff --git a/drivers/misc/kgdbts.c b/drivers/misc/kgdbts.c
44537 index 36f5d52..32311c3 100644
44538 --- a/drivers/misc/kgdbts.c
44539 +++ b/drivers/misc/kgdbts.c
44540 @@ -834,7 +834,7 @@ static void run_plant_and_detach_test(int is_early)
44541 char before[BREAK_INSTR_SIZE];
44542 char after[BREAK_INSTR_SIZE];
44543
44544 - probe_kernel_read(before, (char *)kgdbts_break_test,
44545 + probe_kernel_read(before, ktla_ktva((char *)kgdbts_break_test),
44546 BREAK_INSTR_SIZE);
44547 init_simple_test();
44548 ts.tst = plant_and_detach_test;
44549 @@ -842,7 +842,7 @@ static void run_plant_and_detach_test(int is_early)
44550 /* Activate test with initial breakpoint */
44551 if (!is_early)
44552 kgdb_breakpoint();
44553 - probe_kernel_read(after, (char *)kgdbts_break_test,
44554 + probe_kernel_read(after, ktla_ktva((char *)kgdbts_break_test),
44555 BREAK_INSTR_SIZE);
44556 if (memcmp(before, after, BREAK_INSTR_SIZE)) {
44557 printk(KERN_CRIT "kgdbts: ERROR kgdb corrupted memory\n");
44558 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.c b/drivers/misc/lis3lv02d/lis3lv02d.c
44559 index 036effe..b3a6336 100644
44560 --- a/drivers/misc/lis3lv02d/lis3lv02d.c
44561 +++ b/drivers/misc/lis3lv02d/lis3lv02d.c
44562 @@ -498,7 +498,7 @@ static irqreturn_t lis302dl_interrupt(int irq, void *data)
44563 * the lid is closed. This leads to interrupts as soon as a little move
44564 * is done.
44565 */
44566 - atomic_inc(&lis3->count);
44567 + atomic_inc_unchecked(&lis3->count);
44568
44569 wake_up_interruptible(&lis3->misc_wait);
44570 kill_fasync(&lis3->async_queue, SIGIO, POLL_IN);
44571 @@ -584,7 +584,7 @@ static int lis3lv02d_misc_open(struct inode *inode, struct file *file)
44572 if (lis3->pm_dev)
44573 pm_runtime_get_sync(lis3->pm_dev);
44574
44575 - atomic_set(&lis3->count, 0);
44576 + atomic_set_unchecked(&lis3->count, 0);
44577 return 0;
44578 }
44579
44580 @@ -616,7 +616,7 @@ static ssize_t lis3lv02d_misc_read(struct file *file, char __user *buf,
44581 add_wait_queue(&lis3->misc_wait, &wait);
44582 while (true) {
44583 set_current_state(TASK_INTERRUPTIBLE);
44584 - data = atomic_xchg(&lis3->count, 0);
44585 + data = atomic_xchg_unchecked(&lis3->count, 0);
44586 if (data)
44587 break;
44588
44589 @@ -657,7 +657,7 @@ static unsigned int lis3lv02d_misc_poll(struct file *file, poll_table *wait)
44590 struct lis3lv02d, miscdev);
44591
44592 poll_wait(file, &lis3->misc_wait, wait);
44593 - if (atomic_read(&lis3->count))
44594 + if (atomic_read_unchecked(&lis3->count))
44595 return POLLIN | POLLRDNORM;
44596 return 0;
44597 }
44598 diff --git a/drivers/misc/lis3lv02d/lis3lv02d.h b/drivers/misc/lis3lv02d/lis3lv02d.h
44599 index c439c82..1f20f57 100644
44600 --- a/drivers/misc/lis3lv02d/lis3lv02d.h
44601 +++ b/drivers/misc/lis3lv02d/lis3lv02d.h
44602 @@ -297,7 +297,7 @@ struct lis3lv02d {
44603 struct input_polled_dev *idev; /* input device */
44604 struct platform_device *pdev; /* platform device */
44605 struct regulator_bulk_data regulators[2];
44606 - atomic_t count; /* interrupt count after last read */
44607 + atomic_unchecked_t count; /* interrupt count after last read */
44608 union axis_conversion ac; /* hw -> logical axis */
44609 int mapped_btns[3];
44610
44611 diff --git a/drivers/misc/sgi-gru/gruhandles.c b/drivers/misc/sgi-gru/gruhandles.c
44612 index 2f30bad..c4c13d0 100644
44613 --- a/drivers/misc/sgi-gru/gruhandles.c
44614 +++ b/drivers/misc/sgi-gru/gruhandles.c
44615 @@ -44,8 +44,8 @@ static void update_mcs_stats(enum mcs_op op, unsigned long clks)
44616 unsigned long nsec;
44617
44618 nsec = CLKS2NSEC(clks);
44619 - atomic_long_inc(&mcs_op_statistics[op].count);
44620 - atomic_long_add(nsec, &mcs_op_statistics[op].total);
44621 + atomic_long_inc_unchecked(&mcs_op_statistics[op].count);
44622 + atomic_long_add_unchecked(nsec, &mcs_op_statistics[op].total);
44623 if (mcs_op_statistics[op].max < nsec)
44624 mcs_op_statistics[op].max = nsec;
44625 }
44626 diff --git a/drivers/misc/sgi-gru/gruprocfs.c b/drivers/misc/sgi-gru/gruprocfs.c
44627 index 4f76359..cdfcb2e 100644
44628 --- a/drivers/misc/sgi-gru/gruprocfs.c
44629 +++ b/drivers/misc/sgi-gru/gruprocfs.c
44630 @@ -32,9 +32,9 @@
44631
44632 #define printstat(s, f) printstat_val(s, &gru_stats.f, #f)
44633
44634 -static void printstat_val(struct seq_file *s, atomic_long_t *v, char *id)
44635 +static void printstat_val(struct seq_file *s, atomic_long_unchecked_t *v, char *id)
44636 {
44637 - unsigned long val = atomic_long_read(v);
44638 + unsigned long val = atomic_long_read_unchecked(v);
44639
44640 seq_printf(s, "%16lu %s\n", val, id);
44641 }
44642 @@ -134,8 +134,8 @@ static int mcs_statistics_show(struct seq_file *s, void *p)
44643
44644 seq_printf(s, "%-20s%12s%12s%12s\n", "#id", "count", "aver-clks", "max-clks");
44645 for (op = 0; op < mcsop_last; op++) {
44646 - count = atomic_long_read(&mcs_op_statistics[op].count);
44647 - total = atomic_long_read(&mcs_op_statistics[op].total);
44648 + count = atomic_long_read_unchecked(&mcs_op_statistics[op].count);
44649 + total = atomic_long_read_unchecked(&mcs_op_statistics[op].total);
44650 max = mcs_op_statistics[op].max;
44651 seq_printf(s, "%-20s%12ld%12ld%12ld\n", id[op], count,
44652 count ? total / count : 0, max);
44653 diff --git a/drivers/misc/sgi-gru/grutables.h b/drivers/misc/sgi-gru/grutables.h
44654 index 5c3ce24..4915ccb 100644
44655 --- a/drivers/misc/sgi-gru/grutables.h
44656 +++ b/drivers/misc/sgi-gru/grutables.h
44657 @@ -167,82 +167,82 @@ extern unsigned int gru_max_gids;
44658 * GRU statistics.
44659 */
44660 struct gru_stats_s {
44661 - atomic_long_t vdata_alloc;
44662 - atomic_long_t vdata_free;
44663 - atomic_long_t gts_alloc;
44664 - atomic_long_t gts_free;
44665 - atomic_long_t gms_alloc;
44666 - atomic_long_t gms_free;
44667 - atomic_long_t gts_double_allocate;
44668 - atomic_long_t assign_context;
44669 - atomic_long_t assign_context_failed;
44670 - atomic_long_t free_context;
44671 - atomic_long_t load_user_context;
44672 - atomic_long_t load_kernel_context;
44673 - atomic_long_t lock_kernel_context;
44674 - atomic_long_t unlock_kernel_context;
44675 - atomic_long_t steal_user_context;
44676 - atomic_long_t steal_kernel_context;
44677 - atomic_long_t steal_context_failed;
44678 - atomic_long_t nopfn;
44679 - atomic_long_t asid_new;
44680 - atomic_long_t asid_next;
44681 - atomic_long_t asid_wrap;
44682 - atomic_long_t asid_reuse;
44683 - atomic_long_t intr;
44684 - atomic_long_t intr_cbr;
44685 - atomic_long_t intr_tfh;
44686 - atomic_long_t intr_spurious;
44687 - atomic_long_t intr_mm_lock_failed;
44688 - atomic_long_t call_os;
44689 - atomic_long_t call_os_wait_queue;
44690 - atomic_long_t user_flush_tlb;
44691 - atomic_long_t user_unload_context;
44692 - atomic_long_t user_exception;
44693 - atomic_long_t set_context_option;
44694 - atomic_long_t check_context_retarget_intr;
44695 - atomic_long_t check_context_unload;
44696 - atomic_long_t tlb_dropin;
44697 - atomic_long_t tlb_preload_page;
44698 - atomic_long_t tlb_dropin_fail_no_asid;
44699 - atomic_long_t tlb_dropin_fail_upm;
44700 - atomic_long_t tlb_dropin_fail_invalid;
44701 - atomic_long_t tlb_dropin_fail_range_active;
44702 - atomic_long_t tlb_dropin_fail_idle;
44703 - atomic_long_t tlb_dropin_fail_fmm;
44704 - atomic_long_t tlb_dropin_fail_no_exception;
44705 - atomic_long_t tfh_stale_on_fault;
44706 - atomic_long_t mmu_invalidate_range;
44707 - atomic_long_t mmu_invalidate_page;
44708 - atomic_long_t flush_tlb;
44709 - atomic_long_t flush_tlb_gru;
44710 - atomic_long_t flush_tlb_gru_tgh;
44711 - atomic_long_t flush_tlb_gru_zero_asid;
44712 + atomic_long_unchecked_t vdata_alloc;
44713 + atomic_long_unchecked_t vdata_free;
44714 + atomic_long_unchecked_t gts_alloc;
44715 + atomic_long_unchecked_t gts_free;
44716 + atomic_long_unchecked_t gms_alloc;
44717 + atomic_long_unchecked_t gms_free;
44718 + atomic_long_unchecked_t gts_double_allocate;
44719 + atomic_long_unchecked_t assign_context;
44720 + atomic_long_unchecked_t assign_context_failed;
44721 + atomic_long_unchecked_t free_context;
44722 + atomic_long_unchecked_t load_user_context;
44723 + atomic_long_unchecked_t load_kernel_context;
44724 + atomic_long_unchecked_t lock_kernel_context;
44725 + atomic_long_unchecked_t unlock_kernel_context;
44726 + atomic_long_unchecked_t steal_user_context;
44727 + atomic_long_unchecked_t steal_kernel_context;
44728 + atomic_long_unchecked_t steal_context_failed;
44729 + atomic_long_unchecked_t nopfn;
44730 + atomic_long_unchecked_t asid_new;
44731 + atomic_long_unchecked_t asid_next;
44732 + atomic_long_unchecked_t asid_wrap;
44733 + atomic_long_unchecked_t asid_reuse;
44734 + atomic_long_unchecked_t intr;
44735 + atomic_long_unchecked_t intr_cbr;
44736 + atomic_long_unchecked_t intr_tfh;
44737 + atomic_long_unchecked_t intr_spurious;
44738 + atomic_long_unchecked_t intr_mm_lock_failed;
44739 + atomic_long_unchecked_t call_os;
44740 + atomic_long_unchecked_t call_os_wait_queue;
44741 + atomic_long_unchecked_t user_flush_tlb;
44742 + atomic_long_unchecked_t user_unload_context;
44743 + atomic_long_unchecked_t user_exception;
44744 + atomic_long_unchecked_t set_context_option;
44745 + atomic_long_unchecked_t check_context_retarget_intr;
44746 + atomic_long_unchecked_t check_context_unload;
44747 + atomic_long_unchecked_t tlb_dropin;
44748 + atomic_long_unchecked_t tlb_preload_page;
44749 + atomic_long_unchecked_t tlb_dropin_fail_no_asid;
44750 + atomic_long_unchecked_t tlb_dropin_fail_upm;
44751 + atomic_long_unchecked_t tlb_dropin_fail_invalid;
44752 + atomic_long_unchecked_t tlb_dropin_fail_range_active;
44753 + atomic_long_unchecked_t tlb_dropin_fail_idle;
44754 + atomic_long_unchecked_t tlb_dropin_fail_fmm;
44755 + atomic_long_unchecked_t tlb_dropin_fail_no_exception;
44756 + atomic_long_unchecked_t tfh_stale_on_fault;
44757 + atomic_long_unchecked_t mmu_invalidate_range;
44758 + atomic_long_unchecked_t mmu_invalidate_page;
44759 + atomic_long_unchecked_t flush_tlb;
44760 + atomic_long_unchecked_t flush_tlb_gru;
44761 + atomic_long_unchecked_t flush_tlb_gru_tgh;
44762 + atomic_long_unchecked_t flush_tlb_gru_zero_asid;
44763
44764 - atomic_long_t copy_gpa;
44765 - atomic_long_t read_gpa;
44766 + atomic_long_unchecked_t copy_gpa;
44767 + atomic_long_unchecked_t read_gpa;
44768
44769 - atomic_long_t mesq_receive;
44770 - atomic_long_t mesq_receive_none;
44771 - atomic_long_t mesq_send;
44772 - atomic_long_t mesq_send_failed;
44773 - atomic_long_t mesq_noop;
44774 - atomic_long_t mesq_send_unexpected_error;
44775 - atomic_long_t mesq_send_lb_overflow;
44776 - atomic_long_t mesq_send_qlimit_reached;
44777 - atomic_long_t mesq_send_amo_nacked;
44778 - atomic_long_t mesq_send_put_nacked;
44779 - atomic_long_t mesq_page_overflow;
44780 - atomic_long_t mesq_qf_locked;
44781 - atomic_long_t mesq_qf_noop_not_full;
44782 - atomic_long_t mesq_qf_switch_head_failed;
44783 - atomic_long_t mesq_qf_unexpected_error;
44784 - atomic_long_t mesq_noop_unexpected_error;
44785 - atomic_long_t mesq_noop_lb_overflow;
44786 - atomic_long_t mesq_noop_qlimit_reached;
44787 - atomic_long_t mesq_noop_amo_nacked;
44788 - atomic_long_t mesq_noop_put_nacked;
44789 - atomic_long_t mesq_noop_page_overflow;
44790 + atomic_long_unchecked_t mesq_receive;
44791 + atomic_long_unchecked_t mesq_receive_none;
44792 + atomic_long_unchecked_t mesq_send;
44793 + atomic_long_unchecked_t mesq_send_failed;
44794 + atomic_long_unchecked_t mesq_noop;
44795 + atomic_long_unchecked_t mesq_send_unexpected_error;
44796 + atomic_long_unchecked_t mesq_send_lb_overflow;
44797 + atomic_long_unchecked_t mesq_send_qlimit_reached;
44798 + atomic_long_unchecked_t mesq_send_amo_nacked;
44799 + atomic_long_unchecked_t mesq_send_put_nacked;
44800 + atomic_long_unchecked_t mesq_page_overflow;
44801 + atomic_long_unchecked_t mesq_qf_locked;
44802 + atomic_long_unchecked_t mesq_qf_noop_not_full;
44803 + atomic_long_unchecked_t mesq_qf_switch_head_failed;
44804 + atomic_long_unchecked_t mesq_qf_unexpected_error;
44805 + atomic_long_unchecked_t mesq_noop_unexpected_error;
44806 + atomic_long_unchecked_t mesq_noop_lb_overflow;
44807 + atomic_long_unchecked_t mesq_noop_qlimit_reached;
44808 + atomic_long_unchecked_t mesq_noop_amo_nacked;
44809 + atomic_long_unchecked_t mesq_noop_put_nacked;
44810 + atomic_long_unchecked_t mesq_noop_page_overflow;
44811
44812 };
44813
44814 @@ -251,8 +251,8 @@ enum mcs_op {cchop_allocate, cchop_start, cchop_interrupt, cchop_interrupt_sync,
44815 tghop_invalidate, mcsop_last};
44816
44817 struct mcs_op_statistic {
44818 - atomic_long_t count;
44819 - atomic_long_t total;
44820 + atomic_long_unchecked_t count;
44821 + atomic_long_unchecked_t total;
44822 unsigned long max;
44823 };
44824
44825 @@ -275,7 +275,7 @@ extern struct mcs_op_statistic mcs_op_statistics[mcsop_last];
44826
44827 #define STAT(id) do { \
44828 if (gru_options & OPT_STATS) \
44829 - atomic_long_inc(&gru_stats.id); \
44830 + atomic_long_inc_unchecked(&gru_stats.id); \
44831 } while (0)
44832
44833 #ifdef CONFIG_SGI_GRU_DEBUG
44834 diff --git a/drivers/misc/sgi-xp/xp.h b/drivers/misc/sgi-xp/xp.h
44835 index c862cd4..0d176fe 100644
44836 --- a/drivers/misc/sgi-xp/xp.h
44837 +++ b/drivers/misc/sgi-xp/xp.h
44838 @@ -288,7 +288,7 @@ struct xpc_interface {
44839 xpc_notify_func, void *);
44840 void (*received) (short, int, void *);
44841 enum xp_retval (*partid_to_nasids) (short, void *);
44842 -};
44843 +} __no_const;
44844
44845 extern struct xpc_interface xpc_interface;
44846
44847 diff --git a/drivers/misc/sgi-xp/xp_main.c b/drivers/misc/sgi-xp/xp_main.c
44848 index 01be66d..e3a0c7e 100644
44849 --- a/drivers/misc/sgi-xp/xp_main.c
44850 +++ b/drivers/misc/sgi-xp/xp_main.c
44851 @@ -78,13 +78,13 @@ xpc_notloaded(void)
44852 }
44853
44854 struct xpc_interface xpc_interface = {
44855 - (void (*)(int))xpc_notloaded,
44856 - (void (*)(int))xpc_notloaded,
44857 - (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
44858 - (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
44859 + .connect = (void (*)(int))xpc_notloaded,
44860 + .disconnect = (void (*)(int))xpc_notloaded,
44861 + .send = (enum xp_retval(*)(short, int, u32, void *, u16))xpc_notloaded,
44862 + .send_notify = (enum xp_retval(*)(short, int, u32, void *, u16, xpc_notify_func,
44863 void *))xpc_notloaded,
44864 - (void (*)(short, int, void *))xpc_notloaded,
44865 - (enum xp_retval(*)(short, void *))xpc_notloaded
44866 + .received = (void (*)(short, int, void *))xpc_notloaded,
44867 + .partid_to_nasids = (enum xp_retval(*)(short, void *))xpc_notloaded
44868 };
44869 EXPORT_SYMBOL_GPL(xpc_interface);
44870
44871 diff --git a/drivers/misc/sgi-xp/xpc.h b/drivers/misc/sgi-xp/xpc.h
44872 index b94d5f7..7f494c5 100644
44873 --- a/drivers/misc/sgi-xp/xpc.h
44874 +++ b/drivers/misc/sgi-xp/xpc.h
44875 @@ -835,6 +835,7 @@ struct xpc_arch_operations {
44876 void (*received_payload) (struct xpc_channel *, void *);
44877 void (*notify_senders_of_disconnect) (struct xpc_channel *);
44878 };
44879 +typedef struct xpc_arch_operations __no_const xpc_arch_operations_no_const;
44880
44881 /* struct xpc_partition act_state values (for XPC HB) */
44882
44883 @@ -876,7 +877,7 @@ extern struct xpc_registration xpc_registrations[];
44884 /* found in xpc_main.c */
44885 extern struct device *xpc_part;
44886 extern struct device *xpc_chan;
44887 -extern struct xpc_arch_operations xpc_arch_ops;
44888 +extern xpc_arch_operations_no_const xpc_arch_ops;
44889 extern int xpc_disengage_timelimit;
44890 extern int xpc_disengage_timedout;
44891 extern int xpc_activate_IRQ_rcvd;
44892 diff --git a/drivers/misc/sgi-xp/xpc_main.c b/drivers/misc/sgi-xp/xpc_main.c
44893 index 82dc574..8539ab2 100644
44894 --- a/drivers/misc/sgi-xp/xpc_main.c
44895 +++ b/drivers/misc/sgi-xp/xpc_main.c
44896 @@ -166,7 +166,7 @@ static struct notifier_block xpc_die_notifier = {
44897 .notifier_call = xpc_system_die,
44898 };
44899
44900 -struct xpc_arch_operations xpc_arch_ops;
44901 +xpc_arch_operations_no_const xpc_arch_ops;
44902
44903 /*
44904 * Timer function to enforce the timelimit on the partition disengage.
44905 @@ -1210,7 +1210,7 @@ xpc_system_die(struct notifier_block *nb, unsigned long event, void *_die_args)
44906
44907 if (((die_args->trapnr == X86_TRAP_MF) ||
44908 (die_args->trapnr == X86_TRAP_XF)) &&
44909 - !user_mode_vm(die_args->regs))
44910 + !user_mode(die_args->regs))
44911 xpc_die_deactivate();
44912
44913 break;
44914 diff --git a/drivers/mmc/card/block.c b/drivers/mmc/card/block.c
44915 index 7b5424f..ed1d6ac 100644
44916 --- a/drivers/mmc/card/block.c
44917 +++ b/drivers/mmc/card/block.c
44918 @@ -575,7 +575,7 @@ static int mmc_blk_ioctl_cmd(struct block_device *bdev,
44919 if (idata->ic.postsleep_min_us)
44920 usleep_range(idata->ic.postsleep_min_us, idata->ic.postsleep_max_us);
44921
44922 - if (copy_to_user(&(ic_ptr->response), cmd.resp, sizeof(cmd.resp))) {
44923 + if (copy_to_user(ic_ptr->response, cmd.resp, sizeof(cmd.resp))) {
44924 err = -EFAULT;
44925 goto cmd_rel_host;
44926 }
44927 diff --git a/drivers/mmc/core/mmc_ops.c b/drivers/mmc/core/mmc_ops.c
44928 index e5b5eeb..7bf2212 100644
44929 --- a/drivers/mmc/core/mmc_ops.c
44930 +++ b/drivers/mmc/core/mmc_ops.c
44931 @@ -247,7 +247,7 @@ mmc_send_cxd_data(struct mmc_card *card, struct mmc_host *host,
44932 void *data_buf;
44933 int is_on_stack;
44934
44935 - is_on_stack = object_is_on_stack(buf);
44936 + is_on_stack = object_starts_on_stack(buf);
44937 if (is_on_stack) {
44938 /*
44939 * dma onto stack is unsafe/nonportable, but callers to this
44940 diff --git a/drivers/mmc/host/dw_mmc.h b/drivers/mmc/host/dw_mmc.h
44941 index 6bf24ab..13d0293b 100644
44942 --- a/drivers/mmc/host/dw_mmc.h
44943 +++ b/drivers/mmc/host/dw_mmc.h
44944 @@ -258,5 +258,5 @@ struct dw_mci_drv_data {
44945 int (*parse_dt)(struct dw_mci *host);
44946 int (*execute_tuning)(struct dw_mci_slot *slot, u32 opcode,
44947 struct dw_mci_tuning_data *tuning_data);
44948 -};
44949 +} __do_const;
44950 #endif /* _DW_MMC_H_ */
44951 diff --git a/drivers/mmc/host/mmci.c b/drivers/mmc/host/mmci.c
44952 index f320579..7b7ebac 100644
44953 --- a/drivers/mmc/host/mmci.c
44954 +++ b/drivers/mmc/host/mmci.c
44955 @@ -1504,7 +1504,9 @@ static int mmci_probe(struct amba_device *dev,
44956 }
44957
44958 if (variant->busy_detect) {
44959 - mmci_ops.card_busy = mmci_card_busy;
44960 + pax_open_kernel();
44961 + *(void **)&mmci_ops.card_busy = mmci_card_busy;
44962 + pax_close_kernel();
44963 mmci_write_datactrlreg(host, MCI_ST_DPSM_BUSYMODE);
44964 }
44965
44966 diff --git a/drivers/mmc/host/sdhci-esdhc-imx.c b/drivers/mmc/host/sdhci-esdhc-imx.c
44967 index 1dcaf8a..025af25 100644
44968 --- a/drivers/mmc/host/sdhci-esdhc-imx.c
44969 +++ b/drivers/mmc/host/sdhci-esdhc-imx.c
44970 @@ -1009,9 +1009,12 @@ static int sdhci_esdhc_imx_probe(struct platform_device *pdev)
44971 host->quirks2 |= SDHCI_QUIRK2_PRESET_VALUE_BROKEN;
44972 }
44973
44974 - if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING)
44975 - sdhci_esdhc_ops.platform_execute_tuning =
44976 + if (imx_data->socdata->flags & ESDHC_FLAG_MAN_TUNING) {
44977 + pax_open_kernel();
44978 + *(void **)&sdhci_esdhc_ops.platform_execute_tuning =
44979 esdhc_executing_tuning;
44980 + pax_close_kernel();
44981 + }
44982 boarddata = &imx_data->boarddata;
44983 if (sdhci_esdhc_imx_probe_dt(pdev, boarddata) < 0) {
44984 if (!host->mmc->parent->platform_data) {
44985 diff --git a/drivers/mmc/host/sdhci-s3c.c b/drivers/mmc/host/sdhci-s3c.c
44986 index 6debda9..2ba7427 100644
44987 --- a/drivers/mmc/host/sdhci-s3c.c
44988 +++ b/drivers/mmc/host/sdhci-s3c.c
44989 @@ -668,9 +668,11 @@ static int sdhci_s3c_probe(struct platform_device *pdev)
44990 * we can use overriding functions instead of default.
44991 */
44992 if (host->quirks & SDHCI_QUIRK_NONSTANDARD_CLOCK) {
44993 - sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44994 - sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44995 - sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
44996 + pax_open_kernel();
44997 + *(void **)&sdhci_s3c_ops.set_clock = sdhci_cmu_set_clock;
44998 + *(void **)&sdhci_s3c_ops.get_min_clock = sdhci_cmu_get_min_clock;
44999 + *(void **)&sdhci_s3c_ops.get_max_clock = sdhci_cmu_get_max_clock;
45000 + pax_close_kernel();
45001 }
45002
45003 /* It supports additional host capabilities if needed */
45004 diff --git a/drivers/mtd/chips/cfi_cmdset_0020.c b/drivers/mtd/chips/cfi_cmdset_0020.c
45005 index 096993f..f02c23b 100644
45006 --- a/drivers/mtd/chips/cfi_cmdset_0020.c
45007 +++ b/drivers/mtd/chips/cfi_cmdset_0020.c
45008 @@ -669,7 +669,7 @@ cfi_staa_writev(struct mtd_info *mtd, const struct kvec *vecs,
45009 size_t totlen = 0, thislen;
45010 int ret = 0;
45011 size_t buflen = 0;
45012 - static char *buffer;
45013 + char *buffer;
45014
45015 if (!ECCBUF_SIZE) {
45016 /* We should fall back to a general writev implementation.
45017 diff --git a/drivers/mtd/nand/denali.c b/drivers/mtd/nand/denali.c
45018 index 370b9dd..1a1176b 100644
45019 --- a/drivers/mtd/nand/denali.c
45020 +++ b/drivers/mtd/nand/denali.c
45021 @@ -24,6 +24,7 @@
45022 #include <linux/slab.h>
45023 #include <linux/mtd/mtd.h>
45024 #include <linux/module.h>
45025 +#include <linux/slab.h>
45026
45027 #include "denali.h"
45028
45029 diff --git a/drivers/mtd/nftlmount.c b/drivers/mtd/nftlmount.c
45030 index 51b9d6a..52af9a7 100644
45031 --- a/drivers/mtd/nftlmount.c
45032 +++ b/drivers/mtd/nftlmount.c
45033 @@ -24,6 +24,7 @@
45034 #include <asm/errno.h>
45035 #include <linux/delay.h>
45036 #include <linux/slab.h>
45037 +#include <linux/sched.h>
45038 #include <linux/mtd/mtd.h>
45039 #include <linux/mtd/nand.h>
45040 #include <linux/mtd/nftl.h>
45041 diff --git a/drivers/mtd/sm_ftl.c b/drivers/mtd/sm_ftl.c
45042 index 4b8e895..6b3c498 100644
45043 --- a/drivers/mtd/sm_ftl.c
45044 +++ b/drivers/mtd/sm_ftl.c
45045 @@ -56,7 +56,7 @@ static ssize_t sm_attr_show(struct device *dev, struct device_attribute *attr,
45046 #define SM_CIS_VENDOR_OFFSET 0x59
45047 static struct attribute_group *sm_create_sysfs_attributes(struct sm_ftl *ftl)
45048 {
45049 - struct attribute_group *attr_group;
45050 + attribute_group_no_const *attr_group;
45051 struct attribute **attributes;
45052 struct sm_sysfs_attribute *vendor_attribute;
45053
45054 diff --git a/drivers/net/bonding/bond_main.c b/drivers/net/bonding/bond_main.c
45055 index 4b8c58b..a200546 100644
45056 --- a/drivers/net/bonding/bond_main.c
45057 +++ b/drivers/net/bonding/bond_main.c
45058 @@ -4527,6 +4527,7 @@ static void __exit bonding_exit(void)
45059
45060 bond_netlink_fini();
45061 unregister_pernet_subsys(&bond_net_ops);
45062 + rtnl_link_unregister(&bond_link_ops);
45063
45064 #ifdef CONFIG_NET_POLL_CONTROLLER
45065 /*
45066 diff --git a/drivers/net/bonding/bond_netlink.c b/drivers/net/bonding/bond_netlink.c
45067 index 40e7b1c..6a70fff 100644
45068 --- a/drivers/net/bonding/bond_netlink.c
45069 +++ b/drivers/net/bonding/bond_netlink.c
45070 @@ -102,7 +102,7 @@ nla_put_failure:
45071 return -EMSGSIZE;
45072 }
45073
45074 -struct rtnl_link_ops bond_link_ops __read_mostly = {
45075 +struct rtnl_link_ops bond_link_ops = {
45076 .kind = "bond",
45077 .priv_size = sizeof(struct bonding),
45078 .setup = bond_setup,
45079 diff --git a/drivers/net/ethernet/8390/ax88796.c b/drivers/net/ethernet/8390/ax88796.c
45080 index 36fa577..a158806 100644
45081 --- a/drivers/net/ethernet/8390/ax88796.c
45082 +++ b/drivers/net/ethernet/8390/ax88796.c
45083 @@ -872,9 +872,11 @@ static int ax_probe(struct platform_device *pdev)
45084 if (ax->plat->reg_offsets)
45085 ei_local->reg_offset = ax->plat->reg_offsets;
45086 else {
45087 + resource_size_t _mem_size = mem_size;
45088 + do_div(_mem_size, 0x18);
45089 ei_local->reg_offset = ax->reg_offsets;
45090 for (ret = 0; ret < 0x18; ret++)
45091 - ax->reg_offsets[ret] = (mem_size / 0x18) * ret;
45092 + ax->reg_offsets[ret] = _mem_size * ret;
45093 }
45094
45095 if (!request_mem_region(mem->start, mem_size, pdev->name)) {
45096 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45097 index 41f3ca5a..1ee5364 100644
45098 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45099 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_cmn.h
45100 @@ -1139,7 +1139,7 @@ static inline u8 bnx2x_get_path_func_num(struct bnx2x *bp)
45101 static inline void bnx2x_init_bp_objs(struct bnx2x *bp)
45102 {
45103 /* RX_MODE controlling object */
45104 - bnx2x_init_rx_mode_obj(bp, &bp->rx_mode_obj);
45105 + bnx2x_init_rx_mode_obj(bp);
45106
45107 /* multicast configuration controlling object */
45108 bnx2x_init_mcast_obj(bp, &bp->mcast_obj, bp->fp->cl_id, bp->fp->cid,
45109 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45110 index 18438a5..c923b8e 100644
45111 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45112 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.c
45113 @@ -2591,15 +2591,14 @@ int bnx2x_config_rx_mode(struct bnx2x *bp,
45114 return rc;
45115 }
45116
45117 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45118 - struct bnx2x_rx_mode_obj *o)
45119 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp)
45120 {
45121 if (CHIP_IS_E1x(bp)) {
45122 - o->wait_comp = bnx2x_empty_rx_mode_wait;
45123 - o->config_rx_mode = bnx2x_set_rx_mode_e1x;
45124 + bp->rx_mode_obj.wait_comp = bnx2x_empty_rx_mode_wait;
45125 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e1x;
45126 } else {
45127 - o->wait_comp = bnx2x_wait_rx_mode_comp_e2;
45128 - o->config_rx_mode = bnx2x_set_rx_mode_e2;
45129 + bp->rx_mode_obj.wait_comp = bnx2x_wait_rx_mode_comp_e2;
45130 + bp->rx_mode_obj.config_rx_mode = bnx2x_set_rx_mode_e2;
45131 }
45132 }
45133
45134 diff --git a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45135 index 6a53c15..6e7d1e7 100644
45136 --- a/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45137 +++ b/drivers/net/ethernet/broadcom/bnx2x/bnx2x_sp.h
45138 @@ -1332,8 +1332,7 @@ int bnx2x_vlan_mac_move(struct bnx2x *bp,
45139
45140 /********************* RX MODE ****************/
45141
45142 -void bnx2x_init_rx_mode_obj(struct bnx2x *bp,
45143 - struct bnx2x_rx_mode_obj *o);
45144 +void bnx2x_init_rx_mode_obj(struct bnx2x *bp);
45145
45146 /**
45147 * bnx2x_config_rx_mode - Send and RX_MODE ramrod according to the provided parameters.
45148 diff --git a/drivers/net/ethernet/broadcom/tg3.h b/drivers/net/ethernet/broadcom/tg3.h
45149 index 5c3835a..d18b952 100644
45150 --- a/drivers/net/ethernet/broadcom/tg3.h
45151 +++ b/drivers/net/ethernet/broadcom/tg3.h
45152 @@ -150,6 +150,7 @@
45153 #define CHIPREV_ID_5750_A0 0x4000
45154 #define CHIPREV_ID_5750_A1 0x4001
45155 #define CHIPREV_ID_5750_A3 0x4003
45156 +#define CHIPREV_ID_5750_C1 0x4201
45157 #define CHIPREV_ID_5750_C2 0x4202
45158 #define CHIPREV_ID_5752_A0_HW 0x5000
45159 #define CHIPREV_ID_5752_A0 0x6000
45160 diff --git a/drivers/net/ethernet/brocade/bna/bna_enet.c b/drivers/net/ethernet/brocade/bna/bna_enet.c
45161 index 3ca77fa..fcc015f 100644
45162 --- a/drivers/net/ethernet/brocade/bna/bna_enet.c
45163 +++ b/drivers/net/ethernet/brocade/bna/bna_enet.c
45164 @@ -1690,10 +1690,10 @@ bna_cb_ioceth_reset(void *arg)
45165 }
45166
45167 static struct bfa_ioc_cbfn bna_ioceth_cbfn = {
45168 - bna_cb_ioceth_enable,
45169 - bna_cb_ioceth_disable,
45170 - bna_cb_ioceth_hbfail,
45171 - bna_cb_ioceth_reset
45172 + .enable_cbfn = bna_cb_ioceth_enable,
45173 + .disable_cbfn = bna_cb_ioceth_disable,
45174 + .hbfail_cbfn = bna_cb_ioceth_hbfail,
45175 + .reset_cbfn = bna_cb_ioceth_reset
45176 };
45177
45178 static void bna_attr_init(struct bna_ioceth *ioceth)
45179 diff --git a/drivers/net/ethernet/chelsio/cxgb3/l2t.h b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45180 index 8cffcdf..aadf043 100644
45181 --- a/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45182 +++ b/drivers/net/ethernet/chelsio/cxgb3/l2t.h
45183 @@ -87,7 +87,7 @@ typedef void (*arp_failure_handler_func)(struct t3cdev * dev,
45184 */
45185 struct l2t_skb_cb {
45186 arp_failure_handler_func arp_failure_handler;
45187 -};
45188 +} __no_const;
45189
45190 #define L2T_SKB_CB(skb) ((struct l2t_skb_cb *)(skb)->cb)
45191
45192 diff --git a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45193 index fff02ed..d421412 100644
45194 --- a/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45195 +++ b/drivers/net/ethernet/chelsio/cxgb4/cxgb4_main.c
45196 @@ -2120,7 +2120,7 @@ static void get_regs(struct net_device *dev, struct ethtool_regs *regs,
45197
45198 int i;
45199 struct adapter *ap = netdev2adap(dev);
45200 - static const unsigned int *reg_ranges;
45201 + const unsigned int *reg_ranges;
45202 int arr_size = 0, buf_size = 0;
45203
45204 if (is_t4(ap->params.chip)) {
45205 diff --git a/drivers/net/ethernet/dec/tulip/de4x5.c b/drivers/net/ethernet/dec/tulip/de4x5.c
45206 index c05b66d..ed69872 100644
45207 --- a/drivers/net/ethernet/dec/tulip/de4x5.c
45208 +++ b/drivers/net/ethernet/dec/tulip/de4x5.c
45209 @@ -5388,7 +5388,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45210 for (i=0; i<ETH_ALEN; i++) {
45211 tmp.addr[i] = dev->dev_addr[i];
45212 }
45213 - if (copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45214 + if (ioc->len > sizeof tmp.addr || copy_to_user(ioc->data, tmp.addr, ioc->len)) return -EFAULT;
45215 break;
45216
45217 case DE4X5_SET_HWADDR: /* Set the hardware address */
45218 @@ -5428,7 +5428,7 @@ de4x5_ioctl(struct net_device *dev, struct ifreq *rq, int cmd)
45219 spin_lock_irqsave(&lp->lock, flags);
45220 memcpy(&statbuf, &lp->pktStats, ioc->len);
45221 spin_unlock_irqrestore(&lp->lock, flags);
45222 - if (copy_to_user(ioc->data, &statbuf, ioc->len))
45223 + if (ioc->len > sizeof statbuf || copy_to_user(ioc->data, &statbuf, ioc->len))
45224 return -EFAULT;
45225 break;
45226 }
45227 diff --git a/drivers/net/ethernet/emulex/benet/be_main.c b/drivers/net/ethernet/emulex/benet/be_main.c
45228 index a37039d..a51d7e8 100644
45229 --- a/drivers/net/ethernet/emulex/benet/be_main.c
45230 +++ b/drivers/net/ethernet/emulex/benet/be_main.c
45231 @@ -533,7 +533,7 @@ static void accumulate_16bit_val(u32 *acc, u16 val)
45232
45233 if (wrapped)
45234 newacc += 65536;
45235 - ACCESS_ONCE(*acc) = newacc;
45236 + ACCESS_ONCE_RW(*acc) = newacc;
45237 }
45238
45239 static void populate_erx_stats(struct be_adapter *adapter,
45240 diff --git a/drivers/net/ethernet/faraday/ftgmac100.c b/drivers/net/ethernet/faraday/ftgmac100.c
45241 index 212f44b..fb69959 100644
45242 --- a/drivers/net/ethernet/faraday/ftgmac100.c
45243 +++ b/drivers/net/ethernet/faraday/ftgmac100.c
45244 @@ -31,6 +31,8 @@
45245 #include <linux/netdevice.h>
45246 #include <linux/phy.h>
45247 #include <linux/platform_device.h>
45248 +#include <linux/interrupt.h>
45249 +#include <linux/irqreturn.h>
45250 #include <net/ip.h>
45251
45252 #include "ftgmac100.h"
45253 diff --git a/drivers/net/ethernet/faraday/ftmac100.c b/drivers/net/ethernet/faraday/ftmac100.c
45254 index 8be5b40..081bc1b 100644
45255 --- a/drivers/net/ethernet/faraday/ftmac100.c
45256 +++ b/drivers/net/ethernet/faraday/ftmac100.c
45257 @@ -31,6 +31,8 @@
45258 #include <linux/module.h>
45259 #include <linux/netdevice.h>
45260 #include <linux/platform_device.h>
45261 +#include <linux/interrupt.h>
45262 +#include <linux/irqreturn.h>
45263
45264 #include "ftmac100.h"
45265
45266 diff --git a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45267 index 5184e2a..acb28c3 100644
45268 --- a/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45269 +++ b/drivers/net/ethernet/intel/ixgbe/ixgbe_ptp.c
45270 @@ -776,7 +776,7 @@ void ixgbe_ptp_start_cyclecounter(struct ixgbe_adapter *adapter)
45271 }
45272
45273 /* update the base incval used to calculate frequency adjustment */
45274 - ACCESS_ONCE(adapter->base_incval) = incval;
45275 + ACCESS_ONCE_RW(adapter->base_incval) = incval;
45276 smp_mb();
45277
45278 /* need lock to prevent incorrect read while modifying cyclecounter */
45279 diff --git a/drivers/net/ethernet/neterion/vxge/vxge-config.c b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45280 index fbe5363..266b4e3 100644
45281 --- a/drivers/net/ethernet/neterion/vxge/vxge-config.c
45282 +++ b/drivers/net/ethernet/neterion/vxge/vxge-config.c
45283 @@ -3461,7 +3461,10 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45284 struct __vxge_hw_fifo *fifo;
45285 struct vxge_hw_fifo_config *config;
45286 u32 txdl_size, txdl_per_memblock;
45287 - struct vxge_hw_mempool_cbs fifo_mp_callback;
45288 + static struct vxge_hw_mempool_cbs fifo_mp_callback = {
45289 + .item_func_alloc = __vxge_hw_fifo_mempool_item_alloc,
45290 + };
45291 +
45292 struct __vxge_hw_virtualpath *vpath;
45293
45294 if ((vp == NULL) || (attr == NULL)) {
45295 @@ -3544,8 +3547,6 @@ __vxge_hw_fifo_create(struct __vxge_hw_vpath_handle *vp,
45296 goto exit;
45297 }
45298
45299 - fifo_mp_callback.item_func_alloc = __vxge_hw_fifo_mempool_item_alloc;
45300 -
45301 fifo->mempool =
45302 __vxge_hw_mempool_create(vpath->hldev,
45303 fifo->config->memblock_size,
45304 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45305 index 918e18d..4ca3650 100644
45306 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45307 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_init.c
45308 @@ -2086,7 +2086,9 @@ int qlcnic_83xx_configure_opmode(struct qlcnic_adapter *adapter)
45309 adapter->max_tx_rings = QLCNIC_MAX_VNIC_TX_RINGS;
45310 } else if (ret == QLC_83XX_DEFAULT_OPMODE) {
45311 ahw->nic_mode = QLCNIC_DEFAULT_MODE;
45312 - adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45313 + pax_open_kernel();
45314 + *(void **)&adapter->nic_ops->init_driver = qlcnic_83xx_init_default_driver;
45315 + pax_close_kernel();
45316 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45317 adapter->max_sds_rings = QLCNIC_MAX_SDS_RINGS;
45318 adapter->max_tx_rings = QLCNIC_MAX_TX_RINGS;
45319 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45320 index 734d286..b017bf5 100644
45321 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45322 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_83xx_vnic.c
45323 @@ -207,17 +207,23 @@ int qlcnic_83xx_config_vnic_opmode(struct qlcnic_adapter *adapter)
45324 case QLCNIC_NON_PRIV_FUNC:
45325 ahw->op_mode = QLCNIC_NON_PRIV_FUNC;
45326 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45327 - nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45328 + pax_open_kernel();
45329 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_non_privileged_vnic;
45330 + pax_close_kernel();
45331 break;
45332 case QLCNIC_PRIV_FUNC:
45333 ahw->op_mode = QLCNIC_PRIV_FUNC;
45334 ahw->idc.state_entry = qlcnic_83xx_idc_vnic_pf_entry;
45335 - nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45336 + pax_open_kernel();
45337 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_privileged_vnic;
45338 + pax_close_kernel();
45339 break;
45340 case QLCNIC_MGMT_FUNC:
45341 ahw->op_mode = QLCNIC_MGMT_FUNC;
45342 ahw->idc.state_entry = qlcnic_83xx_idc_ready_state_entry;
45343 - nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45344 + pax_open_kernel();
45345 + *(void **)&nic_ops->init_driver = qlcnic_83xx_init_mgmt_vnic;
45346 + pax_close_kernel();
45347 break;
45348 default:
45349 dev_err(&adapter->pdev->dev, "Invalid Virtual NIC opmode\n");
45350 diff --git a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45351 index 7763962..c3499a7 100644
45352 --- a/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45353 +++ b/drivers/net/ethernet/qlogic/qlcnic/qlcnic_minidump.c
45354 @@ -1108,7 +1108,7 @@ int qlcnic_dump_fw(struct qlcnic_adapter *adapter)
45355 struct qlcnic_dump_entry *entry;
45356 struct qlcnic_fw_dump *fw_dump = &adapter->ahw->fw_dump;
45357 struct qlcnic_dump_template_hdr *tmpl_hdr = fw_dump->tmpl_hdr;
45358 - static const struct qlcnic_dump_operations *fw_dump_ops;
45359 + const struct qlcnic_dump_operations *fw_dump_ops;
45360 struct device *dev = &adapter->pdev->dev;
45361 struct qlcnic_hardware_context *ahw;
45362 void *temp_buffer;
45363 diff --git a/drivers/net/ethernet/realtek/r8169.c b/drivers/net/ethernet/realtek/r8169.c
45364 index c737f0e..32b8682 100644
45365 --- a/drivers/net/ethernet/realtek/r8169.c
45366 +++ b/drivers/net/ethernet/realtek/r8169.c
45367 @@ -759,22 +759,22 @@ struct rtl8169_private {
45368 struct mdio_ops {
45369 void (*write)(struct rtl8169_private *, int, int);
45370 int (*read)(struct rtl8169_private *, int);
45371 - } mdio_ops;
45372 + } __no_const mdio_ops;
45373
45374 struct pll_power_ops {
45375 void (*down)(struct rtl8169_private *);
45376 void (*up)(struct rtl8169_private *);
45377 - } pll_power_ops;
45378 + } __no_const pll_power_ops;
45379
45380 struct jumbo_ops {
45381 void (*enable)(struct rtl8169_private *);
45382 void (*disable)(struct rtl8169_private *);
45383 - } jumbo_ops;
45384 + } __no_const jumbo_ops;
45385
45386 struct csi_ops {
45387 void (*write)(struct rtl8169_private *, int, int);
45388 u32 (*read)(struct rtl8169_private *, int);
45389 - } csi_ops;
45390 + } __no_const csi_ops;
45391
45392 int (*set_speed)(struct net_device *, u8 aneg, u16 sp, u8 dpx, u32 adv);
45393 int (*get_settings)(struct net_device *, struct ethtool_cmd *);
45394 diff --git a/drivers/net/ethernet/sfc/ptp.c b/drivers/net/ethernet/sfc/ptp.c
45395 index 3dd39dc..85efa46 100644
45396 --- a/drivers/net/ethernet/sfc/ptp.c
45397 +++ b/drivers/net/ethernet/sfc/ptp.c
45398 @@ -541,7 +541,7 @@ static int efx_ptp_synchronize(struct efx_nic *efx, unsigned int num_readings)
45399 ptp->start.dma_addr);
45400
45401 /* Clear flag that signals MC ready */
45402 - ACCESS_ONCE(*start) = 0;
45403 + ACCESS_ONCE_RW(*start) = 0;
45404 rc = efx_mcdi_rpc_start(efx, MC_CMD_PTP, synch_buf,
45405 MC_CMD_PTP_IN_SYNCHRONIZE_LEN);
45406 EFX_BUG_ON_PARANOID(rc);
45407 diff --git a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45408 index 50617c5..b13724c 100644
45409 --- a/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45410 +++ b/drivers/net/ethernet/stmicro/stmmac/mmc_core.c
45411 @@ -140,8 +140,8 @@ void dwmac_mmc_ctrl(void __iomem *ioaddr, unsigned int mode)
45412
45413 writel(value, ioaddr + MMC_CNTRL);
45414
45415 - pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
45416 - MMC_CNTRL, value);
45417 +// pr_debug("stmmac: MMC ctrl register (offset 0x%x): 0x%08x\n",
45418 +// MMC_CNTRL, value);
45419 }
45420
45421 /* To mask all all interrupts.*/
45422 diff --git a/drivers/net/hyperv/hyperv_net.h b/drivers/net/hyperv/hyperv_net.h
45423 index e6fe0d8..2b7d752 100644
45424 --- a/drivers/net/hyperv/hyperv_net.h
45425 +++ b/drivers/net/hyperv/hyperv_net.h
45426 @@ -101,7 +101,7 @@ struct rndis_device {
45427
45428 enum rndis_device_state state;
45429 bool link_state;
45430 - atomic_t new_req_id;
45431 + atomic_unchecked_t new_req_id;
45432
45433 spinlock_t request_lock;
45434 struct list_head req_list;
45435 diff --git a/drivers/net/hyperv/rndis_filter.c b/drivers/net/hyperv/rndis_filter.c
45436 index 0775f0a..d4fb316 100644
45437 --- a/drivers/net/hyperv/rndis_filter.c
45438 +++ b/drivers/net/hyperv/rndis_filter.c
45439 @@ -104,7 +104,7 @@ static struct rndis_request *get_rndis_request(struct rndis_device *dev,
45440 * template
45441 */
45442 set = &rndis_msg->msg.set_req;
45443 - set->req_id = atomic_inc_return(&dev->new_req_id);
45444 + set->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
45445
45446 /* Add to the request list */
45447 spin_lock_irqsave(&dev->request_lock, flags);
45448 @@ -752,7 +752,7 @@ static void rndis_filter_halt_device(struct rndis_device *dev)
45449
45450 /* Setup the rndis set */
45451 halt = &request->request_msg.msg.halt_req;
45452 - halt->req_id = atomic_inc_return(&dev->new_req_id);
45453 + halt->req_id = atomic_inc_return_unchecked(&dev->new_req_id);
45454
45455 /* Ignore return since this msg is optional. */
45456 rndis_filter_send_request(dev, request);
45457 diff --git a/drivers/net/ieee802154/fakehard.c b/drivers/net/ieee802154/fakehard.c
45458 index bf0d55e..82bcfbd1 100644
45459 --- a/drivers/net/ieee802154/fakehard.c
45460 +++ b/drivers/net/ieee802154/fakehard.c
45461 @@ -364,7 +364,7 @@ static int ieee802154fake_probe(struct platform_device *pdev)
45462 phy->transmit_power = 0xbf;
45463
45464 dev->netdev_ops = &fake_ops;
45465 - dev->ml_priv = &fake_mlme;
45466 + dev->ml_priv = (void *)&fake_mlme;
45467
45468 priv = netdev_priv(dev);
45469 priv->phy = phy;
45470 diff --git a/drivers/net/macvlan.c b/drivers/net/macvlan.c
45471 index bc8faae..e51e25d 100644
45472 --- a/drivers/net/macvlan.c
45473 +++ b/drivers/net/macvlan.c
45474 @@ -990,13 +990,15 @@ static const struct nla_policy macvlan_policy[IFLA_MACVLAN_MAX + 1] = {
45475 int macvlan_link_register(struct rtnl_link_ops *ops)
45476 {
45477 /* common fields */
45478 - ops->priv_size = sizeof(struct macvlan_dev);
45479 - ops->validate = macvlan_validate;
45480 - ops->maxtype = IFLA_MACVLAN_MAX;
45481 - ops->policy = macvlan_policy;
45482 - ops->changelink = macvlan_changelink;
45483 - ops->get_size = macvlan_get_size;
45484 - ops->fill_info = macvlan_fill_info;
45485 + pax_open_kernel();
45486 + *(size_t *)&ops->priv_size = sizeof(struct macvlan_dev);
45487 + *(void **)&ops->validate = macvlan_validate;
45488 + *(int *)&ops->maxtype = IFLA_MACVLAN_MAX;
45489 + *(const void **)&ops->policy = macvlan_policy;
45490 + *(void **)&ops->changelink = macvlan_changelink;
45491 + *(void **)&ops->get_size = macvlan_get_size;
45492 + *(void **)&ops->fill_info = macvlan_fill_info;
45493 + pax_close_kernel();
45494
45495 return rtnl_link_register(ops);
45496 };
45497 @@ -1051,7 +1053,7 @@ static int macvlan_device_event(struct notifier_block *unused,
45498 return NOTIFY_DONE;
45499 }
45500
45501 -static struct notifier_block macvlan_notifier_block __read_mostly = {
45502 +static struct notifier_block macvlan_notifier_block = {
45503 .notifier_call = macvlan_device_event,
45504 };
45505
45506 diff --git a/drivers/net/macvtap.c b/drivers/net/macvtap.c
45507 index 2a89da0..c17fe1d 100644
45508 --- a/drivers/net/macvtap.c
45509 +++ b/drivers/net/macvtap.c
45510 @@ -1012,7 +1012,7 @@ static long macvtap_ioctl(struct file *file, unsigned int cmd,
45511 }
45512
45513 ret = 0;
45514 - if (copy_to_user(&ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
45515 + if (copy_to_user(ifr->ifr_name, vlan->dev->name, IFNAMSIZ) ||
45516 put_user(q->flags, &ifr->ifr_flags))
45517 ret = -EFAULT;
45518 macvtap_put_vlan(vlan);
45519 @@ -1182,7 +1182,7 @@ static int macvtap_device_event(struct notifier_block *unused,
45520 return NOTIFY_DONE;
45521 }
45522
45523 -static struct notifier_block macvtap_notifier_block __read_mostly = {
45524 +static struct notifier_block macvtap_notifier_block = {
45525 .notifier_call = macvtap_device_event,
45526 };
45527
45528 diff --git a/drivers/net/phy/mdio-bitbang.c b/drivers/net/phy/mdio-bitbang.c
45529 index daec9b0..6428fcb 100644
45530 --- a/drivers/net/phy/mdio-bitbang.c
45531 +++ b/drivers/net/phy/mdio-bitbang.c
45532 @@ -234,6 +234,7 @@ void free_mdio_bitbang(struct mii_bus *bus)
45533 struct mdiobb_ctrl *ctrl = bus->priv;
45534
45535 module_put(ctrl->ops->owner);
45536 + mdiobus_unregister(bus);
45537 mdiobus_free(bus);
45538 }
45539 EXPORT_SYMBOL(free_mdio_bitbang);
45540 diff --git a/drivers/net/ppp/ppp_generic.c b/drivers/net/ppp/ppp_generic.c
45541 index 72ff14b..11d442d 100644
45542 --- a/drivers/net/ppp/ppp_generic.c
45543 +++ b/drivers/net/ppp/ppp_generic.c
45544 @@ -999,7 +999,6 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
45545 void __user *addr = (void __user *) ifr->ifr_ifru.ifru_data;
45546 struct ppp_stats stats;
45547 struct ppp_comp_stats cstats;
45548 - char *vers;
45549
45550 switch (cmd) {
45551 case SIOCGPPPSTATS:
45552 @@ -1021,8 +1020,7 @@ ppp_net_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
45553 break;
45554
45555 case SIOCGPPPVER:
45556 - vers = PPP_VERSION;
45557 - if (copy_to_user(addr, vers, strlen(vers) + 1))
45558 + if (copy_to_user(addr, PPP_VERSION, sizeof(PPP_VERSION)))
45559 break;
45560 err = 0;
45561 break;
45562 diff --git a/drivers/net/slip/slhc.c b/drivers/net/slip/slhc.c
45563 index 1252d9c..80e660b 100644
45564 --- a/drivers/net/slip/slhc.c
45565 +++ b/drivers/net/slip/slhc.c
45566 @@ -488,7 +488,7 @@ slhc_uncompress(struct slcompress *comp, unsigned char *icp, int isize)
45567 register struct tcphdr *thp;
45568 register struct iphdr *ip;
45569 register struct cstate *cs;
45570 - int len, hdrlen;
45571 + long len, hdrlen;
45572 unsigned char *cp = icp;
45573
45574 /* We've got a compressed packet; read the change byte */
45575 diff --git a/drivers/net/team/team.c b/drivers/net/team/team.c
45576 index b75ae5b..953c157 100644
45577 --- a/drivers/net/team/team.c
45578 +++ b/drivers/net/team/team.c
45579 @@ -2865,7 +2865,7 @@ static int team_device_event(struct notifier_block *unused,
45580 return NOTIFY_DONE;
45581 }
45582
45583 -static struct notifier_block team_notifier_block __read_mostly = {
45584 +static struct notifier_block team_notifier_block = {
45585 .notifier_call = team_device_event,
45586 };
45587
45588 diff --git a/drivers/net/tun.c b/drivers/net/tun.c
45589 index ecec802..614f08f 100644
45590 --- a/drivers/net/tun.c
45591 +++ b/drivers/net/tun.c
45592 @@ -1839,7 +1839,7 @@ unlock:
45593 }
45594
45595 static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
45596 - unsigned long arg, int ifreq_len)
45597 + unsigned long arg, size_t ifreq_len)
45598 {
45599 struct tun_file *tfile = file->private_data;
45600 struct tun_struct *tun;
45601 @@ -1852,6 +1852,9 @@ static long __tun_chr_ioctl(struct file *file, unsigned int cmd,
45602 unsigned int ifindex;
45603 int ret;
45604
45605 + if (ifreq_len > sizeof ifr)
45606 + return -EFAULT;
45607 +
45608 if (cmd == TUNSETIFF || cmd == TUNSETQUEUE || _IOC_TYPE(cmd) == 0x89) {
45609 if (copy_from_user(&ifr, argp, ifreq_len))
45610 return -EFAULT;
45611 diff --git a/drivers/net/usb/hso.c b/drivers/net/usb/hso.c
45612 index 1a48234..a555339 100644
45613 --- a/drivers/net/usb/hso.c
45614 +++ b/drivers/net/usb/hso.c
45615 @@ -71,7 +71,7 @@
45616 #include <asm/byteorder.h>
45617 #include <linux/serial_core.h>
45618 #include <linux/serial.h>
45619 -
45620 +#include <asm/local.h>
45621
45622 #define MOD_AUTHOR "Option Wireless"
45623 #define MOD_DESCRIPTION "USB High Speed Option driver"
45624 @@ -1179,7 +1179,7 @@ static void put_rxbuf_data_and_resubmit_ctrl_urb(struct hso_serial *serial)
45625 struct urb *urb;
45626
45627 urb = serial->rx_urb[0];
45628 - if (serial->port.count > 0) {
45629 + if (atomic_read(&serial->port.count) > 0) {
45630 count = put_rxbuf_data(urb, serial);
45631 if (count == -1)
45632 return;
45633 @@ -1215,7 +1215,7 @@ static void hso_std_serial_read_bulk_callback(struct urb *urb)
45634 DUMP1(urb->transfer_buffer, urb->actual_length);
45635
45636 /* Anyone listening? */
45637 - if (serial->port.count == 0)
45638 + if (atomic_read(&serial->port.count) == 0)
45639 return;
45640
45641 if (status == 0) {
45642 @@ -1297,8 +1297,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
45643 tty_port_tty_set(&serial->port, tty);
45644
45645 /* check for port already opened, if not set the termios */
45646 - serial->port.count++;
45647 - if (serial->port.count == 1) {
45648 + if (atomic_inc_return(&serial->port.count) == 1) {
45649 serial->rx_state = RX_IDLE;
45650 /* Force default termio settings */
45651 _hso_serial_set_termios(tty, NULL);
45652 @@ -1310,7 +1309,7 @@ static int hso_serial_open(struct tty_struct *tty, struct file *filp)
45653 result = hso_start_serial_device(serial->parent, GFP_KERNEL);
45654 if (result) {
45655 hso_stop_serial_device(serial->parent);
45656 - serial->port.count--;
45657 + atomic_dec(&serial->port.count);
45658 kref_put(&serial->parent->ref, hso_serial_ref_free);
45659 }
45660 } else {
45661 @@ -1347,10 +1346,10 @@ static void hso_serial_close(struct tty_struct *tty, struct file *filp)
45662
45663 /* reset the rts and dtr */
45664 /* do the actual close */
45665 - serial->port.count--;
45666 + atomic_dec(&serial->port.count);
45667
45668 - if (serial->port.count <= 0) {
45669 - serial->port.count = 0;
45670 + if (atomic_read(&serial->port.count) <= 0) {
45671 + atomic_set(&serial->port.count, 0);
45672 tty_port_tty_set(&serial->port, NULL);
45673 if (!usb_gone)
45674 hso_stop_serial_device(serial->parent);
45675 @@ -1426,7 +1425,7 @@ static void hso_serial_set_termios(struct tty_struct *tty, struct ktermios *old)
45676
45677 /* the actual setup */
45678 spin_lock_irqsave(&serial->serial_lock, flags);
45679 - if (serial->port.count)
45680 + if (atomic_read(&serial->port.count))
45681 _hso_serial_set_termios(tty, old);
45682 else
45683 tty->termios = *old;
45684 @@ -1895,7 +1894,7 @@ static void intr_callback(struct urb *urb)
45685 D1("Pending read interrupt on port %d\n", i);
45686 spin_lock(&serial->serial_lock);
45687 if (serial->rx_state == RX_IDLE &&
45688 - serial->port.count > 0) {
45689 + atomic_read(&serial->port.count) > 0) {
45690 /* Setup and send a ctrl req read on
45691 * port i */
45692 if (!serial->rx_urb_filled[0]) {
45693 @@ -3071,7 +3070,7 @@ static int hso_resume(struct usb_interface *iface)
45694 /* Start all serial ports */
45695 for (i = 0; i < HSO_SERIAL_TTY_MINORS; i++) {
45696 if (serial_table[i] && (serial_table[i]->interface == iface)) {
45697 - if (dev2ser(serial_table[i])->port.count) {
45698 + if (atomic_read(&dev2ser(serial_table[i])->port.count)) {
45699 result =
45700 hso_start_serial_device(serial_table[i], GFP_NOIO);
45701 hso_kick_transmit(dev2ser(serial_table[i]));
45702 diff --git a/drivers/net/usb/sierra_net.c b/drivers/net/usb/sierra_net.c
45703 index a79e9d3..78cd4fa 100644
45704 --- a/drivers/net/usb/sierra_net.c
45705 +++ b/drivers/net/usb/sierra_net.c
45706 @@ -52,7 +52,7 @@ static const char driver_name[] = "sierra_net";
45707 /* atomic counter partially included in MAC address to make sure 2 devices
45708 * do not end up with the same MAC - concept breaks in case of > 255 ifaces
45709 */
45710 -static atomic_t iface_counter = ATOMIC_INIT(0);
45711 +static atomic_unchecked_t iface_counter = ATOMIC_INIT(0);
45712
45713 /*
45714 * SYNC Timer Delay definition used to set the expiry time
45715 @@ -698,7 +698,7 @@ static int sierra_net_bind(struct usbnet *dev, struct usb_interface *intf)
45716 dev->net->netdev_ops = &sierra_net_device_ops;
45717
45718 /* change MAC addr to include, ifacenum, and to be unique */
45719 - dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return(&iface_counter);
45720 + dev->net->dev_addr[ETH_ALEN-2] = atomic_inc_return_unchecked(&iface_counter);
45721 dev->net->dev_addr[ETH_ALEN-1] = ifacenum;
45722
45723 /* we will have to manufacture ethernet headers, prepare template */
45724 diff --git a/drivers/net/vxlan.c b/drivers/net/vxlan.c
45725 index 0247973..088193a 100644
45726 --- a/drivers/net/vxlan.c
45727 +++ b/drivers/net/vxlan.c
45728 @@ -2615,7 +2615,7 @@ nla_put_failure:
45729 return -EMSGSIZE;
45730 }
45731
45732 -static struct rtnl_link_ops vxlan_link_ops __read_mostly = {
45733 +static struct rtnl_link_ops vxlan_link_ops = {
45734 .kind = "vxlan",
45735 .maxtype = IFLA_VXLAN_MAX,
45736 .policy = vxlan_policy,
45737 diff --git a/drivers/net/wan/lmc/lmc_media.c b/drivers/net/wan/lmc/lmc_media.c
45738 index 5920c99..ff2e4a5 100644
45739 --- a/drivers/net/wan/lmc/lmc_media.c
45740 +++ b/drivers/net/wan/lmc/lmc_media.c
45741 @@ -95,62 +95,63 @@ static inline void write_av9110_bit (lmc_softc_t *, int);
45742 static void write_av9110(lmc_softc_t *, u32, u32, u32, u32, u32);
45743
45744 lmc_media_t lmc_ds3_media = {
45745 - lmc_ds3_init, /* special media init stuff */
45746 - lmc_ds3_default, /* reset to default state */
45747 - lmc_ds3_set_status, /* reset status to state provided */
45748 - lmc_dummy_set_1, /* set clock source */
45749 - lmc_dummy_set2_1, /* set line speed */
45750 - lmc_ds3_set_100ft, /* set cable length */
45751 - lmc_ds3_set_scram, /* set scrambler */
45752 - lmc_ds3_get_link_status, /* get link status */
45753 - lmc_dummy_set_1, /* set link status */
45754 - lmc_ds3_set_crc_length, /* set CRC length */
45755 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
45756 - lmc_ds3_watchdog
45757 + .init = lmc_ds3_init, /* special media init stuff */
45758 + .defaults = lmc_ds3_default, /* reset to default state */
45759 + .set_status = lmc_ds3_set_status, /* reset status to state provided */
45760 + .set_clock_source = lmc_dummy_set_1, /* set clock source */
45761 + .set_speed = lmc_dummy_set2_1, /* set line speed */
45762 + .set_cable_length = lmc_ds3_set_100ft, /* set cable length */
45763 + .set_scrambler = lmc_ds3_set_scram, /* set scrambler */
45764 + .get_link_status = lmc_ds3_get_link_status, /* get link status */
45765 + .set_link_status = lmc_dummy_set_1, /* set link status */
45766 + .set_crc_length = lmc_ds3_set_crc_length, /* set CRC length */
45767 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
45768 + .watchdog = lmc_ds3_watchdog
45769 };
45770
45771 lmc_media_t lmc_hssi_media = {
45772 - lmc_hssi_init, /* special media init stuff */
45773 - lmc_hssi_default, /* reset to default state */
45774 - lmc_hssi_set_status, /* reset status to state provided */
45775 - lmc_hssi_set_clock, /* set clock source */
45776 - lmc_dummy_set2_1, /* set line speed */
45777 - lmc_dummy_set_1, /* set cable length */
45778 - lmc_dummy_set_1, /* set scrambler */
45779 - lmc_hssi_get_link_status, /* get link status */
45780 - lmc_hssi_set_link_status, /* set link status */
45781 - lmc_hssi_set_crc_length, /* set CRC length */
45782 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
45783 - lmc_hssi_watchdog
45784 + .init = lmc_hssi_init, /* special media init stuff */
45785 + .defaults = lmc_hssi_default, /* reset to default state */
45786 + .set_status = lmc_hssi_set_status, /* reset status to state provided */
45787 + .set_clock_source = lmc_hssi_set_clock, /* set clock source */
45788 + .set_speed = lmc_dummy_set2_1, /* set line speed */
45789 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
45790 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
45791 + .get_link_status = lmc_hssi_get_link_status, /* get link status */
45792 + .set_link_status = lmc_hssi_set_link_status, /* set link status */
45793 + .set_crc_length = lmc_hssi_set_crc_length, /* set CRC length */
45794 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
45795 + .watchdog = lmc_hssi_watchdog
45796 };
45797
45798 -lmc_media_t lmc_ssi_media = { lmc_ssi_init, /* special media init stuff */
45799 - lmc_ssi_default, /* reset to default state */
45800 - lmc_ssi_set_status, /* reset status to state provided */
45801 - lmc_ssi_set_clock, /* set clock source */
45802 - lmc_ssi_set_speed, /* set line speed */
45803 - lmc_dummy_set_1, /* set cable length */
45804 - lmc_dummy_set_1, /* set scrambler */
45805 - lmc_ssi_get_link_status, /* get link status */
45806 - lmc_ssi_set_link_status, /* set link status */
45807 - lmc_ssi_set_crc_length, /* set CRC length */
45808 - lmc_dummy_set_1, /* set T1 or E1 circuit type */
45809 - lmc_ssi_watchdog
45810 +lmc_media_t lmc_ssi_media = {
45811 + .init = lmc_ssi_init, /* special media init stuff */
45812 + .defaults = lmc_ssi_default, /* reset to default state */
45813 + .set_status = lmc_ssi_set_status, /* reset status to state provided */
45814 + .set_clock_source = lmc_ssi_set_clock, /* set clock source */
45815 + .set_speed = lmc_ssi_set_speed, /* set line speed */
45816 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
45817 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
45818 + .get_link_status = lmc_ssi_get_link_status, /* get link status */
45819 + .set_link_status = lmc_ssi_set_link_status, /* set link status */
45820 + .set_crc_length = lmc_ssi_set_crc_length, /* set CRC length */
45821 + .set_circuit_type = lmc_dummy_set_1, /* set T1 or E1 circuit type */
45822 + .watchdog = lmc_ssi_watchdog
45823 };
45824
45825 lmc_media_t lmc_t1_media = {
45826 - lmc_t1_init, /* special media init stuff */
45827 - lmc_t1_default, /* reset to default state */
45828 - lmc_t1_set_status, /* reset status to state provided */
45829 - lmc_t1_set_clock, /* set clock source */
45830 - lmc_dummy_set2_1, /* set line speed */
45831 - lmc_dummy_set_1, /* set cable length */
45832 - lmc_dummy_set_1, /* set scrambler */
45833 - lmc_t1_get_link_status, /* get link status */
45834 - lmc_dummy_set_1, /* set link status */
45835 - lmc_t1_set_crc_length, /* set CRC length */
45836 - lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
45837 - lmc_t1_watchdog
45838 + .init = lmc_t1_init, /* special media init stuff */
45839 + .defaults = lmc_t1_default, /* reset to default state */
45840 + .set_status = lmc_t1_set_status, /* reset status to state provided */
45841 + .set_clock_source = lmc_t1_set_clock, /* set clock source */
45842 + .set_speed = lmc_dummy_set2_1, /* set line speed */
45843 + .set_cable_length = lmc_dummy_set_1, /* set cable length */
45844 + .set_scrambler = lmc_dummy_set_1, /* set scrambler */
45845 + .get_link_status = lmc_t1_get_link_status, /* get link status */
45846 + .set_link_status = lmc_dummy_set_1, /* set link status */
45847 + .set_crc_length = lmc_t1_set_crc_length, /* set CRC length */
45848 + .set_circuit_type = lmc_t1_set_circuit_type, /* set T1 or E1 circuit type */
45849 + .watchdog = lmc_t1_watchdog
45850 };
45851
45852 static void
45853 diff --git a/drivers/net/wan/z85230.c b/drivers/net/wan/z85230.c
45854 index feacc3b..5bac0de 100644
45855 --- a/drivers/net/wan/z85230.c
45856 +++ b/drivers/net/wan/z85230.c
45857 @@ -485,9 +485,9 @@ static void z8530_status(struct z8530_channel *chan)
45858
45859 struct z8530_irqhandler z8530_sync =
45860 {
45861 - z8530_rx,
45862 - z8530_tx,
45863 - z8530_status
45864 + .rx = z8530_rx,
45865 + .tx = z8530_tx,
45866 + .status = z8530_status
45867 };
45868
45869 EXPORT_SYMBOL(z8530_sync);
45870 @@ -605,15 +605,15 @@ static void z8530_dma_status(struct z8530_channel *chan)
45871 }
45872
45873 static struct z8530_irqhandler z8530_dma_sync = {
45874 - z8530_dma_rx,
45875 - z8530_dma_tx,
45876 - z8530_dma_status
45877 + .rx = z8530_dma_rx,
45878 + .tx = z8530_dma_tx,
45879 + .status = z8530_dma_status
45880 };
45881
45882 static struct z8530_irqhandler z8530_txdma_sync = {
45883 - z8530_rx,
45884 - z8530_dma_tx,
45885 - z8530_dma_status
45886 + .rx = z8530_rx,
45887 + .tx = z8530_dma_tx,
45888 + .status = z8530_dma_status
45889 };
45890
45891 /**
45892 @@ -680,9 +680,9 @@ static void z8530_status_clear(struct z8530_channel *chan)
45893
45894 struct z8530_irqhandler z8530_nop=
45895 {
45896 - z8530_rx_clear,
45897 - z8530_tx_clear,
45898 - z8530_status_clear
45899 + .rx = z8530_rx_clear,
45900 + .tx = z8530_tx_clear,
45901 + .status = z8530_status_clear
45902 };
45903
45904
45905 diff --git a/drivers/net/wimax/i2400m/rx.c b/drivers/net/wimax/i2400m/rx.c
45906 index 0b60295..b8bfa5b 100644
45907 --- a/drivers/net/wimax/i2400m/rx.c
45908 +++ b/drivers/net/wimax/i2400m/rx.c
45909 @@ -1359,7 +1359,7 @@ int i2400m_rx_setup(struct i2400m *i2400m)
45910 if (i2400m->rx_roq == NULL)
45911 goto error_roq_alloc;
45912
45913 - rd = kcalloc(I2400M_RO_CIN + 1, sizeof(*i2400m->rx_roq[0].log),
45914 + rd = kcalloc(sizeof(*i2400m->rx_roq[0].log), I2400M_RO_CIN + 1,
45915 GFP_KERNEL);
45916 if (rd == NULL) {
45917 result = -ENOMEM;
45918 diff --git a/drivers/net/wireless/airo.c b/drivers/net/wireless/airo.c
45919 index edf4b57..68b51c0 100644
45920 --- a/drivers/net/wireless/airo.c
45921 +++ b/drivers/net/wireless/airo.c
45922 @@ -7843,7 +7843,7 @@ static int writerids(struct net_device *dev, aironet_ioctl *comp) {
45923 struct airo_info *ai = dev->ml_priv;
45924 int ridcode;
45925 int enabled;
45926 - static int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
45927 + int (* writer)(struct airo_info *, u16 rid, const void *, int, int);
45928 unsigned char *iobuf;
45929
45930 /* Only super-user can write RIDs */
45931 diff --git a/drivers/net/wireless/at76c50x-usb.c b/drivers/net/wireless/at76c50x-usb.c
45932 index 34c8a33..3261fdc 100644
45933 --- a/drivers/net/wireless/at76c50x-usb.c
45934 +++ b/drivers/net/wireless/at76c50x-usb.c
45935 @@ -353,7 +353,7 @@ static int at76_dfu_get_state(struct usb_device *udev, u8 *state)
45936 }
45937
45938 /* Convert timeout from the DFU status to jiffies */
45939 -static inline unsigned long at76_get_timeout(struct dfu_status *s)
45940 +static inline unsigned long __intentional_overflow(-1) at76_get_timeout(struct dfu_status *s)
45941 {
45942 return msecs_to_jiffies((s->poll_timeout[2] << 16)
45943 | (s->poll_timeout[1] << 8)
45944 diff --git a/drivers/net/wireless/ath/ath10k/htc.c b/drivers/net/wireless/ath/ath10k/htc.c
45945 index edae50b..b24278c 100644
45946 --- a/drivers/net/wireless/ath/ath10k/htc.c
45947 +++ b/drivers/net/wireless/ath/ath10k/htc.c
45948 @@ -842,7 +842,10 @@ void ath10k_htc_stop(struct ath10k_htc *htc)
45949 /* registered target arrival callback from the HIF layer */
45950 int ath10k_htc_init(struct ath10k *ar)
45951 {
45952 - struct ath10k_hif_cb htc_callbacks;
45953 + static struct ath10k_hif_cb htc_callbacks = {
45954 + .rx_completion = ath10k_htc_rx_completion_handler,
45955 + .tx_completion = ath10k_htc_tx_completion_handler,
45956 + };
45957 struct ath10k_htc_ep *ep = NULL;
45958 struct ath10k_htc *htc = &ar->htc;
45959
45960 @@ -852,8 +855,6 @@ int ath10k_htc_init(struct ath10k *ar)
45961 ath10k_htc_reset_endpoint_states(htc);
45962
45963 /* setup HIF layer callbacks */
45964 - htc_callbacks.rx_completion = ath10k_htc_rx_completion_handler;
45965 - htc_callbacks.tx_completion = ath10k_htc_tx_completion_handler;
45966 htc->ar = ar;
45967
45968 /* Get HIF default pipe for HTC message exchange */
45969 diff --git a/drivers/net/wireless/ath/ath10k/htc.h b/drivers/net/wireless/ath/ath10k/htc.h
45970 index 4716d33..a688310 100644
45971 --- a/drivers/net/wireless/ath/ath10k/htc.h
45972 +++ b/drivers/net/wireless/ath/ath10k/htc.h
45973 @@ -271,13 +271,13 @@ enum ath10k_htc_ep_id {
45974
45975 struct ath10k_htc_ops {
45976 void (*target_send_suspend_complete)(struct ath10k *ar);
45977 -};
45978 +} __no_const;
45979
45980 struct ath10k_htc_ep_ops {
45981 void (*ep_tx_complete)(struct ath10k *, struct sk_buff *);
45982 void (*ep_rx_complete)(struct ath10k *, struct sk_buff *);
45983 void (*ep_tx_credits)(struct ath10k *);
45984 -};
45985 +} __no_const;
45986
45987 /* service connection information */
45988 struct ath10k_htc_svc_conn_req {
45989 diff --git a/drivers/net/wireless/ath/ath9k/ar9002_mac.c b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
45990 index a366d6b..b6f28f8 100644
45991 --- a/drivers/net/wireless/ath/ath9k/ar9002_mac.c
45992 +++ b/drivers/net/wireless/ath/ath9k/ar9002_mac.c
45993 @@ -218,8 +218,8 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
45994 ads->ds_txstatus6 = ads->ds_txstatus7 = 0;
45995 ads->ds_txstatus8 = ads->ds_txstatus9 = 0;
45996
45997 - ACCESS_ONCE(ads->ds_link) = i->link;
45998 - ACCESS_ONCE(ads->ds_data) = i->buf_addr[0];
45999 + ACCESS_ONCE_RW(ads->ds_link) = i->link;
46000 + ACCESS_ONCE_RW(ads->ds_data) = i->buf_addr[0];
46001
46002 ctl1 = i->buf_len[0] | (i->is_last ? 0 : AR_TxMore);
46003 ctl6 = SM(i->keytype, AR_EncrType);
46004 @@ -233,26 +233,26 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46005
46006 if ((i->is_first || i->is_last) &&
46007 i->aggr != AGGR_BUF_MIDDLE && i->aggr != AGGR_BUF_LAST) {
46008 - ACCESS_ONCE(ads->ds_ctl2) = set11nTries(i->rates, 0)
46009 + ACCESS_ONCE_RW(ads->ds_ctl2) = set11nTries(i->rates, 0)
46010 | set11nTries(i->rates, 1)
46011 | set11nTries(i->rates, 2)
46012 | set11nTries(i->rates, 3)
46013 | (i->dur_update ? AR_DurUpdateEna : 0)
46014 | SM(0, AR_BurstDur);
46015
46016 - ACCESS_ONCE(ads->ds_ctl3) = set11nRate(i->rates, 0)
46017 + ACCESS_ONCE_RW(ads->ds_ctl3) = set11nRate(i->rates, 0)
46018 | set11nRate(i->rates, 1)
46019 | set11nRate(i->rates, 2)
46020 | set11nRate(i->rates, 3);
46021 } else {
46022 - ACCESS_ONCE(ads->ds_ctl2) = 0;
46023 - ACCESS_ONCE(ads->ds_ctl3) = 0;
46024 + ACCESS_ONCE_RW(ads->ds_ctl2) = 0;
46025 + ACCESS_ONCE_RW(ads->ds_ctl3) = 0;
46026 }
46027
46028 if (!i->is_first) {
46029 - ACCESS_ONCE(ads->ds_ctl0) = 0;
46030 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46031 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46032 + ACCESS_ONCE_RW(ads->ds_ctl0) = 0;
46033 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46034 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46035 return;
46036 }
46037
46038 @@ -277,7 +277,7 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46039 break;
46040 }
46041
46042 - ACCESS_ONCE(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46043 + ACCESS_ONCE_RW(ads->ds_ctl0) = (i->pkt_len & AR_FrameLen)
46044 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46045 | SM(i->txpower, AR_XmitPower)
46046 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46047 @@ -287,19 +287,19 @@ ar9002_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46048 | (i->flags & ATH9K_TXDESC_RTSENA ? AR_RTSEnable :
46049 (i->flags & ATH9K_TXDESC_CTSENA ? AR_CTSEnable : 0));
46050
46051 - ACCESS_ONCE(ads->ds_ctl1) = ctl1;
46052 - ACCESS_ONCE(ads->ds_ctl6) = ctl6;
46053 + ACCESS_ONCE_RW(ads->ds_ctl1) = ctl1;
46054 + ACCESS_ONCE_RW(ads->ds_ctl6) = ctl6;
46055
46056 if (i->aggr == AGGR_BUF_MIDDLE || i->aggr == AGGR_BUF_LAST)
46057 return;
46058
46059 - ACCESS_ONCE(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46060 + ACCESS_ONCE_RW(ads->ds_ctl4) = set11nPktDurRTSCTS(i->rates, 0)
46061 | set11nPktDurRTSCTS(i->rates, 1);
46062
46063 - ACCESS_ONCE(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46064 + ACCESS_ONCE_RW(ads->ds_ctl5) = set11nPktDurRTSCTS(i->rates, 2)
46065 | set11nPktDurRTSCTS(i->rates, 3);
46066
46067 - ACCESS_ONCE(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46068 + ACCESS_ONCE_RW(ads->ds_ctl7) = set11nRateFlags(i->rates, 0)
46069 | set11nRateFlags(i->rates, 1)
46070 | set11nRateFlags(i->rates, 2)
46071 | set11nRateFlags(i->rates, 3)
46072 diff --git a/drivers/net/wireless/ath/ath9k/ar9003_mac.c b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46073 index f6c5c1b..6058354 100644
46074 --- a/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46075 +++ b/drivers/net/wireless/ath/ath9k/ar9003_mac.c
46076 @@ -39,47 +39,47 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46077 (i->qcu << AR_TxQcuNum_S) | desc_len;
46078
46079 checksum += val;
46080 - ACCESS_ONCE(ads->info) = val;
46081 + ACCESS_ONCE_RW(ads->info) = val;
46082
46083 checksum += i->link;
46084 - ACCESS_ONCE(ads->link) = i->link;
46085 + ACCESS_ONCE_RW(ads->link) = i->link;
46086
46087 checksum += i->buf_addr[0];
46088 - ACCESS_ONCE(ads->data0) = i->buf_addr[0];
46089 + ACCESS_ONCE_RW(ads->data0) = i->buf_addr[0];
46090 checksum += i->buf_addr[1];
46091 - ACCESS_ONCE(ads->data1) = i->buf_addr[1];
46092 + ACCESS_ONCE_RW(ads->data1) = i->buf_addr[1];
46093 checksum += i->buf_addr[2];
46094 - ACCESS_ONCE(ads->data2) = i->buf_addr[2];
46095 + ACCESS_ONCE_RW(ads->data2) = i->buf_addr[2];
46096 checksum += i->buf_addr[3];
46097 - ACCESS_ONCE(ads->data3) = i->buf_addr[3];
46098 + ACCESS_ONCE_RW(ads->data3) = i->buf_addr[3];
46099
46100 checksum += (val = (i->buf_len[0] << AR_BufLen_S) & AR_BufLen);
46101 - ACCESS_ONCE(ads->ctl3) = val;
46102 + ACCESS_ONCE_RW(ads->ctl3) = val;
46103 checksum += (val = (i->buf_len[1] << AR_BufLen_S) & AR_BufLen);
46104 - ACCESS_ONCE(ads->ctl5) = val;
46105 + ACCESS_ONCE_RW(ads->ctl5) = val;
46106 checksum += (val = (i->buf_len[2] << AR_BufLen_S) & AR_BufLen);
46107 - ACCESS_ONCE(ads->ctl7) = val;
46108 + ACCESS_ONCE_RW(ads->ctl7) = val;
46109 checksum += (val = (i->buf_len[3] << AR_BufLen_S) & AR_BufLen);
46110 - ACCESS_ONCE(ads->ctl9) = val;
46111 + ACCESS_ONCE_RW(ads->ctl9) = val;
46112
46113 checksum = (u16) (((checksum & 0xffff) + (checksum >> 16)) & 0xffff);
46114 - ACCESS_ONCE(ads->ctl10) = checksum;
46115 + ACCESS_ONCE_RW(ads->ctl10) = checksum;
46116
46117 if (i->is_first || i->is_last) {
46118 - ACCESS_ONCE(ads->ctl13) = set11nTries(i->rates, 0)
46119 + ACCESS_ONCE_RW(ads->ctl13) = set11nTries(i->rates, 0)
46120 | set11nTries(i->rates, 1)
46121 | set11nTries(i->rates, 2)
46122 | set11nTries(i->rates, 3)
46123 | (i->dur_update ? AR_DurUpdateEna : 0)
46124 | SM(0, AR_BurstDur);
46125
46126 - ACCESS_ONCE(ads->ctl14) = set11nRate(i->rates, 0)
46127 + ACCESS_ONCE_RW(ads->ctl14) = set11nRate(i->rates, 0)
46128 | set11nRate(i->rates, 1)
46129 | set11nRate(i->rates, 2)
46130 | set11nRate(i->rates, 3);
46131 } else {
46132 - ACCESS_ONCE(ads->ctl13) = 0;
46133 - ACCESS_ONCE(ads->ctl14) = 0;
46134 + ACCESS_ONCE_RW(ads->ctl13) = 0;
46135 + ACCESS_ONCE_RW(ads->ctl14) = 0;
46136 }
46137
46138 ads->ctl20 = 0;
46139 @@ -89,17 +89,17 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46140
46141 ctl17 = SM(i->keytype, AR_EncrType);
46142 if (!i->is_first) {
46143 - ACCESS_ONCE(ads->ctl11) = 0;
46144 - ACCESS_ONCE(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46145 - ACCESS_ONCE(ads->ctl15) = 0;
46146 - ACCESS_ONCE(ads->ctl16) = 0;
46147 - ACCESS_ONCE(ads->ctl17) = ctl17;
46148 - ACCESS_ONCE(ads->ctl18) = 0;
46149 - ACCESS_ONCE(ads->ctl19) = 0;
46150 + ACCESS_ONCE_RW(ads->ctl11) = 0;
46151 + ACCESS_ONCE_RW(ads->ctl12) = i->is_last ? 0 : AR_TxMore;
46152 + ACCESS_ONCE_RW(ads->ctl15) = 0;
46153 + ACCESS_ONCE_RW(ads->ctl16) = 0;
46154 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46155 + ACCESS_ONCE_RW(ads->ctl18) = 0;
46156 + ACCESS_ONCE_RW(ads->ctl19) = 0;
46157 return;
46158 }
46159
46160 - ACCESS_ONCE(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46161 + ACCESS_ONCE_RW(ads->ctl11) = (i->pkt_len & AR_FrameLen)
46162 | (i->flags & ATH9K_TXDESC_VMF ? AR_VirtMoreFrag : 0)
46163 | SM(i->txpower, AR_XmitPower)
46164 | (i->flags & ATH9K_TXDESC_VEOL ? AR_VEOL : 0)
46165 @@ -135,22 +135,22 @@ ar9003_set_txdesc(struct ath_hw *ah, void *ds, struct ath_tx_info *i)
46166 val = (i->flags & ATH9K_TXDESC_PAPRD) >> ATH9K_TXDESC_PAPRD_S;
46167 ctl12 |= SM(val, AR_PAPRDChainMask);
46168
46169 - ACCESS_ONCE(ads->ctl12) = ctl12;
46170 - ACCESS_ONCE(ads->ctl17) = ctl17;
46171 + ACCESS_ONCE_RW(ads->ctl12) = ctl12;
46172 + ACCESS_ONCE_RW(ads->ctl17) = ctl17;
46173
46174 - ACCESS_ONCE(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46175 + ACCESS_ONCE_RW(ads->ctl15) = set11nPktDurRTSCTS(i->rates, 0)
46176 | set11nPktDurRTSCTS(i->rates, 1);
46177
46178 - ACCESS_ONCE(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46179 + ACCESS_ONCE_RW(ads->ctl16) = set11nPktDurRTSCTS(i->rates, 2)
46180 | set11nPktDurRTSCTS(i->rates, 3);
46181
46182 - ACCESS_ONCE(ads->ctl18) = set11nRateFlags(i->rates, 0)
46183 + ACCESS_ONCE_RW(ads->ctl18) = set11nRateFlags(i->rates, 0)
46184 | set11nRateFlags(i->rates, 1)
46185 | set11nRateFlags(i->rates, 2)
46186 | set11nRateFlags(i->rates, 3)
46187 | SM(i->rtscts_rate, AR_RTSCTSRate);
46188
46189 - ACCESS_ONCE(ads->ctl19) = AR_Not_Sounding;
46190 + ACCESS_ONCE_RW(ads->ctl19) = AR_Not_Sounding;
46191 }
46192
46193 static u16 ar9003_calc_ptr_chksum(struct ar9003_txc *ads)
46194 diff --git a/drivers/net/wireless/ath/ath9k/hw.h b/drivers/net/wireless/ath/ath9k/hw.h
46195 index a2c9a5d..b52273e 100644
46196 --- a/drivers/net/wireless/ath/ath9k/hw.h
46197 +++ b/drivers/net/wireless/ath/ath9k/hw.h
46198 @@ -635,7 +635,7 @@ struct ath_hw_private_ops {
46199
46200 /* ANI */
46201 void (*ani_cache_ini_regs)(struct ath_hw *ah);
46202 -};
46203 +} __no_const;
46204
46205 /**
46206 * struct ath_spec_scan - parameters for Atheros spectral scan
46207 @@ -711,7 +711,7 @@ struct ath_hw_ops {
46208 #ifdef CONFIG_ATH9K_BTCOEX_SUPPORT
46209 void (*set_bt_ant_diversity)(struct ath_hw *hw, bool enable);
46210 #endif
46211 -};
46212 +} __no_const;
46213
46214 struct ath_nf_limits {
46215 s16 max;
46216 diff --git a/drivers/net/wireless/b43/phy_lp.c b/drivers/net/wireless/b43/phy_lp.c
46217 index 92190da..f3a4c4c 100644
46218 --- a/drivers/net/wireless/b43/phy_lp.c
46219 +++ b/drivers/net/wireless/b43/phy_lp.c
46220 @@ -2514,7 +2514,7 @@ static int lpphy_b2063_tune(struct b43_wldev *dev,
46221 {
46222 struct ssb_bus *bus = dev->dev->sdev->bus;
46223
46224 - static const struct b206x_channel *chandata = NULL;
46225 + const struct b206x_channel *chandata = NULL;
46226 u32 crystal_freq = bus->chipco.pmu.crystalfreq * 1000;
46227 u32 freqref, vco_freq, val1, val2, val3, timeout, timeoutref, count;
46228 u16 old_comm15, scale;
46229 diff --git a/drivers/net/wireless/iwlegacy/3945-mac.c b/drivers/net/wireless/iwlegacy/3945-mac.c
46230 index dea3b50..543db99 100644
46231 --- a/drivers/net/wireless/iwlegacy/3945-mac.c
46232 +++ b/drivers/net/wireless/iwlegacy/3945-mac.c
46233 @@ -3639,7 +3639,9 @@ il3945_pci_probe(struct pci_dev *pdev, const struct pci_device_id *ent)
46234 */
46235 if (il3945_mod_params.disable_hw_scan) {
46236 D_INFO("Disabling hw_scan\n");
46237 - il3945_mac_ops.hw_scan = NULL;
46238 + pax_open_kernel();
46239 + *(void **)&il3945_mac_ops.hw_scan = NULL;
46240 + pax_close_kernel();
46241 }
46242
46243 D_INFO("*** LOAD DRIVER ***\n");
46244 diff --git a/drivers/net/wireless/iwlwifi/dvm/debugfs.c b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46245 index d94f8ab..5b568c8 100644
46246 --- a/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46247 +++ b/drivers/net/wireless/iwlwifi/dvm/debugfs.c
46248 @@ -188,7 +188,7 @@ static ssize_t iwl_dbgfs_sram_write(struct file *file,
46249 {
46250 struct iwl_priv *priv = file->private_data;
46251 char buf[64];
46252 - int buf_size;
46253 + size_t buf_size;
46254 u32 offset, len;
46255
46256 memset(buf, 0, sizeof(buf));
46257 @@ -458,7 +458,7 @@ static ssize_t iwl_dbgfs_rx_handlers_write(struct file *file,
46258 struct iwl_priv *priv = file->private_data;
46259
46260 char buf[8];
46261 - int buf_size;
46262 + size_t buf_size;
46263 u32 reset_flag;
46264
46265 memset(buf, 0, sizeof(buf));
46266 @@ -539,7 +539,7 @@ static ssize_t iwl_dbgfs_disable_ht40_write(struct file *file,
46267 {
46268 struct iwl_priv *priv = file->private_data;
46269 char buf[8];
46270 - int buf_size;
46271 + size_t buf_size;
46272 int ht40;
46273
46274 memset(buf, 0, sizeof(buf));
46275 @@ -591,7 +591,7 @@ static ssize_t iwl_dbgfs_sleep_level_override_write(struct file *file,
46276 {
46277 struct iwl_priv *priv = file->private_data;
46278 char buf[8];
46279 - int buf_size;
46280 + size_t buf_size;
46281 int value;
46282
46283 memset(buf, 0, sizeof(buf));
46284 @@ -683,10 +683,10 @@ DEBUGFS_READ_FILE_OPS(temperature);
46285 DEBUGFS_READ_WRITE_FILE_OPS(sleep_level_override);
46286 DEBUGFS_READ_FILE_OPS(current_sleep_command);
46287
46288 -static const char *fmt_value = " %-30s %10u\n";
46289 -static const char *fmt_hex = " %-30s 0x%02X\n";
46290 -static const char *fmt_table = " %-30s %10u %10u %10u %10u\n";
46291 -static const char *fmt_header =
46292 +static const char fmt_value[] = " %-30s %10u\n";
46293 +static const char fmt_hex[] = " %-30s 0x%02X\n";
46294 +static const char fmt_table[] = " %-30s %10u %10u %10u %10u\n";
46295 +static const char fmt_header[] =
46296 "%-32s current cumulative delta max\n";
46297
46298 static int iwl_statistics_flag(struct iwl_priv *priv, char *buf, int bufsz)
46299 @@ -1856,7 +1856,7 @@ static ssize_t iwl_dbgfs_clear_ucode_statistics_write(struct file *file,
46300 {
46301 struct iwl_priv *priv = file->private_data;
46302 char buf[8];
46303 - int buf_size;
46304 + size_t buf_size;
46305 int clear;
46306
46307 memset(buf, 0, sizeof(buf));
46308 @@ -1901,7 +1901,7 @@ static ssize_t iwl_dbgfs_ucode_tracing_write(struct file *file,
46309 {
46310 struct iwl_priv *priv = file->private_data;
46311 char buf[8];
46312 - int buf_size;
46313 + size_t buf_size;
46314 int trace;
46315
46316 memset(buf, 0, sizeof(buf));
46317 @@ -1972,7 +1972,7 @@ static ssize_t iwl_dbgfs_missed_beacon_write(struct file *file,
46318 {
46319 struct iwl_priv *priv = file->private_data;
46320 char buf[8];
46321 - int buf_size;
46322 + size_t buf_size;
46323 int missed;
46324
46325 memset(buf, 0, sizeof(buf));
46326 @@ -2013,7 +2013,7 @@ static ssize_t iwl_dbgfs_plcp_delta_write(struct file *file,
46327
46328 struct iwl_priv *priv = file->private_data;
46329 char buf[8];
46330 - int buf_size;
46331 + size_t buf_size;
46332 int plcp;
46333
46334 memset(buf, 0, sizeof(buf));
46335 @@ -2073,7 +2073,7 @@ static ssize_t iwl_dbgfs_txfifo_flush_write(struct file *file,
46336
46337 struct iwl_priv *priv = file->private_data;
46338 char buf[8];
46339 - int buf_size;
46340 + size_t buf_size;
46341 int flush;
46342
46343 memset(buf, 0, sizeof(buf));
46344 @@ -2163,7 +2163,7 @@ static ssize_t iwl_dbgfs_protection_mode_write(struct file *file,
46345
46346 struct iwl_priv *priv = file->private_data;
46347 char buf[8];
46348 - int buf_size;
46349 + size_t buf_size;
46350 int rts;
46351
46352 if (!priv->cfg->ht_params)
46353 @@ -2205,7 +2205,7 @@ static ssize_t iwl_dbgfs_echo_test_write(struct file *file,
46354 {
46355 struct iwl_priv *priv = file->private_data;
46356 char buf[8];
46357 - int buf_size;
46358 + size_t buf_size;
46359
46360 memset(buf, 0, sizeof(buf));
46361 buf_size = min(count, sizeof(buf) - 1);
46362 @@ -2239,7 +2239,7 @@ static ssize_t iwl_dbgfs_log_event_write(struct file *file,
46363 struct iwl_priv *priv = file->private_data;
46364 u32 event_log_flag;
46365 char buf[8];
46366 - int buf_size;
46367 + size_t buf_size;
46368
46369 /* check that the interface is up */
46370 if (!iwl_is_ready(priv))
46371 @@ -2293,7 +2293,7 @@ static ssize_t iwl_dbgfs_calib_disabled_write(struct file *file,
46372 struct iwl_priv *priv = file->private_data;
46373 char buf[8];
46374 u32 calib_disabled;
46375 - int buf_size;
46376 + size_t buf_size;
46377
46378 memset(buf, 0, sizeof(buf));
46379 buf_size = min(count, sizeof(buf) - 1);
46380 diff --git a/drivers/net/wireless/iwlwifi/dvm/main.c b/drivers/net/wireless/iwlwifi/dvm/main.c
46381 index 7aad766..06addb4 100644
46382 --- a/drivers/net/wireless/iwlwifi/dvm/main.c
46383 +++ b/drivers/net/wireless/iwlwifi/dvm/main.c
46384 @@ -1123,7 +1123,7 @@ static void iwl_option_config(struct iwl_priv *priv)
46385 static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
46386 {
46387 struct iwl_nvm_data *data = priv->nvm_data;
46388 - char *debug_msg;
46389 + static const char debug_msg[] = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
46390
46391 if (data->sku_cap_11n_enable &&
46392 !priv->cfg->ht_params) {
46393 @@ -1137,7 +1137,6 @@ static int iwl_eeprom_init_hw_params(struct iwl_priv *priv)
46394 return -EINVAL;
46395 }
46396
46397 - debug_msg = "Device SKU: 24GHz %s %s, 52GHz %s %s, 11.n %s %s\n";
46398 IWL_DEBUG_INFO(priv, debug_msg,
46399 data->sku_cap_band_24GHz_enable ? "" : "NOT", "enabled",
46400 data->sku_cap_band_52GHz_enable ? "" : "NOT", "enabled",
46401 diff --git a/drivers/net/wireless/iwlwifi/pcie/trans.c b/drivers/net/wireless/iwlwifi/pcie/trans.c
46402 index f53ef83..5e34bcb 100644
46403 --- a/drivers/net/wireless/iwlwifi/pcie/trans.c
46404 +++ b/drivers/net/wireless/iwlwifi/pcie/trans.c
46405 @@ -1390,7 +1390,7 @@ static ssize_t iwl_dbgfs_interrupt_write(struct file *file,
46406 struct isr_statistics *isr_stats = &trans_pcie->isr_stats;
46407
46408 char buf[8];
46409 - int buf_size;
46410 + size_t buf_size;
46411 u32 reset_flag;
46412
46413 memset(buf, 0, sizeof(buf));
46414 @@ -1411,7 +1411,7 @@ static ssize_t iwl_dbgfs_csr_write(struct file *file,
46415 {
46416 struct iwl_trans *trans = file->private_data;
46417 char buf[8];
46418 - int buf_size;
46419 + size_t buf_size;
46420 int csr;
46421
46422 memset(buf, 0, sizeof(buf));
46423 diff --git a/drivers/net/wireless/mac80211_hwsim.c b/drivers/net/wireless/mac80211_hwsim.c
46424 index a1b32ee..94b3c3d 100644
46425 --- a/drivers/net/wireless/mac80211_hwsim.c
46426 +++ b/drivers/net/wireless/mac80211_hwsim.c
46427 @@ -2224,25 +2224,19 @@ static int __init init_mac80211_hwsim(void)
46428
46429 if (channels > 1) {
46430 hwsim_if_comb.num_different_channels = channels;
46431 - mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
46432 - mac80211_hwsim_ops.cancel_hw_scan =
46433 - mac80211_hwsim_cancel_hw_scan;
46434 - mac80211_hwsim_ops.sw_scan_start = NULL;
46435 - mac80211_hwsim_ops.sw_scan_complete = NULL;
46436 - mac80211_hwsim_ops.remain_on_channel =
46437 - mac80211_hwsim_roc;
46438 - mac80211_hwsim_ops.cancel_remain_on_channel =
46439 - mac80211_hwsim_croc;
46440 - mac80211_hwsim_ops.add_chanctx =
46441 - mac80211_hwsim_add_chanctx;
46442 - mac80211_hwsim_ops.remove_chanctx =
46443 - mac80211_hwsim_remove_chanctx;
46444 - mac80211_hwsim_ops.change_chanctx =
46445 - mac80211_hwsim_change_chanctx;
46446 - mac80211_hwsim_ops.assign_vif_chanctx =
46447 - mac80211_hwsim_assign_vif_chanctx;
46448 - mac80211_hwsim_ops.unassign_vif_chanctx =
46449 - mac80211_hwsim_unassign_vif_chanctx;
46450 + pax_open_kernel();
46451 + *(void **)&mac80211_hwsim_ops.hw_scan = mac80211_hwsim_hw_scan;
46452 + *(void **)&mac80211_hwsim_ops.cancel_hw_scan = mac80211_hwsim_cancel_hw_scan;
46453 + *(void **)&mac80211_hwsim_ops.sw_scan_start = NULL;
46454 + *(void **)&mac80211_hwsim_ops.sw_scan_complete = NULL;
46455 + *(void **)&mac80211_hwsim_ops.remain_on_channel = mac80211_hwsim_roc;
46456 + *(void **)&mac80211_hwsim_ops.cancel_remain_on_channel = mac80211_hwsim_croc;
46457 + *(void **)&mac80211_hwsim_ops.add_chanctx = mac80211_hwsim_add_chanctx;
46458 + *(void **)&mac80211_hwsim_ops.remove_chanctx = mac80211_hwsim_remove_chanctx;
46459 + *(void **)&mac80211_hwsim_ops.change_chanctx = mac80211_hwsim_change_chanctx;
46460 + *(void **)&mac80211_hwsim_ops.assign_vif_chanctx = mac80211_hwsim_assign_vif_chanctx;
46461 + *(void **)&mac80211_hwsim_ops.unassign_vif_chanctx = mac80211_hwsim_unassign_vif_chanctx;
46462 + pax_close_kernel();
46463 }
46464
46465 spin_lock_init(&hwsim_radio_lock);
46466 diff --git a/drivers/net/wireless/rndis_wlan.c b/drivers/net/wireless/rndis_wlan.c
46467 index 8169a85..7fa3b47 100644
46468 --- a/drivers/net/wireless/rndis_wlan.c
46469 +++ b/drivers/net/wireless/rndis_wlan.c
46470 @@ -1238,7 +1238,7 @@ static int set_rts_threshold(struct usbnet *usbdev, u32 rts_threshold)
46471
46472 netdev_dbg(usbdev->net, "%s(): %i\n", __func__, rts_threshold);
46473
46474 - if (rts_threshold < 0 || rts_threshold > 2347)
46475 + if (rts_threshold > 2347)
46476 rts_threshold = 2347;
46477
46478 tmp = cpu_to_le32(rts_threshold);
46479 diff --git a/drivers/net/wireless/rt2x00/rt2x00.h b/drivers/net/wireless/rt2x00/rt2x00.h
46480 index e4ba2ce..63d7417 100644
46481 --- a/drivers/net/wireless/rt2x00/rt2x00.h
46482 +++ b/drivers/net/wireless/rt2x00/rt2x00.h
46483 @@ -377,7 +377,7 @@ struct rt2x00_intf {
46484 * for hardware which doesn't support hardware
46485 * sequence counting.
46486 */
46487 - atomic_t seqno;
46488 + atomic_unchecked_t seqno;
46489 };
46490
46491 static inline struct rt2x00_intf* vif_to_intf(struct ieee80211_vif *vif)
46492 diff --git a/drivers/net/wireless/rt2x00/rt2x00queue.c b/drivers/net/wireless/rt2x00/rt2x00queue.c
46493 index a5d38e8..d3c24ea 100644
46494 --- a/drivers/net/wireless/rt2x00/rt2x00queue.c
46495 +++ b/drivers/net/wireless/rt2x00/rt2x00queue.c
46496 @@ -252,9 +252,9 @@ static void rt2x00queue_create_tx_descriptor_seq(struct rt2x00_dev *rt2x00dev,
46497 * sequence counter given by mac80211.
46498 */
46499 if (test_bit(ENTRY_TXD_FIRST_FRAGMENT, &txdesc->flags))
46500 - seqno = atomic_add_return(0x10, &intf->seqno);
46501 + seqno = atomic_add_return_unchecked(0x10, &intf->seqno);
46502 else
46503 - seqno = atomic_read(&intf->seqno);
46504 + seqno = atomic_read_unchecked(&intf->seqno);
46505
46506 hdr->seq_ctrl &= cpu_to_le16(IEEE80211_SCTL_FRAG);
46507 hdr->seq_ctrl |= cpu_to_le16(seqno);
46508 diff --git a/drivers/net/wireless/ti/wl1251/sdio.c b/drivers/net/wireless/ti/wl1251/sdio.c
46509 index e2b3d9c..67a5184 100644
46510 --- a/drivers/net/wireless/ti/wl1251/sdio.c
46511 +++ b/drivers/net/wireless/ti/wl1251/sdio.c
46512 @@ -271,13 +271,17 @@ static int wl1251_sdio_probe(struct sdio_func *func,
46513
46514 irq_set_irq_type(wl->irq, IRQ_TYPE_EDGE_RISING);
46515
46516 - wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
46517 - wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
46518 + pax_open_kernel();
46519 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_enable_line_irq;
46520 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_disable_line_irq;
46521 + pax_close_kernel();
46522
46523 wl1251_info("using dedicated interrupt line");
46524 } else {
46525 - wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
46526 - wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
46527 + pax_open_kernel();
46528 + *(void **)&wl1251_sdio_ops.enable_irq = wl1251_sdio_enable_irq;
46529 + *(void **)&wl1251_sdio_ops.disable_irq = wl1251_sdio_disable_irq;
46530 + pax_close_kernel();
46531
46532 wl1251_info("using SDIO interrupt");
46533 }
46534 diff --git a/drivers/net/wireless/ti/wl12xx/main.c b/drivers/net/wireless/ti/wl12xx/main.c
46535 index be7129b..4161356 100644
46536 --- a/drivers/net/wireless/ti/wl12xx/main.c
46537 +++ b/drivers/net/wireless/ti/wl12xx/main.c
46538 @@ -656,7 +656,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
46539 sizeof(wl->conf.mem));
46540
46541 /* read data preparation is only needed by wl127x */
46542 - wl->ops->prepare_read = wl127x_prepare_read;
46543 + pax_open_kernel();
46544 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
46545 + pax_close_kernel();
46546
46547 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
46548 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
46549 @@ -681,7 +683,9 @@ static int wl12xx_identify_chip(struct wl1271 *wl)
46550 sizeof(wl->conf.mem));
46551
46552 /* read data preparation is only needed by wl127x */
46553 - wl->ops->prepare_read = wl127x_prepare_read;
46554 + pax_open_kernel();
46555 + *(void **)&wl->ops->prepare_read = wl127x_prepare_read;
46556 + pax_close_kernel();
46557
46558 wlcore_set_min_fw_ver(wl, WL127X_CHIP_VER,
46559 WL127X_IFTYPE_SR_VER, WL127X_MAJOR_SR_VER,
46560 diff --git a/drivers/net/wireless/ti/wl18xx/main.c b/drivers/net/wireless/ti/wl18xx/main.c
46561 index ec37b16..7e34d66 100644
46562 --- a/drivers/net/wireless/ti/wl18xx/main.c
46563 +++ b/drivers/net/wireless/ti/wl18xx/main.c
46564 @@ -1823,8 +1823,10 @@ static int wl18xx_setup(struct wl1271 *wl)
46565 }
46566
46567 if (!checksum_param) {
46568 - wl18xx_ops.set_rx_csum = NULL;
46569 - wl18xx_ops.init_vif = NULL;
46570 + pax_open_kernel();
46571 + *(void **)&wl18xx_ops.set_rx_csum = NULL;
46572 + *(void **)&wl18xx_ops.init_vif = NULL;
46573 + pax_close_kernel();
46574 }
46575
46576 /* Enable 11a Band only if we have 5G antennas */
46577 diff --git a/drivers/net/wireless/zd1211rw/zd_usb.c b/drivers/net/wireless/zd1211rw/zd_usb.c
46578 index 84d94f5..bd6c61c 100644
46579 --- a/drivers/net/wireless/zd1211rw/zd_usb.c
46580 +++ b/drivers/net/wireless/zd1211rw/zd_usb.c
46581 @@ -386,7 +386,7 @@ static inline void handle_regs_int(struct urb *urb)
46582 {
46583 struct zd_usb *usb = urb->context;
46584 struct zd_usb_interrupt *intr = &usb->intr;
46585 - int len;
46586 + unsigned int len;
46587 u16 int_num;
46588
46589 ZD_ASSERT(in_interrupt());
46590 diff --git a/drivers/nfc/nfcwilink.c b/drivers/nfc/nfcwilink.c
46591 index 7130864..00e64de 100644
46592 --- a/drivers/nfc/nfcwilink.c
46593 +++ b/drivers/nfc/nfcwilink.c
46594 @@ -498,7 +498,7 @@ static struct nci_ops nfcwilink_ops = {
46595
46596 static int nfcwilink_probe(struct platform_device *pdev)
46597 {
46598 - static struct nfcwilink *drv;
46599 + struct nfcwilink *drv;
46600 int rc;
46601 __u32 protocols;
46602
46603 diff --git a/drivers/oprofile/buffer_sync.c b/drivers/oprofile/buffer_sync.c
46604 index d93b2b6..ae50401 100644
46605 --- a/drivers/oprofile/buffer_sync.c
46606 +++ b/drivers/oprofile/buffer_sync.c
46607 @@ -332,7 +332,7 @@ static void add_data(struct op_entry *entry, struct mm_struct *mm)
46608 if (cookie == NO_COOKIE)
46609 offset = pc;
46610 if (cookie == INVALID_COOKIE) {
46611 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
46612 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
46613 offset = pc;
46614 }
46615 if (cookie != last_cookie) {
46616 @@ -376,14 +376,14 @@ add_sample(struct mm_struct *mm, struct op_sample *s, int in_kernel)
46617 /* add userspace sample */
46618
46619 if (!mm) {
46620 - atomic_inc(&oprofile_stats.sample_lost_no_mm);
46621 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mm);
46622 return 0;
46623 }
46624
46625 cookie = lookup_dcookie(mm, s->eip, &offset);
46626
46627 if (cookie == INVALID_COOKIE) {
46628 - atomic_inc(&oprofile_stats.sample_lost_no_mapping);
46629 + atomic_inc_unchecked(&oprofile_stats.sample_lost_no_mapping);
46630 return 0;
46631 }
46632
46633 @@ -552,7 +552,7 @@ void sync_buffer(int cpu)
46634 /* ignore backtraces if failed to add a sample */
46635 if (state == sb_bt_start) {
46636 state = sb_bt_ignore;
46637 - atomic_inc(&oprofile_stats.bt_lost_no_mapping);
46638 + atomic_inc_unchecked(&oprofile_stats.bt_lost_no_mapping);
46639 }
46640 }
46641 release_mm(mm);
46642 diff --git a/drivers/oprofile/event_buffer.c b/drivers/oprofile/event_buffer.c
46643 index c0cc4e7..44d4e54 100644
46644 --- a/drivers/oprofile/event_buffer.c
46645 +++ b/drivers/oprofile/event_buffer.c
46646 @@ -53,7 +53,7 @@ void add_event_entry(unsigned long value)
46647 }
46648
46649 if (buffer_pos == buffer_size) {
46650 - atomic_inc(&oprofile_stats.event_lost_overflow);
46651 + atomic_inc_unchecked(&oprofile_stats.event_lost_overflow);
46652 return;
46653 }
46654
46655 diff --git a/drivers/oprofile/oprof.c b/drivers/oprofile/oprof.c
46656 index ed2c3ec..deda85a 100644
46657 --- a/drivers/oprofile/oprof.c
46658 +++ b/drivers/oprofile/oprof.c
46659 @@ -110,7 +110,7 @@ static void switch_worker(struct work_struct *work)
46660 if (oprofile_ops.switch_events())
46661 return;
46662
46663 - atomic_inc(&oprofile_stats.multiplex_counter);
46664 + atomic_inc_unchecked(&oprofile_stats.multiplex_counter);
46665 start_switch_worker();
46666 }
46667
46668 diff --git a/drivers/oprofile/oprofile_files.c b/drivers/oprofile/oprofile_files.c
46669 index ee2cfce..7f8f699 100644
46670 --- a/drivers/oprofile/oprofile_files.c
46671 +++ b/drivers/oprofile/oprofile_files.c
46672 @@ -27,7 +27,7 @@ unsigned long oprofile_time_slice;
46673
46674 #ifdef CONFIG_OPROFILE_EVENT_MULTIPLEX
46675
46676 -static ssize_t timeout_read(struct file *file, char __user *buf,
46677 +static ssize_t __intentional_overflow(-1) timeout_read(struct file *file, char __user *buf,
46678 size_t count, loff_t *offset)
46679 {
46680 return oprofilefs_ulong_to_user(jiffies_to_msecs(oprofile_time_slice),
46681 diff --git a/drivers/oprofile/oprofile_stats.c b/drivers/oprofile/oprofile_stats.c
46682 index 59659ce..6c860a0 100644
46683 --- a/drivers/oprofile/oprofile_stats.c
46684 +++ b/drivers/oprofile/oprofile_stats.c
46685 @@ -30,11 +30,11 @@ void oprofile_reset_stats(void)
46686 cpu_buf->sample_invalid_eip = 0;
46687 }
46688
46689 - atomic_set(&oprofile_stats.sample_lost_no_mm, 0);
46690 - atomic_set(&oprofile_stats.sample_lost_no_mapping, 0);
46691 - atomic_set(&oprofile_stats.event_lost_overflow, 0);
46692 - atomic_set(&oprofile_stats.bt_lost_no_mapping, 0);
46693 - atomic_set(&oprofile_stats.multiplex_counter, 0);
46694 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mm, 0);
46695 + atomic_set_unchecked(&oprofile_stats.sample_lost_no_mapping, 0);
46696 + atomic_set_unchecked(&oprofile_stats.event_lost_overflow, 0);
46697 + atomic_set_unchecked(&oprofile_stats.bt_lost_no_mapping, 0);
46698 + atomic_set_unchecked(&oprofile_stats.multiplex_counter, 0);
46699 }
46700
46701
46702 diff --git a/drivers/oprofile/oprofile_stats.h b/drivers/oprofile/oprofile_stats.h
46703 index 1fc622b..8c48fc3 100644
46704 --- a/drivers/oprofile/oprofile_stats.h
46705 +++ b/drivers/oprofile/oprofile_stats.h
46706 @@ -13,11 +13,11 @@
46707 #include <linux/atomic.h>
46708
46709 struct oprofile_stat_struct {
46710 - atomic_t sample_lost_no_mm;
46711 - atomic_t sample_lost_no_mapping;
46712 - atomic_t bt_lost_no_mapping;
46713 - atomic_t event_lost_overflow;
46714 - atomic_t multiplex_counter;
46715 + atomic_unchecked_t sample_lost_no_mm;
46716 + atomic_unchecked_t sample_lost_no_mapping;
46717 + atomic_unchecked_t bt_lost_no_mapping;
46718 + atomic_unchecked_t event_lost_overflow;
46719 + atomic_unchecked_t multiplex_counter;
46720 };
46721
46722 extern struct oprofile_stat_struct oprofile_stats;
46723 diff --git a/drivers/oprofile/oprofilefs.c b/drivers/oprofile/oprofilefs.c
46724 index 3f49345..c750d0b 100644
46725 --- a/drivers/oprofile/oprofilefs.c
46726 +++ b/drivers/oprofile/oprofilefs.c
46727 @@ -176,8 +176,8 @@ int oprofilefs_create_ro_ulong(struct dentry *root,
46728
46729 static ssize_t atomic_read_file(struct file *file, char __user *buf, size_t count, loff_t *offset)
46730 {
46731 - atomic_t *val = file->private_data;
46732 - return oprofilefs_ulong_to_user(atomic_read(val), buf, count, offset);
46733 + atomic_unchecked_t *val = file->private_data;
46734 + return oprofilefs_ulong_to_user(atomic_read_unchecked(val), buf, count, offset);
46735 }
46736
46737
46738 @@ -189,7 +189,7 @@ static const struct file_operations atomic_ro_fops = {
46739
46740
46741 int oprofilefs_create_ro_atomic(struct dentry *root,
46742 - char const *name, atomic_t *val)
46743 + char const *name, atomic_unchecked_t *val)
46744 {
46745 return __oprofilefs_create_file(root, name,
46746 &atomic_ro_fops, 0444, val);
46747 diff --git a/drivers/oprofile/timer_int.c b/drivers/oprofile/timer_int.c
46748 index 61be1d9..dec05d7 100644
46749 --- a/drivers/oprofile/timer_int.c
46750 +++ b/drivers/oprofile/timer_int.c
46751 @@ -93,7 +93,7 @@ static int oprofile_cpu_notify(struct notifier_block *self,
46752 return NOTIFY_OK;
46753 }
46754
46755 -static struct notifier_block __refdata oprofile_cpu_notifier = {
46756 +static struct notifier_block oprofile_cpu_notifier = {
46757 .notifier_call = oprofile_cpu_notify,
46758 };
46759
46760 diff --git a/drivers/parport/procfs.c b/drivers/parport/procfs.c
46761 index 92ed045..62d39bd7 100644
46762 --- a/drivers/parport/procfs.c
46763 +++ b/drivers/parport/procfs.c
46764 @@ -64,7 +64,7 @@ static int do_active_device(ctl_table *table, int write,
46765
46766 *ppos += len;
46767
46768 - return copy_to_user(result, buffer, len) ? -EFAULT : 0;
46769 + return (len > sizeof buffer || copy_to_user(result, buffer, len)) ? -EFAULT : 0;
46770 }
46771
46772 #ifdef CONFIG_PARPORT_1284
46773 @@ -106,7 +106,7 @@ static int do_autoprobe(ctl_table *table, int write,
46774
46775 *ppos += len;
46776
46777 - return copy_to_user (result, buffer, len) ? -EFAULT : 0;
46778 + return (len > sizeof buffer || copy_to_user (result, buffer, len)) ? -EFAULT : 0;
46779 }
46780 #endif /* IEEE1284.3 support. */
46781
46782 diff --git a/drivers/pci/hotplug/acpiphp_ibm.c b/drivers/pci/hotplug/acpiphp_ibm.c
46783 index ecfac7e..41be7028 100644
46784 --- a/drivers/pci/hotplug/acpiphp_ibm.c
46785 +++ b/drivers/pci/hotplug/acpiphp_ibm.c
46786 @@ -453,7 +453,9 @@ static int __init ibm_acpiphp_init(void)
46787 goto init_cleanup;
46788 }
46789
46790 - ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
46791 + pax_open_kernel();
46792 + *(size_t *)&ibm_apci_table_attr.size = ibm_get_table_from_acpi(NULL);
46793 + pax_close_kernel();
46794 retval = sysfs_create_bin_file(sysdir, &ibm_apci_table_attr);
46795
46796 return retval;
46797 diff --git a/drivers/pci/hotplug/cpcihp_generic.c b/drivers/pci/hotplug/cpcihp_generic.c
46798 index 7536eef..52dc8fa 100644
46799 --- a/drivers/pci/hotplug/cpcihp_generic.c
46800 +++ b/drivers/pci/hotplug/cpcihp_generic.c
46801 @@ -73,7 +73,6 @@ static u16 port;
46802 static unsigned int enum_bit;
46803 static u8 enum_mask;
46804
46805 -static struct cpci_hp_controller_ops generic_hpc_ops;
46806 static struct cpci_hp_controller generic_hpc;
46807
46808 static int __init validate_parameters(void)
46809 @@ -139,6 +138,10 @@ static int query_enum(void)
46810 return ((value & enum_mask) == enum_mask);
46811 }
46812
46813 +static struct cpci_hp_controller_ops generic_hpc_ops = {
46814 + .query_enum = query_enum,
46815 +};
46816 +
46817 static int __init cpcihp_generic_init(void)
46818 {
46819 int status;
46820 @@ -165,7 +168,6 @@ static int __init cpcihp_generic_init(void)
46821 pci_dev_put(dev);
46822
46823 memset(&generic_hpc, 0, sizeof (struct cpci_hp_controller));
46824 - generic_hpc_ops.query_enum = query_enum;
46825 generic_hpc.ops = &generic_hpc_ops;
46826
46827 status = cpci_hp_register_controller(&generic_hpc);
46828 diff --git a/drivers/pci/hotplug/cpcihp_zt5550.c b/drivers/pci/hotplug/cpcihp_zt5550.c
46829 index e8c4a7c..7046f5c 100644
46830 --- a/drivers/pci/hotplug/cpcihp_zt5550.c
46831 +++ b/drivers/pci/hotplug/cpcihp_zt5550.c
46832 @@ -59,7 +59,6 @@
46833 /* local variables */
46834 static bool debug;
46835 static bool poll;
46836 -static struct cpci_hp_controller_ops zt5550_hpc_ops;
46837 static struct cpci_hp_controller zt5550_hpc;
46838
46839 /* Primary cPCI bus bridge device */
46840 @@ -205,6 +204,10 @@ static int zt5550_hc_disable_irq(void)
46841 return 0;
46842 }
46843
46844 +static struct cpci_hp_controller_ops zt5550_hpc_ops = {
46845 + .query_enum = zt5550_hc_query_enum,
46846 +};
46847 +
46848 static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id *ent)
46849 {
46850 int status;
46851 @@ -216,16 +219,17 @@ static int zt5550_hc_init_one (struct pci_dev *pdev, const struct pci_device_id
46852 dbg("returned from zt5550_hc_config");
46853
46854 memset(&zt5550_hpc, 0, sizeof (struct cpci_hp_controller));
46855 - zt5550_hpc_ops.query_enum = zt5550_hc_query_enum;
46856 zt5550_hpc.ops = &zt5550_hpc_ops;
46857 if(!poll) {
46858 zt5550_hpc.irq = hc_dev->irq;
46859 zt5550_hpc.irq_flags = IRQF_SHARED;
46860 zt5550_hpc.dev_id = hc_dev;
46861
46862 - zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
46863 - zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
46864 - zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
46865 + pax_open_kernel();
46866 + *(void **)&zt5550_hpc_ops.enable_irq = zt5550_hc_enable_irq;
46867 + *(void **)&zt5550_hpc_ops.disable_irq = zt5550_hc_disable_irq;
46868 + *(void **)&zt5550_hpc_ops.check_irq = zt5550_hc_check_irq;
46869 + pax_open_kernel();
46870 } else {
46871 info("using ENUM# polling mode");
46872 }
46873 diff --git a/drivers/pci/hotplug/cpqphp_nvram.c b/drivers/pci/hotplug/cpqphp_nvram.c
46874 index 76ba8a1..20ca857 100644
46875 --- a/drivers/pci/hotplug/cpqphp_nvram.c
46876 +++ b/drivers/pci/hotplug/cpqphp_nvram.c
46877 @@ -428,9 +428,13 @@ static u32 store_HRT (void __iomem *rom_start)
46878
46879 void compaq_nvram_init (void __iomem *rom_start)
46880 {
46881 +
46882 +#ifndef CONFIG_PAX_KERNEXEC
46883 if (rom_start) {
46884 compaq_int15_entry_point = (rom_start + ROM_INT15_PHY_ADDR - ROM_PHY_ADDR);
46885 }
46886 +#endif
46887 +
46888 dbg("int15 entry = %p\n", compaq_int15_entry_point);
46889
46890 /* initialize our int15 lock */
46891 diff --git a/drivers/pci/hotplug/pci_hotplug_core.c b/drivers/pci/hotplug/pci_hotplug_core.c
46892 index cfa92a9..29539c5 100644
46893 --- a/drivers/pci/hotplug/pci_hotplug_core.c
46894 +++ b/drivers/pci/hotplug/pci_hotplug_core.c
46895 @@ -441,8 +441,10 @@ int __pci_hp_register(struct hotplug_slot *slot, struct pci_bus *bus,
46896 return -EINVAL;
46897 }
46898
46899 - slot->ops->owner = owner;
46900 - slot->ops->mod_name = mod_name;
46901 + pax_open_kernel();
46902 + *(struct module **)&slot->ops->owner = owner;
46903 + *(const char **)&slot->ops->mod_name = mod_name;
46904 + pax_close_kernel();
46905
46906 mutex_lock(&pci_hp_mutex);
46907 /*
46908 diff --git a/drivers/pci/hotplug/pciehp_core.c b/drivers/pci/hotplug/pciehp_core.c
46909 index bbd48bb..6907ef4 100644
46910 --- a/drivers/pci/hotplug/pciehp_core.c
46911 +++ b/drivers/pci/hotplug/pciehp_core.c
46912 @@ -92,7 +92,7 @@ static int init_slot(struct controller *ctrl)
46913 struct slot *slot = ctrl->slot;
46914 struct hotplug_slot *hotplug = NULL;
46915 struct hotplug_slot_info *info = NULL;
46916 - struct hotplug_slot_ops *ops = NULL;
46917 + hotplug_slot_ops_no_const *ops = NULL;
46918 char name[SLOT_NAME_SIZE];
46919 int retval = -ENOMEM;
46920
46921 diff --git a/drivers/pci/pci-sysfs.c b/drivers/pci/pci-sysfs.c
46922 index c91e6c1..5c723ef 100644
46923 --- a/drivers/pci/pci-sysfs.c
46924 +++ b/drivers/pci/pci-sysfs.c
46925 @@ -1117,7 +1117,7 @@ static int pci_create_attr(struct pci_dev *pdev, int num, int write_combine)
46926 {
46927 /* allocate attribute structure, piggyback attribute name */
46928 int name_len = write_combine ? 13 : 10;
46929 - struct bin_attribute *res_attr;
46930 + bin_attribute_no_const *res_attr;
46931 int retval;
46932
46933 res_attr = kzalloc(sizeof(*res_attr) + name_len, GFP_ATOMIC);
46934 @@ -1302,7 +1302,7 @@ static struct device_attribute reset_attr = __ATTR(reset, 0200, NULL, reset_stor
46935 static int pci_create_capabilities_sysfs(struct pci_dev *dev)
46936 {
46937 int retval;
46938 - struct bin_attribute *attr;
46939 + bin_attribute_no_const *attr;
46940
46941 /* If the device has VPD, try to expose it in sysfs. */
46942 if (dev->vpd) {
46943 @@ -1349,7 +1349,7 @@ int __must_check pci_create_sysfs_dev_files (struct pci_dev *pdev)
46944 {
46945 int retval;
46946 int rom_size = 0;
46947 - struct bin_attribute *attr;
46948 + bin_attribute_no_const *attr;
46949
46950 if (!sysfs_initialized)
46951 return -EACCES;
46952 diff --git a/drivers/pci/pci.h b/drivers/pci/pci.h
46953 index 9c91ecc..bda4796 100644
46954 --- a/drivers/pci/pci.h
46955 +++ b/drivers/pci/pci.h
46956 @@ -95,7 +95,7 @@ struct pci_vpd_ops {
46957 struct pci_vpd {
46958 unsigned int len;
46959 const struct pci_vpd_ops *ops;
46960 - struct bin_attribute *attr; /* descriptor for sysfs VPD entry */
46961 + bin_attribute_no_const *attr; /* descriptor for sysfs VPD entry */
46962 };
46963
46964 int pci_vpd_pci22_init(struct pci_dev *dev);
46965 diff --git a/drivers/pci/pcie/aspm.c b/drivers/pci/pcie/aspm.c
46966 index f1272dc..e92a1ac 100644
46967 --- a/drivers/pci/pcie/aspm.c
46968 +++ b/drivers/pci/pcie/aspm.c
46969 @@ -27,9 +27,9 @@
46970 #define MODULE_PARAM_PREFIX "pcie_aspm."
46971
46972 /* Note: those are not register definitions */
46973 -#define ASPM_STATE_L0S_UP (1) /* Upstream direction L0s state */
46974 -#define ASPM_STATE_L0S_DW (2) /* Downstream direction L0s state */
46975 -#define ASPM_STATE_L1 (4) /* L1 state */
46976 +#define ASPM_STATE_L0S_UP (1U) /* Upstream direction L0s state */
46977 +#define ASPM_STATE_L0S_DW (2U) /* Downstream direction L0s state */
46978 +#define ASPM_STATE_L1 (4U) /* L1 state */
46979 #define ASPM_STATE_L0S (ASPM_STATE_L0S_UP | ASPM_STATE_L0S_DW)
46980 #define ASPM_STATE_ALL (ASPM_STATE_L0S | ASPM_STATE_L1)
46981
46982 diff --git a/drivers/pci/probe.c b/drivers/pci/probe.c
46983 index 38e403d..a2ce55a 100644
46984 --- a/drivers/pci/probe.c
46985 +++ b/drivers/pci/probe.c
46986 @@ -175,7 +175,7 @@ int __pci_read_base(struct pci_dev *dev, enum pci_bar_type type,
46987 struct pci_bus_region region, inverted_region;
46988 bool bar_too_big = false, bar_disabled = false;
46989
46990 - mask = type ? PCI_ROM_ADDRESS_MASK : ~0;
46991 + mask = type ? (u32)PCI_ROM_ADDRESS_MASK : ~0;
46992
46993 /* No printks while decoding is disabled! */
46994 if (!dev->mmio_always_on) {
46995 diff --git a/drivers/pci/proc.c b/drivers/pci/proc.c
46996 index 46d1378..30e452b 100644
46997 --- a/drivers/pci/proc.c
46998 +++ b/drivers/pci/proc.c
46999 @@ -434,7 +434,16 @@ static const struct file_operations proc_bus_pci_dev_operations = {
47000 static int __init pci_proc_init(void)
47001 {
47002 struct pci_dev *dev = NULL;
47003 +
47004 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
47005 +#ifdef CONFIG_GRKERNSEC_PROC_USER
47006 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR, NULL);
47007 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
47008 + proc_bus_pci_dir = proc_mkdir_mode("bus/pci", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
47009 +#endif
47010 +#else
47011 proc_bus_pci_dir = proc_mkdir("bus/pci", NULL);
47012 +#endif
47013 proc_create("devices", 0, proc_bus_pci_dir,
47014 &proc_bus_pci_dev_operations);
47015 proc_initialized = 1;
47016 diff --git a/drivers/platform/chrome/chromeos_laptop.c b/drivers/platform/chrome/chromeos_laptop.c
47017 index 3e5b4497..dcdfb70 100644
47018 --- a/drivers/platform/chrome/chromeos_laptop.c
47019 +++ b/drivers/platform/chrome/chromeos_laptop.c
47020 @@ -301,7 +301,7 @@ static int __init setup_tsl2563_als(const struct dmi_system_id *id)
47021 return 0;
47022 }
47023
47024 -static struct dmi_system_id __initdata chromeos_laptop_dmi_table[] = {
47025 +static struct dmi_system_id __initconst chromeos_laptop_dmi_table[] = {
47026 {
47027 .ident = "Samsung Series 5 550 - Touchpad",
47028 .matches = {
47029 diff --git a/drivers/platform/x86/asus-wmi.c b/drivers/platform/x86/asus-wmi.c
47030 index 19c313b..ed28b38 100644
47031 --- a/drivers/platform/x86/asus-wmi.c
47032 +++ b/drivers/platform/x86/asus-wmi.c
47033 @@ -1618,6 +1618,10 @@ static int show_dsts(struct seq_file *m, void *data)
47034 int err;
47035 u32 retval = -1;
47036
47037 +#ifdef CONFIG_GRKERNSEC_KMEM
47038 + return -EPERM;
47039 +#endif
47040 +
47041 err = asus_wmi_get_devstate(asus, asus->debug.dev_id, &retval);
47042
47043 if (err < 0)
47044 @@ -1634,6 +1638,10 @@ static int show_devs(struct seq_file *m, void *data)
47045 int err;
47046 u32 retval = -1;
47047
47048 +#ifdef CONFIG_GRKERNSEC_KMEM
47049 + return -EPERM;
47050 +#endif
47051 +
47052 err = asus_wmi_set_devstate(asus->debug.dev_id, asus->debug.ctrl_param,
47053 &retval);
47054
47055 @@ -1658,6 +1666,10 @@ static int show_call(struct seq_file *m, void *data)
47056 union acpi_object *obj;
47057 acpi_status status;
47058
47059 +#ifdef CONFIG_GRKERNSEC_KMEM
47060 + return -EPERM;
47061 +#endif
47062 +
47063 status = wmi_evaluate_method(ASUS_WMI_MGMT_GUID,
47064 1, asus->debug.method_id,
47065 &input, &output);
47066 diff --git a/drivers/platform/x86/msi-laptop.c b/drivers/platform/x86/msi-laptop.c
47067 index 62f8030..c7f2a45 100644
47068 --- a/drivers/platform/x86/msi-laptop.c
47069 +++ b/drivers/platform/x86/msi-laptop.c
47070 @@ -1000,12 +1000,14 @@ static int __init load_scm_model_init(struct platform_device *sdev)
47071
47072 if (!quirks->ec_read_only) {
47073 /* allow userland write sysfs file */
47074 - dev_attr_bluetooth.store = store_bluetooth;
47075 - dev_attr_wlan.store = store_wlan;
47076 - dev_attr_threeg.store = store_threeg;
47077 - dev_attr_bluetooth.attr.mode |= S_IWUSR;
47078 - dev_attr_wlan.attr.mode |= S_IWUSR;
47079 - dev_attr_threeg.attr.mode |= S_IWUSR;
47080 + pax_open_kernel();
47081 + *(void **)&dev_attr_bluetooth.store = store_bluetooth;
47082 + *(void **)&dev_attr_wlan.store = store_wlan;
47083 + *(void **)&dev_attr_threeg.store = store_threeg;
47084 + *(umode_t *)&dev_attr_bluetooth.attr.mode |= S_IWUSR;
47085 + *(umode_t *)&dev_attr_wlan.attr.mode |= S_IWUSR;
47086 + *(umode_t *)&dev_attr_threeg.attr.mode |= S_IWUSR;
47087 + pax_close_kernel();
47088 }
47089
47090 /* disable hardware control by fn key */
47091 diff --git a/drivers/platform/x86/msi-wmi.c b/drivers/platform/x86/msi-wmi.c
47092 index 70222f2..8c8ce66 100644
47093 --- a/drivers/platform/x86/msi-wmi.c
47094 +++ b/drivers/platform/x86/msi-wmi.c
47095 @@ -183,7 +183,7 @@ static const struct backlight_ops msi_backlight_ops = {
47096 static void msi_wmi_notify(u32 value, void *context)
47097 {
47098 struct acpi_buffer response = { ACPI_ALLOCATE_BUFFER, NULL };
47099 - static struct key_entry *key;
47100 + struct key_entry *key;
47101 union acpi_object *obj;
47102 acpi_status status;
47103
47104 diff --git a/drivers/platform/x86/sony-laptop.c b/drivers/platform/x86/sony-laptop.c
47105 index fb233ae..23a325c 100644
47106 --- a/drivers/platform/x86/sony-laptop.c
47107 +++ b/drivers/platform/x86/sony-laptop.c
47108 @@ -2453,7 +2453,7 @@ static void sony_nc_gfx_switch_cleanup(struct platform_device *pd)
47109 }
47110
47111 /* High speed charging function */
47112 -static struct device_attribute *hsc_handle;
47113 +static device_attribute_no_const *hsc_handle;
47114
47115 static ssize_t sony_nc_highspeed_charging_store(struct device *dev,
47116 struct device_attribute *attr,
47117 diff --git a/drivers/platform/x86/thinkpad_acpi.c b/drivers/platform/x86/thinkpad_acpi.c
47118 index 58b0274..6704626 100644
47119 --- a/drivers/platform/x86/thinkpad_acpi.c
47120 +++ b/drivers/platform/x86/thinkpad_acpi.c
47121 @@ -2100,7 +2100,7 @@ static int hotkey_mask_get(void)
47122 return 0;
47123 }
47124
47125 -void static hotkey_mask_warn_incomplete_mask(void)
47126 +static void hotkey_mask_warn_incomplete_mask(void)
47127 {
47128 /* log only what the user can fix... */
47129 const u32 wantedmask = hotkey_driver_mask &
47130 @@ -2327,11 +2327,6 @@ static void hotkey_read_nvram(struct tp_nvram_state *n, const u32 m)
47131 }
47132 }
47133
47134 -static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47135 - struct tp_nvram_state *newn,
47136 - const u32 event_mask)
47137 -{
47138 -
47139 #define TPACPI_COMPARE_KEY(__scancode, __member) \
47140 do { \
47141 if ((event_mask & (1 << __scancode)) && \
47142 @@ -2345,36 +2340,42 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47143 tpacpi_hotkey_send_key(__scancode); \
47144 } while (0)
47145
47146 - void issue_volchange(const unsigned int oldvol,
47147 - const unsigned int newvol)
47148 - {
47149 - unsigned int i = oldvol;
47150 +static void issue_volchange(const unsigned int oldvol,
47151 + const unsigned int newvol,
47152 + const u32 event_mask)
47153 +{
47154 + unsigned int i = oldvol;
47155
47156 - while (i > newvol) {
47157 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47158 - i--;
47159 - }
47160 - while (i < newvol) {
47161 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47162 - i++;
47163 - }
47164 + while (i > newvol) {
47165 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEDOWN);
47166 + i--;
47167 }
47168 + while (i < newvol) {
47169 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47170 + i++;
47171 + }
47172 +}
47173
47174 - void issue_brightnesschange(const unsigned int oldbrt,
47175 - const unsigned int newbrt)
47176 - {
47177 - unsigned int i = oldbrt;
47178 +static void issue_brightnesschange(const unsigned int oldbrt,
47179 + const unsigned int newbrt,
47180 + const u32 event_mask)
47181 +{
47182 + unsigned int i = oldbrt;
47183
47184 - while (i > newbrt) {
47185 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47186 - i--;
47187 - }
47188 - while (i < newbrt) {
47189 - TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47190 - i++;
47191 - }
47192 + while (i > newbrt) {
47193 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNEND);
47194 + i--;
47195 + }
47196 + while (i < newbrt) {
47197 + TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47198 + i++;
47199 }
47200 +}
47201
47202 +static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47203 + struct tp_nvram_state *newn,
47204 + const u32 event_mask)
47205 +{
47206 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_THINKPAD, thinkpad_toggle);
47207 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNSPACE, zoom_toggle);
47208 TPACPI_COMPARE_KEY(TP_ACPI_HOTKEYSCAN_FNF7, display_toggle);
47209 @@ -2408,7 +2409,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47210 oldn->volume_level != newn->volume_level) {
47211 /* recently muted, or repeated mute keypress, or
47212 * multiple presses ending in mute */
47213 - issue_volchange(oldn->volume_level, newn->volume_level);
47214 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47215 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_MUTE);
47216 }
47217 } else {
47218 @@ -2418,7 +2419,7 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47219 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_VOLUMEUP);
47220 }
47221 if (oldn->volume_level != newn->volume_level) {
47222 - issue_volchange(oldn->volume_level, newn->volume_level);
47223 + issue_volchange(oldn->volume_level, newn->volume_level, event_mask);
47224 } else if (oldn->volume_toggle != newn->volume_toggle) {
47225 /* repeated vol up/down keypress at end of scale ? */
47226 if (newn->volume_level == 0)
47227 @@ -2431,7 +2432,8 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47228 /* handle brightness */
47229 if (oldn->brightness_level != newn->brightness_level) {
47230 issue_brightnesschange(oldn->brightness_level,
47231 - newn->brightness_level);
47232 + newn->brightness_level,
47233 + event_mask);
47234 } else if (oldn->brightness_toggle != newn->brightness_toggle) {
47235 /* repeated key presses that didn't change state */
47236 if (newn->brightness_level == 0)
47237 @@ -2440,10 +2442,10 @@ static void hotkey_compare_and_issue_event(struct tp_nvram_state *oldn,
47238 && !tp_features.bright_unkfw)
47239 TPACPI_MAY_SEND_KEY(TP_ACPI_HOTKEYSCAN_FNHOME);
47240 }
47241 +}
47242
47243 #undef TPACPI_COMPARE_KEY
47244 #undef TPACPI_MAY_SEND_KEY
47245 -}
47246
47247 /*
47248 * Polling driver
47249 diff --git a/drivers/pnp/pnpbios/bioscalls.c b/drivers/pnp/pnpbios/bioscalls.c
47250 index 769d265..a3a05ca 100644
47251 --- a/drivers/pnp/pnpbios/bioscalls.c
47252 +++ b/drivers/pnp/pnpbios/bioscalls.c
47253 @@ -58,7 +58,7 @@ do { \
47254 set_desc_limit(&gdt[(selname) >> 3], (size) - 1); \
47255 } while(0)
47256
47257 -static struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4092,
47258 +static const struct desc_struct bad_bios_desc = GDT_ENTRY_INIT(0x4093,
47259 (unsigned long)__va(0x400UL), PAGE_SIZE - 0x400 - 1);
47260
47261 /*
47262 @@ -95,7 +95,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47263
47264 cpu = get_cpu();
47265 save_desc_40 = get_cpu_gdt_table(cpu)[0x40 / 8];
47266 +
47267 + pax_open_kernel();
47268 get_cpu_gdt_table(cpu)[0x40 / 8] = bad_bios_desc;
47269 + pax_close_kernel();
47270
47271 /* On some boxes IRQ's during PnP BIOS calls are deadly. */
47272 spin_lock_irqsave(&pnp_bios_lock, flags);
47273 @@ -133,7 +136,10 @@ static inline u16 call_pnp_bios(u16 func, u16 arg1, u16 arg2, u16 arg3,
47274 :"memory");
47275 spin_unlock_irqrestore(&pnp_bios_lock, flags);
47276
47277 + pax_open_kernel();
47278 get_cpu_gdt_table(cpu)[0x40 / 8] = save_desc_40;
47279 + pax_close_kernel();
47280 +
47281 put_cpu();
47282
47283 /* If we get here and this is set then the PnP BIOS faulted on us. */
47284 @@ -467,7 +473,7 @@ int pnp_bios_read_escd(char *data, u32 nvram_base)
47285 return status;
47286 }
47287
47288 -void pnpbios_calls_init(union pnp_bios_install_struct *header)
47289 +void __init pnpbios_calls_init(union pnp_bios_install_struct *header)
47290 {
47291 int i;
47292
47293 @@ -475,6 +481,8 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47294 pnp_bios_callpoint.offset = header->fields.pm16offset;
47295 pnp_bios_callpoint.segment = PNP_CS16;
47296
47297 + pax_open_kernel();
47298 +
47299 for_each_possible_cpu(i) {
47300 struct desc_struct *gdt = get_cpu_gdt_table(i);
47301 if (!gdt)
47302 @@ -486,4 +494,6 @@ void pnpbios_calls_init(union pnp_bios_install_struct *header)
47303 set_desc_base(&gdt[GDT_ENTRY_PNPBIOS_DS],
47304 (unsigned long)__va(header->fields.pm16dseg));
47305 }
47306 +
47307 + pax_close_kernel();
47308 }
47309 diff --git a/drivers/pnp/resource.c b/drivers/pnp/resource.c
47310 index d95e101..67f0c3f 100644
47311 --- a/drivers/pnp/resource.c
47312 +++ b/drivers/pnp/resource.c
47313 @@ -360,7 +360,7 @@ int pnp_check_irq(struct pnp_dev *dev, struct resource *res)
47314 return 1;
47315
47316 /* check if the resource is valid */
47317 - if (*irq < 0 || *irq > 15)
47318 + if (*irq > 15)
47319 return 0;
47320
47321 /* check if the resource is reserved */
47322 @@ -424,7 +424,7 @@ int pnp_check_dma(struct pnp_dev *dev, struct resource *res)
47323 return 1;
47324
47325 /* check if the resource is valid */
47326 - if (*dma < 0 || *dma == 4 || *dma > 7)
47327 + if (*dma == 4 || *dma > 7)
47328 return 0;
47329
47330 /* check if the resource is reserved */
47331 diff --git a/drivers/power/pda_power.c b/drivers/power/pda_power.c
47332 index 0c52e2a..3421ab7 100644
47333 --- a/drivers/power/pda_power.c
47334 +++ b/drivers/power/pda_power.c
47335 @@ -37,7 +37,11 @@ static int polling;
47336
47337 #if IS_ENABLED(CONFIG_USB_PHY)
47338 static struct usb_phy *transceiver;
47339 -static struct notifier_block otg_nb;
47340 +static int otg_handle_notification(struct notifier_block *nb,
47341 + unsigned long event, void *unused);
47342 +static struct notifier_block otg_nb = {
47343 + .notifier_call = otg_handle_notification
47344 +};
47345 #endif
47346
47347 static struct regulator *ac_draw;
47348 @@ -369,7 +373,6 @@ static int pda_power_probe(struct platform_device *pdev)
47349
47350 #if IS_ENABLED(CONFIG_USB_PHY)
47351 if (!IS_ERR_OR_NULL(transceiver) && pdata->use_otg_notifier) {
47352 - otg_nb.notifier_call = otg_handle_notification;
47353 ret = usb_register_notifier(transceiver, &otg_nb);
47354 if (ret) {
47355 dev_err(dev, "failure to register otg notifier\n");
47356 diff --git a/drivers/power/power_supply.h b/drivers/power/power_supply.h
47357 index cc439fd..8fa30df 100644
47358 --- a/drivers/power/power_supply.h
47359 +++ b/drivers/power/power_supply.h
47360 @@ -16,12 +16,12 @@ struct power_supply;
47361
47362 #ifdef CONFIG_SYSFS
47363
47364 -extern void power_supply_init_attrs(struct device_type *dev_type);
47365 +extern void power_supply_init_attrs(void);
47366 extern int power_supply_uevent(struct device *dev, struct kobj_uevent_env *env);
47367
47368 #else
47369
47370 -static inline void power_supply_init_attrs(struct device_type *dev_type) {}
47371 +static inline void power_supply_init_attrs(void) {}
47372 #define power_supply_uevent NULL
47373
47374 #endif /* CONFIG_SYSFS */
47375 diff --git a/drivers/power/power_supply_core.c b/drivers/power/power_supply_core.c
47376 index 557af94..84dc1fe 100644
47377 --- a/drivers/power/power_supply_core.c
47378 +++ b/drivers/power/power_supply_core.c
47379 @@ -24,7 +24,10 @@
47380 struct class *power_supply_class;
47381 EXPORT_SYMBOL_GPL(power_supply_class);
47382
47383 -static struct device_type power_supply_dev_type;
47384 +extern const struct attribute_group *power_supply_attr_groups[];
47385 +static struct device_type power_supply_dev_type = {
47386 + .groups = power_supply_attr_groups,
47387 +};
47388
47389 static bool __power_supply_is_supplied_by(struct power_supply *supplier,
47390 struct power_supply *supply)
47391 @@ -584,7 +587,7 @@ static int __init power_supply_class_init(void)
47392 return PTR_ERR(power_supply_class);
47393
47394 power_supply_class->dev_uevent = power_supply_uevent;
47395 - power_supply_init_attrs(&power_supply_dev_type);
47396 + power_supply_init_attrs();
47397
47398 return 0;
47399 }
47400 diff --git a/drivers/power/power_supply_sysfs.c b/drivers/power/power_supply_sysfs.c
47401 index 44420d1..967126e 100644
47402 --- a/drivers/power/power_supply_sysfs.c
47403 +++ b/drivers/power/power_supply_sysfs.c
47404 @@ -230,17 +230,15 @@ static struct attribute_group power_supply_attr_group = {
47405 .is_visible = power_supply_attr_is_visible,
47406 };
47407
47408 -static const struct attribute_group *power_supply_attr_groups[] = {
47409 +const struct attribute_group *power_supply_attr_groups[] = {
47410 &power_supply_attr_group,
47411 NULL,
47412 };
47413
47414 -void power_supply_init_attrs(struct device_type *dev_type)
47415 +void power_supply_init_attrs(void)
47416 {
47417 int i;
47418
47419 - dev_type->groups = power_supply_attr_groups;
47420 -
47421 for (i = 0; i < ARRAY_SIZE(power_supply_attrs); i++)
47422 __power_supply_attrs[i] = &power_supply_attrs[i].attr;
47423 }
47424 diff --git a/drivers/powercap/powercap_sys.c b/drivers/powercap/powercap_sys.c
47425 index 84419af..268ede8 100644
47426 --- a/drivers/powercap/powercap_sys.c
47427 +++ b/drivers/powercap/powercap_sys.c
47428 @@ -154,8 +154,77 @@ struct powercap_constraint_attr {
47429 struct device_attribute name_attr;
47430 };
47431
47432 +static ssize_t show_constraint_name(struct device *dev,
47433 + struct device_attribute *dev_attr,
47434 + char *buf);
47435 +
47436 static struct powercap_constraint_attr
47437 - constraint_attrs[MAX_CONSTRAINTS_PER_ZONE];
47438 + constraint_attrs[MAX_CONSTRAINTS_PER_ZONE] = {
47439 + [0 ... MAX_CONSTRAINTS_PER_ZONE - 1] = {
47440 + .power_limit_attr = {
47441 + .attr = {
47442 + .name = NULL,
47443 + .mode = S_IWUSR | S_IRUGO
47444 + },
47445 + .show = show_constraint_power_limit_uw,
47446 + .store = store_constraint_power_limit_uw
47447 + },
47448 +
47449 + .time_window_attr = {
47450 + .attr = {
47451 + .name = NULL,
47452 + .mode = S_IWUSR | S_IRUGO
47453 + },
47454 + .show = show_constraint_time_window_us,
47455 + .store = store_constraint_time_window_us
47456 + },
47457 +
47458 + .max_power_attr = {
47459 + .attr = {
47460 + .name = NULL,
47461 + .mode = S_IRUGO
47462 + },
47463 + .show = show_constraint_max_power_uw,
47464 + .store = NULL
47465 + },
47466 +
47467 + .min_power_attr = {
47468 + .attr = {
47469 + .name = NULL,
47470 + .mode = S_IRUGO
47471 + },
47472 + .show = show_constraint_min_power_uw,
47473 + .store = NULL
47474 + },
47475 +
47476 + .max_time_window_attr = {
47477 + .attr = {
47478 + .name = NULL,
47479 + .mode = S_IRUGO
47480 + },
47481 + .show = show_constraint_max_time_window_us,
47482 + .store = NULL
47483 + },
47484 +
47485 + .min_time_window_attr = {
47486 + .attr = {
47487 + .name = NULL,
47488 + .mode = S_IRUGO
47489 + },
47490 + .show = show_constraint_min_time_window_us,
47491 + .store = NULL
47492 + },
47493 +
47494 + .name_attr = {
47495 + .attr = {
47496 + .name = NULL,
47497 + .mode = S_IRUGO
47498 + },
47499 + .show = show_constraint_name,
47500 + .store = NULL
47501 + }
47502 + }
47503 +};
47504
47505 /* A list of powercap control_types */
47506 static LIST_HEAD(powercap_cntrl_list);
47507 @@ -193,23 +262,16 @@ static ssize_t show_constraint_name(struct device *dev,
47508 }
47509
47510 static int create_constraint_attribute(int id, const char *name,
47511 - int mode,
47512 - struct device_attribute *dev_attr,
47513 - ssize_t (*show)(struct device *,
47514 - struct device_attribute *, char *),
47515 - ssize_t (*store)(struct device *,
47516 - struct device_attribute *,
47517 - const char *, size_t)
47518 - )
47519 + struct device_attribute *dev_attr)
47520 {
47521 + name = kasprintf(GFP_KERNEL, "constraint_%d_%s", id, name);
47522
47523 - dev_attr->attr.name = kasprintf(GFP_KERNEL, "constraint_%d_%s",
47524 - id, name);
47525 - if (!dev_attr->attr.name)
47526 + if (!name)
47527 return -ENOMEM;
47528 - dev_attr->attr.mode = mode;
47529 - dev_attr->show = show;
47530 - dev_attr->store = store;
47531 +
47532 + pax_open_kernel();
47533 + *(const char **)&dev_attr->attr.name = name;
47534 + pax_close_kernel();
47535
47536 return 0;
47537 }
47538 @@ -236,49 +298,31 @@ static int seed_constraint_attributes(void)
47539
47540 for (i = 0; i < MAX_CONSTRAINTS_PER_ZONE; ++i) {
47541 ret = create_constraint_attribute(i, "power_limit_uw",
47542 - S_IWUSR | S_IRUGO,
47543 - &constraint_attrs[i].power_limit_attr,
47544 - show_constraint_power_limit_uw,
47545 - store_constraint_power_limit_uw);
47546 + &constraint_attrs[i].power_limit_attr);
47547 if (ret)
47548 goto err_alloc;
47549 ret = create_constraint_attribute(i, "time_window_us",
47550 - S_IWUSR | S_IRUGO,
47551 - &constraint_attrs[i].time_window_attr,
47552 - show_constraint_time_window_us,
47553 - store_constraint_time_window_us);
47554 + &constraint_attrs[i].time_window_attr);
47555 if (ret)
47556 goto err_alloc;
47557 - ret = create_constraint_attribute(i, "name", S_IRUGO,
47558 - &constraint_attrs[i].name_attr,
47559 - show_constraint_name,
47560 - NULL);
47561 + ret = create_constraint_attribute(i, "name",
47562 + &constraint_attrs[i].name_attr);
47563 if (ret)
47564 goto err_alloc;
47565 - ret = create_constraint_attribute(i, "max_power_uw", S_IRUGO,
47566 - &constraint_attrs[i].max_power_attr,
47567 - show_constraint_max_power_uw,
47568 - NULL);
47569 + ret = create_constraint_attribute(i, "max_power_uw",
47570 + &constraint_attrs[i].max_power_attr);
47571 if (ret)
47572 goto err_alloc;
47573 - ret = create_constraint_attribute(i, "min_power_uw", S_IRUGO,
47574 - &constraint_attrs[i].min_power_attr,
47575 - show_constraint_min_power_uw,
47576 - NULL);
47577 + ret = create_constraint_attribute(i, "min_power_uw",
47578 + &constraint_attrs[i].min_power_attr);
47579 if (ret)
47580 goto err_alloc;
47581 ret = create_constraint_attribute(i, "max_time_window_us",
47582 - S_IRUGO,
47583 - &constraint_attrs[i].max_time_window_attr,
47584 - show_constraint_max_time_window_us,
47585 - NULL);
47586 + &constraint_attrs[i].max_time_window_attr);
47587 if (ret)
47588 goto err_alloc;
47589 ret = create_constraint_attribute(i, "min_time_window_us",
47590 - S_IRUGO,
47591 - &constraint_attrs[i].min_time_window_attr,
47592 - show_constraint_min_time_window_us,
47593 - NULL);
47594 + &constraint_attrs[i].min_time_window_attr);
47595 if (ret)
47596 goto err_alloc;
47597
47598 @@ -378,10 +422,12 @@ static void create_power_zone_common_attributes(
47599 power_zone->zone_dev_attrs[count++] =
47600 &dev_attr_max_energy_range_uj.attr;
47601 if (power_zone->ops->get_energy_uj) {
47602 + pax_open_kernel();
47603 if (power_zone->ops->reset_energy_uj)
47604 - dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
47605 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IWUSR | S_IRUGO;
47606 else
47607 - dev_attr_energy_uj.attr.mode = S_IRUGO;
47608 + *(umode_t *)&dev_attr_energy_uj.attr.mode = S_IRUGO;
47609 + pax_close_kernel();
47610 power_zone->zone_dev_attrs[count++] =
47611 &dev_attr_energy_uj.attr;
47612 }
47613 diff --git a/drivers/regulator/core.c b/drivers/regulator/core.c
47614 index d85f313..ae857d0 100644
47615 --- a/drivers/regulator/core.c
47616 +++ b/drivers/regulator/core.c
47617 @@ -3362,7 +3362,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
47618 {
47619 const struct regulation_constraints *constraints = NULL;
47620 const struct regulator_init_data *init_data;
47621 - static atomic_t regulator_no = ATOMIC_INIT(0);
47622 + static atomic_unchecked_t regulator_no = ATOMIC_INIT(0);
47623 struct regulator_dev *rdev;
47624 struct device *dev;
47625 int ret, i;
47626 @@ -3432,7 +3432,7 @@ regulator_register(const struct regulator_desc *regulator_desc,
47627 rdev->dev.of_node = config->of_node;
47628 rdev->dev.parent = dev;
47629 dev_set_name(&rdev->dev, "regulator.%d",
47630 - atomic_inc_return(&regulator_no) - 1);
47631 + atomic_inc_return_unchecked(&regulator_no) - 1);
47632 ret = device_register(&rdev->dev);
47633 if (ret != 0) {
47634 put_device(&rdev->dev);
47635 diff --git a/drivers/regulator/max8660.c b/drivers/regulator/max8660.c
47636 index 8d94d3d..653b623 100644
47637 --- a/drivers/regulator/max8660.c
47638 +++ b/drivers/regulator/max8660.c
47639 @@ -420,8 +420,10 @@ static int max8660_probe(struct i2c_client *client,
47640 max8660->shadow_regs[MAX8660_OVER1] = 5;
47641 } else {
47642 /* Otherwise devices can be toggled via software */
47643 - max8660_dcdc_ops.enable = max8660_dcdc_enable;
47644 - max8660_dcdc_ops.disable = max8660_dcdc_disable;
47645 + pax_open_kernel();
47646 + *(void **)&max8660_dcdc_ops.enable = max8660_dcdc_enable;
47647 + *(void **)&max8660_dcdc_ops.disable = max8660_dcdc_disable;
47648 + pax_close_kernel();
47649 }
47650
47651 /*
47652 diff --git a/drivers/regulator/max8973-regulator.c b/drivers/regulator/max8973-regulator.c
47653 index 892aa1e..ebd1b9c 100644
47654 --- a/drivers/regulator/max8973-regulator.c
47655 +++ b/drivers/regulator/max8973-regulator.c
47656 @@ -406,9 +406,11 @@ static int max8973_probe(struct i2c_client *client,
47657 if (!pdata || !pdata->enable_ext_control) {
47658 max->desc.enable_reg = MAX8973_VOUT;
47659 max->desc.enable_mask = MAX8973_VOUT_ENABLE;
47660 - max->ops.enable = regulator_enable_regmap;
47661 - max->ops.disable = regulator_disable_regmap;
47662 - max->ops.is_enabled = regulator_is_enabled_regmap;
47663 + pax_open_kernel();
47664 + *(void **)&max->ops.enable = regulator_enable_regmap;
47665 + *(void **)&max->ops.disable = regulator_disable_regmap;
47666 + *(void **)&max->ops.is_enabled = regulator_is_enabled_regmap;
47667 + pax_close_kernel();
47668 }
47669
47670 if (pdata) {
47671 diff --git a/drivers/regulator/mc13892-regulator.c b/drivers/regulator/mc13892-regulator.c
47672 index 96c9f80..90974ca 100644
47673 --- a/drivers/regulator/mc13892-regulator.c
47674 +++ b/drivers/regulator/mc13892-regulator.c
47675 @@ -582,10 +582,12 @@ static int mc13892_regulator_probe(struct platform_device *pdev)
47676 }
47677 mc13xxx_unlock(mc13892);
47678
47679 - mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
47680 + pax_open_kernel();
47681 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->set_mode
47682 = mc13892_vcam_set_mode;
47683 - mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
47684 + *(void **)&mc13892_regulators[MC13892_VCAM].desc.ops->get_mode
47685 = mc13892_vcam_get_mode;
47686 + pax_close_kernel();
47687
47688 mc13xxx_data = mc13xxx_parse_regulators_dt(pdev, mc13892_regulators,
47689 ARRAY_SIZE(mc13892_regulators));
47690 diff --git a/drivers/rtc/rtc-cmos.c b/drivers/rtc/rtc-cmos.c
47691 index a2325bc..04c549f 100644
47692 --- a/drivers/rtc/rtc-cmos.c
47693 +++ b/drivers/rtc/rtc-cmos.c
47694 @@ -779,7 +779,9 @@ cmos_do_probe(struct device *dev, struct resource *ports, int rtc_irq)
47695 hpet_rtc_timer_init();
47696
47697 /* export at least the first block of NVRAM */
47698 - nvram.size = address_space - NVRAM_OFFSET;
47699 + pax_open_kernel();
47700 + *(size_t *)&nvram.size = address_space - NVRAM_OFFSET;
47701 + pax_close_kernel();
47702 retval = sysfs_create_bin_file(&dev->kobj, &nvram);
47703 if (retval < 0) {
47704 dev_dbg(dev, "can't create nvram file? %d\n", retval);
47705 diff --git a/drivers/rtc/rtc-dev.c b/drivers/rtc/rtc-dev.c
47706 index d049393..bb20be0 100644
47707 --- a/drivers/rtc/rtc-dev.c
47708 +++ b/drivers/rtc/rtc-dev.c
47709 @@ -16,6 +16,7 @@
47710 #include <linux/module.h>
47711 #include <linux/rtc.h>
47712 #include <linux/sched.h>
47713 +#include <linux/grsecurity.h>
47714 #include "rtc-core.h"
47715
47716 static dev_t rtc_devt;
47717 @@ -347,6 +348,8 @@ static long rtc_dev_ioctl(struct file *file,
47718 if (copy_from_user(&tm, uarg, sizeof(tm)))
47719 return -EFAULT;
47720
47721 + gr_log_timechange();
47722 +
47723 return rtc_set_time(rtc, &tm);
47724
47725 case RTC_PIE_ON:
47726 diff --git a/drivers/rtc/rtc-ds1307.c b/drivers/rtc/rtc-ds1307.c
47727 index 4e75345..09f8663 100644
47728 --- a/drivers/rtc/rtc-ds1307.c
47729 +++ b/drivers/rtc/rtc-ds1307.c
47730 @@ -107,7 +107,7 @@ struct ds1307 {
47731 u8 offset; /* register's offset */
47732 u8 regs[11];
47733 u16 nvram_offset;
47734 - struct bin_attribute *nvram;
47735 + bin_attribute_no_const *nvram;
47736 enum ds_type type;
47737 unsigned long flags;
47738 #define HAS_NVRAM 0 /* bit 0 == sysfs file active */
47739 diff --git a/drivers/rtc/rtc-m48t59.c b/drivers/rtc/rtc-m48t59.c
47740 index 11880c1..b823aa4 100644
47741 --- a/drivers/rtc/rtc-m48t59.c
47742 +++ b/drivers/rtc/rtc-m48t59.c
47743 @@ -483,7 +483,9 @@ static int m48t59_rtc_probe(struct platform_device *pdev)
47744 if (IS_ERR(m48t59->rtc))
47745 return PTR_ERR(m48t59->rtc);
47746
47747 - m48t59_nvram_attr.size = pdata->offset;
47748 + pax_open_kernel();
47749 + *(size_t *)&m48t59_nvram_attr.size = pdata->offset;
47750 + pax_close_kernel();
47751
47752 ret = sysfs_create_bin_file(&pdev->dev.kobj, &m48t59_nvram_attr);
47753 if (ret)
47754 diff --git a/drivers/scsi/aic7xxx/aic79xx_pci.c b/drivers/scsi/aic7xxx/aic79xx_pci.c
47755 index 14b5f8d..cc9bd26 100644
47756 --- a/drivers/scsi/aic7xxx/aic79xx_pci.c
47757 +++ b/drivers/scsi/aic7xxx/aic79xx_pci.c
47758 @@ -827,7 +827,7 @@ ahd_pci_intr(struct ahd_softc *ahd)
47759 for (bit = 0; bit < 8; bit++) {
47760
47761 if ((pci_status[i] & (0x1 << bit)) != 0) {
47762 - static const char *s;
47763 + const char *s;
47764
47765 s = pci_status_strings[bit];
47766 if (i == 7/*TARG*/ && bit == 3)
47767 @@ -887,23 +887,15 @@ ahd_pci_split_intr(struct ahd_softc *ahd, u_int intstat)
47768
47769 for (bit = 0; bit < 8; bit++) {
47770
47771 - if ((split_status[i] & (0x1 << bit)) != 0) {
47772 - static const char *s;
47773 -
47774 - s = split_status_strings[bit];
47775 - printk(s, ahd_name(ahd),
47776 + if ((split_status[i] & (0x1 << bit)) != 0)
47777 + printk(split_status_strings[bit], ahd_name(ahd),
47778 split_status_source[i]);
47779 - }
47780
47781 if (i > 1)
47782 continue;
47783
47784 - if ((sg_split_status[i] & (0x1 << bit)) != 0) {
47785 - static const char *s;
47786 -
47787 - s = split_status_strings[bit];
47788 - printk(s, ahd_name(ahd), "SG");
47789 - }
47790 + if ((sg_split_status[i] & (0x1 << bit)) != 0)
47791 + printk(split_status_strings[bit], ahd_name(ahd), "SG");
47792 }
47793 }
47794 /*
47795 diff --git a/drivers/scsi/bfa/bfa_fcpim.h b/drivers/scsi/bfa/bfa_fcpim.h
47796 index e693af6..2e525b6 100644
47797 --- a/drivers/scsi/bfa/bfa_fcpim.h
47798 +++ b/drivers/scsi/bfa/bfa_fcpim.h
47799 @@ -36,7 +36,7 @@ struct bfa_iotag_s {
47800
47801 struct bfa_itn_s {
47802 bfa_isr_func_t isr;
47803 -};
47804 +} __no_const;
47805
47806 void bfa_itn_create(struct bfa_s *bfa, struct bfa_rport_s *rport,
47807 void (*isr)(struct bfa_s *bfa, struct bfi_msg_s *m));
47808 diff --git a/drivers/scsi/bfa/bfa_fcs.c b/drivers/scsi/bfa/bfa_fcs.c
47809 index a3ab5cc..8143622 100644
47810 --- a/drivers/scsi/bfa/bfa_fcs.c
47811 +++ b/drivers/scsi/bfa/bfa_fcs.c
47812 @@ -38,10 +38,21 @@ struct bfa_fcs_mod_s {
47813 #define BFA_FCS_MODULE(_mod) { _mod ## _modinit, _mod ## _modexit }
47814
47815 static struct bfa_fcs_mod_s fcs_modules[] = {
47816 - { bfa_fcs_port_attach, NULL, NULL },
47817 - { bfa_fcs_uf_attach, NULL, NULL },
47818 - { bfa_fcs_fabric_attach, bfa_fcs_fabric_modinit,
47819 - bfa_fcs_fabric_modexit },
47820 + {
47821 + .attach = bfa_fcs_port_attach,
47822 + .modinit = NULL,
47823 + .modexit = NULL
47824 + },
47825 + {
47826 + .attach = bfa_fcs_uf_attach,
47827 + .modinit = NULL,
47828 + .modexit = NULL
47829 + },
47830 + {
47831 + .attach = bfa_fcs_fabric_attach,
47832 + .modinit = bfa_fcs_fabric_modinit,
47833 + .modexit = bfa_fcs_fabric_modexit
47834 + },
47835 };
47836
47837 /*
47838 diff --git a/drivers/scsi/bfa/bfa_fcs_lport.c b/drivers/scsi/bfa/bfa_fcs_lport.c
47839 index f5e4e61..a0acaf6 100644
47840 --- a/drivers/scsi/bfa/bfa_fcs_lport.c
47841 +++ b/drivers/scsi/bfa/bfa_fcs_lport.c
47842 @@ -89,15 +89,26 @@ static struct {
47843 void (*offline) (struct bfa_fcs_lport_s *port);
47844 } __port_action[] = {
47845 {
47846 - bfa_fcs_lport_unknown_init, bfa_fcs_lport_unknown_online,
47847 - bfa_fcs_lport_unknown_offline}, {
47848 - bfa_fcs_lport_fab_init, bfa_fcs_lport_fab_online,
47849 - bfa_fcs_lport_fab_offline}, {
47850 - bfa_fcs_lport_n2n_init, bfa_fcs_lport_n2n_online,
47851 - bfa_fcs_lport_n2n_offline}, {
47852 - bfa_fcs_lport_loop_init, bfa_fcs_lport_loop_online,
47853 - bfa_fcs_lport_loop_offline},
47854 - };
47855 + .init = bfa_fcs_lport_unknown_init,
47856 + .online = bfa_fcs_lport_unknown_online,
47857 + .offline = bfa_fcs_lport_unknown_offline
47858 + },
47859 + {
47860 + .init = bfa_fcs_lport_fab_init,
47861 + .online = bfa_fcs_lport_fab_online,
47862 + .offline = bfa_fcs_lport_fab_offline
47863 + },
47864 + {
47865 + .init = bfa_fcs_lport_n2n_init,
47866 + .online = bfa_fcs_lport_n2n_online,
47867 + .offline = bfa_fcs_lport_n2n_offline
47868 + },
47869 + {
47870 + .init = bfa_fcs_lport_loop_init,
47871 + .online = bfa_fcs_lport_loop_online,
47872 + .offline = bfa_fcs_lport_loop_offline
47873 + },
47874 +};
47875
47876 /*
47877 * fcs_port_sm FCS logical port state machine
47878 diff --git a/drivers/scsi/bfa/bfa_ioc.h b/drivers/scsi/bfa/bfa_ioc.h
47879 index 90814fe..4384138 100644
47880 --- a/drivers/scsi/bfa/bfa_ioc.h
47881 +++ b/drivers/scsi/bfa/bfa_ioc.h
47882 @@ -258,7 +258,7 @@ struct bfa_ioc_cbfn_s {
47883 bfa_ioc_disable_cbfn_t disable_cbfn;
47884 bfa_ioc_hbfail_cbfn_t hbfail_cbfn;
47885 bfa_ioc_reset_cbfn_t reset_cbfn;
47886 -};
47887 +} __no_const;
47888
47889 /*
47890 * IOC event notification mechanism.
47891 @@ -352,7 +352,7 @@ struct bfa_ioc_hwif_s {
47892 void (*ioc_set_alt_fwstate) (struct bfa_ioc_s *ioc,
47893 enum bfi_ioc_state fwstate);
47894 enum bfi_ioc_state (*ioc_get_alt_fwstate) (struct bfa_ioc_s *ioc);
47895 -};
47896 +} __no_const;
47897
47898 /*
47899 * Queue element to wait for room in request queue. FIFO order is
47900 diff --git a/drivers/scsi/bfa/bfa_modules.h b/drivers/scsi/bfa/bfa_modules.h
47901 index a14c784..6de6790 100644
47902 --- a/drivers/scsi/bfa/bfa_modules.h
47903 +++ b/drivers/scsi/bfa/bfa_modules.h
47904 @@ -78,12 +78,12 @@ enum {
47905 \
47906 extern struct bfa_module_s hal_mod_ ## __mod; \
47907 struct bfa_module_s hal_mod_ ## __mod = { \
47908 - bfa_ ## __mod ## _meminfo, \
47909 - bfa_ ## __mod ## _attach, \
47910 - bfa_ ## __mod ## _detach, \
47911 - bfa_ ## __mod ## _start, \
47912 - bfa_ ## __mod ## _stop, \
47913 - bfa_ ## __mod ## _iocdisable, \
47914 + .meminfo = bfa_ ## __mod ## _meminfo, \
47915 + .attach = bfa_ ## __mod ## _attach, \
47916 + .detach = bfa_ ## __mod ## _detach, \
47917 + .start = bfa_ ## __mod ## _start, \
47918 + .stop = bfa_ ## __mod ## _stop, \
47919 + .iocdisable = bfa_ ## __mod ## _iocdisable, \
47920 }
47921
47922 #define BFA_CACHELINE_SZ (256)
47923 diff --git a/drivers/scsi/fcoe/fcoe_sysfs.c b/drivers/scsi/fcoe/fcoe_sysfs.c
47924 index 045c4e1..13de803 100644
47925 --- a/drivers/scsi/fcoe/fcoe_sysfs.c
47926 +++ b/drivers/scsi/fcoe/fcoe_sysfs.c
47927 @@ -33,8 +33,8 @@
47928 */
47929 #include "libfcoe.h"
47930
47931 -static atomic_t ctlr_num;
47932 -static atomic_t fcf_num;
47933 +static atomic_unchecked_t ctlr_num;
47934 +static atomic_unchecked_t fcf_num;
47935
47936 /*
47937 * fcoe_fcf_dev_loss_tmo: the default number of seconds that fcoe sysfs
47938 @@ -685,7 +685,7 @@ struct fcoe_ctlr_device *fcoe_ctlr_device_add(struct device *parent,
47939 if (!ctlr)
47940 goto out;
47941
47942 - ctlr->id = atomic_inc_return(&ctlr_num) - 1;
47943 + ctlr->id = atomic_inc_return_unchecked(&ctlr_num) - 1;
47944 ctlr->f = f;
47945 ctlr->mode = FIP_CONN_TYPE_FABRIC;
47946 INIT_LIST_HEAD(&ctlr->fcfs);
47947 @@ -902,7 +902,7 @@ struct fcoe_fcf_device *fcoe_fcf_device_add(struct fcoe_ctlr_device *ctlr,
47948 fcf->dev.parent = &ctlr->dev;
47949 fcf->dev.bus = &fcoe_bus_type;
47950 fcf->dev.type = &fcoe_fcf_device_type;
47951 - fcf->id = atomic_inc_return(&fcf_num) - 1;
47952 + fcf->id = atomic_inc_return_unchecked(&fcf_num) - 1;
47953 fcf->state = FCOE_FCF_STATE_UNKNOWN;
47954
47955 fcf->dev_loss_tmo = ctlr->fcf_dev_loss_tmo;
47956 @@ -938,8 +938,8 @@ int __init fcoe_sysfs_setup(void)
47957 {
47958 int error;
47959
47960 - atomic_set(&ctlr_num, 0);
47961 - atomic_set(&fcf_num, 0);
47962 + atomic_set_unchecked(&ctlr_num, 0);
47963 + atomic_set_unchecked(&fcf_num, 0);
47964
47965 error = bus_register(&fcoe_bus_type);
47966 if (error)
47967 diff --git a/drivers/scsi/hosts.c b/drivers/scsi/hosts.c
47968 index f2c5005..db36c02 100644
47969 --- a/drivers/scsi/hosts.c
47970 +++ b/drivers/scsi/hosts.c
47971 @@ -42,7 +42,7 @@
47972 #include "scsi_logging.h"
47973
47974
47975 -static atomic_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
47976 +static atomic_unchecked_t scsi_host_next_hn = ATOMIC_INIT(0); /* host_no for next new host */
47977
47978
47979 static void scsi_host_cls_release(struct device *dev)
47980 @@ -367,7 +367,7 @@ struct Scsi_Host *scsi_host_alloc(struct scsi_host_template *sht, int privsize)
47981 * subtract one because we increment first then return, but we need to
47982 * know what the next host number was before increment
47983 */
47984 - shost->host_no = atomic_inc_return(&scsi_host_next_hn) - 1;
47985 + shost->host_no = atomic_inc_return_unchecked(&scsi_host_next_hn) - 1;
47986 shost->dma_channel = 0xff;
47987
47988 /* These three are default values which can be overridden */
47989 diff --git a/drivers/scsi/hpsa.c b/drivers/scsi/hpsa.c
47990 index 20a5e6e..8b23cea 100644
47991 --- a/drivers/scsi/hpsa.c
47992 +++ b/drivers/scsi/hpsa.c
47993 @@ -578,7 +578,7 @@ static inline u32 next_command(struct ctlr_info *h, u8 q)
47994 unsigned long flags;
47995
47996 if (unlikely(!(h->transMethod & CFGTBL_Trans_Performant)))
47997 - return h->access.command_completed(h, q);
47998 + return h->access->command_completed(h, q);
47999
48000 if ((rq->head[rq->current_entry] & 1) == rq->wraparound) {
48001 a = rq->head[rq->current_entry];
48002 @@ -3444,7 +3444,7 @@ static void start_io(struct ctlr_info *h)
48003 while (!list_empty(&h->reqQ)) {
48004 c = list_entry(h->reqQ.next, struct CommandList, list);
48005 /* can't do anything if fifo is full */
48006 - if ((h->access.fifo_full(h))) {
48007 + if ((h->access->fifo_full(h))) {
48008 dev_warn(&h->pdev->dev, "fifo full\n");
48009 break;
48010 }
48011 @@ -3466,7 +3466,7 @@ static void start_io(struct ctlr_info *h)
48012
48013 /* Tell the controller execute command */
48014 spin_unlock_irqrestore(&h->lock, flags);
48015 - h->access.submit_command(h, c);
48016 + h->access->submit_command(h, c);
48017 spin_lock_irqsave(&h->lock, flags);
48018 }
48019 spin_unlock_irqrestore(&h->lock, flags);
48020 @@ -3474,17 +3474,17 @@ static void start_io(struct ctlr_info *h)
48021
48022 static inline unsigned long get_next_completion(struct ctlr_info *h, u8 q)
48023 {
48024 - return h->access.command_completed(h, q);
48025 + return h->access->command_completed(h, q);
48026 }
48027
48028 static inline bool interrupt_pending(struct ctlr_info *h)
48029 {
48030 - return h->access.intr_pending(h);
48031 + return h->access->intr_pending(h);
48032 }
48033
48034 static inline long interrupt_not_for_us(struct ctlr_info *h)
48035 {
48036 - return (h->access.intr_pending(h) == 0) ||
48037 + return (h->access->intr_pending(h) == 0) ||
48038 (h->interrupts_enabled == 0);
48039 }
48040
48041 @@ -4386,7 +4386,7 @@ static int hpsa_pci_init(struct ctlr_info *h)
48042 if (prod_index < 0)
48043 return -ENODEV;
48044 h->product_name = products[prod_index].product_name;
48045 - h->access = *(products[prod_index].access);
48046 + h->access = products[prod_index].access;
48047
48048 pci_disable_link_state(h->pdev, PCIE_LINK_STATE_L0S |
48049 PCIE_LINK_STATE_L1 | PCIE_LINK_STATE_CLKPM);
48050 @@ -4668,7 +4668,7 @@ static void controller_lockup_detected(struct ctlr_info *h)
48051
48052 assert_spin_locked(&lockup_detector_lock);
48053 remove_ctlr_from_lockup_detector_list(h);
48054 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48055 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48056 spin_lock_irqsave(&h->lock, flags);
48057 h->lockup_detected = readl(h->vaddr + SA5_SCRATCHPAD_OFFSET);
48058 spin_unlock_irqrestore(&h->lock, flags);
48059 @@ -4845,7 +4845,7 @@ reinit_after_soft_reset:
48060 }
48061
48062 /* make sure the board interrupts are off */
48063 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48064 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48065
48066 if (hpsa_request_irq(h, do_hpsa_intr_msi, do_hpsa_intr_intx))
48067 goto clean2;
48068 @@ -4879,7 +4879,7 @@ reinit_after_soft_reset:
48069 * fake ones to scoop up any residual completions.
48070 */
48071 spin_lock_irqsave(&h->lock, flags);
48072 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48073 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48074 spin_unlock_irqrestore(&h->lock, flags);
48075 free_irqs(h);
48076 rc = hpsa_request_irq(h, hpsa_msix_discard_completions,
48077 @@ -4898,9 +4898,9 @@ reinit_after_soft_reset:
48078 dev_info(&h->pdev->dev, "Board READY.\n");
48079 dev_info(&h->pdev->dev,
48080 "Waiting for stale completions to drain.\n");
48081 - h->access.set_intr_mask(h, HPSA_INTR_ON);
48082 + h->access->set_intr_mask(h, HPSA_INTR_ON);
48083 msleep(10000);
48084 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48085 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48086
48087 rc = controller_reset_failed(h->cfgtable);
48088 if (rc)
48089 @@ -4921,7 +4921,7 @@ reinit_after_soft_reset:
48090 }
48091
48092 /* Turn the interrupts on so we can service requests */
48093 - h->access.set_intr_mask(h, HPSA_INTR_ON);
48094 + h->access->set_intr_mask(h, HPSA_INTR_ON);
48095
48096 hpsa_hba_inquiry(h);
48097 hpsa_register_scsi(h); /* hook ourselves into SCSI subsystem */
48098 @@ -4976,7 +4976,7 @@ static void hpsa_shutdown(struct pci_dev *pdev)
48099 * To write all data in the battery backed cache to disks
48100 */
48101 hpsa_flush_cache(h);
48102 - h->access.set_intr_mask(h, HPSA_INTR_OFF);
48103 + h->access->set_intr_mask(h, HPSA_INTR_OFF);
48104 hpsa_free_irqs_and_disable_msix(h);
48105 }
48106
48107 @@ -5143,7 +5143,7 @@ static void hpsa_enter_performant_mode(struct ctlr_info *h, u32 use_short_tags)
48108 return;
48109 }
48110 /* Change the access methods to the performant access methods */
48111 - h->access = SA5_performant_access;
48112 + h->access = &SA5_performant_access;
48113 h->transMethod = CFGTBL_Trans_Performant;
48114 }
48115
48116 diff --git a/drivers/scsi/hpsa.h b/drivers/scsi/hpsa.h
48117 index bc85e72..d463049 100644
48118 --- a/drivers/scsi/hpsa.h
48119 +++ b/drivers/scsi/hpsa.h
48120 @@ -79,7 +79,7 @@ struct ctlr_info {
48121 unsigned int msix_vector;
48122 unsigned int msi_vector;
48123 int intr_mode; /* either PERF_MODE_INT or SIMPLE_MODE_INT */
48124 - struct access_method access;
48125 + struct access_method *access;
48126
48127 /* queue and queue Info */
48128 struct list_head reqQ;
48129 @@ -381,19 +381,19 @@ static bool SA5_performant_intr_pending(struct ctlr_info *h)
48130 }
48131
48132 static struct access_method SA5_access = {
48133 - SA5_submit_command,
48134 - SA5_intr_mask,
48135 - SA5_fifo_full,
48136 - SA5_intr_pending,
48137 - SA5_completed,
48138 + .submit_command = SA5_submit_command,
48139 + .set_intr_mask = SA5_intr_mask,
48140 + .fifo_full = SA5_fifo_full,
48141 + .intr_pending = SA5_intr_pending,
48142 + .command_completed = SA5_completed,
48143 };
48144
48145 static struct access_method SA5_performant_access = {
48146 - SA5_submit_command,
48147 - SA5_performant_intr_mask,
48148 - SA5_fifo_full,
48149 - SA5_performant_intr_pending,
48150 - SA5_performant_completed,
48151 + .submit_command = SA5_submit_command,
48152 + .set_intr_mask = SA5_performant_intr_mask,
48153 + .fifo_full = SA5_fifo_full,
48154 + .intr_pending = SA5_performant_intr_pending,
48155 + .command_completed = SA5_performant_completed,
48156 };
48157
48158 struct board_type {
48159 diff --git a/drivers/scsi/libfc/fc_exch.c b/drivers/scsi/libfc/fc_exch.c
48160 index 1b3a094..068e683 100644
48161 --- a/drivers/scsi/libfc/fc_exch.c
48162 +++ b/drivers/scsi/libfc/fc_exch.c
48163 @@ -101,12 +101,12 @@ struct fc_exch_mgr {
48164 u16 pool_max_index;
48165
48166 struct {
48167 - atomic_t no_free_exch;
48168 - atomic_t no_free_exch_xid;
48169 - atomic_t xid_not_found;
48170 - atomic_t xid_busy;
48171 - atomic_t seq_not_found;
48172 - atomic_t non_bls_resp;
48173 + atomic_unchecked_t no_free_exch;
48174 + atomic_unchecked_t no_free_exch_xid;
48175 + atomic_unchecked_t xid_not_found;
48176 + atomic_unchecked_t xid_busy;
48177 + atomic_unchecked_t seq_not_found;
48178 + atomic_unchecked_t non_bls_resp;
48179 } stats;
48180 };
48181
48182 @@ -811,7 +811,7 @@ static struct fc_exch *fc_exch_em_alloc(struct fc_lport *lport,
48183 /* allocate memory for exchange */
48184 ep = mempool_alloc(mp->ep_pool, GFP_ATOMIC);
48185 if (!ep) {
48186 - atomic_inc(&mp->stats.no_free_exch);
48187 + atomic_inc_unchecked(&mp->stats.no_free_exch);
48188 goto out;
48189 }
48190 memset(ep, 0, sizeof(*ep));
48191 @@ -874,7 +874,7 @@ out:
48192 return ep;
48193 err:
48194 spin_unlock_bh(&pool->lock);
48195 - atomic_inc(&mp->stats.no_free_exch_xid);
48196 + atomic_inc_unchecked(&mp->stats.no_free_exch_xid);
48197 mempool_free(ep, mp->ep_pool);
48198 return NULL;
48199 }
48200 @@ -1023,7 +1023,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48201 xid = ntohs(fh->fh_ox_id); /* we originated exch */
48202 ep = fc_exch_find(mp, xid);
48203 if (!ep) {
48204 - atomic_inc(&mp->stats.xid_not_found);
48205 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48206 reject = FC_RJT_OX_ID;
48207 goto out;
48208 }
48209 @@ -1053,7 +1053,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48210 ep = fc_exch_find(mp, xid);
48211 if ((f_ctl & FC_FC_FIRST_SEQ) && fc_sof_is_init(fr_sof(fp))) {
48212 if (ep) {
48213 - atomic_inc(&mp->stats.xid_busy);
48214 + atomic_inc_unchecked(&mp->stats.xid_busy);
48215 reject = FC_RJT_RX_ID;
48216 goto rel;
48217 }
48218 @@ -1064,7 +1064,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48219 }
48220 xid = ep->xid; /* get our XID */
48221 } else if (!ep) {
48222 - atomic_inc(&mp->stats.xid_not_found);
48223 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48224 reject = FC_RJT_RX_ID; /* XID not found */
48225 goto out;
48226 }
48227 @@ -1082,7 +1082,7 @@ static enum fc_pf_rjt_reason fc_seq_lookup_recip(struct fc_lport *lport,
48228 } else {
48229 sp = &ep->seq;
48230 if (sp->id != fh->fh_seq_id) {
48231 - atomic_inc(&mp->stats.seq_not_found);
48232 + atomic_inc_unchecked(&mp->stats.seq_not_found);
48233 if (f_ctl & FC_FC_END_SEQ) {
48234 /*
48235 * Update sequence_id based on incoming last
48236 @@ -1533,22 +1533,22 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48237
48238 ep = fc_exch_find(mp, ntohs(fh->fh_ox_id));
48239 if (!ep) {
48240 - atomic_inc(&mp->stats.xid_not_found);
48241 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48242 goto out;
48243 }
48244 if (ep->esb_stat & ESB_ST_COMPLETE) {
48245 - atomic_inc(&mp->stats.xid_not_found);
48246 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48247 goto rel;
48248 }
48249 if (ep->rxid == FC_XID_UNKNOWN)
48250 ep->rxid = ntohs(fh->fh_rx_id);
48251 if (ep->sid != 0 && ep->sid != ntoh24(fh->fh_d_id)) {
48252 - atomic_inc(&mp->stats.xid_not_found);
48253 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48254 goto rel;
48255 }
48256 if (ep->did != ntoh24(fh->fh_s_id) &&
48257 ep->did != FC_FID_FLOGI) {
48258 - atomic_inc(&mp->stats.xid_not_found);
48259 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48260 goto rel;
48261 }
48262 sof = fr_sof(fp);
48263 @@ -1557,7 +1557,7 @@ static void fc_exch_recv_seq_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48264 sp->ssb_stat |= SSB_ST_RESP;
48265 sp->id = fh->fh_seq_id;
48266 } else if (sp->id != fh->fh_seq_id) {
48267 - atomic_inc(&mp->stats.seq_not_found);
48268 + atomic_inc_unchecked(&mp->stats.seq_not_found);
48269 goto rel;
48270 }
48271
48272 @@ -1619,9 +1619,9 @@ static void fc_exch_recv_resp(struct fc_exch_mgr *mp, struct fc_frame *fp)
48273 sp = fc_seq_lookup_orig(mp, fp); /* doesn't hold sequence */
48274
48275 if (!sp)
48276 - atomic_inc(&mp->stats.xid_not_found);
48277 + atomic_inc_unchecked(&mp->stats.xid_not_found);
48278 else
48279 - atomic_inc(&mp->stats.non_bls_resp);
48280 + atomic_inc_unchecked(&mp->stats.non_bls_resp);
48281
48282 fc_frame_free(fp);
48283 }
48284 @@ -2261,13 +2261,13 @@ void fc_exch_update_stats(struct fc_lport *lport)
48285
48286 list_for_each_entry(ema, &lport->ema_list, ema_list) {
48287 mp = ema->mp;
48288 - st->fc_no_free_exch += atomic_read(&mp->stats.no_free_exch);
48289 + st->fc_no_free_exch += atomic_read_unchecked(&mp->stats.no_free_exch);
48290 st->fc_no_free_exch_xid +=
48291 - atomic_read(&mp->stats.no_free_exch_xid);
48292 - st->fc_xid_not_found += atomic_read(&mp->stats.xid_not_found);
48293 - st->fc_xid_busy += atomic_read(&mp->stats.xid_busy);
48294 - st->fc_seq_not_found += atomic_read(&mp->stats.seq_not_found);
48295 - st->fc_non_bls_resp += atomic_read(&mp->stats.non_bls_resp);
48296 + atomic_read_unchecked(&mp->stats.no_free_exch_xid);
48297 + st->fc_xid_not_found += atomic_read_unchecked(&mp->stats.xid_not_found);
48298 + st->fc_xid_busy += atomic_read_unchecked(&mp->stats.xid_busy);
48299 + st->fc_seq_not_found += atomic_read_unchecked(&mp->stats.seq_not_found);
48300 + st->fc_non_bls_resp += atomic_read_unchecked(&mp->stats.non_bls_resp);
48301 }
48302 }
48303 EXPORT_SYMBOL(fc_exch_update_stats);
48304 diff --git a/drivers/scsi/libsas/sas_ata.c b/drivers/scsi/libsas/sas_ata.c
48305 index d289583..b745eec 100644
48306 --- a/drivers/scsi/libsas/sas_ata.c
48307 +++ b/drivers/scsi/libsas/sas_ata.c
48308 @@ -554,7 +554,7 @@ static struct ata_port_operations sas_sata_ops = {
48309 .postreset = ata_std_postreset,
48310 .error_handler = ata_std_error_handler,
48311 .post_internal_cmd = sas_ata_post_internal,
48312 - .qc_defer = ata_std_qc_defer,
48313 + .qc_defer = ata_std_qc_defer,
48314 .qc_prep = ata_noop_qc_prep,
48315 .qc_issue = sas_ata_qc_issue,
48316 .qc_fill_rtf = sas_ata_qc_fill_rtf,
48317 diff --git a/drivers/scsi/lpfc/lpfc.h b/drivers/scsi/lpfc/lpfc.h
48318 index 4e1b75c..0bbdfa9 100644
48319 --- a/drivers/scsi/lpfc/lpfc.h
48320 +++ b/drivers/scsi/lpfc/lpfc.h
48321 @@ -432,7 +432,7 @@ struct lpfc_vport {
48322 struct dentry *debug_nodelist;
48323 struct dentry *vport_debugfs_root;
48324 struct lpfc_debugfs_trc *disc_trc;
48325 - atomic_t disc_trc_cnt;
48326 + atomic_unchecked_t disc_trc_cnt;
48327 #endif
48328 uint8_t stat_data_enabled;
48329 uint8_t stat_data_blocked;
48330 @@ -865,8 +865,8 @@ struct lpfc_hba {
48331 struct timer_list fabric_block_timer;
48332 unsigned long bit_flags;
48333 #define FABRIC_COMANDS_BLOCKED 0
48334 - atomic_t num_rsrc_err;
48335 - atomic_t num_cmd_success;
48336 + atomic_unchecked_t num_rsrc_err;
48337 + atomic_unchecked_t num_cmd_success;
48338 unsigned long last_rsrc_error_time;
48339 unsigned long last_ramp_down_time;
48340 unsigned long last_ramp_up_time;
48341 @@ -902,7 +902,7 @@ struct lpfc_hba {
48342
48343 struct dentry *debug_slow_ring_trc;
48344 struct lpfc_debugfs_trc *slow_ring_trc;
48345 - atomic_t slow_ring_trc_cnt;
48346 + atomic_unchecked_t slow_ring_trc_cnt;
48347 /* iDiag debugfs sub-directory */
48348 struct dentry *idiag_root;
48349 struct dentry *idiag_pci_cfg;
48350 diff --git a/drivers/scsi/lpfc/lpfc_debugfs.c b/drivers/scsi/lpfc/lpfc_debugfs.c
48351 index 60084e6..0e2e700 100644
48352 --- a/drivers/scsi/lpfc/lpfc_debugfs.c
48353 +++ b/drivers/scsi/lpfc/lpfc_debugfs.c
48354 @@ -106,7 +106,7 @@ MODULE_PARM_DESC(lpfc_debugfs_mask_disc_trc,
48355
48356 #include <linux/debugfs.h>
48357
48358 -static atomic_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
48359 +static atomic_unchecked_t lpfc_debugfs_seq_trc_cnt = ATOMIC_INIT(0);
48360 static unsigned long lpfc_debugfs_start_time = 0L;
48361
48362 /* iDiag */
48363 @@ -147,7 +147,7 @@ lpfc_debugfs_disc_trc_data(struct lpfc_vport *vport, char *buf, int size)
48364 lpfc_debugfs_enable = 0;
48365
48366 len = 0;
48367 - index = (atomic_read(&vport->disc_trc_cnt) + 1) &
48368 + index = (atomic_read_unchecked(&vport->disc_trc_cnt) + 1) &
48369 (lpfc_debugfs_max_disc_trc - 1);
48370 for (i = index; i < lpfc_debugfs_max_disc_trc; i++) {
48371 dtp = vport->disc_trc + i;
48372 @@ -213,7 +213,7 @@ lpfc_debugfs_slow_ring_trc_data(struct lpfc_hba *phba, char *buf, int size)
48373 lpfc_debugfs_enable = 0;
48374
48375 len = 0;
48376 - index = (atomic_read(&phba->slow_ring_trc_cnt) + 1) &
48377 + index = (atomic_read_unchecked(&phba->slow_ring_trc_cnt) + 1) &
48378 (lpfc_debugfs_max_slow_ring_trc - 1);
48379 for (i = index; i < lpfc_debugfs_max_slow_ring_trc; i++) {
48380 dtp = phba->slow_ring_trc + i;
48381 @@ -646,14 +646,14 @@ lpfc_debugfs_disc_trc(struct lpfc_vport *vport, int mask, char *fmt,
48382 !vport || !vport->disc_trc)
48383 return;
48384
48385 - index = atomic_inc_return(&vport->disc_trc_cnt) &
48386 + index = atomic_inc_return_unchecked(&vport->disc_trc_cnt) &
48387 (lpfc_debugfs_max_disc_trc - 1);
48388 dtp = vport->disc_trc + index;
48389 dtp->fmt = fmt;
48390 dtp->data1 = data1;
48391 dtp->data2 = data2;
48392 dtp->data3 = data3;
48393 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
48394 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
48395 dtp->jif = jiffies;
48396 #endif
48397 return;
48398 @@ -684,14 +684,14 @@ lpfc_debugfs_slow_ring_trc(struct lpfc_hba *phba, char *fmt,
48399 !phba || !phba->slow_ring_trc)
48400 return;
48401
48402 - index = atomic_inc_return(&phba->slow_ring_trc_cnt) &
48403 + index = atomic_inc_return_unchecked(&phba->slow_ring_trc_cnt) &
48404 (lpfc_debugfs_max_slow_ring_trc - 1);
48405 dtp = phba->slow_ring_trc + index;
48406 dtp->fmt = fmt;
48407 dtp->data1 = data1;
48408 dtp->data2 = data2;
48409 dtp->data3 = data3;
48410 - dtp->seq_cnt = atomic_inc_return(&lpfc_debugfs_seq_trc_cnt);
48411 + dtp->seq_cnt = atomic_inc_return_unchecked(&lpfc_debugfs_seq_trc_cnt);
48412 dtp->jif = jiffies;
48413 #endif
48414 return;
48415 @@ -4168,7 +4168,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
48416 "slow_ring buffer\n");
48417 goto debug_failed;
48418 }
48419 - atomic_set(&phba->slow_ring_trc_cnt, 0);
48420 + atomic_set_unchecked(&phba->slow_ring_trc_cnt, 0);
48421 memset(phba->slow_ring_trc, 0,
48422 (sizeof(struct lpfc_debugfs_trc) *
48423 lpfc_debugfs_max_slow_ring_trc));
48424 @@ -4214,7 +4214,7 @@ lpfc_debugfs_initialize(struct lpfc_vport *vport)
48425 "buffer\n");
48426 goto debug_failed;
48427 }
48428 - atomic_set(&vport->disc_trc_cnt, 0);
48429 + atomic_set_unchecked(&vport->disc_trc_cnt, 0);
48430
48431 snprintf(name, sizeof(name), "discovery_trace");
48432 vport->debug_disc_trc =
48433 diff --git a/drivers/scsi/lpfc/lpfc_init.c b/drivers/scsi/lpfc/lpfc_init.c
48434 index 68c94cc..8c27be5 100644
48435 --- a/drivers/scsi/lpfc/lpfc_init.c
48436 +++ b/drivers/scsi/lpfc/lpfc_init.c
48437 @@ -10949,8 +10949,10 @@ lpfc_init(void)
48438 "misc_register returned with status %d", error);
48439
48440 if (lpfc_enable_npiv) {
48441 - lpfc_transport_functions.vport_create = lpfc_vport_create;
48442 - lpfc_transport_functions.vport_delete = lpfc_vport_delete;
48443 + pax_open_kernel();
48444 + *(void **)&lpfc_transport_functions.vport_create = lpfc_vport_create;
48445 + *(void **)&lpfc_transport_functions.vport_delete = lpfc_vport_delete;
48446 + pax_close_kernel();
48447 }
48448 lpfc_transport_template =
48449 fc_attach_transport(&lpfc_transport_functions);
48450 diff --git a/drivers/scsi/lpfc/lpfc_scsi.c b/drivers/scsi/lpfc/lpfc_scsi.c
48451 index b2ede05..aaf482ca 100644
48452 --- a/drivers/scsi/lpfc/lpfc_scsi.c
48453 +++ b/drivers/scsi/lpfc/lpfc_scsi.c
48454 @@ -353,7 +353,7 @@ lpfc_rampdown_queue_depth(struct lpfc_hba *phba)
48455 uint32_t evt_posted;
48456
48457 spin_lock_irqsave(&phba->hbalock, flags);
48458 - atomic_inc(&phba->num_rsrc_err);
48459 + atomic_inc_unchecked(&phba->num_rsrc_err);
48460 phba->last_rsrc_error_time = jiffies;
48461
48462 if ((phba->last_ramp_down_time + QUEUE_RAMP_DOWN_INTERVAL) > jiffies) {
48463 @@ -394,7 +394,7 @@ lpfc_rampup_queue_depth(struct lpfc_vport *vport,
48464 unsigned long flags;
48465 struct lpfc_hba *phba = vport->phba;
48466 uint32_t evt_posted;
48467 - atomic_inc(&phba->num_cmd_success);
48468 + atomic_inc_unchecked(&phba->num_cmd_success);
48469
48470 if (vport->cfg_lun_queue_depth <= queue_depth)
48471 return;
48472 @@ -438,8 +438,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
48473 unsigned long num_rsrc_err, num_cmd_success;
48474 int i;
48475
48476 - num_rsrc_err = atomic_read(&phba->num_rsrc_err);
48477 - num_cmd_success = atomic_read(&phba->num_cmd_success);
48478 + num_rsrc_err = atomic_read_unchecked(&phba->num_rsrc_err);
48479 + num_cmd_success = atomic_read_unchecked(&phba->num_cmd_success);
48480
48481 /*
48482 * The error and success command counters are global per
48483 @@ -467,8 +467,8 @@ lpfc_ramp_down_queue_handler(struct lpfc_hba *phba)
48484 }
48485 }
48486 lpfc_destroy_vport_work_array(phba, vports);
48487 - atomic_set(&phba->num_rsrc_err, 0);
48488 - atomic_set(&phba->num_cmd_success, 0);
48489 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
48490 + atomic_set_unchecked(&phba->num_cmd_success, 0);
48491 }
48492
48493 /**
48494 @@ -502,8 +502,8 @@ lpfc_ramp_up_queue_handler(struct lpfc_hba *phba)
48495 }
48496 }
48497 lpfc_destroy_vport_work_array(phba, vports);
48498 - atomic_set(&phba->num_rsrc_err, 0);
48499 - atomic_set(&phba->num_cmd_success, 0);
48500 + atomic_set_unchecked(&phba->num_rsrc_err, 0);
48501 + atomic_set_unchecked(&phba->num_cmd_success, 0);
48502 }
48503
48504 /**
48505 diff --git a/drivers/scsi/mpt2sas/mpt2sas_scsih.c b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
48506 index 7f0af4f..193ac3e 100644
48507 --- a/drivers/scsi/mpt2sas/mpt2sas_scsih.c
48508 +++ b/drivers/scsi/mpt2sas/mpt2sas_scsih.c
48509 @@ -1557,7 +1557,7 @@ _scsih_get_resync(struct device *dev)
48510 {
48511 struct scsi_device *sdev = to_scsi_device(dev);
48512 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
48513 - static struct _raid_device *raid_device;
48514 + struct _raid_device *raid_device;
48515 unsigned long flags;
48516 Mpi2RaidVolPage0_t vol_pg0;
48517 Mpi2ConfigReply_t mpi_reply;
48518 @@ -1609,7 +1609,7 @@ _scsih_get_state(struct device *dev)
48519 {
48520 struct scsi_device *sdev = to_scsi_device(dev);
48521 struct MPT2SAS_ADAPTER *ioc = shost_priv(sdev->host);
48522 - static struct _raid_device *raid_device;
48523 + struct _raid_device *raid_device;
48524 unsigned long flags;
48525 Mpi2RaidVolPage0_t vol_pg0;
48526 Mpi2ConfigReply_t mpi_reply;
48527 @@ -6637,7 +6637,7 @@ _scsih_sas_ir_operation_status_event(struct MPT2SAS_ADAPTER *ioc,
48528 struct fw_event_work *fw_event)
48529 {
48530 Mpi2EventDataIrOperationStatus_t *event_data = fw_event->event_data;
48531 - static struct _raid_device *raid_device;
48532 + struct _raid_device *raid_device;
48533 unsigned long flags;
48534 u16 handle;
48535
48536 @@ -7108,7 +7108,7 @@ _scsih_scan_for_devices_after_reset(struct MPT2SAS_ADAPTER *ioc)
48537 u64 sas_address;
48538 struct _sas_device *sas_device;
48539 struct _sas_node *expander_device;
48540 - static struct _raid_device *raid_device;
48541 + struct _raid_device *raid_device;
48542 u8 retry_count;
48543 unsigned long flags;
48544
48545 diff --git a/drivers/scsi/pmcraid.c b/drivers/scsi/pmcraid.c
48546 index be8ce54..94ed33a 100644
48547 --- a/drivers/scsi/pmcraid.c
48548 +++ b/drivers/scsi/pmcraid.c
48549 @@ -200,8 +200,8 @@ static int pmcraid_slave_alloc(struct scsi_device *scsi_dev)
48550 res->scsi_dev = scsi_dev;
48551 scsi_dev->hostdata = res;
48552 res->change_detected = 0;
48553 - atomic_set(&res->read_failures, 0);
48554 - atomic_set(&res->write_failures, 0);
48555 + atomic_set_unchecked(&res->read_failures, 0);
48556 + atomic_set_unchecked(&res->write_failures, 0);
48557 rc = 0;
48558 }
48559 spin_unlock_irqrestore(&pinstance->resource_lock, lock_flags);
48560 @@ -2687,9 +2687,9 @@ static int pmcraid_error_handler(struct pmcraid_cmd *cmd)
48561
48562 /* If this was a SCSI read/write command keep count of errors */
48563 if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_READ_CMD)
48564 - atomic_inc(&res->read_failures);
48565 + atomic_inc_unchecked(&res->read_failures);
48566 else if (SCSI_CMD_TYPE(scsi_cmd->cmnd[0]) == SCSI_WRITE_CMD)
48567 - atomic_inc(&res->write_failures);
48568 + atomic_inc_unchecked(&res->write_failures);
48569
48570 if (!RES_IS_GSCSI(res->cfg_entry) &&
48571 masked_ioasc != PMCRAID_IOASC_HW_DEVICE_BUS_STATUS_ERROR) {
48572 @@ -3545,7 +3545,7 @@ static int pmcraid_queuecommand_lck(
48573 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
48574 * hrrq_id assigned here in queuecommand
48575 */
48576 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
48577 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
48578 pinstance->num_hrrq;
48579 cmd->cmd_done = pmcraid_io_done;
48580
48581 @@ -3857,7 +3857,7 @@ static long pmcraid_ioctl_passthrough(
48582 * block of scsi_cmd which is re-used (e.g. cancel/abort), which uses
48583 * hrrq_id assigned here in queuecommand
48584 */
48585 - ioarcb->hrrq_id = atomic_add_return(1, &(pinstance->last_message_id)) %
48586 + ioarcb->hrrq_id = atomic_add_return_unchecked(1, &(pinstance->last_message_id)) %
48587 pinstance->num_hrrq;
48588
48589 if (request_size) {
48590 @@ -4495,7 +4495,7 @@ static void pmcraid_worker_function(struct work_struct *workp)
48591
48592 pinstance = container_of(workp, struct pmcraid_instance, worker_q);
48593 /* add resources only after host is added into system */
48594 - if (!atomic_read(&pinstance->expose_resources))
48595 + if (!atomic_read_unchecked(&pinstance->expose_resources))
48596 return;
48597
48598 fw_version = be16_to_cpu(pinstance->inq_data->fw_version);
48599 @@ -5322,8 +5322,8 @@ static int pmcraid_init_instance(struct pci_dev *pdev, struct Scsi_Host *host,
48600 init_waitqueue_head(&pinstance->reset_wait_q);
48601
48602 atomic_set(&pinstance->outstanding_cmds, 0);
48603 - atomic_set(&pinstance->last_message_id, 0);
48604 - atomic_set(&pinstance->expose_resources, 0);
48605 + atomic_set_unchecked(&pinstance->last_message_id, 0);
48606 + atomic_set_unchecked(&pinstance->expose_resources, 0);
48607
48608 INIT_LIST_HEAD(&pinstance->free_res_q);
48609 INIT_LIST_HEAD(&pinstance->used_res_q);
48610 @@ -6036,7 +6036,7 @@ static int pmcraid_probe(struct pci_dev *pdev,
48611 /* Schedule worker thread to handle CCN and take care of adding and
48612 * removing devices to OS
48613 */
48614 - atomic_set(&pinstance->expose_resources, 1);
48615 + atomic_set_unchecked(&pinstance->expose_resources, 1);
48616 schedule_work(&pinstance->worker_q);
48617 return rc;
48618
48619 diff --git a/drivers/scsi/pmcraid.h b/drivers/scsi/pmcraid.h
48620 index e1d150f..6c6df44 100644
48621 --- a/drivers/scsi/pmcraid.h
48622 +++ b/drivers/scsi/pmcraid.h
48623 @@ -748,7 +748,7 @@ struct pmcraid_instance {
48624 struct pmcraid_isr_param hrrq_vector[PMCRAID_NUM_MSIX_VECTORS];
48625
48626 /* Message id as filled in last fired IOARCB, used to identify HRRQ */
48627 - atomic_t last_message_id;
48628 + atomic_unchecked_t last_message_id;
48629
48630 /* configuration table */
48631 struct pmcraid_config_table *cfg_table;
48632 @@ -777,7 +777,7 @@ struct pmcraid_instance {
48633 atomic_t outstanding_cmds;
48634
48635 /* should add/delete resources to mid-layer now ?*/
48636 - atomic_t expose_resources;
48637 + atomic_unchecked_t expose_resources;
48638
48639
48640
48641 @@ -813,8 +813,8 @@ struct pmcraid_resource_entry {
48642 struct pmcraid_config_table_entry_ext cfg_entry_ext;
48643 };
48644 struct scsi_device *scsi_dev; /* Link scsi_device structure */
48645 - atomic_t read_failures; /* count of failed READ commands */
48646 - atomic_t write_failures; /* count of failed WRITE commands */
48647 + atomic_unchecked_t read_failures; /* count of failed READ commands */
48648 + atomic_unchecked_t write_failures; /* count of failed WRITE commands */
48649
48650 /* To indicate add/delete/modify during CCN */
48651 u8 change_detected;
48652 diff --git a/drivers/scsi/qla2xxx/qla_attr.c b/drivers/scsi/qla2xxx/qla_attr.c
48653 index 5f174b8..98d32b0 100644
48654 --- a/drivers/scsi/qla2xxx/qla_attr.c
48655 +++ b/drivers/scsi/qla2xxx/qla_attr.c
48656 @@ -2040,7 +2040,7 @@ qla24xx_vport_disable(struct fc_vport *fc_vport, bool disable)
48657 return 0;
48658 }
48659
48660 -struct fc_function_template qla2xxx_transport_functions = {
48661 +fc_function_template_no_const qla2xxx_transport_functions = {
48662
48663 .show_host_node_name = 1,
48664 .show_host_port_name = 1,
48665 @@ -2088,7 +2088,7 @@ struct fc_function_template qla2xxx_transport_functions = {
48666 .bsg_timeout = qla24xx_bsg_timeout,
48667 };
48668
48669 -struct fc_function_template qla2xxx_transport_vport_functions = {
48670 +fc_function_template_no_const qla2xxx_transport_vport_functions = {
48671
48672 .show_host_node_name = 1,
48673 .show_host_port_name = 1,
48674 diff --git a/drivers/scsi/qla2xxx/qla_gbl.h b/drivers/scsi/qla2xxx/qla_gbl.h
48675 index 4446bf5..9a3574d 100644
48676 --- a/drivers/scsi/qla2xxx/qla_gbl.h
48677 +++ b/drivers/scsi/qla2xxx/qla_gbl.h
48678 @@ -538,8 +538,8 @@ extern void qla2x00_get_sym_node_name(scsi_qla_host_t *, uint8_t *);
48679 struct device_attribute;
48680 extern struct device_attribute *qla2x00_host_attrs[];
48681 struct fc_function_template;
48682 -extern struct fc_function_template qla2xxx_transport_functions;
48683 -extern struct fc_function_template qla2xxx_transport_vport_functions;
48684 +extern fc_function_template_no_const qla2xxx_transport_functions;
48685 +extern fc_function_template_no_const qla2xxx_transport_vport_functions;
48686 extern void qla2x00_alloc_sysfs_attr(scsi_qla_host_t *);
48687 extern void qla2x00_free_sysfs_attr(scsi_qla_host_t *);
48688 extern void qla2x00_init_host_attr(scsi_qla_host_t *);
48689 diff --git a/drivers/scsi/qla2xxx/qla_os.c b/drivers/scsi/qla2xxx/qla_os.c
48690 index 52be35e..b933907 100644
48691 --- a/drivers/scsi/qla2xxx/qla_os.c
48692 +++ b/drivers/scsi/qla2xxx/qla_os.c
48693 @@ -1568,8 +1568,10 @@ qla2x00_config_dma_addressing(struct qla_hw_data *ha)
48694 !pci_set_consistent_dma_mask(ha->pdev, DMA_BIT_MASK(64))) {
48695 /* Ok, a 64bit DMA mask is applicable. */
48696 ha->flags.enable_64bit_addressing = 1;
48697 - ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
48698 - ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
48699 + pax_open_kernel();
48700 + *(void **)&ha->isp_ops->calc_req_entries = qla2x00_calc_iocbs_64;
48701 + *(void **)&ha->isp_ops->build_iocbs = qla2x00_build_scsi_iocbs_64;
48702 + pax_close_kernel();
48703 return;
48704 }
48705 }
48706 diff --git a/drivers/scsi/qla4xxx/ql4_def.h b/drivers/scsi/qla4xxx/ql4_def.h
48707 index 084d1fd..9f939eb 100644
48708 --- a/drivers/scsi/qla4xxx/ql4_def.h
48709 +++ b/drivers/scsi/qla4xxx/ql4_def.h
48710 @@ -296,7 +296,7 @@ struct ddb_entry {
48711 * (4000 only) */
48712 atomic_t relogin_timer; /* Max Time to wait for
48713 * relogin to complete */
48714 - atomic_t relogin_retry_count; /* Num of times relogin has been
48715 + atomic_unchecked_t relogin_retry_count; /* Num of times relogin has been
48716 * retried */
48717 uint32_t default_time2wait; /* Default Min time between
48718 * relogins (+aens) */
48719 diff --git a/drivers/scsi/qla4xxx/ql4_os.c b/drivers/scsi/qla4xxx/ql4_os.c
48720 index cf174a4..128a420 100644
48721 --- a/drivers/scsi/qla4xxx/ql4_os.c
48722 +++ b/drivers/scsi/qla4xxx/ql4_os.c
48723 @@ -3311,12 +3311,12 @@ static void qla4xxx_check_relogin_flash_ddb(struct iscsi_cls_session *cls_sess)
48724 */
48725 if (!iscsi_is_session_online(cls_sess)) {
48726 /* Reset retry relogin timer */
48727 - atomic_inc(&ddb_entry->relogin_retry_count);
48728 + atomic_inc_unchecked(&ddb_entry->relogin_retry_count);
48729 DEBUG2(ql4_printk(KERN_INFO, ha,
48730 "%s: index[%d] relogin timed out-retrying"
48731 " relogin (%d), retry (%d)\n", __func__,
48732 ddb_entry->fw_ddb_index,
48733 - atomic_read(&ddb_entry->relogin_retry_count),
48734 + atomic_read_unchecked(&ddb_entry->relogin_retry_count),
48735 ddb_entry->default_time2wait + 4));
48736 set_bit(DPC_RELOGIN_DEVICE, &ha->dpc_flags);
48737 atomic_set(&ddb_entry->retry_relogin_timer,
48738 @@ -5458,7 +5458,7 @@ static void qla4xxx_setup_flash_ddb_entry(struct scsi_qla_host *ha,
48739
48740 atomic_set(&ddb_entry->retry_relogin_timer, INVALID_ENTRY);
48741 atomic_set(&ddb_entry->relogin_timer, 0);
48742 - atomic_set(&ddb_entry->relogin_retry_count, 0);
48743 + atomic_set_unchecked(&ddb_entry->relogin_retry_count, 0);
48744 def_timeout = le16_to_cpu(ddb_entry->fw_ddb_entry.def_timeout);
48745 ddb_entry->default_relogin_timeout =
48746 (def_timeout > LOGIN_TOV) && (def_timeout < LOGIN_TOV * 10) ?
48747 diff --git a/drivers/scsi/scsi.c b/drivers/scsi/scsi.c
48748 index fe0bcb1..c9255be 100644
48749 --- a/drivers/scsi/scsi.c
48750 +++ b/drivers/scsi/scsi.c
48751 @@ -655,7 +655,7 @@ int scsi_dispatch_cmd(struct scsi_cmnd *cmd)
48752 struct Scsi_Host *host = cmd->device->host;
48753 int rtn = 0;
48754
48755 - atomic_inc(&cmd->device->iorequest_cnt);
48756 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
48757
48758 /* check if the device is still usable */
48759 if (unlikely(cmd->device->sdev_state == SDEV_DEL)) {
48760 diff --git a/drivers/scsi/scsi_lib.c b/drivers/scsi/scsi_lib.c
48761 index 7bd7f0d..44147bf 100644
48762 --- a/drivers/scsi/scsi_lib.c
48763 +++ b/drivers/scsi/scsi_lib.c
48764 @@ -1474,7 +1474,7 @@ static void scsi_kill_request(struct request *req, struct request_queue *q)
48765 shost = sdev->host;
48766 scsi_init_cmd_errh(cmd);
48767 cmd->result = DID_NO_CONNECT << 16;
48768 - atomic_inc(&cmd->device->iorequest_cnt);
48769 + atomic_inc_unchecked(&cmd->device->iorequest_cnt);
48770
48771 /*
48772 * SCSI request completion path will do scsi_device_unbusy(),
48773 @@ -1500,9 +1500,9 @@ static void scsi_softirq_done(struct request *rq)
48774
48775 INIT_LIST_HEAD(&cmd->eh_entry);
48776
48777 - atomic_inc(&cmd->device->iodone_cnt);
48778 + atomic_inc_unchecked(&cmd->device->iodone_cnt);
48779 if (cmd->result)
48780 - atomic_inc(&cmd->device->ioerr_cnt);
48781 + atomic_inc_unchecked(&cmd->device->ioerr_cnt);
48782
48783 disposition = scsi_decide_disposition(cmd);
48784 if (disposition != SUCCESS &&
48785 diff --git a/drivers/scsi/scsi_sysfs.c b/drivers/scsi/scsi_sysfs.c
48786 index 8ff62c2..693b6f7 100644
48787 --- a/drivers/scsi/scsi_sysfs.c
48788 +++ b/drivers/scsi/scsi_sysfs.c
48789 @@ -725,7 +725,7 @@ show_iostat_##field(struct device *dev, struct device_attribute *attr, \
48790 char *buf) \
48791 { \
48792 struct scsi_device *sdev = to_scsi_device(dev); \
48793 - unsigned long long count = atomic_read(&sdev->field); \
48794 + unsigned long long count = atomic_read_unchecked(&sdev->field); \
48795 return snprintf(buf, 20, "0x%llx\n", count); \
48796 } \
48797 static DEVICE_ATTR(field, S_IRUGO, show_iostat_##field, NULL)
48798 diff --git a/drivers/scsi/scsi_tgt_lib.c b/drivers/scsi/scsi_tgt_lib.c
48799 index 84a1fdf..693b0d6 100644
48800 --- a/drivers/scsi/scsi_tgt_lib.c
48801 +++ b/drivers/scsi/scsi_tgt_lib.c
48802 @@ -362,7 +362,7 @@ static int scsi_map_user_pages(struct scsi_tgt_cmd *tcmd, struct scsi_cmnd *cmd,
48803 int err;
48804
48805 dprintk("%lx %u\n", uaddr, len);
48806 - err = blk_rq_map_user(q, rq, NULL, (void *)uaddr, len, GFP_KERNEL);
48807 + err = blk_rq_map_user(q, rq, NULL, (void __user *)uaddr, len, GFP_KERNEL);
48808 if (err) {
48809 /*
48810 * TODO: need to fixup sg_tablesize, max_segment_size,
48811 diff --git a/drivers/scsi/scsi_transport_fc.c b/drivers/scsi/scsi_transport_fc.c
48812 index 4628fd5..a94a1c2 100644
48813 --- a/drivers/scsi/scsi_transport_fc.c
48814 +++ b/drivers/scsi/scsi_transport_fc.c
48815 @@ -497,7 +497,7 @@ static DECLARE_TRANSPORT_CLASS(fc_vport_class,
48816 * Netlink Infrastructure
48817 */
48818
48819 -static atomic_t fc_event_seq;
48820 +static atomic_unchecked_t fc_event_seq;
48821
48822 /**
48823 * fc_get_event_number - Obtain the next sequential FC event number
48824 @@ -510,7 +510,7 @@ static atomic_t fc_event_seq;
48825 u32
48826 fc_get_event_number(void)
48827 {
48828 - return atomic_add_return(1, &fc_event_seq);
48829 + return atomic_add_return_unchecked(1, &fc_event_seq);
48830 }
48831 EXPORT_SYMBOL(fc_get_event_number);
48832
48833 @@ -654,7 +654,7 @@ static __init int fc_transport_init(void)
48834 {
48835 int error;
48836
48837 - atomic_set(&fc_event_seq, 0);
48838 + atomic_set_unchecked(&fc_event_seq, 0);
48839
48840 error = transport_class_register(&fc_host_class);
48841 if (error)
48842 @@ -844,7 +844,7 @@ static int fc_str_to_dev_loss(const char *buf, unsigned long *val)
48843 char *cp;
48844
48845 *val = simple_strtoul(buf, &cp, 0);
48846 - if ((*cp && (*cp != '\n')) || (*val < 0))
48847 + if (*cp && (*cp != '\n'))
48848 return -EINVAL;
48849 /*
48850 * Check for overflow; dev_loss_tmo is u32
48851 diff --git a/drivers/scsi/scsi_transport_iscsi.c b/drivers/scsi/scsi_transport_iscsi.c
48852 index 63a6ca4..5d5cadd 100644
48853 --- a/drivers/scsi/scsi_transport_iscsi.c
48854 +++ b/drivers/scsi/scsi_transport_iscsi.c
48855 @@ -79,7 +79,7 @@ struct iscsi_internal {
48856 struct transport_container session_cont;
48857 };
48858
48859 -static atomic_t iscsi_session_nr; /* sysfs session id for next new session */
48860 +static atomic_unchecked_t iscsi_session_nr; /* sysfs session id for next new session */
48861 static struct workqueue_struct *iscsi_eh_timer_workq;
48862
48863 static DEFINE_IDA(iscsi_sess_ida);
48864 @@ -1737,7 +1737,7 @@ int iscsi_add_session(struct iscsi_cls_session *session, unsigned int target_id)
48865 int err;
48866
48867 ihost = shost->shost_data;
48868 - session->sid = atomic_add_return(1, &iscsi_session_nr);
48869 + session->sid = atomic_add_return_unchecked(1, &iscsi_session_nr);
48870
48871 if (target_id == ISCSI_MAX_TARGET) {
48872 id = ida_simple_get(&iscsi_sess_ida, 0, 0, GFP_KERNEL);
48873 @@ -4103,7 +4103,7 @@ static __init int iscsi_transport_init(void)
48874 printk(KERN_INFO "Loading iSCSI transport class v%s.\n",
48875 ISCSI_TRANSPORT_VERSION);
48876
48877 - atomic_set(&iscsi_session_nr, 0);
48878 + atomic_set_unchecked(&iscsi_session_nr, 0);
48879
48880 err = class_register(&iscsi_transport_class);
48881 if (err)
48882 diff --git a/drivers/scsi/scsi_transport_srp.c b/drivers/scsi/scsi_transport_srp.c
48883 index 2700a5a..752ec38 100644
48884 --- a/drivers/scsi/scsi_transport_srp.c
48885 +++ b/drivers/scsi/scsi_transport_srp.c
48886 @@ -36,7 +36,7 @@
48887 #include "scsi_transport_srp_internal.h"
48888
48889 struct srp_host_attrs {
48890 - atomic_t next_port_id;
48891 + atomic_unchecked_t next_port_id;
48892 };
48893 #define to_srp_host_attrs(host) ((struct srp_host_attrs *)(host)->shost_data)
48894
48895 @@ -94,7 +94,7 @@ static int srp_host_setup(struct transport_container *tc, struct device *dev,
48896 struct Scsi_Host *shost = dev_to_shost(dev);
48897 struct srp_host_attrs *srp_host = to_srp_host_attrs(shost);
48898
48899 - atomic_set(&srp_host->next_port_id, 0);
48900 + atomic_set_unchecked(&srp_host->next_port_id, 0);
48901 return 0;
48902 }
48903
48904 @@ -730,7 +730,7 @@ struct srp_rport *srp_rport_add(struct Scsi_Host *shost,
48905 rport_fast_io_fail_timedout);
48906 INIT_DELAYED_WORK(&rport->dev_loss_work, rport_dev_loss_timedout);
48907
48908 - id = atomic_inc_return(&to_srp_host_attrs(shost)->next_port_id);
48909 + id = atomic_inc_return_unchecked(&to_srp_host_attrs(shost)->next_port_id);
48910 dev_set_name(&rport->dev, "port-%d:%d", shost->host_no, id);
48911
48912 transport_setup_device(&rport->dev);
48913 diff --git a/drivers/scsi/sd.c b/drivers/scsi/sd.c
48914 index 69725f7..03aaee1 100644
48915 --- a/drivers/scsi/sd.c
48916 +++ b/drivers/scsi/sd.c
48917 @@ -2964,7 +2964,7 @@ static int sd_probe(struct device *dev)
48918 sdkp->disk = gd;
48919 sdkp->index = index;
48920 atomic_set(&sdkp->openers, 0);
48921 - atomic_set(&sdkp->device->ioerr_cnt, 0);
48922 + atomic_set_unchecked(&sdkp->device->ioerr_cnt, 0);
48923
48924 if (!sdp->request_queue->rq_timeout) {
48925 if (sdp->type != TYPE_MOD)
48926 diff --git a/drivers/scsi/sg.c b/drivers/scsi/sg.c
48927 index df5e961..df6b97f 100644
48928 --- a/drivers/scsi/sg.c
48929 +++ b/drivers/scsi/sg.c
48930 @@ -1102,7 +1102,7 @@ sg_ioctl(struct file *filp, unsigned int cmd_in, unsigned long arg)
48931 sdp->disk->disk_name,
48932 MKDEV(SCSI_GENERIC_MAJOR, sdp->index),
48933 NULL,
48934 - (char *)arg);
48935 + (char __user *)arg);
48936 case BLKTRACESTART:
48937 return blk_trace_startstop(sdp->device->request_queue, 1);
48938 case BLKTRACESTOP:
48939 diff --git a/drivers/spi/spi.c b/drivers/spi/spi.c
48940 index d745f95..6bef2fc 100644
48941 --- a/drivers/spi/spi.c
48942 +++ b/drivers/spi/spi.c
48943 @@ -1947,7 +1947,7 @@ int spi_bus_unlock(struct spi_master *master)
48944 EXPORT_SYMBOL_GPL(spi_bus_unlock);
48945
48946 /* portable code must never pass more than 32 bytes */
48947 -#define SPI_BUFSIZ max(32, SMP_CACHE_BYTES)
48948 +#define SPI_BUFSIZ max(32UL, SMP_CACHE_BYTES)
48949
48950 static u8 *buf;
48951
48952 diff --git a/drivers/staging/android/timed_output.c b/drivers/staging/android/timed_output.c
48953 index 2c61783..4d49e4e 100644
48954 --- a/drivers/staging/android/timed_output.c
48955 +++ b/drivers/staging/android/timed_output.c
48956 @@ -25,7 +25,7 @@
48957 #include "timed_output.h"
48958
48959 static struct class *timed_output_class;
48960 -static atomic_t device_count;
48961 +static atomic_unchecked_t device_count;
48962
48963 static ssize_t enable_show(struct device *dev, struct device_attribute *attr,
48964 char *buf)
48965 @@ -63,7 +63,7 @@ static int create_timed_output_class(void)
48966 timed_output_class = class_create(THIS_MODULE, "timed_output");
48967 if (IS_ERR(timed_output_class))
48968 return PTR_ERR(timed_output_class);
48969 - atomic_set(&device_count, 0);
48970 + atomic_set_unchecked(&device_count, 0);
48971 timed_output_class->dev_groups = timed_output_groups;
48972 }
48973
48974 @@ -81,7 +81,7 @@ int timed_output_dev_register(struct timed_output_dev *tdev)
48975 if (ret < 0)
48976 return ret;
48977
48978 - tdev->index = atomic_inc_return(&device_count);
48979 + tdev->index = atomic_inc_return_unchecked(&device_count);
48980 tdev->dev = device_create(timed_output_class, NULL,
48981 MKDEV(0, tdev->index), NULL, "%s", tdev->name);
48982 if (IS_ERR(tdev->dev))
48983 diff --git a/drivers/staging/gdm724x/gdm_tty.c b/drivers/staging/gdm724x/gdm_tty.c
48984 index c0f7cd7..5424212 100644
48985 --- a/drivers/staging/gdm724x/gdm_tty.c
48986 +++ b/drivers/staging/gdm724x/gdm_tty.c
48987 @@ -45,7 +45,7 @@
48988 #define gdm_tty_send_control(n, r, v, d, l) (\
48989 n->tty_dev->send_control(n->tty_dev->priv_dev, r, v, d, l))
48990
48991 -#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && gdm->port.count)
48992 +#define GDM_TTY_READY(gdm) (gdm && gdm->tty_dev && atomic_read(&gdm->port.count))
48993
48994 static struct tty_driver *gdm_driver[TTY_MAX_COUNT];
48995 static struct gdm *gdm_table[TTY_MAX_COUNT][GDM_TTY_MINOR];
48996 diff --git a/drivers/staging/lustre/lnet/selftest/brw_test.c b/drivers/staging/lustre/lnet/selftest/brw_test.c
48997 index b7613c8..c302392 100644
48998 --- a/drivers/staging/lustre/lnet/selftest/brw_test.c
48999 +++ b/drivers/staging/lustre/lnet/selftest/brw_test.c
49000 @@ -487,13 +487,11 @@ brw_server_handle(struct srpc_server_rpc *rpc)
49001 return 0;
49002 }
49003
49004 -sfw_test_client_ops_t brw_test_client;
49005 -void brw_init_test_client(void)
49006 -{
49007 - brw_test_client.tso_init = brw_client_init;
49008 - brw_test_client.tso_fini = brw_client_fini;
49009 - brw_test_client.tso_prep_rpc = brw_client_prep_rpc;
49010 - brw_test_client.tso_done_rpc = brw_client_done_rpc;
49011 +sfw_test_client_ops_t brw_test_client = {
49012 + .tso_init = brw_client_init,
49013 + .tso_fini = brw_client_fini,
49014 + .tso_prep_rpc = brw_client_prep_rpc,
49015 + .tso_done_rpc = brw_client_done_rpc,
49016 };
49017
49018 srpc_service_t brw_test_service;
49019 diff --git a/drivers/staging/lustre/lnet/selftest/framework.c b/drivers/staging/lustre/lnet/selftest/framework.c
49020 index 483c785..e1a2a7b 100644
49021 --- a/drivers/staging/lustre/lnet/selftest/framework.c
49022 +++ b/drivers/staging/lustre/lnet/selftest/framework.c
49023 @@ -1635,12 +1635,10 @@ static srpc_service_t sfw_services[] =
49024
49025 extern sfw_test_client_ops_t ping_test_client;
49026 extern srpc_service_t ping_test_service;
49027 -extern void ping_init_test_client(void);
49028 extern void ping_init_test_service(void);
49029
49030 extern sfw_test_client_ops_t brw_test_client;
49031 extern srpc_service_t brw_test_service;
49032 -extern void brw_init_test_client(void);
49033 extern void brw_init_test_service(void);
49034
49035
49036 @@ -1684,12 +1682,10 @@ sfw_startup (void)
49037 INIT_LIST_HEAD(&sfw_data.fw_zombie_rpcs);
49038 INIT_LIST_HEAD(&sfw_data.fw_zombie_sessions);
49039
49040 - brw_init_test_client();
49041 brw_init_test_service();
49042 rc = sfw_register_test(&brw_test_service, &brw_test_client);
49043 LASSERT (rc == 0);
49044
49045 - ping_init_test_client();
49046 ping_init_test_service();
49047 rc = sfw_register_test(&ping_test_service, &ping_test_client);
49048 LASSERT (rc == 0);
49049 diff --git a/drivers/staging/lustre/lnet/selftest/ping_test.c b/drivers/staging/lustre/lnet/selftest/ping_test.c
49050 index f0f9194..b589047 100644
49051 --- a/drivers/staging/lustre/lnet/selftest/ping_test.c
49052 +++ b/drivers/staging/lustre/lnet/selftest/ping_test.c
49053 @@ -210,14 +210,12 @@ ping_server_handle(struct srpc_server_rpc *rpc)
49054 return 0;
49055 }
49056
49057 -sfw_test_client_ops_t ping_test_client;
49058 -void ping_init_test_client(void)
49059 -{
49060 - ping_test_client.tso_init = ping_client_init;
49061 - ping_test_client.tso_fini = ping_client_fini;
49062 - ping_test_client.tso_prep_rpc = ping_client_prep_rpc;
49063 - ping_test_client.tso_done_rpc = ping_client_done_rpc;
49064 -}
49065 +sfw_test_client_ops_t ping_test_client = {
49066 + .tso_init = ping_client_init,
49067 + .tso_fini = ping_client_fini,
49068 + .tso_prep_rpc = ping_client_prep_rpc,
49069 + .tso_done_rpc = ping_client_done_rpc,
49070 +};
49071
49072 srpc_service_t ping_test_service;
49073 void ping_init_test_service(void)
49074 diff --git a/drivers/staging/lustre/lustre/include/lustre_dlm.h b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49075 index bc2b82f..67fd598 100644
49076 --- a/drivers/staging/lustre/lustre/include/lustre_dlm.h
49077 +++ b/drivers/staging/lustre/lustre/include/lustre_dlm.h
49078 @@ -1141,7 +1141,7 @@ struct ldlm_callback_suite {
49079 ldlm_completion_callback lcs_completion;
49080 ldlm_blocking_callback lcs_blocking;
49081 ldlm_glimpse_callback lcs_glimpse;
49082 -};
49083 +} __no_const;
49084
49085 /* ldlm_lockd.c */
49086 int ldlm_del_waiting_lock(struct ldlm_lock *lock);
49087 diff --git a/drivers/staging/lustre/lustre/include/obd.h b/drivers/staging/lustre/lustre/include/obd.h
49088 index d0aea15..7af68e1 100644
49089 --- a/drivers/staging/lustre/lustre/include/obd.h
49090 +++ b/drivers/staging/lustre/lustre/include/obd.h
49091 @@ -1417,7 +1417,7 @@ struct md_ops {
49092 * lprocfs_alloc_md_stats() in obdclass/lprocfs_status.c. Also, add a
49093 * wrapper function in include/linux/obd_class.h.
49094 */
49095 -};
49096 +} __no_const;
49097
49098 struct lsm_operations {
49099 void (*lsm_free)(struct lov_stripe_md *);
49100 diff --git a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49101 index 39fcdac..222780f 100644
49102 --- a/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49103 +++ b/drivers/staging/lustre/lustre/ldlm/ldlm_flock.c
49104 @@ -249,7 +249,7 @@ ldlm_process_flock_lock(struct ldlm_lock *req, __u64 *flags, int first_enq,
49105 int added = (mode == LCK_NL);
49106 int overlaps = 0;
49107 int splitted = 0;
49108 - const struct ldlm_callback_suite null_cbs = { NULL };
49109 + const struct ldlm_callback_suite null_cbs = { };
49110 int rc;
49111
49112 CDEBUG(D_DLMTRACE, "flags %#llx owner "LPU64" pid %u mode %u start "
49113 diff --git a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49114 index fc6c977..df1f956 100644
49115 --- a/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49116 +++ b/drivers/staging/lustre/lustre/libcfs/linux/linux-proc.c
49117 @@ -219,7 +219,7 @@ DECLARE_PROC_HANDLER(proc_debug_mb)
49118 int LL_PROC_PROTO(proc_console_max_delay_cs)
49119 {
49120 int rc, max_delay_cs;
49121 - ctl_table_t dummy = *table;
49122 + ctl_table_no_const dummy = *table;
49123 cfs_duration_t d;
49124
49125 dummy.data = &max_delay_cs;
49126 @@ -250,7 +250,7 @@ int LL_PROC_PROTO(proc_console_max_delay_cs)
49127 int LL_PROC_PROTO(proc_console_min_delay_cs)
49128 {
49129 int rc, min_delay_cs;
49130 - ctl_table_t dummy = *table;
49131 + ctl_table_no_const dummy = *table;
49132 cfs_duration_t d;
49133
49134 dummy.data = &min_delay_cs;
49135 @@ -281,7 +281,7 @@ int LL_PROC_PROTO(proc_console_min_delay_cs)
49136 int LL_PROC_PROTO(proc_console_backoff)
49137 {
49138 int rc, backoff;
49139 - ctl_table_t dummy = *table;
49140 + ctl_table_no_const dummy = *table;
49141
49142 dummy.data = &backoff;
49143 dummy.proc_handler = &proc_dointvec;
49144 diff --git a/drivers/staging/lustre/lustre/libcfs/module.c b/drivers/staging/lustre/lustre/libcfs/module.c
49145 index f3108c7..cd4f9da 100644
49146 --- a/drivers/staging/lustre/lustre/libcfs/module.c
49147 +++ b/drivers/staging/lustre/lustre/libcfs/module.c
49148 @@ -348,11 +348,11 @@ out:
49149
49150
49151 struct cfs_psdev_ops libcfs_psdev_ops = {
49152 - libcfs_psdev_open,
49153 - libcfs_psdev_release,
49154 - NULL,
49155 - NULL,
49156 - libcfs_ioctl
49157 + .p_open = libcfs_psdev_open,
49158 + .p_close = libcfs_psdev_release,
49159 + .p_read = NULL,
49160 + .p_write = NULL,
49161 + .p_ioctl = libcfs_ioctl
49162 };
49163
49164 extern int insert_proc(void);
49165 diff --git a/drivers/staging/media/solo6x10/solo6x10-core.c b/drivers/staging/media/solo6x10/solo6x10-core.c
49166 index 3675020..e80d92c 100644
49167 --- a/drivers/staging/media/solo6x10/solo6x10-core.c
49168 +++ b/drivers/staging/media/solo6x10/solo6x10-core.c
49169 @@ -434,7 +434,7 @@ static void solo_device_release(struct device *dev)
49170
49171 static int solo_sysfs_init(struct solo_dev *solo_dev)
49172 {
49173 - struct bin_attribute *sdram_attr = &solo_dev->sdram_attr;
49174 + bin_attribute_no_const *sdram_attr = &solo_dev->sdram_attr;
49175 struct device *dev = &solo_dev->dev;
49176 const char *driver;
49177 int i;
49178 diff --git a/drivers/staging/media/solo6x10/solo6x10-g723.c b/drivers/staging/media/solo6x10/solo6x10-g723.c
49179 index 1db18c7..35e6afc 100644
49180 --- a/drivers/staging/media/solo6x10/solo6x10-g723.c
49181 +++ b/drivers/staging/media/solo6x10/solo6x10-g723.c
49182 @@ -355,7 +355,7 @@ static int solo_snd_pcm_init(struct solo_dev *solo_dev)
49183
49184 int solo_g723_init(struct solo_dev *solo_dev)
49185 {
49186 - static struct snd_device_ops ops = { NULL };
49187 + static struct snd_device_ops ops = { };
49188 struct snd_card *card;
49189 struct snd_kcontrol_new kctl;
49190 char name[32];
49191 diff --git a/drivers/staging/media/solo6x10/solo6x10-p2m.c b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49192 index 7f2f247..d999137 100644
49193 --- a/drivers/staging/media/solo6x10/solo6x10-p2m.c
49194 +++ b/drivers/staging/media/solo6x10/solo6x10-p2m.c
49195 @@ -77,7 +77,7 @@ int solo_p2m_dma_desc(struct solo_dev *solo_dev,
49196
49197 /* Get next ID. According to Softlogic, 6110 has problems on !=0 P2M */
49198 if (solo_dev->type != SOLO_DEV_6110 && multi_p2m) {
49199 - p2m_id = atomic_inc_return(&solo_dev->p2m_count) % SOLO_NR_P2M;
49200 + p2m_id = atomic_inc_return_unchecked(&solo_dev->p2m_count) % SOLO_NR_P2M;
49201 if (p2m_id < 0)
49202 p2m_id = -p2m_id;
49203 }
49204 diff --git a/drivers/staging/media/solo6x10/solo6x10.h b/drivers/staging/media/solo6x10/solo6x10.h
49205 index f1bbb8c..a73eaba 100644
49206 --- a/drivers/staging/media/solo6x10/solo6x10.h
49207 +++ b/drivers/staging/media/solo6x10/solo6x10.h
49208 @@ -237,7 +237,7 @@ struct solo_dev {
49209
49210 /* P2M DMA Engine */
49211 struct solo_p2m_dev p2m_dev[SOLO_NR_P2M];
49212 - atomic_t p2m_count;
49213 + atomic_unchecked_t p2m_count;
49214 int p2m_jiffies;
49215 unsigned int p2m_timeouts;
49216
49217 diff --git a/drivers/staging/octeon/ethernet-rx.c b/drivers/staging/octeon/ethernet-rx.c
49218 index 0315f60..2ecae10 100644
49219 --- a/drivers/staging/octeon/ethernet-rx.c
49220 +++ b/drivers/staging/octeon/ethernet-rx.c
49221 @@ -418,11 +418,11 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49222 /* Increment RX stats for virtual ports */
49223 if (work->ipprt >= CVMX_PIP_NUM_INPUT_PORTS) {
49224 #ifdef CONFIG_64BIT
49225 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_packets);
49226 - atomic64_add(skb->len, (atomic64_t *)&priv->stats.rx_bytes);
49227 + atomic64_add_unchecked(1, (atomic64_unchecked_t *)&priv->stats.rx_packets);
49228 + atomic64_add_unchecked(skb->len, (atomic64_unchecked_t *)&priv->stats.rx_bytes);
49229 #else
49230 - atomic_add(1, (atomic_t *)&priv->stats.rx_packets);
49231 - atomic_add(skb->len, (atomic_t *)&priv->stats.rx_bytes);
49232 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_packets);
49233 + atomic_add_unchecked(skb->len, (atomic_unchecked_t *)&priv->stats.rx_bytes);
49234 #endif
49235 }
49236 netif_receive_skb(skb);
49237 @@ -433,9 +433,9 @@ static int cvm_oct_napi_poll(struct napi_struct *napi, int budget)
49238 dev->name);
49239 */
49240 #ifdef CONFIG_64BIT
49241 - atomic64_add(1, (atomic64_t *)&priv->stats.rx_dropped);
49242 + atomic64_unchecked_add(1, (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49243 #else
49244 - atomic_add(1, (atomic_t *)&priv->stats.rx_dropped);
49245 + atomic_add_unchecked(1, (atomic_unchecked_t *)&priv->stats.rx_dropped);
49246 #endif
49247 dev_kfree_skb_irq(skb);
49248 }
49249 diff --git a/drivers/staging/octeon/ethernet.c b/drivers/staging/octeon/ethernet.c
49250 index bd6ca71..8f0961e 100644
49251 --- a/drivers/staging/octeon/ethernet.c
49252 +++ b/drivers/staging/octeon/ethernet.c
49253 @@ -254,11 +254,11 @@ static struct net_device_stats *cvm_oct_common_get_stats(struct net_device *dev)
49254 * since the RX tasklet also increments it.
49255 */
49256 #ifdef CONFIG_64BIT
49257 - atomic64_add(rx_status.dropped_packets,
49258 - (atomic64_t *)&priv->stats.rx_dropped);
49259 + atomic64_add_unchecked(rx_status.dropped_packets,
49260 + (atomic64_unchecked_t *)&priv->stats.rx_dropped);
49261 #else
49262 - atomic_add(rx_status.dropped_packets,
49263 - (atomic_t *)&priv->stats.rx_dropped);
49264 + atomic_add_unchecked(rx_status.dropped_packets,
49265 + (atomic_unchecked_t *)&priv->stats.rx_dropped);
49266 #endif
49267 }
49268
49269 diff --git a/drivers/staging/rtl8188eu/include/hal_intf.h b/drivers/staging/rtl8188eu/include/hal_intf.h
49270 index 439c3c9..2d74293 100644
49271 --- a/drivers/staging/rtl8188eu/include/hal_intf.h
49272 +++ b/drivers/staging/rtl8188eu/include/hal_intf.h
49273 @@ -271,7 +271,7 @@ struct hal_ops {
49274 s32 (*c2h_handler)(struct adapter *padapter,
49275 struct c2h_evt_hdr *c2h_evt);
49276 c2h_id_filter c2h_id_filter_ccx;
49277 -};
49278 +} __no_const;
49279
49280 enum rt_eeprom_type {
49281 EEPROM_93C46,
49282 diff --git a/drivers/staging/rtl8188eu/include/rtw_io.h b/drivers/staging/rtl8188eu/include/rtw_io.h
49283 index eb6f0e5..e6a0958 100644
49284 --- a/drivers/staging/rtl8188eu/include/rtw_io.h
49285 +++ b/drivers/staging/rtl8188eu/include/rtw_io.h
49286 @@ -126,7 +126,7 @@ struct _io_ops {
49287 u32 (*_write_scsi)(struct intf_hdl *pintfhdl,u32 cnt, u8 *pmem);
49288 void (*_read_port_cancel)(struct intf_hdl *pintfhdl);
49289 void (*_write_port_cancel)(struct intf_hdl *pintfhdl);
49290 -};
49291 +} __no_const;
49292
49293 struct io_req {
49294 struct list_head list;
49295 diff --git a/drivers/staging/rtl8712/rtl871x_io.h b/drivers/staging/rtl8712/rtl871x_io.h
49296 index dc23395..cf7e9b1 100644
49297 --- a/drivers/staging/rtl8712/rtl871x_io.h
49298 +++ b/drivers/staging/rtl8712/rtl871x_io.h
49299 @@ -108,7 +108,7 @@ struct _io_ops {
49300 u8 *pmem);
49301 u32 (*_write_port)(struct intf_hdl *pintfhdl, u32 addr, u32 cnt,
49302 u8 *pmem);
49303 -};
49304 +} __no_const;
49305
49306 struct io_req {
49307 struct list_head list;
49308 diff --git a/drivers/staging/sbe-2t3e3/netdev.c b/drivers/staging/sbe-2t3e3/netdev.c
49309 index 1f5088b..0e59820 100644
49310 --- a/drivers/staging/sbe-2t3e3/netdev.c
49311 +++ b/drivers/staging/sbe-2t3e3/netdev.c
49312 @@ -51,7 +51,7 @@ static int t3e3_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
49313 t3e3_if_config(sc, cmd_2t3e3, (char *)&param, &resp, &rlen);
49314
49315 if (rlen)
49316 - if (copy_to_user(data, &resp, rlen))
49317 + if (rlen > sizeof resp || copy_to_user(data, &resp, rlen))
49318 return -EFAULT;
49319
49320 return 0;
49321 diff --git a/drivers/staging/usbip/vhci.h b/drivers/staging/usbip/vhci.h
49322 index a863a98..d272795 100644
49323 --- a/drivers/staging/usbip/vhci.h
49324 +++ b/drivers/staging/usbip/vhci.h
49325 @@ -83,7 +83,7 @@ struct vhci_hcd {
49326 unsigned resuming:1;
49327 unsigned long re_timeout;
49328
49329 - atomic_t seqnum;
49330 + atomic_unchecked_t seqnum;
49331
49332 /*
49333 * NOTE:
49334 diff --git a/drivers/staging/usbip/vhci_hcd.c b/drivers/staging/usbip/vhci_hcd.c
49335 index e810ad5..931336f 100644
49336 --- a/drivers/staging/usbip/vhci_hcd.c
49337 +++ b/drivers/staging/usbip/vhci_hcd.c
49338 @@ -441,7 +441,7 @@ static void vhci_tx_urb(struct urb *urb)
49339
49340 spin_lock(&vdev->priv_lock);
49341
49342 - priv->seqnum = atomic_inc_return(&the_controller->seqnum);
49343 + priv->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
49344 if (priv->seqnum == 0xffff)
49345 dev_info(&urb->dev->dev, "seqnum max\n");
49346
49347 @@ -687,7 +687,7 @@ static int vhci_urb_dequeue(struct usb_hcd *hcd, struct urb *urb, int status)
49348 return -ENOMEM;
49349 }
49350
49351 - unlink->seqnum = atomic_inc_return(&the_controller->seqnum);
49352 + unlink->seqnum = atomic_inc_return_unchecked(&the_controller->seqnum);
49353 if (unlink->seqnum == 0xffff)
49354 pr_info("seqnum max\n");
49355
49356 @@ -891,7 +891,7 @@ static int vhci_start(struct usb_hcd *hcd)
49357 vdev->rhport = rhport;
49358 }
49359
49360 - atomic_set(&vhci->seqnum, 0);
49361 + atomic_set_unchecked(&vhci->seqnum, 0);
49362 spin_lock_init(&vhci->lock);
49363
49364 hcd->power_budget = 0; /* no limit */
49365 diff --git a/drivers/staging/usbip/vhci_rx.c b/drivers/staging/usbip/vhci_rx.c
49366 index d07fcb5..358e1e1 100644
49367 --- a/drivers/staging/usbip/vhci_rx.c
49368 +++ b/drivers/staging/usbip/vhci_rx.c
49369 @@ -80,7 +80,7 @@ static void vhci_recv_ret_submit(struct vhci_device *vdev,
49370 if (!urb) {
49371 pr_err("cannot find a urb of seqnum %u\n", pdu->base.seqnum);
49372 pr_info("max seqnum %d\n",
49373 - atomic_read(&the_controller->seqnum));
49374 + atomic_read_unchecked(&the_controller->seqnum));
49375 usbip_event_add(ud, VDEV_EVENT_ERROR_TCP);
49376 return;
49377 }
49378 diff --git a/drivers/staging/vt6655/hostap.c b/drivers/staging/vt6655/hostap.c
49379 index ab8b2ba..99184aa 100644
49380 --- a/drivers/staging/vt6655/hostap.c
49381 +++ b/drivers/staging/vt6655/hostap.c
49382 @@ -69,14 +69,13 @@ static int msglevel = MSG_LEVEL_INFO;
49383 *
49384 */
49385
49386 +static net_device_ops_no_const apdev_netdev_ops;
49387 +
49388 static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
49389 {
49390 PSDevice apdev_priv;
49391 struct net_device *dev = pDevice->dev;
49392 int ret;
49393 - const struct net_device_ops apdev_netdev_ops = {
49394 - .ndo_start_xmit = pDevice->tx_80211,
49395 - };
49396
49397 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
49398
49399 @@ -88,6 +87,8 @@ static int hostap_enable_hostapd(PSDevice pDevice, int rtnl_locked)
49400 *apdev_priv = *pDevice;
49401 eth_hw_addr_inherit(pDevice->apdev, dev);
49402
49403 + /* only half broken now */
49404 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
49405 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
49406
49407 pDevice->apdev->type = ARPHRD_IEEE80211;
49408 diff --git a/drivers/staging/vt6656/hostap.c b/drivers/staging/vt6656/hostap.c
49409 index 67ba48b..24e602f 100644
49410 --- a/drivers/staging/vt6656/hostap.c
49411 +++ b/drivers/staging/vt6656/hostap.c
49412 @@ -60,14 +60,13 @@ static int msglevel =MSG_LEVEL_INFO;
49413 *
49414 */
49415
49416 +static net_device_ops_no_const apdev_netdev_ops;
49417 +
49418 static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
49419 {
49420 struct vnt_private *apdev_priv;
49421 struct net_device *dev = pDevice->dev;
49422 int ret;
49423 - const struct net_device_ops apdev_netdev_ops = {
49424 - .ndo_start_xmit = pDevice->tx_80211,
49425 - };
49426
49427 DBG_PRT(MSG_LEVEL_DEBUG, KERN_INFO "%s: Enabling hostapd mode\n", dev->name);
49428
49429 @@ -79,6 +78,8 @@ static int hostap_enable_hostapd(struct vnt_private *pDevice, int rtnl_locked)
49430 *apdev_priv = *pDevice;
49431 memcpy(pDevice->apdev->dev_addr, dev->dev_addr, ETH_ALEN);
49432
49433 + /* only half broken now */
49434 + apdev_netdev_ops.ndo_start_xmit = pDevice->tx_80211;
49435 pDevice->apdev->netdev_ops = &apdev_netdev_ops;
49436
49437 pDevice->apdev->type = ARPHRD_IEEE80211;
49438 diff --git a/drivers/target/sbp/sbp_target.c b/drivers/target/sbp/sbp_target.c
49439 index 24884ca..26c8220 100644
49440 --- a/drivers/target/sbp/sbp_target.c
49441 +++ b/drivers/target/sbp/sbp_target.c
49442 @@ -62,7 +62,7 @@ static const u32 sbp_unit_directory_template[] = {
49443
49444 #define SESSION_MAINTENANCE_INTERVAL HZ
49445
49446 -static atomic_t login_id = ATOMIC_INIT(0);
49447 +static atomic_unchecked_t login_id = ATOMIC_INIT(0);
49448
49449 static void session_maintenance_work(struct work_struct *);
49450 static int sbp_run_transaction(struct fw_card *, int, int, int, int,
49451 @@ -444,7 +444,7 @@ static void sbp_management_request_login(
49452 login->lun = se_lun;
49453 login->status_fifo_addr = sbp2_pointer_to_addr(&req->orb.status_fifo);
49454 login->exclusive = LOGIN_ORB_EXCLUSIVE(be32_to_cpu(req->orb.misc));
49455 - login->login_id = atomic_inc_return(&login_id);
49456 + login->login_id = atomic_inc_return_unchecked(&login_id);
49457
49458 login->tgt_agt = sbp_target_agent_register(login);
49459 if (IS_ERR(login->tgt_agt)) {
49460 diff --git a/drivers/target/target_core_device.c b/drivers/target/target_core_device.c
49461 index d06de84..fd38c9b 100644
49462 --- a/drivers/target/target_core_device.c
49463 +++ b/drivers/target/target_core_device.c
49464 @@ -1435,7 +1435,7 @@ struct se_device *target_alloc_device(struct se_hba *hba, const char *name)
49465 spin_lock_init(&dev->se_tmr_lock);
49466 spin_lock_init(&dev->qf_cmd_lock);
49467 sema_init(&dev->caw_sem, 1);
49468 - atomic_set(&dev->dev_ordered_id, 0);
49469 + atomic_set_unchecked(&dev->dev_ordered_id, 0);
49470 INIT_LIST_HEAD(&dev->t10_wwn.t10_vpd_list);
49471 spin_lock_init(&dev->t10_wwn.t10_vpd_lock);
49472 INIT_LIST_HEAD(&dev->t10_pr.registration_list);
49473 diff --git a/drivers/target/target_core_transport.c b/drivers/target/target_core_transport.c
49474 index dee2be1..f5fd8ca 100644
49475 --- a/drivers/target/target_core_transport.c
49476 +++ b/drivers/target/target_core_transport.c
49477 @@ -1113,7 +1113,7 @@ transport_check_alloc_task_attr(struct se_cmd *cmd)
49478 * Used to determine when ORDERED commands should go from
49479 * Dormant to Active status.
49480 */
49481 - cmd->se_ordered_id = atomic_inc_return(&dev->dev_ordered_id);
49482 + cmd->se_ordered_id = atomic_inc_return_unchecked(&dev->dev_ordered_id);
49483 smp_mb__after_atomic_inc();
49484 pr_debug("Allocated se_ordered_id: %u for Task Attr: 0x%02x on %s\n",
49485 cmd->se_ordered_id, cmd->sam_task_attr,
49486 diff --git a/drivers/tty/cyclades.c b/drivers/tty/cyclades.c
49487 index 33f83fe..d80f8e1 100644
49488 --- a/drivers/tty/cyclades.c
49489 +++ b/drivers/tty/cyclades.c
49490 @@ -1570,10 +1570,10 @@ static int cy_open(struct tty_struct *tty, struct file *filp)
49491 printk(KERN_DEBUG "cyc:cy_open ttyC%d, count = %d\n", info->line,
49492 info->port.count);
49493 #endif
49494 - info->port.count++;
49495 + atomic_inc(&info->port.count);
49496 #ifdef CY_DEBUG_COUNT
49497 printk(KERN_DEBUG "cyc:cy_open (%d): incrementing count to %d\n",
49498 - current->pid, info->port.count);
49499 + current->pid, atomic_read(&info->port.count));
49500 #endif
49501
49502 /*
49503 @@ -3972,7 +3972,7 @@ static int cyclades_proc_show(struct seq_file *m, void *v)
49504 for (j = 0; j < cy_card[i].nports; j++) {
49505 info = &cy_card[i].ports[j];
49506
49507 - if (info->port.count) {
49508 + if (atomic_read(&info->port.count)) {
49509 /* XXX is the ldisc num worth this? */
49510 struct tty_struct *tty;
49511 struct tty_ldisc *ld;
49512 diff --git a/drivers/tty/hvc/hvc_console.c b/drivers/tty/hvc/hvc_console.c
49513 index 9eba119..5070303 100644
49514 --- a/drivers/tty/hvc/hvc_console.c
49515 +++ b/drivers/tty/hvc/hvc_console.c
49516 @@ -338,7 +338,7 @@ static int hvc_open(struct tty_struct *tty, struct file * filp)
49517
49518 spin_lock_irqsave(&hp->port.lock, flags);
49519 /* Check and then increment for fast path open. */
49520 - if (hp->port.count++ > 0) {
49521 + if (atomic_inc_return(&hp->port.count) > 1) {
49522 spin_unlock_irqrestore(&hp->port.lock, flags);
49523 hvc_kick();
49524 return 0;
49525 @@ -393,7 +393,7 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
49526
49527 spin_lock_irqsave(&hp->port.lock, flags);
49528
49529 - if (--hp->port.count == 0) {
49530 + if (atomic_dec_return(&hp->port.count) == 0) {
49531 spin_unlock_irqrestore(&hp->port.lock, flags);
49532 /* We are done with the tty pointer now. */
49533 tty_port_tty_set(&hp->port, NULL);
49534 @@ -415,9 +415,9 @@ static void hvc_close(struct tty_struct *tty, struct file * filp)
49535 */
49536 tty_wait_until_sent_from_close(tty, HVC_CLOSE_WAIT);
49537 } else {
49538 - if (hp->port.count < 0)
49539 + if (atomic_read(&hp->port.count) < 0)
49540 printk(KERN_ERR "hvc_close %X: oops, count is %d\n",
49541 - hp->vtermno, hp->port.count);
49542 + hp->vtermno, atomic_read(&hp->port.count));
49543 spin_unlock_irqrestore(&hp->port.lock, flags);
49544 }
49545 }
49546 @@ -447,12 +447,12 @@ static void hvc_hangup(struct tty_struct *tty)
49547 * open->hangup case this can be called after the final close so prevent
49548 * that from happening for now.
49549 */
49550 - if (hp->port.count <= 0) {
49551 + if (atomic_read(&hp->port.count) <= 0) {
49552 spin_unlock_irqrestore(&hp->port.lock, flags);
49553 return;
49554 }
49555
49556 - hp->port.count = 0;
49557 + atomic_set(&hp->port.count, 0);
49558 spin_unlock_irqrestore(&hp->port.lock, flags);
49559 tty_port_tty_set(&hp->port, NULL);
49560
49561 @@ -500,7 +500,7 @@ static int hvc_write(struct tty_struct *tty, const unsigned char *buf, int count
49562 return -EPIPE;
49563
49564 /* FIXME what's this (unprotected) check for? */
49565 - if (hp->port.count <= 0)
49566 + if (atomic_read(&hp->port.count) <= 0)
49567 return -EIO;
49568
49569 spin_lock_irqsave(&hp->lock, flags);
49570 diff --git a/drivers/tty/hvc/hvcs.c b/drivers/tty/hvc/hvcs.c
49571 index 81e939e..95ead10 100644
49572 --- a/drivers/tty/hvc/hvcs.c
49573 +++ b/drivers/tty/hvc/hvcs.c
49574 @@ -83,6 +83,7 @@
49575 #include <asm/hvcserver.h>
49576 #include <asm/uaccess.h>
49577 #include <asm/vio.h>
49578 +#include <asm/local.h>
49579
49580 /*
49581 * 1.3.0 -> 1.3.1 In hvcs_open memset(..,0x00,..) instead of memset(..,0x3F,00).
49582 @@ -416,7 +417,7 @@ static ssize_t hvcs_vterm_state_store(struct device *dev, struct device_attribut
49583
49584 spin_lock_irqsave(&hvcsd->lock, flags);
49585
49586 - if (hvcsd->port.count > 0) {
49587 + if (atomic_read(&hvcsd->port.count) > 0) {
49588 spin_unlock_irqrestore(&hvcsd->lock, flags);
49589 printk(KERN_INFO "HVCS: vterm state unchanged. "
49590 "The hvcs device node is still in use.\n");
49591 @@ -1127,7 +1128,7 @@ static int hvcs_install(struct tty_driver *driver, struct tty_struct *tty)
49592 }
49593 }
49594
49595 - hvcsd->port.count = 0;
49596 + atomic_set(&hvcsd->port.count, 0);
49597 hvcsd->port.tty = tty;
49598 tty->driver_data = hvcsd;
49599
49600 @@ -1180,7 +1181,7 @@ static int hvcs_open(struct tty_struct *tty, struct file *filp)
49601 unsigned long flags;
49602
49603 spin_lock_irqsave(&hvcsd->lock, flags);
49604 - hvcsd->port.count++;
49605 + atomic_inc(&hvcsd->port.count);
49606 hvcsd->todo_mask |= HVCS_SCHED_READ;
49607 spin_unlock_irqrestore(&hvcsd->lock, flags);
49608
49609 @@ -1216,7 +1217,7 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
49610 hvcsd = tty->driver_data;
49611
49612 spin_lock_irqsave(&hvcsd->lock, flags);
49613 - if (--hvcsd->port.count == 0) {
49614 + if (atomic_dec_and_test(&hvcsd->port.count)) {
49615
49616 vio_disable_interrupts(hvcsd->vdev);
49617
49618 @@ -1241,10 +1242,10 @@ static void hvcs_close(struct tty_struct *tty, struct file *filp)
49619
49620 free_irq(irq, hvcsd);
49621 return;
49622 - } else if (hvcsd->port.count < 0) {
49623 + } else if (atomic_read(&hvcsd->port.count) < 0) {
49624 printk(KERN_ERR "HVCS: vty-server@%X open_count: %d"
49625 " is missmanaged.\n",
49626 - hvcsd->vdev->unit_address, hvcsd->port.count);
49627 + hvcsd->vdev->unit_address, atomic_read(&hvcsd->port.count));
49628 }
49629
49630 spin_unlock_irqrestore(&hvcsd->lock, flags);
49631 @@ -1266,7 +1267,7 @@ static void hvcs_hangup(struct tty_struct * tty)
49632
49633 spin_lock_irqsave(&hvcsd->lock, flags);
49634 /* Preserve this so that we know how many kref refs to put */
49635 - temp_open_count = hvcsd->port.count;
49636 + temp_open_count = atomic_read(&hvcsd->port.count);
49637
49638 /*
49639 * Don't kref put inside the spinlock because the destruction
49640 @@ -1281,7 +1282,7 @@ static void hvcs_hangup(struct tty_struct * tty)
49641 tty->driver_data = NULL;
49642 hvcsd->port.tty = NULL;
49643
49644 - hvcsd->port.count = 0;
49645 + atomic_set(&hvcsd->port.count, 0);
49646
49647 /* This will drop any buffered data on the floor which is OK in a hangup
49648 * scenario. */
49649 @@ -1352,7 +1353,7 @@ static int hvcs_write(struct tty_struct *tty,
49650 * the middle of a write operation? This is a crummy place to do this
49651 * but we want to keep it all in the spinlock.
49652 */
49653 - if (hvcsd->port.count <= 0) {
49654 + if (atomic_read(&hvcsd->port.count) <= 0) {
49655 spin_unlock_irqrestore(&hvcsd->lock, flags);
49656 return -ENODEV;
49657 }
49658 @@ -1426,7 +1427,7 @@ static int hvcs_write_room(struct tty_struct *tty)
49659 {
49660 struct hvcs_struct *hvcsd = tty->driver_data;
49661
49662 - if (!hvcsd || hvcsd->port.count <= 0)
49663 + if (!hvcsd || atomic_read(&hvcsd->port.count) <= 0)
49664 return 0;
49665
49666 return HVCS_BUFF_LEN - hvcsd->chars_in_buffer;
49667 diff --git a/drivers/tty/hvc/hvsi.c b/drivers/tty/hvc/hvsi.c
49668 index 4190199..48f2920 100644
49669 --- a/drivers/tty/hvc/hvsi.c
49670 +++ b/drivers/tty/hvc/hvsi.c
49671 @@ -85,7 +85,7 @@ struct hvsi_struct {
49672 int n_outbuf;
49673 uint32_t vtermno;
49674 uint32_t virq;
49675 - atomic_t seqno; /* HVSI packet sequence number */
49676 + atomic_unchecked_t seqno; /* HVSI packet sequence number */
49677 uint16_t mctrl;
49678 uint8_t state; /* HVSI protocol state */
49679 uint8_t flags;
49680 @@ -295,7 +295,7 @@ static int hvsi_version_respond(struct hvsi_struct *hp, uint16_t query_seqno)
49681
49682 packet.hdr.type = VS_QUERY_RESPONSE_PACKET_HEADER;
49683 packet.hdr.len = sizeof(struct hvsi_query_response);
49684 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49685 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49686 packet.verb = VSV_SEND_VERSION_NUMBER;
49687 packet.u.version = HVSI_VERSION;
49688 packet.query_seqno = query_seqno+1;
49689 @@ -555,7 +555,7 @@ static int hvsi_query(struct hvsi_struct *hp, uint16_t verb)
49690
49691 packet.hdr.type = VS_QUERY_PACKET_HEADER;
49692 packet.hdr.len = sizeof(struct hvsi_query);
49693 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49694 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49695 packet.verb = verb;
49696
49697 pr_debug("%s: sending %i bytes\n", __func__, packet.hdr.len);
49698 @@ -597,7 +597,7 @@ static int hvsi_set_mctrl(struct hvsi_struct *hp, uint16_t mctrl)
49699 int wrote;
49700
49701 packet.hdr.type = VS_CONTROL_PACKET_HEADER,
49702 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49703 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49704 packet.hdr.len = sizeof(struct hvsi_control);
49705 packet.verb = VSV_SET_MODEM_CTL;
49706 packet.mask = HVSI_TSDTR;
49707 @@ -680,7 +680,7 @@ static int hvsi_put_chars(struct hvsi_struct *hp, const char *buf, int count)
49708 BUG_ON(count > HVSI_MAX_OUTGOING_DATA);
49709
49710 packet.hdr.type = VS_DATA_PACKET_HEADER;
49711 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49712 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49713 packet.hdr.len = count + sizeof(struct hvsi_header);
49714 memcpy(&packet.data, buf, count);
49715
49716 @@ -697,7 +697,7 @@ static void hvsi_close_protocol(struct hvsi_struct *hp)
49717 struct hvsi_control packet __ALIGNED__;
49718
49719 packet.hdr.type = VS_CONTROL_PACKET_HEADER;
49720 - packet.hdr.seqno = atomic_inc_return(&hp->seqno);
49721 + packet.hdr.seqno = atomic_inc_return_unchecked(&hp->seqno);
49722 packet.hdr.len = 6;
49723 packet.verb = VSV_CLOSE_PROTOCOL;
49724
49725 diff --git a/drivers/tty/hvc/hvsi_lib.c b/drivers/tty/hvc/hvsi_lib.c
49726 index 347050e..14f8fbf 100644
49727 --- a/drivers/tty/hvc/hvsi_lib.c
49728 +++ b/drivers/tty/hvc/hvsi_lib.c
49729 @@ -9,7 +9,7 @@
49730
49731 static int hvsi_send_packet(struct hvsi_priv *pv, struct hvsi_header *packet)
49732 {
49733 - packet->seqno = cpu_to_be16(atomic_inc_return(&pv->seqno));
49734 + packet->seqno = cpu_to_be16(atomic_inc_return_unchecked(&pv->seqno));
49735
49736 /* Assumes that always succeeds, works in practice */
49737 return pv->put_chars(pv->termno, (char *)packet, packet->len);
49738 @@ -21,7 +21,7 @@ static void hvsi_start_handshake(struct hvsi_priv *pv)
49739
49740 /* Reset state */
49741 pv->established = 0;
49742 - atomic_set(&pv->seqno, 0);
49743 + atomic_set_unchecked(&pv->seqno, 0);
49744
49745 pr_devel("HVSI@%x: Handshaking started\n", pv->termno);
49746
49747 diff --git a/drivers/tty/ipwireless/tty.c b/drivers/tty/ipwireless/tty.c
49748 index 8fd72ff..34a0bed 100644
49749 --- a/drivers/tty/ipwireless/tty.c
49750 +++ b/drivers/tty/ipwireless/tty.c
49751 @@ -29,6 +29,7 @@
49752 #include <linux/tty_driver.h>
49753 #include <linux/tty_flip.h>
49754 #include <linux/uaccess.h>
49755 +#include <asm/local.h>
49756
49757 #include "tty.h"
49758 #include "network.h"
49759 @@ -99,10 +100,10 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
49760 mutex_unlock(&tty->ipw_tty_mutex);
49761 return -ENODEV;
49762 }
49763 - if (tty->port.count == 0)
49764 + if (atomic_read(&tty->port.count) == 0)
49765 tty->tx_bytes_queued = 0;
49766
49767 - tty->port.count++;
49768 + atomic_inc(&tty->port.count);
49769
49770 tty->port.tty = linux_tty;
49771 linux_tty->driver_data = tty;
49772 @@ -118,9 +119,7 @@ static int ipw_open(struct tty_struct *linux_tty, struct file *filp)
49773
49774 static void do_ipw_close(struct ipw_tty *tty)
49775 {
49776 - tty->port.count--;
49777 -
49778 - if (tty->port.count == 0) {
49779 + if (atomic_dec_return(&tty->port.count) == 0) {
49780 struct tty_struct *linux_tty = tty->port.tty;
49781
49782 if (linux_tty != NULL) {
49783 @@ -141,7 +140,7 @@ static void ipw_hangup(struct tty_struct *linux_tty)
49784 return;
49785
49786 mutex_lock(&tty->ipw_tty_mutex);
49787 - if (tty->port.count == 0) {
49788 + if (atomic_read(&tty->port.count) == 0) {
49789 mutex_unlock(&tty->ipw_tty_mutex);
49790 return;
49791 }
49792 @@ -164,7 +163,7 @@ void ipwireless_tty_received(struct ipw_tty *tty, unsigned char *data,
49793
49794 mutex_lock(&tty->ipw_tty_mutex);
49795
49796 - if (!tty->port.count) {
49797 + if (!atomic_read(&tty->port.count)) {
49798 mutex_unlock(&tty->ipw_tty_mutex);
49799 return;
49800 }
49801 @@ -206,7 +205,7 @@ static int ipw_write(struct tty_struct *linux_tty,
49802 return -ENODEV;
49803
49804 mutex_lock(&tty->ipw_tty_mutex);
49805 - if (!tty->port.count) {
49806 + if (!atomic_read(&tty->port.count)) {
49807 mutex_unlock(&tty->ipw_tty_mutex);
49808 return -EINVAL;
49809 }
49810 @@ -246,7 +245,7 @@ static int ipw_write_room(struct tty_struct *linux_tty)
49811 if (!tty)
49812 return -ENODEV;
49813
49814 - if (!tty->port.count)
49815 + if (!atomic_read(&tty->port.count))
49816 return -EINVAL;
49817
49818 room = IPWIRELESS_TX_QUEUE_SIZE - tty->tx_bytes_queued;
49819 @@ -288,7 +287,7 @@ static int ipw_chars_in_buffer(struct tty_struct *linux_tty)
49820 if (!tty)
49821 return 0;
49822
49823 - if (!tty->port.count)
49824 + if (!atomic_read(&tty->port.count))
49825 return 0;
49826
49827 return tty->tx_bytes_queued;
49828 @@ -369,7 +368,7 @@ static int ipw_tiocmget(struct tty_struct *linux_tty)
49829 if (!tty)
49830 return -ENODEV;
49831
49832 - if (!tty->port.count)
49833 + if (!atomic_read(&tty->port.count))
49834 return -EINVAL;
49835
49836 return get_control_lines(tty);
49837 @@ -385,7 +384,7 @@ ipw_tiocmset(struct tty_struct *linux_tty,
49838 if (!tty)
49839 return -ENODEV;
49840
49841 - if (!tty->port.count)
49842 + if (!atomic_read(&tty->port.count))
49843 return -EINVAL;
49844
49845 return set_control_lines(tty, set, clear);
49846 @@ -399,7 +398,7 @@ static int ipw_ioctl(struct tty_struct *linux_tty,
49847 if (!tty)
49848 return -ENODEV;
49849
49850 - if (!tty->port.count)
49851 + if (!atomic_read(&tty->port.count))
49852 return -EINVAL;
49853
49854 /* FIXME: Exactly how is the tty object locked here .. */
49855 @@ -555,7 +554,7 @@ void ipwireless_tty_free(struct ipw_tty *tty)
49856 * are gone */
49857 mutex_lock(&ttyj->ipw_tty_mutex);
49858 }
49859 - while (ttyj->port.count)
49860 + while (atomic_read(&ttyj->port.count))
49861 do_ipw_close(ttyj);
49862 ipwireless_disassociate_network_ttys(network,
49863 ttyj->channel_idx);
49864 diff --git a/drivers/tty/moxa.c b/drivers/tty/moxa.c
49865 index 1deaca4..c8582d4 100644
49866 --- a/drivers/tty/moxa.c
49867 +++ b/drivers/tty/moxa.c
49868 @@ -1189,7 +1189,7 @@ static int moxa_open(struct tty_struct *tty, struct file *filp)
49869 }
49870
49871 ch = &brd->ports[port % MAX_PORTS_PER_BOARD];
49872 - ch->port.count++;
49873 + atomic_inc(&ch->port.count);
49874 tty->driver_data = ch;
49875 tty_port_tty_set(&ch->port, tty);
49876 mutex_lock(&ch->port.mutex);
49877 diff --git a/drivers/tty/n_gsm.c b/drivers/tty/n_gsm.c
49878 index c0f76da..d974c32 100644
49879 --- a/drivers/tty/n_gsm.c
49880 +++ b/drivers/tty/n_gsm.c
49881 @@ -1632,7 +1632,7 @@ static struct gsm_dlci *gsm_dlci_alloc(struct gsm_mux *gsm, int addr)
49882 spin_lock_init(&dlci->lock);
49883 mutex_init(&dlci->mutex);
49884 dlci->fifo = &dlci->_fifo;
49885 - if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL) < 0) {
49886 + if (kfifo_alloc(&dlci->_fifo, 4096, GFP_KERNEL)) {
49887 kfree(dlci);
49888 return NULL;
49889 }
49890 @@ -2935,7 +2935,7 @@ static int gsmtty_open(struct tty_struct *tty, struct file *filp)
49891 struct gsm_dlci *dlci = tty->driver_data;
49892 struct tty_port *port = &dlci->port;
49893
49894 - port->count++;
49895 + atomic_inc(&port->count);
49896 dlci_get(dlci);
49897 dlci_get(dlci->gsm->dlci[0]);
49898 mux_get(dlci->gsm);
49899 diff --git a/drivers/tty/n_tty.c b/drivers/tty/n_tty.c
49900 index 34aacaa..dad073b 100644
49901 --- a/drivers/tty/n_tty.c
49902 +++ b/drivers/tty/n_tty.c
49903 @@ -114,7 +114,7 @@ struct n_tty_data {
49904 int minimum_to_wake;
49905
49906 /* consumer-published */
49907 - size_t read_tail;
49908 + size_t read_tail __intentional_overflow(-1);
49909 size_t line_start;
49910
49911 /* protected by output lock */
49912 @@ -2502,6 +2502,7 @@ void n_tty_inherit_ops(struct tty_ldisc_ops *ops)
49913 {
49914 *ops = tty_ldisc_N_TTY;
49915 ops->owner = NULL;
49916 - ops->refcount = ops->flags = 0;
49917 + atomic_set(&ops->refcount, 0);
49918 + ops->flags = 0;
49919 }
49920 EXPORT_SYMBOL_GPL(n_tty_inherit_ops);
49921 diff --git a/drivers/tty/pty.c b/drivers/tty/pty.c
49922 index 25c9bc7..24077b7 100644
49923 --- a/drivers/tty/pty.c
49924 +++ b/drivers/tty/pty.c
49925 @@ -790,8 +790,10 @@ static void __init unix98_pty_init(void)
49926 panic("Couldn't register Unix98 pts driver");
49927
49928 /* Now create the /dev/ptmx special device */
49929 + pax_open_kernel();
49930 tty_default_fops(&ptmx_fops);
49931 - ptmx_fops.open = ptmx_open;
49932 + *(void **)&ptmx_fops.open = ptmx_open;
49933 + pax_close_kernel();
49934
49935 cdev_init(&ptmx_cdev, &ptmx_fops);
49936 if (cdev_add(&ptmx_cdev, MKDEV(TTYAUX_MAJOR, 2), 1) ||
49937 diff --git a/drivers/tty/rocket.c b/drivers/tty/rocket.c
49938 index 354564e..fe50d9a 100644
49939 --- a/drivers/tty/rocket.c
49940 +++ b/drivers/tty/rocket.c
49941 @@ -914,7 +914,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
49942 tty->driver_data = info;
49943 tty_port_tty_set(port, tty);
49944
49945 - if (port->count++ == 0) {
49946 + if (atomic_inc_return(&port->count) == 1) {
49947 atomic_inc(&rp_num_ports_open);
49948
49949 #ifdef ROCKET_DEBUG_OPEN
49950 @@ -923,7 +923,7 @@ static int rp_open(struct tty_struct *tty, struct file *filp)
49951 #endif
49952 }
49953 #ifdef ROCKET_DEBUG_OPEN
49954 - printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, info->port.count);
49955 + printk(KERN_INFO "rp_open ttyR%d, count=%d\n", info->line, atomic-read(&info->port.count));
49956 #endif
49957
49958 /*
49959 @@ -1515,7 +1515,7 @@ static void rp_hangup(struct tty_struct *tty)
49960 spin_unlock_irqrestore(&info->port.lock, flags);
49961 return;
49962 }
49963 - if (info->port.count)
49964 + if (atomic_read(&info->port.count))
49965 atomic_dec(&rp_num_ports_open);
49966 clear_bit((info->aiop * 8) + info->chan, (void *) &xmit_flags[info->board]);
49967 spin_unlock_irqrestore(&info->port.lock, flags);
49968 diff --git a/drivers/tty/serial/ioc4_serial.c b/drivers/tty/serial/ioc4_serial.c
49969 index 1274499..f541382 100644
49970 --- a/drivers/tty/serial/ioc4_serial.c
49971 +++ b/drivers/tty/serial/ioc4_serial.c
49972 @@ -437,7 +437,7 @@ struct ioc4_soft {
49973 } is_intr_info[MAX_IOC4_INTR_ENTS];
49974
49975 /* Number of entries active in the above array */
49976 - atomic_t is_num_intrs;
49977 + atomic_unchecked_t is_num_intrs;
49978 } is_intr_type[IOC4_NUM_INTR_TYPES];
49979
49980 /* is_ir_lock must be held while
49981 @@ -974,7 +974,7 @@ intr_connect(struct ioc4_soft *soft, int type,
49982 BUG_ON(!((type == IOC4_SIO_INTR_TYPE)
49983 || (type == IOC4_OTHER_INTR_TYPE)));
49984
49985 - i = atomic_inc_return(&soft-> is_intr_type[type].is_num_intrs) - 1;
49986 + i = atomic_inc_return_unchecked(&soft-> is_intr_type[type].is_num_intrs) - 1;
49987 BUG_ON(!(i < MAX_IOC4_INTR_ENTS || (printk("i %d\n", i), 0)));
49988
49989 /* Save off the lower level interrupt handler */
49990 @@ -1001,7 +1001,7 @@ static irqreturn_t ioc4_intr(int irq, void *arg)
49991
49992 soft = arg;
49993 for (intr_type = 0; intr_type < IOC4_NUM_INTR_TYPES; intr_type++) {
49994 - num_intrs = (int)atomic_read(
49995 + num_intrs = (int)atomic_read_unchecked(
49996 &soft->is_intr_type[intr_type].is_num_intrs);
49997
49998 this_mir = this_ir = pending_intrs(soft, intr_type);
49999 diff --git a/drivers/tty/serial/kgdboc.c b/drivers/tty/serial/kgdboc.c
50000 index a260cde..6b2b5ce 100644
50001 --- a/drivers/tty/serial/kgdboc.c
50002 +++ b/drivers/tty/serial/kgdboc.c
50003 @@ -24,8 +24,9 @@
50004 #define MAX_CONFIG_LEN 40
50005
50006 static struct kgdb_io kgdboc_io_ops;
50007 +static struct kgdb_io kgdboc_io_ops_console;
50008
50009 -/* -1 = init not run yet, 0 = unconfigured, 1 = configured. */
50010 +/* -1 = init not run yet, 0 = unconfigured, 1/2 = configured. */
50011 static int configured = -1;
50012
50013 static char config[MAX_CONFIG_LEN];
50014 @@ -151,6 +152,8 @@ static void cleanup_kgdboc(void)
50015 kgdboc_unregister_kbd();
50016 if (configured == 1)
50017 kgdb_unregister_io_module(&kgdboc_io_ops);
50018 + else if (configured == 2)
50019 + kgdb_unregister_io_module(&kgdboc_io_ops_console);
50020 }
50021
50022 static int configure_kgdboc(void)
50023 @@ -160,13 +163,13 @@ static int configure_kgdboc(void)
50024 int err;
50025 char *cptr = config;
50026 struct console *cons;
50027 + int is_console = 0;
50028
50029 err = kgdboc_option_setup(config);
50030 if (err || !strlen(config) || isspace(config[0]))
50031 goto noconfig;
50032
50033 err = -ENODEV;
50034 - kgdboc_io_ops.is_console = 0;
50035 kgdb_tty_driver = NULL;
50036
50037 kgdboc_use_kms = 0;
50038 @@ -187,7 +190,7 @@ static int configure_kgdboc(void)
50039 int idx;
50040 if (cons->device && cons->device(cons, &idx) == p &&
50041 idx == tty_line) {
50042 - kgdboc_io_ops.is_console = 1;
50043 + is_console = 1;
50044 break;
50045 }
50046 cons = cons->next;
50047 @@ -197,7 +200,13 @@ static int configure_kgdboc(void)
50048 kgdb_tty_line = tty_line;
50049
50050 do_register:
50051 - err = kgdb_register_io_module(&kgdboc_io_ops);
50052 + if (is_console) {
50053 + err = kgdb_register_io_module(&kgdboc_io_ops_console);
50054 + configured = 2;
50055 + } else {
50056 + err = kgdb_register_io_module(&kgdboc_io_ops);
50057 + configured = 1;
50058 + }
50059 if (err)
50060 goto noconfig;
50061
50062 @@ -205,8 +214,6 @@ do_register:
50063 if (err)
50064 goto nmi_con_failed;
50065
50066 - configured = 1;
50067 -
50068 return 0;
50069
50070 nmi_con_failed:
50071 @@ -223,7 +230,7 @@ noconfig:
50072 static int __init init_kgdboc(void)
50073 {
50074 /* Already configured? */
50075 - if (configured == 1)
50076 + if (configured >= 1)
50077 return 0;
50078
50079 return configure_kgdboc();
50080 @@ -272,7 +279,7 @@ static int param_set_kgdboc_var(const char *kmessage, struct kernel_param *kp)
50081 if (config[len - 1] == '\n')
50082 config[len - 1] = '\0';
50083
50084 - if (configured == 1)
50085 + if (configured >= 1)
50086 cleanup_kgdboc();
50087
50088 /* Go and configure with the new params. */
50089 @@ -312,6 +319,15 @@ static struct kgdb_io kgdboc_io_ops = {
50090 .post_exception = kgdboc_post_exp_handler,
50091 };
50092
50093 +static struct kgdb_io kgdboc_io_ops_console = {
50094 + .name = "kgdboc",
50095 + .read_char = kgdboc_get_char,
50096 + .write_char = kgdboc_put_char,
50097 + .pre_exception = kgdboc_pre_exp_handler,
50098 + .post_exception = kgdboc_post_exp_handler,
50099 + .is_console = 1
50100 +};
50101 +
50102 #ifdef CONFIG_KGDB_SERIAL_CONSOLE
50103 /* This is only available if kgdboc is a built in for early debugging */
50104 static int __init kgdboc_early_init(char *opt)
50105 diff --git a/drivers/tty/serial/msm_serial.c b/drivers/tty/serial/msm_serial.c
50106 index b5d779c..3622cfe 100644
50107 --- a/drivers/tty/serial/msm_serial.c
50108 +++ b/drivers/tty/serial/msm_serial.c
50109 @@ -897,7 +897,7 @@ static struct uart_driver msm_uart_driver = {
50110 .cons = MSM_CONSOLE,
50111 };
50112
50113 -static atomic_t msm_uart_next_id = ATOMIC_INIT(0);
50114 +static atomic_unchecked_t msm_uart_next_id = ATOMIC_INIT(0);
50115
50116 static const struct of_device_id msm_uartdm_table[] = {
50117 { .compatible = "qcom,msm-uartdm" },
50118 @@ -912,7 +912,7 @@ static int __init msm_serial_probe(struct platform_device *pdev)
50119 int irq;
50120
50121 if (pdev->id == -1)
50122 - pdev->id = atomic_inc_return(&msm_uart_next_id) - 1;
50123 + pdev->id = atomic_inc_return_unchecked(&msm_uart_next_id) - 1;
50124
50125 if (unlikely(pdev->id < 0 || pdev->id >= UART_NR))
50126 return -ENXIO;
50127 diff --git a/drivers/tty/serial/samsung.c b/drivers/tty/serial/samsung.c
50128 index c1af04d..0815c8a 100644
50129 --- a/drivers/tty/serial/samsung.c
50130 +++ b/drivers/tty/serial/samsung.c
50131 @@ -463,11 +463,16 @@ static void s3c24xx_serial_shutdown(struct uart_port *port)
50132 }
50133 }
50134
50135 +static int s3c64xx_serial_startup(struct uart_port *port);
50136 static int s3c24xx_serial_startup(struct uart_port *port)
50137 {
50138 struct s3c24xx_uart_port *ourport = to_ourport(port);
50139 int ret;
50140
50141 + /* Startup sequence is different for s3c64xx and higher SoC's */
50142 + if (s3c24xx_serial_has_interrupt_mask(port))
50143 + return s3c64xx_serial_startup(port);
50144 +
50145 dbg("s3c24xx_serial_startup: port=%p (%08lx,%p)\n",
50146 port->mapbase, port->membase);
50147
50148 @@ -1141,10 +1146,6 @@ static int s3c24xx_serial_init_port(struct s3c24xx_uart_port *ourport,
50149 /* setup info for port */
50150 port->dev = &platdev->dev;
50151
50152 - /* Startup sequence is different for s3c64xx and higher SoC's */
50153 - if (s3c24xx_serial_has_interrupt_mask(port))
50154 - s3c24xx_serial_ops.startup = s3c64xx_serial_startup;
50155 -
50156 port->uartclk = 1;
50157
50158 if (cfg->uart_flags & UPF_CONS_FLOW) {
50159 diff --git a/drivers/tty/serial/serial_core.c b/drivers/tty/serial/serial_core.c
50160 index 0f02351..07c59c5 100644
50161 --- a/drivers/tty/serial/serial_core.c
50162 +++ b/drivers/tty/serial/serial_core.c
50163 @@ -1448,7 +1448,7 @@ static void uart_hangup(struct tty_struct *tty)
50164 uart_flush_buffer(tty);
50165 uart_shutdown(tty, state);
50166 spin_lock_irqsave(&port->lock, flags);
50167 - port->count = 0;
50168 + atomic_set(&port->count, 0);
50169 clear_bit(ASYNCB_NORMAL_ACTIVE, &port->flags);
50170 spin_unlock_irqrestore(&port->lock, flags);
50171 tty_port_tty_set(port, NULL);
50172 @@ -1544,7 +1544,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50173 goto end;
50174 }
50175
50176 - port->count++;
50177 + atomic_inc(&port->count);
50178 if (!state->uart_port || state->uart_port->flags & UPF_DEAD) {
50179 retval = -ENXIO;
50180 goto err_dec_count;
50181 @@ -1572,7 +1572,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50182 /*
50183 * Make sure the device is in D0 state.
50184 */
50185 - if (port->count == 1)
50186 + if (atomic_read(&port->count) == 1)
50187 uart_change_pm(state, UART_PM_STATE_ON);
50188
50189 /*
50190 @@ -1590,7 +1590,7 @@ static int uart_open(struct tty_struct *tty, struct file *filp)
50191 end:
50192 return retval;
50193 err_dec_count:
50194 - port->count--;
50195 + atomic_inc(&port->count);
50196 mutex_unlock(&port->mutex);
50197 goto end;
50198 }
50199 diff --git a/drivers/tty/synclink.c b/drivers/tty/synclink.c
50200 index e1ce141..6d4ed80 100644
50201 --- a/drivers/tty/synclink.c
50202 +++ b/drivers/tty/synclink.c
50203 @@ -3090,7 +3090,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
50204
50205 if (debug_level >= DEBUG_LEVEL_INFO)
50206 printk("%s(%d):mgsl_close(%s) entry, count=%d\n",
50207 - __FILE__,__LINE__, info->device_name, info->port.count);
50208 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
50209
50210 if (tty_port_close_start(&info->port, tty, filp) == 0)
50211 goto cleanup;
50212 @@ -3108,7 +3108,7 @@ static void mgsl_close(struct tty_struct *tty, struct file * filp)
50213 cleanup:
50214 if (debug_level >= DEBUG_LEVEL_INFO)
50215 printk("%s(%d):mgsl_close(%s) exit, count=%d\n", __FILE__,__LINE__,
50216 - tty->driver->name, info->port.count);
50217 + tty->driver->name, atomic_read(&info->port.count));
50218
50219 } /* end of mgsl_close() */
50220
50221 @@ -3207,8 +3207,8 @@ static void mgsl_hangup(struct tty_struct *tty)
50222
50223 mgsl_flush_buffer(tty);
50224 shutdown(info);
50225 -
50226 - info->port.count = 0;
50227 +
50228 + atomic_set(&info->port.count, 0);
50229 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
50230 info->port.tty = NULL;
50231
50232 @@ -3297,12 +3297,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50233
50234 if (debug_level >= DEBUG_LEVEL_INFO)
50235 printk("%s(%d):block_til_ready before block on %s count=%d\n",
50236 - __FILE__,__LINE__, tty->driver->name, port->count );
50237 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50238
50239 spin_lock_irqsave(&info->irq_spinlock, flags);
50240 if (!tty_hung_up_p(filp)) {
50241 extra_count = true;
50242 - port->count--;
50243 + atomic_dec(&port->count);
50244 }
50245 spin_unlock_irqrestore(&info->irq_spinlock, flags);
50246 port->blocked_open++;
50247 @@ -3331,7 +3331,7 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50248
50249 if (debug_level >= DEBUG_LEVEL_INFO)
50250 printk("%s(%d):block_til_ready blocking on %s count=%d\n",
50251 - __FILE__,__LINE__, tty->driver->name, port->count );
50252 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50253
50254 tty_unlock(tty);
50255 schedule();
50256 @@ -3343,12 +3343,12 @@ static int block_til_ready(struct tty_struct *tty, struct file * filp,
50257
50258 /* FIXME: Racy on hangup during close wait */
50259 if (extra_count)
50260 - port->count++;
50261 + atomic_inc(&port->count);
50262 port->blocked_open--;
50263
50264 if (debug_level >= DEBUG_LEVEL_INFO)
50265 printk("%s(%d):block_til_ready after blocking on %s count=%d\n",
50266 - __FILE__,__LINE__, tty->driver->name, port->count );
50267 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50268
50269 if (!retval)
50270 port->flags |= ASYNC_NORMAL_ACTIVE;
50271 @@ -3400,7 +3400,7 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
50272
50273 if (debug_level >= DEBUG_LEVEL_INFO)
50274 printk("%s(%d):mgsl_open(%s), old ref count = %d\n",
50275 - __FILE__,__LINE__,tty->driver->name, info->port.count);
50276 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
50277
50278 /* If port is closing, signal caller to try again */
50279 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
50280 @@ -3419,10 +3419,10 @@ static int mgsl_open(struct tty_struct *tty, struct file * filp)
50281 spin_unlock_irqrestore(&info->netlock, flags);
50282 goto cleanup;
50283 }
50284 - info->port.count++;
50285 + atomic_inc(&info->port.count);
50286 spin_unlock_irqrestore(&info->netlock, flags);
50287
50288 - if (info->port.count == 1) {
50289 + if (atomic_read(&info->port.count) == 1) {
50290 /* 1st open on this device, init hardware */
50291 retval = startup(info);
50292 if (retval < 0)
50293 @@ -3446,8 +3446,8 @@ cleanup:
50294 if (retval) {
50295 if (tty->count == 1)
50296 info->port.tty = NULL; /* tty layer will release tty struct */
50297 - if(info->port.count)
50298 - info->port.count--;
50299 + if (atomic_read(&info->port.count))
50300 + atomic_dec(&info->port.count);
50301 }
50302
50303 return retval;
50304 @@ -7665,7 +7665,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
50305 unsigned short new_crctype;
50306
50307 /* return error if TTY interface open */
50308 - if (info->port.count)
50309 + if (atomic_read(&info->port.count))
50310 return -EBUSY;
50311
50312 switch (encoding)
50313 @@ -7760,7 +7760,7 @@ static int hdlcdev_open(struct net_device *dev)
50314
50315 /* arbitrate between network and tty opens */
50316 spin_lock_irqsave(&info->netlock, flags);
50317 - if (info->port.count != 0 || info->netcount != 0) {
50318 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
50319 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
50320 spin_unlock_irqrestore(&info->netlock, flags);
50321 return -EBUSY;
50322 @@ -7846,7 +7846,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50323 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
50324
50325 /* return error if TTY interface open */
50326 - if (info->port.count)
50327 + if (atomic_read(&info->port.count))
50328 return -EBUSY;
50329
50330 if (cmd != SIOCWANDEV)
50331 diff --git a/drivers/tty/synclink_gt.c b/drivers/tty/synclink_gt.c
50332 index 1abf946..1ee34fc 100644
50333 --- a/drivers/tty/synclink_gt.c
50334 +++ b/drivers/tty/synclink_gt.c
50335 @@ -670,7 +670,7 @@ static int open(struct tty_struct *tty, struct file *filp)
50336 tty->driver_data = info;
50337 info->port.tty = tty;
50338
50339 - DBGINFO(("%s open, old ref count = %d\n", info->device_name, info->port.count));
50340 + DBGINFO(("%s open, old ref count = %d\n", info->device_name, atomic_read(&info->port.count)));
50341
50342 /* If port is closing, signal caller to try again */
50343 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
50344 @@ -691,10 +691,10 @@ static int open(struct tty_struct *tty, struct file *filp)
50345 mutex_unlock(&info->port.mutex);
50346 goto cleanup;
50347 }
50348 - info->port.count++;
50349 + atomic_inc(&info->port.count);
50350 spin_unlock_irqrestore(&info->netlock, flags);
50351
50352 - if (info->port.count == 1) {
50353 + if (atomic_read(&info->port.count) == 1) {
50354 /* 1st open on this device, init hardware */
50355 retval = startup(info);
50356 if (retval < 0) {
50357 @@ -715,8 +715,8 @@ cleanup:
50358 if (retval) {
50359 if (tty->count == 1)
50360 info->port.tty = NULL; /* tty layer will release tty struct */
50361 - if(info->port.count)
50362 - info->port.count--;
50363 + if(atomic_read(&info->port.count))
50364 + atomic_dec(&info->port.count);
50365 }
50366
50367 DBGINFO(("%s open rc=%d\n", info->device_name, retval));
50368 @@ -729,7 +729,7 @@ static void close(struct tty_struct *tty, struct file *filp)
50369
50370 if (sanity_check(info, tty->name, "close"))
50371 return;
50372 - DBGINFO(("%s close entry, count=%d\n", info->device_name, info->port.count));
50373 + DBGINFO(("%s close entry, count=%d\n", info->device_name, atomic_read(&info->port.count)));
50374
50375 if (tty_port_close_start(&info->port, tty, filp) == 0)
50376 goto cleanup;
50377 @@ -746,7 +746,7 @@ static void close(struct tty_struct *tty, struct file *filp)
50378 tty_port_close_end(&info->port, tty);
50379 info->port.tty = NULL;
50380 cleanup:
50381 - DBGINFO(("%s close exit, count=%d\n", tty->driver->name, info->port.count));
50382 + DBGINFO(("%s close exit, count=%d\n", tty->driver->name, atomic_read(&info->port.count)));
50383 }
50384
50385 static void hangup(struct tty_struct *tty)
50386 @@ -764,7 +764,7 @@ static void hangup(struct tty_struct *tty)
50387 shutdown(info);
50388
50389 spin_lock_irqsave(&info->port.lock, flags);
50390 - info->port.count = 0;
50391 + atomic_set(&info->port.count, 0);
50392 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
50393 info->port.tty = NULL;
50394 spin_unlock_irqrestore(&info->port.lock, flags);
50395 @@ -1449,7 +1449,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
50396 unsigned short new_crctype;
50397
50398 /* return error if TTY interface open */
50399 - if (info->port.count)
50400 + if (atomic_read(&info->port.count))
50401 return -EBUSY;
50402
50403 DBGINFO(("%s hdlcdev_attach\n", info->device_name));
50404 @@ -1544,7 +1544,7 @@ static int hdlcdev_open(struct net_device *dev)
50405
50406 /* arbitrate between network and tty opens */
50407 spin_lock_irqsave(&info->netlock, flags);
50408 - if (info->port.count != 0 || info->netcount != 0) {
50409 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
50410 DBGINFO(("%s hdlc_open busy\n", dev->name));
50411 spin_unlock_irqrestore(&info->netlock, flags);
50412 return -EBUSY;
50413 @@ -1629,7 +1629,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50414 DBGINFO(("%s hdlcdev_ioctl\n", dev->name));
50415
50416 /* return error if TTY interface open */
50417 - if (info->port.count)
50418 + if (atomic_read(&info->port.count))
50419 return -EBUSY;
50420
50421 if (cmd != SIOCWANDEV)
50422 @@ -2413,7 +2413,7 @@ static irqreturn_t slgt_interrupt(int dummy, void *dev_id)
50423 if (port == NULL)
50424 continue;
50425 spin_lock(&port->lock);
50426 - if ((port->port.count || port->netcount) &&
50427 + if ((atomic_read(&port->port.count) || port->netcount) &&
50428 port->pending_bh && !port->bh_running &&
50429 !port->bh_requested) {
50430 DBGISR(("%s bh queued\n", port->device_name));
50431 @@ -3302,7 +3302,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50432 spin_lock_irqsave(&info->lock, flags);
50433 if (!tty_hung_up_p(filp)) {
50434 extra_count = true;
50435 - port->count--;
50436 + atomic_dec(&port->count);
50437 }
50438 spin_unlock_irqrestore(&info->lock, flags);
50439 port->blocked_open++;
50440 @@ -3339,7 +3339,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50441 remove_wait_queue(&port->open_wait, &wait);
50442
50443 if (extra_count)
50444 - port->count++;
50445 + atomic_inc(&port->count);
50446 port->blocked_open--;
50447
50448 if (!retval)
50449 diff --git a/drivers/tty/synclinkmp.c b/drivers/tty/synclinkmp.c
50450 index dc6e969..5dc8786 100644
50451 --- a/drivers/tty/synclinkmp.c
50452 +++ b/drivers/tty/synclinkmp.c
50453 @@ -750,7 +750,7 @@ static int open(struct tty_struct *tty, struct file *filp)
50454
50455 if (debug_level >= DEBUG_LEVEL_INFO)
50456 printk("%s(%d):%s open(), old ref count = %d\n",
50457 - __FILE__,__LINE__,tty->driver->name, info->port.count);
50458 + __FILE__,__LINE__,tty->driver->name, atomic_read(&info->port.count));
50459
50460 /* If port is closing, signal caller to try again */
50461 if (tty_hung_up_p(filp) || info->port.flags & ASYNC_CLOSING){
50462 @@ -769,10 +769,10 @@ static int open(struct tty_struct *tty, struct file *filp)
50463 spin_unlock_irqrestore(&info->netlock, flags);
50464 goto cleanup;
50465 }
50466 - info->port.count++;
50467 + atomic_inc(&info->port.count);
50468 spin_unlock_irqrestore(&info->netlock, flags);
50469
50470 - if (info->port.count == 1) {
50471 + if (atomic_read(&info->port.count) == 1) {
50472 /* 1st open on this device, init hardware */
50473 retval = startup(info);
50474 if (retval < 0)
50475 @@ -796,8 +796,8 @@ cleanup:
50476 if (retval) {
50477 if (tty->count == 1)
50478 info->port.tty = NULL; /* tty layer will release tty struct */
50479 - if(info->port.count)
50480 - info->port.count--;
50481 + if(atomic_read(&info->port.count))
50482 + atomic_dec(&info->port.count);
50483 }
50484
50485 return retval;
50486 @@ -815,7 +815,7 @@ static void close(struct tty_struct *tty, struct file *filp)
50487
50488 if (debug_level >= DEBUG_LEVEL_INFO)
50489 printk("%s(%d):%s close() entry, count=%d\n",
50490 - __FILE__,__LINE__, info->device_name, info->port.count);
50491 + __FILE__,__LINE__, info->device_name, atomic_read(&info->port.count));
50492
50493 if (tty_port_close_start(&info->port, tty, filp) == 0)
50494 goto cleanup;
50495 @@ -834,7 +834,7 @@ static void close(struct tty_struct *tty, struct file *filp)
50496 cleanup:
50497 if (debug_level >= DEBUG_LEVEL_INFO)
50498 printk("%s(%d):%s close() exit, count=%d\n", __FILE__,__LINE__,
50499 - tty->driver->name, info->port.count);
50500 + tty->driver->name, atomic_read(&info->port.count));
50501 }
50502
50503 /* Called by tty_hangup() when a hangup is signaled.
50504 @@ -857,7 +857,7 @@ static void hangup(struct tty_struct *tty)
50505 shutdown(info);
50506
50507 spin_lock_irqsave(&info->port.lock, flags);
50508 - info->port.count = 0;
50509 + atomic_set(&info->port.count, 0);
50510 info->port.flags &= ~ASYNC_NORMAL_ACTIVE;
50511 info->port.tty = NULL;
50512 spin_unlock_irqrestore(&info->port.lock, flags);
50513 @@ -1565,7 +1565,7 @@ static int hdlcdev_attach(struct net_device *dev, unsigned short encoding,
50514 unsigned short new_crctype;
50515
50516 /* return error if TTY interface open */
50517 - if (info->port.count)
50518 + if (atomic_read(&info->port.count))
50519 return -EBUSY;
50520
50521 switch (encoding)
50522 @@ -1660,7 +1660,7 @@ static int hdlcdev_open(struct net_device *dev)
50523
50524 /* arbitrate between network and tty opens */
50525 spin_lock_irqsave(&info->netlock, flags);
50526 - if (info->port.count != 0 || info->netcount != 0) {
50527 + if (atomic_read(&info->port.count) != 0 || info->netcount != 0) {
50528 printk(KERN_WARNING "%s: hdlc_open returning busy\n", dev->name);
50529 spin_unlock_irqrestore(&info->netlock, flags);
50530 return -EBUSY;
50531 @@ -1746,7 +1746,7 @@ static int hdlcdev_ioctl(struct net_device *dev, struct ifreq *ifr, int cmd)
50532 printk("%s:hdlcdev_ioctl(%s)\n",__FILE__,dev->name);
50533
50534 /* return error if TTY interface open */
50535 - if (info->port.count)
50536 + if (atomic_read(&info->port.count))
50537 return -EBUSY;
50538
50539 if (cmd != SIOCWANDEV)
50540 @@ -2620,7 +2620,7 @@ static irqreturn_t synclinkmp_interrupt(int dummy, void *dev_id)
50541 * do not request bottom half processing if the
50542 * device is not open in a normal mode.
50543 */
50544 - if ( port && (port->port.count || port->netcount) &&
50545 + if ( port && (atomic_read(&port->port.count) || port->netcount) &&
50546 port->pending_bh && !port->bh_running &&
50547 !port->bh_requested ) {
50548 if ( debug_level >= DEBUG_LEVEL_ISR )
50549 @@ -3318,12 +3318,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50550
50551 if (debug_level >= DEBUG_LEVEL_INFO)
50552 printk("%s(%d):%s block_til_ready() before block, count=%d\n",
50553 - __FILE__,__LINE__, tty->driver->name, port->count );
50554 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50555
50556 spin_lock_irqsave(&info->lock, flags);
50557 if (!tty_hung_up_p(filp)) {
50558 extra_count = true;
50559 - port->count--;
50560 + atomic_dec(&port->count);
50561 }
50562 spin_unlock_irqrestore(&info->lock, flags);
50563 port->blocked_open++;
50564 @@ -3352,7 +3352,7 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50565
50566 if (debug_level >= DEBUG_LEVEL_INFO)
50567 printk("%s(%d):%s block_til_ready() count=%d\n",
50568 - __FILE__,__LINE__, tty->driver->name, port->count );
50569 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50570
50571 tty_unlock(tty);
50572 schedule();
50573 @@ -3363,12 +3363,12 @@ static int block_til_ready(struct tty_struct *tty, struct file *filp,
50574 remove_wait_queue(&port->open_wait, &wait);
50575
50576 if (extra_count)
50577 - port->count++;
50578 + atomic_inc(&port->count);
50579 port->blocked_open--;
50580
50581 if (debug_level >= DEBUG_LEVEL_INFO)
50582 printk("%s(%d):%s block_til_ready() after, count=%d\n",
50583 - __FILE__,__LINE__, tty->driver->name, port->count );
50584 + __FILE__,__LINE__, tty->driver->name, atomic_read(&port->count));
50585
50586 if (!retval)
50587 port->flags |= ASYNC_NORMAL_ACTIVE;
50588 diff --git a/drivers/tty/sysrq.c b/drivers/tty/sysrq.c
50589 index ce396ec..04a37be 100644
50590 --- a/drivers/tty/sysrq.c
50591 +++ b/drivers/tty/sysrq.c
50592 @@ -1075,7 +1075,7 @@ EXPORT_SYMBOL(unregister_sysrq_key);
50593 static ssize_t write_sysrq_trigger(struct file *file, const char __user *buf,
50594 size_t count, loff_t *ppos)
50595 {
50596 - if (count) {
50597 + if (count && capable(CAP_SYS_ADMIN)) {
50598 char c;
50599
50600 if (get_user(c, buf))
50601 diff --git a/drivers/tty/tty_io.c b/drivers/tty/tty_io.c
50602 index c74a00a..02cf211a 100644
50603 --- a/drivers/tty/tty_io.c
50604 +++ b/drivers/tty/tty_io.c
50605 @@ -3474,7 +3474,7 @@ EXPORT_SYMBOL_GPL(get_current_tty);
50606
50607 void tty_default_fops(struct file_operations *fops)
50608 {
50609 - *fops = tty_fops;
50610 + memcpy((void *)fops, &tty_fops, sizeof(tty_fops));
50611 }
50612
50613 /*
50614 diff --git a/drivers/tty/tty_ldisc.c b/drivers/tty/tty_ldisc.c
50615 index 6458e11..6cfc218 100644
50616 --- a/drivers/tty/tty_ldisc.c
50617 +++ b/drivers/tty/tty_ldisc.c
50618 @@ -72,7 +72,7 @@ int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc)
50619 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
50620 tty_ldiscs[disc] = new_ldisc;
50621 new_ldisc->num = disc;
50622 - new_ldisc->refcount = 0;
50623 + atomic_set(&new_ldisc->refcount, 0);
50624 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
50625
50626 return ret;
50627 @@ -100,7 +100,7 @@ int tty_unregister_ldisc(int disc)
50628 return -EINVAL;
50629
50630 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
50631 - if (tty_ldiscs[disc]->refcount)
50632 + if (atomic_read(&tty_ldiscs[disc]->refcount))
50633 ret = -EBUSY;
50634 else
50635 tty_ldiscs[disc] = NULL;
50636 @@ -121,7 +121,7 @@ static struct tty_ldisc_ops *get_ldops(int disc)
50637 if (ldops) {
50638 ret = ERR_PTR(-EAGAIN);
50639 if (try_module_get(ldops->owner)) {
50640 - ldops->refcount++;
50641 + atomic_inc(&ldops->refcount);
50642 ret = ldops;
50643 }
50644 }
50645 @@ -134,7 +134,7 @@ static void put_ldops(struct tty_ldisc_ops *ldops)
50646 unsigned long flags;
50647
50648 raw_spin_lock_irqsave(&tty_ldiscs_lock, flags);
50649 - ldops->refcount--;
50650 + atomic_dec(&ldops->refcount);
50651 module_put(ldops->owner);
50652 raw_spin_unlock_irqrestore(&tty_ldiscs_lock, flags);
50653 }
50654 diff --git a/drivers/tty/tty_port.c b/drivers/tty/tty_port.c
50655 index c94d234..8210f2d 100644
50656 --- a/drivers/tty/tty_port.c
50657 +++ b/drivers/tty/tty_port.c
50658 @@ -236,7 +236,7 @@ void tty_port_hangup(struct tty_port *port)
50659 unsigned long flags;
50660
50661 spin_lock_irqsave(&port->lock, flags);
50662 - port->count = 0;
50663 + atomic_set(&port->count, 0);
50664 port->flags &= ~ASYNC_NORMAL_ACTIVE;
50665 tty = port->tty;
50666 if (tty)
50667 @@ -394,7 +394,7 @@ int tty_port_block_til_ready(struct tty_port *port,
50668 /* The port lock protects the port counts */
50669 spin_lock_irqsave(&port->lock, flags);
50670 if (!tty_hung_up_p(filp))
50671 - port->count--;
50672 + atomic_dec(&port->count);
50673 port->blocked_open++;
50674 spin_unlock_irqrestore(&port->lock, flags);
50675
50676 @@ -436,7 +436,7 @@ int tty_port_block_til_ready(struct tty_port *port,
50677 we must not mess that up further */
50678 spin_lock_irqsave(&port->lock, flags);
50679 if (!tty_hung_up_p(filp))
50680 - port->count++;
50681 + atomic_inc(&port->count);
50682 port->blocked_open--;
50683 if (retval == 0)
50684 port->flags |= ASYNC_NORMAL_ACTIVE;
50685 @@ -470,19 +470,19 @@ int tty_port_close_start(struct tty_port *port,
50686 return 0;
50687 }
50688
50689 - if (tty->count == 1 && port->count != 1) {
50690 + if (tty->count == 1 && atomic_read(&port->count) != 1) {
50691 printk(KERN_WARNING
50692 "tty_port_close_start: tty->count = 1 port count = %d.\n",
50693 - port->count);
50694 - port->count = 1;
50695 + atomic_read(&port->count));
50696 + atomic_set(&port->count, 1);
50697 }
50698 - if (--port->count < 0) {
50699 + if (atomic_dec_return(&port->count) < 0) {
50700 printk(KERN_WARNING "tty_port_close_start: count = %d\n",
50701 - port->count);
50702 - port->count = 0;
50703 + atomic_read(&port->count));
50704 + atomic_set(&port->count, 0);
50705 }
50706
50707 - if (port->count) {
50708 + if (atomic_read(&port->count)) {
50709 spin_unlock_irqrestore(&port->lock, flags);
50710 return 0;
50711 }
50712 @@ -564,7 +564,7 @@ int tty_port_open(struct tty_port *port, struct tty_struct *tty,
50713 {
50714 spin_lock_irq(&port->lock);
50715 if (!tty_hung_up_p(filp))
50716 - ++port->count;
50717 + atomic_inc(&port->count);
50718 spin_unlock_irq(&port->lock);
50719 tty_port_tty_set(port, tty);
50720
50721 diff --git a/drivers/tty/vt/keyboard.c b/drivers/tty/vt/keyboard.c
50722 index d0e3a44..5f8b754 100644
50723 --- a/drivers/tty/vt/keyboard.c
50724 +++ b/drivers/tty/vt/keyboard.c
50725 @@ -641,6 +641,16 @@ static void k_spec(struct vc_data *vc, unsigned char value, char up_flag)
50726 kbd->kbdmode == VC_OFF) &&
50727 value != KVAL(K_SAK))
50728 return; /* SAK is allowed even in raw mode */
50729 +
50730 +#if defined(CONFIG_GRKERNSEC_PROC) || defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
50731 + {
50732 + void *func = fn_handler[value];
50733 + if (func == fn_show_state || func == fn_show_ptregs ||
50734 + func == fn_show_mem)
50735 + return;
50736 + }
50737 +#endif
50738 +
50739 fn_handler[value](vc);
50740 }
50741
50742 @@ -1776,9 +1786,6 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
50743 if (copy_from_user(&tmp, user_kbe, sizeof(struct kbentry)))
50744 return -EFAULT;
50745
50746 - if (!capable(CAP_SYS_TTY_CONFIG))
50747 - perm = 0;
50748 -
50749 switch (cmd) {
50750 case KDGKBENT:
50751 /* Ensure another thread doesn't free it under us */
50752 @@ -1793,6 +1800,9 @@ int vt_do_kdsk_ioctl(int cmd, struct kbentry __user *user_kbe, int perm,
50753 spin_unlock_irqrestore(&kbd_event_lock, flags);
50754 return put_user(val, &user_kbe->kb_value);
50755 case KDSKBENT:
50756 + if (!capable(CAP_SYS_TTY_CONFIG))
50757 + perm = 0;
50758 +
50759 if (!perm)
50760 return -EPERM;
50761 if (!i && v == K_NOSUCHMAP) {
50762 @@ -1883,9 +1893,6 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
50763 int i, j, k;
50764 int ret;
50765
50766 - if (!capable(CAP_SYS_TTY_CONFIG))
50767 - perm = 0;
50768 -
50769 kbs = kmalloc(sizeof(*kbs), GFP_KERNEL);
50770 if (!kbs) {
50771 ret = -ENOMEM;
50772 @@ -1919,6 +1926,9 @@ int vt_do_kdgkb_ioctl(int cmd, struct kbsentry __user *user_kdgkb, int perm)
50773 kfree(kbs);
50774 return ((p && *p) ? -EOVERFLOW : 0);
50775 case KDSKBSENT:
50776 + if (!capable(CAP_SYS_TTY_CONFIG))
50777 + perm = 0;
50778 +
50779 if (!perm) {
50780 ret = -EPERM;
50781 goto reterr;
50782 diff --git a/drivers/uio/uio.c b/drivers/uio/uio.c
50783 index a673e5b..36e5d32 100644
50784 --- a/drivers/uio/uio.c
50785 +++ b/drivers/uio/uio.c
50786 @@ -25,6 +25,7 @@
50787 #include <linux/kobject.h>
50788 #include <linux/cdev.h>
50789 #include <linux/uio_driver.h>
50790 +#include <asm/local.h>
50791
50792 #define UIO_MAX_DEVICES (1U << MINORBITS)
50793
50794 @@ -32,7 +33,7 @@ struct uio_device {
50795 struct module *owner;
50796 struct device *dev;
50797 int minor;
50798 - atomic_t event;
50799 + atomic_unchecked_t event;
50800 struct fasync_struct *async_queue;
50801 wait_queue_head_t wait;
50802 struct uio_info *info;
50803 @@ -243,7 +244,7 @@ static ssize_t event_show(struct device *dev,
50804 struct device_attribute *attr, char *buf)
50805 {
50806 struct uio_device *idev = dev_get_drvdata(dev);
50807 - return sprintf(buf, "%u\n", (unsigned int)atomic_read(&idev->event));
50808 + return sprintf(buf, "%u\n", (unsigned int)atomic_read_unchecked(&idev->event));
50809 }
50810 static DEVICE_ATTR_RO(event);
50811
50812 @@ -405,7 +406,7 @@ void uio_event_notify(struct uio_info *info)
50813 {
50814 struct uio_device *idev = info->uio_dev;
50815
50816 - atomic_inc(&idev->event);
50817 + atomic_inc_unchecked(&idev->event);
50818 wake_up_interruptible(&idev->wait);
50819 kill_fasync(&idev->async_queue, SIGIO, POLL_IN);
50820 }
50821 @@ -458,7 +459,7 @@ static int uio_open(struct inode *inode, struct file *filep)
50822 }
50823
50824 listener->dev = idev;
50825 - listener->event_count = atomic_read(&idev->event);
50826 + listener->event_count = atomic_read_unchecked(&idev->event);
50827 filep->private_data = listener;
50828
50829 if (idev->info->open) {
50830 @@ -509,7 +510,7 @@ static unsigned int uio_poll(struct file *filep, poll_table *wait)
50831 return -EIO;
50832
50833 poll_wait(filep, &idev->wait, wait);
50834 - if (listener->event_count != atomic_read(&idev->event))
50835 + if (listener->event_count != atomic_read_unchecked(&idev->event))
50836 return POLLIN | POLLRDNORM;
50837 return 0;
50838 }
50839 @@ -534,7 +535,7 @@ static ssize_t uio_read(struct file *filep, char __user *buf,
50840 do {
50841 set_current_state(TASK_INTERRUPTIBLE);
50842
50843 - event_count = atomic_read(&idev->event);
50844 + event_count = atomic_read_unchecked(&idev->event);
50845 if (event_count != listener->event_count) {
50846 if (copy_to_user(buf, &event_count, count))
50847 retval = -EFAULT;
50848 @@ -591,9 +592,13 @@ static ssize_t uio_write(struct file *filep, const char __user *buf,
50849 static int uio_find_mem_index(struct vm_area_struct *vma)
50850 {
50851 struct uio_device *idev = vma->vm_private_data;
50852 + unsigned long size;
50853
50854 if (vma->vm_pgoff < MAX_UIO_MAPS) {
50855 - if (idev->info->mem[vma->vm_pgoff].size == 0)
50856 + size = idev->info->mem[vma->vm_pgoff].size;
50857 + if (size == 0)
50858 + return -1;
50859 + if (vma->vm_end - vma->vm_start > size)
50860 return -1;
50861 return (int)vma->vm_pgoff;
50862 }
50863 @@ -825,7 +830,7 @@ int __uio_register_device(struct module *owner,
50864 idev->owner = owner;
50865 idev->info = info;
50866 init_waitqueue_head(&idev->wait);
50867 - atomic_set(&idev->event, 0);
50868 + atomic_set_unchecked(&idev->event, 0);
50869
50870 ret = uio_get_minor(idev);
50871 if (ret)
50872 diff --git a/drivers/usb/atm/cxacru.c b/drivers/usb/atm/cxacru.c
50873 index 8a7eb77..c00402f 100644
50874 --- a/drivers/usb/atm/cxacru.c
50875 +++ b/drivers/usb/atm/cxacru.c
50876 @@ -473,7 +473,7 @@ static ssize_t cxacru_sysfs_store_adsl_config(struct device *dev,
50877 ret = sscanf(buf + pos, "%x=%x%n", &index, &value, &tmp);
50878 if (ret < 2)
50879 return -EINVAL;
50880 - if (index < 0 || index > 0x7f)
50881 + if (index > 0x7f)
50882 return -EINVAL;
50883 pos += tmp;
50884
50885 diff --git a/drivers/usb/atm/usbatm.c b/drivers/usb/atm/usbatm.c
50886 index 25a7bfc..57f3cf5 100644
50887 --- a/drivers/usb/atm/usbatm.c
50888 +++ b/drivers/usb/atm/usbatm.c
50889 @@ -331,7 +331,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50890 if (printk_ratelimit())
50891 atm_warn(instance, "%s: OAM not supported (vpi %d, vci %d)!\n",
50892 __func__, vpi, vci);
50893 - atomic_inc(&vcc->stats->rx_err);
50894 + atomic_inc_unchecked(&vcc->stats->rx_err);
50895 return;
50896 }
50897
50898 @@ -358,7 +358,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50899 if (length > ATM_MAX_AAL5_PDU) {
50900 atm_rldbg(instance, "%s: bogus length %u (vcc: 0x%p)!\n",
50901 __func__, length, vcc);
50902 - atomic_inc(&vcc->stats->rx_err);
50903 + atomic_inc_unchecked(&vcc->stats->rx_err);
50904 goto out;
50905 }
50906
50907 @@ -367,14 +367,14 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50908 if (sarb->len < pdu_length) {
50909 atm_rldbg(instance, "%s: bogus pdu_length %u (sarb->len: %u, vcc: 0x%p)!\n",
50910 __func__, pdu_length, sarb->len, vcc);
50911 - atomic_inc(&vcc->stats->rx_err);
50912 + atomic_inc_unchecked(&vcc->stats->rx_err);
50913 goto out;
50914 }
50915
50916 if (crc32_be(~0, skb_tail_pointer(sarb) - pdu_length, pdu_length) != 0xc704dd7b) {
50917 atm_rldbg(instance, "%s: packet failed crc check (vcc: 0x%p)!\n",
50918 __func__, vcc);
50919 - atomic_inc(&vcc->stats->rx_err);
50920 + atomic_inc_unchecked(&vcc->stats->rx_err);
50921 goto out;
50922 }
50923
50924 @@ -386,7 +386,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50925 if (printk_ratelimit())
50926 atm_err(instance, "%s: no memory for skb (length: %u)!\n",
50927 __func__, length);
50928 - atomic_inc(&vcc->stats->rx_drop);
50929 + atomic_inc_unchecked(&vcc->stats->rx_drop);
50930 goto out;
50931 }
50932
50933 @@ -414,7 +414,7 @@ static void usbatm_extract_one_cell(struct usbatm_data *instance, unsigned char
50934
50935 vcc->push(vcc, skb);
50936
50937 - atomic_inc(&vcc->stats->rx);
50938 + atomic_inc_unchecked(&vcc->stats->rx);
50939 out:
50940 skb_trim(sarb, 0);
50941 }
50942 @@ -612,7 +612,7 @@ static void usbatm_tx_process(unsigned long data)
50943 struct atm_vcc *vcc = UDSL_SKB(skb)->atm.vcc;
50944
50945 usbatm_pop(vcc, skb);
50946 - atomic_inc(&vcc->stats->tx);
50947 + atomic_inc_unchecked(&vcc->stats->tx);
50948
50949 skb = skb_dequeue(&instance->sndqueue);
50950 }
50951 @@ -756,11 +756,11 @@ static int usbatm_atm_proc_read(struct atm_dev *atm_dev, loff_t * pos, char *pag
50952 if (!left--)
50953 return sprintf(page,
50954 "AAL5: tx %d ( %d err ), rx %d ( %d err, %d drop )\n",
50955 - atomic_read(&atm_dev->stats.aal5.tx),
50956 - atomic_read(&atm_dev->stats.aal5.tx_err),
50957 - atomic_read(&atm_dev->stats.aal5.rx),
50958 - atomic_read(&atm_dev->stats.aal5.rx_err),
50959 - atomic_read(&atm_dev->stats.aal5.rx_drop));
50960 + atomic_read_unchecked(&atm_dev->stats.aal5.tx),
50961 + atomic_read_unchecked(&atm_dev->stats.aal5.tx_err),
50962 + atomic_read_unchecked(&atm_dev->stats.aal5.rx),
50963 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_err),
50964 + atomic_read_unchecked(&atm_dev->stats.aal5.rx_drop));
50965
50966 if (!left--) {
50967 if (instance->disconnected)
50968 diff --git a/drivers/usb/core/devices.c b/drivers/usb/core/devices.c
50969 index 2a3bbdf..91d72cf 100644
50970 --- a/drivers/usb/core/devices.c
50971 +++ b/drivers/usb/core/devices.c
50972 @@ -126,7 +126,7 @@ static const char format_endpt[] =
50973 * time it gets called.
50974 */
50975 static struct device_connect_event {
50976 - atomic_t count;
50977 + atomic_unchecked_t count;
50978 wait_queue_head_t wait;
50979 } device_event = {
50980 .count = ATOMIC_INIT(1),
50981 @@ -164,7 +164,7 @@ static const struct class_info clas_info[] = {
50982
50983 void usbfs_conn_disc_event(void)
50984 {
50985 - atomic_add(2, &device_event.count);
50986 + atomic_add_unchecked(2, &device_event.count);
50987 wake_up(&device_event.wait);
50988 }
50989
50990 @@ -652,7 +652,7 @@ static unsigned int usb_device_poll(struct file *file,
50991
50992 poll_wait(file, &device_event.wait, wait);
50993
50994 - event_count = atomic_read(&device_event.count);
50995 + event_count = atomic_read_unchecked(&device_event.count);
50996 if (file->f_version != event_count) {
50997 file->f_version = event_count;
50998 return POLLIN | POLLRDNORM;
50999 diff --git a/drivers/usb/core/devio.c b/drivers/usb/core/devio.c
51000 index 967152a..16fa2e5 100644
51001 --- a/drivers/usb/core/devio.c
51002 +++ b/drivers/usb/core/devio.c
51003 @@ -187,7 +187,7 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51004 struct dev_state *ps = file->private_data;
51005 struct usb_device *dev = ps->dev;
51006 ssize_t ret = 0;
51007 - unsigned len;
51008 + size_t len;
51009 loff_t pos;
51010 int i;
51011
51012 @@ -229,22 +229,22 @@ static ssize_t usbdev_read(struct file *file, char __user *buf, size_t nbytes,
51013 for (i = 0; nbytes && i < dev->descriptor.bNumConfigurations; i++) {
51014 struct usb_config_descriptor *config =
51015 (struct usb_config_descriptor *)dev->rawdescriptors[i];
51016 - unsigned int length = le16_to_cpu(config->wTotalLength);
51017 + size_t length = le16_to_cpu(config->wTotalLength);
51018
51019 if (*ppos < pos + length) {
51020
51021 /* The descriptor may claim to be longer than it
51022 * really is. Here is the actual allocated length. */
51023 - unsigned alloclen =
51024 + size_t alloclen =
51025 le16_to_cpu(dev->config[i].desc.wTotalLength);
51026
51027 - len = length - (*ppos - pos);
51028 + len = length + pos - *ppos;
51029 if (len > nbytes)
51030 len = nbytes;
51031
51032 /* Simply don't write (skip over) unallocated parts */
51033 if (alloclen > (*ppos - pos)) {
51034 - alloclen -= (*ppos - pos);
51035 + alloclen = alloclen + pos - *ppos;
51036 if (copy_to_user(buf,
51037 dev->rawdescriptors[i] + (*ppos - pos),
51038 min(len, alloclen))) {
51039 diff --git a/drivers/usb/core/hcd.c b/drivers/usb/core/hcd.c
51040 index 6bffb8c..b404e8b 100644
51041 --- a/drivers/usb/core/hcd.c
51042 +++ b/drivers/usb/core/hcd.c
51043 @@ -1550,7 +1550,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51044 */
51045 usb_get_urb(urb);
51046 atomic_inc(&urb->use_count);
51047 - atomic_inc(&urb->dev->urbnum);
51048 + atomic_inc_unchecked(&urb->dev->urbnum);
51049 usbmon_urb_submit(&hcd->self, urb);
51050
51051 /* NOTE requirements on root-hub callers (usbfs and the hub
51052 @@ -1577,7 +1577,7 @@ int usb_hcd_submit_urb (struct urb *urb, gfp_t mem_flags)
51053 urb->hcpriv = NULL;
51054 INIT_LIST_HEAD(&urb->urb_list);
51055 atomic_dec(&urb->use_count);
51056 - atomic_dec(&urb->dev->urbnum);
51057 + atomic_dec_unchecked(&urb->dev->urbnum);
51058 if (atomic_read(&urb->reject))
51059 wake_up(&usb_kill_urb_queue);
51060 usb_put_urb(urb);
51061 diff --git a/drivers/usb/core/hub.c b/drivers/usb/core/hub.c
51062 index 07e6654..6420edf 100644
51063 --- a/drivers/usb/core/hub.c
51064 +++ b/drivers/usb/core/hub.c
51065 @@ -27,6 +27,7 @@
51066 #include <linux/freezer.h>
51067 #include <linux/random.h>
51068 #include <linux/pm_qos.h>
51069 +#include <linux/grsecurity.h>
51070
51071 #include <asm/uaccess.h>
51072 #include <asm/byteorder.h>
51073 @@ -4442,6 +4443,10 @@ static void hub_port_connect_change(struct usb_hub *hub, int port1,
51074 goto done;
51075 return;
51076 }
51077 +
51078 + if (gr_handle_new_usb())
51079 + goto done;
51080 +
51081 if (hub_is_superspeed(hub->hdev))
51082 unit_load = 150;
51083 else
51084 diff --git a/drivers/usb/core/message.c b/drivers/usb/core/message.c
51085 index bb31597..6c5ef8b 100644
51086 --- a/drivers/usb/core/message.c
51087 +++ b/drivers/usb/core/message.c
51088 @@ -129,7 +129,7 @@ static int usb_internal_control_msg(struct usb_device *usb_dev,
51089 * Return: If successful, the number of bytes transferred. Otherwise, a negative
51090 * error number.
51091 */
51092 -int usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51093 +int __intentional_overflow(-1) usb_control_msg(struct usb_device *dev, unsigned int pipe, __u8 request,
51094 __u8 requesttype, __u16 value, __u16 index, void *data,
51095 __u16 size, int timeout)
51096 {
51097 @@ -181,7 +181,7 @@ EXPORT_SYMBOL_GPL(usb_control_msg);
51098 * If successful, 0. Otherwise a negative error number. The number of actual
51099 * bytes transferred will be stored in the @actual_length paramater.
51100 */
51101 -int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51102 +int __intentional_overflow(-1) usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
51103 void *data, int len, int *actual_length, int timeout)
51104 {
51105 return usb_bulk_msg(usb_dev, pipe, data, len, actual_length, timeout);
51106 @@ -221,7 +221,7 @@ EXPORT_SYMBOL_GPL(usb_interrupt_msg);
51107 * bytes transferred will be stored in the @actual_length paramater.
51108 *
51109 */
51110 -int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51111 +int __intentional_overflow(-1) usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
51112 void *data, int len, int *actual_length, int timeout)
51113 {
51114 struct urb *urb;
51115 diff --git a/drivers/usb/core/sysfs.c b/drivers/usb/core/sysfs.c
51116 index 52a97ad..e73330f 100644
51117 --- a/drivers/usb/core/sysfs.c
51118 +++ b/drivers/usb/core/sysfs.c
51119 @@ -244,7 +244,7 @@ static ssize_t urbnum_show(struct device *dev, struct device_attribute *attr,
51120 struct usb_device *udev;
51121
51122 udev = to_usb_device(dev);
51123 - return sprintf(buf, "%d\n", atomic_read(&udev->urbnum));
51124 + return sprintf(buf, "%d\n", atomic_read_unchecked(&udev->urbnum));
51125 }
51126 static DEVICE_ATTR_RO(urbnum);
51127
51128 diff --git a/drivers/usb/core/usb.c b/drivers/usb/core/usb.c
51129 index 4d11449..f4ccabf 100644
51130 --- a/drivers/usb/core/usb.c
51131 +++ b/drivers/usb/core/usb.c
51132 @@ -433,7 +433,7 @@ struct usb_device *usb_alloc_dev(struct usb_device *parent,
51133 set_dev_node(&dev->dev, dev_to_node(bus->controller));
51134 dev->state = USB_STATE_ATTACHED;
51135 dev->lpm_disable_count = 1;
51136 - atomic_set(&dev->urbnum, 0);
51137 + atomic_set_unchecked(&dev->urbnum, 0);
51138
51139 INIT_LIST_HEAD(&dev->ep0.urb_list);
51140 dev->ep0.desc.bLength = USB_DT_ENDPOINT_SIZE;
51141 diff --git a/drivers/usb/dwc3/gadget.c b/drivers/usb/dwc3/gadget.c
51142 index 02e44fc..3c4fe64 100644
51143 --- a/drivers/usb/dwc3/gadget.c
51144 +++ b/drivers/usb/dwc3/gadget.c
51145 @@ -532,8 +532,6 @@ static int __dwc3_gadget_ep_enable(struct dwc3_ep *dep,
51146 if (!usb_endpoint_xfer_isoc(desc))
51147 return 0;
51148
51149 - memset(&trb_link, 0, sizeof(trb_link));
51150 -
51151 /* Link TRB for ISOC. The HWO bit is never reset */
51152 trb_st_hw = &dep->trb_pool[0];
51153
51154 diff --git a/drivers/usb/early/ehci-dbgp.c b/drivers/usb/early/ehci-dbgp.c
51155 index 8cfc319..4868255 100644
51156 --- a/drivers/usb/early/ehci-dbgp.c
51157 +++ b/drivers/usb/early/ehci-dbgp.c
51158 @@ -98,7 +98,8 @@ static inline u32 dbgp_len_update(u32 x, u32 len)
51159
51160 #ifdef CONFIG_KGDB
51161 static struct kgdb_io kgdbdbgp_io_ops;
51162 -#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops)
51163 +static struct kgdb_io kgdbdbgp_io_ops_console;
51164 +#define dbgp_kgdb_mode (dbg_io_ops == &kgdbdbgp_io_ops || dbg_io_ops == &kgdbdbgp_io_ops_console)
51165 #else
51166 #define dbgp_kgdb_mode (0)
51167 #endif
51168 @@ -1043,6 +1044,13 @@ static struct kgdb_io kgdbdbgp_io_ops = {
51169 .write_char = kgdbdbgp_write_char,
51170 };
51171
51172 +static struct kgdb_io kgdbdbgp_io_ops_console = {
51173 + .name = "kgdbdbgp",
51174 + .read_char = kgdbdbgp_read_char,
51175 + .write_char = kgdbdbgp_write_char,
51176 + .is_console = 1
51177 +};
51178 +
51179 static int kgdbdbgp_wait_time;
51180
51181 static int __init kgdbdbgp_parse_config(char *str)
51182 @@ -1058,8 +1066,10 @@ static int __init kgdbdbgp_parse_config(char *str)
51183 ptr++;
51184 kgdbdbgp_wait_time = simple_strtoul(ptr, &ptr, 10);
51185 }
51186 - kgdb_register_io_module(&kgdbdbgp_io_ops);
51187 - kgdbdbgp_io_ops.is_console = early_dbgp_console.index != -1;
51188 + if (early_dbgp_console.index != -1)
51189 + kgdb_register_io_module(&kgdbdbgp_io_ops_console);
51190 + else
51191 + kgdb_register_io_module(&kgdbdbgp_io_ops);
51192
51193 return 0;
51194 }
51195 diff --git a/drivers/usb/gadget/u_serial.c b/drivers/usb/gadget/u_serial.c
51196 index b369292..9f3ba40 100644
51197 --- a/drivers/usb/gadget/u_serial.c
51198 +++ b/drivers/usb/gadget/u_serial.c
51199 @@ -733,9 +733,9 @@ static int gs_open(struct tty_struct *tty, struct file *file)
51200 spin_lock_irq(&port->port_lock);
51201
51202 /* already open? Great. */
51203 - if (port->port.count) {
51204 + if (atomic_read(&port->port.count)) {
51205 status = 0;
51206 - port->port.count++;
51207 + atomic_inc(&port->port.count);
51208
51209 /* currently opening/closing? wait ... */
51210 } else if (port->openclose) {
51211 @@ -794,7 +794,7 @@ static int gs_open(struct tty_struct *tty, struct file *file)
51212 tty->driver_data = port;
51213 port->port.tty = tty;
51214
51215 - port->port.count = 1;
51216 + atomic_set(&port->port.count, 1);
51217 port->openclose = false;
51218
51219 /* if connected, start the I/O stream */
51220 @@ -836,11 +836,11 @@ static void gs_close(struct tty_struct *tty, struct file *file)
51221
51222 spin_lock_irq(&port->port_lock);
51223
51224 - if (port->port.count != 1) {
51225 - if (port->port.count == 0)
51226 + if (atomic_read(&port->port.count) != 1) {
51227 + if (atomic_read(&port->port.count) == 0)
51228 WARN_ON(1);
51229 else
51230 - --port->port.count;
51231 + atomic_dec(&port->port.count);
51232 goto exit;
51233 }
51234
51235 @@ -850,7 +850,7 @@ static void gs_close(struct tty_struct *tty, struct file *file)
51236 * and sleep if necessary
51237 */
51238 port->openclose = true;
51239 - port->port.count = 0;
51240 + atomic_set(&port->port.count, 0);
51241
51242 gser = port->port_usb;
51243 if (gser && gser->disconnect)
51244 @@ -1066,7 +1066,7 @@ static int gs_closed(struct gs_port *port)
51245 int cond;
51246
51247 spin_lock_irq(&port->port_lock);
51248 - cond = (port->port.count == 0) && !port->openclose;
51249 + cond = (atomic_read(&port->port.count) == 0) && !port->openclose;
51250 spin_unlock_irq(&port->port_lock);
51251 return cond;
51252 }
51253 @@ -1209,7 +1209,7 @@ int gserial_connect(struct gserial *gser, u8 port_num)
51254 /* if it's already open, start I/O ... and notify the serial
51255 * protocol about open/close status (connect/disconnect).
51256 */
51257 - if (port->port.count) {
51258 + if (atomic_read(&port->port.count)) {
51259 pr_debug("gserial_connect: start ttyGS%d\n", port->port_num);
51260 gs_start_io(port);
51261 if (gser->connect)
51262 @@ -1256,7 +1256,7 @@ void gserial_disconnect(struct gserial *gser)
51263
51264 port->port_usb = NULL;
51265 gser->ioport = NULL;
51266 - if (port->port.count > 0 || port->openclose) {
51267 + if (atomic_read(&port->port.count) > 0 || port->openclose) {
51268 wake_up_interruptible(&port->drain_wait);
51269 if (port->port.tty)
51270 tty_hangup(port->port.tty);
51271 @@ -1272,7 +1272,7 @@ void gserial_disconnect(struct gserial *gser)
51272
51273 /* finally, free any unused/unusable I/O buffers */
51274 spin_lock_irqsave(&port->port_lock, flags);
51275 - if (port->port.count == 0 && !port->openclose)
51276 + if (atomic_read(&port->port.count) == 0 && !port->openclose)
51277 gs_buf_free(&port->port_write_buf);
51278 gs_free_requests(gser->out, &port->read_pool, NULL);
51279 gs_free_requests(gser->out, &port->read_queue, NULL);
51280 diff --git a/drivers/usb/host/ehci-hub.c b/drivers/usb/host/ehci-hub.c
51281 index 835fc08..f8b22bf 100644
51282 --- a/drivers/usb/host/ehci-hub.c
51283 +++ b/drivers/usb/host/ehci-hub.c
51284 @@ -762,7 +762,7 @@ static struct urb *request_single_step_set_feature_urb(
51285 urb->transfer_flags = URB_DIR_IN;
51286 usb_get_urb(urb);
51287 atomic_inc(&urb->use_count);
51288 - atomic_inc(&urb->dev->urbnum);
51289 + atomic_inc_unchecked(&urb->dev->urbnum);
51290 urb->setup_dma = dma_map_single(
51291 hcd->self.controller,
51292 urb->setup_packet,
51293 @@ -829,7 +829,7 @@ static int ehset_single_step_set_feature(struct usb_hcd *hcd, int port)
51294 urb->status = -EINPROGRESS;
51295 usb_get_urb(urb);
51296 atomic_inc(&urb->use_count);
51297 - atomic_inc(&urb->dev->urbnum);
51298 + atomic_inc_unchecked(&urb->dev->urbnum);
51299 retval = submit_single_step_set_feature(hcd, urb, 0);
51300 if (!retval && !wait_for_completion_timeout(&done,
51301 msecs_to_jiffies(2000))) {
51302 diff --git a/drivers/usb/misc/appledisplay.c b/drivers/usb/misc/appledisplay.c
51303 index ba6a5d6..f88f7f3 100644
51304 --- a/drivers/usb/misc/appledisplay.c
51305 +++ b/drivers/usb/misc/appledisplay.c
51306 @@ -83,7 +83,7 @@ struct appledisplay {
51307 spinlock_t lock;
51308 };
51309
51310 -static atomic_t count_displays = ATOMIC_INIT(0);
51311 +static atomic_unchecked_t count_displays = ATOMIC_INIT(0);
51312 static struct workqueue_struct *wq;
51313
51314 static void appledisplay_complete(struct urb *urb)
51315 @@ -281,7 +281,7 @@ static int appledisplay_probe(struct usb_interface *iface,
51316
51317 /* Register backlight device */
51318 snprintf(bl_name, sizeof(bl_name), "appledisplay%d",
51319 - atomic_inc_return(&count_displays) - 1);
51320 + atomic_inc_return_unchecked(&count_displays) - 1);
51321 memset(&props, 0, sizeof(struct backlight_properties));
51322 props.type = BACKLIGHT_RAW;
51323 props.max_brightness = 0xff;
51324 diff --git a/drivers/usb/serial/console.c b/drivers/usb/serial/console.c
51325 index c69bb50..215ef37 100644
51326 --- a/drivers/usb/serial/console.c
51327 +++ b/drivers/usb/serial/console.c
51328 @@ -124,7 +124,7 @@ static int usb_console_setup(struct console *co, char *options)
51329
51330 info->port = port;
51331
51332 - ++port->port.count;
51333 + atomic_inc(&port->port.count);
51334 if (!test_bit(ASYNCB_INITIALIZED, &port->port.flags)) {
51335 if (serial->type->set_termios) {
51336 /*
51337 @@ -170,7 +170,7 @@ static int usb_console_setup(struct console *co, char *options)
51338 }
51339 /* Now that any required fake tty operations are completed restore
51340 * the tty port count */
51341 - --port->port.count;
51342 + atomic_dec(&port->port.count);
51343 /* The console is special in terms of closing the device so
51344 * indicate this port is now acting as a system console. */
51345 port->port.console = 1;
51346 @@ -183,7 +183,7 @@ static int usb_console_setup(struct console *co, char *options)
51347 free_tty:
51348 kfree(tty);
51349 reset_open_count:
51350 - port->port.count = 0;
51351 + atomic_set(&port->port.count, 0);
51352 usb_autopm_put_interface(serial->interface);
51353 error_get_interface:
51354 usb_serial_put(serial);
51355 @@ -194,7 +194,7 @@ static int usb_console_setup(struct console *co, char *options)
51356 static void usb_console_write(struct console *co,
51357 const char *buf, unsigned count)
51358 {
51359 - static struct usbcons_info *info = &usbcons_info;
51360 + struct usbcons_info *info = &usbcons_info;
51361 struct usb_serial_port *port = info->port;
51362 struct usb_serial *serial;
51363 int retval = -ENODEV;
51364 diff --git a/drivers/usb/storage/usb.h b/drivers/usb/storage/usb.h
51365 index 75f70f0..d467e1a 100644
51366 --- a/drivers/usb/storage/usb.h
51367 +++ b/drivers/usb/storage/usb.h
51368 @@ -63,7 +63,7 @@ struct us_unusual_dev {
51369 __u8 useProtocol;
51370 __u8 useTransport;
51371 int (*initFunction)(struct us_data *);
51372 -};
51373 +} __do_const;
51374
51375
51376 /* Dynamic bitflag definitions (us->dflags): used in set_bit() etc. */
51377 diff --git a/drivers/usb/wusbcore/wa-hc.h b/drivers/usb/wusbcore/wa-hc.h
51378 index e614f02..3fd60e2 100644
51379 --- a/drivers/usb/wusbcore/wa-hc.h
51380 +++ b/drivers/usb/wusbcore/wa-hc.h
51381 @@ -225,7 +225,7 @@ struct wahc {
51382 spinlock_t xfer_list_lock;
51383 struct work_struct xfer_enqueue_work;
51384 struct work_struct xfer_error_work;
51385 - atomic_t xfer_id_count;
51386 + atomic_unchecked_t xfer_id_count;
51387
51388 kernel_ulong_t quirks;
51389 };
51390 @@ -287,7 +287,7 @@ static inline void wa_init(struct wahc *wa)
51391 INIT_WORK(&wa->xfer_enqueue_work, wa_urb_enqueue_run);
51392 INIT_WORK(&wa->xfer_error_work, wa_process_errored_transfers_run);
51393 wa->dto_in_use = 0;
51394 - atomic_set(&wa->xfer_id_count, 1);
51395 + atomic_set_unchecked(&wa->xfer_id_count, 1);
51396 }
51397
51398 /**
51399 diff --git a/drivers/usb/wusbcore/wa-xfer.c b/drivers/usb/wusbcore/wa-xfer.c
51400 index ed5abe8..7036400 100644
51401 --- a/drivers/usb/wusbcore/wa-xfer.c
51402 +++ b/drivers/usb/wusbcore/wa-xfer.c
51403 @@ -312,7 +312,7 @@ static void wa_xfer_completion(struct wa_xfer *xfer)
51404 */
51405 static void wa_xfer_id_init(struct wa_xfer *xfer)
51406 {
51407 - xfer->id = atomic_add_return(1, &xfer->wa->xfer_id_count);
51408 + xfer->id = atomic_add_return_unchecked(1, &xfer->wa->xfer_id_count);
51409 }
51410
51411 /* Return the xfer's ID. */
51412 diff --git a/drivers/vfio/vfio.c b/drivers/vfio/vfio.c
51413 index 1eab4ac..e21efc9 100644
51414 --- a/drivers/vfio/vfio.c
51415 +++ b/drivers/vfio/vfio.c
51416 @@ -488,7 +488,7 @@ static int vfio_group_nb_add_dev(struct vfio_group *group, struct device *dev)
51417 return 0;
51418
51419 /* TODO Prevent device auto probing */
51420 - WARN("Device %s added to live group %d!\n", dev_name(dev),
51421 + WARN(1, "Device %s added to live group %d!\n", dev_name(dev),
51422 iommu_group_id(group->iommu_group));
51423
51424 return 0;
51425 diff --git a/drivers/vhost/vringh.c b/drivers/vhost/vringh.c
51426 index 5174eba..451e6bc 100644
51427 --- a/drivers/vhost/vringh.c
51428 +++ b/drivers/vhost/vringh.c
51429 @@ -530,17 +530,17 @@ static inline void __vringh_notify_disable(struct vringh *vrh,
51430 /* Userspace access helpers: in this case, addresses are really userspace. */
51431 static inline int getu16_user(u16 *val, const u16 *p)
51432 {
51433 - return get_user(*val, (__force u16 __user *)p);
51434 + return get_user(*val, (u16 __force_user *)p);
51435 }
51436
51437 static inline int putu16_user(u16 *p, u16 val)
51438 {
51439 - return put_user(val, (__force u16 __user *)p);
51440 + return put_user(val, (u16 __force_user *)p);
51441 }
51442
51443 static inline int copydesc_user(void *dst, const void *src, size_t len)
51444 {
51445 - return copy_from_user(dst, (__force void __user *)src, len) ?
51446 + return copy_from_user(dst, (void __force_user *)src, len) ?
51447 -EFAULT : 0;
51448 }
51449
51450 @@ -548,19 +548,19 @@ static inline int putused_user(struct vring_used_elem *dst,
51451 const struct vring_used_elem *src,
51452 unsigned int num)
51453 {
51454 - return copy_to_user((__force void __user *)dst, src,
51455 + return copy_to_user((void __force_user *)dst, src,
51456 sizeof(*dst) * num) ? -EFAULT : 0;
51457 }
51458
51459 static inline int xfer_from_user(void *src, void *dst, size_t len)
51460 {
51461 - return copy_from_user(dst, (__force void __user *)src, len) ?
51462 + return copy_from_user(dst, (void __force_user *)src, len) ?
51463 -EFAULT : 0;
51464 }
51465
51466 static inline int xfer_to_user(void *dst, void *src, size_t len)
51467 {
51468 - return copy_to_user((__force void __user *)dst, src, len) ?
51469 + return copy_to_user((void __force_user *)dst, src, len) ?
51470 -EFAULT : 0;
51471 }
51472
51473 @@ -596,9 +596,9 @@ int vringh_init_user(struct vringh *vrh, u32 features,
51474 vrh->last_used_idx = 0;
51475 vrh->vring.num = num;
51476 /* vring expects kernel addresses, but only used via accessors. */
51477 - vrh->vring.desc = (__force struct vring_desc *)desc;
51478 - vrh->vring.avail = (__force struct vring_avail *)avail;
51479 - vrh->vring.used = (__force struct vring_used *)used;
51480 + vrh->vring.desc = (__force_kernel struct vring_desc *)desc;
51481 + vrh->vring.avail = (__force_kernel struct vring_avail *)avail;
51482 + vrh->vring.used = (__force_kernel struct vring_used *)used;
51483 return 0;
51484 }
51485 EXPORT_SYMBOL(vringh_init_user);
51486 @@ -800,7 +800,7 @@ static inline int getu16_kern(u16 *val, const u16 *p)
51487
51488 static inline int putu16_kern(u16 *p, u16 val)
51489 {
51490 - ACCESS_ONCE(*p) = val;
51491 + ACCESS_ONCE_RW(*p) = val;
51492 return 0;
51493 }
51494
51495 diff --git a/drivers/video/arcfb.c b/drivers/video/arcfb.c
51496 index 1b0b233..6f34c2c 100644
51497 --- a/drivers/video/arcfb.c
51498 +++ b/drivers/video/arcfb.c
51499 @@ -458,7 +458,7 @@ static ssize_t arcfb_write(struct fb_info *info, const char __user *buf,
51500 return -ENOSPC;
51501
51502 err = 0;
51503 - if ((count + p) > fbmemlength) {
51504 + if (count > (fbmemlength - p)) {
51505 count = fbmemlength - p;
51506 err = -ENOSPC;
51507 }
51508 diff --git a/drivers/video/aty/aty128fb.c b/drivers/video/aty/aty128fb.c
51509 index 12ca031..84a8a74 100644
51510 --- a/drivers/video/aty/aty128fb.c
51511 +++ b/drivers/video/aty/aty128fb.c
51512 @@ -149,7 +149,7 @@ enum {
51513 };
51514
51515 /* Must match above enum */
51516 -static char * const r128_family[] = {
51517 +static const char * const r128_family[] = {
51518 "AGP",
51519 "PCI",
51520 "PRO AGP",
51521 diff --git a/drivers/video/aty/atyfb_base.c b/drivers/video/aty/atyfb_base.c
51522 index 28fafbf..ae91651 100644
51523 --- a/drivers/video/aty/atyfb_base.c
51524 +++ b/drivers/video/aty/atyfb_base.c
51525 @@ -1326,10 +1326,14 @@ static int atyfb_set_par(struct fb_info *info)
51526 par->accel_flags = var->accel_flags; /* hack */
51527
51528 if (var->accel_flags) {
51529 - info->fbops->fb_sync = atyfb_sync;
51530 + pax_open_kernel();
51531 + *(void **)&info->fbops->fb_sync = atyfb_sync;
51532 + pax_close_kernel();
51533 info->flags &= ~FBINFO_HWACCEL_DISABLED;
51534 } else {
51535 - info->fbops->fb_sync = NULL;
51536 + pax_open_kernel();
51537 + *(void **)&info->fbops->fb_sync = NULL;
51538 + pax_close_kernel();
51539 info->flags |= FBINFO_HWACCEL_DISABLED;
51540 }
51541
51542 diff --git a/drivers/video/aty/mach64_cursor.c b/drivers/video/aty/mach64_cursor.c
51543 index 95ec042..e6affdd 100644
51544 --- a/drivers/video/aty/mach64_cursor.c
51545 +++ b/drivers/video/aty/mach64_cursor.c
51546 @@ -7,6 +7,7 @@
51547 #include <linux/string.h>
51548
51549 #include <asm/io.h>
51550 +#include <asm/pgtable.h>
51551
51552 #ifdef __sparc__
51553 #include <asm/fbio.h>
51554 @@ -208,7 +209,9 @@ int aty_init_cursor(struct fb_info *info)
51555 info->sprite.buf_align = 16; /* and 64 lines tall. */
51556 info->sprite.flags = FB_PIXMAP_IO;
51557
51558 - info->fbops->fb_cursor = atyfb_cursor;
51559 + pax_open_kernel();
51560 + *(void **)&info->fbops->fb_cursor = atyfb_cursor;
51561 + pax_close_kernel();
51562
51563 return 0;
51564 }
51565 diff --git a/drivers/video/backlight/kb3886_bl.c b/drivers/video/backlight/kb3886_bl.c
51566 index 7592cc2..92feb56 100644
51567 --- a/drivers/video/backlight/kb3886_bl.c
51568 +++ b/drivers/video/backlight/kb3886_bl.c
51569 @@ -78,7 +78,7 @@ static struct kb3886bl_machinfo *bl_machinfo;
51570 static unsigned long kb3886bl_flags;
51571 #define KB3886BL_SUSPENDED 0x01
51572
51573 -static struct dmi_system_id __initdata kb3886bl_device_table[] = {
51574 +static const struct dmi_system_id __initconst kb3886bl_device_table[] = {
51575 {
51576 .ident = "Sahara Touch-iT",
51577 .matches = {
51578 diff --git a/drivers/video/fb_defio.c b/drivers/video/fb_defio.c
51579 index 900aa4e..6d49418 100644
51580 --- a/drivers/video/fb_defio.c
51581 +++ b/drivers/video/fb_defio.c
51582 @@ -206,7 +206,9 @@ void fb_deferred_io_init(struct fb_info *info)
51583
51584 BUG_ON(!fbdefio);
51585 mutex_init(&fbdefio->lock);
51586 - info->fbops->fb_mmap = fb_deferred_io_mmap;
51587 + pax_open_kernel();
51588 + *(void **)&info->fbops->fb_mmap = fb_deferred_io_mmap;
51589 + pax_close_kernel();
51590 INIT_DELAYED_WORK(&info->deferred_work, fb_deferred_io_work);
51591 INIT_LIST_HEAD(&fbdefio->pagelist);
51592 if (fbdefio->delay == 0) /* set a default of 1 s */
51593 @@ -237,7 +239,7 @@ void fb_deferred_io_cleanup(struct fb_info *info)
51594 page->mapping = NULL;
51595 }
51596
51597 - info->fbops->fb_mmap = NULL;
51598 + *(void **)&info->fbops->fb_mmap = NULL;
51599 mutex_destroy(&fbdefio->lock);
51600 }
51601 EXPORT_SYMBOL_GPL(fb_deferred_io_cleanup);
51602 diff --git a/drivers/video/fbmem.c b/drivers/video/fbmem.c
51603 index 010d191..7b8235a 100644
51604 --- a/drivers/video/fbmem.c
51605 +++ b/drivers/video/fbmem.c
51606 @@ -433,7 +433,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
51607 image->dx += image->width + 8;
51608 }
51609 } else if (rotate == FB_ROTATE_UD) {
51610 - for (x = 0; x < num && image->dx >= 0; x++) {
51611 + for (x = 0; x < num && (__s32)image->dx >= 0; x++) {
51612 info->fbops->fb_imageblit(info, image);
51613 image->dx -= image->width + 8;
51614 }
51615 @@ -445,7 +445,7 @@ static void fb_do_show_logo(struct fb_info *info, struct fb_image *image,
51616 image->dy += image->height + 8;
51617 }
51618 } else if (rotate == FB_ROTATE_CCW) {
51619 - for (x = 0; x < num && image->dy >= 0; x++) {
51620 + for (x = 0; x < num && (__s32)image->dy >= 0; x++) {
51621 info->fbops->fb_imageblit(info, image);
51622 image->dy -= image->height + 8;
51623 }
51624 @@ -1179,7 +1179,7 @@ static long do_fb_ioctl(struct fb_info *info, unsigned int cmd,
51625 return -EFAULT;
51626 if (con2fb.console < 1 || con2fb.console > MAX_NR_CONSOLES)
51627 return -EINVAL;
51628 - if (con2fb.framebuffer < 0 || con2fb.framebuffer >= FB_MAX)
51629 + if (con2fb.framebuffer >= FB_MAX)
51630 return -EINVAL;
51631 if (!registered_fb[con2fb.framebuffer])
51632 request_module("fb%d", con2fb.framebuffer);
51633 @@ -1300,7 +1300,7 @@ static int do_fscreeninfo_to_user(struct fb_fix_screeninfo *fix,
51634 __u32 data;
51635 int err;
51636
51637 - err = copy_to_user(&fix32->id, &fix->id, sizeof(fix32->id));
51638 + err = copy_to_user(fix32->id, &fix->id, sizeof(fix32->id));
51639
51640 data = (__u32) (unsigned long) fix->smem_start;
51641 err |= put_user(data, &fix32->smem_start);
51642 diff --git a/drivers/video/hyperv_fb.c b/drivers/video/hyperv_fb.c
51643 index 130708f..cdac1a9 100644
51644 --- a/drivers/video/hyperv_fb.c
51645 +++ b/drivers/video/hyperv_fb.c
51646 @@ -233,7 +233,7 @@ static uint screen_fb_size;
51647 static inline int synthvid_send(struct hv_device *hdev,
51648 struct synthvid_msg *msg)
51649 {
51650 - static atomic64_t request_id = ATOMIC64_INIT(0);
51651 + static atomic64_unchecked_t request_id = ATOMIC64_INIT(0);
51652 int ret;
51653
51654 msg->pipe_hdr.type = PIPE_MSG_DATA;
51655 @@ -241,7 +241,7 @@ static inline int synthvid_send(struct hv_device *hdev,
51656
51657 ret = vmbus_sendpacket(hdev->channel, msg,
51658 msg->vid_hdr.size + sizeof(struct pipe_msg_hdr),
51659 - atomic64_inc_return(&request_id),
51660 + atomic64_inc_return_unchecked(&request_id),
51661 VM_PKT_DATA_INBAND, 0);
51662
51663 if (ret)
51664 diff --git a/drivers/video/i810/i810_accel.c b/drivers/video/i810/i810_accel.c
51665 index 7672d2e..b56437f 100644
51666 --- a/drivers/video/i810/i810_accel.c
51667 +++ b/drivers/video/i810/i810_accel.c
51668 @@ -73,6 +73,7 @@ static inline int wait_for_space(struct fb_info *info, u32 space)
51669 }
51670 }
51671 printk("ringbuffer lockup!!!\n");
51672 + printk("head:%u tail:%u iring.size:%u space:%u\n", head, tail, par->iring.size, space);
51673 i810_report_error(mmio);
51674 par->dev_flags |= LOCKUP;
51675 info->pixmap.scan_align = 1;
51676 diff --git a/drivers/video/logo/logo_linux_clut224.ppm b/drivers/video/logo/logo_linux_clut224.ppm
51677 index 3c14e43..2630570 100644
51678 --- a/drivers/video/logo/logo_linux_clut224.ppm
51679 +++ b/drivers/video/logo/logo_linux_clut224.ppm
51680 @@ -2,1603 +2,1123 @@ P3
51681 # Standard 224-color Linux logo
51682 80 80
51683 255
51684 - 0 0 0 0 0 0 0 0 0 0 0 0
51685 - 0 0 0 0 0 0 0 0 0 0 0 0
51686 - 0 0 0 0 0 0 0 0 0 0 0 0
51687 - 0 0 0 0 0 0 0 0 0 0 0 0
51688 - 0 0 0 0 0 0 0 0 0 0 0 0
51689 - 0 0 0 0 0 0 0 0 0 0 0 0
51690 - 0 0 0 0 0 0 0 0 0 0 0 0
51691 - 0 0 0 0 0 0 0 0 0 0 0 0
51692 - 0 0 0 0 0 0 0 0 0 0 0 0
51693 - 6 6 6 6 6 6 10 10 10 10 10 10
51694 - 10 10 10 6 6 6 6 6 6 6 6 6
51695 - 0 0 0 0 0 0 0 0 0 0 0 0
51696 - 0 0 0 0 0 0 0 0 0 0 0 0
51697 - 0 0 0 0 0 0 0 0 0 0 0 0
51698 - 0 0 0 0 0 0 0 0 0 0 0 0
51699 - 0 0 0 0 0 0 0 0 0 0 0 0
51700 - 0 0 0 0 0 0 0 0 0 0 0 0
51701 - 0 0 0 0 0 0 0 0 0 0 0 0
51702 - 0 0 0 0 0 0 0 0 0 0 0 0
51703 - 0 0 0 0 0 0 0 0 0 0 0 0
51704 - 0 0 0 0 0 0 0 0 0 0 0 0
51705 - 0 0 0 0 0 0 0 0 0 0 0 0
51706 - 0 0 0 0 0 0 0 0 0 0 0 0
51707 - 0 0 0 0 0 0 0 0 0 0 0 0
51708 - 0 0 0 0 0 0 0 0 0 0 0 0
51709 - 0 0 0 0 0 0 0 0 0 0 0 0
51710 - 0 0 0 0 0 0 0 0 0 0 0 0
51711 - 0 0 0 0 0 0 0 0 0 0 0 0
51712 - 0 0 0 6 6 6 10 10 10 14 14 14
51713 - 22 22 22 26 26 26 30 30 30 34 34 34
51714 - 30 30 30 30 30 30 26 26 26 18 18 18
51715 - 14 14 14 10 10 10 6 6 6 0 0 0
51716 - 0 0 0 0 0 0 0 0 0 0 0 0
51717 - 0 0 0 0 0 0 0 0 0 0 0 0
51718 - 0 0 0 0 0 0 0 0 0 0 0 0
51719 - 0 0 0 0 0 0 0 0 0 0 0 0
51720 - 0 0 0 0 0 0 0 0 0 0 0 0
51721 - 0 0 0 0 0 0 0 0 0 0 0 0
51722 - 0 0 0 0 0 0 0 0 0 0 0 0
51723 - 0 0 0 0 0 0 0 0 0 0 0 0
51724 - 0 0 0 0 0 0 0 0 0 0 0 0
51725 - 0 0 0 0 0 1 0 0 1 0 0 0
51726 - 0 0 0 0 0 0 0 0 0 0 0 0
51727 - 0 0 0 0 0 0 0 0 0 0 0 0
51728 - 0 0 0 0 0 0 0 0 0 0 0 0
51729 - 0 0 0 0 0 0 0 0 0 0 0 0
51730 - 0 0 0 0 0 0 0 0 0 0 0 0
51731 - 0 0 0 0 0 0 0 0 0 0 0 0
51732 - 6 6 6 14 14 14 26 26 26 42 42 42
51733 - 54 54 54 66 66 66 78 78 78 78 78 78
51734 - 78 78 78 74 74 74 66 66 66 54 54 54
51735 - 42 42 42 26 26 26 18 18 18 10 10 10
51736 - 6 6 6 0 0 0 0 0 0 0 0 0
51737 - 0 0 0 0 0 0 0 0 0 0 0 0
51738 - 0 0 0 0 0 0 0 0 0 0 0 0
51739 - 0 0 0 0 0 0 0 0 0 0 0 0
51740 - 0 0 0 0 0 0 0 0 0 0 0 0
51741 - 0 0 0 0 0 0 0 0 0 0 0 0
51742 - 0 0 0 0 0 0 0 0 0 0 0 0
51743 - 0 0 0 0 0 0 0 0 0 0 0 0
51744 - 0 0 0 0 0 0 0 0 0 0 0 0
51745 - 0 0 1 0 0 0 0 0 0 0 0 0
51746 - 0 0 0 0 0 0 0 0 0 0 0 0
51747 - 0 0 0 0 0 0 0 0 0 0 0 0
51748 - 0 0 0 0 0 0 0 0 0 0 0 0
51749 - 0 0 0 0 0 0 0 0 0 0 0 0
51750 - 0 0 0 0 0 0 0 0 0 0 0 0
51751 - 0 0 0 0 0 0 0 0 0 10 10 10
51752 - 22 22 22 42 42 42 66 66 66 86 86 86
51753 - 66 66 66 38 38 38 38 38 38 22 22 22
51754 - 26 26 26 34 34 34 54 54 54 66 66 66
51755 - 86 86 86 70 70 70 46 46 46 26 26 26
51756 - 14 14 14 6 6 6 0 0 0 0 0 0
51757 - 0 0 0 0 0 0 0 0 0 0 0 0
51758 - 0 0 0 0 0 0 0 0 0 0 0 0
51759 - 0 0 0 0 0 0 0 0 0 0 0 0
51760 - 0 0 0 0 0 0 0 0 0 0 0 0
51761 - 0 0 0 0 0 0 0 0 0 0 0 0
51762 - 0 0 0 0 0 0 0 0 0 0 0 0
51763 - 0 0 0 0 0 0 0 0 0 0 0 0
51764 - 0 0 0 0 0 0 0 0 0 0 0 0
51765 - 0 0 1 0 0 1 0 0 1 0 0 0
51766 - 0 0 0 0 0 0 0 0 0 0 0 0
51767 - 0 0 0 0 0 0 0 0 0 0 0 0
51768 - 0 0 0 0 0 0 0 0 0 0 0 0
51769 - 0 0 0 0 0 0 0 0 0 0 0 0
51770 - 0 0 0 0 0 0 0 0 0 0 0 0
51771 - 0 0 0 0 0 0 10 10 10 26 26 26
51772 - 50 50 50 82 82 82 58 58 58 6 6 6
51773 - 2 2 6 2 2 6 2 2 6 2 2 6
51774 - 2 2 6 2 2 6 2 2 6 2 2 6
51775 - 6 6 6 54 54 54 86 86 86 66 66 66
51776 - 38 38 38 18 18 18 6 6 6 0 0 0
51777 - 0 0 0 0 0 0 0 0 0 0 0 0
51778 - 0 0 0 0 0 0 0 0 0 0 0 0
51779 - 0 0 0 0 0 0 0 0 0 0 0 0
51780 - 0 0 0 0 0 0 0 0 0 0 0 0
51781 - 0 0 0 0 0 0 0 0 0 0 0 0
51782 - 0 0 0 0 0 0 0 0 0 0 0 0
51783 - 0 0 0 0 0 0 0 0 0 0 0 0
51784 - 0 0 0 0 0 0 0 0 0 0 0 0
51785 - 0 0 0 0 0 0 0 0 0 0 0 0
51786 - 0 0 0 0 0 0 0 0 0 0 0 0
51787 - 0 0 0 0 0 0 0 0 0 0 0 0
51788 - 0 0 0 0 0 0 0 0 0 0 0 0
51789 - 0 0 0 0 0 0 0 0 0 0 0 0
51790 - 0 0 0 0 0 0 0 0 0 0 0 0
51791 - 0 0 0 6 6 6 22 22 22 50 50 50
51792 - 78 78 78 34 34 34 2 2 6 2 2 6
51793 - 2 2 6 2 2 6 2 2 6 2 2 6
51794 - 2 2 6 2 2 6 2 2 6 2 2 6
51795 - 2 2 6 2 2 6 6 6 6 70 70 70
51796 - 78 78 78 46 46 46 22 22 22 6 6 6
51797 - 0 0 0 0 0 0 0 0 0 0 0 0
51798 - 0 0 0 0 0 0 0 0 0 0 0 0
51799 - 0 0 0 0 0 0 0 0 0 0 0 0
51800 - 0 0 0 0 0 0 0 0 0 0 0 0
51801 - 0 0 0 0 0 0 0 0 0 0 0 0
51802 - 0 0 0 0 0 0 0 0 0 0 0 0
51803 - 0 0 0 0 0 0 0 0 0 0 0 0
51804 - 0 0 0 0 0 0 0 0 0 0 0 0
51805 - 0 0 1 0 0 1 0 0 1 0 0 0
51806 - 0 0 0 0 0 0 0 0 0 0 0 0
51807 - 0 0 0 0 0 0 0 0 0 0 0 0
51808 - 0 0 0 0 0 0 0 0 0 0 0 0
51809 - 0 0 0 0 0 0 0 0 0 0 0 0
51810 - 0 0 0 0 0 0 0 0 0 0 0 0
51811 - 6 6 6 18 18 18 42 42 42 82 82 82
51812 - 26 26 26 2 2 6 2 2 6 2 2 6
51813 - 2 2 6 2 2 6 2 2 6 2 2 6
51814 - 2 2 6 2 2 6 2 2 6 14 14 14
51815 - 46 46 46 34 34 34 6 6 6 2 2 6
51816 - 42 42 42 78 78 78 42 42 42 18 18 18
51817 - 6 6 6 0 0 0 0 0 0 0 0 0
51818 - 0 0 0 0 0 0 0 0 0 0 0 0
51819 - 0 0 0 0 0 0 0 0 0 0 0 0
51820 - 0 0 0 0 0 0 0 0 0 0 0 0
51821 - 0 0 0 0 0 0 0 0 0 0 0 0
51822 - 0 0 0 0 0 0 0 0 0 0 0 0
51823 - 0 0 0 0 0 0 0 0 0 0 0 0
51824 - 0 0 0 0 0 0 0 0 0 0 0 0
51825 - 0 0 1 0 0 0 0 0 1 0 0 0
51826 - 0 0 0 0 0 0 0 0 0 0 0 0
51827 - 0 0 0 0 0 0 0 0 0 0 0 0
51828 - 0 0 0 0 0 0 0 0 0 0 0 0
51829 - 0 0 0 0 0 0 0 0 0 0 0 0
51830 - 0 0 0 0 0 0 0 0 0 0 0 0
51831 - 10 10 10 30 30 30 66 66 66 58 58 58
51832 - 2 2 6 2 2 6 2 2 6 2 2 6
51833 - 2 2 6 2 2 6 2 2 6 2 2 6
51834 - 2 2 6 2 2 6 2 2 6 26 26 26
51835 - 86 86 86 101 101 101 46 46 46 10 10 10
51836 - 2 2 6 58 58 58 70 70 70 34 34 34
51837 - 10 10 10 0 0 0 0 0 0 0 0 0
51838 - 0 0 0 0 0 0 0 0 0 0 0 0
51839 - 0 0 0 0 0 0 0 0 0 0 0 0
51840 - 0 0 0 0 0 0 0 0 0 0 0 0
51841 - 0 0 0 0 0 0 0 0 0 0 0 0
51842 - 0 0 0 0 0 0 0 0 0 0 0 0
51843 - 0 0 0 0 0 0 0 0 0 0 0 0
51844 - 0 0 0 0 0 0 0 0 0 0 0 0
51845 - 0 0 1 0 0 1 0 0 1 0 0 0
51846 - 0 0 0 0 0 0 0 0 0 0 0 0
51847 - 0 0 0 0 0 0 0 0 0 0 0 0
51848 - 0 0 0 0 0 0 0 0 0 0 0 0
51849 - 0 0 0 0 0 0 0 0 0 0 0 0
51850 - 0 0 0 0 0 0 0 0 0 0 0 0
51851 - 14 14 14 42 42 42 86 86 86 10 10 10
51852 - 2 2 6 2 2 6 2 2 6 2 2 6
51853 - 2 2 6 2 2 6 2 2 6 2 2 6
51854 - 2 2 6 2 2 6 2 2 6 30 30 30
51855 - 94 94 94 94 94 94 58 58 58 26 26 26
51856 - 2 2 6 6 6 6 78 78 78 54 54 54
51857 - 22 22 22 6 6 6 0 0 0 0 0 0
51858 - 0 0 0 0 0 0 0 0 0 0 0 0
51859 - 0 0 0 0 0 0 0 0 0 0 0 0
51860 - 0 0 0 0 0 0 0 0 0 0 0 0
51861 - 0 0 0 0 0 0 0 0 0 0 0 0
51862 - 0 0 0 0 0 0 0 0 0 0 0 0
51863 - 0 0 0 0 0 0 0 0 0 0 0 0
51864 - 0 0 0 0 0 0 0 0 0 0 0 0
51865 - 0 0 0 0 0 0 0 0 0 0 0 0
51866 - 0 0 0 0 0 0 0 0 0 0 0 0
51867 - 0 0 0 0 0 0 0 0 0 0 0 0
51868 - 0 0 0 0 0 0 0 0 0 0 0 0
51869 - 0 0 0 0 0 0 0 0 0 0 0 0
51870 - 0 0 0 0 0 0 0 0 0 6 6 6
51871 - 22 22 22 62 62 62 62 62 62 2 2 6
51872 - 2 2 6 2 2 6 2 2 6 2 2 6
51873 - 2 2 6 2 2 6 2 2 6 2 2 6
51874 - 2 2 6 2 2 6 2 2 6 26 26 26
51875 - 54 54 54 38 38 38 18 18 18 10 10 10
51876 - 2 2 6 2 2 6 34 34 34 82 82 82
51877 - 38 38 38 14 14 14 0 0 0 0 0 0
51878 - 0 0 0 0 0 0 0 0 0 0 0 0
51879 - 0 0 0 0 0 0 0 0 0 0 0 0
51880 - 0 0 0 0 0 0 0 0 0 0 0 0
51881 - 0 0 0 0 0 0 0 0 0 0 0 0
51882 - 0 0 0 0 0 0 0 0 0 0 0 0
51883 - 0 0 0 0 0 0 0 0 0 0 0 0
51884 - 0 0 0 0 0 0 0 0 0 0 0 0
51885 - 0 0 0 0 0 1 0 0 1 0 0 0
51886 - 0 0 0 0 0 0 0 0 0 0 0 0
51887 - 0 0 0 0 0 0 0 0 0 0 0 0
51888 - 0 0 0 0 0 0 0 0 0 0 0 0
51889 - 0 0 0 0 0 0 0 0 0 0 0 0
51890 - 0 0 0 0 0 0 0 0 0 6 6 6
51891 - 30 30 30 78 78 78 30 30 30 2 2 6
51892 - 2 2 6 2 2 6 2 2 6 2 2 6
51893 - 2 2 6 2 2 6 2 2 6 2 2 6
51894 - 2 2 6 2 2 6 2 2 6 10 10 10
51895 - 10 10 10 2 2 6 2 2 6 2 2 6
51896 - 2 2 6 2 2 6 2 2 6 78 78 78
51897 - 50 50 50 18 18 18 6 6 6 0 0 0
51898 - 0 0 0 0 0 0 0 0 0 0 0 0
51899 - 0 0 0 0 0 0 0 0 0 0 0 0
51900 - 0 0 0 0 0 0 0 0 0 0 0 0
51901 - 0 0 0 0 0 0 0 0 0 0 0 0
51902 - 0 0 0 0 0 0 0 0 0 0 0 0
51903 - 0 0 0 0 0 0 0 0 0 0 0 0
51904 - 0 0 0 0 0 0 0 0 0 0 0 0
51905 - 0 0 1 0 0 0 0 0 0 0 0 0
51906 - 0 0 0 0 0 0 0 0 0 0 0 0
51907 - 0 0 0 0 0 0 0 0 0 0 0 0
51908 - 0 0 0 0 0 0 0 0 0 0 0 0
51909 - 0 0 0 0 0 0 0 0 0 0 0 0
51910 - 0 0 0 0 0 0 0 0 0 10 10 10
51911 - 38 38 38 86 86 86 14 14 14 2 2 6
51912 - 2 2 6 2 2 6 2 2 6 2 2 6
51913 - 2 2 6 2 2 6 2 2 6 2 2 6
51914 - 2 2 6 2 2 6 2 2 6 2 2 6
51915 - 2 2 6 2 2 6 2 2 6 2 2 6
51916 - 2 2 6 2 2 6 2 2 6 54 54 54
51917 - 66 66 66 26 26 26 6 6 6 0 0 0
51918 - 0 0 0 0 0 0 0 0 0 0 0 0
51919 - 0 0 0 0 0 0 0 0 0 0 0 0
51920 - 0 0 0 0 0 0 0 0 0 0 0 0
51921 - 0 0 0 0 0 0 0 0 0 0 0 0
51922 - 0 0 0 0 0 0 0 0 0 0 0 0
51923 - 0 0 0 0 0 0 0 0 0 0 0 0
51924 - 0 0 0 0 0 0 0 0 0 0 0 0
51925 - 0 0 0 0 0 1 0 0 1 0 0 0
51926 - 0 0 0 0 0 0 0 0 0 0 0 0
51927 - 0 0 0 0 0 0 0 0 0 0 0 0
51928 - 0 0 0 0 0 0 0 0 0 0 0 0
51929 - 0 0 0 0 0 0 0 0 0 0 0 0
51930 - 0 0 0 0 0 0 0 0 0 14 14 14
51931 - 42 42 42 82 82 82 2 2 6 2 2 6
51932 - 2 2 6 6 6 6 10 10 10 2 2 6
51933 - 2 2 6 2 2 6 2 2 6 2 2 6
51934 - 2 2 6 2 2 6 2 2 6 6 6 6
51935 - 14 14 14 10 10 10 2 2 6 2 2 6
51936 - 2 2 6 2 2 6 2 2 6 18 18 18
51937 - 82 82 82 34 34 34 10 10 10 0 0 0
51938 - 0 0 0 0 0 0 0 0 0 0 0 0
51939 - 0 0 0 0 0 0 0 0 0 0 0 0
51940 - 0 0 0 0 0 0 0 0 0 0 0 0
51941 - 0 0 0 0 0 0 0 0 0 0 0 0
51942 - 0 0 0 0 0 0 0 0 0 0 0 0
51943 - 0 0 0 0 0 0 0 0 0 0 0 0
51944 - 0 0 0 0 0 0 0 0 0 0 0 0
51945 - 0 0 1 0 0 0 0 0 0 0 0 0
51946 - 0 0 0 0 0 0 0 0 0 0 0 0
51947 - 0 0 0 0 0 0 0 0 0 0 0 0
51948 - 0 0 0 0 0 0 0 0 0 0 0 0
51949 - 0 0 0 0 0 0 0 0 0 0 0 0
51950 - 0 0 0 0 0 0 0 0 0 14 14 14
51951 - 46 46 46 86 86 86 2 2 6 2 2 6
51952 - 6 6 6 6 6 6 22 22 22 34 34 34
51953 - 6 6 6 2 2 6 2 2 6 2 2 6
51954 - 2 2 6 2 2 6 18 18 18 34 34 34
51955 - 10 10 10 50 50 50 22 22 22 2 2 6
51956 - 2 2 6 2 2 6 2 2 6 10 10 10
51957 - 86 86 86 42 42 42 14 14 14 0 0 0
51958 - 0 0 0 0 0 0 0 0 0 0 0 0
51959 - 0 0 0 0 0 0 0 0 0 0 0 0
51960 - 0 0 0 0 0 0 0 0 0 0 0 0
51961 - 0 0 0 0 0 0 0 0 0 0 0 0
51962 - 0 0 0 0 0 0 0 0 0 0 0 0
51963 - 0 0 0 0 0 0 0 0 0 0 0 0
51964 - 0 0 0 0 0 0 0 0 0 0 0 0
51965 - 0 0 1 0 0 1 0 0 1 0 0 0
51966 - 0 0 0 0 0 0 0 0 0 0 0 0
51967 - 0 0 0 0 0 0 0 0 0 0 0 0
51968 - 0 0 0 0 0 0 0 0 0 0 0 0
51969 - 0 0 0 0 0 0 0 0 0 0 0 0
51970 - 0 0 0 0 0 0 0 0 0 14 14 14
51971 - 46 46 46 86 86 86 2 2 6 2 2 6
51972 - 38 38 38 116 116 116 94 94 94 22 22 22
51973 - 22 22 22 2 2 6 2 2 6 2 2 6
51974 - 14 14 14 86 86 86 138 138 138 162 162 162
51975 -154 154 154 38 38 38 26 26 26 6 6 6
51976 - 2 2 6 2 2 6 2 2 6 2 2 6
51977 - 86 86 86 46 46 46 14 14 14 0 0 0
51978 - 0 0 0 0 0 0 0 0 0 0 0 0
51979 - 0 0 0 0 0 0 0 0 0 0 0 0
51980 - 0 0 0 0 0 0 0 0 0 0 0 0
51981 - 0 0 0 0 0 0 0 0 0 0 0 0
51982 - 0 0 0 0 0 0 0 0 0 0 0 0
51983 - 0 0 0 0 0 0 0 0 0 0 0 0
51984 - 0 0 0 0 0 0 0 0 0 0 0 0
51985 - 0 0 0 0 0 0 0 0 0 0 0 0
51986 - 0 0 0 0 0 0 0 0 0 0 0 0
51987 - 0 0 0 0 0 0 0 0 0 0 0 0
51988 - 0 0 0 0 0 0 0 0 0 0 0 0
51989 - 0 0 0 0 0 0 0 0 0 0 0 0
51990 - 0 0 0 0 0 0 0 0 0 14 14 14
51991 - 46 46 46 86 86 86 2 2 6 14 14 14
51992 -134 134 134 198 198 198 195 195 195 116 116 116
51993 - 10 10 10 2 2 6 2 2 6 6 6 6
51994 -101 98 89 187 187 187 210 210 210 218 218 218
51995 -214 214 214 134 134 134 14 14 14 6 6 6
51996 - 2 2 6 2 2 6 2 2 6 2 2 6
51997 - 86 86 86 50 50 50 18 18 18 6 6 6
51998 - 0 0 0 0 0 0 0 0 0 0 0 0
51999 - 0 0 0 0 0 0 0 0 0 0 0 0
52000 - 0 0 0 0 0 0 0 0 0 0 0 0
52001 - 0 0 0 0 0 0 0 0 0 0 0 0
52002 - 0 0 0 0 0 0 0 0 0 0 0 0
52003 - 0 0 0 0 0 0 0 0 0 0 0 0
52004 - 0 0 0 0 0 0 0 0 1 0 0 0
52005 - 0 0 1 0 0 1 0 0 1 0 0 0
52006 - 0 0 0 0 0 0 0 0 0 0 0 0
52007 - 0 0 0 0 0 0 0 0 0 0 0 0
52008 - 0 0 0 0 0 0 0 0 0 0 0 0
52009 - 0 0 0 0 0 0 0 0 0 0 0 0
52010 - 0 0 0 0 0 0 0 0 0 14 14 14
52011 - 46 46 46 86 86 86 2 2 6 54 54 54
52012 -218 218 218 195 195 195 226 226 226 246 246 246
52013 - 58 58 58 2 2 6 2 2 6 30 30 30
52014 -210 210 210 253 253 253 174 174 174 123 123 123
52015 -221 221 221 234 234 234 74 74 74 2 2 6
52016 - 2 2 6 2 2 6 2 2 6 2 2 6
52017 - 70 70 70 58 58 58 22 22 22 6 6 6
52018 - 0 0 0 0 0 0 0 0 0 0 0 0
52019 - 0 0 0 0 0 0 0 0 0 0 0 0
52020 - 0 0 0 0 0 0 0 0 0 0 0 0
52021 - 0 0 0 0 0 0 0 0 0 0 0 0
52022 - 0 0 0 0 0 0 0 0 0 0 0 0
52023 - 0 0 0 0 0 0 0 0 0 0 0 0
52024 - 0 0 0 0 0 0 0 0 0 0 0 0
52025 - 0 0 0 0 0 0 0 0 0 0 0 0
52026 - 0 0 0 0 0 0 0 0 0 0 0 0
52027 - 0 0 0 0 0 0 0 0 0 0 0 0
52028 - 0 0 0 0 0 0 0 0 0 0 0 0
52029 - 0 0 0 0 0 0 0 0 0 0 0 0
52030 - 0 0 0 0 0 0 0 0 0 14 14 14
52031 - 46 46 46 82 82 82 2 2 6 106 106 106
52032 -170 170 170 26 26 26 86 86 86 226 226 226
52033 -123 123 123 10 10 10 14 14 14 46 46 46
52034 -231 231 231 190 190 190 6 6 6 70 70 70
52035 - 90 90 90 238 238 238 158 158 158 2 2 6
52036 - 2 2 6 2 2 6 2 2 6 2 2 6
52037 - 70 70 70 58 58 58 22 22 22 6 6 6
52038 - 0 0 0 0 0 0 0 0 0 0 0 0
52039 - 0 0 0 0 0 0 0 0 0 0 0 0
52040 - 0 0 0 0 0 0 0 0 0 0 0 0
52041 - 0 0 0 0 0 0 0 0 0 0 0 0
52042 - 0 0 0 0 0 0 0 0 0 0 0 0
52043 - 0 0 0 0 0 0 0 0 0 0 0 0
52044 - 0 0 0 0 0 0 0 0 1 0 0 0
52045 - 0 0 1 0 0 1 0 0 1 0 0 0
52046 - 0 0 0 0 0 0 0 0 0 0 0 0
52047 - 0 0 0 0 0 0 0 0 0 0 0 0
52048 - 0 0 0 0 0 0 0 0 0 0 0 0
52049 - 0 0 0 0 0 0 0 0 0 0 0 0
52050 - 0 0 0 0 0 0 0 0 0 14 14 14
52051 - 42 42 42 86 86 86 6 6 6 116 116 116
52052 -106 106 106 6 6 6 70 70 70 149 149 149
52053 -128 128 128 18 18 18 38 38 38 54 54 54
52054 -221 221 221 106 106 106 2 2 6 14 14 14
52055 - 46 46 46 190 190 190 198 198 198 2 2 6
52056 - 2 2 6 2 2 6 2 2 6 2 2 6
52057 - 74 74 74 62 62 62 22 22 22 6 6 6
52058 - 0 0 0 0 0 0 0 0 0 0 0 0
52059 - 0 0 0 0 0 0 0 0 0 0 0 0
52060 - 0 0 0 0 0 0 0 0 0 0 0 0
52061 - 0 0 0 0 0 0 0 0 0 0 0 0
52062 - 0 0 0 0 0 0 0 0 0 0 0 0
52063 - 0 0 0 0 0 0 0 0 0 0 0 0
52064 - 0 0 0 0 0 0 0 0 1 0 0 0
52065 - 0 0 1 0 0 0 0 0 1 0 0 0
52066 - 0 0 0 0 0 0 0 0 0 0 0 0
52067 - 0 0 0 0 0 0 0 0 0 0 0 0
52068 - 0 0 0 0 0 0 0 0 0 0 0 0
52069 - 0 0 0 0 0 0 0 0 0 0 0 0
52070 - 0 0 0 0 0 0 0 0 0 14 14 14
52071 - 42 42 42 94 94 94 14 14 14 101 101 101
52072 -128 128 128 2 2 6 18 18 18 116 116 116
52073 -118 98 46 121 92 8 121 92 8 98 78 10
52074 -162 162 162 106 106 106 2 2 6 2 2 6
52075 - 2 2 6 195 195 195 195 195 195 6 6 6
52076 - 2 2 6 2 2 6 2 2 6 2 2 6
52077 - 74 74 74 62 62 62 22 22 22 6 6 6
52078 - 0 0 0 0 0 0 0 0 0 0 0 0
52079 - 0 0 0 0 0 0 0 0 0 0 0 0
52080 - 0 0 0 0 0 0 0 0 0 0 0 0
52081 - 0 0 0 0 0 0 0 0 0 0 0 0
52082 - 0 0 0 0 0 0 0 0 0 0 0 0
52083 - 0 0 0 0 0 0 0 0 0 0 0 0
52084 - 0 0 0 0 0 0 0 0 1 0 0 1
52085 - 0 0 1 0 0 0 0 0 1 0 0 0
52086 - 0 0 0 0 0 0 0 0 0 0 0 0
52087 - 0 0 0 0 0 0 0 0 0 0 0 0
52088 - 0 0 0 0 0 0 0 0 0 0 0 0
52089 - 0 0 0 0 0 0 0 0 0 0 0 0
52090 - 0 0 0 0 0 0 0 0 0 10 10 10
52091 - 38 38 38 90 90 90 14 14 14 58 58 58
52092 -210 210 210 26 26 26 54 38 6 154 114 10
52093 -226 170 11 236 186 11 225 175 15 184 144 12
52094 -215 174 15 175 146 61 37 26 9 2 2 6
52095 - 70 70 70 246 246 246 138 138 138 2 2 6
52096 - 2 2 6 2 2 6 2 2 6 2 2 6
52097 - 70 70 70 66 66 66 26 26 26 6 6 6
52098 - 0 0 0 0 0 0 0 0 0 0 0 0
52099 - 0 0 0 0 0 0 0 0 0 0 0 0
52100 - 0 0 0 0 0 0 0 0 0 0 0 0
52101 - 0 0 0 0 0 0 0 0 0 0 0 0
52102 - 0 0 0 0 0 0 0 0 0 0 0 0
52103 - 0 0 0 0 0 0 0 0 0 0 0 0
52104 - 0 0 0 0 0 0 0 0 0 0 0 0
52105 - 0 0 0 0 0 0 0 0 0 0 0 0
52106 - 0 0 0 0 0 0 0 0 0 0 0 0
52107 - 0 0 0 0 0 0 0 0 0 0 0 0
52108 - 0 0 0 0 0 0 0 0 0 0 0 0
52109 - 0 0 0 0 0 0 0 0 0 0 0 0
52110 - 0 0 0 0 0 0 0 0 0 10 10 10
52111 - 38 38 38 86 86 86 14 14 14 10 10 10
52112 -195 195 195 188 164 115 192 133 9 225 175 15
52113 -239 182 13 234 190 10 232 195 16 232 200 30
52114 -245 207 45 241 208 19 232 195 16 184 144 12
52115 -218 194 134 211 206 186 42 42 42 2 2 6
52116 - 2 2 6 2 2 6 2 2 6 2 2 6
52117 - 50 50 50 74 74 74 30 30 30 6 6 6
52118 - 0 0 0 0 0 0 0 0 0 0 0 0
52119 - 0 0 0 0 0 0 0 0 0 0 0 0
52120 - 0 0 0 0 0 0 0 0 0 0 0 0
52121 - 0 0 0 0 0 0 0 0 0 0 0 0
52122 - 0 0 0 0 0 0 0 0 0 0 0 0
52123 - 0 0 0 0 0 0 0 0 0 0 0 0
52124 - 0 0 0 0 0 0 0 0 0 0 0 0
52125 - 0 0 0 0 0 0 0 0 0 0 0 0
52126 - 0 0 0 0 0 0 0 0 0 0 0 0
52127 - 0 0 0 0 0 0 0 0 0 0 0 0
52128 - 0 0 0 0 0 0 0 0 0 0 0 0
52129 - 0 0 0 0 0 0 0 0 0 0 0 0
52130 - 0 0 0 0 0 0 0 0 0 10 10 10
52131 - 34 34 34 86 86 86 14 14 14 2 2 6
52132 -121 87 25 192 133 9 219 162 10 239 182 13
52133 -236 186 11 232 195 16 241 208 19 244 214 54
52134 -246 218 60 246 218 38 246 215 20 241 208 19
52135 -241 208 19 226 184 13 121 87 25 2 2 6
52136 - 2 2 6 2 2 6 2 2 6 2 2 6
52137 - 50 50 50 82 82 82 34 34 34 10 10 10
52138 - 0 0 0 0 0 0 0 0 0 0 0 0
52139 - 0 0 0 0 0 0 0 0 0 0 0 0
52140 - 0 0 0 0 0 0 0 0 0 0 0 0
52141 - 0 0 0 0 0 0 0 0 0 0 0 0
52142 - 0 0 0 0 0 0 0 0 0 0 0 0
52143 - 0 0 0 0 0 0 0 0 0 0 0 0
52144 - 0 0 0 0 0 0 0 0 0 0 0 0
52145 - 0 0 0 0 0 0 0 0 0 0 0 0
52146 - 0 0 0 0 0 0 0 0 0 0 0 0
52147 - 0 0 0 0 0 0 0 0 0 0 0 0
52148 - 0 0 0 0 0 0 0 0 0 0 0 0
52149 - 0 0 0 0 0 0 0 0 0 0 0 0
52150 - 0 0 0 0 0 0 0 0 0 10 10 10
52151 - 34 34 34 82 82 82 30 30 30 61 42 6
52152 -180 123 7 206 145 10 230 174 11 239 182 13
52153 -234 190 10 238 202 15 241 208 19 246 218 74
52154 -246 218 38 246 215 20 246 215 20 246 215 20
52155 -226 184 13 215 174 15 184 144 12 6 6 6
52156 - 2 2 6 2 2 6 2 2 6 2 2 6
52157 - 26 26 26 94 94 94 42 42 42 14 14 14
52158 - 0 0 0 0 0 0 0 0 0 0 0 0
52159 - 0 0 0 0 0 0 0 0 0 0 0 0
52160 - 0 0 0 0 0 0 0 0 0 0 0 0
52161 - 0 0 0 0 0 0 0 0 0 0 0 0
52162 - 0 0 0 0 0 0 0 0 0 0 0 0
52163 - 0 0 0 0 0 0 0 0 0 0 0 0
52164 - 0 0 0 0 0 0 0 0 0 0 0 0
52165 - 0 0 0 0 0 0 0 0 0 0 0 0
52166 - 0 0 0 0 0 0 0 0 0 0 0 0
52167 - 0 0 0 0 0 0 0 0 0 0 0 0
52168 - 0 0 0 0 0 0 0 0 0 0 0 0
52169 - 0 0 0 0 0 0 0 0 0 0 0 0
52170 - 0 0 0 0 0 0 0 0 0 10 10 10
52171 - 30 30 30 78 78 78 50 50 50 104 69 6
52172 -192 133 9 216 158 10 236 178 12 236 186 11
52173 -232 195 16 241 208 19 244 214 54 245 215 43
52174 -246 215 20 246 215 20 241 208 19 198 155 10
52175 -200 144 11 216 158 10 156 118 10 2 2 6
52176 - 2 2 6 2 2 6 2 2 6 2 2 6
52177 - 6 6 6 90 90 90 54 54 54 18 18 18
52178 - 6 6 6 0 0 0 0 0 0 0 0 0
52179 - 0 0 0 0 0 0 0 0 0 0 0 0
52180 - 0 0 0 0 0 0 0 0 0 0 0 0
52181 - 0 0 0 0 0 0 0 0 0 0 0 0
52182 - 0 0 0 0 0 0 0 0 0 0 0 0
52183 - 0 0 0 0 0 0 0 0 0 0 0 0
52184 - 0 0 0 0 0 0 0 0 0 0 0 0
52185 - 0 0 0 0 0 0 0 0 0 0 0 0
52186 - 0 0 0 0 0 0 0 0 0 0 0 0
52187 - 0 0 0 0 0 0 0 0 0 0 0 0
52188 - 0 0 0 0 0 0 0 0 0 0 0 0
52189 - 0 0 0 0 0 0 0 0 0 0 0 0
52190 - 0 0 0 0 0 0 0 0 0 10 10 10
52191 - 30 30 30 78 78 78 46 46 46 22 22 22
52192 -137 92 6 210 162 10 239 182 13 238 190 10
52193 -238 202 15 241 208 19 246 215 20 246 215 20
52194 -241 208 19 203 166 17 185 133 11 210 150 10
52195 -216 158 10 210 150 10 102 78 10 2 2 6
52196 - 6 6 6 54 54 54 14 14 14 2 2 6
52197 - 2 2 6 62 62 62 74 74 74 30 30 30
52198 - 10 10 10 0 0 0 0 0 0 0 0 0
52199 - 0 0 0 0 0 0 0 0 0 0 0 0
52200 - 0 0 0 0 0 0 0 0 0 0 0 0
52201 - 0 0 0 0 0 0 0 0 0 0 0 0
52202 - 0 0 0 0 0 0 0 0 0 0 0 0
52203 - 0 0 0 0 0 0 0 0 0 0 0 0
52204 - 0 0 0 0 0 0 0 0 0 0 0 0
52205 - 0 0 0 0 0 0 0 0 0 0 0 0
52206 - 0 0 0 0 0 0 0 0 0 0 0 0
52207 - 0 0 0 0 0 0 0 0 0 0 0 0
52208 - 0 0 0 0 0 0 0 0 0 0 0 0
52209 - 0 0 0 0 0 0 0 0 0 0 0 0
52210 - 0 0 0 0 0 0 0 0 0 10 10 10
52211 - 34 34 34 78 78 78 50 50 50 6 6 6
52212 - 94 70 30 139 102 15 190 146 13 226 184 13
52213 -232 200 30 232 195 16 215 174 15 190 146 13
52214 -168 122 10 192 133 9 210 150 10 213 154 11
52215 -202 150 34 182 157 106 101 98 89 2 2 6
52216 - 2 2 6 78 78 78 116 116 116 58 58 58
52217 - 2 2 6 22 22 22 90 90 90 46 46 46
52218 - 18 18 18 6 6 6 0 0 0 0 0 0
52219 - 0 0 0 0 0 0 0 0 0 0 0 0
52220 - 0 0 0 0 0 0 0 0 0 0 0 0
52221 - 0 0 0 0 0 0 0 0 0 0 0 0
52222 - 0 0 0 0 0 0 0 0 0 0 0 0
52223 - 0 0 0 0 0 0 0 0 0 0 0 0
52224 - 0 0 0 0 0 0 0 0 0 0 0 0
52225 - 0 0 0 0 0 0 0 0 0 0 0 0
52226 - 0 0 0 0 0 0 0 0 0 0 0 0
52227 - 0 0 0 0 0 0 0 0 0 0 0 0
52228 - 0 0 0 0 0 0 0 0 0 0 0 0
52229 - 0 0 0 0 0 0 0 0 0 0 0 0
52230 - 0 0 0 0 0 0 0 0 0 10 10 10
52231 - 38 38 38 86 86 86 50 50 50 6 6 6
52232 -128 128 128 174 154 114 156 107 11 168 122 10
52233 -198 155 10 184 144 12 197 138 11 200 144 11
52234 -206 145 10 206 145 10 197 138 11 188 164 115
52235 -195 195 195 198 198 198 174 174 174 14 14 14
52236 - 2 2 6 22 22 22 116 116 116 116 116 116
52237 - 22 22 22 2 2 6 74 74 74 70 70 70
52238 - 30 30 30 10 10 10 0 0 0 0 0 0
52239 - 0 0 0 0 0 0 0 0 0 0 0 0
52240 - 0 0 0 0 0 0 0 0 0 0 0 0
52241 - 0 0 0 0 0 0 0 0 0 0 0 0
52242 - 0 0 0 0 0 0 0 0 0 0 0 0
52243 - 0 0 0 0 0 0 0 0 0 0 0 0
52244 - 0 0 0 0 0 0 0 0 0 0 0 0
52245 - 0 0 0 0 0 0 0 0 0 0 0 0
52246 - 0 0 0 0 0 0 0 0 0 0 0 0
52247 - 0 0 0 0 0 0 0 0 0 0 0 0
52248 - 0 0 0 0 0 0 0 0 0 0 0 0
52249 - 0 0 0 0 0 0 0 0 0 0 0 0
52250 - 0 0 0 0 0 0 6 6 6 18 18 18
52251 - 50 50 50 101 101 101 26 26 26 10 10 10
52252 -138 138 138 190 190 190 174 154 114 156 107 11
52253 -197 138 11 200 144 11 197 138 11 192 133 9
52254 -180 123 7 190 142 34 190 178 144 187 187 187
52255 -202 202 202 221 221 221 214 214 214 66 66 66
52256 - 2 2 6 2 2 6 50 50 50 62 62 62
52257 - 6 6 6 2 2 6 10 10 10 90 90 90
52258 - 50 50 50 18 18 18 6 6 6 0 0 0
52259 - 0 0 0 0 0 0 0 0 0 0 0 0
52260 - 0 0 0 0 0 0 0 0 0 0 0 0
52261 - 0 0 0 0 0 0 0 0 0 0 0 0
52262 - 0 0 0 0 0 0 0 0 0 0 0 0
52263 - 0 0 0 0 0 0 0 0 0 0 0 0
52264 - 0 0 0 0 0 0 0 0 0 0 0 0
52265 - 0 0 0 0 0 0 0 0 0 0 0 0
52266 - 0 0 0 0 0 0 0 0 0 0 0 0
52267 - 0 0 0 0 0 0 0 0 0 0 0 0
52268 - 0 0 0 0 0 0 0 0 0 0 0 0
52269 - 0 0 0 0 0 0 0 0 0 0 0 0
52270 - 0 0 0 0 0 0 10 10 10 34 34 34
52271 - 74 74 74 74 74 74 2 2 6 6 6 6
52272 -144 144 144 198 198 198 190 190 190 178 166 146
52273 -154 121 60 156 107 11 156 107 11 168 124 44
52274 -174 154 114 187 187 187 190 190 190 210 210 210
52275 -246 246 246 253 253 253 253 253 253 182 182 182
52276 - 6 6 6 2 2 6 2 2 6 2 2 6
52277 - 2 2 6 2 2 6 2 2 6 62 62 62
52278 - 74 74 74 34 34 34 14 14 14 0 0 0
52279 - 0 0 0 0 0 0 0 0 0 0 0 0
52280 - 0 0 0 0 0 0 0 0 0 0 0 0
52281 - 0 0 0 0 0 0 0 0 0 0 0 0
52282 - 0 0 0 0 0 0 0 0 0 0 0 0
52283 - 0 0 0 0 0 0 0 0 0 0 0 0
52284 - 0 0 0 0 0 0 0 0 0 0 0 0
52285 - 0 0 0 0 0 0 0 0 0 0 0 0
52286 - 0 0 0 0 0 0 0 0 0 0 0 0
52287 - 0 0 0 0 0 0 0 0 0 0 0 0
52288 - 0 0 0 0 0 0 0 0 0 0 0 0
52289 - 0 0 0 0 0 0 0 0 0 0 0 0
52290 - 0 0 0 10 10 10 22 22 22 54 54 54
52291 - 94 94 94 18 18 18 2 2 6 46 46 46
52292 -234 234 234 221 221 221 190 190 190 190 190 190
52293 -190 190 190 187 187 187 187 187 187 190 190 190
52294 -190 190 190 195 195 195 214 214 214 242 242 242
52295 -253 253 253 253 253 253 253 253 253 253 253 253
52296 - 82 82 82 2 2 6 2 2 6 2 2 6
52297 - 2 2 6 2 2 6 2 2 6 14 14 14
52298 - 86 86 86 54 54 54 22 22 22 6 6 6
52299 - 0 0 0 0 0 0 0 0 0 0 0 0
52300 - 0 0 0 0 0 0 0 0 0 0 0 0
52301 - 0 0 0 0 0 0 0 0 0 0 0 0
52302 - 0 0 0 0 0 0 0 0 0 0 0 0
52303 - 0 0 0 0 0 0 0 0 0 0 0 0
52304 - 0 0 0 0 0 0 0 0 0 0 0 0
52305 - 0 0 0 0 0 0 0 0 0 0 0 0
52306 - 0 0 0 0 0 0 0 0 0 0 0 0
52307 - 0 0 0 0 0 0 0 0 0 0 0 0
52308 - 0 0 0 0 0 0 0 0 0 0 0 0
52309 - 0 0 0 0 0 0 0 0 0 0 0 0
52310 - 6 6 6 18 18 18 46 46 46 90 90 90
52311 - 46 46 46 18 18 18 6 6 6 182 182 182
52312 -253 253 253 246 246 246 206 206 206 190 190 190
52313 -190 190 190 190 190 190 190 190 190 190 190 190
52314 -206 206 206 231 231 231 250 250 250 253 253 253
52315 -253 253 253 253 253 253 253 253 253 253 253 253
52316 -202 202 202 14 14 14 2 2 6 2 2 6
52317 - 2 2 6 2 2 6 2 2 6 2 2 6
52318 - 42 42 42 86 86 86 42 42 42 18 18 18
52319 - 6 6 6 0 0 0 0 0 0 0 0 0
52320 - 0 0 0 0 0 0 0 0 0 0 0 0
52321 - 0 0 0 0 0 0 0 0 0 0 0 0
52322 - 0 0 0 0 0 0 0 0 0 0 0 0
52323 - 0 0 0 0 0 0 0 0 0 0 0 0
52324 - 0 0 0 0 0 0 0 0 0 0 0 0
52325 - 0 0 0 0 0 0 0 0 0 0 0 0
52326 - 0 0 0 0 0 0 0 0 0 0 0 0
52327 - 0 0 0 0 0 0 0 0 0 0 0 0
52328 - 0 0 0 0 0 0 0 0 0 0 0 0
52329 - 0 0 0 0 0 0 0 0 0 6 6 6
52330 - 14 14 14 38 38 38 74 74 74 66 66 66
52331 - 2 2 6 6 6 6 90 90 90 250 250 250
52332 -253 253 253 253 253 253 238 238 238 198 198 198
52333 -190 190 190 190 190 190 195 195 195 221 221 221
52334 -246 246 246 253 253 253 253 253 253 253 253 253
52335 -253 253 253 253 253 253 253 253 253 253 253 253
52336 -253 253 253 82 82 82 2 2 6 2 2 6
52337 - 2 2 6 2 2 6 2 2 6 2 2 6
52338 - 2 2 6 78 78 78 70 70 70 34 34 34
52339 - 14 14 14 6 6 6 0 0 0 0 0 0
52340 - 0 0 0 0 0 0 0 0 0 0 0 0
52341 - 0 0 0 0 0 0 0 0 0 0 0 0
52342 - 0 0 0 0 0 0 0 0 0 0 0 0
52343 - 0 0 0 0 0 0 0 0 0 0 0 0
52344 - 0 0 0 0 0 0 0 0 0 0 0 0
52345 - 0 0 0 0 0 0 0 0 0 0 0 0
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 14 14 14
52350 - 34 34 34 66 66 66 78 78 78 6 6 6
52351 - 2 2 6 18 18 18 218 218 218 253 253 253
52352 -253 253 253 253 253 253 253 253 253 246 246 246
52353 -226 226 226 231 231 231 246 246 246 253 253 253
52354 -253 253 253 253 253 253 253 253 253 253 253 253
52355 -253 253 253 253 253 253 253 253 253 253 253 253
52356 -253 253 253 178 178 178 2 2 6 2 2 6
52357 - 2 2 6 2 2 6 2 2 6 2 2 6
52358 - 2 2 6 18 18 18 90 90 90 62 62 62
52359 - 30 30 30 10 10 10 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 10 10 10 26 26 26
52370 - 58 58 58 90 90 90 18 18 18 2 2 6
52371 - 2 2 6 110 110 110 253 253 253 253 253 253
52372 -253 253 253 253 253 253 253 253 253 253 253 253
52373 -250 250 250 253 253 253 253 253 253 253 253 253
52374 -253 253 253 253 253 253 253 253 253 253 253 253
52375 -253 253 253 253 253 253 253 253 253 253 253 253
52376 -253 253 253 231 231 231 18 18 18 2 2 6
52377 - 2 2 6 2 2 6 2 2 6 2 2 6
52378 - 2 2 6 2 2 6 18 18 18 94 94 94
52379 - 54 54 54 26 26 26 10 10 10 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 0 0 0 0 0 0 0
52388 - 0 0 0 0 0 0 0 0 0 0 0 0
52389 - 0 0 0 6 6 6 22 22 22 50 50 50
52390 - 90 90 90 26 26 26 2 2 6 2 2 6
52391 - 14 14 14 195 195 195 250 250 250 253 253 253
52392 -253 253 253 253 253 253 253 253 253 253 253 253
52393 -253 253 253 253 253 253 253 253 253 253 253 253
52394 -253 253 253 253 253 253 253 253 253 253 253 253
52395 -253 253 253 253 253 253 253 253 253 253 253 253
52396 -250 250 250 242 242 242 54 54 54 2 2 6
52397 - 2 2 6 2 2 6 2 2 6 2 2 6
52398 - 2 2 6 2 2 6 2 2 6 38 38 38
52399 - 86 86 86 50 50 50 22 22 22 6 6 6
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 0 0 0 0 0 0 0 0 0 0
52408 - 0 0 0 0 0 0 0 0 0 0 0 0
52409 - 6 6 6 14 14 14 38 38 38 82 82 82
52410 - 34 34 34 2 2 6 2 2 6 2 2 6
52411 - 42 42 42 195 195 195 246 246 246 253 253 253
52412 -253 253 253 253 253 253 253 253 253 250 250 250
52413 -242 242 242 242 242 242 250 250 250 253 253 253
52414 -253 253 253 253 253 253 253 253 253 253 253 253
52415 -253 253 253 250 250 250 246 246 246 238 238 238
52416 -226 226 226 231 231 231 101 101 101 6 6 6
52417 - 2 2 6 2 2 6 2 2 6 2 2 6
52418 - 2 2 6 2 2 6 2 2 6 2 2 6
52419 - 38 38 38 82 82 82 42 42 42 14 14 14
52420 - 6 6 6 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 0 0 0 0 0 0 0 0 0 0
52428 - 0 0 0 0 0 0 0 0 0 0 0 0
52429 - 10 10 10 26 26 26 62 62 62 66 66 66
52430 - 2 2 6 2 2 6 2 2 6 6 6 6
52431 - 70 70 70 170 170 170 206 206 206 234 234 234
52432 -246 246 246 250 250 250 250 250 250 238 238 238
52433 -226 226 226 231 231 231 238 238 238 250 250 250
52434 -250 250 250 250 250 250 246 246 246 231 231 231
52435 -214 214 214 206 206 206 202 202 202 202 202 202
52436 -198 198 198 202 202 202 182 182 182 18 18 18
52437 - 2 2 6 2 2 6 2 2 6 2 2 6
52438 - 2 2 6 2 2 6 2 2 6 2 2 6
52439 - 2 2 6 62 62 62 66 66 66 30 30 30
52440 - 10 10 10 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 - 14 14 14 42 42 42 82 82 82 18 18 18
52450 - 2 2 6 2 2 6 2 2 6 10 10 10
52451 - 94 94 94 182 182 182 218 218 218 242 242 242
52452 -250 250 250 253 253 253 253 253 253 250 250 250
52453 -234 234 234 253 253 253 253 253 253 253 253 253
52454 -253 253 253 253 253 253 253 253 253 246 246 246
52455 -238 238 238 226 226 226 210 210 210 202 202 202
52456 -195 195 195 195 195 195 210 210 210 158 158 158
52457 - 6 6 6 14 14 14 50 50 50 14 14 14
52458 - 2 2 6 2 2 6 2 2 6 2 2 6
52459 - 2 2 6 6 6 6 86 86 86 46 46 46
52460 - 18 18 18 6 6 6 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 0 0 0 0 0 0 0 0 0 0
52468 - 0 0 0 0 0 0 0 0 0 6 6 6
52469 - 22 22 22 54 54 54 70 70 70 2 2 6
52470 - 2 2 6 10 10 10 2 2 6 22 22 22
52471 -166 166 166 231 231 231 250 250 250 253 253 253
52472 -253 253 253 253 253 253 253 253 253 250 250 250
52473 -242 242 242 253 253 253 253 253 253 253 253 253
52474 -253 253 253 253 253 253 253 253 253 253 253 253
52475 -253 253 253 253 253 253 253 253 253 246 246 246
52476 -231 231 231 206 206 206 198 198 198 226 226 226
52477 - 94 94 94 2 2 6 6 6 6 38 38 38
52478 - 30 30 30 2 2 6 2 2 6 2 2 6
52479 - 2 2 6 2 2 6 62 62 62 66 66 66
52480 - 26 26 26 10 10 10 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 0 0 0 0 0 0 0 0 0 0
52488 - 0 0 0 0 0 0 0 0 0 10 10 10
52489 - 30 30 30 74 74 74 50 50 50 2 2 6
52490 - 26 26 26 26 26 26 2 2 6 106 106 106
52491 -238 238 238 253 253 253 253 253 253 253 253 253
52492 -253 253 253 253 253 253 253 253 253 253 253 253
52493 -253 253 253 253 253 253 253 253 253 253 253 253
52494 -253 253 253 253 253 253 253 253 253 253 253 253
52495 -253 253 253 253 253 253 253 253 253 253 253 253
52496 -253 253 253 246 246 246 218 218 218 202 202 202
52497 -210 210 210 14 14 14 2 2 6 2 2 6
52498 - 30 30 30 22 22 22 2 2 6 2 2 6
52499 - 2 2 6 2 2 6 18 18 18 86 86 86
52500 - 42 42 42 14 14 14 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 0 0 0 0 0 0 0 0 0 0
52508 - 0 0 0 0 0 0 0 0 0 14 14 14
52509 - 42 42 42 90 90 90 22 22 22 2 2 6
52510 - 42 42 42 2 2 6 18 18 18 218 218 218
52511 -253 253 253 253 253 253 253 253 253 253 253 253
52512 -253 253 253 253 253 253 253 253 253 253 253 253
52513 -253 253 253 253 253 253 253 253 253 253 253 253
52514 -253 253 253 253 253 253 253 253 253 253 253 253
52515 -253 253 253 253 253 253 253 253 253 253 253 253
52516 -253 253 253 253 253 253 250 250 250 221 221 221
52517 -218 218 218 101 101 101 2 2 6 14 14 14
52518 - 18 18 18 38 38 38 10 10 10 2 2 6
52519 - 2 2 6 2 2 6 2 2 6 78 78 78
52520 - 58 58 58 22 22 22 6 6 6 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 6 6 6 18 18 18
52529 - 54 54 54 82 82 82 2 2 6 26 26 26
52530 - 22 22 22 2 2 6 123 123 123 253 253 253
52531 -253 253 253 253 253 253 253 253 253 253 253 253
52532 -253 253 253 253 253 253 253 253 253 253 253 253
52533 -253 253 253 253 253 253 253 253 253 253 253 253
52534 -253 253 253 253 253 253 253 253 253 253 253 253
52535 -253 253 253 253 253 253 253 253 253 253 253 253
52536 -253 253 253 253 253 253 253 253 253 250 250 250
52537 -238 238 238 198 198 198 6 6 6 38 38 38
52538 - 58 58 58 26 26 26 38 38 38 2 2 6
52539 - 2 2 6 2 2 6 2 2 6 46 46 46
52540 - 78 78 78 30 30 30 10 10 10 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 0 0 0 0 0 0 0
52548 - 0 0 0 0 0 0 10 10 10 30 30 30
52549 - 74 74 74 58 58 58 2 2 6 42 42 42
52550 - 2 2 6 22 22 22 231 231 231 253 253 253
52551 -253 253 253 253 253 253 253 253 253 253 253 253
52552 -253 253 253 253 253 253 253 253 253 250 250 250
52553 -253 253 253 253 253 253 253 253 253 253 253 253
52554 -253 253 253 253 253 253 253 253 253 253 253 253
52555 -253 253 253 253 253 253 253 253 253 253 253 253
52556 -253 253 253 253 253 253 253 253 253 253 253 253
52557 -253 253 253 246 246 246 46 46 46 38 38 38
52558 - 42 42 42 14 14 14 38 38 38 14 14 14
52559 - 2 2 6 2 2 6 2 2 6 6 6 6
52560 - 86 86 86 46 46 46 14 14 14 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 0 0 0 0 0 0 0 0 0 0
52568 - 0 0 0 6 6 6 14 14 14 42 42 42
52569 - 90 90 90 18 18 18 18 18 18 26 26 26
52570 - 2 2 6 116 116 116 253 253 253 253 253 253
52571 -253 253 253 253 253 253 253 253 253 253 253 253
52572 -253 253 253 253 253 253 250 250 250 238 238 238
52573 -253 253 253 253 253 253 253 253 253 253 253 253
52574 -253 253 253 253 253 253 253 253 253 253 253 253
52575 -253 253 253 253 253 253 253 253 253 253 253 253
52576 -253 253 253 253 253 253 253 253 253 253 253 253
52577 -253 253 253 253 253 253 94 94 94 6 6 6
52578 - 2 2 6 2 2 6 10 10 10 34 34 34
52579 - 2 2 6 2 2 6 2 2 6 2 2 6
52580 - 74 74 74 58 58 58 22 22 22 6 6 6
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 0 0 0 0 0 0 0
52588 - 0 0 0 10 10 10 26 26 26 66 66 66
52589 - 82 82 82 2 2 6 38 38 38 6 6 6
52590 - 14 14 14 210 210 210 253 253 253 253 253 253
52591 -253 253 253 253 253 253 253 253 253 253 253 253
52592 -253 253 253 253 253 253 246 246 246 242 242 242
52593 -253 253 253 253 253 253 253 253 253 253 253 253
52594 -253 253 253 253 253 253 253 253 253 253 253 253
52595 -253 253 253 253 253 253 253 253 253 253 253 253
52596 -253 253 253 253 253 253 253 253 253 253 253 253
52597 -253 253 253 253 253 253 144 144 144 2 2 6
52598 - 2 2 6 2 2 6 2 2 6 46 46 46
52599 - 2 2 6 2 2 6 2 2 6 2 2 6
52600 - 42 42 42 74 74 74 30 30 30 10 10 10
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 0 0 0 0 0 0 0 0 0 0
52608 - 6 6 6 14 14 14 42 42 42 90 90 90
52609 - 26 26 26 6 6 6 42 42 42 2 2 6
52610 - 74 74 74 250 250 250 253 253 253 253 253 253
52611 -253 253 253 253 253 253 253 253 253 253 253 253
52612 -253 253 253 253 253 253 242 242 242 242 242 242
52613 -253 253 253 253 253 253 253 253 253 253 253 253
52614 -253 253 253 253 253 253 253 253 253 253 253 253
52615 -253 253 253 253 253 253 253 253 253 253 253 253
52616 -253 253 253 253 253 253 253 253 253 253 253 253
52617 -253 253 253 253 253 253 182 182 182 2 2 6
52618 - 2 2 6 2 2 6 2 2 6 46 46 46
52619 - 2 2 6 2 2 6 2 2 6 2 2 6
52620 - 10 10 10 86 86 86 38 38 38 10 10 10
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 0 0 0 0 0 0 0 0 0 0
52628 - 10 10 10 26 26 26 66 66 66 82 82 82
52629 - 2 2 6 22 22 22 18 18 18 2 2 6
52630 -149 149 149 253 253 253 253 253 253 253 253 253
52631 -253 253 253 253 253 253 253 253 253 253 253 253
52632 -253 253 253 253 253 253 234 234 234 242 242 242
52633 -253 253 253 253 253 253 253 253 253 253 253 253
52634 -253 253 253 253 253 253 253 253 253 253 253 253
52635 -253 253 253 253 253 253 253 253 253 253 253 253
52636 -253 253 253 253 253 253 253 253 253 253 253 253
52637 -253 253 253 253 253 253 206 206 206 2 2 6
52638 - 2 2 6 2 2 6 2 2 6 38 38 38
52639 - 2 2 6 2 2 6 2 2 6 2 2 6
52640 - 6 6 6 86 86 86 46 46 46 14 14 14
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 6 6 6
52648 - 18 18 18 46 46 46 86 86 86 18 18 18
52649 - 2 2 6 34 34 34 10 10 10 6 6 6
52650 -210 210 210 253 253 253 253 253 253 253 253 253
52651 -253 253 253 253 253 253 253 253 253 253 253 253
52652 -253 253 253 253 253 253 234 234 234 242 242 242
52653 -253 253 253 253 253 253 253 253 253 253 253 253
52654 -253 253 253 253 253 253 253 253 253 253 253 253
52655 -253 253 253 253 253 253 253 253 253 253 253 253
52656 -253 253 253 253 253 253 253 253 253 253 253 253
52657 -253 253 253 253 253 253 221 221 221 6 6 6
52658 - 2 2 6 2 2 6 6 6 6 30 30 30
52659 - 2 2 6 2 2 6 2 2 6 2 2 6
52660 - 2 2 6 82 82 82 54 54 54 18 18 18
52661 - 6 6 6 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 0 0 0 0
52667 - 0 0 0 0 0 0 0 0 0 10 10 10
52668 - 26 26 26 66 66 66 62 62 62 2 2 6
52669 - 2 2 6 38 38 38 10 10 10 26 26 26
52670 -238 238 238 253 253 253 253 253 253 253 253 253
52671 -253 253 253 253 253 253 253 253 253 253 253 253
52672 -253 253 253 253 253 253 231 231 231 238 238 238
52673 -253 253 253 253 253 253 253 253 253 253 253 253
52674 -253 253 253 253 253 253 253 253 253 253 253 253
52675 -253 253 253 253 253 253 253 253 253 253 253 253
52676 -253 253 253 253 253 253 253 253 253 253 253 253
52677 -253 253 253 253 253 253 231 231 231 6 6 6
52678 - 2 2 6 2 2 6 10 10 10 30 30 30
52679 - 2 2 6 2 2 6 2 2 6 2 2 6
52680 - 2 2 6 66 66 66 58 58 58 22 22 22
52681 - 6 6 6 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 10 10 10
52688 - 38 38 38 78 78 78 6 6 6 2 2 6
52689 - 2 2 6 46 46 46 14 14 14 42 42 42
52690 -246 246 246 253 253 253 253 253 253 253 253 253
52691 -253 253 253 253 253 253 253 253 253 253 253 253
52692 -253 253 253 253 253 253 231 231 231 242 242 242
52693 -253 253 253 253 253 253 253 253 253 253 253 253
52694 -253 253 253 253 253 253 253 253 253 253 253 253
52695 -253 253 253 253 253 253 253 253 253 253 253 253
52696 -253 253 253 253 253 253 253 253 253 253 253 253
52697 -253 253 253 253 253 253 234 234 234 10 10 10
52698 - 2 2 6 2 2 6 22 22 22 14 14 14
52699 - 2 2 6 2 2 6 2 2 6 2 2 6
52700 - 2 2 6 66 66 66 62 62 62 22 22 22
52701 - 6 6 6 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 0 0 0 0
52707 - 0 0 0 0 0 0 6 6 6 18 18 18
52708 - 50 50 50 74 74 74 2 2 6 2 2 6
52709 - 14 14 14 70 70 70 34 34 34 62 62 62
52710 -250 250 250 253 253 253 253 253 253 253 253 253
52711 -253 253 253 253 253 253 253 253 253 253 253 253
52712 -253 253 253 253 253 253 231 231 231 246 246 246
52713 -253 253 253 253 253 253 253 253 253 253 253 253
52714 -253 253 253 253 253 253 253 253 253 253 253 253
52715 -253 253 253 253 253 253 253 253 253 253 253 253
52716 -253 253 253 253 253 253 253 253 253 253 253 253
52717 -253 253 253 253 253 253 234 234 234 14 14 14
52718 - 2 2 6 2 2 6 30 30 30 2 2 6
52719 - 2 2 6 2 2 6 2 2 6 2 2 6
52720 - 2 2 6 66 66 66 62 62 62 22 22 22
52721 - 6 6 6 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 0 0 0 0
52727 - 0 0 0 0 0 0 6 6 6 18 18 18
52728 - 54 54 54 62 62 62 2 2 6 2 2 6
52729 - 2 2 6 30 30 30 46 46 46 70 70 70
52730 -250 250 250 253 253 253 253 253 253 253 253 253
52731 -253 253 253 253 253 253 253 253 253 253 253 253
52732 -253 253 253 253 253 253 231 231 231 246 246 246
52733 -253 253 253 253 253 253 253 253 253 253 253 253
52734 -253 253 253 253 253 253 253 253 253 253 253 253
52735 -253 253 253 253 253 253 253 253 253 253 253 253
52736 -253 253 253 253 253 253 253 253 253 253 253 253
52737 -253 253 253 253 253 253 226 226 226 10 10 10
52738 - 2 2 6 6 6 6 30 30 30 2 2 6
52739 - 2 2 6 2 2 6 2 2 6 2 2 6
52740 - 2 2 6 66 66 66 58 58 58 22 22 22
52741 - 6 6 6 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 0 0 0 0
52747 - 0 0 0 0 0 0 6 6 6 22 22 22
52748 - 58 58 58 62 62 62 2 2 6 2 2 6
52749 - 2 2 6 2 2 6 30 30 30 78 78 78
52750 -250 250 250 253 253 253 253 253 253 253 253 253
52751 -253 253 253 253 253 253 253 253 253 253 253 253
52752 -253 253 253 253 253 253 231 231 231 246 246 246
52753 -253 253 253 253 253 253 253 253 253 253 253 253
52754 -253 253 253 253 253 253 253 253 253 253 253 253
52755 -253 253 253 253 253 253 253 253 253 253 253 253
52756 -253 253 253 253 253 253 253 253 253 253 253 253
52757 -253 253 253 253 253 253 206 206 206 2 2 6
52758 - 22 22 22 34 34 34 18 14 6 22 22 22
52759 - 26 26 26 18 18 18 6 6 6 2 2 6
52760 - 2 2 6 82 82 82 54 54 54 18 18 18
52761 - 6 6 6 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 6 6 6 26 26 26
52768 - 62 62 62 106 106 106 74 54 14 185 133 11
52769 -210 162 10 121 92 8 6 6 6 62 62 62
52770 -238 238 238 253 253 253 253 253 253 253 253 253
52771 -253 253 253 253 253 253 253 253 253 253 253 253
52772 -253 253 253 253 253 253 231 231 231 246 246 246
52773 -253 253 253 253 253 253 253 253 253 253 253 253
52774 -253 253 253 253 253 253 253 253 253 253 253 253
52775 -253 253 253 253 253 253 253 253 253 253 253 253
52776 -253 253 253 253 253 253 253 253 253 253 253 253
52777 -253 253 253 253 253 253 158 158 158 18 18 18
52778 - 14 14 14 2 2 6 2 2 6 2 2 6
52779 - 6 6 6 18 18 18 66 66 66 38 38 38
52780 - 6 6 6 94 94 94 50 50 50 18 18 18
52781 - 6 6 6 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 6 6 6
52787 - 10 10 10 10 10 10 18 18 18 38 38 38
52788 - 78 78 78 142 134 106 216 158 10 242 186 14
52789 -246 190 14 246 190 14 156 118 10 10 10 10
52790 - 90 90 90 238 238 238 253 253 253 253 253 253
52791 -253 253 253 253 253 253 253 253 253 253 253 253
52792 -253 253 253 253 253 253 231 231 231 250 250 250
52793 -253 253 253 253 253 253 253 253 253 253 253 253
52794 -253 253 253 253 253 253 253 253 253 253 253 253
52795 -253 253 253 253 253 253 253 253 253 253 253 253
52796 -253 253 253 253 253 253 253 253 253 246 230 190
52797 -238 204 91 238 204 91 181 142 44 37 26 9
52798 - 2 2 6 2 2 6 2 2 6 2 2 6
52799 - 2 2 6 2 2 6 38 38 38 46 46 46
52800 - 26 26 26 106 106 106 54 54 54 18 18 18
52801 - 6 6 6 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 6 6 6 14 14 14 22 22 22
52807 - 30 30 30 38 38 38 50 50 50 70 70 70
52808 -106 106 106 190 142 34 226 170 11 242 186 14
52809 -246 190 14 246 190 14 246 190 14 154 114 10
52810 - 6 6 6 74 74 74 226 226 226 253 253 253
52811 -253 253 253 253 253 253 253 253 253 253 253 253
52812 -253 253 253 253 253 253 231 231 231 250 250 250
52813 -253 253 253 253 253 253 253 253 253 253 253 253
52814 -253 253 253 253 253 253 253 253 253 253 253 253
52815 -253 253 253 253 253 253 253 253 253 253 253 253
52816 -253 253 253 253 253 253 253 253 253 228 184 62
52817 -241 196 14 241 208 19 232 195 16 38 30 10
52818 - 2 2 6 2 2 6 2 2 6 2 2 6
52819 - 2 2 6 6 6 6 30 30 30 26 26 26
52820 -203 166 17 154 142 90 66 66 66 26 26 26
52821 - 6 6 6 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 - 6 6 6 18 18 18 38 38 38 58 58 58
52827 - 78 78 78 86 86 86 101 101 101 123 123 123
52828 -175 146 61 210 150 10 234 174 13 246 186 14
52829 -246 190 14 246 190 14 246 190 14 238 190 10
52830 -102 78 10 2 2 6 46 46 46 198 198 198
52831 -253 253 253 253 253 253 253 253 253 253 253 253
52832 -253 253 253 253 253 253 234 234 234 242 242 242
52833 -253 253 253 253 253 253 253 253 253 253 253 253
52834 -253 253 253 253 253 253 253 253 253 253 253 253
52835 -253 253 253 253 253 253 253 253 253 253 253 253
52836 -253 253 253 253 253 253 253 253 253 224 178 62
52837 -242 186 14 241 196 14 210 166 10 22 18 6
52838 - 2 2 6 2 2 6 2 2 6 2 2 6
52839 - 2 2 6 2 2 6 6 6 6 121 92 8
52840 -238 202 15 232 195 16 82 82 82 34 34 34
52841 - 10 10 10 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 - 14 14 14 38 38 38 70 70 70 154 122 46
52847 -190 142 34 200 144 11 197 138 11 197 138 11
52848 -213 154 11 226 170 11 242 186 14 246 190 14
52849 -246 190 14 246 190 14 246 190 14 246 190 14
52850 -225 175 15 46 32 6 2 2 6 22 22 22
52851 -158 158 158 250 250 250 253 253 253 253 253 253
52852 -253 253 253 253 253 253 253 253 253 253 253 253
52853 -253 253 253 253 253 253 253 253 253 253 253 253
52854 -253 253 253 253 253 253 253 253 253 253 253 253
52855 -253 253 253 253 253 253 253 253 253 253 253 253
52856 -253 253 253 250 250 250 242 242 242 224 178 62
52857 -239 182 13 236 186 11 213 154 11 46 32 6
52858 - 2 2 6 2 2 6 2 2 6 2 2 6
52859 - 2 2 6 2 2 6 61 42 6 225 175 15
52860 -238 190 10 236 186 11 112 100 78 42 42 42
52861 - 14 14 14 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 6 6 6
52866 - 22 22 22 54 54 54 154 122 46 213 154 11
52867 -226 170 11 230 174 11 226 170 11 226 170 11
52868 -236 178 12 242 186 14 246 190 14 246 190 14
52869 -246 190 14 246 190 14 246 190 14 246 190 14
52870 -241 196 14 184 144 12 10 10 10 2 2 6
52871 - 6 6 6 116 116 116 242 242 242 253 253 253
52872 -253 253 253 253 253 253 253 253 253 253 253 253
52873 -253 253 253 253 253 253 253 253 253 253 253 253
52874 -253 253 253 253 253 253 253 253 253 253 253 253
52875 -253 253 253 253 253 253 253 253 253 253 253 253
52876 -253 253 253 231 231 231 198 198 198 214 170 54
52877 -236 178 12 236 178 12 210 150 10 137 92 6
52878 - 18 14 6 2 2 6 2 2 6 2 2 6
52879 - 6 6 6 70 47 6 200 144 11 236 178 12
52880 -239 182 13 239 182 13 124 112 88 58 58 58
52881 - 22 22 22 6 6 6 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 10 10 10
52886 - 30 30 30 70 70 70 180 133 36 226 170 11
52887 -239 182 13 242 186 14 242 186 14 246 186 14
52888 -246 190 14 246 190 14 246 190 14 246 190 14
52889 -246 190 14 246 190 14 246 190 14 246 190 14
52890 -246 190 14 232 195 16 98 70 6 2 2 6
52891 - 2 2 6 2 2 6 66 66 66 221 221 221
52892 -253 253 253 253 253 253 253 253 253 253 253 253
52893 -253 253 253 253 253 253 253 253 253 253 253 253
52894 -253 253 253 253 253 253 253 253 253 253 253 253
52895 -253 253 253 253 253 253 253 253 253 253 253 253
52896 -253 253 253 206 206 206 198 198 198 214 166 58
52897 -230 174 11 230 174 11 216 158 10 192 133 9
52898 -163 110 8 116 81 8 102 78 10 116 81 8
52899 -167 114 7 197 138 11 226 170 11 239 182 13
52900 -242 186 14 242 186 14 162 146 94 78 78 78
52901 - 34 34 34 14 14 14 6 6 6 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 6 6 6
52906 - 30 30 30 78 78 78 190 142 34 226 170 11
52907 -239 182 13 246 190 14 246 190 14 246 190 14
52908 -246 190 14 246 190 14 246 190 14 246 190 14
52909 -246 190 14 246 190 14 246 190 14 246 190 14
52910 -246 190 14 241 196 14 203 166 17 22 18 6
52911 - 2 2 6 2 2 6 2 2 6 38 38 38
52912 -218 218 218 253 253 253 253 253 253 253 253 253
52913 -253 253 253 253 253 253 253 253 253 253 253 253
52914 -253 253 253 253 253 253 253 253 253 253 253 253
52915 -253 253 253 253 253 253 253 253 253 253 253 253
52916 -250 250 250 206 206 206 198 198 198 202 162 69
52917 -226 170 11 236 178 12 224 166 10 210 150 10
52918 -200 144 11 197 138 11 192 133 9 197 138 11
52919 -210 150 10 226 170 11 242 186 14 246 190 14
52920 -246 190 14 246 186 14 225 175 15 124 112 88
52921 - 62 62 62 30 30 30 14 14 14 6 6 6
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 10 10 10
52926 - 30 30 30 78 78 78 174 135 50 224 166 10
52927 -239 182 13 246 190 14 246 190 14 246 190 14
52928 -246 190 14 246 190 14 246 190 14 246 190 14
52929 -246 190 14 246 190 14 246 190 14 246 190 14
52930 -246 190 14 246 190 14 241 196 14 139 102 15
52931 - 2 2 6 2 2 6 2 2 6 2 2 6
52932 - 78 78 78 250 250 250 253 253 253 253 253 253
52933 -253 253 253 253 253 253 253 253 253 253 253 253
52934 -253 253 253 253 253 253 253 253 253 253 253 253
52935 -253 253 253 253 253 253 253 253 253 253 253 253
52936 -250 250 250 214 214 214 198 198 198 190 150 46
52937 -219 162 10 236 178 12 234 174 13 224 166 10
52938 -216 158 10 213 154 11 213 154 11 216 158 10
52939 -226 170 11 239 182 13 246 190 14 246 190 14
52940 -246 190 14 246 190 14 242 186 14 206 162 42
52941 -101 101 101 58 58 58 30 30 30 14 14 14
52942 - 6 6 6 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 10 10 10
52946 - 30 30 30 74 74 74 174 135 50 216 158 10
52947 -236 178 12 246 190 14 246 190 14 246 190 14
52948 -246 190 14 246 190 14 246 190 14 246 190 14
52949 -246 190 14 246 190 14 246 190 14 246 190 14
52950 -246 190 14 246 190 14 241 196 14 226 184 13
52951 - 61 42 6 2 2 6 2 2 6 2 2 6
52952 - 22 22 22 238 238 238 253 253 253 253 253 253
52953 -253 253 253 253 253 253 253 253 253 253 253 253
52954 -253 253 253 253 253 253 253 253 253 253 253 253
52955 -253 253 253 253 253 253 253 253 253 253 253 253
52956 -253 253 253 226 226 226 187 187 187 180 133 36
52957 -216 158 10 236 178 12 239 182 13 236 178 12
52958 -230 174 11 226 170 11 226 170 11 230 174 11
52959 -236 178 12 242 186 14 246 190 14 246 190 14
52960 -246 190 14 246 190 14 246 186 14 239 182 13
52961 -206 162 42 106 106 106 66 66 66 34 34 34
52962 - 14 14 14 6 6 6 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 6 6 6
52966 - 26 26 26 70 70 70 163 133 67 213 154 11
52967 -236 178 12 246 190 14 246 190 14 246 190 14
52968 -246 190 14 246 190 14 246 190 14 246 190 14
52969 -246 190 14 246 190 14 246 190 14 246 190 14
52970 -246 190 14 246 190 14 246 190 14 241 196 14
52971 -190 146 13 18 14 6 2 2 6 2 2 6
52972 - 46 46 46 246 246 246 253 253 253 253 253 253
52973 -253 253 253 253 253 253 253 253 253 253 253 253
52974 -253 253 253 253 253 253 253 253 253 253 253 253
52975 -253 253 253 253 253 253 253 253 253 253 253 253
52976 -253 253 253 221 221 221 86 86 86 156 107 11
52977 -216 158 10 236 178 12 242 186 14 246 186 14
52978 -242 186 14 239 182 13 239 182 13 242 186 14
52979 -242 186 14 246 186 14 246 190 14 246 190 14
52980 -246 190 14 246 190 14 246 190 14 246 190 14
52981 -242 186 14 225 175 15 142 122 72 66 66 66
52982 - 30 30 30 10 10 10 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 6 6 6
52986 - 26 26 26 70 70 70 163 133 67 210 150 10
52987 -236 178 12 246 190 14 246 190 14 246 190 14
52988 -246 190 14 246 190 14 246 190 14 246 190 14
52989 -246 190 14 246 190 14 246 190 14 246 190 14
52990 -246 190 14 246 190 14 246 190 14 246 190 14
52991 -232 195 16 121 92 8 34 34 34 106 106 106
52992 -221 221 221 253 253 253 253 253 253 253 253 253
52993 -253 253 253 253 253 253 253 253 253 253 253 253
52994 -253 253 253 253 253 253 253 253 253 253 253 253
52995 -253 253 253 253 253 253 253 253 253 253 253 253
52996 -242 242 242 82 82 82 18 14 6 163 110 8
52997 -216 158 10 236 178 12 242 186 14 246 190 14
52998 -246 190 14 246 190 14 246 190 14 246 190 14
52999 -246 190 14 246 190 14 246 190 14 246 190 14
53000 -246 190 14 246 190 14 246 190 14 246 190 14
53001 -246 190 14 246 190 14 242 186 14 163 133 67
53002 - 46 46 46 18 18 18 6 6 6 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 10 10 10
53006 - 30 30 30 78 78 78 163 133 67 210 150 10
53007 -236 178 12 246 186 14 246 190 14 246 190 14
53008 -246 190 14 246 190 14 246 190 14 246 190 14
53009 -246 190 14 246 190 14 246 190 14 246 190 14
53010 -246 190 14 246 190 14 246 190 14 246 190 14
53011 -241 196 14 215 174 15 190 178 144 253 253 253
53012 -253 253 253 253 253 253 253 253 253 253 253 253
53013 -253 253 253 253 253 253 253 253 253 253 253 253
53014 -253 253 253 253 253 253 253 253 253 253 253 253
53015 -253 253 253 253 253 253 253 253 253 218 218 218
53016 - 58 58 58 2 2 6 22 18 6 167 114 7
53017 -216 158 10 236 178 12 246 186 14 246 190 14
53018 -246 190 14 246 190 14 246 190 14 246 190 14
53019 -246 190 14 246 190 14 246 190 14 246 190 14
53020 -246 190 14 246 190 14 246 190 14 246 190 14
53021 -246 190 14 246 186 14 242 186 14 190 150 46
53022 - 54 54 54 22 22 22 6 6 6 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 14 14 14
53026 - 38 38 38 86 86 86 180 133 36 213 154 11
53027 -236 178 12 246 186 14 246 190 14 246 190 14
53028 -246 190 14 246 190 14 246 190 14 246 190 14
53029 -246 190 14 246 190 14 246 190 14 246 190 14
53030 -246 190 14 246 190 14 246 190 14 246 190 14
53031 -246 190 14 232 195 16 190 146 13 214 214 214
53032 -253 253 253 253 253 253 253 253 253 253 253 253
53033 -253 253 253 253 253 253 253 253 253 253 253 253
53034 -253 253 253 253 253 253 253 253 253 253 253 253
53035 -253 253 253 250 250 250 170 170 170 26 26 26
53036 - 2 2 6 2 2 6 37 26 9 163 110 8
53037 -219 162 10 239 182 13 246 186 14 246 190 14
53038 -246 190 14 246 190 14 246 190 14 246 190 14
53039 -246 190 14 246 190 14 246 190 14 246 190 14
53040 -246 190 14 246 190 14 246 190 14 246 190 14
53041 -246 186 14 236 178 12 224 166 10 142 122 72
53042 - 46 46 46 18 18 18 6 6 6 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 6 6 6 18 18 18
53046 - 50 50 50 109 106 95 192 133 9 224 166 10
53047 -242 186 14 246 190 14 246 190 14 246 190 14
53048 -246 190 14 246 190 14 246 190 14 246 190 14
53049 -246 190 14 246 190 14 246 190 14 246 190 14
53050 -246 190 14 246 190 14 246 190 14 246 190 14
53051 -242 186 14 226 184 13 210 162 10 142 110 46
53052 -226 226 226 253 253 253 253 253 253 253 253 253
53053 -253 253 253 253 253 253 253 253 253 253 253 253
53054 -253 253 253 253 253 253 253 253 253 253 253 253
53055 -198 198 198 66 66 66 2 2 6 2 2 6
53056 - 2 2 6 2 2 6 50 34 6 156 107 11
53057 -219 162 10 239 182 13 246 186 14 246 190 14
53058 -246 190 14 246 190 14 246 190 14 246 190 14
53059 -246 190 14 246 190 14 246 190 14 246 190 14
53060 -246 190 14 246 190 14 246 190 14 242 186 14
53061 -234 174 13 213 154 11 154 122 46 66 66 66
53062 - 30 30 30 10 10 10 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 6 6 6 22 22 22
53066 - 58 58 58 154 121 60 206 145 10 234 174 13
53067 -242 186 14 246 186 14 246 190 14 246 190 14
53068 -246 190 14 246 190 14 246 190 14 246 190 14
53069 -246 190 14 246 190 14 246 190 14 246 190 14
53070 -246 190 14 246 190 14 246 190 14 246 190 14
53071 -246 186 14 236 178 12 210 162 10 163 110 8
53072 - 61 42 6 138 138 138 218 218 218 250 250 250
53073 -253 253 253 253 253 253 253 253 253 250 250 250
53074 -242 242 242 210 210 210 144 144 144 66 66 66
53075 - 6 6 6 2 2 6 2 2 6 2 2 6
53076 - 2 2 6 2 2 6 61 42 6 163 110 8
53077 -216 158 10 236 178 12 246 190 14 246 190 14
53078 -246 190 14 246 190 14 246 190 14 246 190 14
53079 -246 190 14 246 190 14 246 190 14 246 190 14
53080 -246 190 14 239 182 13 230 174 11 216 158 10
53081 -190 142 34 124 112 88 70 70 70 38 38 38
53082 - 18 18 18 6 6 6 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 6 6 6 22 22 22
53086 - 62 62 62 168 124 44 206 145 10 224 166 10
53087 -236 178 12 239 182 13 242 186 14 242 186 14
53088 -246 186 14 246 190 14 246 190 14 246 190 14
53089 -246 190 14 246 190 14 246 190 14 246 190 14
53090 -246 190 14 246 190 14 246 190 14 246 190 14
53091 -246 190 14 236 178 12 216 158 10 175 118 6
53092 - 80 54 7 2 2 6 6 6 6 30 30 30
53093 - 54 54 54 62 62 62 50 50 50 38 38 38
53094 - 14 14 14 2 2 6 2 2 6 2 2 6
53095 - 2 2 6 2 2 6 2 2 6 2 2 6
53096 - 2 2 6 6 6 6 80 54 7 167 114 7
53097 -213 154 11 236 178 12 246 190 14 246 190 14
53098 -246 190 14 246 190 14 246 190 14 246 190 14
53099 -246 190 14 242 186 14 239 182 13 239 182 13
53100 -230 174 11 210 150 10 174 135 50 124 112 88
53101 - 82 82 82 54 54 54 34 34 34 18 18 18
53102 - 6 6 6 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 6 6 6 18 18 18
53106 - 50 50 50 158 118 36 192 133 9 200 144 11
53107 -216 158 10 219 162 10 224 166 10 226 170 11
53108 -230 174 11 236 178 12 239 182 13 239 182 13
53109 -242 186 14 246 186 14 246 190 14 246 190 14
53110 -246 190 14 246 190 14 246 190 14 246 190 14
53111 -246 186 14 230 174 11 210 150 10 163 110 8
53112 -104 69 6 10 10 10 2 2 6 2 2 6
53113 - 2 2 6 2 2 6 2 2 6 2 2 6
53114 - 2 2 6 2 2 6 2 2 6 2 2 6
53115 - 2 2 6 2 2 6 2 2 6 2 2 6
53116 - 2 2 6 6 6 6 91 60 6 167 114 7
53117 -206 145 10 230 174 11 242 186 14 246 190 14
53118 -246 190 14 246 190 14 246 186 14 242 186 14
53119 -239 182 13 230 174 11 224 166 10 213 154 11
53120 -180 133 36 124 112 88 86 86 86 58 58 58
53121 - 38 38 38 22 22 22 10 10 10 6 6 6
53122 - 0 0 0 0 0 0 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 14 14 14
53126 - 34 34 34 70 70 70 138 110 50 158 118 36
53127 -167 114 7 180 123 7 192 133 9 197 138 11
53128 -200 144 11 206 145 10 213 154 11 219 162 10
53129 -224 166 10 230 174 11 239 182 13 242 186 14
53130 -246 186 14 246 186 14 246 186 14 246 186 14
53131 -239 182 13 216 158 10 185 133 11 152 99 6
53132 -104 69 6 18 14 6 2 2 6 2 2 6
53133 - 2 2 6 2 2 6 2 2 6 2 2 6
53134 - 2 2 6 2 2 6 2 2 6 2 2 6
53135 - 2 2 6 2 2 6 2 2 6 2 2 6
53136 - 2 2 6 6 6 6 80 54 7 152 99 6
53137 -192 133 9 219 162 10 236 178 12 239 182 13
53138 -246 186 14 242 186 14 239 182 13 236 178 12
53139 -224 166 10 206 145 10 192 133 9 154 121 60
53140 - 94 94 94 62 62 62 42 42 42 22 22 22
53141 - 14 14 14 6 6 6 0 0 0 0 0 0
53142 - 0 0 0 0 0 0 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 6 6 6
53146 - 18 18 18 34 34 34 58 58 58 78 78 78
53147 -101 98 89 124 112 88 142 110 46 156 107 11
53148 -163 110 8 167 114 7 175 118 6 180 123 7
53149 -185 133 11 197 138 11 210 150 10 219 162 10
53150 -226 170 11 236 178 12 236 178 12 234 174 13
53151 -219 162 10 197 138 11 163 110 8 130 83 6
53152 - 91 60 6 10 10 10 2 2 6 2 2 6
53153 - 18 18 18 38 38 38 38 38 38 38 38 38
53154 - 38 38 38 38 38 38 38 38 38 38 38 38
53155 - 38 38 38 38 38 38 26 26 26 2 2 6
53156 - 2 2 6 6 6 6 70 47 6 137 92 6
53157 -175 118 6 200 144 11 219 162 10 230 174 11
53158 -234 174 13 230 174 11 219 162 10 210 150 10
53159 -192 133 9 163 110 8 124 112 88 82 82 82
53160 - 50 50 50 30 30 30 14 14 14 6 6 6
53161 - 0 0 0 0 0 0 0 0 0 0 0 0
53162 - 0 0 0 0 0 0 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 - 6 6 6 14 14 14 22 22 22 34 34 34
53167 - 42 42 42 58 58 58 74 74 74 86 86 86
53168 -101 98 89 122 102 70 130 98 46 121 87 25
53169 -137 92 6 152 99 6 163 110 8 180 123 7
53170 -185 133 11 197 138 11 206 145 10 200 144 11
53171 -180 123 7 156 107 11 130 83 6 104 69 6
53172 - 50 34 6 54 54 54 110 110 110 101 98 89
53173 - 86 86 86 82 82 82 78 78 78 78 78 78
53174 - 78 78 78 78 78 78 78 78 78 78 78 78
53175 - 78 78 78 82 82 82 86 86 86 94 94 94
53176 -106 106 106 101 101 101 86 66 34 124 80 6
53177 -156 107 11 180 123 7 192 133 9 200 144 11
53178 -206 145 10 200 144 11 192 133 9 175 118 6
53179 -139 102 15 109 106 95 70 70 70 42 42 42
53180 - 22 22 22 10 10 10 0 0 0 0 0 0
53181 - 0 0 0 0 0 0 0 0 0 0 0 0
53182 - 0 0 0 0 0 0 0 0 0 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 6 6 6 10 10 10
53187 - 14 14 14 22 22 22 30 30 30 38 38 38
53188 - 50 50 50 62 62 62 74 74 74 90 90 90
53189 -101 98 89 112 100 78 121 87 25 124 80 6
53190 -137 92 6 152 99 6 152 99 6 152 99 6
53191 -138 86 6 124 80 6 98 70 6 86 66 30
53192 -101 98 89 82 82 82 58 58 58 46 46 46
53193 - 38 38 38 34 34 34 34 34 34 34 34 34
53194 - 34 34 34 34 34 34 34 34 34 34 34 34
53195 - 34 34 34 34 34 34 38 38 38 42 42 42
53196 - 54 54 54 82 82 82 94 86 76 91 60 6
53197 -134 86 6 156 107 11 167 114 7 175 118 6
53198 -175 118 6 167 114 7 152 99 6 121 87 25
53199 -101 98 89 62 62 62 34 34 34 18 18 18
53200 - 6 6 6 0 0 0 0 0 0 0 0 0
53201 - 0 0 0 0 0 0 0 0 0 0 0 0
53202 - 0 0 0 0 0 0 0 0 0 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 6 6 6 6 6 6 10 10 10
53208 - 18 18 18 22 22 22 30 30 30 42 42 42
53209 - 50 50 50 66 66 66 86 86 86 101 98 89
53210 -106 86 58 98 70 6 104 69 6 104 69 6
53211 -104 69 6 91 60 6 82 62 34 90 90 90
53212 - 62 62 62 38 38 38 22 22 22 14 14 14
53213 - 10 10 10 10 10 10 10 10 10 10 10 10
53214 - 10 10 10 10 10 10 6 6 6 10 10 10
53215 - 10 10 10 10 10 10 10 10 10 14 14 14
53216 - 22 22 22 42 42 42 70 70 70 89 81 66
53217 - 80 54 7 104 69 6 124 80 6 137 92 6
53218 -134 86 6 116 81 8 100 82 52 86 86 86
53219 - 58 58 58 30 30 30 14 14 14 6 6 6
53220 - 0 0 0 0 0 0 0 0 0 0 0 0
53221 - 0 0 0 0 0 0 0 0 0 0 0 0
53222 - 0 0 0 0 0 0 0 0 0 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 6 6 6 10 10 10 14 14 14
53229 - 18 18 18 26 26 26 38 38 38 54 54 54
53230 - 70 70 70 86 86 86 94 86 76 89 81 66
53231 - 89 81 66 86 86 86 74 74 74 50 50 50
53232 - 30 30 30 14 14 14 6 6 6 0 0 0
53233 - 0 0 0 0 0 0 0 0 0 0 0 0
53234 - 0 0 0 0 0 0 0 0 0 0 0 0
53235 - 0 0 0 0 0 0 0 0 0 0 0 0
53236 - 6 6 6 18 18 18 34 34 34 58 58 58
53237 - 82 82 82 89 81 66 89 81 66 89 81 66
53238 - 94 86 66 94 86 76 74 74 74 50 50 50
53239 - 26 26 26 14 14 14 6 6 6 0 0 0
53240 - 0 0 0 0 0 0 0 0 0 0 0 0
53241 - 0 0 0 0 0 0 0 0 0 0 0 0
53242 - 0 0 0 0 0 0 0 0 0 0 0 0
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 - 6 6 6 6 6 6 14 14 14 18 18 18
53250 - 30 30 30 38 38 38 46 46 46 54 54 54
53251 - 50 50 50 42 42 42 30 30 30 18 18 18
53252 - 10 10 10 0 0 0 0 0 0 0 0 0
53253 - 0 0 0 0 0 0 0 0 0 0 0 0
53254 - 0 0 0 0 0 0 0 0 0 0 0 0
53255 - 0 0 0 0 0 0 0 0 0 0 0 0
53256 - 0 0 0 6 6 6 14 14 14 26 26 26
53257 - 38 38 38 50 50 50 58 58 58 58 58 58
53258 - 54 54 54 42 42 42 30 30 30 18 18 18
53259 - 10 10 10 0 0 0 0 0 0 0 0 0
53260 - 0 0 0 0 0 0 0 0 0 0 0 0
53261 - 0 0 0 0 0 0 0 0 0 0 0 0
53262 - 0 0 0 0 0 0 0 0 0 0 0 0
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 6 6 6
53270 - 6 6 6 10 10 10 14 14 14 18 18 18
53271 - 18 18 18 14 14 14 10 10 10 6 6 6
53272 - 0 0 0 0 0 0 0 0 0 0 0 0
53273 - 0 0 0 0 0 0 0 0 0 0 0 0
53274 - 0 0 0 0 0 0 0 0 0 0 0 0
53275 - 0 0 0 0 0 0 0 0 0 0 0 0
53276 - 0 0 0 0 0 0 0 0 0 6 6 6
53277 - 14 14 14 18 18 18 22 22 22 22 22 22
53278 - 18 18 18 14 14 14 10 10 10 6 6 6
53279 - 0 0 0 0 0 0 0 0 0 0 0 0
53280 - 0 0 0 0 0 0 0 0 0 0 0 0
53281 - 0 0 0 0 0 0 0 0 0 0 0 0
53282 - 0 0 0 0 0 0 0 0 0 0 0 0
53283 - 0 0 0 0 0 0 0 0 0 0 0 0
53284 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53290 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53291 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53292 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53295 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53296 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53297 +4 4 4 4 4 4
53298 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53304 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53305 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53306 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53309 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53310 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53311 +4 4 4 4 4 4
53312 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53316 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53317 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53318 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53319 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53320 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53323 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53324 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53325 +4 4 4 4 4 4
53326 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53332 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53333 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53334 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53338 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53339 +4 4 4 4 4 4
53340 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53346 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53347 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53348 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53352 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53353 +4 4 4 4 4 4
53354 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53360 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53361 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53362 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53363 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53364 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53365 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53366 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53367 +4 4 4 4 4 4
53368 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53372 +4 4 4 4 4 4 4 4 4 3 3 3 0 0 0 0 0 0
53373 +0 0 0 0 0 0 0 0 0 0 0 0 3 3 3 4 4 4
53374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53375 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53376 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53377 +4 4 4 4 4 4 4 4 4 4 4 4 1 1 1 0 0 0
53378 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
53379 +4 4 4 4 4 4 4 4 4 2 1 0 2 1 0 3 2 2
53380 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53381 +4 4 4 4 4 4
53382 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53386 +4 4 4 4 4 4 2 2 2 0 0 0 3 4 3 26 28 28
53387 +37 38 37 37 38 37 14 17 19 2 2 2 0 0 0 2 2 2
53388 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53389 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53390 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53391 +4 4 4 4 4 4 3 3 3 0 0 0 1 1 1 6 6 6
53392 +2 2 2 0 0 0 3 3 3 4 4 4 4 4 4 4 4 4
53393 +4 4 5 3 3 3 1 0 0 0 0 0 1 0 0 0 0 0
53394 +1 1 1 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53395 +4 4 4 4 4 4
53396 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53398 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53400 +2 2 2 0 0 0 0 0 0 14 17 19 60 74 84 137 136 137
53401 +153 152 153 137 136 137 125 124 125 60 73 81 6 6 6 3 1 0
53402 +0 0 0 3 3 3 4 4 4 4 4 4 4 4 4 4 4 4
53403 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53404 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53405 +4 4 4 4 4 4 0 0 0 4 4 4 41 54 63 125 124 125
53406 +60 73 81 6 6 6 4 0 0 3 3 3 4 4 4 4 4 4
53407 +4 4 4 0 0 0 6 9 11 41 54 63 41 65 82 22 30 35
53408 +2 2 2 2 1 0 4 4 4 4 4 4 4 4 4 4 4 4
53409 +4 4 4 4 4 4
53410 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53411 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53412 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53413 +4 4 4 4 4 4 5 5 5 5 5 5 2 2 2 0 0 0
53414 +4 0 0 6 6 6 41 54 63 137 136 137 174 174 174 167 166 167
53415 +165 164 165 165 164 165 163 162 163 163 162 163 125 124 125 41 54 63
53416 +1 1 1 0 0 0 0 0 0 3 3 3 5 5 5 4 4 4
53417 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53418 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
53419 +3 3 3 2 0 0 4 0 0 60 73 81 156 155 156 167 166 167
53420 +163 162 163 85 115 134 5 7 8 0 0 0 4 4 4 5 5 5
53421 +0 0 0 2 5 5 55 98 126 90 154 193 90 154 193 72 125 159
53422 +37 51 59 2 0 0 1 1 1 4 5 5 4 4 4 4 4 4
53423 +4 4 4 4 4 4
53424 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53425 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53426 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53427 +4 4 4 5 5 5 4 4 4 1 1 1 0 0 0 3 3 3
53428 +37 38 37 125 124 125 163 162 163 174 174 174 158 157 158 158 157 158
53429 +156 155 156 156 155 156 158 157 158 165 164 165 174 174 174 166 165 166
53430 +125 124 125 16 19 21 1 0 0 0 0 0 0 0 0 4 4 4
53431 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
53432 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 1 1 1
53433 +0 0 0 0 0 0 37 38 37 153 152 153 174 174 174 158 157 158
53434 +174 174 174 163 162 163 37 38 37 4 3 3 4 0 0 1 1 1
53435 +0 0 0 22 40 52 101 161 196 101 161 196 90 154 193 101 161 196
53436 +64 123 161 14 17 19 0 0 0 4 4 4 4 4 4 4 4 4
53437 +4 4 4 4 4 4
53438 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53439 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53440 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
53441 +5 5 5 2 2 2 0 0 0 4 0 0 24 26 27 85 115 134
53442 +156 155 156 174 174 174 167 166 167 156 155 156 154 153 154 157 156 157
53443 +156 155 156 156 155 156 155 154 155 153 152 153 158 157 158 167 166 167
53444 +174 174 174 156 155 156 60 74 84 16 19 21 0 0 0 0 0 0
53445 +1 1 1 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
53446 +4 4 4 5 5 5 6 6 6 3 3 3 0 0 0 4 0 0
53447 +13 16 17 60 73 81 137 136 137 165 164 165 156 155 156 153 152 153
53448 +174 174 174 177 184 187 60 73 81 3 1 0 0 0 0 1 1 2
53449 +22 30 35 64 123 161 136 185 209 90 154 193 90 154 193 90 154 193
53450 +90 154 193 21 29 34 0 0 0 3 2 2 4 4 5 4 4 4
53451 +4 4 4 4 4 4
53452 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53453 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53454 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 3 3 3
53455 +0 0 0 0 0 0 10 13 16 60 74 84 157 156 157 174 174 174
53456 +174 174 174 158 157 158 153 152 153 154 153 154 156 155 156 155 154 155
53457 +156 155 156 155 154 155 154 153 154 157 156 157 154 153 154 153 152 153
53458 +163 162 163 174 174 174 177 184 187 137 136 137 60 73 81 13 16 17
53459 +4 0 0 0 0 0 3 3 3 5 5 5 4 4 4 4 4 4
53460 +5 5 5 4 4 4 1 1 1 0 0 0 3 3 3 41 54 63
53461 +131 129 131 174 174 174 174 174 174 174 174 174 167 166 167 174 174 174
53462 +190 197 201 137 136 137 24 26 27 4 0 0 16 21 25 50 82 103
53463 +90 154 193 136 185 209 90 154 193 101 161 196 101 161 196 101 161 196
53464 +31 91 132 3 6 7 0 0 0 4 4 4 4 4 4 4 4 4
53465 +4 4 4 4 4 4
53466 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53467 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53468 +4 4 4 4 4 4 4 4 4 2 2 2 0 0 0 4 0 0
53469 +4 0 0 43 57 68 137 136 137 177 184 187 174 174 174 163 162 163
53470 +155 154 155 155 154 155 156 155 156 155 154 155 158 157 158 165 164 165
53471 +167 166 167 166 165 166 163 162 163 157 156 157 155 154 155 155 154 155
53472 +153 152 153 156 155 156 167 166 167 174 174 174 174 174 174 131 129 131
53473 +41 54 63 5 5 5 0 0 0 0 0 0 3 3 3 4 4 4
53474 +1 1 1 0 0 0 1 0 0 26 28 28 125 124 125 174 174 174
53475 +177 184 187 174 174 174 174 174 174 156 155 156 131 129 131 137 136 137
53476 +125 124 125 24 26 27 4 0 0 41 65 82 90 154 193 136 185 209
53477 +136 185 209 101 161 196 53 118 160 37 112 160 90 154 193 34 86 122
53478 +7 12 15 0 0 0 4 4 4 4 4 4 4 4 4 4 4 4
53479 +4 4 4 4 4 4
53480 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53481 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53482 +4 4 4 3 3 3 0 0 0 0 0 0 5 5 5 37 38 37
53483 +125 124 125 167 166 167 174 174 174 167 166 167 158 157 158 155 154 155
53484 +156 155 156 156 155 156 156 155 156 163 162 163 167 166 167 155 154 155
53485 +137 136 137 153 152 153 156 155 156 165 164 165 163 162 163 156 155 156
53486 +156 155 156 156 155 156 155 154 155 158 157 158 166 165 166 174 174 174
53487 +167 166 167 125 124 125 37 38 37 1 0 0 0 0 0 0 0 0
53488 +0 0 0 24 26 27 60 74 84 158 157 158 174 174 174 174 174 174
53489 +166 165 166 158 157 158 125 124 125 41 54 63 13 16 17 6 6 6
53490 +6 6 6 37 38 37 80 127 157 136 185 209 101 161 196 101 161 196
53491 +90 154 193 28 67 93 6 10 14 13 20 25 13 20 25 6 10 14
53492 +1 1 2 4 3 3 4 4 4 4 4 4 4 4 4 4 4 4
53493 +4 4 4 4 4 4
53494 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53495 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53496 +1 1 1 1 0 0 4 3 3 37 38 37 60 74 84 153 152 153
53497 +167 166 167 167 166 167 158 157 158 154 153 154 155 154 155 156 155 156
53498 +157 156 157 158 157 158 167 166 167 167 166 167 131 129 131 43 57 68
53499 +26 28 28 37 38 37 60 73 81 131 129 131 165 164 165 166 165 166
53500 +158 157 158 155 154 155 156 155 156 156 155 156 156 155 156 158 157 158
53501 +165 164 165 174 174 174 163 162 163 60 74 84 16 19 21 13 16 17
53502 +60 73 81 131 129 131 174 174 174 174 174 174 167 166 167 165 164 165
53503 +137 136 137 60 73 81 24 26 27 4 0 0 4 0 0 16 19 21
53504 +52 104 138 101 161 196 136 185 209 136 185 209 90 154 193 27 99 146
53505 +13 20 25 4 5 7 2 5 5 4 5 7 1 1 2 0 0 0
53506 +4 4 4 4 4 4 3 3 3 2 2 2 2 2 2 4 4 4
53507 +4 4 4 4 4 4
53508 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53509 +4 4 4 4 4 4 4 4 4 4 4 4 3 3 3 0 0 0
53510 +0 0 0 13 16 17 60 73 81 137 136 137 174 174 174 166 165 166
53511 +158 157 158 156 155 156 157 156 157 156 155 156 155 154 155 158 157 158
53512 +167 166 167 174 174 174 153 152 153 60 73 81 16 19 21 4 0 0
53513 +4 0 0 4 0 0 6 6 6 26 28 28 60 74 84 158 157 158
53514 +174 174 174 166 165 166 157 156 157 155 154 155 156 155 156 156 155 156
53515 +155 154 155 158 157 158 167 166 167 167 166 167 131 129 131 125 124 125
53516 +137 136 137 167 166 167 167 166 167 174 174 174 158 157 158 125 124 125
53517 +16 19 21 4 0 0 4 0 0 10 13 16 49 76 92 107 159 188
53518 +136 185 209 136 185 209 90 154 193 26 108 161 22 40 52 6 10 14
53519 +2 3 3 1 1 2 1 1 2 4 4 5 4 4 5 4 4 5
53520 +4 4 5 2 2 1 0 0 0 0 0 0 0 0 0 2 2 2
53521 +4 4 4 4 4 4
53522 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53523 +4 4 4 5 5 5 3 3 3 0 0 0 1 0 0 4 0 0
53524 +37 51 59 131 129 131 167 166 167 167 166 167 163 162 163 157 156 157
53525 +157 156 157 155 154 155 153 152 153 157 156 157 167 166 167 174 174 174
53526 +153 152 153 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
53527 +4 3 3 4 3 3 4 0 0 6 6 6 4 0 0 37 38 37
53528 +125 124 125 174 174 174 174 174 174 165 164 165 156 155 156 154 153 154
53529 +156 155 156 156 155 156 155 154 155 163 162 163 158 157 158 163 162 163
53530 +174 174 174 174 174 174 174 174 174 125 124 125 37 38 37 0 0 0
53531 +4 0 0 6 9 11 41 54 63 90 154 193 136 185 209 146 190 211
53532 +136 185 209 37 112 160 22 40 52 6 10 14 3 6 7 1 1 2
53533 +1 1 2 3 3 3 1 1 2 3 3 3 4 4 4 4 4 4
53534 +2 2 2 2 0 0 16 19 21 37 38 37 24 26 27 0 0 0
53535 +0 0 0 4 4 4
53536 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 5 5 5
53537 +4 4 4 0 0 0 0 0 0 0 0 0 26 28 28 120 125 127
53538 +158 157 158 174 174 174 165 164 165 157 156 157 155 154 155 156 155 156
53539 +153 152 153 153 152 153 167 166 167 174 174 174 174 174 174 125 124 125
53540 +37 38 37 4 0 0 0 0 0 4 0 0 4 3 3 4 4 4
53541 +4 4 4 4 4 4 5 5 5 4 0 0 4 0 0 4 0 0
53542 +4 3 3 43 57 68 137 136 137 174 174 174 174 174 174 165 164 165
53543 +154 153 154 153 152 153 153 152 153 153 152 153 163 162 163 174 174 174
53544 +174 174 174 153 152 153 60 73 81 6 6 6 4 0 0 4 3 3
53545 +32 43 50 80 127 157 136 185 209 146 190 211 146 190 211 90 154 193
53546 +28 67 93 28 67 93 40 71 93 3 6 7 1 1 2 2 5 5
53547 +50 82 103 79 117 143 26 37 45 0 0 0 3 3 3 1 1 1
53548 +0 0 0 41 54 63 137 136 137 174 174 174 153 152 153 60 73 81
53549 +2 0 0 0 0 0
53550 +4 4 4 4 4 4 4 4 4 4 4 4 6 6 6 2 2 2
53551 +0 0 0 2 0 0 24 26 27 60 74 84 153 152 153 174 174 174
53552 +174 174 174 157 156 157 154 153 154 156 155 156 154 153 154 153 152 153
53553 +165 164 165 174 174 174 177 184 187 137 136 137 43 57 68 6 6 6
53554 +4 0 0 2 0 0 3 3 3 5 5 5 5 5 5 4 4 4
53555 +4 4 4 4 4 4 4 4 4 5 5 5 6 6 6 4 3 3
53556 +4 0 0 4 0 0 24 26 27 60 73 81 153 152 153 174 174 174
53557 +174 174 174 158 157 158 158 157 158 174 174 174 174 174 174 158 157 158
53558 +60 74 84 24 26 27 4 0 0 4 0 0 17 23 27 59 113 148
53559 +136 185 209 191 222 234 146 190 211 136 185 209 31 91 132 7 11 13
53560 +22 40 52 101 161 196 90 154 193 6 9 11 3 4 4 43 95 132
53561 +136 185 209 172 205 220 55 98 126 0 0 0 0 0 0 2 0 0
53562 +26 28 28 153 152 153 177 184 187 167 166 167 177 184 187 165 164 165
53563 +37 38 37 0 0 0
53564 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
53565 +13 16 17 60 73 81 137 136 137 174 174 174 174 174 174 165 164 165
53566 +153 152 153 153 152 153 155 154 155 154 153 154 158 157 158 174 174 174
53567 +177 184 187 163 162 163 60 73 81 16 19 21 4 0 0 4 0 0
53568 +4 3 3 4 4 4 5 5 5 5 5 5 4 4 4 5 5 5
53569 +5 5 5 5 5 5 5 5 5 4 4 4 4 4 4 5 5 5
53570 +6 6 6 4 0 0 4 0 0 4 0 0 24 26 27 60 74 84
53571 +166 165 166 174 174 174 177 184 187 165 164 165 125 124 125 24 26 27
53572 +4 0 0 4 0 0 5 5 5 50 82 103 136 185 209 172 205 220
53573 +146 190 211 136 185 209 26 108 161 22 40 52 7 12 15 44 81 103
53574 +71 116 144 28 67 93 37 51 59 41 65 82 100 139 164 101 161 196
53575 +90 154 193 90 154 193 28 67 93 0 0 0 0 0 0 26 28 28
53576 +125 124 125 167 166 167 163 162 163 153 152 153 163 162 163 174 174 174
53577 +85 115 134 4 0 0
53578 +4 4 4 5 5 5 4 4 4 1 0 0 4 0 0 34 47 55
53579 +125 124 125 174 174 174 174 174 174 167 166 167 157 156 157 153 152 153
53580 +155 154 155 155 154 155 158 157 158 166 165 166 167 166 167 154 153 154
53581 +125 124 125 26 28 28 4 0 0 4 0 0 4 0 0 5 5 5
53582 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 1 1 1
53583 +0 0 0 0 0 0 1 1 1 4 4 4 4 4 4 4 4 4
53584 +5 5 5 5 5 5 4 3 3 4 0 0 4 0 0 6 6 6
53585 +37 38 37 131 129 131 137 136 137 37 38 37 0 0 0 4 0 0
53586 +4 5 5 43 61 72 90 154 193 172 205 220 146 190 211 136 185 209
53587 +90 154 193 28 67 93 13 20 25 43 61 72 71 116 144 44 81 103
53588 +2 5 5 7 11 13 59 113 148 101 161 196 90 154 193 28 67 93
53589 +13 20 25 6 10 14 0 0 0 13 16 17 60 73 81 137 136 137
53590 +166 165 166 158 157 158 156 155 156 154 153 154 167 166 167 174 174 174
53591 +60 73 81 4 0 0
53592 +4 4 4 4 4 4 0 0 0 3 3 3 60 74 84 174 174 174
53593 +174 174 174 167 166 167 163 162 163 155 154 155 157 156 157 155 154 155
53594 +156 155 156 163 162 163 167 166 167 158 157 158 125 124 125 37 38 37
53595 +4 3 3 4 0 0 4 0 0 6 6 6 6 6 6 5 5 5
53596 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 2 3 3
53597 +10 13 16 7 11 13 1 0 0 0 0 0 2 2 1 4 4 4
53598 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 4 0 0
53599 +4 0 0 7 11 13 13 16 17 4 0 0 3 3 3 34 47 55
53600 +80 127 157 146 190 211 172 205 220 136 185 209 136 185 209 136 185 209
53601 +28 67 93 22 40 52 55 98 126 55 98 126 21 29 34 7 11 13
53602 +50 82 103 101 161 196 101 161 196 35 83 115 13 20 25 2 2 1
53603 +1 1 2 1 1 2 37 51 59 131 129 131 174 174 174 174 174 174
53604 +167 166 167 163 162 163 163 162 163 167 166 167 174 174 174 125 124 125
53605 +16 19 21 4 0 0
53606 +4 4 4 4 0 0 4 0 0 60 74 84 174 174 174 174 174 174
53607 +158 157 158 155 154 155 155 154 155 156 155 156 155 154 155 158 157 158
53608 +167 166 167 165 164 165 131 129 131 60 73 81 13 16 17 4 0 0
53609 +4 0 0 4 3 3 6 6 6 4 3 3 5 5 5 4 4 4
53610 +4 4 4 3 2 2 0 0 0 0 0 0 7 11 13 45 69 86
53611 +80 127 157 71 116 144 43 61 72 7 11 13 0 0 0 1 1 1
53612 +4 3 3 4 4 4 4 4 4 4 4 4 6 6 6 5 5 5
53613 +3 2 2 4 0 0 1 0 0 21 29 34 59 113 148 136 185 209
53614 +146 190 211 136 185 209 136 185 209 136 185 209 136 185 209 136 185 209
53615 +68 124 159 44 81 103 22 40 52 13 16 17 43 61 72 90 154 193
53616 +136 185 209 59 113 148 21 29 34 3 4 3 1 1 1 0 0 0
53617 +24 26 27 125 124 125 163 162 163 174 174 174 166 165 166 165 164 165
53618 +163 162 163 125 124 125 125 124 125 125 124 125 125 124 125 26 28 28
53619 +4 0 0 4 3 3
53620 +3 3 3 0 0 0 24 26 27 153 152 153 177 184 187 158 157 158
53621 +156 155 156 156 155 156 155 154 155 155 154 155 165 164 165 174 174 174
53622 +155 154 155 60 74 84 26 28 28 4 0 0 4 0 0 3 1 0
53623 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 3 3
53624 +2 0 0 0 0 0 0 0 0 32 43 50 72 125 159 101 161 196
53625 +136 185 209 101 161 196 101 161 196 79 117 143 32 43 50 0 0 0
53626 +0 0 0 2 2 2 4 4 4 4 4 4 3 3 3 1 0 0
53627 +0 0 0 4 5 5 49 76 92 101 161 196 146 190 211 146 190 211
53628 +136 185 209 136 185 209 136 185 209 136 185 209 136 185 209 90 154 193
53629 +28 67 93 13 16 17 37 51 59 80 127 157 136 185 209 90 154 193
53630 +22 40 52 6 9 11 3 4 3 2 2 1 16 19 21 60 73 81
53631 +137 136 137 163 162 163 158 157 158 166 165 166 167 166 167 153 152 153
53632 +60 74 84 37 38 37 6 6 6 13 16 17 4 0 0 1 0 0
53633 +3 2 2 4 4 4
53634 +3 2 2 4 0 0 37 38 37 137 136 137 167 166 167 158 157 158
53635 +157 156 157 154 153 154 157 156 157 167 166 167 174 174 174 125 124 125
53636 +37 38 37 4 0 0 4 0 0 4 0 0 4 3 3 4 4 4
53637 +4 4 4 4 4 4 5 5 5 5 5 5 1 1 1 0 0 0
53638 +0 0 0 16 21 25 55 98 126 90 154 193 136 185 209 101 161 196
53639 +101 161 196 101 161 196 136 185 209 136 185 209 101 161 196 55 98 126
53640 +14 17 19 0 0 0 0 0 0 0 0 0 0 0 0 0 0 0
53641 +22 40 52 90 154 193 146 190 211 146 190 211 136 185 209 136 185 209
53642 +136 185 209 136 185 209 136 185 209 101 161 196 35 83 115 7 11 13
53643 +17 23 27 59 113 148 136 185 209 101 161 196 34 86 122 7 12 15
53644 +2 5 5 3 4 3 6 6 6 60 73 81 131 129 131 163 162 163
53645 +166 165 166 174 174 174 174 174 174 163 162 163 125 124 125 41 54 63
53646 +13 16 17 4 0 0 4 0 0 4 0 0 1 0 0 2 2 2
53647 +4 4 4 4 4 4
53648 +1 1 1 2 1 0 43 57 68 137 136 137 153 152 153 153 152 153
53649 +163 162 163 156 155 156 165 164 165 167 166 167 60 74 84 6 6 6
53650 +4 0 0 4 0 0 5 5 5 4 4 4 4 4 4 4 4 4
53651 +4 5 5 6 6 6 4 3 3 0 0 0 0 0 0 11 15 18
53652 +40 71 93 100 139 164 101 161 196 101 161 196 101 161 196 101 161 196
53653 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 136 185 209
53654 +101 161 196 45 69 86 6 6 6 0 0 0 17 23 27 55 98 126
53655 +136 185 209 146 190 211 136 185 209 136 185 209 136 185 209 136 185 209
53656 +136 185 209 136 185 209 90 154 193 22 40 52 7 11 13 50 82 103
53657 +136 185 209 136 185 209 53 118 160 22 40 52 7 11 13 2 5 5
53658 +3 4 3 37 38 37 125 124 125 157 156 157 166 165 166 167 166 167
53659 +174 174 174 174 174 174 137 136 137 60 73 81 4 0 0 4 0 0
53660 +4 0 0 4 0 0 5 5 5 3 3 3 3 3 3 4 4 4
53661 +4 4 4 4 4 4
53662 +4 0 0 4 0 0 41 54 63 137 136 137 125 124 125 131 129 131
53663 +155 154 155 167 166 167 174 174 174 60 74 84 6 6 6 4 0 0
53664 +4 3 3 6 6 6 4 4 4 4 4 4 4 4 4 5 5 5
53665 +4 4 4 1 1 1 0 0 0 3 6 7 41 65 82 72 125 159
53666 +101 161 196 101 161 196 101 161 196 90 154 193 90 154 193 101 161 196
53667 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
53668 +136 185 209 136 185 209 80 127 157 55 98 126 101 161 196 146 190 211
53669 +136 185 209 136 185 209 136 185 209 101 161 196 136 185 209 101 161 196
53670 +136 185 209 101 161 196 35 83 115 22 30 35 101 161 196 172 205 220
53671 +90 154 193 28 67 93 7 11 13 2 5 5 3 4 3 13 16 17
53672 +85 115 134 167 166 167 174 174 174 174 174 174 174 174 174 174 174 174
53673 +167 166 167 60 74 84 13 16 17 4 0 0 4 0 0 4 3 3
53674 +6 6 6 5 5 5 4 4 4 5 5 5 4 4 4 5 5 5
53675 +5 5 5 5 5 5
53676 +1 1 1 4 0 0 41 54 63 137 136 137 137 136 137 125 124 125
53677 +131 129 131 167 166 167 157 156 157 37 38 37 6 6 6 4 0 0
53678 +6 6 6 5 5 5 4 4 4 4 4 4 4 5 5 2 2 1
53679 +0 0 0 0 0 0 26 37 45 58 111 146 101 161 196 101 161 196
53680 +101 161 196 90 154 193 90 154 193 90 154 193 101 161 196 101 161 196
53681 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53682 +101 161 196 136 185 209 136 185 209 136 185 209 146 190 211 136 185 209
53683 +136 185 209 101 161 196 136 185 209 136 185 209 101 161 196 136 185 209
53684 +101 161 196 136 185 209 136 185 209 136 185 209 136 185 209 16 89 141
53685 +7 11 13 2 5 5 2 5 5 13 16 17 60 73 81 154 154 154
53686 +174 174 174 174 174 174 174 174 174 174 174 174 163 162 163 125 124 125
53687 +24 26 27 4 0 0 4 0 0 4 0 0 5 5 5 5 5 5
53688 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
53689 +5 5 5 4 4 4
53690 +4 0 0 6 6 6 37 38 37 137 136 137 137 136 137 131 129 131
53691 +131 129 131 153 152 153 131 129 131 26 28 28 4 0 0 4 3 3
53692 +6 6 6 4 4 4 4 4 4 4 4 4 0 0 0 0 0 0
53693 +13 20 25 51 88 114 90 154 193 101 161 196 101 161 196 90 154 193
53694 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
53695 +101 161 196 101 161 196 101 161 196 101 161 196 136 185 209 101 161 196
53696 +101 161 196 136 185 209 101 161 196 136 185 209 136 185 209 101 161 196
53697 +136 185 209 101 161 196 136 185 209 101 161 196 101 161 196 101 161 196
53698 +136 185 209 136 185 209 136 185 209 37 112 160 21 29 34 5 7 8
53699 +2 5 5 13 16 17 43 57 68 131 129 131 174 174 174 174 174 174
53700 +174 174 174 167 166 167 157 156 157 125 124 125 37 38 37 4 0 0
53701 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
53702 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53703 +4 4 4 4 4 4
53704 +1 1 1 4 0 0 41 54 63 153 152 153 137 136 137 137 136 137
53705 +137 136 137 153 152 153 125 124 125 24 26 27 4 0 0 3 2 2
53706 +4 4 4 4 4 4 4 3 3 4 0 0 3 6 7 43 61 72
53707 +64 123 161 101 161 196 90 154 193 90 154 193 90 154 193 90 154 193
53708 +90 154 193 90 154 193 90 154 193 90 154 193 101 161 196 90 154 193
53709 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53710 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53711 +136 185 209 101 161 196 101 161 196 136 185 209 136 185 209 101 161 196
53712 +101 161 196 90 154 193 28 67 93 13 16 17 7 11 13 3 6 7
53713 +37 51 59 125 124 125 163 162 163 174 174 174 167 166 167 166 165 166
53714 +167 166 167 131 129 131 60 73 81 4 0 0 4 0 0 4 0 0
53715 +3 3 3 5 5 5 6 6 6 4 4 4 4 4 4 4 4 4
53716 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53717 +4 4 4 4 4 4
53718 +4 0 0 4 0 0 41 54 63 137 136 137 153 152 153 137 136 137
53719 +153 152 153 157 156 157 125 124 125 24 26 27 0 0 0 2 2 2
53720 +4 4 4 4 4 4 2 0 0 0 0 0 28 67 93 90 154 193
53721 +90 154 193 90 154 193 90 154 193 90 154 193 64 123 161 90 154 193
53722 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
53723 +90 154 193 101 161 196 101 161 196 101 161 196 90 154 193 136 185 209
53724 +101 161 196 101 161 196 136 185 209 101 161 196 136 185 209 101 161 196
53725 +101 161 196 101 161 196 136 185 209 101 161 196 101 161 196 90 154 193
53726 +35 83 115 13 16 17 3 6 7 2 5 5 13 16 17 60 74 84
53727 +154 154 154 166 165 166 165 164 165 158 157 158 163 162 163 157 156 157
53728 +60 74 84 13 16 17 4 0 0 4 0 0 3 2 2 4 4 4
53729 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53730 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53731 +4 4 4 4 4 4
53732 +1 1 1 4 0 0 41 54 63 157 156 157 155 154 155 137 136 137
53733 +153 152 153 158 157 158 137 136 137 26 28 28 2 0 0 2 2 2
53734 +4 4 4 4 4 4 1 0 0 6 10 14 34 86 122 90 154 193
53735 +64 123 161 90 154 193 64 123 161 90 154 193 90 154 193 90 154 193
53736 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
53737 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53738 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 101 161 196
53739 +136 185 209 101 161 196 136 185 209 90 154 193 26 108 161 22 40 52
53740 +13 16 17 5 7 8 2 5 5 2 5 5 37 38 37 165 164 165
53741 +174 174 174 163 162 163 154 154 154 165 164 165 167 166 167 60 73 81
53742 +6 6 6 4 0 0 4 0 0 4 4 4 4 4 4 4 4 4
53743 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53744 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53745 +4 4 4 4 4 4
53746 +4 0 0 6 6 6 41 54 63 156 155 156 158 157 158 153 152 153
53747 +156 155 156 165 164 165 137 136 137 26 28 28 0 0 0 2 2 2
53748 +4 4 5 4 4 4 2 0 0 7 12 15 31 96 139 64 123 161
53749 +90 154 193 64 123 161 90 154 193 90 154 193 64 123 161 90 154 193
53750 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
53751 +90 154 193 90 154 193 90 154 193 101 161 196 101 161 196 101 161 196
53752 +101 161 196 101 161 196 101 161 196 101 161 196 101 161 196 136 185 209
53753 +101 161 196 136 185 209 26 108 161 22 40 52 7 11 13 5 7 8
53754 +2 5 5 2 5 5 2 5 5 2 2 1 37 38 37 158 157 158
53755 +174 174 174 154 154 154 156 155 156 167 166 167 165 164 165 37 38 37
53756 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53757 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53758 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53759 +4 4 4 4 4 4
53760 +3 1 0 4 0 0 60 73 81 157 156 157 163 162 163 153 152 153
53761 +158 157 158 167 166 167 137 136 137 26 28 28 2 0 0 2 2 2
53762 +4 5 5 4 4 4 4 0 0 7 12 15 24 86 132 26 108 161
53763 +37 112 160 64 123 161 90 154 193 64 123 161 90 154 193 90 154 193
53764 +90 154 193 90 154 193 90 154 193 90 154 193 90 154 193 90 154 193
53765 +90 154 193 101 161 196 90 154 193 101 161 196 101 161 196 101 161 196
53766 +101 161 196 101 161 196 101 161 196 136 185 209 101 161 196 136 185 209
53767 +90 154 193 35 83 115 13 16 17 13 16 17 7 11 13 3 6 7
53768 +5 7 8 6 6 6 3 4 3 2 2 1 30 32 34 154 154 154
53769 +167 166 167 154 154 154 154 154 154 174 174 174 165 164 165 37 38 37
53770 +6 6 6 4 0 0 6 6 6 4 4 4 4 4 4 4 4 4
53771 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53772 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53773 +4 4 4 4 4 4
53774 +4 0 0 4 0 0 41 54 63 163 162 163 166 165 166 154 154 154
53775 +163 162 163 174 174 174 137 136 137 26 28 28 0 0 0 2 2 2
53776 +4 5 5 4 4 5 1 1 2 6 10 14 28 67 93 18 97 151
53777 +18 97 151 18 97 151 26 108 161 37 112 160 37 112 160 90 154 193
53778 +64 123 161 90 154 193 90 154 193 90 154 193 90 154 193 101 161 196
53779 +90 154 193 101 161 196 101 161 196 90 154 193 101 161 196 101 161 196
53780 +101 161 196 101 161 196 101 161 196 136 185 209 90 154 193 16 89 141
53781 +13 20 25 7 11 13 5 7 8 5 7 8 2 5 5 4 5 5
53782 +3 4 3 4 5 5 3 4 3 0 0 0 37 38 37 158 157 158
53783 +174 174 174 158 157 158 158 157 158 167 166 167 174 174 174 41 54 63
53784 +4 0 0 3 2 2 5 5 5 4 4 4 4 4 4 4 4 4
53785 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53786 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53787 +4 4 4 4 4 4
53788 +1 1 1 4 0 0 60 73 81 165 164 165 174 174 174 158 157 158
53789 +167 166 167 174 174 174 153 152 153 26 28 28 2 0 0 2 2 2
53790 +4 5 5 4 4 4 4 0 0 7 12 15 10 87 144 10 87 144
53791 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
53792 +26 108 161 37 112 160 53 118 160 90 154 193 90 154 193 90 154 193
53793 +90 154 193 90 154 193 101 161 196 101 161 196 101 161 196 101 161 196
53794 +101 161 196 136 185 209 90 154 193 26 108 161 22 40 52 13 16 17
53795 +7 11 13 3 6 7 5 7 8 5 7 8 2 5 5 4 5 5
53796 +4 5 5 6 6 6 3 4 3 0 0 0 30 32 34 158 157 158
53797 +174 174 174 156 155 156 155 154 155 165 164 165 154 153 154 37 38 37
53798 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53799 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53800 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53801 +4 4 4 4 4 4
53802 +4 0 0 4 0 0 60 73 81 167 166 167 174 174 174 163 162 163
53803 +174 174 174 174 174 174 153 152 153 26 28 28 0 0 0 3 3 3
53804 +5 5 5 4 4 4 1 1 2 7 12 15 28 67 93 18 97 151
53805 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
53806 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53807 +90 154 193 26 108 161 90 154 193 90 154 193 90 154 193 101 161 196
53808 +101 161 196 26 108 161 22 40 52 13 16 17 7 11 13 2 5 5
53809 +2 5 5 6 6 6 2 5 5 4 5 5 4 5 5 4 5 5
53810 +3 4 3 5 5 5 3 4 3 2 0 0 30 32 34 137 136 137
53811 +153 152 153 137 136 137 131 129 131 137 136 137 131 129 131 37 38 37
53812 +4 0 0 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53813 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53814 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53815 +4 4 4 4 4 4
53816 +1 1 1 4 0 0 60 73 81 167 166 167 174 174 174 166 165 166
53817 +174 174 174 177 184 187 153 152 153 30 32 34 1 0 0 3 3 3
53818 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
53819 +18 97 151 18 97 151 18 97 151 26 108 161 26 108 161 26 108 161
53820 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53821 +26 108 161 26 108 161 26 108 161 90 154 193 90 154 193 26 108 161
53822 +35 83 115 13 16 17 7 11 13 5 7 8 3 6 7 5 7 8
53823 +2 5 5 6 6 6 4 5 5 4 5 5 3 4 3 4 5 5
53824 +3 4 3 6 6 6 3 4 3 0 0 0 26 28 28 125 124 125
53825 +131 129 131 125 124 125 125 124 125 131 129 131 131 129 131 37 38 37
53826 +4 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53827 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53828 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53829 +4 4 4 4 4 4
53830 +3 1 0 4 0 0 60 73 81 174 174 174 177 184 187 167 166 167
53831 +174 174 174 177 184 187 153 152 153 30 32 34 0 0 0 3 3 3
53832 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
53833 +18 97 151 18 97 151 18 97 151 18 97 151 18 97 151 26 108 161
53834 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53835 +26 108 161 90 154 193 26 108 161 26 108 161 24 86 132 13 20 25
53836 +7 11 13 13 20 25 22 40 52 5 7 8 3 4 3 3 4 3
53837 +4 5 5 3 4 3 4 5 5 3 4 3 4 5 5 3 4 3
53838 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
53839 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53840 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53841 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53842 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53843 +4 4 4 4 4 4
53844 +1 1 1 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
53845 +174 174 174 190 197 201 157 156 157 30 32 34 1 0 0 3 3 3
53846 +5 5 5 4 3 3 4 0 0 7 12 15 10 87 144 10 87 144
53847 +18 97 151 19 95 150 19 95 150 18 97 151 18 97 151 26 108 161
53848 +18 97 151 26 108 161 26 108 161 26 108 161 26 108 161 90 154 193
53849 +26 108 161 26 108 161 26 108 161 22 40 52 2 5 5 3 4 3
53850 +28 67 93 37 112 160 34 86 122 2 5 5 3 4 3 3 4 3
53851 +3 4 3 3 4 3 3 4 3 2 2 1 3 4 3 4 4 4
53852 +4 5 5 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53853 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53854 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53855 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53856 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53857 +4 4 4 4 4 4
53858 +4 0 0 4 0 0 60 73 81 174 174 174 177 184 187 174 174 174
53859 +174 174 174 190 197 201 158 157 158 30 32 34 0 0 0 2 2 2
53860 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 18 97 151
53861 +10 87 144 19 95 150 19 95 150 18 97 151 18 97 151 18 97 151
53862 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53863 +18 97 151 22 40 52 2 5 5 2 2 1 22 40 52 26 108 161
53864 +90 154 193 37 112 160 22 40 52 3 4 3 13 20 25 22 30 35
53865 +3 6 7 1 1 1 2 2 2 6 9 11 5 5 5 4 3 3
53866 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
53867 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53868 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53869 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53870 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53871 +4 4 4 4 4 4
53872 +1 1 1 4 0 0 60 73 81 177 184 187 193 200 203 174 174 174
53873 +177 184 187 193 200 203 163 162 163 30 32 34 4 0 0 2 2 2
53874 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
53875 +10 87 144 10 87 144 19 95 150 19 95 150 19 95 150 18 97 151
53876 +26 108 161 26 108 161 26 108 161 90 154 193 26 108 161 28 67 93
53877 +6 10 14 2 5 5 13 20 25 24 86 132 37 112 160 90 154 193
53878 +10 87 144 7 12 15 2 5 5 28 67 93 37 112 160 28 67 93
53879 +2 2 1 7 12 15 35 83 115 28 67 93 3 6 7 1 0 0
53880 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53881 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53882 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53883 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53884 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53885 +4 4 4 4 4 4
53886 +4 0 0 4 0 0 60 73 81 174 174 174 190 197 201 174 174 174
53887 +177 184 187 193 200 203 163 162 163 30 32 34 0 0 0 2 2 2
53888 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
53889 +10 87 144 16 89 141 19 95 150 10 87 144 26 108 161 26 108 161
53890 +26 108 161 26 108 161 26 108 161 28 67 93 6 10 14 1 1 2
53891 +7 12 15 28 67 93 26 108 161 16 89 141 24 86 132 21 29 34
53892 +3 4 3 21 29 34 37 112 160 37 112 160 27 99 146 21 29 34
53893 +21 29 34 26 108 161 90 154 193 35 83 115 1 1 2 2 0 0
53894 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 125 124 125
53895 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53896 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53897 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53898 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53899 +4 4 4 4 4 4
53900 +3 1 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
53901 +190 197 201 193 200 203 165 164 165 37 38 37 4 0 0 2 2 2
53902 +5 5 5 4 3 3 4 0 0 6 10 14 24 86 132 10 87 144
53903 +10 87 144 10 87 144 16 89 141 18 97 151 18 97 151 10 87 144
53904 +24 86 132 24 86 132 13 20 25 4 5 7 4 5 7 22 40 52
53905 +18 97 151 37 112 160 26 108 161 7 12 15 1 1 1 0 0 0
53906 +28 67 93 37 112 160 26 108 161 28 67 93 22 40 52 28 67 93
53907 +26 108 161 90 154 193 26 108 161 10 87 144 0 0 0 2 0 0
53908 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53909 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53910 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53911 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53912 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53913 +4 4 4 4 4 4
53914 +4 0 0 6 6 6 60 73 81 174 174 174 193 200 203 174 174 174
53915 +190 197 201 193 200 203 165 164 165 30 32 34 0 0 0 2 2 2
53916 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
53917 +10 87 144 10 87 144 10 87 144 18 97 151 28 67 93 6 10 14
53918 +0 0 0 1 1 2 4 5 7 13 20 25 16 89 141 26 108 161
53919 +26 108 161 26 108 161 24 86 132 6 9 11 2 3 3 22 40 52
53920 +37 112 160 16 89 141 22 40 52 28 67 93 26 108 161 26 108 161
53921 +90 154 193 26 108 161 26 108 161 28 67 93 1 1 1 4 0 0
53922 +4 4 4 5 5 5 3 3 3 4 0 0 26 28 28 124 126 130
53923 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53924 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53925 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53926 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53927 +4 4 4 4 4 4
53928 +4 0 0 4 0 0 60 73 81 193 200 203 193 200 203 174 174 174
53929 +193 200 203 193 200 203 167 166 167 37 38 37 4 0 0 2 2 2
53930 +5 5 5 4 4 4 4 0 0 6 10 14 28 67 93 10 87 144
53931 +10 87 144 10 87 144 18 97 151 10 87 144 13 20 25 4 5 7
53932 +1 1 2 1 1 1 22 40 52 26 108 161 26 108 161 26 108 161
53933 +26 108 161 26 108 161 26 108 161 24 86 132 22 40 52 22 40 52
53934 +22 40 52 22 40 52 10 87 144 26 108 161 26 108 161 26 108 161
53935 +26 108 161 26 108 161 90 154 193 10 87 144 0 0 0 4 0 0
53936 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53937 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53938 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53939 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53940 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53941 +4 4 4 4 4 4
53942 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
53943 +190 197 201 205 212 215 167 166 167 30 32 34 0 0 0 2 2 2
53944 +5 5 5 4 4 4 1 1 2 6 10 14 28 67 93 10 87 144
53945 +10 87 144 10 87 144 10 87 144 10 87 144 22 40 52 1 1 2
53946 +2 0 0 1 1 2 24 86 132 26 108 161 26 108 161 26 108 161
53947 +26 108 161 19 95 150 16 89 141 10 87 144 22 40 52 22 40 52
53948 +10 87 144 26 108 161 37 112 160 26 108 161 26 108 161 26 108 161
53949 +26 108 161 26 108 161 26 108 161 28 67 93 2 0 0 3 1 0
53950 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
53951 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53952 +0 0 0 3 3 3 5 5 5 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
53956 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
53957 +193 200 203 193 200 203 174 174 174 37 38 37 4 0 0 2 2 2
53958 +5 5 5 4 4 4 3 2 2 1 1 2 13 20 25 10 87 144
53959 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 13 20 25
53960 +13 20 25 22 40 52 10 87 144 18 97 151 18 97 151 26 108 161
53961 +10 87 144 13 20 25 6 10 14 21 29 34 24 86 132 18 97 151
53962 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53963 +26 108 161 90 154 193 18 97 151 13 20 25 0 0 0 4 3 3
53964 +4 4 4 5 5 5 3 3 3 0 0 0 26 28 28 131 129 131
53965 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53966 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53967 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53968 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53969 +4 4 4 4 4 4
53970 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
53971 +190 197 201 220 221 221 167 166 167 30 32 34 1 0 0 2 2 2
53972 +5 5 5 4 4 4 4 4 5 2 5 5 4 5 7 13 20 25
53973 +28 67 93 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
53974 +10 87 144 10 87 144 18 97 151 10 87 144 18 97 151 18 97 151
53975 +28 67 93 2 3 3 0 0 0 28 67 93 26 108 161 26 108 161
53976 +26 108 161 26 108 161 26 108 161 26 108 161 26 108 161 26 108 161
53977 +26 108 161 10 87 144 13 20 25 1 1 2 3 2 2 4 4 4
53978 +4 4 4 5 5 5 3 3 3 2 0 0 26 28 28 131 129 131
53979 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53980 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53981 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53982 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53983 +4 4 4 4 4 4
53984 +4 0 0 4 0 0 60 73 81 220 221 221 190 197 201 174 174 174
53985 +193 200 203 193 200 203 174 174 174 26 28 28 4 0 0 4 3 3
53986 +5 5 5 4 4 4 4 4 4 4 4 5 1 1 2 2 5 5
53987 +4 5 7 22 40 52 10 87 144 10 87 144 18 97 151 10 87 144
53988 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 18 97 151
53989 +10 87 144 28 67 93 22 40 52 10 87 144 26 108 161 18 97 151
53990 +18 97 151 18 97 151 26 108 161 26 108 161 26 108 161 26 108 161
53991 +22 40 52 1 1 2 0 0 0 2 3 3 4 4 4 4 4 4
53992 +4 4 4 5 5 5 4 4 4 0 0 0 26 28 28 131 129 131
53993 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
53994 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
53995 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53996 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
53997 +4 4 4 4 4 4
53998 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
53999 +190 197 201 220 221 221 190 197 201 41 54 63 4 0 0 2 2 2
54000 +6 6 6 4 4 4 4 4 4 4 4 5 4 4 5 3 3 3
54001 +1 1 2 1 1 2 6 10 14 22 40 52 10 87 144 18 97 151
54002 +18 97 151 10 87 144 10 87 144 10 87 144 18 97 151 10 87 144
54003 +10 87 144 18 97 151 26 108 161 18 97 151 18 97 151 10 87 144
54004 +26 108 161 26 108 161 26 108 161 10 87 144 28 67 93 6 10 14
54005 +1 1 2 1 1 2 4 3 3 4 4 5 4 4 4 4 4 4
54006 +5 5 5 5 5 5 1 1 1 4 0 0 37 51 59 137 136 137
54007 +137 136 137 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54008 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54009 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54010 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54011 +4 4 4 4 4 4
54012 +4 0 0 4 0 0 60 73 81 220 221 221 193 200 203 174 174 174
54013 +193 200 203 193 200 203 220 221 221 137 136 137 13 16 17 4 0 0
54014 +2 2 2 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5
54015 +4 4 5 4 3 3 1 1 2 4 5 7 13 20 25 28 67 93
54016 +10 87 144 10 87 144 10 87 144 10 87 144 10 87 144 10 87 144
54017 +10 87 144 18 97 151 18 97 151 10 87 144 18 97 151 26 108 161
54018 +26 108 161 18 97 151 28 67 93 6 10 14 0 0 0 0 0 0
54019 +2 3 3 4 5 5 4 4 5 4 4 4 4 4 4 5 5 5
54020 +3 3 3 1 1 1 0 0 0 16 19 21 125 124 125 137 136 137
54021 +131 129 131 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54022 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54023 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54024 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54025 +4 4 4 4 4 4
54026 +4 0 0 6 6 6 60 73 81 174 174 174 220 221 221 174 174 174
54027 +193 200 203 190 197 201 220 221 221 220 221 221 153 152 153 30 32 34
54028 +0 0 0 0 0 0 2 2 2 4 4 4 4 4 4 4 4 4
54029 +4 4 4 4 5 5 4 5 7 1 1 2 1 1 2 4 5 7
54030 +13 20 25 28 67 93 10 87 144 18 97 151 10 87 144 10 87 144
54031 +10 87 144 10 87 144 10 87 144 18 97 151 26 108 161 18 97 151
54032 +28 67 93 7 12 15 0 0 0 0 0 0 2 2 1 4 4 4
54033 +4 5 5 4 5 5 4 4 4 4 4 4 3 3 3 0 0 0
54034 +0 0 0 0 0 0 37 38 37 125 124 125 158 157 158 131 129 131
54035 +125 124 125 125 124 125 125 124 125 137 136 137 131 129 131 37 38 37
54036 +0 0 0 3 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54037 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54038 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54039 +4 4 4 4 4 4
54040 +4 3 3 4 0 0 41 54 63 193 200 203 220 221 221 174 174 174
54041 +193 200 203 193 200 203 193 200 203 220 221 221 244 246 246 193 200 203
54042 +120 125 127 5 5 5 1 0 0 0 0 0 1 1 1 4 4 4
54043 +4 4 4 4 4 4 4 5 5 4 5 5 4 4 5 1 1 2
54044 +4 5 7 4 5 7 22 40 52 10 87 144 10 87 144 10 87 144
54045 +10 87 144 10 87 144 18 97 151 10 87 144 10 87 144 13 20 25
54046 +4 5 7 2 3 3 1 1 2 4 4 4 4 5 5 4 4 4
54047 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 1 2
54048 +24 26 27 60 74 84 153 152 153 163 162 163 137 136 137 125 124 125
54049 +125 124 125 125 124 125 125 124 125 137 136 137 125 124 125 26 28 28
54050 +0 0 0 3 3 3 5 5 5 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
54054 +4 0 0 6 6 6 26 28 28 156 155 156 220 221 221 220 221 221
54055 +174 174 174 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54056 +220 221 221 167 166 167 60 73 81 7 11 13 0 0 0 0 0 0
54057 +3 3 3 4 4 4 4 4 4 4 4 4 4 4 5 4 4 5
54058 +4 4 5 1 1 2 1 1 2 4 5 7 22 40 52 10 87 144
54059 +10 87 144 10 87 144 10 87 144 22 40 52 4 5 7 1 1 2
54060 +1 1 2 4 4 5 4 4 4 4 4 4 4 4 4 4 4 4
54061 +5 5 5 2 2 2 0 0 0 4 0 0 16 19 21 60 73 81
54062 +137 136 137 167 166 167 158 157 158 137 136 137 131 129 131 131 129 131
54063 +125 124 125 125 124 125 131 129 131 155 154 155 60 74 84 5 7 8
54064 +0 0 0 4 4 4 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
54068 +5 5 5 4 0 0 4 0 0 60 73 81 193 200 203 220 221 221
54069 +193 200 203 193 200 203 193 200 203 193 200 203 205 212 215 220 221 221
54070 +220 221 221 220 221 221 220 221 221 137 136 137 43 57 68 6 6 6
54071 +4 0 0 1 1 1 4 4 4 4 4 4 4 4 4 4 4 4
54072 +4 4 5 4 4 5 3 2 2 1 1 2 2 5 5 13 20 25
54073 +22 40 52 22 40 52 13 20 25 2 3 3 1 1 2 3 3 3
54074 +4 5 7 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54075 +1 1 1 0 0 0 2 3 3 41 54 63 131 129 131 166 165 166
54076 +166 165 166 155 154 155 153 152 153 137 136 137 137 136 137 125 124 125
54077 +125 124 125 137 136 137 137 136 137 125 124 125 37 38 37 4 3 3
54078 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4
54081 +4 4 4 4 4 4
54082 +4 3 3 6 6 6 6 6 6 13 16 17 60 73 81 167 166 167
54083 +220 221 221 220 221 221 220 221 221 193 200 203 193 200 203 193 200 203
54084 +205 212 215 220 221 221 220 221 221 244 246 246 205 212 215 125 124 125
54085 +24 26 27 0 0 0 0 0 0 2 2 2 5 5 5 5 5 5
54086 +4 4 4 4 4 4 4 4 4 4 4 5 1 1 2 4 5 7
54087 +4 5 7 4 5 7 1 1 2 3 2 2 4 4 5 4 4 4
54088 +4 4 4 4 4 4 5 5 5 4 4 4 0 0 0 0 0 0
54089 +2 0 0 26 28 28 125 124 125 174 174 174 174 174 174 166 165 166
54090 +156 155 156 153 152 153 137 136 137 137 136 137 131 129 131 137 136 137
54091 +137 136 137 137 136 137 60 74 84 30 32 34 4 0 0 4 0 0
54092 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54093 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54094 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54095 +4 4 4 4 4 4
54096 +5 5 5 6 6 6 4 0 0 4 0 0 6 6 6 26 28 28
54097 +125 124 125 174 174 174 220 221 221 220 221 221 220 221 221 193 200 203
54098 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54099 +193 200 203 60 74 84 13 16 17 4 0 0 0 0 0 3 3 3
54100 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 5 3 3 3
54101 +1 1 2 3 3 3 4 4 5 4 4 5 4 4 4 4 4 4
54102 +5 5 5 5 5 5 2 2 2 0 0 0 0 0 0 13 16 17
54103 +60 74 84 174 174 174 193 200 203 174 174 174 167 166 167 163 162 163
54104 +153 152 153 153 152 153 137 136 137 137 136 137 153 152 153 137 136 137
54105 +125 124 125 41 54 63 24 26 27 4 0 0 4 0 0 5 5 5
54106 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54107 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54108 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54109 +4 4 4 4 4 4
54110 +4 3 3 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54111 +6 6 6 37 38 37 131 129 131 220 221 221 220 221 221 220 221 221
54112 +193 200 203 193 200 203 220 221 221 205 212 215 220 221 221 244 246 246
54113 +244 246 246 244 246 246 174 174 174 41 54 63 0 0 0 0 0 0
54114 +0 0 0 4 4 4 5 5 5 5 5 5 4 4 4 4 4 5
54115 +4 4 5 4 4 5 4 4 4 4 4 4 6 6 6 6 6 6
54116 +3 3 3 0 0 0 2 0 0 13 16 17 60 73 81 156 155 156
54117 +220 221 221 193 200 203 174 174 174 165 164 165 163 162 163 154 153 154
54118 +153 152 153 153 152 153 158 157 158 163 162 163 137 136 137 60 73 81
54119 +13 16 17 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
54120 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54121 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54122 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54123 +4 4 4 4 4 4
54124 +5 5 5 4 3 3 4 3 3 6 6 6 6 6 6 6 6 6
54125 +6 6 6 6 6 6 6 6 6 37 38 37 167 166 167 244 246 246
54126 +244 246 246 220 221 221 205 212 215 205 212 215 220 221 221 193 200 203
54127 +220 221 221 244 246 246 244 246 246 244 246 246 137 136 137 37 38 37
54128 +3 2 2 0 0 0 1 1 1 5 5 5 5 5 5 4 4 4
54129 +4 4 4 4 4 4 4 4 4 5 5 5 4 4 4 1 1 1
54130 +0 0 0 5 5 5 43 57 68 153 152 153 193 200 203 220 221 221
54131 +177 184 187 174 174 174 167 166 167 166 165 166 158 157 158 157 156 157
54132 +158 157 158 166 165 166 156 155 156 85 115 134 13 16 17 4 0 0
54133 +4 0 0 4 0 0 5 5 5 5 5 5 4 4 4 4 4 4
54134 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54135 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54136 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54137 +4 4 4 4 4 4
54138 +5 5 5 4 3 3 6 6 6 6 6 6 4 0 0 6 6 6
54139 +6 6 6 6 6 6 6 6 6 6 6 6 13 16 17 60 73 81
54140 +177 184 187 220 221 221 220 221 221 220 221 221 205 212 215 220 221 221
54141 +220 221 221 205 212 215 220 221 221 244 246 246 244 246 246 205 212 215
54142 +125 124 125 30 32 34 0 0 0 0 0 0 2 2 2 5 5 5
54143 +4 4 4 4 4 4 4 4 4 1 1 1 0 0 0 1 0 0
54144 +37 38 37 131 129 131 205 212 215 220 221 221 193 200 203 174 174 174
54145 +174 174 174 174 174 174 167 166 167 165 164 165 166 165 166 167 166 167
54146 +158 157 158 125 124 125 37 38 37 4 0 0 4 0 0 4 0 0
54147 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54148 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54149 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54150 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54151 +4 4 4 4 4 4
54152 +4 4 4 5 5 5 4 3 3 4 3 3 6 6 6 6 6 6
54153 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54154 +26 28 28 125 124 125 205 212 215 220 221 221 220 221 221 220 221 221
54155 +205 212 215 220 221 221 205 212 215 220 221 221 220 221 221 244 246 246
54156 +244 246 246 190 197 201 60 74 84 16 19 21 4 0 0 0 0 0
54157 +0 0 0 0 0 0 0 0 0 0 0 0 16 19 21 120 125 127
54158 +177 184 187 220 221 221 205 212 215 177 184 187 174 174 174 177 184 187
54159 +174 174 174 174 174 174 167 166 167 174 174 174 166 165 166 137 136 137
54160 +60 73 81 13 16 17 4 0 0 4 0 0 4 3 3 6 6 6
54161 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54162 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54163 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54164 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54165 +4 4 4 4 4 4
54166 +5 5 5 4 3 3 5 5 5 4 3 3 6 6 6 4 0 0
54167 +6 6 6 6 6 6 4 0 0 6 6 6 4 0 0 6 6 6
54168 +6 6 6 6 6 6 37 38 37 137 136 137 193 200 203 220 221 221
54169 +220 221 221 205 212 215 220 221 221 205 212 215 205 212 215 220 221 221
54170 +220 221 221 220 221 221 244 246 246 166 165 166 43 57 68 2 2 2
54171 +0 0 0 4 0 0 16 19 21 60 73 81 157 156 157 202 210 214
54172 +220 221 221 193 200 203 177 184 187 177 184 187 177 184 187 174 174 174
54173 +174 174 174 174 174 174 174 174 174 157 156 157 60 74 84 24 26 27
54174 +4 0 0 4 0 0 4 0 0 6 6 6 4 4 4 4 4 4
54175 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54176 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54177 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54178 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54179 +4 4 4 4 4 4
54180 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
54181 +6 6 6 4 0 0 6 6 6 6 6 6 6 6 6 4 0 0
54182 +4 0 0 4 0 0 6 6 6 24 26 27 60 73 81 167 166 167
54183 +220 221 221 220 221 221 220 221 221 205 212 215 205 212 215 205 212 215
54184 +205 212 215 220 221 221 220 221 221 220 221 221 205 212 215 137 136 137
54185 +60 74 84 125 124 125 137 136 137 190 197 201 220 221 221 193 200 203
54186 +177 184 187 177 184 187 177 184 187 174 174 174 174 174 174 177 184 187
54187 +190 197 201 174 174 174 125 124 125 37 38 37 6 6 6 4 0 0
54188 +4 0 0 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54189 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54190 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54191 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54192 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54193 +4 4 4 4 4 4
54194 +4 4 4 4 4 4 5 5 5 5 5 5 4 3 3 6 6 6
54195 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 6 6 6
54196 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
54197 +125 124 125 193 200 203 244 246 246 220 221 221 205 212 215 205 212 215
54198 +205 212 215 193 200 203 205 212 215 205 212 215 220 221 221 220 221 221
54199 +193 200 203 193 200 203 205 212 215 193 200 203 193 200 203 177 184 187
54200 +190 197 201 190 197 201 174 174 174 190 197 201 193 200 203 190 197 201
54201 +153 152 153 60 73 81 4 0 0 4 0 0 4 0 0 3 2 2
54202 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54203 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54204 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54205 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54206 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54207 +4 4 4 4 4 4
54208 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
54209 +6 6 6 4 3 3 4 3 3 4 3 3 6 6 6 6 6 6
54210 +4 0 0 6 6 6 6 6 6 6 6 6 4 0 0 4 0 0
54211 +4 0 0 26 28 28 131 129 131 220 221 221 244 246 246 220 221 221
54212 +205 212 215 193 200 203 205 212 215 193 200 203 193 200 203 205 212 215
54213 +220 221 221 193 200 203 193 200 203 193 200 203 190 197 201 174 174 174
54214 +174 174 174 190 197 201 193 200 203 193 200 203 167 166 167 125 124 125
54215 +6 6 6 4 0 0 4 0 0 4 3 3 4 4 4 4 4 4
54216 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54217 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54218 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54219 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54220 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54221 +4 4 4 4 4 4
54222 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54223 +5 5 5 4 3 3 5 5 5 6 6 6 4 3 3 5 5 5
54224 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54225 +4 0 0 4 0 0 6 6 6 41 54 63 158 157 158 220 221 221
54226 +220 221 221 220 221 221 193 200 203 193 200 203 193 200 203 190 197 201
54227 +190 197 201 190 197 201 190 197 201 190 197 201 174 174 174 193 200 203
54228 +193 200 203 220 221 221 174 174 174 125 124 125 37 38 37 4 0 0
54229 +4 0 0 4 3 3 6 6 6 4 4 4 4 4 4 4 4 4
54230 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54231 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54232 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54233 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54234 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54235 +4 4 4 4 4 4
54236 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54237 +4 4 4 5 5 5 4 3 3 4 3 3 4 3 3 5 5 5
54238 +4 3 3 6 6 6 5 5 5 4 3 3 6 6 6 6 6 6
54239 +6 6 6 6 6 6 4 0 0 4 0 0 13 16 17 60 73 81
54240 +174 174 174 220 221 221 220 221 221 205 212 215 190 197 201 174 174 174
54241 +193 200 203 174 174 174 190 197 201 174 174 174 193 200 203 220 221 221
54242 +193 200 203 131 129 131 37 38 37 6 6 6 4 0 0 4 0 0
54243 +6 6 6 6 6 6 4 3 3 5 5 5 4 4 4 4 4 4
54244 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54245 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54246 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54247 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54248 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54249 +4 4 4 4 4 4
54250 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54251 +4 4 4 4 4 4 4 4 4 5 5 5 5 5 5 5 5 5
54252 +5 5 5 4 3 3 4 3 3 5 5 5 4 3 3 4 3 3
54253 +5 5 5 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
54254 +6 6 6 125 124 125 174 174 174 220 221 221 220 221 221 193 200 203
54255 +193 200 203 193 200 203 193 200 203 193 200 203 220 221 221 158 157 158
54256 +60 73 81 6 6 6 4 0 0 4 0 0 5 5 5 6 6 6
54257 +5 5 5 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54258 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54259 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54260 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54261 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54262 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54263 +4 4 4 4 4 4
54264 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54265 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54266 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
54267 +5 5 5 5 5 5 6 6 6 6 6 6 4 0 0 4 0 0
54268 +4 0 0 4 0 0 26 28 28 125 124 125 174 174 174 193 200 203
54269 +193 200 203 174 174 174 193 200 203 167 166 167 125 124 125 6 6 6
54270 +6 6 6 6 6 6 4 0 0 6 6 6 6 6 6 5 5 5
54271 +4 3 3 5 5 5 4 4 4 4 4 4 4 4 4 4 4 4
54272 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54273 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54274 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54275 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54276 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54277 +4 4 4 4 4 4
54278 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54279 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54280 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54281 +4 3 3 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54282 +6 6 6 4 0 0 4 0 0 6 6 6 37 38 37 125 124 125
54283 +153 152 153 131 129 131 125 124 125 37 38 37 6 6 6 6 6 6
54284 +6 6 6 4 0 0 6 6 6 6 6 6 4 3 3 5 5 5
54285 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54286 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54287 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54288 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54289 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54290 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54291 +4 4 4 4 4 4
54292 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54293 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54294 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54295 +4 4 4 5 5 5 5 5 5 4 3 3 5 5 5 4 3 3
54296 +6 6 6 6 6 6 4 0 0 4 0 0 6 6 6 6 6 6
54297 +24 26 27 24 26 27 6 6 6 6 6 6 6 6 6 4 0 0
54298 +6 6 6 6 6 6 4 0 0 6 6 6 5 5 5 4 3 3
54299 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54300 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54301 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54302 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54303 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54304 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54305 +4 4 4 4 4 4
54306 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54307 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54308 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54309 +4 4 4 4 4 4 5 5 5 4 3 3 5 5 5 6 6 6
54310 +4 0 0 6 6 6 6 6 6 6 6 6 6 6 6 6 6 6
54311 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 6 6 6
54312 +4 0 0 6 6 6 6 6 6 4 3 3 5 5 5 4 4 4
54313 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54314 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54315 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54316 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54317 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54318 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54319 +4 4 4 4 4 4
54320 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54321 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54322 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54323 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 5 5 5
54324 +5 5 5 5 5 5 4 0 0 6 6 6 4 0 0 6 6 6
54325 +6 6 6 6 6 6 6 6 6 4 0 0 6 6 6 4 0 0
54326 +6 6 6 4 3 3 5 5 5 4 3 3 5 5 5 4 4 4
54327 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54328 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54329 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54330 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54331 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54332 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54333 +4 4 4 4 4 4
54334 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54335 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54336 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54337 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 5 5 5
54338 +4 3 3 6 6 6 4 3 3 6 6 6 6 6 6 6 6 6
54339 +4 0 0 6 6 6 4 0 0 6 6 6 6 6 6 6 6 6
54340 +6 6 6 4 3 3 5 5 5 4 4 4 4 4 4 4 4 4
54341 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54342 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54343 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54344 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54345 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54346 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54347 +4 4 4 4 4 4
54348 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54349 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54350 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54351 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54352 +4 4 4 5 5 5 4 3 3 5 5 5 4 0 0 6 6 6
54353 +6 6 6 4 0 0 6 6 6 6 6 6 4 0 0 6 6 6
54354 +4 3 3 5 5 5 5 5 5 4 4 4 4 4 4 4 4 4
54355 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54356 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54357 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54358 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54359 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54360 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54361 +4 4 4 4 4 4
54362 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54363 +4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
54366 +4 4 4 5 5 5 4 3 3 5 5 5 6 6 6 4 3 3
54367 +4 3 3 6 6 6 6 6 6 4 3 3 6 6 6 4 3 3
54368 +5 5 5 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54369 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54370 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54371 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54372 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54373 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54374 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54375 +4 4 4 4 4 4
54376 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54377 +4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
54380 +4 4 4 4 4 4 4 4 4 5 5 5 4 3 3 6 6 6
54381 +5 5 5 4 3 3 4 3 3 4 3 3 5 5 5 5 5 5
54382 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54383 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54384 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54385 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54386 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54387 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54388 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54389 +4 4 4 4 4 4
54390 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 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 4 4 4 4 4 4 4 4 4 4 4 4
54394 +4 4 4 4 4 4 4 4 4 4 4 4 5 5 5 4 3 3
54395 +5 5 5 4 3 3 5 5 5 5 5 5 4 4 4 4 4 4
54396 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54397 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54398 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54399 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54400 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54401 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54402 +4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4 4
54403 +4 4 4 4 4 4
54404 diff --git a/drivers/video/matrox/matroxfb_DAC1064.c b/drivers/video/matrox/matroxfb_DAC1064.c
54405 index a01147f..5d896f8 100644
54406 --- a/drivers/video/matrox/matroxfb_DAC1064.c
54407 +++ b/drivers/video/matrox/matroxfb_DAC1064.c
54408 @@ -1088,14 +1088,20 @@ static void MGAG100_restore(struct matrox_fb_info *minfo)
54409
54410 #ifdef CONFIG_FB_MATROX_MYSTIQUE
54411 struct matrox_switch matrox_mystique = {
54412 - MGA1064_preinit, MGA1064_reset, MGA1064_init, MGA1064_restore,
54413 + .preinit = MGA1064_preinit,
54414 + .reset = MGA1064_reset,
54415 + .init = MGA1064_init,
54416 + .restore = MGA1064_restore,
54417 };
54418 EXPORT_SYMBOL(matrox_mystique);
54419 #endif
54420
54421 #ifdef CONFIG_FB_MATROX_G
54422 struct matrox_switch matrox_G100 = {
54423 - MGAG100_preinit, MGAG100_reset, MGAG100_init, MGAG100_restore,
54424 + .preinit = MGAG100_preinit,
54425 + .reset = MGAG100_reset,
54426 + .init = MGAG100_init,
54427 + .restore = MGAG100_restore,
54428 };
54429 EXPORT_SYMBOL(matrox_G100);
54430 #endif
54431 diff --git a/drivers/video/matrox/matroxfb_Ti3026.c b/drivers/video/matrox/matroxfb_Ti3026.c
54432 index 195ad7c..09743fc 100644
54433 --- a/drivers/video/matrox/matroxfb_Ti3026.c
54434 +++ b/drivers/video/matrox/matroxfb_Ti3026.c
54435 @@ -738,7 +738,10 @@ static int Ti3026_preinit(struct matrox_fb_info *minfo)
54436 }
54437
54438 struct matrox_switch matrox_millennium = {
54439 - Ti3026_preinit, Ti3026_reset, Ti3026_init, Ti3026_restore
54440 + .preinit = Ti3026_preinit,
54441 + .reset = Ti3026_reset,
54442 + .init = Ti3026_init,
54443 + .restore = Ti3026_restore
54444 };
54445 EXPORT_SYMBOL(matrox_millennium);
54446 #endif
54447 diff --git a/drivers/video/mb862xx/mb862xxfb_accel.c b/drivers/video/mb862xx/mb862xxfb_accel.c
54448 index fe92eed..106e085 100644
54449 --- a/drivers/video/mb862xx/mb862xxfb_accel.c
54450 +++ b/drivers/video/mb862xx/mb862xxfb_accel.c
54451 @@ -312,14 +312,18 @@ void mb862xxfb_init_accel(struct fb_info *info, int xres)
54452 struct mb862xxfb_par *par = info->par;
54453
54454 if (info->var.bits_per_pixel == 32) {
54455 - info->fbops->fb_fillrect = cfb_fillrect;
54456 - info->fbops->fb_copyarea = cfb_copyarea;
54457 - info->fbops->fb_imageblit = cfb_imageblit;
54458 + pax_open_kernel();
54459 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
54460 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
54461 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
54462 + pax_close_kernel();
54463 } else {
54464 outreg(disp, GC_L0EM, 3);
54465 - info->fbops->fb_fillrect = mb86290fb_fillrect;
54466 - info->fbops->fb_copyarea = mb86290fb_copyarea;
54467 - info->fbops->fb_imageblit = mb86290fb_imageblit;
54468 + pax_open_kernel();
54469 + *(void **)&info->fbops->fb_fillrect = mb86290fb_fillrect;
54470 + *(void **)&info->fbops->fb_copyarea = mb86290fb_copyarea;
54471 + *(void **)&info->fbops->fb_imageblit = mb86290fb_imageblit;
54472 + pax_close_kernel();
54473 }
54474 outreg(draw, GDC_REG_DRAW_BASE, 0);
54475 outreg(draw, GDC_REG_MODE_MISC, 0x8000);
54476 diff --git a/drivers/video/nvidia/nvidia.c b/drivers/video/nvidia/nvidia.c
54477 index ff22871..b129bed 100644
54478 --- a/drivers/video/nvidia/nvidia.c
54479 +++ b/drivers/video/nvidia/nvidia.c
54480 @@ -669,19 +669,23 @@ static int nvidiafb_set_par(struct fb_info *info)
54481 info->fix.line_length = (info->var.xres_virtual *
54482 info->var.bits_per_pixel) >> 3;
54483 if (info->var.accel_flags) {
54484 - info->fbops->fb_imageblit = nvidiafb_imageblit;
54485 - info->fbops->fb_fillrect = nvidiafb_fillrect;
54486 - info->fbops->fb_copyarea = nvidiafb_copyarea;
54487 - info->fbops->fb_sync = nvidiafb_sync;
54488 + pax_open_kernel();
54489 + *(void **)&info->fbops->fb_imageblit = nvidiafb_imageblit;
54490 + *(void **)&info->fbops->fb_fillrect = nvidiafb_fillrect;
54491 + *(void **)&info->fbops->fb_copyarea = nvidiafb_copyarea;
54492 + *(void **)&info->fbops->fb_sync = nvidiafb_sync;
54493 + pax_close_kernel();
54494 info->pixmap.scan_align = 4;
54495 info->flags &= ~FBINFO_HWACCEL_DISABLED;
54496 info->flags |= FBINFO_READS_FAST;
54497 NVResetGraphics(info);
54498 } else {
54499 - info->fbops->fb_imageblit = cfb_imageblit;
54500 - info->fbops->fb_fillrect = cfb_fillrect;
54501 - info->fbops->fb_copyarea = cfb_copyarea;
54502 - info->fbops->fb_sync = NULL;
54503 + pax_open_kernel();
54504 + *(void **)&info->fbops->fb_imageblit = cfb_imageblit;
54505 + *(void **)&info->fbops->fb_fillrect = cfb_fillrect;
54506 + *(void **)&info->fbops->fb_copyarea = cfb_copyarea;
54507 + *(void **)&info->fbops->fb_sync = NULL;
54508 + pax_close_kernel();
54509 info->pixmap.scan_align = 1;
54510 info->flags |= FBINFO_HWACCEL_DISABLED;
54511 info->flags &= ~FBINFO_READS_FAST;
54512 @@ -1173,8 +1177,11 @@ static int nvidia_set_fbinfo(struct fb_info *info)
54513 info->pixmap.size = 8 * 1024;
54514 info->pixmap.flags = FB_PIXMAP_SYSTEM;
54515
54516 - if (!hwcur)
54517 - info->fbops->fb_cursor = NULL;
54518 + if (!hwcur) {
54519 + pax_open_kernel();
54520 + *(void **)&info->fbops->fb_cursor = NULL;
54521 + pax_close_kernel();
54522 + }
54523
54524 info->var.accel_flags = (!noaccel);
54525
54526 diff --git a/drivers/video/omap2/dss/display.c b/drivers/video/omap2/dss/display.c
54527 index 669a81f..e216d76 100644
54528 --- a/drivers/video/omap2/dss/display.c
54529 +++ b/drivers/video/omap2/dss/display.c
54530 @@ -137,12 +137,14 @@ int omapdss_register_display(struct omap_dss_device *dssdev)
54531 snprintf(dssdev->alias, sizeof(dssdev->alias),
54532 "display%d", disp_num_counter++);
54533
54534 + pax_open_kernel();
54535 if (drv && drv->get_resolution == NULL)
54536 - drv->get_resolution = omapdss_default_get_resolution;
54537 + *(void **)&drv->get_resolution = omapdss_default_get_resolution;
54538 if (drv && drv->get_recommended_bpp == NULL)
54539 - drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
54540 + *(void **)&drv->get_recommended_bpp = omapdss_default_get_recommended_bpp;
54541 if (drv && drv->get_timings == NULL)
54542 - drv->get_timings = omapdss_default_get_timings;
54543 + *(void **)&drv->get_timings = omapdss_default_get_timings;
54544 + pax_close_kernel();
54545
54546 mutex_lock(&panel_list_mutex);
54547 list_add_tail(&dssdev->panel_list, &panel_list);
54548 diff --git a/drivers/video/s1d13xxxfb.c b/drivers/video/s1d13xxxfb.c
54549 index 83433cb..71e9b98 100644
54550 --- a/drivers/video/s1d13xxxfb.c
54551 +++ b/drivers/video/s1d13xxxfb.c
54552 @@ -881,8 +881,10 @@ static int s1d13xxxfb_probe(struct platform_device *pdev)
54553
54554 switch(prod_id) {
54555 case S1D13506_PROD_ID: /* activate acceleration */
54556 - s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
54557 - s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
54558 + pax_open_kernel();
54559 + *(void **)&s1d13xxxfb_fbops.fb_fillrect = s1d13xxxfb_bitblt_solidfill;
54560 + *(void **)&s1d13xxxfb_fbops.fb_copyarea = s1d13xxxfb_bitblt_copyarea;
54561 + pax_close_kernel();
54562 info->flags = FBINFO_DEFAULT | FBINFO_HWACCEL_YPAN |
54563 FBINFO_HWACCEL_FILLRECT | FBINFO_HWACCEL_COPYAREA;
54564 break;
54565 diff --git a/drivers/video/smscufx.c b/drivers/video/smscufx.c
54566 index d513ed6..90b0de9 100644
54567 --- a/drivers/video/smscufx.c
54568 +++ b/drivers/video/smscufx.c
54569 @@ -1175,7 +1175,9 @@ static int ufx_ops_release(struct fb_info *info, int user)
54570 fb_deferred_io_cleanup(info);
54571 kfree(info->fbdefio);
54572 info->fbdefio = NULL;
54573 - info->fbops->fb_mmap = ufx_ops_mmap;
54574 + pax_open_kernel();
54575 + *(void **)&info->fbops->fb_mmap = ufx_ops_mmap;
54576 + pax_close_kernel();
54577 }
54578
54579 pr_debug("released /dev/fb%d user=%d count=%d",
54580 diff --git a/drivers/video/udlfb.c b/drivers/video/udlfb.c
54581 index 025f14e..20eb4db 100644
54582 --- a/drivers/video/udlfb.c
54583 +++ b/drivers/video/udlfb.c
54584 @@ -623,11 +623,11 @@ static int dlfb_handle_damage(struct dlfb_data *dev, int x, int y,
54585 dlfb_urb_completion(urb);
54586
54587 error:
54588 - atomic_add(bytes_sent, &dev->bytes_sent);
54589 - atomic_add(bytes_identical, &dev->bytes_identical);
54590 - atomic_add(width*height*2, &dev->bytes_rendered);
54591 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
54592 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
54593 + atomic_add_unchecked(width*height*2, &dev->bytes_rendered);
54594 end_cycles = get_cycles();
54595 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
54596 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
54597 >> 10)), /* Kcycles */
54598 &dev->cpu_kcycles_used);
54599
54600 @@ -748,11 +748,11 @@ static void dlfb_dpy_deferred_io(struct fb_info *info,
54601 dlfb_urb_completion(urb);
54602
54603 error:
54604 - atomic_add(bytes_sent, &dev->bytes_sent);
54605 - atomic_add(bytes_identical, &dev->bytes_identical);
54606 - atomic_add(bytes_rendered, &dev->bytes_rendered);
54607 + atomic_add_unchecked(bytes_sent, &dev->bytes_sent);
54608 + atomic_add_unchecked(bytes_identical, &dev->bytes_identical);
54609 + atomic_add_unchecked(bytes_rendered, &dev->bytes_rendered);
54610 end_cycles = get_cycles();
54611 - atomic_add(((unsigned int) ((end_cycles - start_cycles)
54612 + atomic_add_unchecked(((unsigned int) ((end_cycles - start_cycles)
54613 >> 10)), /* Kcycles */
54614 &dev->cpu_kcycles_used);
54615 }
54616 @@ -993,7 +993,9 @@ static int dlfb_ops_release(struct fb_info *info, int user)
54617 fb_deferred_io_cleanup(info);
54618 kfree(info->fbdefio);
54619 info->fbdefio = NULL;
54620 - info->fbops->fb_mmap = dlfb_ops_mmap;
54621 + pax_open_kernel();
54622 + *(void **)&info->fbops->fb_mmap = dlfb_ops_mmap;
54623 + pax_close_kernel();
54624 }
54625
54626 pr_warn("released /dev/fb%d user=%d count=%d\n",
54627 @@ -1376,7 +1378,7 @@ static ssize_t metrics_bytes_rendered_show(struct device *fbdev,
54628 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54629 struct dlfb_data *dev = fb_info->par;
54630 return snprintf(buf, PAGE_SIZE, "%u\n",
54631 - atomic_read(&dev->bytes_rendered));
54632 + atomic_read_unchecked(&dev->bytes_rendered));
54633 }
54634
54635 static ssize_t metrics_bytes_identical_show(struct device *fbdev,
54636 @@ -1384,7 +1386,7 @@ static ssize_t metrics_bytes_identical_show(struct device *fbdev,
54637 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54638 struct dlfb_data *dev = fb_info->par;
54639 return snprintf(buf, PAGE_SIZE, "%u\n",
54640 - atomic_read(&dev->bytes_identical));
54641 + atomic_read_unchecked(&dev->bytes_identical));
54642 }
54643
54644 static ssize_t metrics_bytes_sent_show(struct device *fbdev,
54645 @@ -1392,7 +1394,7 @@ static ssize_t metrics_bytes_sent_show(struct device *fbdev,
54646 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54647 struct dlfb_data *dev = fb_info->par;
54648 return snprintf(buf, PAGE_SIZE, "%u\n",
54649 - atomic_read(&dev->bytes_sent));
54650 + atomic_read_unchecked(&dev->bytes_sent));
54651 }
54652
54653 static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
54654 @@ -1400,7 +1402,7 @@ static ssize_t metrics_cpu_kcycles_used_show(struct device *fbdev,
54655 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54656 struct dlfb_data *dev = fb_info->par;
54657 return snprintf(buf, PAGE_SIZE, "%u\n",
54658 - atomic_read(&dev->cpu_kcycles_used));
54659 + atomic_read_unchecked(&dev->cpu_kcycles_used));
54660 }
54661
54662 static ssize_t edid_show(
54663 @@ -1460,10 +1462,10 @@ static ssize_t metrics_reset_store(struct device *fbdev,
54664 struct fb_info *fb_info = dev_get_drvdata(fbdev);
54665 struct dlfb_data *dev = fb_info->par;
54666
54667 - atomic_set(&dev->bytes_rendered, 0);
54668 - atomic_set(&dev->bytes_identical, 0);
54669 - atomic_set(&dev->bytes_sent, 0);
54670 - atomic_set(&dev->cpu_kcycles_used, 0);
54671 + atomic_set_unchecked(&dev->bytes_rendered, 0);
54672 + atomic_set_unchecked(&dev->bytes_identical, 0);
54673 + atomic_set_unchecked(&dev->bytes_sent, 0);
54674 + atomic_set_unchecked(&dev->cpu_kcycles_used, 0);
54675
54676 return count;
54677 }
54678 diff --git a/drivers/video/uvesafb.c b/drivers/video/uvesafb.c
54679 index 256fba7..6e75516 100644
54680 --- a/drivers/video/uvesafb.c
54681 +++ b/drivers/video/uvesafb.c
54682 @@ -19,6 +19,7 @@
54683 #include <linux/io.h>
54684 #include <linux/mutex.h>
54685 #include <linux/slab.h>
54686 +#include <linux/moduleloader.h>
54687 #include <video/edid.h>
54688 #include <video/uvesafb.h>
54689 #ifdef CONFIG_X86
54690 @@ -565,10 +566,32 @@ static int uvesafb_vbe_getpmi(struct uvesafb_ktask *task,
54691 if ((task->t.regs.eax & 0xffff) != 0x4f || task->t.regs.es < 0xc000) {
54692 par->pmi_setpal = par->ypan = 0;
54693 } else {
54694 +
54695 +#ifdef CONFIG_PAX_KERNEXEC
54696 +#ifdef CONFIG_MODULES
54697 + par->pmi_code = module_alloc_exec((u16)task->t.regs.ecx);
54698 +#endif
54699 + if (!par->pmi_code) {
54700 + par->pmi_setpal = par->ypan = 0;
54701 + return 0;
54702 + }
54703 +#endif
54704 +
54705 par->pmi_base = (u16 *)phys_to_virt(((u32)task->t.regs.es << 4)
54706 + task->t.regs.edi);
54707 +
54708 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54709 + pax_open_kernel();
54710 + memcpy(par->pmi_code, par->pmi_base, (u16)task->t.regs.ecx);
54711 + pax_close_kernel();
54712 +
54713 + par->pmi_start = ktva_ktla(par->pmi_code + par->pmi_base[1]);
54714 + par->pmi_pal = ktva_ktla(par->pmi_code + par->pmi_base[2]);
54715 +#else
54716 par->pmi_start = (u8 *)par->pmi_base + par->pmi_base[1];
54717 par->pmi_pal = (u8 *)par->pmi_base + par->pmi_base[2];
54718 +#endif
54719 +
54720 printk(KERN_INFO "uvesafb: protected mode interface info at "
54721 "%04x:%04x\n",
54722 (u16)task->t.regs.es, (u16)task->t.regs.edi);
54723 @@ -813,13 +836,14 @@ static int uvesafb_vbe_init(struct fb_info *info)
54724 par->ypan = ypan;
54725
54726 if (par->pmi_setpal || par->ypan) {
54727 +#if !defined(CONFIG_MODULES) || !defined(CONFIG_PAX_KERNEXEC)
54728 if (__supported_pte_mask & _PAGE_NX) {
54729 par->pmi_setpal = par->ypan = 0;
54730 printk(KERN_WARNING "uvesafb: NX protection is active, "
54731 "better not use the PMI.\n");
54732 - } else {
54733 + } else
54734 +#endif
54735 uvesafb_vbe_getpmi(task, par);
54736 - }
54737 }
54738 #else
54739 /* The protected mode interface is not available on non-x86. */
54740 @@ -1453,8 +1477,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
54741 info->fix.ywrapstep = (par->ypan > 1) ? 1 : 0;
54742
54743 /* Disable blanking if the user requested so. */
54744 - if (!blank)
54745 - info->fbops->fb_blank = NULL;
54746 + if (!blank) {
54747 + pax_open_kernel();
54748 + *(void **)&info->fbops->fb_blank = NULL;
54749 + pax_close_kernel();
54750 + }
54751
54752 /*
54753 * Find out how much IO memory is required for the mode with
54754 @@ -1530,8 +1557,11 @@ static void uvesafb_init_info(struct fb_info *info, struct vbe_mode_ib *mode)
54755 info->flags = FBINFO_FLAG_DEFAULT |
54756 (par->ypan ? FBINFO_HWACCEL_YPAN : 0);
54757
54758 - if (!par->ypan)
54759 - info->fbops->fb_pan_display = NULL;
54760 + if (!par->ypan) {
54761 + pax_open_kernel();
54762 + *(void **)&info->fbops->fb_pan_display = NULL;
54763 + pax_close_kernel();
54764 + }
54765 }
54766
54767 static void uvesafb_init_mtrr(struct fb_info *info)
54768 @@ -1792,6 +1822,11 @@ out_mode:
54769 out:
54770 kfree(par->vbe_modes);
54771
54772 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54773 + if (par->pmi_code)
54774 + module_free_exec(NULL, par->pmi_code);
54775 +#endif
54776 +
54777 framebuffer_release(info);
54778 return err;
54779 }
54780 @@ -1816,6 +1851,12 @@ static int uvesafb_remove(struct platform_device *dev)
54781 kfree(par->vbe_modes);
54782 kfree(par->vbe_state_orig);
54783 kfree(par->vbe_state_saved);
54784 +
54785 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54786 + if (par->pmi_code)
54787 + module_free_exec(NULL, par->pmi_code);
54788 +#endif
54789 +
54790 }
54791
54792 framebuffer_release(info);
54793 diff --git a/drivers/video/vesafb.c b/drivers/video/vesafb.c
54794 index 1c7da3b..56ea0bd 100644
54795 --- a/drivers/video/vesafb.c
54796 +++ b/drivers/video/vesafb.c
54797 @@ -9,6 +9,7 @@
54798 */
54799
54800 #include <linux/module.h>
54801 +#include <linux/moduleloader.h>
54802 #include <linux/kernel.h>
54803 #include <linux/errno.h>
54804 #include <linux/string.h>
54805 @@ -52,8 +53,8 @@ static int vram_remap; /* Set amount of memory to be used */
54806 static int vram_total; /* Set total amount of memory */
54807 static int pmi_setpal __read_mostly = 1; /* pmi for palette changes ??? */
54808 static int ypan __read_mostly; /* 0..nothing, 1..ypan, 2..ywrap */
54809 -static void (*pmi_start)(void) __read_mostly;
54810 -static void (*pmi_pal) (void) __read_mostly;
54811 +static void (*pmi_start)(void) __read_only;
54812 +static void (*pmi_pal) (void) __read_only;
54813 static int depth __read_mostly;
54814 static int vga_compat __read_mostly;
54815 /* --------------------------------------------------------------------- */
54816 @@ -234,6 +235,7 @@ static int vesafb_probe(struct platform_device *dev)
54817 unsigned int size_remap;
54818 unsigned int size_total;
54819 char *option = NULL;
54820 + void *pmi_code = NULL;
54821
54822 /* ignore error return of fb_get_options */
54823 fb_get_options("vesafb", &option);
54824 @@ -280,10 +282,6 @@ static int vesafb_probe(struct platform_device *dev)
54825 size_remap = size_total;
54826 vesafb_fix.smem_len = size_remap;
54827
54828 -#ifndef __i386__
54829 - screen_info.vesapm_seg = 0;
54830 -#endif
54831 -
54832 if (!request_mem_region(vesafb_fix.smem_start, size_total, "vesafb")) {
54833 printk(KERN_WARNING
54834 "vesafb: cannot reserve video memory at 0x%lx\n",
54835 @@ -312,9 +310,21 @@ static int vesafb_probe(struct platform_device *dev)
54836 printk(KERN_INFO "vesafb: mode is %dx%dx%d, linelength=%d, pages=%d\n",
54837 vesafb_defined.xres, vesafb_defined.yres, vesafb_defined.bits_per_pixel, vesafb_fix.line_length, screen_info.pages);
54838
54839 +#ifdef __i386__
54840 +
54841 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54842 + pmi_code = module_alloc_exec(screen_info.vesapm_size);
54843 + if (!pmi_code)
54844 +#elif !defined(CONFIG_PAX_KERNEXEC)
54845 + if (0)
54846 +#endif
54847 +
54848 +#endif
54849 + screen_info.vesapm_seg = 0;
54850 +
54851 if (screen_info.vesapm_seg) {
54852 - printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x\n",
54853 - screen_info.vesapm_seg,screen_info.vesapm_off);
54854 + printk(KERN_INFO "vesafb: protected mode interface info at %04x:%04x %04x bytes\n",
54855 + screen_info.vesapm_seg,screen_info.vesapm_off,screen_info.vesapm_size);
54856 }
54857
54858 if (screen_info.vesapm_seg < 0xc000)
54859 @@ -322,9 +332,25 @@ static int vesafb_probe(struct platform_device *dev)
54860
54861 if (ypan || pmi_setpal) {
54862 unsigned short *pmi_base;
54863 +
54864 pmi_base = (unsigned short*)phys_to_virt(((unsigned long)screen_info.vesapm_seg << 4) + screen_info.vesapm_off);
54865 - pmi_start = (void*)((char*)pmi_base + pmi_base[1]);
54866 - pmi_pal = (void*)((char*)pmi_base + pmi_base[2]);
54867 +
54868 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54869 + pax_open_kernel();
54870 + memcpy(pmi_code, pmi_base, screen_info.vesapm_size);
54871 +#else
54872 + pmi_code = pmi_base;
54873 +#endif
54874 +
54875 + pmi_start = (void*)((char*)pmi_code + pmi_base[1]);
54876 + pmi_pal = (void*)((char*)pmi_code + pmi_base[2]);
54877 +
54878 +#if defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54879 + pmi_start = ktva_ktla(pmi_start);
54880 + pmi_pal = ktva_ktla(pmi_pal);
54881 + pax_close_kernel();
54882 +#endif
54883 +
54884 printk(KERN_INFO "vesafb: pmi: set display start = %p, set palette = %p\n",pmi_start,pmi_pal);
54885 if (pmi_base[3]) {
54886 printk(KERN_INFO "vesafb: pmi: ports = ");
54887 @@ -477,8 +503,11 @@ static int vesafb_probe(struct platform_device *dev)
54888 info->flags = FBINFO_FLAG_DEFAULT | FBINFO_MISC_FIRMWARE |
54889 (ypan ? FBINFO_HWACCEL_YPAN : 0);
54890
54891 - if (!ypan)
54892 - info->fbops->fb_pan_display = NULL;
54893 + if (!ypan) {
54894 + pax_open_kernel();
54895 + *(void **)&info->fbops->fb_pan_display = NULL;
54896 + pax_close_kernel();
54897 + }
54898
54899 if (fb_alloc_cmap(&info->cmap, 256, 0) < 0) {
54900 err = -ENOMEM;
54901 @@ -492,6 +521,11 @@ static int vesafb_probe(struct platform_device *dev)
54902 fb_info(info, "%s frame buffer device\n", info->fix.id);
54903 return 0;
54904 err:
54905 +
54906 +#if defined(__i386__) && defined(CONFIG_MODULES) && defined(CONFIG_PAX_KERNEXEC)
54907 + module_free_exec(NULL, pmi_code);
54908 +#endif
54909 +
54910 if (info->screen_base)
54911 iounmap(info->screen_base);
54912 framebuffer_release(info);
54913 diff --git a/drivers/video/via/via_clock.h b/drivers/video/via/via_clock.h
54914 index 88714ae..16c2e11 100644
54915 --- a/drivers/video/via/via_clock.h
54916 +++ b/drivers/video/via/via_clock.h
54917 @@ -56,7 +56,7 @@ struct via_clock {
54918
54919 void (*set_engine_pll_state)(u8 state);
54920 void (*set_engine_pll)(struct via_pll_config config);
54921 -};
54922 +} __no_const;
54923
54924
54925 static inline u32 get_pll_internal_frequency(u32 ref_freq,
54926 diff --git a/drivers/xen/xenfs/xenstored.c b/drivers/xen/xenfs/xenstored.c
54927 index fef20db..d28b1ab 100644
54928 --- a/drivers/xen/xenfs/xenstored.c
54929 +++ b/drivers/xen/xenfs/xenstored.c
54930 @@ -24,7 +24,12 @@ static int xsd_release(struct inode *inode, struct file *file)
54931 static int xsd_kva_open(struct inode *inode, struct file *file)
54932 {
54933 file->private_data = (void *)kasprintf(GFP_KERNEL, "0x%p",
54934 +#ifdef CONFIG_GRKERNSEC_HIDESYM
54935 + NULL);
54936 +#else
54937 xen_store_interface);
54938 +#endif
54939 +
54940 if (!file->private_data)
54941 return -ENOMEM;
54942 return 0;
54943 diff --git a/fs/9p/vfs_addr.c b/fs/9p/vfs_addr.c
54944 index 9ff073f..05cef23 100644
54945 --- a/fs/9p/vfs_addr.c
54946 +++ b/fs/9p/vfs_addr.c
54947 @@ -187,7 +187,7 @@ static int v9fs_vfs_writepage_locked(struct page *page)
54948
54949 retval = v9fs_file_write_internal(inode,
54950 v9inode->writeback_fid,
54951 - (__force const char __user *)buffer,
54952 + (const char __force_user *)buffer,
54953 len, &offset, 0);
54954 if (retval > 0)
54955 retval = 0;
54956 diff --git a/fs/9p/vfs_inode.c b/fs/9p/vfs_inode.c
54957 index 4e65aa9..043dc9a 100644
54958 --- a/fs/9p/vfs_inode.c
54959 +++ b/fs/9p/vfs_inode.c
54960 @@ -1306,7 +1306,7 @@ static void *v9fs_vfs_follow_link(struct dentry *dentry, struct nameidata *nd)
54961 void
54962 v9fs_vfs_put_link(struct dentry *dentry, struct nameidata *nd, void *p)
54963 {
54964 - char *s = nd_get_link(nd);
54965 + const char *s = nd_get_link(nd);
54966
54967 p9_debug(P9_DEBUG_VFS, " %s %s\n",
54968 dentry->d_name.name, IS_ERR(s) ? "<error>" : s);
54969 diff --git a/fs/Kconfig.binfmt b/fs/Kconfig.binfmt
54970 index 370b24c..ff0be7b 100644
54971 --- a/fs/Kconfig.binfmt
54972 +++ b/fs/Kconfig.binfmt
54973 @@ -103,7 +103,7 @@ config HAVE_AOUT
54974
54975 config BINFMT_AOUT
54976 tristate "Kernel support for a.out and ECOFF binaries"
54977 - depends on HAVE_AOUT
54978 + depends on HAVE_AOUT && BROKEN
54979 ---help---
54980 A.out (Assembler.OUTput) is a set of formats for libraries and
54981 executables used in the earliest versions of UNIX. Linux used
54982 diff --git a/fs/afs/inode.c b/fs/afs/inode.c
54983 index ce25d75..dc09eeb 100644
54984 --- a/fs/afs/inode.c
54985 +++ b/fs/afs/inode.c
54986 @@ -141,7 +141,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
54987 struct afs_vnode *vnode;
54988 struct super_block *sb;
54989 struct inode *inode;
54990 - static atomic_t afs_autocell_ino;
54991 + static atomic_unchecked_t afs_autocell_ino;
54992
54993 _enter("{%x:%u},%*.*s,",
54994 AFS_FS_I(dir)->fid.vid, AFS_FS_I(dir)->fid.vnode,
54995 @@ -154,7 +154,7 @@ struct inode *afs_iget_autocell(struct inode *dir, const char *dev_name,
54996 data.fid.unique = 0;
54997 data.fid.vnode = 0;
54998
54999 - inode = iget5_locked(sb, atomic_inc_return(&afs_autocell_ino),
55000 + inode = iget5_locked(sb, atomic_inc_return_unchecked(&afs_autocell_ino),
55001 afs_iget5_autocell_test, afs_iget5_set,
55002 &data);
55003 if (!inode) {
55004 diff --git a/fs/aio.c b/fs/aio.c
55005 index 062a5f6..e5618e0 100644
55006 --- a/fs/aio.c
55007 +++ b/fs/aio.c
55008 @@ -374,7 +374,7 @@ static int aio_setup_ring(struct kioctx *ctx)
55009 size += sizeof(struct io_event) * nr_events;
55010
55011 nr_pages = PFN_UP(size);
55012 - if (nr_pages < 0)
55013 + if (nr_pages <= 0)
55014 return -EINVAL;
55015
55016 file = aio_private_file(ctx, nr_pages);
55017 diff --git a/fs/attr.c b/fs/attr.c
55018 index 267968d..5dd8f96 100644
55019 --- a/fs/attr.c
55020 +++ b/fs/attr.c
55021 @@ -102,6 +102,7 @@ int inode_newsize_ok(const struct inode *inode, loff_t offset)
55022 unsigned long limit;
55023
55024 limit = rlimit(RLIMIT_FSIZE);
55025 + gr_learn_resource(current, RLIMIT_FSIZE, (unsigned long)offset, 1);
55026 if (limit != RLIM_INFINITY && offset > limit)
55027 goto out_sig;
55028 if (offset > inode->i_sb->s_maxbytes)
55029 diff --git a/fs/autofs4/waitq.c b/fs/autofs4/waitq.c
55030 index 689e40d..515cac5 100644
55031 --- a/fs/autofs4/waitq.c
55032 +++ b/fs/autofs4/waitq.c
55033 @@ -59,7 +59,7 @@ static int autofs4_write(struct autofs_sb_info *sbi,
55034 {
55035 unsigned long sigpipe, flags;
55036 mm_segment_t fs;
55037 - const char *data = (const char *)addr;
55038 + const char __user *data = (const char __force_user *)addr;
55039 ssize_t wr = 0;
55040
55041 sigpipe = sigismember(&current->pending.signal, SIGPIPE);
55042 @@ -340,6 +340,10 @@ static int validate_request(struct autofs_wait_queue **wait,
55043 return 1;
55044 }
55045
55046 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55047 +static atomic_unchecked_t autofs_dummy_name_id = ATOMIC_INIT(0);
55048 +#endif
55049 +
55050 int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55051 enum autofs_notify notify)
55052 {
55053 @@ -373,7 +377,12 @@ int autofs4_wait(struct autofs_sb_info *sbi, struct dentry *dentry,
55054
55055 /* If this is a direct mount request create a dummy name */
55056 if (IS_ROOT(dentry) && autofs_type_trigger(sbi->type))
55057 +#ifdef CONFIG_GRKERNSEC_HIDESYM
55058 + /* this name does get written to userland via autofs4_write() */
55059 + qstr.len = sprintf(name, "%08x", atomic_inc_return_unchecked(&autofs_dummy_name_id));
55060 +#else
55061 qstr.len = sprintf(name, "%p", dentry);
55062 +#endif
55063 else {
55064 qstr.len = autofs4_getpath(sbi, dentry, &name);
55065 if (!qstr.len) {
55066 diff --git a/fs/befs/endian.h b/fs/befs/endian.h
55067 index 2722387..56059b5 100644
55068 --- a/fs/befs/endian.h
55069 +++ b/fs/befs/endian.h
55070 @@ -11,7 +11,7 @@
55071
55072 #include <asm/byteorder.h>
55073
55074 -static inline u64
55075 +static inline u64 __intentional_overflow(-1)
55076 fs64_to_cpu(const struct super_block *sb, fs64 n)
55077 {
55078 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55079 @@ -29,7 +29,7 @@ cpu_to_fs64(const struct super_block *sb, u64 n)
55080 return (__force fs64)cpu_to_be64(n);
55081 }
55082
55083 -static inline u32
55084 +static inline u32 __intentional_overflow(-1)
55085 fs32_to_cpu(const struct super_block *sb, fs32 n)
55086 {
55087 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55088 @@ -47,7 +47,7 @@ cpu_to_fs32(const struct super_block *sb, u32 n)
55089 return (__force fs32)cpu_to_be32(n);
55090 }
55091
55092 -static inline u16
55093 +static inline u16 __intentional_overflow(-1)
55094 fs16_to_cpu(const struct super_block *sb, fs16 n)
55095 {
55096 if (BEFS_SB(sb)->byte_order == BEFS_BYTESEX_LE)
55097 diff --git a/fs/binfmt_aout.c b/fs/binfmt_aout.c
55098 index ca0ba15..0fa3257 100644
55099 --- a/fs/binfmt_aout.c
55100 +++ b/fs/binfmt_aout.c
55101 @@ -16,6 +16,7 @@
55102 #include <linux/string.h>
55103 #include <linux/fs.h>
55104 #include <linux/file.h>
55105 +#include <linux/security.h>
55106 #include <linux/stat.h>
55107 #include <linux/fcntl.h>
55108 #include <linux/ptrace.h>
55109 @@ -58,6 +59,8 @@ static int aout_core_dump(struct coredump_params *cprm)
55110 #endif
55111 # define START_STACK(u) ((void __user *)u.start_stack)
55112
55113 + memset(&dump, 0, sizeof(dump));
55114 +
55115 fs = get_fs();
55116 set_fs(KERNEL_DS);
55117 has_dumped = 1;
55118 @@ -68,10 +71,12 @@ static int aout_core_dump(struct coredump_params *cprm)
55119
55120 /* If the size of the dump file exceeds the rlimit, then see what would happen
55121 if we wrote the stack, but not the data area. */
55122 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE, 1);
55123 if ((dump.u_dsize + dump.u_ssize+1) * PAGE_SIZE > cprm->limit)
55124 dump.u_dsize = 0;
55125
55126 /* Make sure we have enough room to write the stack and data areas. */
55127 + gr_learn_resource(current, RLIMIT_CORE, (dump.u_ssize + 1) * PAGE_SIZE, 1);
55128 if ((dump.u_ssize + 1) * PAGE_SIZE > cprm->limit)
55129 dump.u_ssize = 0;
55130
55131 @@ -232,6 +237,8 @@ static int load_aout_binary(struct linux_binprm * bprm)
55132 rlim = rlimit(RLIMIT_DATA);
55133 if (rlim >= RLIM_INFINITY)
55134 rlim = ~0;
55135 +
55136 + gr_learn_resource(current, RLIMIT_DATA, ex.a_data + ex.a_bss, 1);
55137 if (ex.a_data + ex.a_bss > rlim)
55138 return -ENOMEM;
55139
55140 @@ -264,6 +271,27 @@ static int load_aout_binary(struct linux_binprm * bprm)
55141
55142 install_exec_creds(bprm);
55143
55144 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55145 + current->mm->pax_flags = 0UL;
55146 +#endif
55147 +
55148 +#ifdef CONFIG_PAX_PAGEEXEC
55149 + if (!(N_FLAGS(ex) & F_PAX_PAGEEXEC)) {
55150 + current->mm->pax_flags |= MF_PAX_PAGEEXEC;
55151 +
55152 +#ifdef CONFIG_PAX_EMUTRAMP
55153 + if (N_FLAGS(ex) & F_PAX_EMUTRAMP)
55154 + current->mm->pax_flags |= MF_PAX_EMUTRAMP;
55155 +#endif
55156 +
55157 +#ifdef CONFIG_PAX_MPROTECT
55158 + if (!(N_FLAGS(ex) & F_PAX_MPROTECT))
55159 + current->mm->pax_flags |= MF_PAX_MPROTECT;
55160 +#endif
55161 +
55162 + }
55163 +#endif
55164 +
55165 if (N_MAGIC(ex) == OMAGIC) {
55166 unsigned long text_addr, map_size;
55167 loff_t pos;
55168 @@ -321,7 +349,7 @@ static int load_aout_binary(struct linux_binprm * bprm)
55169 }
55170
55171 error = vm_mmap(bprm->file, N_DATADDR(ex), ex.a_data,
55172 - PROT_READ | PROT_WRITE | PROT_EXEC,
55173 + PROT_READ | PROT_WRITE,
55174 MAP_FIXED | MAP_PRIVATE | MAP_DENYWRITE | MAP_EXECUTABLE,
55175 fd_offset + ex.a_text);
55176 if (error != N_DATADDR(ex)) {
55177 diff --git a/fs/binfmt_elf.c b/fs/binfmt_elf.c
55178 index 571a423..dbb9c6c 100644
55179 --- a/fs/binfmt_elf.c
55180 +++ b/fs/binfmt_elf.c
55181 @@ -34,6 +34,7 @@
55182 #include <linux/utsname.h>
55183 #include <linux/coredump.h>
55184 #include <linux/sched.h>
55185 +#include <linux/xattr.h>
55186 #include <asm/uaccess.h>
55187 #include <asm/param.h>
55188 #include <asm/page.h>
55189 @@ -60,6 +61,14 @@ static int elf_core_dump(struct coredump_params *cprm);
55190 #define elf_core_dump NULL
55191 #endif
55192
55193 +#ifdef CONFIG_PAX_MPROTECT
55194 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags);
55195 +#endif
55196 +
55197 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55198 +static void elf_handle_mmap(struct file *file);
55199 +#endif
55200 +
55201 #if ELF_EXEC_PAGESIZE > PAGE_SIZE
55202 #define ELF_MIN_ALIGN ELF_EXEC_PAGESIZE
55203 #else
55204 @@ -79,6 +88,15 @@ static struct linux_binfmt elf_format = {
55205 .load_binary = load_elf_binary,
55206 .load_shlib = load_elf_library,
55207 .core_dump = elf_core_dump,
55208 +
55209 +#ifdef CONFIG_PAX_MPROTECT
55210 + .handle_mprotect= elf_handle_mprotect,
55211 +#endif
55212 +
55213 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
55214 + .handle_mmap = elf_handle_mmap,
55215 +#endif
55216 +
55217 .min_coredump = ELF_EXEC_PAGESIZE,
55218 };
55219
55220 @@ -86,6 +104,8 @@ static struct linux_binfmt elf_format = {
55221
55222 static int set_brk(unsigned long start, unsigned long end)
55223 {
55224 + unsigned long e = end;
55225 +
55226 start = ELF_PAGEALIGN(start);
55227 end = ELF_PAGEALIGN(end);
55228 if (end > start) {
55229 @@ -94,7 +114,7 @@ static int set_brk(unsigned long start, unsigned long end)
55230 if (BAD_ADDR(addr))
55231 return addr;
55232 }
55233 - current->mm->start_brk = current->mm->brk = end;
55234 + current->mm->start_brk = current->mm->brk = e;
55235 return 0;
55236 }
55237
55238 @@ -155,12 +175,13 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55239 elf_addr_t __user *u_rand_bytes;
55240 const char *k_platform = ELF_PLATFORM;
55241 const char *k_base_platform = ELF_BASE_PLATFORM;
55242 - unsigned char k_rand_bytes[16];
55243 + u32 k_rand_bytes[4];
55244 int items;
55245 elf_addr_t *elf_info;
55246 int ei_index = 0;
55247 const struct cred *cred = current_cred();
55248 struct vm_area_struct *vma;
55249 + unsigned long saved_auxv[AT_VECTOR_SIZE];
55250
55251 /*
55252 * In some cases (e.g. Hyper-Threading), we want to avoid L1
55253 @@ -202,8 +223,12 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55254 * Generate 16 random bytes for userspace PRNG seeding.
55255 */
55256 get_random_bytes(k_rand_bytes, sizeof(k_rand_bytes));
55257 - u_rand_bytes = (elf_addr_t __user *)
55258 - STACK_ALLOC(p, sizeof(k_rand_bytes));
55259 + prandom_seed(k_rand_bytes[0] ^ prandom_u32());
55260 + prandom_seed(k_rand_bytes[1] ^ prandom_u32());
55261 + prandom_seed(k_rand_bytes[2] ^ prandom_u32());
55262 + prandom_seed(k_rand_bytes[3] ^ prandom_u32());
55263 + p = STACK_ROUND(p, sizeof(k_rand_bytes));
55264 + u_rand_bytes = (elf_addr_t __user *) p;
55265 if (__copy_to_user(u_rand_bytes, k_rand_bytes, sizeof(k_rand_bytes)))
55266 return -EFAULT;
55267
55268 @@ -318,9 +343,11 @@ create_elf_tables(struct linux_binprm *bprm, struct elfhdr *exec,
55269 return -EFAULT;
55270 current->mm->env_end = p;
55271
55272 + memcpy(saved_auxv, elf_info, ei_index * sizeof(elf_addr_t));
55273 +
55274 /* Put the elf_info on the stack in the right place. */
55275 sp = (elf_addr_t __user *)envp + 1;
55276 - if (copy_to_user(sp, elf_info, ei_index * sizeof(elf_addr_t)))
55277 + if (copy_to_user(sp, saved_auxv, ei_index * sizeof(elf_addr_t)))
55278 return -EFAULT;
55279 return 0;
55280 }
55281 @@ -388,15 +415,14 @@ static unsigned long total_mapping_size(struct elf_phdr *cmds, int nr)
55282 an ELF header */
55283
55284 static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55285 - struct file *interpreter, unsigned long *interp_map_addr,
55286 - unsigned long no_base)
55287 + struct file *interpreter, unsigned long no_base)
55288 {
55289 struct elf_phdr *elf_phdata;
55290 struct elf_phdr *eppnt;
55291 - unsigned long load_addr = 0;
55292 + unsigned long load_addr = 0, pax_task_size = TASK_SIZE;
55293 int load_addr_set = 0;
55294 unsigned long last_bss = 0, elf_bss = 0;
55295 - unsigned long error = ~0UL;
55296 + unsigned long error = -EINVAL;
55297 unsigned long total_size;
55298 int retval, i, size;
55299
55300 @@ -442,6 +468,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55301 goto out_close;
55302 }
55303
55304 +#ifdef CONFIG_PAX_SEGMEXEC
55305 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC)
55306 + pax_task_size = SEGMEXEC_TASK_SIZE;
55307 +#endif
55308 +
55309 eppnt = elf_phdata;
55310 for (i = 0; i < interp_elf_ex->e_phnum; i++, eppnt++) {
55311 if (eppnt->p_type == PT_LOAD) {
55312 @@ -465,8 +496,6 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55313 map_addr = elf_map(interpreter, load_addr + vaddr,
55314 eppnt, elf_prot, elf_type, total_size);
55315 total_size = 0;
55316 - if (!*interp_map_addr)
55317 - *interp_map_addr = map_addr;
55318 error = map_addr;
55319 if (BAD_ADDR(map_addr))
55320 goto out_close;
55321 @@ -485,8 +514,8 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55322 k = load_addr + eppnt->p_vaddr;
55323 if (BAD_ADDR(k) ||
55324 eppnt->p_filesz > eppnt->p_memsz ||
55325 - eppnt->p_memsz > TASK_SIZE ||
55326 - TASK_SIZE - eppnt->p_memsz < k) {
55327 + eppnt->p_memsz > pax_task_size ||
55328 + pax_task_size - eppnt->p_memsz < k) {
55329 error = -ENOMEM;
55330 goto out_close;
55331 }
55332 @@ -525,9 +554,11 @@ static unsigned long load_elf_interp(struct elfhdr *interp_elf_ex,
55333 elf_bss = ELF_PAGESTART(elf_bss + ELF_MIN_ALIGN - 1);
55334
55335 /* Map the last of the bss segment */
55336 - error = vm_brk(elf_bss, last_bss - elf_bss);
55337 - if (BAD_ADDR(error))
55338 - goto out_close;
55339 + if (last_bss > elf_bss) {
55340 + error = vm_brk(elf_bss, last_bss - elf_bss);
55341 + if (BAD_ADDR(error))
55342 + goto out_close;
55343 + }
55344 }
55345
55346 error = load_addr;
55347 @@ -538,6 +569,336 @@ out:
55348 return error;
55349 }
55350
55351 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
55352 +#ifdef CONFIG_PAX_SOFTMODE
55353 +static unsigned long pax_parse_pt_pax_softmode(const struct elf_phdr * const elf_phdata)
55354 +{
55355 + unsigned long pax_flags = 0UL;
55356 +
55357 +#ifdef CONFIG_PAX_PAGEEXEC
55358 + if (elf_phdata->p_flags & PF_PAGEEXEC)
55359 + pax_flags |= MF_PAX_PAGEEXEC;
55360 +#endif
55361 +
55362 +#ifdef CONFIG_PAX_SEGMEXEC
55363 + if (elf_phdata->p_flags & PF_SEGMEXEC)
55364 + pax_flags |= MF_PAX_SEGMEXEC;
55365 +#endif
55366 +
55367 +#ifdef CONFIG_PAX_EMUTRAMP
55368 + if ((elf_phdata->p_flags & PF_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
55369 + pax_flags |= MF_PAX_EMUTRAMP;
55370 +#endif
55371 +
55372 +#ifdef CONFIG_PAX_MPROTECT
55373 + if (elf_phdata->p_flags & PF_MPROTECT)
55374 + pax_flags |= MF_PAX_MPROTECT;
55375 +#endif
55376 +
55377 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
55378 + if (randomize_va_space && (elf_phdata->p_flags & PF_RANDMMAP))
55379 + pax_flags |= MF_PAX_RANDMMAP;
55380 +#endif
55381 +
55382 + return pax_flags;
55383 +}
55384 +#endif
55385 +
55386 +static unsigned long pax_parse_pt_pax_hardmode(const struct elf_phdr * const elf_phdata)
55387 +{
55388 + unsigned long pax_flags = 0UL;
55389 +
55390 +#ifdef CONFIG_PAX_PAGEEXEC
55391 + if (!(elf_phdata->p_flags & PF_NOPAGEEXEC))
55392 + pax_flags |= MF_PAX_PAGEEXEC;
55393 +#endif
55394 +
55395 +#ifdef CONFIG_PAX_SEGMEXEC
55396 + if (!(elf_phdata->p_flags & PF_NOSEGMEXEC))
55397 + pax_flags |= MF_PAX_SEGMEXEC;
55398 +#endif
55399 +
55400 +#ifdef CONFIG_PAX_EMUTRAMP
55401 + if (!(elf_phdata->p_flags & PF_NOEMUTRAMP))
55402 + pax_flags |= MF_PAX_EMUTRAMP;
55403 +#endif
55404 +
55405 +#ifdef CONFIG_PAX_MPROTECT
55406 + if (!(elf_phdata->p_flags & PF_NOMPROTECT))
55407 + pax_flags |= MF_PAX_MPROTECT;
55408 +#endif
55409 +
55410 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
55411 + if (randomize_va_space && !(elf_phdata->p_flags & PF_NORANDMMAP))
55412 + pax_flags |= MF_PAX_RANDMMAP;
55413 +#endif
55414 +
55415 + return pax_flags;
55416 +}
55417 +#endif
55418 +
55419 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
55420 +#ifdef CONFIG_PAX_SOFTMODE
55421 +static unsigned long pax_parse_xattr_pax_softmode(unsigned long pax_flags_softmode)
55422 +{
55423 + unsigned long pax_flags = 0UL;
55424 +
55425 +#ifdef CONFIG_PAX_PAGEEXEC
55426 + if (pax_flags_softmode & MF_PAX_PAGEEXEC)
55427 + pax_flags |= MF_PAX_PAGEEXEC;
55428 +#endif
55429 +
55430 +#ifdef CONFIG_PAX_SEGMEXEC
55431 + if (pax_flags_softmode & MF_PAX_SEGMEXEC)
55432 + pax_flags |= MF_PAX_SEGMEXEC;
55433 +#endif
55434 +
55435 +#ifdef CONFIG_PAX_EMUTRAMP
55436 + if ((pax_flags_softmode & MF_PAX_EMUTRAMP) && (pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)))
55437 + pax_flags |= MF_PAX_EMUTRAMP;
55438 +#endif
55439 +
55440 +#ifdef CONFIG_PAX_MPROTECT
55441 + if (pax_flags_softmode & MF_PAX_MPROTECT)
55442 + pax_flags |= MF_PAX_MPROTECT;
55443 +#endif
55444 +
55445 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
55446 + if (randomize_va_space && (pax_flags_softmode & MF_PAX_RANDMMAP))
55447 + pax_flags |= MF_PAX_RANDMMAP;
55448 +#endif
55449 +
55450 + return pax_flags;
55451 +}
55452 +#endif
55453 +
55454 +static unsigned long pax_parse_xattr_pax_hardmode(unsigned long pax_flags_hardmode)
55455 +{
55456 + unsigned long pax_flags = 0UL;
55457 +
55458 +#ifdef CONFIG_PAX_PAGEEXEC
55459 + if (!(pax_flags_hardmode & MF_PAX_PAGEEXEC))
55460 + pax_flags |= MF_PAX_PAGEEXEC;
55461 +#endif
55462 +
55463 +#ifdef CONFIG_PAX_SEGMEXEC
55464 + if (!(pax_flags_hardmode & MF_PAX_SEGMEXEC))
55465 + pax_flags |= MF_PAX_SEGMEXEC;
55466 +#endif
55467 +
55468 +#ifdef CONFIG_PAX_EMUTRAMP
55469 + if (!(pax_flags_hardmode & MF_PAX_EMUTRAMP))
55470 + pax_flags |= MF_PAX_EMUTRAMP;
55471 +#endif
55472 +
55473 +#ifdef CONFIG_PAX_MPROTECT
55474 + if (!(pax_flags_hardmode & MF_PAX_MPROTECT))
55475 + pax_flags |= MF_PAX_MPROTECT;
55476 +#endif
55477 +
55478 +#if defined(CONFIG_PAX_RANDMMAP) || defined(CONFIG_PAX_RANDUSTACK)
55479 + if (randomize_va_space && !(pax_flags_hardmode & MF_PAX_RANDMMAP))
55480 + pax_flags |= MF_PAX_RANDMMAP;
55481 +#endif
55482 +
55483 + return pax_flags;
55484 +}
55485 +#endif
55486 +
55487 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55488 +static unsigned long pax_parse_defaults(void)
55489 +{
55490 + unsigned long pax_flags = 0UL;
55491 +
55492 +#ifdef CONFIG_PAX_SOFTMODE
55493 + if (pax_softmode)
55494 + return pax_flags;
55495 +#endif
55496 +
55497 +#ifdef CONFIG_PAX_PAGEEXEC
55498 + pax_flags |= MF_PAX_PAGEEXEC;
55499 +#endif
55500 +
55501 +#ifdef CONFIG_PAX_SEGMEXEC
55502 + pax_flags |= MF_PAX_SEGMEXEC;
55503 +#endif
55504 +
55505 +#ifdef CONFIG_PAX_MPROTECT
55506 + pax_flags |= MF_PAX_MPROTECT;
55507 +#endif
55508 +
55509 +#ifdef CONFIG_PAX_RANDMMAP
55510 + if (randomize_va_space)
55511 + pax_flags |= MF_PAX_RANDMMAP;
55512 +#endif
55513 +
55514 + return pax_flags;
55515 +}
55516 +
55517 +static unsigned long pax_parse_ei_pax(const struct elfhdr * const elf_ex)
55518 +{
55519 + unsigned long pax_flags = PAX_PARSE_FLAGS_FALLBACK;
55520 +
55521 +#ifdef CONFIG_PAX_EI_PAX
55522 +
55523 +#ifdef CONFIG_PAX_SOFTMODE
55524 + if (pax_softmode)
55525 + return pax_flags;
55526 +#endif
55527 +
55528 + pax_flags = 0UL;
55529 +
55530 +#ifdef CONFIG_PAX_PAGEEXEC
55531 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_PAGEEXEC))
55532 + pax_flags |= MF_PAX_PAGEEXEC;
55533 +#endif
55534 +
55535 +#ifdef CONFIG_PAX_SEGMEXEC
55536 + if (!(elf_ex->e_ident[EI_PAX] & EF_PAX_SEGMEXEC))
55537 + pax_flags |= MF_PAX_SEGMEXEC;
55538 +#endif
55539 +
55540 +#ifdef CONFIG_PAX_EMUTRAMP
55541 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && (elf_ex->e_ident[EI_PAX] & EF_PAX_EMUTRAMP))
55542 + pax_flags |= MF_PAX_EMUTRAMP;
55543 +#endif
55544 +
55545 +#ifdef CONFIG_PAX_MPROTECT
55546 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) && !(elf_ex->e_ident[EI_PAX] & EF_PAX_MPROTECT))
55547 + pax_flags |= MF_PAX_MPROTECT;
55548 +#endif
55549 +
55550 +#ifdef CONFIG_PAX_ASLR
55551 + if (randomize_va_space && !(elf_ex->e_ident[EI_PAX] & EF_PAX_RANDMMAP))
55552 + pax_flags |= MF_PAX_RANDMMAP;
55553 +#endif
55554 +
55555 +#endif
55556 +
55557 + return pax_flags;
55558 +
55559 +}
55560 +
55561 +static unsigned long pax_parse_pt_pax(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata)
55562 +{
55563 +
55564 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
55565 + unsigned long i;
55566 +
55567 + for (i = 0UL; i < elf_ex->e_phnum; i++)
55568 + if (elf_phdata[i].p_type == PT_PAX_FLAGS) {
55569 + if (((elf_phdata[i].p_flags & PF_PAGEEXEC) && (elf_phdata[i].p_flags & PF_NOPAGEEXEC)) ||
55570 + ((elf_phdata[i].p_flags & PF_SEGMEXEC) && (elf_phdata[i].p_flags & PF_NOSEGMEXEC)) ||
55571 + ((elf_phdata[i].p_flags & PF_EMUTRAMP) && (elf_phdata[i].p_flags & PF_NOEMUTRAMP)) ||
55572 + ((elf_phdata[i].p_flags & PF_MPROTECT) && (elf_phdata[i].p_flags & PF_NOMPROTECT)) ||
55573 + ((elf_phdata[i].p_flags & PF_RANDMMAP) && (elf_phdata[i].p_flags & PF_NORANDMMAP)))
55574 + return PAX_PARSE_FLAGS_FALLBACK;
55575 +
55576 +#ifdef CONFIG_PAX_SOFTMODE
55577 + if (pax_softmode)
55578 + return pax_parse_pt_pax_softmode(&elf_phdata[i]);
55579 + else
55580 +#endif
55581 +
55582 + return pax_parse_pt_pax_hardmode(&elf_phdata[i]);
55583 + break;
55584 + }
55585 +#endif
55586 +
55587 + return PAX_PARSE_FLAGS_FALLBACK;
55588 +}
55589 +
55590 +static unsigned long pax_parse_xattr_pax(struct file * const file)
55591 +{
55592 +
55593 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
55594 + ssize_t xattr_size, i;
55595 + unsigned char xattr_value[sizeof("pemrs") - 1];
55596 + unsigned long pax_flags_hardmode = 0UL, pax_flags_softmode = 0UL;
55597 +
55598 + xattr_size = pax_getxattr(file->f_path.dentry, xattr_value, sizeof xattr_value);
55599 + if (xattr_size < 0 || xattr_size > sizeof xattr_value)
55600 + return PAX_PARSE_FLAGS_FALLBACK;
55601 +
55602 + for (i = 0; i < xattr_size; i++)
55603 + switch (xattr_value[i]) {
55604 + default:
55605 + return PAX_PARSE_FLAGS_FALLBACK;
55606 +
55607 +#define parse_flag(option1, option2, flag) \
55608 + case option1: \
55609 + if (pax_flags_hardmode & MF_PAX_##flag) \
55610 + return PAX_PARSE_FLAGS_FALLBACK;\
55611 + pax_flags_hardmode |= MF_PAX_##flag; \
55612 + break; \
55613 + case option2: \
55614 + if (pax_flags_softmode & MF_PAX_##flag) \
55615 + return PAX_PARSE_FLAGS_FALLBACK;\
55616 + pax_flags_softmode |= MF_PAX_##flag; \
55617 + break;
55618 +
55619 + parse_flag('p', 'P', PAGEEXEC);
55620 + parse_flag('e', 'E', EMUTRAMP);
55621 + parse_flag('m', 'M', MPROTECT);
55622 + parse_flag('r', 'R', RANDMMAP);
55623 + parse_flag('s', 'S', SEGMEXEC);
55624 +
55625 +#undef parse_flag
55626 + }
55627 +
55628 + if (pax_flags_hardmode & pax_flags_softmode)
55629 + return PAX_PARSE_FLAGS_FALLBACK;
55630 +
55631 +#ifdef CONFIG_PAX_SOFTMODE
55632 + if (pax_softmode)
55633 + return pax_parse_xattr_pax_softmode(pax_flags_softmode);
55634 + else
55635 +#endif
55636 +
55637 + return pax_parse_xattr_pax_hardmode(pax_flags_hardmode);
55638 +#else
55639 + return PAX_PARSE_FLAGS_FALLBACK;
55640 +#endif
55641 +
55642 +}
55643 +
55644 +static long pax_parse_pax_flags(const struct elfhdr * const elf_ex, const struct elf_phdr * const elf_phdata, struct file * const file)
55645 +{
55646 + unsigned long pax_flags, ei_pax_flags, pt_pax_flags, xattr_pax_flags;
55647 +
55648 + pax_flags = pax_parse_defaults();
55649 + ei_pax_flags = pax_parse_ei_pax(elf_ex);
55650 + pt_pax_flags = pax_parse_pt_pax(elf_ex, elf_phdata);
55651 + xattr_pax_flags = pax_parse_xattr_pax(file);
55652 +
55653 + if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
55654 + xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK &&
55655 + pt_pax_flags != xattr_pax_flags)
55656 + return -EINVAL;
55657 + if (xattr_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
55658 + pax_flags = xattr_pax_flags;
55659 + else if (pt_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
55660 + pax_flags = pt_pax_flags;
55661 + else if (ei_pax_flags != PAX_PARSE_FLAGS_FALLBACK)
55662 + pax_flags = ei_pax_flags;
55663 +
55664 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_PAX_SEGMEXEC)
55665 + if ((pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) == (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
55666 + if ((__supported_pte_mask & _PAGE_NX))
55667 + pax_flags &= ~MF_PAX_SEGMEXEC;
55668 + else
55669 + pax_flags &= ~MF_PAX_PAGEEXEC;
55670 + }
55671 +#endif
55672 +
55673 + if (0 > pax_check_flags(&pax_flags))
55674 + return -EINVAL;
55675 +
55676 + current->mm->pax_flags = pax_flags;
55677 + return 0;
55678 +}
55679 +#endif
55680 +
55681 /*
55682 * These are the functions used to load ELF style executables and shared
55683 * libraries. There is no binary dependent code anywhere else.
55684 @@ -554,6 +915,11 @@ static unsigned long randomize_stack_top(unsigned long stack_top)
55685 {
55686 unsigned int random_variable = 0;
55687
55688 +#ifdef CONFIG_PAX_RANDUSTACK
55689 + if (current->mm->pax_flags & MF_PAX_RANDMMAP)
55690 + return stack_top - current->mm->delta_stack;
55691 +#endif
55692 +
55693 if ((current->flags & PF_RANDOMIZE) &&
55694 !(current->personality & ADDR_NO_RANDOMIZE)) {
55695 random_variable = get_random_int() & STACK_RND_MASK;
55696 @@ -572,7 +938,7 @@ static int load_elf_binary(struct linux_binprm *bprm)
55697 unsigned long load_addr = 0, load_bias = 0;
55698 int load_addr_set = 0;
55699 char * elf_interpreter = NULL;
55700 - unsigned long error;
55701 + unsigned long error = 0;
55702 struct elf_phdr *elf_ppnt, *elf_phdata;
55703 unsigned long elf_bss, elf_brk;
55704 int retval, i;
55705 @@ -582,12 +948,12 @@ static int load_elf_binary(struct linux_binprm *bprm)
55706 unsigned long start_code, end_code, start_data, end_data;
55707 unsigned long reloc_func_desc __maybe_unused = 0;
55708 int executable_stack = EXSTACK_DEFAULT;
55709 - unsigned long def_flags = 0;
55710 struct pt_regs *regs = current_pt_regs();
55711 struct {
55712 struct elfhdr elf_ex;
55713 struct elfhdr interp_elf_ex;
55714 } *loc;
55715 + unsigned long pax_task_size;
55716
55717 loc = kmalloc(sizeof(*loc), GFP_KERNEL);
55718 if (!loc) {
55719 @@ -723,11 +1089,82 @@ static int load_elf_binary(struct linux_binprm *bprm)
55720 goto out_free_dentry;
55721
55722 /* OK, This is the point of no return */
55723 - current->mm->def_flags = def_flags;
55724 + current->mm->def_flags = 0;
55725
55726 /* Do this immediately, since STACK_TOP as used in setup_arg_pages
55727 may depend on the personality. */
55728 SET_PERSONALITY(loc->elf_ex);
55729 +
55730 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55731 + current->mm->pax_flags = 0UL;
55732 +#endif
55733 +
55734 +#ifdef CONFIG_PAX_DLRESOLVE
55735 + current->mm->call_dl_resolve = 0UL;
55736 +#endif
55737 +
55738 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
55739 + current->mm->call_syscall = 0UL;
55740 +#endif
55741 +
55742 +#ifdef CONFIG_PAX_ASLR
55743 + current->mm->delta_mmap = 0UL;
55744 + current->mm->delta_stack = 0UL;
55745 +#endif
55746 +
55747 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
55748 + if (0 > pax_parse_pax_flags(&loc->elf_ex, elf_phdata, bprm->file)) {
55749 + send_sig(SIGKILL, current, 0);
55750 + goto out_free_dentry;
55751 + }
55752 +#endif
55753 +
55754 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
55755 + pax_set_initial_flags(bprm);
55756 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
55757 + if (pax_set_initial_flags_func)
55758 + (pax_set_initial_flags_func)(bprm);
55759 +#endif
55760 +
55761 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
55762 + if ((current->mm->pax_flags & MF_PAX_PAGEEXEC) && !(__supported_pte_mask & _PAGE_NX)) {
55763 + current->mm->context.user_cs_limit = PAGE_SIZE;
55764 + current->mm->def_flags |= VM_PAGEEXEC | VM_NOHUGEPAGE;
55765 + }
55766 +#endif
55767 +
55768 +#ifdef CONFIG_PAX_SEGMEXEC
55769 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
55770 + current->mm->context.user_cs_base = SEGMEXEC_TASK_SIZE;
55771 + current->mm->context.user_cs_limit = TASK_SIZE-SEGMEXEC_TASK_SIZE;
55772 + pax_task_size = SEGMEXEC_TASK_SIZE;
55773 + current->mm->def_flags |= VM_NOHUGEPAGE;
55774 + } else
55775 +#endif
55776 +
55777 + pax_task_size = TASK_SIZE;
55778 +
55779 +#if defined(CONFIG_ARCH_TRACK_EXEC_LIMIT) || defined(CONFIG_PAX_SEGMEXEC)
55780 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
55781 + set_user_cs(current->mm->context.user_cs_base, current->mm->context.user_cs_limit, get_cpu());
55782 + put_cpu();
55783 + }
55784 +#endif
55785 +
55786 +#ifdef CONFIG_PAX_ASLR
55787 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
55788 + current->mm->delta_mmap = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN)-1)) << PAGE_SHIFT;
55789 + current->mm->delta_stack = (pax_get_random_long() & ((1UL << PAX_DELTA_STACK_LEN)-1)) << PAGE_SHIFT;
55790 + }
55791 +#endif
55792 +
55793 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
55794 + if (current->mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
55795 + executable_stack = EXSTACK_DISABLE_X;
55796 + current->personality &= ~READ_IMPLIES_EXEC;
55797 + } else
55798 +#endif
55799 +
55800 if (elf_read_implies_exec(loc->elf_ex, executable_stack))
55801 current->personality |= READ_IMPLIES_EXEC;
55802
55803 @@ -817,6 +1254,20 @@ static int load_elf_binary(struct linux_binprm *bprm)
55804 #else
55805 load_bias = ELF_PAGESTART(ELF_ET_DYN_BASE - vaddr);
55806 #endif
55807 +
55808 +#ifdef CONFIG_PAX_RANDMMAP
55809 + /* PaX: randomize base address at the default exe base if requested */
55810 + if ((current->mm->pax_flags & MF_PAX_RANDMMAP) && elf_interpreter) {
55811 +#ifdef CONFIG_SPARC64
55812 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << (PAGE_SHIFT+1);
55813 +#else
55814 + load_bias = (pax_get_random_long() & ((1UL << PAX_DELTA_MMAP_LEN) - 1)) << PAGE_SHIFT;
55815 +#endif
55816 + load_bias = ELF_PAGESTART(PAX_ELF_ET_DYN_BASE - vaddr + load_bias);
55817 + elf_flags |= MAP_FIXED;
55818 + }
55819 +#endif
55820 +
55821 }
55822
55823 error = elf_map(bprm->file, load_bias + vaddr, elf_ppnt,
55824 @@ -849,9 +1300,9 @@ static int load_elf_binary(struct linux_binprm *bprm)
55825 * allowed task size. Note that p_filesz must always be
55826 * <= p_memsz so it is only necessary to check p_memsz.
55827 */
55828 - if (BAD_ADDR(k) || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
55829 - elf_ppnt->p_memsz > TASK_SIZE ||
55830 - TASK_SIZE - elf_ppnt->p_memsz < k) {
55831 + if (k >= pax_task_size || elf_ppnt->p_filesz > elf_ppnt->p_memsz ||
55832 + elf_ppnt->p_memsz > pax_task_size ||
55833 + pax_task_size - elf_ppnt->p_memsz < k) {
55834 /* set_brk can never work. Avoid overflows. */
55835 send_sig(SIGKILL, current, 0);
55836 retval = -EINVAL;
55837 @@ -890,17 +1341,45 @@ static int load_elf_binary(struct linux_binprm *bprm)
55838 goto out_free_dentry;
55839 }
55840 if (likely(elf_bss != elf_brk) && unlikely(padzero(elf_bss))) {
55841 - send_sig(SIGSEGV, current, 0);
55842 - retval = -EFAULT; /* Nobody gets to see this, but.. */
55843 - goto out_free_dentry;
55844 + /*
55845 + * This bss-zeroing can fail if the ELF
55846 + * file specifies odd protections. So
55847 + * we don't check the return value
55848 + */
55849 }
55850
55851 +#ifdef CONFIG_PAX_RANDMMAP
55852 + if (current->mm->pax_flags & MF_PAX_RANDMMAP) {
55853 + unsigned long start, size, flags;
55854 + vm_flags_t vm_flags;
55855 +
55856 + start = ELF_PAGEALIGN(elf_brk);
55857 + size = PAGE_SIZE + ((pax_get_random_long() & ((1UL << 22) - 1UL)) << 4);
55858 + flags = MAP_FIXED | MAP_PRIVATE;
55859 + vm_flags = VM_DONTEXPAND | VM_DONTDUMP;
55860 +
55861 + down_write(&current->mm->mmap_sem);
55862 + start = get_unmapped_area(NULL, start, PAGE_ALIGN(size), 0, flags);
55863 + retval = -ENOMEM;
55864 + if (!IS_ERR_VALUE(start) && !find_vma_intersection(current->mm, start, start + size + PAGE_SIZE)) {
55865 +// if (current->personality & ADDR_NO_RANDOMIZE)
55866 +// vm_flags |= VM_READ | VM_MAYREAD;
55867 + start = mmap_region(NULL, start, PAGE_ALIGN(size), vm_flags, 0);
55868 + retval = IS_ERR_VALUE(start) ? start : 0;
55869 + }
55870 + up_write(&current->mm->mmap_sem);
55871 + if (retval == 0)
55872 + retval = set_brk(start + size, start + size + PAGE_SIZE);
55873 + if (retval < 0) {
55874 + send_sig(SIGKILL, current, 0);
55875 + goto out_free_dentry;
55876 + }
55877 + }
55878 +#endif
55879 +
55880 if (elf_interpreter) {
55881 - unsigned long interp_map_addr = 0;
55882 -
55883 elf_entry = load_elf_interp(&loc->interp_elf_ex,
55884 interpreter,
55885 - &interp_map_addr,
55886 load_bias);
55887 if (!IS_ERR((void *)elf_entry)) {
55888 /*
55889 @@ -1122,7 +1601,7 @@ static bool always_dump_vma(struct vm_area_struct *vma)
55890 * Decide what to dump of a segment, part, all or none.
55891 */
55892 static unsigned long vma_dump_size(struct vm_area_struct *vma,
55893 - unsigned long mm_flags)
55894 + unsigned long mm_flags, long signr)
55895 {
55896 #define FILTER(type) (mm_flags & (1UL << MMF_DUMP_##type))
55897
55898 @@ -1160,7 +1639,7 @@ static unsigned long vma_dump_size(struct vm_area_struct *vma,
55899 if (vma->vm_file == NULL)
55900 return 0;
55901
55902 - if (FILTER(MAPPED_PRIVATE))
55903 + if (signr == SIGKILL || FILTER(MAPPED_PRIVATE))
55904 goto whole;
55905
55906 /*
55907 @@ -1367,9 +1846,9 @@ static void fill_auxv_note(struct memelfnote *note, struct mm_struct *mm)
55908 {
55909 elf_addr_t *auxv = (elf_addr_t *) mm->saved_auxv;
55910 int i = 0;
55911 - do
55912 + do {
55913 i += 2;
55914 - while (auxv[i - 2] != AT_NULL);
55915 + } while (auxv[i - 2] != AT_NULL);
55916 fill_note(note, "CORE", NT_AUXV, i * sizeof(elf_addr_t), auxv);
55917 }
55918
55919 @@ -1378,7 +1857,7 @@ static void fill_siginfo_note(struct memelfnote *note, user_siginfo_t *csigdata,
55920 {
55921 mm_segment_t old_fs = get_fs();
55922 set_fs(KERNEL_DS);
55923 - copy_siginfo_to_user((user_siginfo_t __user *) csigdata, siginfo);
55924 + copy_siginfo_to_user((user_siginfo_t __force_user *) csigdata, siginfo);
55925 set_fs(old_fs);
55926 fill_note(note, "CORE", NT_SIGINFO, sizeof(*csigdata), csigdata);
55927 }
55928 @@ -2002,14 +2481,14 @@ static void fill_extnum_info(struct elfhdr *elf, struct elf_shdr *shdr4extnum,
55929 }
55930
55931 static size_t elf_core_vma_data_size(struct vm_area_struct *gate_vma,
55932 - unsigned long mm_flags)
55933 + struct coredump_params *cprm)
55934 {
55935 struct vm_area_struct *vma;
55936 size_t size = 0;
55937
55938 for (vma = first_vma(current, gate_vma); vma != NULL;
55939 vma = next_vma(vma, gate_vma))
55940 - size += vma_dump_size(vma, mm_flags);
55941 + size += vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
55942 return size;
55943 }
55944
55945 @@ -2100,7 +2579,7 @@ static int elf_core_dump(struct coredump_params *cprm)
55946
55947 dataoff = offset = roundup(offset, ELF_EXEC_PAGESIZE);
55948
55949 - offset += elf_core_vma_data_size(gate_vma, cprm->mm_flags);
55950 + offset += elf_core_vma_data_size(gate_vma, cprm);
55951 offset += elf_core_extra_data_size();
55952 e_shoff = offset;
55953
55954 @@ -2128,7 +2607,7 @@ static int elf_core_dump(struct coredump_params *cprm)
55955 phdr.p_offset = offset;
55956 phdr.p_vaddr = vma->vm_start;
55957 phdr.p_paddr = 0;
55958 - phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags);
55959 + phdr.p_filesz = vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
55960 phdr.p_memsz = vma->vm_end - vma->vm_start;
55961 offset += phdr.p_filesz;
55962 phdr.p_flags = vma->vm_flags & VM_READ ? PF_R : 0;
55963 @@ -2161,7 +2640,7 @@ static int elf_core_dump(struct coredump_params *cprm)
55964 unsigned long addr;
55965 unsigned long end;
55966
55967 - end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags);
55968 + end = vma->vm_start + vma_dump_size(vma, cprm->mm_flags, cprm->siginfo->si_signo);
55969
55970 for (addr = vma->vm_start; addr < end; addr += PAGE_SIZE) {
55971 struct page *page;
55972 @@ -2202,6 +2681,167 @@ out:
55973
55974 #endif /* CONFIG_ELF_CORE */
55975
55976 +#ifdef CONFIG_PAX_MPROTECT
55977 +/* PaX: non-PIC ELF libraries need relocations on their executable segments
55978 + * therefore we'll grant them VM_MAYWRITE once during their life. Similarly
55979 + * we'll remove VM_MAYWRITE for good on RELRO segments.
55980 + *
55981 + * The checks favour ld-linux.so behaviour which operates on a per ELF segment
55982 + * basis because we want to allow the common case and not the special ones.
55983 + */
55984 +static void elf_handle_mprotect(struct vm_area_struct *vma, unsigned long newflags)
55985 +{
55986 + struct elfhdr elf_h;
55987 + struct elf_phdr elf_p;
55988 + unsigned long i;
55989 + unsigned long oldflags;
55990 + bool is_textrel_rw, is_textrel_rx, is_relro;
55991 +
55992 + if (!(vma->vm_mm->pax_flags & MF_PAX_MPROTECT) || !vma->vm_file)
55993 + return;
55994 +
55995 + oldflags = vma->vm_flags & (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ);
55996 + newflags &= VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_EXEC | VM_WRITE | VM_READ;
55997 +
55998 +#ifdef CONFIG_PAX_ELFRELOCS
55999 + /* possible TEXTREL */
56000 + is_textrel_rw = !vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYREAD | VM_EXEC | VM_READ) && newflags == (VM_WRITE | VM_READ);
56001 + is_textrel_rx = vma->anon_vma && oldflags == (VM_MAYEXEC | VM_MAYWRITE | VM_MAYREAD | VM_WRITE | VM_READ) && newflags == (VM_EXEC | VM_READ);
56002 +#else
56003 + is_textrel_rw = false;
56004 + is_textrel_rx = false;
56005 +#endif
56006 +
56007 + /* possible RELRO */
56008 + is_relro = vma->anon_vma && oldflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ) && newflags == (VM_MAYWRITE | VM_MAYREAD | VM_READ);
56009 +
56010 + if (!is_textrel_rw && !is_textrel_rx && !is_relro)
56011 + return;
56012 +
56013 + if (sizeof(elf_h) != kernel_read(vma->vm_file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56014 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56015 +
56016 +#ifdef CONFIG_PAX_ETEXECRELOCS
56017 + ((is_textrel_rw || is_textrel_rx) && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56018 +#else
56019 + ((is_textrel_rw || is_textrel_rx) && elf_h.e_type != ET_DYN) ||
56020 +#endif
56021 +
56022 + (is_relro && (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC)) ||
56023 + !elf_check_arch(&elf_h) ||
56024 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56025 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56026 + return;
56027 +
56028 + for (i = 0UL; i < elf_h.e_phnum; i++) {
56029 + if (sizeof(elf_p) != kernel_read(vma->vm_file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56030 + return;
56031 + switch (elf_p.p_type) {
56032 + case PT_DYNAMIC:
56033 + if (!is_textrel_rw && !is_textrel_rx)
56034 + continue;
56035 + i = 0UL;
56036 + while ((i+1) * sizeof(elf_dyn) <= elf_p.p_filesz) {
56037 + elf_dyn dyn;
56038 +
56039 + if (sizeof(dyn) != kernel_read(vma->vm_file, elf_p.p_offset + i*sizeof(dyn), (char *)&dyn, sizeof(dyn)))
56040 + break;
56041 + if (dyn.d_tag == DT_NULL)
56042 + break;
56043 + if (dyn.d_tag == DT_TEXTREL || (dyn.d_tag == DT_FLAGS && (dyn.d_un.d_val & DF_TEXTREL))) {
56044 + gr_log_textrel(vma);
56045 + if (is_textrel_rw)
56046 + vma->vm_flags |= VM_MAYWRITE;
56047 + else
56048 + /* PaX: disallow write access after relocs are done, hopefully noone else needs it... */
56049 + vma->vm_flags &= ~VM_MAYWRITE;
56050 + break;
56051 + }
56052 + i++;
56053 + }
56054 + is_textrel_rw = false;
56055 + is_textrel_rx = false;
56056 + continue;
56057 +
56058 + case PT_GNU_RELRO:
56059 + if (!is_relro)
56060 + continue;
56061 + if ((elf_p.p_offset >> PAGE_SHIFT) == vma->vm_pgoff && ELF_PAGEALIGN(elf_p.p_memsz) == vma->vm_end - vma->vm_start)
56062 + vma->vm_flags &= ~VM_MAYWRITE;
56063 + is_relro = false;
56064 + continue;
56065 +
56066 +#ifdef CONFIG_PAX_PT_PAX_FLAGS
56067 + case PT_PAX_FLAGS: {
56068 + const char *msg_mprotect = "", *msg_emutramp = "";
56069 + char *buffer_lib, *buffer_exe;
56070 +
56071 + if (elf_p.p_flags & PF_NOMPROTECT)
56072 + msg_mprotect = "MPROTECT disabled";
56073 +
56074 +#ifdef CONFIG_PAX_EMUTRAMP
56075 + if (!(vma->vm_mm->pax_flags & MF_PAX_EMUTRAMP) && !(elf_p.p_flags & PF_NOEMUTRAMP))
56076 + msg_emutramp = "EMUTRAMP enabled";
56077 +#endif
56078 +
56079 + if (!msg_mprotect[0] && !msg_emutramp[0])
56080 + continue;
56081 +
56082 + if (!printk_ratelimit())
56083 + continue;
56084 +
56085 + buffer_lib = (char *)__get_free_page(GFP_KERNEL);
56086 + buffer_exe = (char *)__get_free_page(GFP_KERNEL);
56087 + if (buffer_lib && buffer_exe) {
56088 + char *path_lib, *path_exe;
56089 +
56090 + path_lib = pax_get_path(&vma->vm_file->f_path, buffer_lib, PAGE_SIZE);
56091 + path_exe = pax_get_path(&vma->vm_mm->exe_file->f_path, buffer_exe, PAGE_SIZE);
56092 +
56093 + pr_info("PAX: %s wants %s%s%s on %s\n", path_lib, msg_mprotect,
56094 + (msg_mprotect[0] && msg_emutramp[0] ? " and " : ""), msg_emutramp, path_exe);
56095 +
56096 + }
56097 + free_page((unsigned long)buffer_exe);
56098 + free_page((unsigned long)buffer_lib);
56099 + continue;
56100 + }
56101 +#endif
56102 +
56103 + }
56104 + }
56105 +}
56106 +#endif
56107 +
56108 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
56109 +
56110 +extern int grsec_enable_log_rwxmaps;
56111 +
56112 +static void elf_handle_mmap(struct file *file)
56113 +{
56114 + struct elfhdr elf_h;
56115 + struct elf_phdr elf_p;
56116 + unsigned long i;
56117 +
56118 + if (!grsec_enable_log_rwxmaps)
56119 + return;
56120 +
56121 + if (sizeof(elf_h) != kernel_read(file, 0UL, (char *)&elf_h, sizeof(elf_h)) ||
56122 + memcmp(elf_h.e_ident, ELFMAG, SELFMAG) ||
56123 + (elf_h.e_type != ET_DYN && elf_h.e_type != ET_EXEC) || !elf_check_arch(&elf_h) ||
56124 + elf_h.e_phentsize != sizeof(struct elf_phdr) ||
56125 + elf_h.e_phnum > 65536UL / sizeof(struct elf_phdr))
56126 + return;
56127 +
56128 + for (i = 0UL; i < elf_h.e_phnum; i++) {
56129 + if (sizeof(elf_p) != kernel_read(file, elf_h.e_phoff + i*sizeof(elf_p), (char *)&elf_p, sizeof(elf_p)))
56130 + return;
56131 + if (elf_p.p_type == PT_GNU_STACK && (elf_p.p_flags & PF_X))
56132 + gr_log_ptgnustack(file);
56133 + }
56134 +}
56135 +#endif
56136 +
56137 static int __init init_elf_binfmt(void)
56138 {
56139 register_binfmt(&elf_format);
56140 diff --git a/fs/binfmt_flat.c b/fs/binfmt_flat.c
56141 index d50bbe5..af3b649 100644
56142 --- a/fs/binfmt_flat.c
56143 +++ b/fs/binfmt_flat.c
56144 @@ -566,7 +566,9 @@ static int load_flat_file(struct linux_binprm * bprm,
56145 realdatastart = (unsigned long) -ENOMEM;
56146 printk("Unable to allocate RAM for process data, errno %d\n",
56147 (int)-realdatastart);
56148 + down_write(&current->mm->mmap_sem);
56149 vm_munmap(textpos, text_len);
56150 + up_write(&current->mm->mmap_sem);
56151 ret = realdatastart;
56152 goto err;
56153 }
56154 @@ -590,8 +592,10 @@ static int load_flat_file(struct linux_binprm * bprm,
56155 }
56156 if (IS_ERR_VALUE(result)) {
56157 printk("Unable to read data+bss, errno %d\n", (int)-result);
56158 + down_write(&current->mm->mmap_sem);
56159 vm_munmap(textpos, text_len);
56160 vm_munmap(realdatastart, len);
56161 + up_write(&current->mm->mmap_sem);
56162 ret = result;
56163 goto err;
56164 }
56165 @@ -653,8 +657,10 @@ static int load_flat_file(struct linux_binprm * bprm,
56166 }
56167 if (IS_ERR_VALUE(result)) {
56168 printk("Unable to read code+data+bss, errno %d\n",(int)-result);
56169 + down_write(&current->mm->mmap_sem);
56170 vm_munmap(textpos, text_len + data_len + extra +
56171 MAX_SHARED_LIBS * sizeof(unsigned long));
56172 + up_write(&current->mm->mmap_sem);
56173 ret = result;
56174 goto err;
56175 }
56176 diff --git a/fs/bio.c b/fs/bio.c
56177 index 33d79a4..c3c9893 100644
56178 --- a/fs/bio.c
56179 +++ b/fs/bio.c
56180 @@ -1106,7 +1106,7 @@ struct bio *bio_copy_user_iov(struct request_queue *q,
56181 /*
56182 * Overflow, abort
56183 */
56184 - if (end < start)
56185 + if (end < start || end - start > INT_MAX - nr_pages)
56186 return ERR_PTR(-EINVAL);
56187
56188 nr_pages += end - start;
56189 @@ -1240,7 +1240,7 @@ static struct bio *__bio_map_user_iov(struct request_queue *q,
56190 /*
56191 * Overflow, abort
56192 */
56193 - if (end < start)
56194 + if (end < start || end - start > INT_MAX - nr_pages)
56195 return ERR_PTR(-EINVAL);
56196
56197 nr_pages += end - start;
56198 @@ -1502,7 +1502,7 @@ static void bio_copy_kern_endio(struct bio *bio, int err)
56199 const int read = bio_data_dir(bio) == READ;
56200 struct bio_map_data *bmd = bio->bi_private;
56201 int i;
56202 - char *p = bmd->sgvecs[0].iov_base;
56203 + char *p = (char __force_kernel *)bmd->sgvecs[0].iov_base;
56204
56205 bio_for_each_segment_all(bvec, bio, i) {
56206 char *addr = page_address(bvec->bv_page);
56207 diff --git a/fs/block_dev.c b/fs/block_dev.c
56208 index 1e86823..8e34695 100644
56209 --- a/fs/block_dev.c
56210 +++ b/fs/block_dev.c
56211 @@ -637,7 +637,7 @@ static bool bd_may_claim(struct block_device *bdev, struct block_device *whole,
56212 else if (bdev->bd_contains == bdev)
56213 return true; /* is a whole device which isn't held */
56214
56215 - else if (whole->bd_holder == bd_may_claim)
56216 + else if (whole->bd_holder == (void *)bd_may_claim)
56217 return true; /* is a partition of a device that is being partitioned */
56218 else if (whole->bd_holder != NULL)
56219 return false; /* is a partition of a held device */
56220 diff --git a/fs/btrfs/ctree.c b/fs/btrfs/ctree.c
56221 index 316136b..e7a3a50 100644
56222 --- a/fs/btrfs/ctree.c
56223 +++ b/fs/btrfs/ctree.c
56224 @@ -1028,9 +1028,12 @@ static noinline int __btrfs_cow_block(struct btrfs_trans_handle *trans,
56225 free_extent_buffer(buf);
56226 add_root_to_dirty_list(root);
56227 } else {
56228 - if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID)
56229 - parent_start = parent->start;
56230 - else
56231 + if (root->root_key.objectid == BTRFS_TREE_RELOC_OBJECTID) {
56232 + if (parent)
56233 + parent_start = parent->start;
56234 + else
56235 + parent_start = 0;
56236 + } else
56237 parent_start = 0;
56238
56239 WARN_ON(trans->transid != btrfs_header_generation(parent));
56240 diff --git a/fs/btrfs/delayed-inode.c b/fs/btrfs/delayed-inode.c
56241 index 8d292fb..bc205c2 100644
56242 --- a/fs/btrfs/delayed-inode.c
56243 +++ b/fs/btrfs/delayed-inode.c
56244 @@ -459,7 +459,7 @@ static int __btrfs_add_delayed_deletion_item(struct btrfs_delayed_node *node,
56245
56246 static void finish_one_item(struct btrfs_delayed_root *delayed_root)
56247 {
56248 - int seq = atomic_inc_return(&delayed_root->items_seq);
56249 + int seq = atomic_inc_return_unchecked(&delayed_root->items_seq);
56250 if ((atomic_dec_return(&delayed_root->items) <
56251 BTRFS_DELAYED_BACKGROUND || seq % BTRFS_DELAYED_BATCH == 0) &&
56252 waitqueue_active(&delayed_root->wait))
56253 @@ -1379,7 +1379,7 @@ void btrfs_assert_delayed_root_empty(struct btrfs_root *root)
56254 static int refs_newer(struct btrfs_delayed_root *delayed_root,
56255 int seq, int count)
56256 {
56257 - int val = atomic_read(&delayed_root->items_seq);
56258 + int val = atomic_read_unchecked(&delayed_root->items_seq);
56259
56260 if (val < seq || val >= seq + count)
56261 return 1;
56262 @@ -1396,7 +1396,7 @@ void btrfs_balance_delayed_items(struct btrfs_root *root)
56263 if (atomic_read(&delayed_root->items) < BTRFS_DELAYED_BACKGROUND)
56264 return;
56265
56266 - seq = atomic_read(&delayed_root->items_seq);
56267 + seq = atomic_read_unchecked(&delayed_root->items_seq);
56268
56269 if (atomic_read(&delayed_root->items) >= BTRFS_DELAYED_WRITEBACK) {
56270 int ret;
56271 diff --git a/fs/btrfs/delayed-inode.h b/fs/btrfs/delayed-inode.h
56272 index a4b38f9..f86a509 100644
56273 --- a/fs/btrfs/delayed-inode.h
56274 +++ b/fs/btrfs/delayed-inode.h
56275 @@ -43,7 +43,7 @@ struct btrfs_delayed_root {
56276 */
56277 struct list_head prepare_list;
56278 atomic_t items; /* for delayed items */
56279 - atomic_t items_seq; /* for delayed items */
56280 + atomic_unchecked_t items_seq; /* for delayed items */
56281 int nodes; /* for delayed nodes */
56282 wait_queue_head_t wait;
56283 };
56284 @@ -87,7 +87,7 @@ static inline void btrfs_init_delayed_root(
56285 struct btrfs_delayed_root *delayed_root)
56286 {
56287 atomic_set(&delayed_root->items, 0);
56288 - atomic_set(&delayed_root->items_seq, 0);
56289 + atomic_set_unchecked(&delayed_root->items_seq, 0);
56290 delayed_root->nodes = 0;
56291 spin_lock_init(&delayed_root->lock);
56292 init_waitqueue_head(&delayed_root->wait);
56293 diff --git a/fs/btrfs/ioctl.c b/fs/btrfs/ioctl.c
56294 index 9f831bb..14afde5 100644
56295 --- a/fs/btrfs/ioctl.c
56296 +++ b/fs/btrfs/ioctl.c
56297 @@ -3457,9 +3457,12 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
56298 for (i = 0; i < num_types; i++) {
56299 struct btrfs_space_info *tmp;
56300
56301 + /* Don't copy in more than we allocated */
56302 if (!slot_count)
56303 break;
56304
56305 + slot_count--;
56306 +
56307 info = NULL;
56308 rcu_read_lock();
56309 list_for_each_entry_rcu(tmp, &root->fs_info->space_info,
56310 @@ -3481,10 +3484,7 @@ static long btrfs_ioctl_space_info(struct btrfs_root *root, void __user *arg)
56311 memcpy(dest, &space, sizeof(space));
56312 dest++;
56313 space_args.total_spaces++;
56314 - slot_count--;
56315 }
56316 - if (!slot_count)
56317 - break;
56318 }
56319 up_read(&info->groups_sem);
56320 }
56321 diff --git a/fs/btrfs/super.c b/fs/btrfs/super.c
56322 index d71a11d..384e2c4 100644
56323 --- a/fs/btrfs/super.c
56324 +++ b/fs/btrfs/super.c
56325 @@ -265,7 +265,7 @@ void __btrfs_abort_transaction(struct btrfs_trans_handle *trans,
56326 function, line, errstr);
56327 return;
56328 }
56329 - ACCESS_ONCE(trans->transaction->aborted) = errno;
56330 + ACCESS_ONCE_RW(trans->transaction->aborted) = errno;
56331 /* Wake up anybody who may be waiting on this transaction */
56332 wake_up(&root->fs_info->transaction_wait);
56333 wake_up(&root->fs_info->transaction_blocked_wait);
56334 diff --git a/fs/buffer.c b/fs/buffer.c
56335 index 6024877..7bd000a 100644
56336 --- a/fs/buffer.c
56337 +++ b/fs/buffer.c
56338 @@ -3426,7 +3426,7 @@ void __init buffer_init(void)
56339 bh_cachep = kmem_cache_create("buffer_head",
56340 sizeof(struct buffer_head), 0,
56341 (SLAB_RECLAIM_ACCOUNT|SLAB_PANIC|
56342 - SLAB_MEM_SPREAD),
56343 + SLAB_MEM_SPREAD|SLAB_NO_SANITIZE),
56344 NULL);
56345
56346 /*
56347 diff --git a/fs/cachefiles/bind.c b/fs/cachefiles/bind.c
56348 index 622f469..e8d2d55 100644
56349 --- a/fs/cachefiles/bind.c
56350 +++ b/fs/cachefiles/bind.c
56351 @@ -39,13 +39,11 @@ int cachefiles_daemon_bind(struct cachefiles_cache *cache, char *args)
56352 args);
56353
56354 /* start by checking things over */
56355 - ASSERT(cache->fstop_percent >= 0 &&
56356 - cache->fstop_percent < cache->fcull_percent &&
56357 + ASSERT(cache->fstop_percent < cache->fcull_percent &&
56358 cache->fcull_percent < cache->frun_percent &&
56359 cache->frun_percent < 100);
56360
56361 - ASSERT(cache->bstop_percent >= 0 &&
56362 - cache->bstop_percent < cache->bcull_percent &&
56363 + ASSERT(cache->bstop_percent < cache->bcull_percent &&
56364 cache->bcull_percent < cache->brun_percent &&
56365 cache->brun_percent < 100);
56366
56367 diff --git a/fs/cachefiles/daemon.c b/fs/cachefiles/daemon.c
56368 index 0a1467b..6a53245 100644
56369 --- a/fs/cachefiles/daemon.c
56370 +++ b/fs/cachefiles/daemon.c
56371 @@ -196,7 +196,7 @@ static ssize_t cachefiles_daemon_read(struct file *file, char __user *_buffer,
56372 if (n > buflen)
56373 return -EMSGSIZE;
56374
56375 - if (copy_to_user(_buffer, buffer, n) != 0)
56376 + if (n > sizeof(buffer) || copy_to_user(_buffer, buffer, n) != 0)
56377 return -EFAULT;
56378
56379 return n;
56380 @@ -222,7 +222,7 @@ static ssize_t cachefiles_daemon_write(struct file *file,
56381 if (test_bit(CACHEFILES_DEAD, &cache->flags))
56382 return -EIO;
56383
56384 - if (datalen < 0 || datalen > PAGE_SIZE - 1)
56385 + if (datalen > PAGE_SIZE - 1)
56386 return -EOPNOTSUPP;
56387
56388 /* drag the command string into the kernel so we can parse it */
56389 @@ -386,7 +386,7 @@ static int cachefiles_daemon_fstop(struct cachefiles_cache *cache, char *args)
56390 if (args[0] != '%' || args[1] != '\0')
56391 return -EINVAL;
56392
56393 - if (fstop < 0 || fstop >= cache->fcull_percent)
56394 + if (fstop >= cache->fcull_percent)
56395 return cachefiles_daemon_range_error(cache, args);
56396
56397 cache->fstop_percent = fstop;
56398 @@ -458,7 +458,7 @@ static int cachefiles_daemon_bstop(struct cachefiles_cache *cache, char *args)
56399 if (args[0] != '%' || args[1] != '\0')
56400 return -EINVAL;
56401
56402 - if (bstop < 0 || bstop >= cache->bcull_percent)
56403 + if (bstop >= cache->bcull_percent)
56404 return cachefiles_daemon_range_error(cache, args);
56405
56406 cache->bstop_percent = bstop;
56407 diff --git a/fs/cachefiles/internal.h b/fs/cachefiles/internal.h
56408 index 5349473..d6c0b93 100644
56409 --- a/fs/cachefiles/internal.h
56410 +++ b/fs/cachefiles/internal.h
56411 @@ -59,7 +59,7 @@ struct cachefiles_cache {
56412 wait_queue_head_t daemon_pollwq; /* poll waitqueue for daemon */
56413 struct rb_root active_nodes; /* active nodes (can't be culled) */
56414 rwlock_t active_lock; /* lock for active_nodes */
56415 - atomic_t gravecounter; /* graveyard uniquifier */
56416 + atomic_unchecked_t gravecounter; /* graveyard uniquifier */
56417 unsigned frun_percent; /* when to stop culling (% files) */
56418 unsigned fcull_percent; /* when to start culling (% files) */
56419 unsigned fstop_percent; /* when to stop allocating (% files) */
56420 @@ -171,19 +171,19 @@ extern int cachefiles_check_in_use(struct cachefiles_cache *cache,
56421 * proc.c
56422 */
56423 #ifdef CONFIG_CACHEFILES_HISTOGRAM
56424 -extern atomic_t cachefiles_lookup_histogram[HZ];
56425 -extern atomic_t cachefiles_mkdir_histogram[HZ];
56426 -extern atomic_t cachefiles_create_histogram[HZ];
56427 +extern atomic_unchecked_t cachefiles_lookup_histogram[HZ];
56428 +extern atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
56429 +extern atomic_unchecked_t cachefiles_create_histogram[HZ];
56430
56431 extern int __init cachefiles_proc_init(void);
56432 extern void cachefiles_proc_cleanup(void);
56433 static inline
56434 -void cachefiles_hist(atomic_t histogram[], unsigned long start_jif)
56435 +void cachefiles_hist(atomic_unchecked_t histogram[], unsigned long start_jif)
56436 {
56437 unsigned long jif = jiffies - start_jif;
56438 if (jif >= HZ)
56439 jif = HZ - 1;
56440 - atomic_inc(&histogram[jif]);
56441 + atomic_inc_unchecked(&histogram[jif]);
56442 }
56443
56444 #else
56445 diff --git a/fs/cachefiles/namei.c b/fs/cachefiles/namei.c
56446 index ca65f39..48921e3 100644
56447 --- a/fs/cachefiles/namei.c
56448 +++ b/fs/cachefiles/namei.c
56449 @@ -317,7 +317,7 @@ try_again:
56450 /* first step is to make up a grave dentry in the graveyard */
56451 sprintf(nbuffer, "%08x%08x",
56452 (uint32_t) get_seconds(),
56453 - (uint32_t) atomic_inc_return(&cache->gravecounter));
56454 + (uint32_t) atomic_inc_return_unchecked(&cache->gravecounter));
56455
56456 /* do the multiway lock magic */
56457 trap = lock_rename(cache->graveyard, dir);
56458 diff --git a/fs/cachefiles/proc.c b/fs/cachefiles/proc.c
56459 index eccd339..4c1d995 100644
56460 --- a/fs/cachefiles/proc.c
56461 +++ b/fs/cachefiles/proc.c
56462 @@ -14,9 +14,9 @@
56463 #include <linux/seq_file.h>
56464 #include "internal.h"
56465
56466 -atomic_t cachefiles_lookup_histogram[HZ];
56467 -atomic_t cachefiles_mkdir_histogram[HZ];
56468 -atomic_t cachefiles_create_histogram[HZ];
56469 +atomic_unchecked_t cachefiles_lookup_histogram[HZ];
56470 +atomic_unchecked_t cachefiles_mkdir_histogram[HZ];
56471 +atomic_unchecked_t cachefiles_create_histogram[HZ];
56472
56473 /*
56474 * display the latency histogram
56475 @@ -35,9 +35,9 @@ static int cachefiles_histogram_show(struct seq_file *m, void *v)
56476 return 0;
56477 default:
56478 index = (unsigned long) v - 3;
56479 - x = atomic_read(&cachefiles_lookup_histogram[index]);
56480 - y = atomic_read(&cachefiles_mkdir_histogram[index]);
56481 - z = atomic_read(&cachefiles_create_histogram[index]);
56482 + x = atomic_read_unchecked(&cachefiles_lookup_histogram[index]);
56483 + y = atomic_read_unchecked(&cachefiles_mkdir_histogram[index]);
56484 + z = atomic_read_unchecked(&cachefiles_create_histogram[index]);
56485 if (x == 0 && y == 0 && z == 0)
56486 return 0;
56487
56488 diff --git a/fs/cachefiles/rdwr.c b/fs/cachefiles/rdwr.c
56489 index ebaff36..7e3ea26 100644
56490 --- a/fs/cachefiles/rdwr.c
56491 +++ b/fs/cachefiles/rdwr.c
56492 @@ -950,7 +950,7 @@ int cachefiles_write_page(struct fscache_storage *op, struct page *page)
56493 old_fs = get_fs();
56494 set_fs(KERNEL_DS);
56495 ret = file->f_op->write(
56496 - file, (const void __user *) data, len, &pos);
56497 + file, (const void __force_user *) data, len, &pos);
56498 set_fs(old_fs);
56499 kunmap(page);
56500 file_end_write(file);
56501 diff --git a/fs/ceph/dir.c b/fs/ceph/dir.c
56502 index 2a0bcae..34ec24e 100644
56503 --- a/fs/ceph/dir.c
56504 +++ b/fs/ceph/dir.c
56505 @@ -240,7 +240,7 @@ static int ceph_readdir(struct file *file, struct dir_context *ctx)
56506 struct ceph_fs_client *fsc = ceph_inode_to_client(inode);
56507 struct ceph_mds_client *mdsc = fsc->mdsc;
56508 unsigned frag = fpos_frag(ctx->pos);
56509 - int off = fpos_off(ctx->pos);
56510 + unsigned int off = fpos_off(ctx->pos);
56511 int err;
56512 u32 ftype;
56513 struct ceph_mds_reply_info_parsed *rinfo;
56514 diff --git a/fs/ceph/super.c b/fs/ceph/super.c
56515 index 6a0951e..03fac6d 100644
56516 --- a/fs/ceph/super.c
56517 +++ b/fs/ceph/super.c
56518 @@ -870,7 +870,7 @@ static int ceph_compare_super(struct super_block *sb, void *data)
56519 /*
56520 * construct our own bdi so we can control readahead, etc.
56521 */
56522 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
56523 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
56524
56525 static int ceph_register_bdi(struct super_block *sb,
56526 struct ceph_fs_client *fsc)
56527 @@ -887,7 +887,7 @@ static int ceph_register_bdi(struct super_block *sb,
56528 default_backing_dev_info.ra_pages;
56529
56530 err = bdi_register(&fsc->backing_dev_info, NULL, "ceph-%ld",
56531 - atomic_long_inc_return(&bdi_seq));
56532 + atomic_long_inc_return_unchecked(&bdi_seq));
56533 if (!err)
56534 sb->s_bdi = &fsc->backing_dev_info;
56535 return err;
56536 diff --git a/fs/cifs/cifs_debug.c b/fs/cifs/cifs_debug.c
56537 index f3ac415..3d2420c 100644
56538 --- a/fs/cifs/cifs_debug.c
56539 +++ b/fs/cifs/cifs_debug.c
56540 @@ -286,8 +286,8 @@ static ssize_t cifs_stats_proc_write(struct file *file,
56541
56542 if (c == '1' || c == 'y' || c == 'Y' || c == '0') {
56543 #ifdef CONFIG_CIFS_STATS2
56544 - atomic_set(&totBufAllocCount, 0);
56545 - atomic_set(&totSmBufAllocCount, 0);
56546 + atomic_set_unchecked(&totBufAllocCount, 0);
56547 + atomic_set_unchecked(&totSmBufAllocCount, 0);
56548 #endif /* CONFIG_CIFS_STATS2 */
56549 spin_lock(&cifs_tcp_ses_lock);
56550 list_for_each(tmp1, &cifs_tcp_ses_list) {
56551 @@ -300,7 +300,7 @@ static ssize_t cifs_stats_proc_write(struct file *file,
56552 tcon = list_entry(tmp3,
56553 struct cifs_tcon,
56554 tcon_list);
56555 - atomic_set(&tcon->num_smbs_sent, 0);
56556 + atomic_set_unchecked(&tcon->num_smbs_sent, 0);
56557 if (server->ops->clear_stats)
56558 server->ops->clear_stats(tcon);
56559 }
56560 @@ -332,8 +332,8 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
56561 smBufAllocCount.counter, cifs_min_small);
56562 #ifdef CONFIG_CIFS_STATS2
56563 seq_printf(m, "Total Large %d Small %d Allocations\n",
56564 - atomic_read(&totBufAllocCount),
56565 - atomic_read(&totSmBufAllocCount));
56566 + atomic_read_unchecked(&totBufAllocCount),
56567 + atomic_read_unchecked(&totSmBufAllocCount));
56568 #endif /* CONFIG_CIFS_STATS2 */
56569
56570 seq_printf(m, "Operations (MIDs): %d\n", atomic_read(&midCount));
56571 @@ -362,7 +362,7 @@ static int cifs_stats_proc_show(struct seq_file *m, void *v)
56572 if (tcon->need_reconnect)
56573 seq_puts(m, "\tDISCONNECTED ");
56574 seq_printf(m, "\nSMBs: %d",
56575 - atomic_read(&tcon->num_smbs_sent));
56576 + atomic_read_unchecked(&tcon->num_smbs_sent));
56577 if (server->ops->print_stats)
56578 server->ops->print_stats(m, tcon);
56579 }
56580 diff --git a/fs/cifs/cifsfs.c b/fs/cifs/cifsfs.c
56581 index 849f613..eae6dec 100644
56582 --- a/fs/cifs/cifsfs.c
56583 +++ b/fs/cifs/cifsfs.c
56584 @@ -1056,7 +1056,7 @@ cifs_init_request_bufs(void)
56585 */
56586 cifs_req_cachep = kmem_cache_create("cifs_request",
56587 CIFSMaxBufSize + max_hdr_size, 0,
56588 - SLAB_HWCACHE_ALIGN, NULL);
56589 + SLAB_HWCACHE_ALIGN | SLAB_USERCOPY, NULL);
56590 if (cifs_req_cachep == NULL)
56591 return -ENOMEM;
56592
56593 @@ -1083,7 +1083,7 @@ cifs_init_request_bufs(void)
56594 efficient to alloc 1 per page off the slab compared to 17K (5page)
56595 alloc of large cifs buffers even when page debugging is on */
56596 cifs_sm_req_cachep = kmem_cache_create("cifs_small_rq",
56597 - MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN,
56598 + MAX_CIFS_SMALL_BUFFER_SIZE, 0, SLAB_HWCACHE_ALIGN | SLAB_USERCOPY,
56599 NULL);
56600 if (cifs_sm_req_cachep == NULL) {
56601 mempool_destroy(cifs_req_poolp);
56602 @@ -1168,8 +1168,8 @@ init_cifs(void)
56603 atomic_set(&bufAllocCount, 0);
56604 atomic_set(&smBufAllocCount, 0);
56605 #ifdef CONFIG_CIFS_STATS2
56606 - atomic_set(&totBufAllocCount, 0);
56607 - atomic_set(&totSmBufAllocCount, 0);
56608 + atomic_set_unchecked(&totBufAllocCount, 0);
56609 + atomic_set_unchecked(&totSmBufAllocCount, 0);
56610 #endif /* CONFIG_CIFS_STATS2 */
56611
56612 atomic_set(&midCount, 0);
56613 diff --git a/fs/cifs/cifsglob.h b/fs/cifs/cifsglob.h
56614 index f918a99..bb300d5 100644
56615 --- a/fs/cifs/cifsglob.h
56616 +++ b/fs/cifs/cifsglob.h
56617 @@ -787,35 +787,35 @@ struct cifs_tcon {
56618 __u16 Flags; /* optional support bits */
56619 enum statusEnum tidStatus;
56620 #ifdef CONFIG_CIFS_STATS
56621 - atomic_t num_smbs_sent;
56622 + atomic_unchecked_t num_smbs_sent;
56623 union {
56624 struct {
56625 - atomic_t num_writes;
56626 - atomic_t num_reads;
56627 - atomic_t num_flushes;
56628 - atomic_t num_oplock_brks;
56629 - atomic_t num_opens;
56630 - atomic_t num_closes;
56631 - atomic_t num_deletes;
56632 - atomic_t num_mkdirs;
56633 - atomic_t num_posixopens;
56634 - atomic_t num_posixmkdirs;
56635 - atomic_t num_rmdirs;
56636 - atomic_t num_renames;
56637 - atomic_t num_t2renames;
56638 - atomic_t num_ffirst;
56639 - atomic_t num_fnext;
56640 - atomic_t num_fclose;
56641 - atomic_t num_hardlinks;
56642 - atomic_t num_symlinks;
56643 - atomic_t num_locks;
56644 - atomic_t num_acl_get;
56645 - atomic_t num_acl_set;
56646 + atomic_unchecked_t num_writes;
56647 + atomic_unchecked_t num_reads;
56648 + atomic_unchecked_t num_flushes;
56649 + atomic_unchecked_t num_oplock_brks;
56650 + atomic_unchecked_t num_opens;
56651 + atomic_unchecked_t num_closes;
56652 + atomic_unchecked_t num_deletes;
56653 + atomic_unchecked_t num_mkdirs;
56654 + atomic_unchecked_t num_posixopens;
56655 + atomic_unchecked_t num_posixmkdirs;
56656 + atomic_unchecked_t num_rmdirs;
56657 + atomic_unchecked_t num_renames;
56658 + atomic_unchecked_t num_t2renames;
56659 + atomic_unchecked_t num_ffirst;
56660 + atomic_unchecked_t num_fnext;
56661 + atomic_unchecked_t num_fclose;
56662 + atomic_unchecked_t num_hardlinks;
56663 + atomic_unchecked_t num_symlinks;
56664 + atomic_unchecked_t num_locks;
56665 + atomic_unchecked_t num_acl_get;
56666 + atomic_unchecked_t num_acl_set;
56667 } cifs_stats;
56668 #ifdef CONFIG_CIFS_SMB2
56669 struct {
56670 - atomic_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
56671 - atomic_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
56672 + atomic_unchecked_t smb2_com_sent[NUMBER_OF_SMB2_COMMANDS];
56673 + atomic_unchecked_t smb2_com_failed[NUMBER_OF_SMB2_COMMANDS];
56674 } smb2_stats;
56675 #endif /* CONFIG_CIFS_SMB2 */
56676 } stats;
56677 @@ -1145,7 +1145,7 @@ convert_delimiter(char *path, char delim)
56678 }
56679
56680 #ifdef CONFIG_CIFS_STATS
56681 -#define cifs_stats_inc atomic_inc
56682 +#define cifs_stats_inc atomic_inc_unchecked
56683
56684 static inline void cifs_stats_bytes_written(struct cifs_tcon *tcon,
56685 unsigned int bytes)
56686 @@ -1511,8 +1511,8 @@ GLOBAL_EXTERN atomic_t tconInfoReconnectCount;
56687 /* Various Debug counters */
56688 GLOBAL_EXTERN atomic_t bufAllocCount; /* current number allocated */
56689 #ifdef CONFIG_CIFS_STATS2
56690 -GLOBAL_EXTERN atomic_t totBufAllocCount; /* total allocated over all time */
56691 -GLOBAL_EXTERN atomic_t totSmBufAllocCount;
56692 +GLOBAL_EXTERN atomic_unchecked_t totBufAllocCount; /* total allocated over all time */
56693 +GLOBAL_EXTERN atomic_unchecked_t totSmBufAllocCount;
56694 #endif
56695 GLOBAL_EXTERN atomic_t smBufAllocCount;
56696 GLOBAL_EXTERN atomic_t midCount;
56697 diff --git a/fs/cifs/file.c b/fs/cifs/file.c
56698 index 5a5a872..92c3210 100644
56699 --- a/fs/cifs/file.c
56700 +++ b/fs/cifs/file.c
56701 @@ -1900,10 +1900,14 @@ static int cifs_writepages(struct address_space *mapping,
56702 index = mapping->writeback_index; /* Start from prev offset */
56703 end = -1;
56704 } else {
56705 - index = wbc->range_start >> PAGE_CACHE_SHIFT;
56706 - end = wbc->range_end >> PAGE_CACHE_SHIFT;
56707 - if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX)
56708 + if (wbc->range_start == 0 && wbc->range_end == LLONG_MAX) {
56709 range_whole = true;
56710 + index = 0;
56711 + end = ULONG_MAX;
56712 + } else {
56713 + index = wbc->range_start >> PAGE_CACHE_SHIFT;
56714 + end = wbc->range_end >> PAGE_CACHE_SHIFT;
56715 + }
56716 scanned = true;
56717 }
56718 retry:
56719 diff --git a/fs/cifs/misc.c b/fs/cifs/misc.c
56720 index 2f9f379..43f8025 100644
56721 --- a/fs/cifs/misc.c
56722 +++ b/fs/cifs/misc.c
56723 @@ -170,7 +170,7 @@ cifs_buf_get(void)
56724 memset(ret_buf, 0, buf_size + 3);
56725 atomic_inc(&bufAllocCount);
56726 #ifdef CONFIG_CIFS_STATS2
56727 - atomic_inc(&totBufAllocCount);
56728 + atomic_inc_unchecked(&totBufAllocCount);
56729 #endif /* CONFIG_CIFS_STATS2 */
56730 }
56731
56732 @@ -205,7 +205,7 @@ cifs_small_buf_get(void)
56733 /* memset(ret_buf, 0, sizeof(struct smb_hdr) + 27);*/
56734 atomic_inc(&smBufAllocCount);
56735 #ifdef CONFIG_CIFS_STATS2
56736 - atomic_inc(&totSmBufAllocCount);
56737 + atomic_inc_unchecked(&totSmBufAllocCount);
56738 #endif /* CONFIG_CIFS_STATS2 */
56739
56740 }
56741 diff --git a/fs/cifs/smb1ops.c b/fs/cifs/smb1ops.c
56742 index 5f5ba0d..8d6ef7d 100644
56743 --- a/fs/cifs/smb1ops.c
56744 +++ b/fs/cifs/smb1ops.c
56745 @@ -609,27 +609,27 @@ static void
56746 cifs_clear_stats(struct cifs_tcon *tcon)
56747 {
56748 #ifdef CONFIG_CIFS_STATS
56749 - atomic_set(&tcon->stats.cifs_stats.num_writes, 0);
56750 - atomic_set(&tcon->stats.cifs_stats.num_reads, 0);
56751 - atomic_set(&tcon->stats.cifs_stats.num_flushes, 0);
56752 - atomic_set(&tcon->stats.cifs_stats.num_oplock_brks, 0);
56753 - atomic_set(&tcon->stats.cifs_stats.num_opens, 0);
56754 - atomic_set(&tcon->stats.cifs_stats.num_posixopens, 0);
56755 - atomic_set(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
56756 - atomic_set(&tcon->stats.cifs_stats.num_closes, 0);
56757 - atomic_set(&tcon->stats.cifs_stats.num_deletes, 0);
56758 - atomic_set(&tcon->stats.cifs_stats.num_mkdirs, 0);
56759 - atomic_set(&tcon->stats.cifs_stats.num_rmdirs, 0);
56760 - atomic_set(&tcon->stats.cifs_stats.num_renames, 0);
56761 - atomic_set(&tcon->stats.cifs_stats.num_t2renames, 0);
56762 - atomic_set(&tcon->stats.cifs_stats.num_ffirst, 0);
56763 - atomic_set(&tcon->stats.cifs_stats.num_fnext, 0);
56764 - atomic_set(&tcon->stats.cifs_stats.num_fclose, 0);
56765 - atomic_set(&tcon->stats.cifs_stats.num_hardlinks, 0);
56766 - atomic_set(&tcon->stats.cifs_stats.num_symlinks, 0);
56767 - atomic_set(&tcon->stats.cifs_stats.num_locks, 0);
56768 - atomic_set(&tcon->stats.cifs_stats.num_acl_get, 0);
56769 - atomic_set(&tcon->stats.cifs_stats.num_acl_set, 0);
56770 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_writes, 0);
56771 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_reads, 0);
56772 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_flushes, 0);
56773 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_oplock_brks, 0);
56774 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_opens, 0);
56775 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixopens, 0);
56776 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs, 0);
56777 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_closes, 0);
56778 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_deletes, 0);
56779 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_mkdirs, 0);
56780 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_rmdirs, 0);
56781 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_renames, 0);
56782 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_t2renames, 0);
56783 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_ffirst, 0);
56784 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fnext, 0);
56785 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_fclose, 0);
56786 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_hardlinks, 0);
56787 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_symlinks, 0);
56788 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_locks, 0);
56789 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_get, 0);
56790 + atomic_set_unchecked(&tcon->stats.cifs_stats.num_acl_set, 0);
56791 #endif
56792 }
56793
56794 @@ -638,36 +638,36 @@ cifs_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
56795 {
56796 #ifdef CONFIG_CIFS_STATS
56797 seq_printf(m, " Oplocks breaks: %d",
56798 - atomic_read(&tcon->stats.cifs_stats.num_oplock_brks));
56799 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_oplock_brks));
56800 seq_printf(m, "\nReads: %d Bytes: %llu",
56801 - atomic_read(&tcon->stats.cifs_stats.num_reads),
56802 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_reads),
56803 (long long)(tcon->bytes_read));
56804 seq_printf(m, "\nWrites: %d Bytes: %llu",
56805 - atomic_read(&tcon->stats.cifs_stats.num_writes),
56806 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_writes),
56807 (long long)(tcon->bytes_written));
56808 seq_printf(m, "\nFlushes: %d",
56809 - atomic_read(&tcon->stats.cifs_stats.num_flushes));
56810 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_flushes));
56811 seq_printf(m, "\nLocks: %d HardLinks: %d Symlinks: %d",
56812 - atomic_read(&tcon->stats.cifs_stats.num_locks),
56813 - atomic_read(&tcon->stats.cifs_stats.num_hardlinks),
56814 - atomic_read(&tcon->stats.cifs_stats.num_symlinks));
56815 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_locks),
56816 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_hardlinks),
56817 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_symlinks));
56818 seq_printf(m, "\nOpens: %d Closes: %d Deletes: %d",
56819 - atomic_read(&tcon->stats.cifs_stats.num_opens),
56820 - atomic_read(&tcon->stats.cifs_stats.num_closes),
56821 - atomic_read(&tcon->stats.cifs_stats.num_deletes));
56822 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_opens),
56823 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_closes),
56824 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_deletes));
56825 seq_printf(m, "\nPosix Opens: %d Posix Mkdirs: %d",
56826 - atomic_read(&tcon->stats.cifs_stats.num_posixopens),
56827 - atomic_read(&tcon->stats.cifs_stats.num_posixmkdirs));
56828 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixopens),
56829 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_posixmkdirs));
56830 seq_printf(m, "\nMkdirs: %d Rmdirs: %d",
56831 - atomic_read(&tcon->stats.cifs_stats.num_mkdirs),
56832 - atomic_read(&tcon->stats.cifs_stats.num_rmdirs));
56833 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_mkdirs),
56834 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_rmdirs));
56835 seq_printf(m, "\nRenames: %d T2 Renames %d",
56836 - atomic_read(&tcon->stats.cifs_stats.num_renames),
56837 - atomic_read(&tcon->stats.cifs_stats.num_t2renames));
56838 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_renames),
56839 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_t2renames));
56840 seq_printf(m, "\nFindFirst: %d FNext %d FClose %d",
56841 - atomic_read(&tcon->stats.cifs_stats.num_ffirst),
56842 - atomic_read(&tcon->stats.cifs_stats.num_fnext),
56843 - atomic_read(&tcon->stats.cifs_stats.num_fclose));
56844 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_ffirst),
56845 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fnext),
56846 + atomic_read_unchecked(&tcon->stats.cifs_stats.num_fclose));
56847 #endif
56848 }
56849
56850 diff --git a/fs/cifs/smb2ops.c b/fs/cifs/smb2ops.c
56851 index 757da3e..07bf1ed 100644
56852 --- a/fs/cifs/smb2ops.c
56853 +++ b/fs/cifs/smb2ops.c
56854 @@ -370,8 +370,8 @@ smb2_clear_stats(struct cifs_tcon *tcon)
56855 #ifdef CONFIG_CIFS_STATS
56856 int i;
56857 for (i = 0; i < NUMBER_OF_SMB2_COMMANDS; i++) {
56858 - atomic_set(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
56859 - atomic_set(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
56860 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_sent[i], 0);
56861 + atomic_set_unchecked(&tcon->stats.smb2_stats.smb2_com_failed[i], 0);
56862 }
56863 #endif
56864 }
56865 @@ -411,65 +411,65 @@ static void
56866 smb2_print_stats(struct seq_file *m, struct cifs_tcon *tcon)
56867 {
56868 #ifdef CONFIG_CIFS_STATS
56869 - atomic_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
56870 - atomic_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
56871 + atomic_unchecked_t *sent = tcon->stats.smb2_stats.smb2_com_sent;
56872 + atomic_unchecked_t *failed = tcon->stats.smb2_stats.smb2_com_failed;
56873 seq_printf(m, "\nNegotiates: %d sent %d failed",
56874 - atomic_read(&sent[SMB2_NEGOTIATE_HE]),
56875 - atomic_read(&failed[SMB2_NEGOTIATE_HE]));
56876 + atomic_read_unchecked(&sent[SMB2_NEGOTIATE_HE]),
56877 + atomic_read_unchecked(&failed[SMB2_NEGOTIATE_HE]));
56878 seq_printf(m, "\nSessionSetups: %d sent %d failed",
56879 - atomic_read(&sent[SMB2_SESSION_SETUP_HE]),
56880 - atomic_read(&failed[SMB2_SESSION_SETUP_HE]));
56881 + atomic_read_unchecked(&sent[SMB2_SESSION_SETUP_HE]),
56882 + atomic_read_unchecked(&failed[SMB2_SESSION_SETUP_HE]));
56883 seq_printf(m, "\nLogoffs: %d sent %d failed",
56884 - atomic_read(&sent[SMB2_LOGOFF_HE]),
56885 - atomic_read(&failed[SMB2_LOGOFF_HE]));
56886 + atomic_read_unchecked(&sent[SMB2_LOGOFF_HE]),
56887 + atomic_read_unchecked(&failed[SMB2_LOGOFF_HE]));
56888 seq_printf(m, "\nTreeConnects: %d sent %d failed",
56889 - atomic_read(&sent[SMB2_TREE_CONNECT_HE]),
56890 - atomic_read(&failed[SMB2_TREE_CONNECT_HE]));
56891 + atomic_read_unchecked(&sent[SMB2_TREE_CONNECT_HE]),
56892 + atomic_read_unchecked(&failed[SMB2_TREE_CONNECT_HE]));
56893 seq_printf(m, "\nTreeDisconnects: %d sent %d failed",
56894 - atomic_read(&sent[SMB2_TREE_DISCONNECT_HE]),
56895 - atomic_read(&failed[SMB2_TREE_DISCONNECT_HE]));
56896 + atomic_read_unchecked(&sent[SMB2_TREE_DISCONNECT_HE]),
56897 + atomic_read_unchecked(&failed[SMB2_TREE_DISCONNECT_HE]));
56898 seq_printf(m, "\nCreates: %d sent %d failed",
56899 - atomic_read(&sent[SMB2_CREATE_HE]),
56900 - atomic_read(&failed[SMB2_CREATE_HE]));
56901 + atomic_read_unchecked(&sent[SMB2_CREATE_HE]),
56902 + atomic_read_unchecked(&failed[SMB2_CREATE_HE]));
56903 seq_printf(m, "\nCloses: %d sent %d failed",
56904 - atomic_read(&sent[SMB2_CLOSE_HE]),
56905 - atomic_read(&failed[SMB2_CLOSE_HE]));
56906 + atomic_read_unchecked(&sent[SMB2_CLOSE_HE]),
56907 + atomic_read_unchecked(&failed[SMB2_CLOSE_HE]));
56908 seq_printf(m, "\nFlushes: %d sent %d failed",
56909 - atomic_read(&sent[SMB2_FLUSH_HE]),
56910 - atomic_read(&failed[SMB2_FLUSH_HE]));
56911 + atomic_read_unchecked(&sent[SMB2_FLUSH_HE]),
56912 + atomic_read_unchecked(&failed[SMB2_FLUSH_HE]));
56913 seq_printf(m, "\nReads: %d sent %d failed",
56914 - atomic_read(&sent[SMB2_READ_HE]),
56915 - atomic_read(&failed[SMB2_READ_HE]));
56916 + atomic_read_unchecked(&sent[SMB2_READ_HE]),
56917 + atomic_read_unchecked(&failed[SMB2_READ_HE]));
56918 seq_printf(m, "\nWrites: %d sent %d failed",
56919 - atomic_read(&sent[SMB2_WRITE_HE]),
56920 - atomic_read(&failed[SMB2_WRITE_HE]));
56921 + atomic_read_unchecked(&sent[SMB2_WRITE_HE]),
56922 + atomic_read_unchecked(&failed[SMB2_WRITE_HE]));
56923 seq_printf(m, "\nLocks: %d sent %d failed",
56924 - atomic_read(&sent[SMB2_LOCK_HE]),
56925 - atomic_read(&failed[SMB2_LOCK_HE]));
56926 + atomic_read_unchecked(&sent[SMB2_LOCK_HE]),
56927 + atomic_read_unchecked(&failed[SMB2_LOCK_HE]));
56928 seq_printf(m, "\nIOCTLs: %d sent %d failed",
56929 - atomic_read(&sent[SMB2_IOCTL_HE]),
56930 - atomic_read(&failed[SMB2_IOCTL_HE]));
56931 + atomic_read_unchecked(&sent[SMB2_IOCTL_HE]),
56932 + atomic_read_unchecked(&failed[SMB2_IOCTL_HE]));
56933 seq_printf(m, "\nCancels: %d sent %d failed",
56934 - atomic_read(&sent[SMB2_CANCEL_HE]),
56935 - atomic_read(&failed[SMB2_CANCEL_HE]));
56936 + atomic_read_unchecked(&sent[SMB2_CANCEL_HE]),
56937 + atomic_read_unchecked(&failed[SMB2_CANCEL_HE]));
56938 seq_printf(m, "\nEchos: %d sent %d failed",
56939 - atomic_read(&sent[SMB2_ECHO_HE]),
56940 - atomic_read(&failed[SMB2_ECHO_HE]));
56941 + atomic_read_unchecked(&sent[SMB2_ECHO_HE]),
56942 + atomic_read_unchecked(&failed[SMB2_ECHO_HE]));
56943 seq_printf(m, "\nQueryDirectories: %d sent %d failed",
56944 - atomic_read(&sent[SMB2_QUERY_DIRECTORY_HE]),
56945 - atomic_read(&failed[SMB2_QUERY_DIRECTORY_HE]));
56946 + atomic_read_unchecked(&sent[SMB2_QUERY_DIRECTORY_HE]),
56947 + atomic_read_unchecked(&failed[SMB2_QUERY_DIRECTORY_HE]));
56948 seq_printf(m, "\nChangeNotifies: %d sent %d failed",
56949 - atomic_read(&sent[SMB2_CHANGE_NOTIFY_HE]),
56950 - atomic_read(&failed[SMB2_CHANGE_NOTIFY_HE]));
56951 + atomic_read_unchecked(&sent[SMB2_CHANGE_NOTIFY_HE]),
56952 + atomic_read_unchecked(&failed[SMB2_CHANGE_NOTIFY_HE]));
56953 seq_printf(m, "\nQueryInfos: %d sent %d failed",
56954 - atomic_read(&sent[SMB2_QUERY_INFO_HE]),
56955 - atomic_read(&failed[SMB2_QUERY_INFO_HE]));
56956 + atomic_read_unchecked(&sent[SMB2_QUERY_INFO_HE]),
56957 + atomic_read_unchecked(&failed[SMB2_QUERY_INFO_HE]));
56958 seq_printf(m, "\nSetInfos: %d sent %d failed",
56959 - atomic_read(&sent[SMB2_SET_INFO_HE]),
56960 - atomic_read(&failed[SMB2_SET_INFO_HE]));
56961 + atomic_read_unchecked(&sent[SMB2_SET_INFO_HE]),
56962 + atomic_read_unchecked(&failed[SMB2_SET_INFO_HE]));
56963 seq_printf(m, "\nOplockBreaks: %d sent %d failed",
56964 - atomic_read(&sent[SMB2_OPLOCK_BREAK_HE]),
56965 - atomic_read(&failed[SMB2_OPLOCK_BREAK_HE]));
56966 + atomic_read_unchecked(&sent[SMB2_OPLOCK_BREAK_HE]),
56967 + atomic_read_unchecked(&failed[SMB2_OPLOCK_BREAK_HE]));
56968 #endif
56969 }
56970
56971 diff --git a/fs/cifs/smb2pdu.c b/fs/cifs/smb2pdu.c
56972 index 2013234..a720734 100644
56973 --- a/fs/cifs/smb2pdu.c
56974 +++ b/fs/cifs/smb2pdu.c
56975 @@ -2091,8 +2091,7 @@ SMB2_query_directory(const unsigned int xid, struct cifs_tcon *tcon,
56976 default:
56977 cifs_dbg(VFS, "info level %u isn't supported\n",
56978 srch_inf->info_level);
56979 - rc = -EINVAL;
56980 - goto qdir_exit;
56981 + return -EINVAL;
56982 }
56983
56984 req->FileIndex = cpu_to_le32(index);
56985 diff --git a/fs/coda/cache.c b/fs/coda/cache.c
56986 index 1da168c..8bc7ff6 100644
56987 --- a/fs/coda/cache.c
56988 +++ b/fs/coda/cache.c
56989 @@ -24,7 +24,7 @@
56990 #include "coda_linux.h"
56991 #include "coda_cache.h"
56992
56993 -static atomic_t permission_epoch = ATOMIC_INIT(0);
56994 +static atomic_unchecked_t permission_epoch = ATOMIC_INIT(0);
56995
56996 /* replace or extend an acl cache hit */
56997 void coda_cache_enter(struct inode *inode, int mask)
56998 @@ -32,7 +32,7 @@ void coda_cache_enter(struct inode *inode, int mask)
56999 struct coda_inode_info *cii = ITOC(inode);
57000
57001 spin_lock(&cii->c_lock);
57002 - cii->c_cached_epoch = atomic_read(&permission_epoch);
57003 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch);
57004 if (!uid_eq(cii->c_uid, current_fsuid())) {
57005 cii->c_uid = current_fsuid();
57006 cii->c_cached_perm = mask;
57007 @@ -46,14 +46,14 @@ void coda_cache_clear_inode(struct inode *inode)
57008 {
57009 struct coda_inode_info *cii = ITOC(inode);
57010 spin_lock(&cii->c_lock);
57011 - cii->c_cached_epoch = atomic_read(&permission_epoch) - 1;
57012 + cii->c_cached_epoch = atomic_read_unchecked(&permission_epoch) - 1;
57013 spin_unlock(&cii->c_lock);
57014 }
57015
57016 /* remove all acl caches */
57017 void coda_cache_clear_all(struct super_block *sb)
57018 {
57019 - atomic_inc(&permission_epoch);
57020 + atomic_inc_unchecked(&permission_epoch);
57021 }
57022
57023
57024 @@ -66,7 +66,7 @@ int coda_cache_check(struct inode *inode, int mask)
57025 spin_lock(&cii->c_lock);
57026 hit = (mask & cii->c_cached_perm) == mask &&
57027 uid_eq(cii->c_uid, current_fsuid()) &&
57028 - cii->c_cached_epoch == atomic_read(&permission_epoch);
57029 + cii->c_cached_epoch == atomic_read_unchecked(&permission_epoch);
57030 spin_unlock(&cii->c_lock);
57031
57032 return hit;
57033 diff --git a/fs/compat.c b/fs/compat.c
57034 index 6af20de..fec3fbb 100644
57035 --- a/fs/compat.c
57036 +++ b/fs/compat.c
57037 @@ -54,7 +54,7 @@
57038 #include <asm/ioctls.h>
57039 #include "internal.h"
57040
57041 -int compat_log = 1;
57042 +int compat_log = 0;
57043
57044 int compat_printk(const char *fmt, ...)
57045 {
57046 @@ -488,7 +488,7 @@ compat_sys_io_setup(unsigned nr_reqs, u32 __user *ctx32p)
57047
57048 set_fs(KERNEL_DS);
57049 /* The __user pointer cast is valid because of the set_fs() */
57050 - ret = sys_io_setup(nr_reqs, (aio_context_t __user *) &ctx64);
57051 + ret = sys_io_setup(nr_reqs, (aio_context_t __force_user *) &ctx64);
57052 set_fs(oldfs);
57053 /* truncating is ok because it's a user address */
57054 if (!ret)
57055 @@ -546,7 +546,7 @@ ssize_t compat_rw_copy_check_uvector(int type,
57056 goto out;
57057
57058 ret = -EINVAL;
57059 - if (nr_segs > UIO_MAXIOV || nr_segs < 0)
57060 + if (nr_segs > UIO_MAXIOV)
57061 goto out;
57062 if (nr_segs > fast_segs) {
57063 ret = -ENOMEM;
57064 @@ -834,6 +834,7 @@ struct compat_old_linux_dirent {
57065 struct compat_readdir_callback {
57066 struct dir_context ctx;
57067 struct compat_old_linux_dirent __user *dirent;
57068 + struct file * file;
57069 int result;
57070 };
57071
57072 @@ -851,6 +852,10 @@ static int compat_fillonedir(void *__buf, const char *name, int namlen,
57073 buf->result = -EOVERFLOW;
57074 return -EOVERFLOW;
57075 }
57076 +
57077 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57078 + return 0;
57079 +
57080 buf->result++;
57081 dirent = buf->dirent;
57082 if (!access_ok(VERIFY_WRITE, dirent,
57083 @@ -882,6 +887,7 @@ asmlinkage long compat_sys_old_readdir(unsigned int fd,
57084 if (!f.file)
57085 return -EBADF;
57086
57087 + buf.file = f.file;
57088 error = iterate_dir(f.file, &buf.ctx);
57089 if (buf.result)
57090 error = buf.result;
57091 @@ -901,6 +907,7 @@ struct compat_getdents_callback {
57092 struct dir_context ctx;
57093 struct compat_linux_dirent __user *current_dir;
57094 struct compat_linux_dirent __user *previous;
57095 + struct file * file;
57096 int count;
57097 int error;
57098 };
57099 @@ -922,6 +929,10 @@ static int compat_filldir(void *__buf, const char *name, int namlen,
57100 buf->error = -EOVERFLOW;
57101 return -EOVERFLOW;
57102 }
57103 +
57104 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57105 + return 0;
57106 +
57107 dirent = buf->previous;
57108 if (dirent) {
57109 if (__put_user(offset, &dirent->d_off))
57110 @@ -967,6 +978,7 @@ asmlinkage long compat_sys_getdents(unsigned int fd,
57111 if (!f.file)
57112 return -EBADF;
57113
57114 + buf.file = f.file;
57115 error = iterate_dir(f.file, &buf.ctx);
57116 if (error >= 0)
57117 error = buf.error;
57118 @@ -987,6 +999,7 @@ struct compat_getdents_callback64 {
57119 struct dir_context ctx;
57120 struct linux_dirent64 __user *current_dir;
57121 struct linux_dirent64 __user *previous;
57122 + struct file * file;
57123 int count;
57124 int error;
57125 };
57126 @@ -1003,6 +1016,10 @@ static int compat_filldir64(void * __buf, const char * name, int namlen, loff_t
57127 buf->error = -EINVAL; /* only used if we fail.. */
57128 if (reclen > buf->count)
57129 return -EINVAL;
57130 +
57131 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
57132 + return 0;
57133 +
57134 dirent = buf->previous;
57135
57136 if (dirent) {
57137 @@ -1052,6 +1069,7 @@ asmlinkage long compat_sys_getdents64(unsigned int fd,
57138 if (!f.file)
57139 return -EBADF;
57140
57141 + buf.file = f.file;
57142 error = iterate_dir(f.file, &buf.ctx);
57143 if (error >= 0)
57144 error = buf.error;
57145 diff --git a/fs/compat_binfmt_elf.c b/fs/compat_binfmt_elf.c
57146 index a81147e..20bf2b5 100644
57147 --- a/fs/compat_binfmt_elf.c
57148 +++ b/fs/compat_binfmt_elf.c
57149 @@ -30,11 +30,13 @@
57150 #undef elf_phdr
57151 #undef elf_shdr
57152 #undef elf_note
57153 +#undef elf_dyn
57154 #undef elf_addr_t
57155 #define elfhdr elf32_hdr
57156 #define elf_phdr elf32_phdr
57157 #define elf_shdr elf32_shdr
57158 #define elf_note elf32_note
57159 +#define elf_dyn Elf32_Dyn
57160 #define elf_addr_t Elf32_Addr
57161
57162 /*
57163 diff --git a/fs/compat_ioctl.c b/fs/compat_ioctl.c
57164 index dc52e13..ec61057 100644
57165 --- a/fs/compat_ioctl.c
57166 +++ b/fs/compat_ioctl.c
57167 @@ -621,7 +621,7 @@ static int serial_struct_ioctl(unsigned fd, unsigned cmd,
57168 return -EFAULT;
57169 if (__get_user(udata, &ss32->iomem_base))
57170 return -EFAULT;
57171 - ss.iomem_base = compat_ptr(udata);
57172 + ss.iomem_base = (unsigned char __force_kernel *)compat_ptr(udata);
57173 if (__get_user(ss.iomem_reg_shift, &ss32->iomem_reg_shift) ||
57174 __get_user(ss.port_high, &ss32->port_high))
57175 return -EFAULT;
57176 @@ -702,8 +702,8 @@ static int do_i2c_rdwr_ioctl(unsigned int fd, unsigned int cmd,
57177 for (i = 0; i < nmsgs; i++) {
57178 if (copy_in_user(&tmsgs[i].addr, &umsgs[i].addr, 3*sizeof(u16)))
57179 return -EFAULT;
57180 - if (get_user(datap, &umsgs[i].buf) ||
57181 - put_user(compat_ptr(datap), &tmsgs[i].buf))
57182 + if (get_user(datap, (u8 __user * __user *)&umsgs[i].buf) ||
57183 + put_user(compat_ptr(datap), (u8 __user * __user *)&tmsgs[i].buf))
57184 return -EFAULT;
57185 }
57186 return sys_ioctl(fd, cmd, (unsigned long)tdata);
57187 @@ -796,7 +796,7 @@ static int compat_ioctl_preallocate(struct file *file,
57188 copy_in_user(&p->l_len, &p32->l_len, sizeof(s64)) ||
57189 copy_in_user(&p->l_sysid, &p32->l_sysid, sizeof(s32)) ||
57190 copy_in_user(&p->l_pid, &p32->l_pid, sizeof(u32)) ||
57191 - copy_in_user(&p->l_pad, &p32->l_pad, 4*sizeof(u32)))
57192 + copy_in_user(p->l_pad, p32->l_pad, 4*sizeof(u32)))
57193 return -EFAULT;
57194
57195 return ioctl_preallocate(file, p);
57196 @@ -1616,8 +1616,8 @@ asmlinkage long compat_sys_ioctl(unsigned int fd, unsigned int cmd,
57197 static int __init init_sys32_ioctl_cmp(const void *p, const void *q)
57198 {
57199 unsigned int a, b;
57200 - a = *(unsigned int *)p;
57201 - b = *(unsigned int *)q;
57202 + a = *(const unsigned int *)p;
57203 + b = *(const unsigned int *)q;
57204 if (a > b)
57205 return 1;
57206 if (a < b)
57207 diff --git a/fs/configfs/dir.c b/fs/configfs/dir.c
57208 index e081acb..911df21 100644
57209 --- a/fs/configfs/dir.c
57210 +++ b/fs/configfs/dir.c
57211 @@ -1548,7 +1548,8 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
57212 }
57213 for (p = q->next; p != &parent_sd->s_children; p = p->next) {
57214 struct configfs_dirent *next;
57215 - const char *name;
57216 + const unsigned char * name;
57217 + char d_name[sizeof(next->s_dentry->d_iname)];
57218 int len;
57219 struct inode *inode = NULL;
57220
57221 @@ -1557,7 +1558,12 @@ static int configfs_readdir(struct file *file, struct dir_context *ctx)
57222 continue;
57223
57224 name = configfs_get_name(next);
57225 - len = strlen(name);
57226 + if (next->s_dentry && name == next->s_dentry->d_iname) {
57227 + len = next->s_dentry->d_name.len;
57228 + memcpy(d_name, name, len);
57229 + name = d_name;
57230 + } else
57231 + len = strlen(name);
57232
57233 /*
57234 * We'll have a dentry and an inode for
57235 diff --git a/fs/coredump.c b/fs/coredump.c
57236 index bc3fbcd..6031650 100644
57237 --- a/fs/coredump.c
57238 +++ b/fs/coredump.c
57239 @@ -438,8 +438,8 @@ static void wait_for_dump_helpers(struct file *file)
57240 struct pipe_inode_info *pipe = file->private_data;
57241
57242 pipe_lock(pipe);
57243 - pipe->readers++;
57244 - pipe->writers--;
57245 + atomic_inc(&pipe->readers);
57246 + atomic_dec(&pipe->writers);
57247 wake_up_interruptible_sync(&pipe->wait);
57248 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
57249 pipe_unlock(pipe);
57250 @@ -448,11 +448,11 @@ static void wait_for_dump_helpers(struct file *file)
57251 * We actually want wait_event_freezable() but then we need
57252 * to clear TIF_SIGPENDING and improve dump_interrupted().
57253 */
57254 - wait_event_interruptible(pipe->wait, pipe->readers == 1);
57255 + wait_event_interruptible(pipe->wait, atomic_read(&pipe->readers) == 1);
57256
57257 pipe_lock(pipe);
57258 - pipe->readers--;
57259 - pipe->writers++;
57260 + atomic_dec(&pipe->readers);
57261 + atomic_inc(&pipe->writers);
57262 pipe_unlock(pipe);
57263 }
57264
57265 @@ -499,7 +499,9 @@ void do_coredump(const siginfo_t *siginfo)
57266 struct files_struct *displaced;
57267 bool need_nonrelative = false;
57268 bool core_dumped = false;
57269 - static atomic_t core_dump_count = ATOMIC_INIT(0);
57270 + static atomic_unchecked_t core_dump_count = ATOMIC_INIT(0);
57271 + long signr = siginfo->si_signo;
57272 + int dumpable;
57273 struct coredump_params cprm = {
57274 .siginfo = siginfo,
57275 .regs = signal_pt_regs(),
57276 @@ -512,12 +514,17 @@ void do_coredump(const siginfo_t *siginfo)
57277 .mm_flags = mm->flags,
57278 };
57279
57280 - audit_core_dumps(siginfo->si_signo);
57281 + audit_core_dumps(signr);
57282 +
57283 + dumpable = __get_dumpable(cprm.mm_flags);
57284 +
57285 + if (signr == SIGSEGV || signr == SIGBUS || signr == SIGKILL || signr == SIGILL)
57286 + gr_handle_brute_attach(dumpable);
57287
57288 binfmt = mm->binfmt;
57289 if (!binfmt || !binfmt->core_dump)
57290 goto fail;
57291 - if (!__get_dumpable(cprm.mm_flags))
57292 + if (!dumpable)
57293 goto fail;
57294
57295 cred = prepare_creds();
57296 @@ -536,7 +543,7 @@ void do_coredump(const siginfo_t *siginfo)
57297 need_nonrelative = true;
57298 }
57299
57300 - retval = coredump_wait(siginfo->si_signo, &core_state);
57301 + retval = coredump_wait(signr, &core_state);
57302 if (retval < 0)
57303 goto fail_creds;
57304
57305 @@ -579,7 +586,7 @@ void do_coredump(const siginfo_t *siginfo)
57306 }
57307 cprm.limit = RLIM_INFINITY;
57308
57309 - dump_count = atomic_inc_return(&core_dump_count);
57310 + dump_count = atomic_inc_return_unchecked(&core_dump_count);
57311 if (core_pipe_limit && (core_pipe_limit < dump_count)) {
57312 printk(KERN_WARNING "Pid %d(%s) over core_pipe_limit\n",
57313 task_tgid_vnr(current), current->comm);
57314 @@ -611,6 +618,8 @@ void do_coredump(const siginfo_t *siginfo)
57315 } else {
57316 struct inode *inode;
57317
57318 + gr_learn_resource(current, RLIMIT_CORE, binfmt->min_coredump, 1);
57319 +
57320 if (cprm.limit < binfmt->min_coredump)
57321 goto fail_unlock;
57322
57323 @@ -669,7 +678,7 @@ close_fail:
57324 filp_close(cprm.file, NULL);
57325 fail_dropcount:
57326 if (ispipe)
57327 - atomic_dec(&core_dump_count);
57328 + atomic_dec_unchecked(&core_dump_count);
57329 fail_unlock:
57330 kfree(cn.corename);
57331 coredump_finish(mm, core_dumped);
57332 @@ -690,6 +699,8 @@ int dump_emit(struct coredump_params *cprm, const void *addr, int nr)
57333 struct file *file = cprm->file;
57334 loff_t pos = file->f_pos;
57335 ssize_t n;
57336 +
57337 + gr_learn_resource(current, RLIMIT_CORE, cprm->written + nr, 1);
57338 if (cprm->written + nr > cprm->limit)
57339 return 0;
57340 while (nr) {
57341 diff --git a/fs/dcache.c b/fs/dcache.c
57342 index fdbe230..ba17c1f 100644
57343 --- a/fs/dcache.c
57344 +++ b/fs/dcache.c
57345 @@ -1495,7 +1495,7 @@ struct dentry *__d_alloc(struct super_block *sb, const struct qstr *name)
57346 */
57347 dentry->d_iname[DNAME_INLINE_LEN-1] = 0;
57348 if (name->len > DNAME_INLINE_LEN-1) {
57349 - dname = kmalloc(name->len + 1, GFP_KERNEL);
57350 + dname = kmalloc(round_up(name->len + 1, sizeof(unsigned long)), GFP_KERNEL);
57351 if (!dname) {
57352 kmem_cache_free(dentry_cache, dentry);
57353 return NULL;
57354 @@ -3428,7 +3428,8 @@ void __init vfs_caches_init(unsigned long mempages)
57355 mempages -= reserve;
57356
57357 names_cachep = kmem_cache_create("names_cache", PATH_MAX, 0,
57358 - SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
57359 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_USERCOPY|
57360 + SLAB_NO_SANITIZE, NULL);
57361
57362 dcache_init();
57363 inode_init();
57364 diff --git a/fs/debugfs/inode.c b/fs/debugfs/inode.c
57365 index 9c0444c..628490c 100644
57366 --- a/fs/debugfs/inode.c
57367 +++ b/fs/debugfs/inode.c
57368 @@ -415,7 +415,11 @@ EXPORT_SYMBOL_GPL(debugfs_create_file);
57369 */
57370 struct dentry *debugfs_create_dir(const char *name, struct dentry *parent)
57371 {
57372 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
57373 + return __create_file(name, S_IFDIR | S_IRWXU,
57374 +#else
57375 return __create_file(name, S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO,
57376 +#endif
57377 parent, NULL, NULL);
57378 }
57379 EXPORT_SYMBOL_GPL(debugfs_create_dir);
57380 diff --git a/fs/ecryptfs/inode.c b/fs/ecryptfs/inode.c
57381 index c36c448..fc96710 100644
57382 --- a/fs/ecryptfs/inode.c
57383 +++ b/fs/ecryptfs/inode.c
57384 @@ -675,7 +675,7 @@ static int ecryptfs_readlink_lower(struct dentry *dentry, char **buf,
57385 old_fs = get_fs();
57386 set_fs(get_ds());
57387 rc = lower_dentry->d_inode->i_op->readlink(lower_dentry,
57388 - (char __user *)lower_buf,
57389 + (char __force_user *)lower_buf,
57390 PATH_MAX);
57391 set_fs(old_fs);
57392 if (rc < 0)
57393 diff --git a/fs/ecryptfs/miscdev.c b/fs/ecryptfs/miscdev.c
57394 index e4141f2..d8263e8 100644
57395 --- a/fs/ecryptfs/miscdev.c
57396 +++ b/fs/ecryptfs/miscdev.c
57397 @@ -304,7 +304,7 @@ check_list:
57398 goto out_unlock_msg_ctx;
57399 i = PKT_TYPE_SIZE + PKT_CTR_SIZE;
57400 if (msg_ctx->msg) {
57401 - if (copy_to_user(&buf[i], packet_length, packet_length_size))
57402 + if (packet_length_size > sizeof(packet_length) || copy_to_user(&buf[i], packet_length, packet_length_size))
57403 goto out_unlock_msg_ctx;
57404 i += packet_length_size;
57405 if (copy_to_user(&buf[i], msg_ctx->msg, msg_ctx->msg_size))
57406 diff --git a/fs/exec.c b/fs/exec.c
57407 index 7ea097f..0158d8a 100644
57408 --- a/fs/exec.c
57409 +++ b/fs/exec.c
57410 @@ -55,8 +55,20 @@
57411 #include <linux/pipe_fs_i.h>
57412 #include <linux/oom.h>
57413 #include <linux/compat.h>
57414 +#include <linux/random.h>
57415 +#include <linux/seq_file.h>
57416 +#include <linux/coredump.h>
57417 +#include <linux/mman.h>
57418 +
57419 +#ifdef CONFIG_PAX_REFCOUNT
57420 +#include <linux/kallsyms.h>
57421 +#include <linux/kdebug.h>
57422 +#endif
57423 +
57424 +#include <trace/events/fs.h>
57425
57426 #include <asm/uaccess.h>
57427 +#include <asm/sections.h>
57428 #include <asm/mmu_context.h>
57429 #include <asm/tlb.h>
57430
57431 @@ -66,19 +78,34 @@
57432
57433 #include <trace/events/sched.h>
57434
57435 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
57436 +void __weak pax_set_initial_flags(struct linux_binprm *bprm)
57437 +{
57438 + 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");
57439 +}
57440 +#endif
57441 +
57442 +#ifdef CONFIG_PAX_HOOK_ACL_FLAGS
57443 +void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
57444 +EXPORT_SYMBOL(pax_set_initial_flags_func);
57445 +#endif
57446 +
57447 int suid_dumpable = 0;
57448
57449 static LIST_HEAD(formats);
57450 static DEFINE_RWLOCK(binfmt_lock);
57451
57452 +extern int gr_process_kernel_exec_ban(void);
57453 +extern int gr_process_suid_exec_ban(const struct linux_binprm *bprm);
57454 +
57455 void __register_binfmt(struct linux_binfmt * fmt, int insert)
57456 {
57457 BUG_ON(!fmt);
57458 if (WARN_ON(!fmt->load_binary))
57459 return;
57460 write_lock(&binfmt_lock);
57461 - insert ? list_add(&fmt->lh, &formats) :
57462 - list_add_tail(&fmt->lh, &formats);
57463 + insert ? pax_list_add((struct list_head *)&fmt->lh, &formats) :
57464 + pax_list_add_tail((struct list_head *)&fmt->lh, &formats);
57465 write_unlock(&binfmt_lock);
57466 }
57467
57468 @@ -87,7 +114,7 @@ EXPORT_SYMBOL(__register_binfmt);
57469 void unregister_binfmt(struct linux_binfmt * fmt)
57470 {
57471 write_lock(&binfmt_lock);
57472 - list_del(&fmt->lh);
57473 + pax_list_del((struct list_head *)&fmt->lh);
57474 write_unlock(&binfmt_lock);
57475 }
57476
57477 @@ -181,18 +208,10 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
57478 int write)
57479 {
57480 struct page *page;
57481 - int ret;
57482
57483 -#ifdef CONFIG_STACK_GROWSUP
57484 - if (write) {
57485 - ret = expand_downwards(bprm->vma, pos);
57486 - if (ret < 0)
57487 - return NULL;
57488 - }
57489 -#endif
57490 - ret = get_user_pages(current, bprm->mm, pos,
57491 - 1, write, 1, &page, NULL);
57492 - if (ret <= 0)
57493 + if (0 > expand_downwards(bprm->vma, pos))
57494 + return NULL;
57495 + if (0 >= get_user_pages(current, bprm->mm, pos, 1, write, 1, &page, NULL))
57496 return NULL;
57497
57498 if (write) {
57499 @@ -208,6 +227,17 @@ static struct page *get_arg_page(struct linux_binprm *bprm, unsigned long pos,
57500 if (size <= ARG_MAX)
57501 return page;
57502
57503 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57504 + // only allow 512KB for argv+env on suid/sgid binaries
57505 + // to prevent easy ASLR exhaustion
57506 + if (((!uid_eq(bprm->cred->euid, current_euid())) ||
57507 + (!gid_eq(bprm->cred->egid, current_egid()))) &&
57508 + (size > (512 * 1024))) {
57509 + put_page(page);
57510 + return NULL;
57511 + }
57512 +#endif
57513 +
57514 /*
57515 * Limit to 1/4-th the stack size for the argv+env strings.
57516 * This ensures that:
57517 @@ -267,6 +297,11 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
57518 vma->vm_end = STACK_TOP_MAX;
57519 vma->vm_start = vma->vm_end - PAGE_SIZE;
57520 vma->vm_flags = VM_SOFTDIRTY | VM_STACK_FLAGS | VM_STACK_INCOMPLETE_SETUP;
57521 +
57522 +#ifdef CONFIG_PAX_SEGMEXEC
57523 + vma->vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
57524 +#endif
57525 +
57526 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
57527 INIT_LIST_HEAD(&vma->anon_vma_chain);
57528
57529 @@ -277,6 +312,12 @@ static int __bprm_mm_init(struct linux_binprm *bprm)
57530 mm->stack_vm = mm->total_vm = 1;
57531 up_write(&mm->mmap_sem);
57532 bprm->p = vma->vm_end - sizeof(void *);
57533 +
57534 +#ifdef CONFIG_PAX_RANDUSTACK
57535 + if (randomize_va_space)
57536 + bprm->p ^= prandom_u32() & ~PAGE_MASK;
57537 +#endif
57538 +
57539 return 0;
57540 err:
57541 up_write(&mm->mmap_sem);
57542 @@ -397,7 +438,7 @@ struct user_arg_ptr {
57543 } ptr;
57544 };
57545
57546 -static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
57547 +const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
57548 {
57549 const char __user *native;
57550
57551 @@ -406,14 +447,14 @@ static const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr)
57552 compat_uptr_t compat;
57553
57554 if (get_user(compat, argv.ptr.compat + nr))
57555 - return ERR_PTR(-EFAULT);
57556 + return (const char __force_user *)ERR_PTR(-EFAULT);
57557
57558 return compat_ptr(compat);
57559 }
57560 #endif
57561
57562 if (get_user(native, argv.ptr.native + nr))
57563 - return ERR_PTR(-EFAULT);
57564 + return (const char __force_user *)ERR_PTR(-EFAULT);
57565
57566 return native;
57567 }
57568 @@ -432,7 +473,7 @@ static int count(struct user_arg_ptr argv, int max)
57569 if (!p)
57570 break;
57571
57572 - if (IS_ERR(p))
57573 + if (IS_ERR((const char __force_kernel *)p))
57574 return -EFAULT;
57575
57576 if (i >= max)
57577 @@ -467,7 +508,7 @@ static int copy_strings(int argc, struct user_arg_ptr argv,
57578
57579 ret = -EFAULT;
57580 str = get_user_arg_ptr(argv, argc);
57581 - if (IS_ERR(str))
57582 + if (IS_ERR((const char __force_kernel *)str))
57583 goto out;
57584
57585 len = strnlen_user(str, MAX_ARG_STRLEN);
57586 @@ -549,7 +590,7 @@ int copy_strings_kernel(int argc, const char *const *__argv,
57587 int r;
57588 mm_segment_t oldfs = get_fs();
57589 struct user_arg_ptr argv = {
57590 - .ptr.native = (const char __user *const __user *)__argv,
57591 + .ptr.native = (const char __user * const __force_user *)__argv,
57592 };
57593
57594 set_fs(KERNEL_DS);
57595 @@ -584,7 +625,8 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
57596 unsigned long new_end = old_end - shift;
57597 struct mmu_gather tlb;
57598
57599 - BUG_ON(new_start > new_end);
57600 + if (new_start >= new_end || new_start < mmap_min_addr)
57601 + return -ENOMEM;
57602
57603 /*
57604 * ensure there are no vmas between where we want to go
57605 @@ -593,6 +635,10 @@ static int shift_arg_pages(struct vm_area_struct *vma, unsigned long shift)
57606 if (vma != find_vma(mm, new_start))
57607 return -EFAULT;
57608
57609 +#ifdef CONFIG_PAX_SEGMEXEC
57610 + BUG_ON(pax_find_mirror_vma(vma));
57611 +#endif
57612 +
57613 /*
57614 * cover the whole range: [new_start, old_end)
57615 */
57616 @@ -673,10 +719,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
57617 stack_top = arch_align_stack(stack_top);
57618 stack_top = PAGE_ALIGN(stack_top);
57619
57620 - if (unlikely(stack_top < mmap_min_addr) ||
57621 - unlikely(vma->vm_end - vma->vm_start >= stack_top - mmap_min_addr))
57622 - return -ENOMEM;
57623 -
57624 stack_shift = vma->vm_end - stack_top;
57625
57626 bprm->p -= stack_shift;
57627 @@ -688,8 +730,28 @@ int setup_arg_pages(struct linux_binprm *bprm,
57628 bprm->exec -= stack_shift;
57629
57630 down_write(&mm->mmap_sem);
57631 +
57632 + /* Move stack pages down in memory. */
57633 + if (stack_shift) {
57634 + ret = shift_arg_pages(vma, stack_shift);
57635 + if (ret)
57636 + goto out_unlock;
57637 + }
57638 +
57639 vm_flags = VM_STACK_FLAGS;
57640
57641 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
57642 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
57643 + vm_flags &= ~VM_EXEC;
57644 +
57645 +#ifdef CONFIG_PAX_MPROTECT
57646 + if (mm->pax_flags & MF_PAX_MPROTECT)
57647 + vm_flags &= ~VM_MAYEXEC;
57648 +#endif
57649 +
57650 + }
57651 +#endif
57652 +
57653 /*
57654 * Adjust stack execute permissions; explicitly enable for
57655 * EXSTACK_ENABLE_X, disable for EXSTACK_DISABLE_X and leave alone
57656 @@ -708,13 +770,6 @@ int setup_arg_pages(struct linux_binprm *bprm,
57657 goto out_unlock;
57658 BUG_ON(prev != vma);
57659
57660 - /* Move stack pages down in memory. */
57661 - if (stack_shift) {
57662 - ret = shift_arg_pages(vma, stack_shift);
57663 - if (ret)
57664 - goto out_unlock;
57665 - }
57666 -
57667 /* mprotect_fixup is overkill to remove the temporary stack flags */
57668 vma->vm_flags &= ~VM_STACK_INCOMPLETE_SETUP;
57669
57670 @@ -738,6 +793,27 @@ int setup_arg_pages(struct linux_binprm *bprm,
57671 #endif
57672 current->mm->start_stack = bprm->p;
57673 ret = expand_stack(vma, stack_base);
57674 +
57675 +#if !defined(CONFIG_STACK_GROWSUP) && defined(CONFIG_PAX_RANDMMAP)
57676 + if (!ret && (mm->pax_flags & MF_PAX_RANDMMAP) && STACK_TOP <= 0xFFFFFFFFU && STACK_TOP > vma->vm_end) {
57677 + unsigned long size;
57678 + vm_flags_t vm_flags;
57679 +
57680 + size = STACK_TOP - vma->vm_end;
57681 + vm_flags = VM_NONE | VM_DONTEXPAND | VM_DONTDUMP;
57682 +
57683 + ret = vma->vm_end != mmap_region(NULL, vma->vm_end, size, vm_flags, 0);
57684 +
57685 +#ifdef CONFIG_X86
57686 + if (!ret) {
57687 + size = PAGE_SIZE + mmap_min_addr + ((mm->delta_mmap ^ mm->delta_stack) & (0xFFUL << PAGE_SHIFT));
57688 + ret = 0 != mmap_region(NULL, 0, PAGE_ALIGN(size), vm_flags, 0);
57689 + }
57690 +#endif
57691 +
57692 + }
57693 +#endif
57694 +
57695 if (ret)
57696 ret = -EFAULT;
57697
57698 @@ -774,6 +850,8 @@ struct file *open_exec(const char *name)
57699
57700 fsnotify_open(file);
57701
57702 + trace_open_exec(name);
57703 +
57704 err = deny_write_access(file);
57705 if (err)
57706 goto exit;
57707 @@ -797,7 +875,7 @@ int kernel_read(struct file *file, loff_t offset,
57708 old_fs = get_fs();
57709 set_fs(get_ds());
57710 /* The cast to a user pointer is valid due to the set_fs() */
57711 - result = vfs_read(file, (void __user *)addr, count, &pos);
57712 + result = vfs_read(file, (void __force_user *)addr, count, &pos);
57713 set_fs(old_fs);
57714 return result;
57715 }
57716 @@ -1253,7 +1331,7 @@ static int check_unsafe_exec(struct linux_binprm *bprm)
57717 }
57718 rcu_read_unlock();
57719
57720 - if (p->fs->users > n_fs) {
57721 + if (atomic_read(&p->fs->users) > n_fs) {
57722 bprm->unsafe |= LSM_UNSAFE_SHARE;
57723 } else {
57724 res = -EAGAIN;
57725 @@ -1443,6 +1521,31 @@ static int exec_binprm(struct linux_binprm *bprm)
57726 return ret;
57727 }
57728
57729 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57730 +static DEFINE_PER_CPU(u64, exec_counter);
57731 +static int __init init_exec_counters(void)
57732 +{
57733 + unsigned int cpu;
57734 +
57735 + for_each_possible_cpu(cpu) {
57736 + per_cpu(exec_counter, cpu) = (u64)cpu;
57737 + }
57738 +
57739 + return 0;
57740 +}
57741 +early_initcall(init_exec_counters);
57742 +static inline void increment_exec_counter(void)
57743 +{
57744 + BUILD_BUG_ON(NR_CPUS > (1 << 16));
57745 + current->exec_id = this_cpu_add_return(exec_counter, 1 << 16);
57746 +}
57747 +#else
57748 +static inline void increment_exec_counter(void) {}
57749 +#endif
57750 +
57751 +extern void gr_handle_exec_args(struct linux_binprm *bprm,
57752 + struct user_arg_ptr argv);
57753 +
57754 /*
57755 * sys_execve() executes a new program.
57756 */
57757 @@ -1450,12 +1553,19 @@ static int do_execve_common(const char *filename,
57758 struct user_arg_ptr argv,
57759 struct user_arg_ptr envp)
57760 {
57761 +#ifdef CONFIG_GRKERNSEC
57762 + struct file *old_exec_file;
57763 + struct acl_subject_label *old_acl;
57764 + struct rlimit old_rlim[RLIM_NLIMITS];
57765 +#endif
57766 struct linux_binprm *bprm;
57767 struct file *file;
57768 struct files_struct *displaced;
57769 bool clear_in_exec;
57770 int retval;
57771
57772 + gr_learn_resource(current, RLIMIT_NPROC, atomic_read(&current_user()->processes), 1);
57773 +
57774 /*
57775 * We move the actual failure in case of RLIMIT_NPROC excess from
57776 * set*uid() to execve() because too many poorly written programs
57777 @@ -1496,12 +1606,22 @@ static int do_execve_common(const char *filename,
57778 if (IS_ERR(file))
57779 goto out_unmark;
57780
57781 + if (gr_ptrace_readexec(file, bprm->unsafe)) {
57782 + retval = -EPERM;
57783 + goto out_file;
57784 + }
57785 +
57786 sched_exec();
57787
57788 bprm->file = file;
57789 bprm->filename = filename;
57790 bprm->interp = filename;
57791
57792 + if (!gr_acl_handle_execve(file->f_path.dentry, file->f_path.mnt)) {
57793 + retval = -EACCES;
57794 + goto out_file;
57795 + }
57796 +
57797 retval = bprm_mm_init(bprm);
57798 if (retval)
57799 goto out_file;
57800 @@ -1518,24 +1638,70 @@ static int do_execve_common(const char *filename,
57801 if (retval < 0)
57802 goto out;
57803
57804 +#ifdef CONFIG_GRKERNSEC
57805 + old_acl = current->acl;
57806 + memcpy(old_rlim, current->signal->rlim, sizeof(old_rlim));
57807 + old_exec_file = current->exec_file;
57808 + get_file(file);
57809 + current->exec_file = file;
57810 +#endif
57811 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
57812 + /* limit suid stack to 8MB
57813 + * we saved the old limits above and will restore them if this exec fails
57814 + */
57815 + if (((!uid_eq(bprm->cred->euid, current_euid())) || (!gid_eq(bprm->cred->egid, current_egid()))) &&
57816 + (old_rlim[RLIMIT_STACK].rlim_cur > (8 * 1024 * 1024)))
57817 + current->signal->rlim[RLIMIT_STACK].rlim_cur = 8 * 1024 * 1024;
57818 +#endif
57819 +
57820 + if (gr_process_kernel_exec_ban() || gr_process_suid_exec_ban(bprm)) {
57821 + retval = -EPERM;
57822 + goto out_fail;
57823 + }
57824 +
57825 + if (!gr_tpe_allow(file)) {
57826 + retval = -EACCES;
57827 + goto out_fail;
57828 + }
57829 +
57830 + if (gr_check_crash_exec(file)) {
57831 + retval = -EACCES;
57832 + goto out_fail;
57833 + }
57834 +
57835 + retval = gr_set_proc_label(file->f_path.dentry, file->f_path.mnt,
57836 + bprm->unsafe);
57837 + if (retval < 0)
57838 + goto out_fail;
57839 +
57840 retval = copy_strings_kernel(1, &bprm->filename, bprm);
57841 if (retval < 0)
57842 - goto out;
57843 + goto out_fail;
57844
57845 bprm->exec = bprm->p;
57846 retval = copy_strings(bprm->envc, envp, bprm);
57847 if (retval < 0)
57848 - goto out;
57849 + goto out_fail;
57850
57851 retval = copy_strings(bprm->argc, argv, bprm);
57852 if (retval < 0)
57853 - goto out;
57854 + goto out_fail;
57855 +
57856 + gr_log_chroot_exec(file->f_path.dentry, file->f_path.mnt);
57857 +
57858 + gr_handle_exec_args(bprm, argv);
57859
57860 retval = exec_binprm(bprm);
57861 if (retval < 0)
57862 - goto out;
57863 + goto out_fail;
57864 +#ifdef CONFIG_GRKERNSEC
57865 + if (old_exec_file)
57866 + fput(old_exec_file);
57867 +#endif
57868
57869 /* execve succeeded */
57870 +
57871 + increment_exec_counter();
57872 current->fs->in_exec = 0;
57873 current->in_execve = 0;
57874 acct_update_integrals(current);
57875 @@ -1545,6 +1711,14 @@ static int do_execve_common(const char *filename,
57876 put_files_struct(displaced);
57877 return retval;
57878
57879 +out_fail:
57880 +#ifdef CONFIG_GRKERNSEC
57881 + current->acl = old_acl;
57882 + memcpy(current->signal->rlim, old_rlim, sizeof(old_rlim));
57883 + fput(current->exec_file);
57884 + current->exec_file = old_exec_file;
57885 +#endif
57886 +
57887 out:
57888 if (bprm->mm) {
57889 acct_arg_size(bprm, 0);
57890 @@ -1699,3 +1873,295 @@ asmlinkage long compat_sys_execve(const char __user * filename,
57891 return error;
57892 }
57893 #endif
57894 +
57895 +int pax_check_flags(unsigned long *flags)
57896 +{
57897 + int retval = 0;
57898 +
57899 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_SEGMEXEC)
57900 + if (*flags & MF_PAX_SEGMEXEC)
57901 + {
57902 + *flags &= ~MF_PAX_SEGMEXEC;
57903 + retval = -EINVAL;
57904 + }
57905 +#endif
57906 +
57907 + if ((*flags & MF_PAX_PAGEEXEC)
57908 +
57909 +#ifdef CONFIG_PAX_PAGEEXEC
57910 + && (*flags & MF_PAX_SEGMEXEC)
57911 +#endif
57912 +
57913 + )
57914 + {
57915 + *flags &= ~MF_PAX_PAGEEXEC;
57916 + retval = -EINVAL;
57917 + }
57918 +
57919 + if ((*flags & MF_PAX_MPROTECT)
57920 +
57921 +#ifdef CONFIG_PAX_MPROTECT
57922 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
57923 +#endif
57924 +
57925 + )
57926 + {
57927 + *flags &= ~MF_PAX_MPROTECT;
57928 + retval = -EINVAL;
57929 + }
57930 +
57931 + if ((*flags & MF_PAX_EMUTRAMP)
57932 +
57933 +#ifdef CONFIG_PAX_EMUTRAMP
57934 + && !(*flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC))
57935 +#endif
57936 +
57937 + )
57938 + {
57939 + *flags &= ~MF_PAX_EMUTRAMP;
57940 + retval = -EINVAL;
57941 + }
57942 +
57943 + return retval;
57944 +}
57945 +
57946 +EXPORT_SYMBOL(pax_check_flags);
57947 +
57948 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
57949 +char *pax_get_path(const struct path *path, char *buf, int buflen)
57950 +{
57951 + char *pathname = d_path(path, buf, buflen);
57952 +
57953 + if (IS_ERR(pathname))
57954 + goto toolong;
57955 +
57956 + pathname = mangle_path(buf, pathname, "\t\n\\");
57957 + if (!pathname)
57958 + goto toolong;
57959 +
57960 + *pathname = 0;
57961 + return buf;
57962 +
57963 +toolong:
57964 + return "<path too long>";
57965 +}
57966 +EXPORT_SYMBOL(pax_get_path);
57967 +
57968 +void pax_report_fault(struct pt_regs *regs, void *pc, void *sp)
57969 +{
57970 + struct task_struct *tsk = current;
57971 + struct mm_struct *mm = current->mm;
57972 + char *buffer_exec = (char *)__get_free_page(GFP_KERNEL);
57973 + char *buffer_fault = (char *)__get_free_page(GFP_KERNEL);
57974 + char *path_exec = NULL;
57975 + char *path_fault = NULL;
57976 + unsigned long start = 0UL, end = 0UL, offset = 0UL;
57977 + siginfo_t info = { };
57978 +
57979 + if (buffer_exec && buffer_fault) {
57980 + struct vm_area_struct *vma, *vma_exec = NULL, *vma_fault = NULL;
57981 +
57982 + down_read(&mm->mmap_sem);
57983 + vma = mm->mmap;
57984 + while (vma && (!vma_exec || !vma_fault)) {
57985 + if (vma->vm_file && mm->exe_file == vma->vm_file && (vma->vm_flags & VM_EXEC))
57986 + vma_exec = vma;
57987 + if (vma->vm_start <= (unsigned long)pc && (unsigned long)pc < vma->vm_end)
57988 + vma_fault = vma;
57989 + vma = vma->vm_next;
57990 + }
57991 + if (vma_exec)
57992 + path_exec = pax_get_path(&vma_exec->vm_file->f_path, buffer_exec, PAGE_SIZE);
57993 + if (vma_fault) {
57994 + start = vma_fault->vm_start;
57995 + end = vma_fault->vm_end;
57996 + offset = vma_fault->vm_pgoff << PAGE_SHIFT;
57997 + if (vma_fault->vm_file)
57998 + path_fault = pax_get_path(&vma_fault->vm_file->f_path, buffer_fault, PAGE_SIZE);
57999 + else if ((unsigned long)pc >= mm->start_brk && (unsigned long)pc < mm->brk)
58000 + path_fault = "<heap>";
58001 + else if (vma_fault->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
58002 + path_fault = "<stack>";
58003 + else
58004 + path_fault = "<anonymous mapping>";
58005 + }
58006 + up_read(&mm->mmap_sem);
58007 + }
58008 + if (tsk->signal->curr_ip)
58009 + printk(KERN_ERR "PAX: From %pI4: execution attempt in: %s, %08lx-%08lx %08lx\n", &tsk->signal->curr_ip, path_fault, start, end, offset);
58010 + else
58011 + printk(KERN_ERR "PAX: execution attempt in: %s, %08lx-%08lx %08lx\n", path_fault, start, end, offset);
58012 + 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),
58013 + from_kuid_munged(&init_user_ns, task_uid(tsk)), from_kuid_munged(&init_user_ns, task_euid(tsk)), pc, sp);
58014 + free_page((unsigned long)buffer_exec);
58015 + free_page((unsigned long)buffer_fault);
58016 + pax_report_insns(regs, pc, sp);
58017 + info.si_signo = SIGKILL;
58018 + info.si_errno = 0;
58019 + info.si_code = SI_KERNEL;
58020 + info.si_pid = 0;
58021 + info.si_uid = 0;
58022 + do_coredump(&info);
58023 +}
58024 +#endif
58025 +
58026 +#ifdef CONFIG_PAX_REFCOUNT
58027 +void pax_report_refcount_overflow(struct pt_regs *regs)
58028 +{
58029 + if (current->signal->curr_ip)
58030 + printk(KERN_ERR "PAX: From %pI4: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n",
58031 + &current->signal->curr_ip, current->comm, task_pid_nr(current),
58032 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58033 + else
58034 + printk(KERN_ERR "PAX: refcount overflow detected in: %s:%d, uid/euid: %u/%u\n", current->comm, task_pid_nr(current),
58035 + from_kuid_munged(&init_user_ns, current_uid()), from_kuid_munged(&init_user_ns, current_euid()));
58036 + print_symbol(KERN_ERR "PAX: refcount overflow occured at: %s\n", instruction_pointer(regs));
58037 + preempt_disable();
58038 + show_regs(regs);
58039 + preempt_enable();
58040 + force_sig_info(SIGKILL, SEND_SIG_FORCED, current);
58041 +}
58042 +#endif
58043 +
58044 +#ifdef CONFIG_PAX_USERCOPY
58045 +/* 0: not at all, 1: fully, 2: fully inside frame, -1: partially (implies an error) */
58046 +static noinline int check_stack_object(const void *obj, unsigned long len)
58047 +{
58048 + const void * const stack = task_stack_page(current);
58049 + const void * const stackend = stack + THREAD_SIZE;
58050 +
58051 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58052 + const void *frame = NULL;
58053 + const void *oldframe;
58054 +#endif
58055 +
58056 + if (obj + len < obj)
58057 + return -1;
58058 +
58059 + if (obj + len <= stack || stackend <= obj)
58060 + return 0;
58061 +
58062 + if (obj < stack || stackend < obj + len)
58063 + return -1;
58064 +
58065 +#if defined(CONFIG_FRAME_POINTER) && defined(CONFIG_X86)
58066 + oldframe = __builtin_frame_address(1);
58067 + if (oldframe)
58068 + frame = __builtin_frame_address(2);
58069 + /*
58070 + low ----------------------------------------------> high
58071 + [saved bp][saved ip][args][local vars][saved bp][saved ip]
58072 + ^----------------^
58073 + allow copies only within here
58074 + */
58075 + while (stack <= frame && frame < stackend) {
58076 + /* if obj + len extends past the last frame, this
58077 + check won't pass and the next frame will be 0,
58078 + causing us to bail out and correctly report
58079 + the copy as invalid
58080 + */
58081 + if (obj + len <= frame)
58082 + return obj >= oldframe + 2 * sizeof(void *) ? 2 : -1;
58083 + oldframe = frame;
58084 + frame = *(const void * const *)frame;
58085 + }
58086 + return -1;
58087 +#else
58088 + return 1;
58089 +#endif
58090 +}
58091 +
58092 +static __noreturn void pax_report_usercopy(const void *ptr, unsigned long len, bool to_user, const char *type)
58093 +{
58094 + if (current->signal->curr_ip)
58095 + printk(KERN_ERR "PAX: From %pI4: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
58096 + &current->signal->curr_ip, to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
58097 + else
58098 + printk(KERN_ERR "PAX: kernel memory %s attempt detected %s %p (%s) (%lu bytes)\n",
58099 + to_user ? "leak" : "overwrite", to_user ? "from" : "to", ptr, type ? : "unknown", len);
58100 + dump_stack();
58101 + gr_handle_kernel_exploit();
58102 + do_group_exit(SIGKILL);
58103 +}
58104 +#endif
58105 +
58106 +#ifdef CONFIG_PAX_USERCOPY
58107 +static inline bool check_kernel_text_object(unsigned long low, unsigned long high)
58108 +{
58109 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
58110 + unsigned long textlow = ktla_ktva((unsigned long)_stext);
58111 +#ifdef CONFIG_MODULES
58112 + unsigned long texthigh = (unsigned long)MODULES_EXEC_VADDR;
58113 +#else
58114 + unsigned long texthigh = ktla_ktva((unsigned long)_etext);
58115 +#endif
58116 +
58117 +#else
58118 + unsigned long textlow = (unsigned long)_stext;
58119 + unsigned long texthigh = (unsigned long)_etext;
58120 +
58121 +#ifdef CONFIG_X86_64
58122 + /* check against linear mapping as well */
58123 + if (high > (unsigned long)__va(__pa(textlow)) &&
58124 + low <= (unsigned long)__va(__pa(texthigh)))
58125 + return true;
58126 +#endif
58127 +
58128 +#endif
58129 +
58130 + if (high <= textlow || low > texthigh)
58131 + return false;
58132 + else
58133 + return true;
58134 +}
58135 +#endif
58136 +
58137 +void __check_object_size(const void *ptr, unsigned long n, bool to_user)
58138 +{
58139 +
58140 +#ifdef CONFIG_PAX_USERCOPY
58141 + const char *type;
58142 +
58143 + if (!n)
58144 + return;
58145 +
58146 + type = check_heap_object(ptr, n);
58147 + if (!type) {
58148 + int ret = check_stack_object(ptr, n);
58149 + if (ret == 1 || ret == 2)
58150 + return;
58151 + if (ret == 0) {
58152 + if (check_kernel_text_object((unsigned long)ptr, (unsigned long)ptr + n))
58153 + type = "<kernel text>";
58154 + else
58155 + return;
58156 + } else
58157 + type = "<process stack>";
58158 + }
58159 +
58160 + pax_report_usercopy(ptr, n, to_user, type);
58161 +#endif
58162 +
58163 +}
58164 +EXPORT_SYMBOL(__check_object_size);
58165 +
58166 +#ifdef CONFIG_PAX_MEMORY_STACKLEAK
58167 +void pax_track_stack(void)
58168 +{
58169 + unsigned long sp = (unsigned long)&sp;
58170 + if (sp < current_thread_info()->lowest_stack &&
58171 + sp > (unsigned long)task_stack_page(current))
58172 + current_thread_info()->lowest_stack = sp;
58173 +}
58174 +EXPORT_SYMBOL(pax_track_stack);
58175 +#endif
58176 +
58177 +#ifdef CONFIG_PAX_SIZE_OVERFLOW
58178 +void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
58179 +{
58180 + printk(KERN_ERR "PAX: size overflow detected in function %s %s:%u %s", func, file, line, ssa_name);
58181 + dump_stack();
58182 + do_group_exit(SIGKILL);
58183 +}
58184 +EXPORT_SYMBOL(report_size_overflow);
58185 +#endif
58186 diff --git a/fs/ext2/balloc.c b/fs/ext2/balloc.c
58187 index 9f9992b..8b59411 100644
58188 --- a/fs/ext2/balloc.c
58189 +++ b/fs/ext2/balloc.c
58190 @@ -1184,10 +1184,10 @@ static int ext2_has_free_blocks(struct ext2_sb_info *sbi)
58191
58192 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
58193 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
58194 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
58195 + if (free_blocks < root_blocks + 1 &&
58196 !uid_eq(sbi->s_resuid, current_fsuid()) &&
58197 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
58198 - !in_group_p (sbi->s_resgid))) {
58199 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
58200 return 0;
58201 }
58202 return 1;
58203 diff --git a/fs/ext2/xattr.c b/fs/ext2/xattr.c
58204 index 2d7557d..14e38f94 100644
58205 --- a/fs/ext2/xattr.c
58206 +++ b/fs/ext2/xattr.c
58207 @@ -247,7 +247,7 @@ ext2_xattr_list(struct dentry *dentry, char *buffer, size_t buffer_size)
58208 struct buffer_head *bh = NULL;
58209 struct ext2_xattr_entry *entry;
58210 char *end;
58211 - size_t rest = buffer_size;
58212 + size_t rest = buffer_size, total_size = 0;
58213 int error;
58214
58215 ea_idebug(inode, "buffer=%p, buffer_size=%ld",
58216 @@ -305,9 +305,10 @@ bad_block: ext2_error(inode->i_sb, "ext2_xattr_list",
58217 buffer += size;
58218 }
58219 rest -= size;
58220 + total_size += size;
58221 }
58222 }
58223 - error = buffer_size - rest; /* total size */
58224 + error = total_size;
58225
58226 cleanup:
58227 brelse(bh);
58228 diff --git a/fs/ext3/balloc.c b/fs/ext3/balloc.c
58229 index 22548f5..41521d8 100644
58230 --- a/fs/ext3/balloc.c
58231 +++ b/fs/ext3/balloc.c
58232 @@ -1438,10 +1438,10 @@ static int ext3_has_free_blocks(struct ext3_sb_info *sbi, int use_reservation)
58233
58234 free_blocks = percpu_counter_read_positive(&sbi->s_freeblocks_counter);
58235 root_blocks = le32_to_cpu(sbi->s_es->s_r_blocks_count);
58236 - if (free_blocks < root_blocks + 1 && !capable(CAP_SYS_RESOURCE) &&
58237 + if (free_blocks < root_blocks + 1 &&
58238 !use_reservation && !uid_eq(sbi->s_resuid, current_fsuid()) &&
58239 (gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) ||
58240 - !in_group_p (sbi->s_resgid))) {
58241 + !in_group_p (sbi->s_resgid)) && !capable_nolog(CAP_SYS_RESOURCE)) {
58242 return 0;
58243 }
58244 return 1;
58245 diff --git a/fs/ext3/xattr.c b/fs/ext3/xattr.c
58246 index b1fc963..881228c 100644
58247 --- a/fs/ext3/xattr.c
58248 +++ b/fs/ext3/xattr.c
58249 @@ -330,7 +330,7 @@ static int
58250 ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
58251 char *buffer, size_t buffer_size)
58252 {
58253 - size_t rest = buffer_size;
58254 + size_t rest = buffer_size, total_size = 0;
58255
58256 for (; !IS_LAST_ENTRY(entry); entry = EXT3_XATTR_NEXT(entry)) {
58257 const struct xattr_handler *handler =
58258 @@ -347,9 +347,10 @@ ext3_xattr_list_entries(struct dentry *dentry, struct ext3_xattr_entry *entry,
58259 buffer += size;
58260 }
58261 rest -= size;
58262 + total_size += size;
58263 }
58264 }
58265 - return buffer_size - rest;
58266 + return total_size;
58267 }
58268
58269 static int
58270 diff --git a/fs/ext4/balloc.c b/fs/ext4/balloc.c
58271 index 6ea7b14..8fa16d9 100644
58272 --- a/fs/ext4/balloc.c
58273 +++ b/fs/ext4/balloc.c
58274 @@ -534,8 +534,8 @@ static int ext4_has_free_clusters(struct ext4_sb_info *sbi,
58275 /* Hm, nope. Are (enough) root reserved clusters available? */
58276 if (uid_eq(sbi->s_resuid, current_fsuid()) ||
58277 (!gid_eq(sbi->s_resgid, GLOBAL_ROOT_GID) && in_group_p(sbi->s_resgid)) ||
58278 - capable(CAP_SYS_RESOURCE) ||
58279 - (flags & EXT4_MB_USE_ROOT_BLOCKS)) {
58280 + (flags & EXT4_MB_USE_ROOT_BLOCKS) ||
58281 + capable_nolog(CAP_SYS_RESOURCE)) {
58282
58283 if (free_clusters >= (nclusters + dirty_clusters +
58284 resv_clusters))
58285 diff --git a/fs/ext4/ext4.h b/fs/ext4/ext4.h
58286 index ece5556..e39d3a8 100644
58287 --- a/fs/ext4/ext4.h
58288 +++ b/fs/ext4/ext4.h
58289 @@ -1267,19 +1267,19 @@ struct ext4_sb_info {
58290 unsigned long s_mb_last_start;
58291
58292 /* stats for buddy allocator */
58293 - atomic_t s_bal_reqs; /* number of reqs with len > 1 */
58294 - atomic_t s_bal_success; /* we found long enough chunks */
58295 - atomic_t s_bal_allocated; /* in blocks */
58296 - atomic_t s_bal_ex_scanned; /* total extents scanned */
58297 - atomic_t s_bal_goals; /* goal hits */
58298 - atomic_t s_bal_breaks; /* too long searches */
58299 - atomic_t s_bal_2orders; /* 2^order hits */
58300 + atomic_unchecked_t s_bal_reqs; /* number of reqs with len > 1 */
58301 + atomic_unchecked_t s_bal_success; /* we found long enough chunks */
58302 + atomic_unchecked_t s_bal_allocated; /* in blocks */
58303 + atomic_unchecked_t s_bal_ex_scanned; /* total extents scanned */
58304 + atomic_unchecked_t s_bal_goals; /* goal hits */
58305 + atomic_unchecked_t s_bal_breaks; /* too long searches */
58306 + atomic_unchecked_t s_bal_2orders; /* 2^order hits */
58307 spinlock_t s_bal_lock;
58308 unsigned long s_mb_buddies_generated;
58309 unsigned long long s_mb_generation_time;
58310 - atomic_t s_mb_lost_chunks;
58311 - atomic_t s_mb_preallocated;
58312 - atomic_t s_mb_discarded;
58313 + atomic_unchecked_t s_mb_lost_chunks;
58314 + atomic_unchecked_t s_mb_preallocated;
58315 + atomic_unchecked_t s_mb_discarded;
58316 atomic_t s_lock_busy;
58317
58318 /* locality groups */
58319 diff --git a/fs/ext4/mballoc.c b/fs/ext4/mballoc.c
58320 index 04a5c75..09894fa 100644
58321 --- a/fs/ext4/mballoc.c
58322 +++ b/fs/ext4/mballoc.c
58323 @@ -1880,7 +1880,7 @@ void ext4_mb_simple_scan_group(struct ext4_allocation_context *ac,
58324 BUG_ON(ac->ac_b_ex.fe_len != ac->ac_g_ex.fe_len);
58325
58326 if (EXT4_SB(sb)->s_mb_stats)
58327 - atomic_inc(&EXT4_SB(sb)->s_bal_2orders);
58328 + atomic_inc_unchecked(&EXT4_SB(sb)->s_bal_2orders);
58329
58330 break;
58331 }
58332 @@ -2189,7 +2189,7 @@ repeat:
58333 ac->ac_status = AC_STATUS_CONTINUE;
58334 ac->ac_flags |= EXT4_MB_HINT_FIRST;
58335 cr = 3;
58336 - atomic_inc(&sbi->s_mb_lost_chunks);
58337 + atomic_inc_unchecked(&sbi->s_mb_lost_chunks);
58338 goto repeat;
58339 }
58340 }
58341 @@ -2697,25 +2697,25 @@ int ext4_mb_release(struct super_block *sb)
58342 if (sbi->s_mb_stats) {
58343 ext4_msg(sb, KERN_INFO,
58344 "mballoc: %u blocks %u reqs (%u success)",
58345 - atomic_read(&sbi->s_bal_allocated),
58346 - atomic_read(&sbi->s_bal_reqs),
58347 - atomic_read(&sbi->s_bal_success));
58348 + atomic_read_unchecked(&sbi->s_bal_allocated),
58349 + atomic_read_unchecked(&sbi->s_bal_reqs),
58350 + atomic_read_unchecked(&sbi->s_bal_success));
58351 ext4_msg(sb, KERN_INFO,
58352 "mballoc: %u extents scanned, %u goal hits, "
58353 "%u 2^N hits, %u breaks, %u lost",
58354 - atomic_read(&sbi->s_bal_ex_scanned),
58355 - atomic_read(&sbi->s_bal_goals),
58356 - atomic_read(&sbi->s_bal_2orders),
58357 - atomic_read(&sbi->s_bal_breaks),
58358 - atomic_read(&sbi->s_mb_lost_chunks));
58359 + atomic_read_unchecked(&sbi->s_bal_ex_scanned),
58360 + atomic_read_unchecked(&sbi->s_bal_goals),
58361 + atomic_read_unchecked(&sbi->s_bal_2orders),
58362 + atomic_read_unchecked(&sbi->s_bal_breaks),
58363 + atomic_read_unchecked(&sbi->s_mb_lost_chunks));
58364 ext4_msg(sb, KERN_INFO,
58365 "mballoc: %lu generated and it took %Lu",
58366 sbi->s_mb_buddies_generated,
58367 sbi->s_mb_generation_time);
58368 ext4_msg(sb, KERN_INFO,
58369 "mballoc: %u preallocated, %u discarded",
58370 - atomic_read(&sbi->s_mb_preallocated),
58371 - atomic_read(&sbi->s_mb_discarded));
58372 + atomic_read_unchecked(&sbi->s_mb_preallocated),
58373 + atomic_read_unchecked(&sbi->s_mb_discarded));
58374 }
58375
58376 free_percpu(sbi->s_locality_groups);
58377 @@ -3169,16 +3169,16 @@ static void ext4_mb_collect_stats(struct ext4_allocation_context *ac)
58378 struct ext4_sb_info *sbi = EXT4_SB(ac->ac_sb);
58379
58380 if (sbi->s_mb_stats && ac->ac_g_ex.fe_len > 1) {
58381 - atomic_inc(&sbi->s_bal_reqs);
58382 - atomic_add(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
58383 + atomic_inc_unchecked(&sbi->s_bal_reqs);
58384 + atomic_add_unchecked(ac->ac_b_ex.fe_len, &sbi->s_bal_allocated);
58385 if (ac->ac_b_ex.fe_len >= ac->ac_o_ex.fe_len)
58386 - atomic_inc(&sbi->s_bal_success);
58387 - atomic_add(ac->ac_found, &sbi->s_bal_ex_scanned);
58388 + atomic_inc_unchecked(&sbi->s_bal_success);
58389 + atomic_add_unchecked(ac->ac_found, &sbi->s_bal_ex_scanned);
58390 if (ac->ac_g_ex.fe_start == ac->ac_b_ex.fe_start &&
58391 ac->ac_g_ex.fe_group == ac->ac_b_ex.fe_group)
58392 - atomic_inc(&sbi->s_bal_goals);
58393 + atomic_inc_unchecked(&sbi->s_bal_goals);
58394 if (ac->ac_found > sbi->s_mb_max_to_scan)
58395 - atomic_inc(&sbi->s_bal_breaks);
58396 + atomic_inc_unchecked(&sbi->s_bal_breaks);
58397 }
58398
58399 if (ac->ac_op == EXT4_MB_HISTORY_ALLOC)
58400 @@ -3583,7 +3583,7 @@ ext4_mb_new_inode_pa(struct ext4_allocation_context *ac)
58401 trace_ext4_mb_new_inode_pa(ac, pa);
58402
58403 ext4_mb_use_inode_pa(ac, pa);
58404 - atomic_add(pa->pa_free, &sbi->s_mb_preallocated);
58405 + atomic_add_unchecked(pa->pa_free, &sbi->s_mb_preallocated);
58406
58407 ei = EXT4_I(ac->ac_inode);
58408 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
58409 @@ -3643,7 +3643,7 @@ ext4_mb_new_group_pa(struct ext4_allocation_context *ac)
58410 trace_ext4_mb_new_group_pa(ac, pa);
58411
58412 ext4_mb_use_group_pa(ac, pa);
58413 - atomic_add(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
58414 + atomic_add_unchecked(pa->pa_free, &EXT4_SB(sb)->s_mb_preallocated);
58415
58416 grp = ext4_get_group_info(sb, ac->ac_b_ex.fe_group);
58417 lg = ac->ac_lg;
58418 @@ -3732,7 +3732,7 @@ ext4_mb_release_inode_pa(struct ext4_buddy *e4b, struct buffer_head *bitmap_bh,
58419 * from the bitmap and continue.
58420 */
58421 }
58422 - atomic_add(free, &sbi->s_mb_discarded);
58423 + atomic_add_unchecked(free, &sbi->s_mb_discarded);
58424
58425 return err;
58426 }
58427 @@ -3750,7 +3750,7 @@ ext4_mb_release_group_pa(struct ext4_buddy *e4b,
58428 ext4_get_group_no_and_offset(sb, pa->pa_pstart, &group, &bit);
58429 BUG_ON(group != e4b->bd_group && pa->pa_len != 0);
58430 mb_free_blocks(pa->pa_inode, e4b, bit, pa->pa_len);
58431 - atomic_add(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
58432 + atomic_add_unchecked(pa->pa_len, &EXT4_SB(sb)->s_mb_discarded);
58433 trace_ext4_mballoc_discard(sb, NULL, group, bit, pa->pa_len);
58434
58435 return 0;
58436 diff --git a/fs/ext4/mmp.c b/fs/ext4/mmp.c
58437 index 04434ad..6404663 100644
58438 --- a/fs/ext4/mmp.c
58439 +++ b/fs/ext4/mmp.c
58440 @@ -113,7 +113,7 @@ static int read_mmp_block(struct super_block *sb, struct buffer_head **bh,
58441 void __dump_mmp_msg(struct super_block *sb, struct mmp_struct *mmp,
58442 const char *function, unsigned int line, const char *msg)
58443 {
58444 - __ext4_warning(sb, function, line, msg);
58445 + __ext4_warning(sb, function, line, "%s", msg);
58446 __ext4_warning(sb, function, line,
58447 "MMP failure info: last update time: %llu, last update "
58448 "node: %s, last update device: %s\n",
58449 diff --git a/fs/ext4/super.c b/fs/ext4/super.c
58450 index 1f7784d..5d8bbad 100644
58451 --- a/fs/ext4/super.c
58452 +++ b/fs/ext4/super.c
58453 @@ -1270,7 +1270,7 @@ static ext4_fsblk_t get_sb_block(void **data)
58454 }
58455
58456 #define DEFAULT_JOURNAL_IOPRIO (IOPRIO_PRIO_VALUE(IOPRIO_CLASS_BE, 3))
58457 -static char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
58458 +static const char deprecated_msg[] = "Mount option \"%s\" will be removed by %s\n"
58459 "Contact linux-ext4@vger.kernel.org if you think we should keep it.\n";
58460
58461 #ifdef CONFIG_QUOTA
58462 @@ -2450,7 +2450,7 @@ struct ext4_attr {
58463 int offset;
58464 int deprecated_val;
58465 } u;
58466 -};
58467 +} __do_const;
58468
58469 static int parse_strtoull(const char *buf,
58470 unsigned long long max, unsigned long long *value)
58471 diff --git a/fs/ext4/xattr.c b/fs/ext4/xattr.c
58472 index 1423c48..9c0c6dc 100644
58473 --- a/fs/ext4/xattr.c
58474 +++ b/fs/ext4/xattr.c
58475 @@ -381,7 +381,7 @@ static int
58476 ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
58477 char *buffer, size_t buffer_size)
58478 {
58479 - size_t rest = buffer_size;
58480 + size_t rest = buffer_size, total_size = 0;
58481
58482 for (; !IS_LAST_ENTRY(entry); entry = EXT4_XATTR_NEXT(entry)) {
58483 const struct xattr_handler *handler =
58484 @@ -398,9 +398,10 @@ ext4_xattr_list_entries(struct dentry *dentry, struct ext4_xattr_entry *entry,
58485 buffer += size;
58486 }
58487 rest -= size;
58488 + total_size += size;
58489 }
58490 }
58491 - return buffer_size - rest;
58492 + return total_size;
58493 }
58494
58495 static int
58496 diff --git a/fs/fcntl.c b/fs/fcntl.c
58497 index ef68665..5deacdc 100644
58498 --- a/fs/fcntl.c
58499 +++ b/fs/fcntl.c
58500 @@ -106,6 +106,11 @@ int __f_setown(struct file *filp, struct pid *pid, enum pid_type type,
58501 if (err)
58502 return err;
58503
58504 + if (gr_handle_chroot_fowner(pid, type))
58505 + return -ENOENT;
58506 + if (gr_check_protected_task_fowner(pid, type))
58507 + return -EACCES;
58508 +
58509 f_modown(filp, pid, type, force);
58510 return 0;
58511 }
58512 diff --git a/fs/fhandle.c b/fs/fhandle.c
58513 index 999ff5c..41f4109 100644
58514 --- a/fs/fhandle.c
58515 +++ b/fs/fhandle.c
58516 @@ -67,8 +67,7 @@ static long do_sys_name_to_handle(struct path *path,
58517 } else
58518 retval = 0;
58519 /* copy the mount id */
58520 - if (copy_to_user(mnt_id, &real_mount(path->mnt)->mnt_id,
58521 - sizeof(*mnt_id)) ||
58522 + if (put_user(real_mount(path->mnt)->mnt_id, mnt_id) ||
58523 copy_to_user(ufh, handle,
58524 sizeof(struct file_handle) + handle_bytes))
58525 retval = -EFAULT;
58526 diff --git a/fs/file.c b/fs/file.c
58527 index 4a78f98..f9a6d25 100644
58528 --- a/fs/file.c
58529 +++ b/fs/file.c
58530 @@ -16,6 +16,7 @@
58531 #include <linux/slab.h>
58532 #include <linux/vmalloc.h>
58533 #include <linux/file.h>
58534 +#include <linux/security.h>
58535 #include <linux/fdtable.h>
58536 #include <linux/bitops.h>
58537 #include <linux/interrupt.h>
58538 @@ -141,7 +142,7 @@ out:
58539 * Return <0 error code on error; 1 on successful completion.
58540 * The files->file_lock should be held on entry, and will be held on exit.
58541 */
58542 -static int expand_fdtable(struct files_struct *files, int nr)
58543 +static int expand_fdtable(struct files_struct *files, unsigned int nr)
58544 __releases(files->file_lock)
58545 __acquires(files->file_lock)
58546 {
58547 @@ -186,7 +187,7 @@ static int expand_fdtable(struct files_struct *files, int nr)
58548 * expanded and execution may have blocked.
58549 * The files->file_lock should be held on entry, and will be held on exit.
58550 */
58551 -static int expand_files(struct files_struct *files, int nr)
58552 +static int expand_files(struct files_struct *files, unsigned int nr)
58553 {
58554 struct fdtable *fdt;
58555
58556 @@ -828,6 +829,7 @@ int replace_fd(unsigned fd, struct file *file, unsigned flags)
58557 if (!file)
58558 return __close_fd(files, fd);
58559
58560 + gr_learn_resource(current, RLIMIT_NOFILE, fd, 0);
58561 if (fd >= rlimit(RLIMIT_NOFILE))
58562 return -EBADF;
58563
58564 @@ -854,6 +856,7 @@ SYSCALL_DEFINE3(dup3, unsigned int, oldfd, unsigned int, newfd, int, flags)
58565 if (unlikely(oldfd == newfd))
58566 return -EINVAL;
58567
58568 + gr_learn_resource(current, RLIMIT_NOFILE, newfd, 0);
58569 if (newfd >= rlimit(RLIMIT_NOFILE))
58570 return -EBADF;
58571
58572 @@ -909,6 +912,7 @@ SYSCALL_DEFINE1(dup, unsigned int, fildes)
58573 int f_dupfd(unsigned int from, struct file *file, unsigned flags)
58574 {
58575 int err;
58576 + gr_learn_resource(current, RLIMIT_NOFILE, from, 0);
58577 if (from >= rlimit(RLIMIT_NOFILE))
58578 return -EINVAL;
58579 err = alloc_fd(from, flags);
58580 diff --git a/fs/filesystems.c b/fs/filesystems.c
58581 index 92567d9..fcd8cbf 100644
58582 --- a/fs/filesystems.c
58583 +++ b/fs/filesystems.c
58584 @@ -273,7 +273,11 @@ struct file_system_type *get_fs_type(const char *name)
58585 int len = dot ? dot - name : strlen(name);
58586
58587 fs = __get_fs_type(name, len);
58588 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
58589 + if (!fs && (___request_module(true, "grsec_modharden_fs", "fs-%.*s", len, name) == 0))
58590 +#else
58591 if (!fs && (request_module("fs-%.*s", len, name) == 0))
58592 +#endif
58593 fs = __get_fs_type(name, len);
58594
58595 if (dot && fs && !(fs->fs_flags & FS_HAS_SUBTYPE)) {
58596 diff --git a/fs/fs_struct.c b/fs/fs_struct.c
58597 index 7dca743..543d620 100644
58598 --- a/fs/fs_struct.c
58599 +++ b/fs/fs_struct.c
58600 @@ -4,6 +4,7 @@
58601 #include <linux/path.h>
58602 #include <linux/slab.h>
58603 #include <linux/fs_struct.h>
58604 +#include <linux/grsecurity.h>
58605 #include "internal.h"
58606
58607 /*
58608 @@ -19,6 +20,7 @@ void set_fs_root(struct fs_struct *fs, const struct path *path)
58609 write_seqcount_begin(&fs->seq);
58610 old_root = fs->root;
58611 fs->root = *path;
58612 + gr_set_chroot_entries(current, path);
58613 write_seqcount_end(&fs->seq);
58614 spin_unlock(&fs->lock);
58615 if (old_root.dentry)
58616 @@ -67,6 +69,10 @@ void chroot_fs_refs(const struct path *old_root, const struct path *new_root)
58617 int hits = 0;
58618 spin_lock(&fs->lock);
58619 write_seqcount_begin(&fs->seq);
58620 + /* this root replacement is only done by pivot_root,
58621 + leave grsec's chroot tagging alone for this task
58622 + so that a pivoted root isn't treated as a chroot
58623 + */
58624 hits += replace_path(&fs->root, old_root, new_root);
58625 hits += replace_path(&fs->pwd, old_root, new_root);
58626 write_seqcount_end(&fs->seq);
58627 @@ -99,7 +105,8 @@ void exit_fs(struct task_struct *tsk)
58628 task_lock(tsk);
58629 spin_lock(&fs->lock);
58630 tsk->fs = NULL;
58631 - kill = !--fs->users;
58632 + gr_clear_chroot_entries(tsk);
58633 + kill = !atomic_dec_return(&fs->users);
58634 spin_unlock(&fs->lock);
58635 task_unlock(tsk);
58636 if (kill)
58637 @@ -112,7 +119,7 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
58638 struct fs_struct *fs = kmem_cache_alloc(fs_cachep, GFP_KERNEL);
58639 /* We don't need to lock fs - think why ;-) */
58640 if (fs) {
58641 - fs->users = 1;
58642 + atomic_set(&fs->users, 1);
58643 fs->in_exec = 0;
58644 spin_lock_init(&fs->lock);
58645 seqcount_init(&fs->seq);
58646 @@ -121,6 +128,9 @@ struct fs_struct *copy_fs_struct(struct fs_struct *old)
58647 spin_lock(&old->lock);
58648 fs->root = old->root;
58649 path_get(&fs->root);
58650 + /* instead of calling gr_set_chroot_entries here,
58651 + we call it from every caller of this function
58652 + */
58653 fs->pwd = old->pwd;
58654 path_get(&fs->pwd);
58655 spin_unlock(&old->lock);
58656 @@ -139,8 +149,9 @@ int unshare_fs_struct(void)
58657
58658 task_lock(current);
58659 spin_lock(&fs->lock);
58660 - kill = !--fs->users;
58661 + kill = !atomic_dec_return(&fs->users);
58662 current->fs = new_fs;
58663 + gr_set_chroot_entries(current, &new_fs->root);
58664 spin_unlock(&fs->lock);
58665 task_unlock(current);
58666
58667 @@ -153,13 +164,13 @@ EXPORT_SYMBOL_GPL(unshare_fs_struct);
58668
58669 int current_umask(void)
58670 {
58671 - return current->fs->umask;
58672 + return current->fs->umask | gr_acl_umask();
58673 }
58674 EXPORT_SYMBOL(current_umask);
58675
58676 /* to be mentioned only in INIT_TASK */
58677 struct fs_struct init_fs = {
58678 - .users = 1,
58679 + .users = ATOMIC_INIT(1),
58680 .lock = __SPIN_LOCK_UNLOCKED(init_fs.lock),
58681 .seq = SEQCNT_ZERO(init_fs.seq),
58682 .umask = 0022,
58683 diff --git a/fs/fscache/cookie.c b/fs/fscache/cookie.c
58684 index 29d7feb..303644d 100644
58685 --- a/fs/fscache/cookie.c
58686 +++ b/fs/fscache/cookie.c
58687 @@ -19,7 +19,7 @@
58688
58689 struct kmem_cache *fscache_cookie_jar;
58690
58691 -static atomic_t fscache_object_debug_id = ATOMIC_INIT(0);
58692 +static atomic_unchecked_t fscache_object_debug_id = ATOMIC_INIT(0);
58693
58694 static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie);
58695 static int fscache_alloc_object(struct fscache_cache *cache,
58696 @@ -69,11 +69,11 @@ struct fscache_cookie *__fscache_acquire_cookie(
58697 parent ? (char *) parent->def->name : "<no-parent>",
58698 def->name, netfs_data, enable);
58699
58700 - fscache_stat(&fscache_n_acquires);
58701 + fscache_stat_unchecked(&fscache_n_acquires);
58702
58703 /* if there's no parent cookie, then we don't create one here either */
58704 if (!parent) {
58705 - fscache_stat(&fscache_n_acquires_null);
58706 + fscache_stat_unchecked(&fscache_n_acquires_null);
58707 _leave(" [no parent]");
58708 return NULL;
58709 }
58710 @@ -88,7 +88,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
58711 /* allocate and initialise a cookie */
58712 cookie = kmem_cache_alloc(fscache_cookie_jar, GFP_KERNEL);
58713 if (!cookie) {
58714 - fscache_stat(&fscache_n_acquires_oom);
58715 + fscache_stat_unchecked(&fscache_n_acquires_oom);
58716 _leave(" [ENOMEM]");
58717 return NULL;
58718 }
58719 @@ -115,13 +115,13 @@ struct fscache_cookie *__fscache_acquire_cookie(
58720
58721 switch (cookie->def->type) {
58722 case FSCACHE_COOKIE_TYPE_INDEX:
58723 - fscache_stat(&fscache_n_cookie_index);
58724 + fscache_stat_unchecked(&fscache_n_cookie_index);
58725 break;
58726 case FSCACHE_COOKIE_TYPE_DATAFILE:
58727 - fscache_stat(&fscache_n_cookie_data);
58728 + fscache_stat_unchecked(&fscache_n_cookie_data);
58729 break;
58730 default:
58731 - fscache_stat(&fscache_n_cookie_special);
58732 + fscache_stat_unchecked(&fscache_n_cookie_special);
58733 break;
58734 }
58735
58736 @@ -135,7 +135,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
58737 } else {
58738 atomic_dec(&parent->n_children);
58739 __fscache_cookie_put(cookie);
58740 - fscache_stat(&fscache_n_acquires_nobufs);
58741 + fscache_stat_unchecked(&fscache_n_acquires_nobufs);
58742 _leave(" = NULL");
58743 return NULL;
58744 }
58745 @@ -144,7 +144,7 @@ struct fscache_cookie *__fscache_acquire_cookie(
58746 }
58747 }
58748
58749 - fscache_stat(&fscache_n_acquires_ok);
58750 + fscache_stat_unchecked(&fscache_n_acquires_ok);
58751 _leave(" = %p", cookie);
58752 return cookie;
58753 }
58754 @@ -213,7 +213,7 @@ static int fscache_acquire_non_index_cookie(struct fscache_cookie *cookie)
58755 cache = fscache_select_cache_for_object(cookie->parent);
58756 if (!cache) {
58757 up_read(&fscache_addremove_sem);
58758 - fscache_stat(&fscache_n_acquires_no_cache);
58759 + fscache_stat_unchecked(&fscache_n_acquires_no_cache);
58760 _leave(" = -ENOMEDIUM [no cache]");
58761 return -ENOMEDIUM;
58762 }
58763 @@ -297,14 +297,14 @@ static int fscache_alloc_object(struct fscache_cache *cache,
58764 object = cache->ops->alloc_object(cache, cookie);
58765 fscache_stat_d(&fscache_n_cop_alloc_object);
58766 if (IS_ERR(object)) {
58767 - fscache_stat(&fscache_n_object_no_alloc);
58768 + fscache_stat_unchecked(&fscache_n_object_no_alloc);
58769 ret = PTR_ERR(object);
58770 goto error;
58771 }
58772
58773 - fscache_stat(&fscache_n_object_alloc);
58774 + fscache_stat_unchecked(&fscache_n_object_alloc);
58775
58776 - object->debug_id = atomic_inc_return(&fscache_object_debug_id);
58777 + object->debug_id = atomic_inc_return_unchecked(&fscache_object_debug_id);
58778
58779 _debug("ALLOC OBJ%x: %s {%lx}",
58780 object->debug_id, cookie->def->name, object->events);
58781 @@ -418,7 +418,7 @@ void __fscache_invalidate(struct fscache_cookie *cookie)
58782
58783 _enter("{%s}", cookie->def->name);
58784
58785 - fscache_stat(&fscache_n_invalidates);
58786 + fscache_stat_unchecked(&fscache_n_invalidates);
58787
58788 /* Only permit invalidation of data files. Invalidating an index will
58789 * require the caller to release all its attachments to the tree rooted
58790 @@ -477,10 +477,10 @@ void __fscache_update_cookie(struct fscache_cookie *cookie)
58791 {
58792 struct fscache_object *object;
58793
58794 - fscache_stat(&fscache_n_updates);
58795 + fscache_stat_unchecked(&fscache_n_updates);
58796
58797 if (!cookie) {
58798 - fscache_stat(&fscache_n_updates_null);
58799 + fscache_stat_unchecked(&fscache_n_updates_null);
58800 _leave(" [no cookie]");
58801 return;
58802 }
58803 @@ -581,12 +581,12 @@ EXPORT_SYMBOL(__fscache_disable_cookie);
58804 */
58805 void __fscache_relinquish_cookie(struct fscache_cookie *cookie, bool retire)
58806 {
58807 - fscache_stat(&fscache_n_relinquishes);
58808 + fscache_stat_unchecked(&fscache_n_relinquishes);
58809 if (retire)
58810 - fscache_stat(&fscache_n_relinquishes_retire);
58811 + fscache_stat_unchecked(&fscache_n_relinquishes_retire);
58812
58813 if (!cookie) {
58814 - fscache_stat(&fscache_n_relinquishes_null);
58815 + fscache_stat_unchecked(&fscache_n_relinquishes_null);
58816 _leave(" [no cookie]");
58817 return;
58818 }
58819 @@ -687,7 +687,7 @@ int __fscache_check_consistency(struct fscache_cookie *cookie)
58820 if (test_bit(FSCACHE_IOERROR, &object->cache->flags))
58821 goto inconsistent;
58822
58823 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
58824 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
58825
58826 __fscache_use_cookie(cookie);
58827 if (fscache_submit_op(object, op) < 0)
58828 diff --git a/fs/fscache/internal.h b/fs/fscache/internal.h
58829 index 4226f66..0fb3f45 100644
58830 --- a/fs/fscache/internal.h
58831 +++ b/fs/fscache/internal.h
58832 @@ -133,8 +133,8 @@ extern void fscache_operation_gc(struct work_struct *);
58833 extern int fscache_wait_for_deferred_lookup(struct fscache_cookie *);
58834 extern int fscache_wait_for_operation_activation(struct fscache_object *,
58835 struct fscache_operation *,
58836 - atomic_t *,
58837 - atomic_t *,
58838 + atomic_unchecked_t *,
58839 + atomic_unchecked_t *,
58840 void (*)(struct fscache_operation *));
58841 extern void fscache_invalidate_writes(struct fscache_cookie *);
58842
58843 @@ -153,101 +153,101 @@ extern void fscache_proc_cleanup(void);
58844 * stats.c
58845 */
58846 #ifdef CONFIG_FSCACHE_STATS
58847 -extern atomic_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
58848 -extern atomic_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
58849 +extern atomic_unchecked_t fscache_n_ops_processed[FSCACHE_MAX_THREADS];
58850 +extern atomic_unchecked_t fscache_n_objs_processed[FSCACHE_MAX_THREADS];
58851
58852 -extern atomic_t fscache_n_op_pend;
58853 -extern atomic_t fscache_n_op_run;
58854 -extern atomic_t fscache_n_op_enqueue;
58855 -extern atomic_t fscache_n_op_deferred_release;
58856 -extern atomic_t fscache_n_op_release;
58857 -extern atomic_t fscache_n_op_gc;
58858 -extern atomic_t fscache_n_op_cancelled;
58859 -extern atomic_t fscache_n_op_rejected;
58860 +extern atomic_unchecked_t fscache_n_op_pend;
58861 +extern atomic_unchecked_t fscache_n_op_run;
58862 +extern atomic_unchecked_t fscache_n_op_enqueue;
58863 +extern atomic_unchecked_t fscache_n_op_deferred_release;
58864 +extern atomic_unchecked_t fscache_n_op_release;
58865 +extern atomic_unchecked_t fscache_n_op_gc;
58866 +extern atomic_unchecked_t fscache_n_op_cancelled;
58867 +extern atomic_unchecked_t fscache_n_op_rejected;
58868
58869 -extern atomic_t fscache_n_attr_changed;
58870 -extern atomic_t fscache_n_attr_changed_ok;
58871 -extern atomic_t fscache_n_attr_changed_nobufs;
58872 -extern atomic_t fscache_n_attr_changed_nomem;
58873 -extern atomic_t fscache_n_attr_changed_calls;
58874 +extern atomic_unchecked_t fscache_n_attr_changed;
58875 +extern atomic_unchecked_t fscache_n_attr_changed_ok;
58876 +extern atomic_unchecked_t fscache_n_attr_changed_nobufs;
58877 +extern atomic_unchecked_t fscache_n_attr_changed_nomem;
58878 +extern atomic_unchecked_t fscache_n_attr_changed_calls;
58879
58880 -extern atomic_t fscache_n_allocs;
58881 -extern atomic_t fscache_n_allocs_ok;
58882 -extern atomic_t fscache_n_allocs_wait;
58883 -extern atomic_t fscache_n_allocs_nobufs;
58884 -extern atomic_t fscache_n_allocs_intr;
58885 -extern atomic_t fscache_n_allocs_object_dead;
58886 -extern atomic_t fscache_n_alloc_ops;
58887 -extern atomic_t fscache_n_alloc_op_waits;
58888 +extern atomic_unchecked_t fscache_n_allocs;
58889 +extern atomic_unchecked_t fscache_n_allocs_ok;
58890 +extern atomic_unchecked_t fscache_n_allocs_wait;
58891 +extern atomic_unchecked_t fscache_n_allocs_nobufs;
58892 +extern atomic_unchecked_t fscache_n_allocs_intr;
58893 +extern atomic_unchecked_t fscache_n_allocs_object_dead;
58894 +extern atomic_unchecked_t fscache_n_alloc_ops;
58895 +extern atomic_unchecked_t fscache_n_alloc_op_waits;
58896
58897 -extern atomic_t fscache_n_retrievals;
58898 -extern atomic_t fscache_n_retrievals_ok;
58899 -extern atomic_t fscache_n_retrievals_wait;
58900 -extern atomic_t fscache_n_retrievals_nodata;
58901 -extern atomic_t fscache_n_retrievals_nobufs;
58902 -extern atomic_t fscache_n_retrievals_intr;
58903 -extern atomic_t fscache_n_retrievals_nomem;
58904 -extern atomic_t fscache_n_retrievals_object_dead;
58905 -extern atomic_t fscache_n_retrieval_ops;
58906 -extern atomic_t fscache_n_retrieval_op_waits;
58907 +extern atomic_unchecked_t fscache_n_retrievals;
58908 +extern atomic_unchecked_t fscache_n_retrievals_ok;
58909 +extern atomic_unchecked_t fscache_n_retrievals_wait;
58910 +extern atomic_unchecked_t fscache_n_retrievals_nodata;
58911 +extern atomic_unchecked_t fscache_n_retrievals_nobufs;
58912 +extern atomic_unchecked_t fscache_n_retrievals_intr;
58913 +extern atomic_unchecked_t fscache_n_retrievals_nomem;
58914 +extern atomic_unchecked_t fscache_n_retrievals_object_dead;
58915 +extern atomic_unchecked_t fscache_n_retrieval_ops;
58916 +extern atomic_unchecked_t fscache_n_retrieval_op_waits;
58917
58918 -extern atomic_t fscache_n_stores;
58919 -extern atomic_t fscache_n_stores_ok;
58920 -extern atomic_t fscache_n_stores_again;
58921 -extern atomic_t fscache_n_stores_nobufs;
58922 -extern atomic_t fscache_n_stores_oom;
58923 -extern atomic_t fscache_n_store_ops;
58924 -extern atomic_t fscache_n_store_calls;
58925 -extern atomic_t fscache_n_store_pages;
58926 -extern atomic_t fscache_n_store_radix_deletes;
58927 -extern atomic_t fscache_n_store_pages_over_limit;
58928 +extern atomic_unchecked_t fscache_n_stores;
58929 +extern atomic_unchecked_t fscache_n_stores_ok;
58930 +extern atomic_unchecked_t fscache_n_stores_again;
58931 +extern atomic_unchecked_t fscache_n_stores_nobufs;
58932 +extern atomic_unchecked_t fscache_n_stores_oom;
58933 +extern atomic_unchecked_t fscache_n_store_ops;
58934 +extern atomic_unchecked_t fscache_n_store_calls;
58935 +extern atomic_unchecked_t fscache_n_store_pages;
58936 +extern atomic_unchecked_t fscache_n_store_radix_deletes;
58937 +extern atomic_unchecked_t fscache_n_store_pages_over_limit;
58938
58939 -extern atomic_t fscache_n_store_vmscan_not_storing;
58940 -extern atomic_t fscache_n_store_vmscan_gone;
58941 -extern atomic_t fscache_n_store_vmscan_busy;
58942 -extern atomic_t fscache_n_store_vmscan_cancelled;
58943 -extern atomic_t fscache_n_store_vmscan_wait;
58944 +extern atomic_unchecked_t fscache_n_store_vmscan_not_storing;
58945 +extern atomic_unchecked_t fscache_n_store_vmscan_gone;
58946 +extern atomic_unchecked_t fscache_n_store_vmscan_busy;
58947 +extern atomic_unchecked_t fscache_n_store_vmscan_cancelled;
58948 +extern atomic_unchecked_t fscache_n_store_vmscan_wait;
58949
58950 -extern atomic_t fscache_n_marks;
58951 -extern atomic_t fscache_n_uncaches;
58952 +extern atomic_unchecked_t fscache_n_marks;
58953 +extern atomic_unchecked_t fscache_n_uncaches;
58954
58955 -extern atomic_t fscache_n_acquires;
58956 -extern atomic_t fscache_n_acquires_null;
58957 -extern atomic_t fscache_n_acquires_no_cache;
58958 -extern atomic_t fscache_n_acquires_ok;
58959 -extern atomic_t fscache_n_acquires_nobufs;
58960 -extern atomic_t fscache_n_acquires_oom;
58961 +extern atomic_unchecked_t fscache_n_acquires;
58962 +extern atomic_unchecked_t fscache_n_acquires_null;
58963 +extern atomic_unchecked_t fscache_n_acquires_no_cache;
58964 +extern atomic_unchecked_t fscache_n_acquires_ok;
58965 +extern atomic_unchecked_t fscache_n_acquires_nobufs;
58966 +extern atomic_unchecked_t fscache_n_acquires_oom;
58967
58968 -extern atomic_t fscache_n_invalidates;
58969 -extern atomic_t fscache_n_invalidates_run;
58970 +extern atomic_unchecked_t fscache_n_invalidates;
58971 +extern atomic_unchecked_t fscache_n_invalidates_run;
58972
58973 -extern atomic_t fscache_n_updates;
58974 -extern atomic_t fscache_n_updates_null;
58975 -extern atomic_t fscache_n_updates_run;
58976 +extern atomic_unchecked_t fscache_n_updates;
58977 +extern atomic_unchecked_t fscache_n_updates_null;
58978 +extern atomic_unchecked_t fscache_n_updates_run;
58979
58980 -extern atomic_t fscache_n_relinquishes;
58981 -extern atomic_t fscache_n_relinquishes_null;
58982 -extern atomic_t fscache_n_relinquishes_waitcrt;
58983 -extern atomic_t fscache_n_relinquishes_retire;
58984 +extern atomic_unchecked_t fscache_n_relinquishes;
58985 +extern atomic_unchecked_t fscache_n_relinquishes_null;
58986 +extern atomic_unchecked_t fscache_n_relinquishes_waitcrt;
58987 +extern atomic_unchecked_t fscache_n_relinquishes_retire;
58988
58989 -extern atomic_t fscache_n_cookie_index;
58990 -extern atomic_t fscache_n_cookie_data;
58991 -extern atomic_t fscache_n_cookie_special;
58992 +extern atomic_unchecked_t fscache_n_cookie_index;
58993 +extern atomic_unchecked_t fscache_n_cookie_data;
58994 +extern atomic_unchecked_t fscache_n_cookie_special;
58995
58996 -extern atomic_t fscache_n_object_alloc;
58997 -extern atomic_t fscache_n_object_no_alloc;
58998 -extern atomic_t fscache_n_object_lookups;
58999 -extern atomic_t fscache_n_object_lookups_negative;
59000 -extern atomic_t fscache_n_object_lookups_positive;
59001 -extern atomic_t fscache_n_object_lookups_timed_out;
59002 -extern atomic_t fscache_n_object_created;
59003 -extern atomic_t fscache_n_object_avail;
59004 -extern atomic_t fscache_n_object_dead;
59005 +extern atomic_unchecked_t fscache_n_object_alloc;
59006 +extern atomic_unchecked_t fscache_n_object_no_alloc;
59007 +extern atomic_unchecked_t fscache_n_object_lookups;
59008 +extern atomic_unchecked_t fscache_n_object_lookups_negative;
59009 +extern atomic_unchecked_t fscache_n_object_lookups_positive;
59010 +extern atomic_unchecked_t fscache_n_object_lookups_timed_out;
59011 +extern atomic_unchecked_t fscache_n_object_created;
59012 +extern atomic_unchecked_t fscache_n_object_avail;
59013 +extern atomic_unchecked_t fscache_n_object_dead;
59014
59015 -extern atomic_t fscache_n_checkaux_none;
59016 -extern atomic_t fscache_n_checkaux_okay;
59017 -extern atomic_t fscache_n_checkaux_update;
59018 -extern atomic_t fscache_n_checkaux_obsolete;
59019 +extern atomic_unchecked_t fscache_n_checkaux_none;
59020 +extern atomic_unchecked_t fscache_n_checkaux_okay;
59021 +extern atomic_unchecked_t fscache_n_checkaux_update;
59022 +extern atomic_unchecked_t fscache_n_checkaux_obsolete;
59023
59024 extern atomic_t fscache_n_cop_alloc_object;
59025 extern atomic_t fscache_n_cop_lookup_object;
59026 @@ -272,6 +272,11 @@ static inline void fscache_stat(atomic_t *stat)
59027 atomic_inc(stat);
59028 }
59029
59030 +static inline void fscache_stat_unchecked(atomic_unchecked_t *stat)
59031 +{
59032 + atomic_inc_unchecked(stat);
59033 +}
59034 +
59035 static inline void fscache_stat_d(atomic_t *stat)
59036 {
59037 atomic_dec(stat);
59038 @@ -284,6 +289,7 @@ extern const struct file_operations fscache_stats_fops;
59039
59040 #define __fscache_stat(stat) (NULL)
59041 #define fscache_stat(stat) do {} while (0)
59042 +#define fscache_stat_unchecked(stat) do {} while (0)
59043 #define fscache_stat_d(stat) do {} while (0)
59044 #endif
59045
59046 diff --git a/fs/fscache/object.c b/fs/fscache/object.c
59047 index 53d35c5..5d68ed4 100644
59048 --- a/fs/fscache/object.c
59049 +++ b/fs/fscache/object.c
59050 @@ -451,7 +451,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
59051 _debug("LOOKUP \"%s\" in \"%s\"",
59052 cookie->def->name, object->cache->tag->name);
59053
59054 - fscache_stat(&fscache_n_object_lookups);
59055 + fscache_stat_unchecked(&fscache_n_object_lookups);
59056 fscache_stat(&fscache_n_cop_lookup_object);
59057 ret = object->cache->ops->lookup_object(object);
59058 fscache_stat_d(&fscache_n_cop_lookup_object);
59059 @@ -461,7 +461,7 @@ static const struct fscache_state *fscache_look_up_object(struct fscache_object
59060 if (ret == -ETIMEDOUT) {
59061 /* probably stuck behind another object, so move this one to
59062 * the back of the queue */
59063 - fscache_stat(&fscache_n_object_lookups_timed_out);
59064 + fscache_stat_unchecked(&fscache_n_object_lookups_timed_out);
59065 _leave(" [timeout]");
59066 return NO_TRANSIT;
59067 }
59068 @@ -489,7 +489,7 @@ void fscache_object_lookup_negative(struct fscache_object *object)
59069 _enter("{OBJ%x,%s}", object->debug_id, object->state->name);
59070
59071 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
59072 - fscache_stat(&fscache_n_object_lookups_negative);
59073 + fscache_stat_unchecked(&fscache_n_object_lookups_negative);
59074
59075 /* Allow write requests to begin stacking up and read requests to begin
59076 * returning ENODATA.
59077 @@ -524,7 +524,7 @@ void fscache_obtained_object(struct fscache_object *object)
59078 /* if we were still looking up, then we must have a positive lookup
59079 * result, in which case there may be data available */
59080 if (!test_and_set_bit(FSCACHE_OBJECT_IS_LOOKED_UP, &object->flags)) {
59081 - fscache_stat(&fscache_n_object_lookups_positive);
59082 + fscache_stat_unchecked(&fscache_n_object_lookups_positive);
59083
59084 /* We do (presumably) have data */
59085 clear_bit_unlock(FSCACHE_COOKIE_NO_DATA_YET, &cookie->flags);
59086 @@ -536,7 +536,7 @@ void fscache_obtained_object(struct fscache_object *object)
59087 clear_bit_unlock(FSCACHE_COOKIE_LOOKING_UP, &cookie->flags);
59088 wake_up_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP);
59089 } else {
59090 - fscache_stat(&fscache_n_object_created);
59091 + fscache_stat_unchecked(&fscache_n_object_created);
59092 }
59093
59094 set_bit(FSCACHE_OBJECT_IS_AVAILABLE, &object->flags);
59095 @@ -572,7 +572,7 @@ static const struct fscache_state *fscache_object_available(struct fscache_objec
59096 fscache_stat_d(&fscache_n_cop_lookup_complete);
59097
59098 fscache_hist(fscache_obj_instantiate_histogram, object->lookup_jif);
59099 - fscache_stat(&fscache_n_object_avail);
59100 + fscache_stat_unchecked(&fscache_n_object_avail);
59101
59102 _leave("");
59103 return transit_to(JUMPSTART_DEPS);
59104 @@ -719,7 +719,7 @@ static const struct fscache_state *fscache_drop_object(struct fscache_object *ob
59105
59106 /* this just shifts the object release to the work processor */
59107 fscache_put_object(object);
59108 - fscache_stat(&fscache_n_object_dead);
59109 + fscache_stat_unchecked(&fscache_n_object_dead);
59110
59111 _leave("");
59112 return transit_to(OBJECT_DEAD);
59113 @@ -884,7 +884,7 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
59114 enum fscache_checkaux result;
59115
59116 if (!object->cookie->def->check_aux) {
59117 - fscache_stat(&fscache_n_checkaux_none);
59118 + fscache_stat_unchecked(&fscache_n_checkaux_none);
59119 return FSCACHE_CHECKAUX_OKAY;
59120 }
59121
59122 @@ -893,17 +893,17 @@ enum fscache_checkaux fscache_check_aux(struct fscache_object *object,
59123 switch (result) {
59124 /* entry okay as is */
59125 case FSCACHE_CHECKAUX_OKAY:
59126 - fscache_stat(&fscache_n_checkaux_okay);
59127 + fscache_stat_unchecked(&fscache_n_checkaux_okay);
59128 break;
59129
59130 /* entry requires update */
59131 case FSCACHE_CHECKAUX_NEEDS_UPDATE:
59132 - fscache_stat(&fscache_n_checkaux_update);
59133 + fscache_stat_unchecked(&fscache_n_checkaux_update);
59134 break;
59135
59136 /* entry requires deletion */
59137 case FSCACHE_CHECKAUX_OBSOLETE:
59138 - fscache_stat(&fscache_n_checkaux_obsolete);
59139 + fscache_stat_unchecked(&fscache_n_checkaux_obsolete);
59140 break;
59141
59142 default:
59143 @@ -989,7 +989,7 @@ static const struct fscache_state *fscache_invalidate_object(struct fscache_obje
59144 {
59145 const struct fscache_state *s;
59146
59147 - fscache_stat(&fscache_n_invalidates_run);
59148 + fscache_stat_unchecked(&fscache_n_invalidates_run);
59149 fscache_stat(&fscache_n_cop_invalidate_object);
59150 s = _fscache_invalidate_object(object, event);
59151 fscache_stat_d(&fscache_n_cop_invalidate_object);
59152 @@ -1004,7 +1004,7 @@ static const struct fscache_state *fscache_update_object(struct fscache_object *
59153 {
59154 _enter("{OBJ%x},%d", object->debug_id, event);
59155
59156 - fscache_stat(&fscache_n_updates_run);
59157 + fscache_stat_unchecked(&fscache_n_updates_run);
59158 fscache_stat(&fscache_n_cop_update_object);
59159 object->cache->ops->update_object(object);
59160 fscache_stat_d(&fscache_n_cop_update_object);
59161 diff --git a/fs/fscache/operation.c b/fs/fscache/operation.c
59162 index 318071a..379938b 100644
59163 --- a/fs/fscache/operation.c
59164 +++ b/fs/fscache/operation.c
59165 @@ -17,7 +17,7 @@
59166 #include <linux/slab.h>
59167 #include "internal.h"
59168
59169 -atomic_t fscache_op_debug_id;
59170 +atomic_unchecked_t fscache_op_debug_id;
59171 EXPORT_SYMBOL(fscache_op_debug_id);
59172
59173 /**
59174 @@ -39,7 +39,7 @@ void fscache_enqueue_operation(struct fscache_operation *op)
59175 ASSERTCMP(atomic_read(&op->usage), >, 0);
59176 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_IN_PROGRESS);
59177
59178 - fscache_stat(&fscache_n_op_enqueue);
59179 + fscache_stat_unchecked(&fscache_n_op_enqueue);
59180 switch (op->flags & FSCACHE_OP_TYPE) {
59181 case FSCACHE_OP_ASYNC:
59182 _debug("queue async");
59183 @@ -73,7 +73,7 @@ static void fscache_run_op(struct fscache_object *object,
59184 wake_up_bit(&op->flags, FSCACHE_OP_WAITING);
59185 if (op->processor)
59186 fscache_enqueue_operation(op);
59187 - fscache_stat(&fscache_n_op_run);
59188 + fscache_stat_unchecked(&fscache_n_op_run);
59189 }
59190
59191 /*
59192 @@ -105,11 +105,11 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
59193 if (object->n_in_progress > 0) {
59194 atomic_inc(&op->usage);
59195 list_add_tail(&op->pend_link, &object->pending_ops);
59196 - fscache_stat(&fscache_n_op_pend);
59197 + fscache_stat_unchecked(&fscache_n_op_pend);
59198 } else if (!list_empty(&object->pending_ops)) {
59199 atomic_inc(&op->usage);
59200 list_add_tail(&op->pend_link, &object->pending_ops);
59201 - fscache_stat(&fscache_n_op_pend);
59202 + fscache_stat_unchecked(&fscache_n_op_pend);
59203 fscache_start_operations(object);
59204 } else {
59205 ASSERTCMP(object->n_in_progress, ==, 0);
59206 @@ -125,7 +125,7 @@ int fscache_submit_exclusive_op(struct fscache_object *object,
59207 object->n_exclusive++; /* reads and writes must wait */
59208 atomic_inc(&op->usage);
59209 list_add_tail(&op->pend_link, &object->pending_ops);
59210 - fscache_stat(&fscache_n_op_pend);
59211 + fscache_stat_unchecked(&fscache_n_op_pend);
59212 ret = 0;
59213 } else {
59214 /* If we're in any other state, there must have been an I/O
59215 @@ -212,11 +212,11 @@ int fscache_submit_op(struct fscache_object *object,
59216 if (object->n_exclusive > 0) {
59217 atomic_inc(&op->usage);
59218 list_add_tail(&op->pend_link, &object->pending_ops);
59219 - fscache_stat(&fscache_n_op_pend);
59220 + fscache_stat_unchecked(&fscache_n_op_pend);
59221 } else if (!list_empty(&object->pending_ops)) {
59222 atomic_inc(&op->usage);
59223 list_add_tail(&op->pend_link, &object->pending_ops);
59224 - fscache_stat(&fscache_n_op_pend);
59225 + fscache_stat_unchecked(&fscache_n_op_pend);
59226 fscache_start_operations(object);
59227 } else {
59228 ASSERTCMP(object->n_exclusive, ==, 0);
59229 @@ -228,10 +228,10 @@ int fscache_submit_op(struct fscache_object *object,
59230 object->n_ops++;
59231 atomic_inc(&op->usage);
59232 list_add_tail(&op->pend_link, &object->pending_ops);
59233 - fscache_stat(&fscache_n_op_pend);
59234 + fscache_stat_unchecked(&fscache_n_op_pend);
59235 ret = 0;
59236 } else if (fscache_object_is_dying(object)) {
59237 - fscache_stat(&fscache_n_op_rejected);
59238 + fscache_stat_unchecked(&fscache_n_op_rejected);
59239 op->state = FSCACHE_OP_ST_CANCELLED;
59240 ret = -ENOBUFS;
59241 } else if (!test_bit(FSCACHE_IOERROR, &object->cache->flags)) {
59242 @@ -310,7 +310,7 @@ int fscache_cancel_op(struct fscache_operation *op,
59243 ret = -EBUSY;
59244 if (op->state == FSCACHE_OP_ST_PENDING) {
59245 ASSERT(!list_empty(&op->pend_link));
59246 - fscache_stat(&fscache_n_op_cancelled);
59247 + fscache_stat_unchecked(&fscache_n_op_cancelled);
59248 list_del_init(&op->pend_link);
59249 if (do_cancel)
59250 do_cancel(op);
59251 @@ -342,7 +342,7 @@ void fscache_cancel_all_ops(struct fscache_object *object)
59252 while (!list_empty(&object->pending_ops)) {
59253 op = list_entry(object->pending_ops.next,
59254 struct fscache_operation, pend_link);
59255 - fscache_stat(&fscache_n_op_cancelled);
59256 + fscache_stat_unchecked(&fscache_n_op_cancelled);
59257 list_del_init(&op->pend_link);
59258
59259 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_PENDING);
59260 @@ -414,7 +414,7 @@ void fscache_put_operation(struct fscache_operation *op)
59261 op->state, ==, FSCACHE_OP_ST_CANCELLED);
59262 op->state = FSCACHE_OP_ST_DEAD;
59263
59264 - fscache_stat(&fscache_n_op_release);
59265 + fscache_stat_unchecked(&fscache_n_op_release);
59266
59267 if (op->release) {
59268 op->release(op);
59269 @@ -433,7 +433,7 @@ void fscache_put_operation(struct fscache_operation *op)
59270 * lock, and defer it otherwise */
59271 if (!spin_trylock(&object->lock)) {
59272 _debug("defer put");
59273 - fscache_stat(&fscache_n_op_deferred_release);
59274 + fscache_stat_unchecked(&fscache_n_op_deferred_release);
59275
59276 cache = object->cache;
59277 spin_lock(&cache->op_gc_list_lock);
59278 @@ -486,7 +486,7 @@ void fscache_operation_gc(struct work_struct *work)
59279
59280 _debug("GC DEFERRED REL OBJ%x OP%x",
59281 object->debug_id, op->debug_id);
59282 - fscache_stat(&fscache_n_op_gc);
59283 + fscache_stat_unchecked(&fscache_n_op_gc);
59284
59285 ASSERTCMP(atomic_read(&op->usage), ==, 0);
59286 ASSERTCMP(op->state, ==, FSCACHE_OP_ST_DEAD);
59287 diff --git a/fs/fscache/page.c b/fs/fscache/page.c
59288 index 7f5c658..6c1e164 100644
59289 --- a/fs/fscache/page.c
59290 +++ b/fs/fscache/page.c
59291 @@ -61,7 +61,7 @@ try_again:
59292 val = radix_tree_lookup(&cookie->stores, page->index);
59293 if (!val) {
59294 rcu_read_unlock();
59295 - fscache_stat(&fscache_n_store_vmscan_not_storing);
59296 + fscache_stat_unchecked(&fscache_n_store_vmscan_not_storing);
59297 __fscache_uncache_page(cookie, page);
59298 return true;
59299 }
59300 @@ -91,11 +91,11 @@ try_again:
59301 spin_unlock(&cookie->stores_lock);
59302
59303 if (xpage) {
59304 - fscache_stat(&fscache_n_store_vmscan_cancelled);
59305 - fscache_stat(&fscache_n_store_radix_deletes);
59306 + fscache_stat_unchecked(&fscache_n_store_vmscan_cancelled);
59307 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
59308 ASSERTCMP(xpage, ==, page);
59309 } else {
59310 - fscache_stat(&fscache_n_store_vmscan_gone);
59311 + fscache_stat_unchecked(&fscache_n_store_vmscan_gone);
59312 }
59313
59314 wake_up_bit(&cookie->flags, 0);
59315 @@ -110,11 +110,11 @@ page_busy:
59316 * sleeping on memory allocation, so we may need to impose a timeout
59317 * too. */
59318 if (!(gfp & __GFP_WAIT) || !(gfp & __GFP_FS)) {
59319 - fscache_stat(&fscache_n_store_vmscan_busy);
59320 + fscache_stat_unchecked(&fscache_n_store_vmscan_busy);
59321 return false;
59322 }
59323
59324 - fscache_stat(&fscache_n_store_vmscan_wait);
59325 + fscache_stat_unchecked(&fscache_n_store_vmscan_wait);
59326 __fscache_wait_on_page_write(cookie, page);
59327 gfp &= ~__GFP_WAIT;
59328 goto try_again;
59329 @@ -140,7 +140,7 @@ static void fscache_end_page_write(struct fscache_object *object,
59330 FSCACHE_COOKIE_STORING_TAG);
59331 if (!radix_tree_tag_get(&cookie->stores, page->index,
59332 FSCACHE_COOKIE_PENDING_TAG)) {
59333 - fscache_stat(&fscache_n_store_radix_deletes);
59334 + fscache_stat_unchecked(&fscache_n_store_radix_deletes);
59335 xpage = radix_tree_delete(&cookie->stores, page->index);
59336 }
59337 spin_unlock(&cookie->stores_lock);
59338 @@ -161,7 +161,7 @@ static void fscache_attr_changed_op(struct fscache_operation *op)
59339
59340 _enter("{OBJ%x OP%x}", object->debug_id, op->debug_id);
59341
59342 - fscache_stat(&fscache_n_attr_changed_calls);
59343 + fscache_stat_unchecked(&fscache_n_attr_changed_calls);
59344
59345 if (fscache_object_is_active(object)) {
59346 fscache_stat(&fscache_n_cop_attr_changed);
59347 @@ -188,11 +188,11 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
59348
59349 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
59350
59351 - fscache_stat(&fscache_n_attr_changed);
59352 + fscache_stat_unchecked(&fscache_n_attr_changed);
59353
59354 op = kzalloc(sizeof(*op), GFP_KERNEL);
59355 if (!op) {
59356 - fscache_stat(&fscache_n_attr_changed_nomem);
59357 + fscache_stat_unchecked(&fscache_n_attr_changed_nomem);
59358 _leave(" = -ENOMEM");
59359 return -ENOMEM;
59360 }
59361 @@ -214,7 +214,7 @@ int __fscache_attr_changed(struct fscache_cookie *cookie)
59362 if (fscache_submit_exclusive_op(object, op) < 0)
59363 goto nobufs;
59364 spin_unlock(&cookie->lock);
59365 - fscache_stat(&fscache_n_attr_changed_ok);
59366 + fscache_stat_unchecked(&fscache_n_attr_changed_ok);
59367 fscache_put_operation(op);
59368 _leave(" = 0");
59369 return 0;
59370 @@ -225,7 +225,7 @@ nobufs:
59371 kfree(op);
59372 if (wake_cookie)
59373 __fscache_wake_unused_cookie(cookie);
59374 - fscache_stat(&fscache_n_attr_changed_nobufs);
59375 + fscache_stat_unchecked(&fscache_n_attr_changed_nobufs);
59376 _leave(" = %d", -ENOBUFS);
59377 return -ENOBUFS;
59378 }
59379 @@ -264,7 +264,7 @@ static struct fscache_retrieval *fscache_alloc_retrieval(
59380 /* allocate a retrieval operation and attempt to submit it */
59381 op = kzalloc(sizeof(*op), GFP_NOIO);
59382 if (!op) {
59383 - fscache_stat(&fscache_n_retrievals_nomem);
59384 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
59385 return NULL;
59386 }
59387
59388 @@ -294,13 +294,13 @@ int fscache_wait_for_deferred_lookup(struct fscache_cookie *cookie)
59389 return 0;
59390 }
59391
59392 - fscache_stat(&fscache_n_retrievals_wait);
59393 + fscache_stat_unchecked(&fscache_n_retrievals_wait);
59394
59395 jif = jiffies;
59396 if (wait_on_bit(&cookie->flags, FSCACHE_COOKIE_LOOKING_UP,
59397 fscache_wait_bit_interruptible,
59398 TASK_INTERRUPTIBLE) != 0) {
59399 - fscache_stat(&fscache_n_retrievals_intr);
59400 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
59401 _leave(" = -ERESTARTSYS");
59402 return -ERESTARTSYS;
59403 }
59404 @@ -329,8 +329,8 @@ static void fscache_do_cancel_retrieval(struct fscache_operation *_op)
59405 */
59406 int fscache_wait_for_operation_activation(struct fscache_object *object,
59407 struct fscache_operation *op,
59408 - atomic_t *stat_op_waits,
59409 - atomic_t *stat_object_dead,
59410 + atomic_unchecked_t *stat_op_waits,
59411 + atomic_unchecked_t *stat_object_dead,
59412 void (*do_cancel)(struct fscache_operation *))
59413 {
59414 int ret;
59415 @@ -340,7 +340,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
59416
59417 _debug(">>> WT");
59418 if (stat_op_waits)
59419 - fscache_stat(stat_op_waits);
59420 + fscache_stat_unchecked(stat_op_waits);
59421 if (wait_on_bit(&op->flags, FSCACHE_OP_WAITING,
59422 fscache_wait_bit_interruptible,
59423 TASK_INTERRUPTIBLE) != 0) {
59424 @@ -358,7 +358,7 @@ int fscache_wait_for_operation_activation(struct fscache_object *object,
59425 check_if_dead:
59426 if (op->state == FSCACHE_OP_ST_CANCELLED) {
59427 if (stat_object_dead)
59428 - fscache_stat(stat_object_dead);
59429 + fscache_stat_unchecked(stat_object_dead);
59430 _leave(" = -ENOBUFS [cancelled]");
59431 return -ENOBUFS;
59432 }
59433 @@ -366,7 +366,7 @@ check_if_dead:
59434 pr_err("%s() = -ENOBUFS [obj dead %d]\n", __func__, op->state);
59435 fscache_cancel_op(op, do_cancel);
59436 if (stat_object_dead)
59437 - fscache_stat(stat_object_dead);
59438 + fscache_stat_unchecked(stat_object_dead);
59439 return -ENOBUFS;
59440 }
59441 return 0;
59442 @@ -394,7 +394,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
59443
59444 _enter("%p,%p,,,", cookie, page);
59445
59446 - fscache_stat(&fscache_n_retrievals);
59447 + fscache_stat_unchecked(&fscache_n_retrievals);
59448
59449 if (hlist_empty(&cookie->backing_objects))
59450 goto nobufs;
59451 @@ -436,7 +436,7 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
59452 goto nobufs_unlock_dec;
59453 spin_unlock(&cookie->lock);
59454
59455 - fscache_stat(&fscache_n_retrieval_ops);
59456 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
59457
59458 /* pin the netfs read context in case we need to do the actual netfs
59459 * read because we've encountered a cache read failure */
59460 @@ -467,15 +467,15 @@ int __fscache_read_or_alloc_page(struct fscache_cookie *cookie,
59461
59462 error:
59463 if (ret == -ENOMEM)
59464 - fscache_stat(&fscache_n_retrievals_nomem);
59465 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
59466 else if (ret == -ERESTARTSYS)
59467 - fscache_stat(&fscache_n_retrievals_intr);
59468 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
59469 else if (ret == -ENODATA)
59470 - fscache_stat(&fscache_n_retrievals_nodata);
59471 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
59472 else if (ret < 0)
59473 - fscache_stat(&fscache_n_retrievals_nobufs);
59474 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
59475 else
59476 - fscache_stat(&fscache_n_retrievals_ok);
59477 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
59478
59479 fscache_put_retrieval(op);
59480 _leave(" = %d", ret);
59481 @@ -490,7 +490,7 @@ nobufs_unlock:
59482 __fscache_wake_unused_cookie(cookie);
59483 kfree(op);
59484 nobufs:
59485 - fscache_stat(&fscache_n_retrievals_nobufs);
59486 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
59487 _leave(" = -ENOBUFS");
59488 return -ENOBUFS;
59489 }
59490 @@ -529,7 +529,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
59491
59492 _enter("%p,,%d,,,", cookie, *nr_pages);
59493
59494 - fscache_stat(&fscache_n_retrievals);
59495 + fscache_stat_unchecked(&fscache_n_retrievals);
59496
59497 if (hlist_empty(&cookie->backing_objects))
59498 goto nobufs;
59499 @@ -567,7 +567,7 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
59500 goto nobufs_unlock_dec;
59501 spin_unlock(&cookie->lock);
59502
59503 - fscache_stat(&fscache_n_retrieval_ops);
59504 + fscache_stat_unchecked(&fscache_n_retrieval_ops);
59505
59506 /* pin the netfs read context in case we need to do the actual netfs
59507 * read because we've encountered a cache read failure */
59508 @@ -598,15 +598,15 @@ int __fscache_read_or_alloc_pages(struct fscache_cookie *cookie,
59509
59510 error:
59511 if (ret == -ENOMEM)
59512 - fscache_stat(&fscache_n_retrievals_nomem);
59513 + fscache_stat_unchecked(&fscache_n_retrievals_nomem);
59514 else if (ret == -ERESTARTSYS)
59515 - fscache_stat(&fscache_n_retrievals_intr);
59516 + fscache_stat_unchecked(&fscache_n_retrievals_intr);
59517 else if (ret == -ENODATA)
59518 - fscache_stat(&fscache_n_retrievals_nodata);
59519 + fscache_stat_unchecked(&fscache_n_retrievals_nodata);
59520 else if (ret < 0)
59521 - fscache_stat(&fscache_n_retrievals_nobufs);
59522 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
59523 else
59524 - fscache_stat(&fscache_n_retrievals_ok);
59525 + fscache_stat_unchecked(&fscache_n_retrievals_ok);
59526
59527 fscache_put_retrieval(op);
59528 _leave(" = %d", ret);
59529 @@ -621,7 +621,7 @@ nobufs_unlock:
59530 if (wake_cookie)
59531 __fscache_wake_unused_cookie(cookie);
59532 nobufs:
59533 - fscache_stat(&fscache_n_retrievals_nobufs);
59534 + fscache_stat_unchecked(&fscache_n_retrievals_nobufs);
59535 _leave(" = -ENOBUFS");
59536 return -ENOBUFS;
59537 }
59538 @@ -646,7 +646,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
59539
59540 _enter("%p,%p,,,", cookie, page);
59541
59542 - fscache_stat(&fscache_n_allocs);
59543 + fscache_stat_unchecked(&fscache_n_allocs);
59544
59545 if (hlist_empty(&cookie->backing_objects))
59546 goto nobufs;
59547 @@ -680,7 +680,7 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
59548 goto nobufs_unlock_dec;
59549 spin_unlock(&cookie->lock);
59550
59551 - fscache_stat(&fscache_n_alloc_ops);
59552 + fscache_stat_unchecked(&fscache_n_alloc_ops);
59553
59554 ret = fscache_wait_for_operation_activation(
59555 object, &op->op,
59556 @@ -697,11 +697,11 @@ int __fscache_alloc_page(struct fscache_cookie *cookie,
59557
59558 error:
59559 if (ret == -ERESTARTSYS)
59560 - fscache_stat(&fscache_n_allocs_intr);
59561 + fscache_stat_unchecked(&fscache_n_allocs_intr);
59562 else if (ret < 0)
59563 - fscache_stat(&fscache_n_allocs_nobufs);
59564 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
59565 else
59566 - fscache_stat(&fscache_n_allocs_ok);
59567 + fscache_stat_unchecked(&fscache_n_allocs_ok);
59568
59569 fscache_put_retrieval(op);
59570 _leave(" = %d", ret);
59571 @@ -715,7 +715,7 @@ nobufs_unlock:
59572 if (wake_cookie)
59573 __fscache_wake_unused_cookie(cookie);
59574 nobufs:
59575 - fscache_stat(&fscache_n_allocs_nobufs);
59576 + fscache_stat_unchecked(&fscache_n_allocs_nobufs);
59577 _leave(" = -ENOBUFS");
59578 return -ENOBUFS;
59579 }
59580 @@ -791,7 +791,7 @@ static void fscache_write_op(struct fscache_operation *_op)
59581
59582 spin_lock(&cookie->stores_lock);
59583
59584 - fscache_stat(&fscache_n_store_calls);
59585 + fscache_stat_unchecked(&fscache_n_store_calls);
59586
59587 /* find a page to store */
59588 page = NULL;
59589 @@ -802,7 +802,7 @@ static void fscache_write_op(struct fscache_operation *_op)
59590 page = results[0];
59591 _debug("gang %d [%lx]", n, page->index);
59592 if (page->index > op->store_limit) {
59593 - fscache_stat(&fscache_n_store_pages_over_limit);
59594 + fscache_stat_unchecked(&fscache_n_store_pages_over_limit);
59595 goto superseded;
59596 }
59597
59598 @@ -814,7 +814,7 @@ static void fscache_write_op(struct fscache_operation *_op)
59599 spin_unlock(&cookie->stores_lock);
59600 spin_unlock(&object->lock);
59601
59602 - fscache_stat(&fscache_n_store_pages);
59603 + fscache_stat_unchecked(&fscache_n_store_pages);
59604 fscache_stat(&fscache_n_cop_write_page);
59605 ret = object->cache->ops->write_page(op, page);
59606 fscache_stat_d(&fscache_n_cop_write_page);
59607 @@ -918,7 +918,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
59608 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
59609 ASSERT(PageFsCache(page));
59610
59611 - fscache_stat(&fscache_n_stores);
59612 + fscache_stat_unchecked(&fscache_n_stores);
59613
59614 if (test_bit(FSCACHE_COOKIE_INVALIDATING, &cookie->flags)) {
59615 _leave(" = -ENOBUFS [invalidating]");
59616 @@ -977,7 +977,7 @@ int __fscache_write_page(struct fscache_cookie *cookie,
59617 spin_unlock(&cookie->stores_lock);
59618 spin_unlock(&object->lock);
59619
59620 - op->op.debug_id = atomic_inc_return(&fscache_op_debug_id);
59621 + op->op.debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
59622 op->store_limit = object->store_limit;
59623
59624 __fscache_use_cookie(cookie);
59625 @@ -986,8 +986,8 @@ int __fscache_write_page(struct fscache_cookie *cookie,
59626
59627 spin_unlock(&cookie->lock);
59628 radix_tree_preload_end();
59629 - fscache_stat(&fscache_n_store_ops);
59630 - fscache_stat(&fscache_n_stores_ok);
59631 + fscache_stat_unchecked(&fscache_n_store_ops);
59632 + fscache_stat_unchecked(&fscache_n_stores_ok);
59633
59634 /* the work queue now carries its own ref on the object */
59635 fscache_put_operation(&op->op);
59636 @@ -995,14 +995,14 @@ int __fscache_write_page(struct fscache_cookie *cookie,
59637 return 0;
59638
59639 already_queued:
59640 - fscache_stat(&fscache_n_stores_again);
59641 + fscache_stat_unchecked(&fscache_n_stores_again);
59642 already_pending:
59643 spin_unlock(&cookie->stores_lock);
59644 spin_unlock(&object->lock);
59645 spin_unlock(&cookie->lock);
59646 radix_tree_preload_end();
59647 kfree(op);
59648 - fscache_stat(&fscache_n_stores_ok);
59649 + fscache_stat_unchecked(&fscache_n_stores_ok);
59650 _leave(" = 0");
59651 return 0;
59652
59653 @@ -1024,14 +1024,14 @@ nobufs:
59654 kfree(op);
59655 if (wake_cookie)
59656 __fscache_wake_unused_cookie(cookie);
59657 - fscache_stat(&fscache_n_stores_nobufs);
59658 + fscache_stat_unchecked(&fscache_n_stores_nobufs);
59659 _leave(" = -ENOBUFS");
59660 return -ENOBUFS;
59661
59662 nomem_free:
59663 kfree(op);
59664 nomem:
59665 - fscache_stat(&fscache_n_stores_oom);
59666 + fscache_stat_unchecked(&fscache_n_stores_oom);
59667 _leave(" = -ENOMEM");
59668 return -ENOMEM;
59669 }
59670 @@ -1049,7 +1049,7 @@ void __fscache_uncache_page(struct fscache_cookie *cookie, struct page *page)
59671 ASSERTCMP(cookie->def->type, !=, FSCACHE_COOKIE_TYPE_INDEX);
59672 ASSERTCMP(page, !=, NULL);
59673
59674 - fscache_stat(&fscache_n_uncaches);
59675 + fscache_stat_unchecked(&fscache_n_uncaches);
59676
59677 /* cache withdrawal may beat us to it */
59678 if (!PageFsCache(page))
59679 @@ -1100,7 +1100,7 @@ void fscache_mark_page_cached(struct fscache_retrieval *op, struct page *page)
59680 struct fscache_cookie *cookie = op->op.object->cookie;
59681
59682 #ifdef CONFIG_FSCACHE_STATS
59683 - atomic_inc(&fscache_n_marks);
59684 + atomic_inc_unchecked(&fscache_n_marks);
59685 #endif
59686
59687 _debug("- mark %p{%lx}", page, page->index);
59688 diff --git a/fs/fscache/stats.c b/fs/fscache/stats.c
59689 index 40d13c7..ddf52b9 100644
59690 --- a/fs/fscache/stats.c
59691 +++ b/fs/fscache/stats.c
59692 @@ -18,99 +18,99 @@
59693 /*
59694 * operation counters
59695 */
59696 -atomic_t fscache_n_op_pend;
59697 -atomic_t fscache_n_op_run;
59698 -atomic_t fscache_n_op_enqueue;
59699 -atomic_t fscache_n_op_requeue;
59700 -atomic_t fscache_n_op_deferred_release;
59701 -atomic_t fscache_n_op_release;
59702 -atomic_t fscache_n_op_gc;
59703 -atomic_t fscache_n_op_cancelled;
59704 -atomic_t fscache_n_op_rejected;
59705 +atomic_unchecked_t fscache_n_op_pend;
59706 +atomic_unchecked_t fscache_n_op_run;
59707 +atomic_unchecked_t fscache_n_op_enqueue;
59708 +atomic_unchecked_t fscache_n_op_requeue;
59709 +atomic_unchecked_t fscache_n_op_deferred_release;
59710 +atomic_unchecked_t fscache_n_op_release;
59711 +atomic_unchecked_t fscache_n_op_gc;
59712 +atomic_unchecked_t fscache_n_op_cancelled;
59713 +atomic_unchecked_t fscache_n_op_rejected;
59714
59715 -atomic_t fscache_n_attr_changed;
59716 -atomic_t fscache_n_attr_changed_ok;
59717 -atomic_t fscache_n_attr_changed_nobufs;
59718 -atomic_t fscache_n_attr_changed_nomem;
59719 -atomic_t fscache_n_attr_changed_calls;
59720 +atomic_unchecked_t fscache_n_attr_changed;
59721 +atomic_unchecked_t fscache_n_attr_changed_ok;
59722 +atomic_unchecked_t fscache_n_attr_changed_nobufs;
59723 +atomic_unchecked_t fscache_n_attr_changed_nomem;
59724 +atomic_unchecked_t fscache_n_attr_changed_calls;
59725
59726 -atomic_t fscache_n_allocs;
59727 -atomic_t fscache_n_allocs_ok;
59728 -atomic_t fscache_n_allocs_wait;
59729 -atomic_t fscache_n_allocs_nobufs;
59730 -atomic_t fscache_n_allocs_intr;
59731 -atomic_t fscache_n_allocs_object_dead;
59732 -atomic_t fscache_n_alloc_ops;
59733 -atomic_t fscache_n_alloc_op_waits;
59734 +atomic_unchecked_t fscache_n_allocs;
59735 +atomic_unchecked_t fscache_n_allocs_ok;
59736 +atomic_unchecked_t fscache_n_allocs_wait;
59737 +atomic_unchecked_t fscache_n_allocs_nobufs;
59738 +atomic_unchecked_t fscache_n_allocs_intr;
59739 +atomic_unchecked_t fscache_n_allocs_object_dead;
59740 +atomic_unchecked_t fscache_n_alloc_ops;
59741 +atomic_unchecked_t fscache_n_alloc_op_waits;
59742
59743 -atomic_t fscache_n_retrievals;
59744 -atomic_t fscache_n_retrievals_ok;
59745 -atomic_t fscache_n_retrievals_wait;
59746 -atomic_t fscache_n_retrievals_nodata;
59747 -atomic_t fscache_n_retrievals_nobufs;
59748 -atomic_t fscache_n_retrievals_intr;
59749 -atomic_t fscache_n_retrievals_nomem;
59750 -atomic_t fscache_n_retrievals_object_dead;
59751 -atomic_t fscache_n_retrieval_ops;
59752 -atomic_t fscache_n_retrieval_op_waits;
59753 +atomic_unchecked_t fscache_n_retrievals;
59754 +atomic_unchecked_t fscache_n_retrievals_ok;
59755 +atomic_unchecked_t fscache_n_retrievals_wait;
59756 +atomic_unchecked_t fscache_n_retrievals_nodata;
59757 +atomic_unchecked_t fscache_n_retrievals_nobufs;
59758 +atomic_unchecked_t fscache_n_retrievals_intr;
59759 +atomic_unchecked_t fscache_n_retrievals_nomem;
59760 +atomic_unchecked_t fscache_n_retrievals_object_dead;
59761 +atomic_unchecked_t fscache_n_retrieval_ops;
59762 +atomic_unchecked_t fscache_n_retrieval_op_waits;
59763
59764 -atomic_t fscache_n_stores;
59765 -atomic_t fscache_n_stores_ok;
59766 -atomic_t fscache_n_stores_again;
59767 -atomic_t fscache_n_stores_nobufs;
59768 -atomic_t fscache_n_stores_oom;
59769 -atomic_t fscache_n_store_ops;
59770 -atomic_t fscache_n_store_calls;
59771 -atomic_t fscache_n_store_pages;
59772 -atomic_t fscache_n_store_radix_deletes;
59773 -atomic_t fscache_n_store_pages_over_limit;
59774 +atomic_unchecked_t fscache_n_stores;
59775 +atomic_unchecked_t fscache_n_stores_ok;
59776 +atomic_unchecked_t fscache_n_stores_again;
59777 +atomic_unchecked_t fscache_n_stores_nobufs;
59778 +atomic_unchecked_t fscache_n_stores_oom;
59779 +atomic_unchecked_t fscache_n_store_ops;
59780 +atomic_unchecked_t fscache_n_store_calls;
59781 +atomic_unchecked_t fscache_n_store_pages;
59782 +atomic_unchecked_t fscache_n_store_radix_deletes;
59783 +atomic_unchecked_t fscache_n_store_pages_over_limit;
59784
59785 -atomic_t fscache_n_store_vmscan_not_storing;
59786 -atomic_t fscache_n_store_vmscan_gone;
59787 -atomic_t fscache_n_store_vmscan_busy;
59788 -atomic_t fscache_n_store_vmscan_cancelled;
59789 -atomic_t fscache_n_store_vmscan_wait;
59790 +atomic_unchecked_t fscache_n_store_vmscan_not_storing;
59791 +atomic_unchecked_t fscache_n_store_vmscan_gone;
59792 +atomic_unchecked_t fscache_n_store_vmscan_busy;
59793 +atomic_unchecked_t fscache_n_store_vmscan_cancelled;
59794 +atomic_unchecked_t fscache_n_store_vmscan_wait;
59795
59796 -atomic_t fscache_n_marks;
59797 -atomic_t fscache_n_uncaches;
59798 +atomic_unchecked_t fscache_n_marks;
59799 +atomic_unchecked_t fscache_n_uncaches;
59800
59801 -atomic_t fscache_n_acquires;
59802 -atomic_t fscache_n_acquires_null;
59803 -atomic_t fscache_n_acquires_no_cache;
59804 -atomic_t fscache_n_acquires_ok;
59805 -atomic_t fscache_n_acquires_nobufs;
59806 -atomic_t fscache_n_acquires_oom;
59807 +atomic_unchecked_t fscache_n_acquires;
59808 +atomic_unchecked_t fscache_n_acquires_null;
59809 +atomic_unchecked_t fscache_n_acquires_no_cache;
59810 +atomic_unchecked_t fscache_n_acquires_ok;
59811 +atomic_unchecked_t fscache_n_acquires_nobufs;
59812 +atomic_unchecked_t fscache_n_acquires_oom;
59813
59814 -atomic_t fscache_n_invalidates;
59815 -atomic_t fscache_n_invalidates_run;
59816 +atomic_unchecked_t fscache_n_invalidates;
59817 +atomic_unchecked_t fscache_n_invalidates_run;
59818
59819 -atomic_t fscache_n_updates;
59820 -atomic_t fscache_n_updates_null;
59821 -atomic_t fscache_n_updates_run;
59822 +atomic_unchecked_t fscache_n_updates;
59823 +atomic_unchecked_t fscache_n_updates_null;
59824 +atomic_unchecked_t fscache_n_updates_run;
59825
59826 -atomic_t fscache_n_relinquishes;
59827 -atomic_t fscache_n_relinquishes_null;
59828 -atomic_t fscache_n_relinquishes_waitcrt;
59829 -atomic_t fscache_n_relinquishes_retire;
59830 +atomic_unchecked_t fscache_n_relinquishes;
59831 +atomic_unchecked_t fscache_n_relinquishes_null;
59832 +atomic_unchecked_t fscache_n_relinquishes_waitcrt;
59833 +atomic_unchecked_t fscache_n_relinquishes_retire;
59834
59835 -atomic_t fscache_n_cookie_index;
59836 -atomic_t fscache_n_cookie_data;
59837 -atomic_t fscache_n_cookie_special;
59838 +atomic_unchecked_t fscache_n_cookie_index;
59839 +atomic_unchecked_t fscache_n_cookie_data;
59840 +atomic_unchecked_t fscache_n_cookie_special;
59841
59842 -atomic_t fscache_n_object_alloc;
59843 -atomic_t fscache_n_object_no_alloc;
59844 -atomic_t fscache_n_object_lookups;
59845 -atomic_t fscache_n_object_lookups_negative;
59846 -atomic_t fscache_n_object_lookups_positive;
59847 -atomic_t fscache_n_object_lookups_timed_out;
59848 -atomic_t fscache_n_object_created;
59849 -atomic_t fscache_n_object_avail;
59850 -atomic_t fscache_n_object_dead;
59851 +atomic_unchecked_t fscache_n_object_alloc;
59852 +atomic_unchecked_t fscache_n_object_no_alloc;
59853 +atomic_unchecked_t fscache_n_object_lookups;
59854 +atomic_unchecked_t fscache_n_object_lookups_negative;
59855 +atomic_unchecked_t fscache_n_object_lookups_positive;
59856 +atomic_unchecked_t fscache_n_object_lookups_timed_out;
59857 +atomic_unchecked_t fscache_n_object_created;
59858 +atomic_unchecked_t fscache_n_object_avail;
59859 +atomic_unchecked_t fscache_n_object_dead;
59860
59861 -atomic_t fscache_n_checkaux_none;
59862 -atomic_t fscache_n_checkaux_okay;
59863 -atomic_t fscache_n_checkaux_update;
59864 -atomic_t fscache_n_checkaux_obsolete;
59865 +atomic_unchecked_t fscache_n_checkaux_none;
59866 +atomic_unchecked_t fscache_n_checkaux_okay;
59867 +atomic_unchecked_t fscache_n_checkaux_update;
59868 +atomic_unchecked_t fscache_n_checkaux_obsolete;
59869
59870 atomic_t fscache_n_cop_alloc_object;
59871 atomic_t fscache_n_cop_lookup_object;
59872 @@ -138,118 +138,118 @@ static int fscache_stats_show(struct seq_file *m, void *v)
59873 seq_puts(m, "FS-Cache statistics\n");
59874
59875 seq_printf(m, "Cookies: idx=%u dat=%u spc=%u\n",
59876 - atomic_read(&fscache_n_cookie_index),
59877 - atomic_read(&fscache_n_cookie_data),
59878 - atomic_read(&fscache_n_cookie_special));
59879 + atomic_read_unchecked(&fscache_n_cookie_index),
59880 + atomic_read_unchecked(&fscache_n_cookie_data),
59881 + atomic_read_unchecked(&fscache_n_cookie_special));
59882
59883 seq_printf(m, "Objects: alc=%u nal=%u avl=%u ded=%u\n",
59884 - atomic_read(&fscache_n_object_alloc),
59885 - atomic_read(&fscache_n_object_no_alloc),
59886 - atomic_read(&fscache_n_object_avail),
59887 - atomic_read(&fscache_n_object_dead));
59888 + atomic_read_unchecked(&fscache_n_object_alloc),
59889 + atomic_read_unchecked(&fscache_n_object_no_alloc),
59890 + atomic_read_unchecked(&fscache_n_object_avail),
59891 + atomic_read_unchecked(&fscache_n_object_dead));
59892 seq_printf(m, "ChkAux : non=%u ok=%u upd=%u obs=%u\n",
59893 - atomic_read(&fscache_n_checkaux_none),
59894 - atomic_read(&fscache_n_checkaux_okay),
59895 - atomic_read(&fscache_n_checkaux_update),
59896 - atomic_read(&fscache_n_checkaux_obsolete));
59897 + atomic_read_unchecked(&fscache_n_checkaux_none),
59898 + atomic_read_unchecked(&fscache_n_checkaux_okay),
59899 + atomic_read_unchecked(&fscache_n_checkaux_update),
59900 + atomic_read_unchecked(&fscache_n_checkaux_obsolete));
59901
59902 seq_printf(m, "Pages : mrk=%u unc=%u\n",
59903 - atomic_read(&fscache_n_marks),
59904 - atomic_read(&fscache_n_uncaches));
59905 + atomic_read_unchecked(&fscache_n_marks),
59906 + atomic_read_unchecked(&fscache_n_uncaches));
59907
59908 seq_printf(m, "Acquire: n=%u nul=%u noc=%u ok=%u nbf=%u"
59909 " oom=%u\n",
59910 - atomic_read(&fscache_n_acquires),
59911 - atomic_read(&fscache_n_acquires_null),
59912 - atomic_read(&fscache_n_acquires_no_cache),
59913 - atomic_read(&fscache_n_acquires_ok),
59914 - atomic_read(&fscache_n_acquires_nobufs),
59915 - atomic_read(&fscache_n_acquires_oom));
59916 + atomic_read_unchecked(&fscache_n_acquires),
59917 + atomic_read_unchecked(&fscache_n_acquires_null),
59918 + atomic_read_unchecked(&fscache_n_acquires_no_cache),
59919 + atomic_read_unchecked(&fscache_n_acquires_ok),
59920 + atomic_read_unchecked(&fscache_n_acquires_nobufs),
59921 + atomic_read_unchecked(&fscache_n_acquires_oom));
59922
59923 seq_printf(m, "Lookups: n=%u neg=%u pos=%u crt=%u tmo=%u\n",
59924 - atomic_read(&fscache_n_object_lookups),
59925 - atomic_read(&fscache_n_object_lookups_negative),
59926 - atomic_read(&fscache_n_object_lookups_positive),
59927 - atomic_read(&fscache_n_object_created),
59928 - atomic_read(&fscache_n_object_lookups_timed_out));
59929 + atomic_read_unchecked(&fscache_n_object_lookups),
59930 + atomic_read_unchecked(&fscache_n_object_lookups_negative),
59931 + atomic_read_unchecked(&fscache_n_object_lookups_positive),
59932 + atomic_read_unchecked(&fscache_n_object_created),
59933 + atomic_read_unchecked(&fscache_n_object_lookups_timed_out));
59934
59935 seq_printf(m, "Invals : n=%u run=%u\n",
59936 - atomic_read(&fscache_n_invalidates),
59937 - atomic_read(&fscache_n_invalidates_run));
59938 + atomic_read_unchecked(&fscache_n_invalidates),
59939 + atomic_read_unchecked(&fscache_n_invalidates_run));
59940
59941 seq_printf(m, "Updates: n=%u nul=%u run=%u\n",
59942 - atomic_read(&fscache_n_updates),
59943 - atomic_read(&fscache_n_updates_null),
59944 - atomic_read(&fscache_n_updates_run));
59945 + atomic_read_unchecked(&fscache_n_updates),
59946 + atomic_read_unchecked(&fscache_n_updates_null),
59947 + atomic_read_unchecked(&fscache_n_updates_run));
59948
59949 seq_printf(m, "Relinqs: n=%u nul=%u wcr=%u rtr=%u\n",
59950 - atomic_read(&fscache_n_relinquishes),
59951 - atomic_read(&fscache_n_relinquishes_null),
59952 - atomic_read(&fscache_n_relinquishes_waitcrt),
59953 - atomic_read(&fscache_n_relinquishes_retire));
59954 + atomic_read_unchecked(&fscache_n_relinquishes),
59955 + atomic_read_unchecked(&fscache_n_relinquishes_null),
59956 + atomic_read_unchecked(&fscache_n_relinquishes_waitcrt),
59957 + atomic_read_unchecked(&fscache_n_relinquishes_retire));
59958
59959 seq_printf(m, "AttrChg: n=%u ok=%u nbf=%u oom=%u run=%u\n",
59960 - atomic_read(&fscache_n_attr_changed),
59961 - atomic_read(&fscache_n_attr_changed_ok),
59962 - atomic_read(&fscache_n_attr_changed_nobufs),
59963 - atomic_read(&fscache_n_attr_changed_nomem),
59964 - atomic_read(&fscache_n_attr_changed_calls));
59965 + atomic_read_unchecked(&fscache_n_attr_changed),
59966 + atomic_read_unchecked(&fscache_n_attr_changed_ok),
59967 + atomic_read_unchecked(&fscache_n_attr_changed_nobufs),
59968 + atomic_read_unchecked(&fscache_n_attr_changed_nomem),
59969 + atomic_read_unchecked(&fscache_n_attr_changed_calls));
59970
59971 seq_printf(m, "Allocs : n=%u ok=%u wt=%u nbf=%u int=%u\n",
59972 - atomic_read(&fscache_n_allocs),
59973 - atomic_read(&fscache_n_allocs_ok),
59974 - atomic_read(&fscache_n_allocs_wait),
59975 - atomic_read(&fscache_n_allocs_nobufs),
59976 - atomic_read(&fscache_n_allocs_intr));
59977 + atomic_read_unchecked(&fscache_n_allocs),
59978 + atomic_read_unchecked(&fscache_n_allocs_ok),
59979 + atomic_read_unchecked(&fscache_n_allocs_wait),
59980 + atomic_read_unchecked(&fscache_n_allocs_nobufs),
59981 + atomic_read_unchecked(&fscache_n_allocs_intr));
59982 seq_printf(m, "Allocs : ops=%u owt=%u abt=%u\n",
59983 - atomic_read(&fscache_n_alloc_ops),
59984 - atomic_read(&fscache_n_alloc_op_waits),
59985 - atomic_read(&fscache_n_allocs_object_dead));
59986 + atomic_read_unchecked(&fscache_n_alloc_ops),
59987 + atomic_read_unchecked(&fscache_n_alloc_op_waits),
59988 + atomic_read_unchecked(&fscache_n_allocs_object_dead));
59989
59990 seq_printf(m, "Retrvls: n=%u ok=%u wt=%u nod=%u nbf=%u"
59991 " int=%u oom=%u\n",
59992 - atomic_read(&fscache_n_retrievals),
59993 - atomic_read(&fscache_n_retrievals_ok),
59994 - atomic_read(&fscache_n_retrievals_wait),
59995 - atomic_read(&fscache_n_retrievals_nodata),
59996 - atomic_read(&fscache_n_retrievals_nobufs),
59997 - atomic_read(&fscache_n_retrievals_intr),
59998 - atomic_read(&fscache_n_retrievals_nomem));
59999 + atomic_read_unchecked(&fscache_n_retrievals),
60000 + atomic_read_unchecked(&fscache_n_retrievals_ok),
60001 + atomic_read_unchecked(&fscache_n_retrievals_wait),
60002 + atomic_read_unchecked(&fscache_n_retrievals_nodata),
60003 + atomic_read_unchecked(&fscache_n_retrievals_nobufs),
60004 + atomic_read_unchecked(&fscache_n_retrievals_intr),
60005 + atomic_read_unchecked(&fscache_n_retrievals_nomem));
60006 seq_printf(m, "Retrvls: ops=%u owt=%u abt=%u\n",
60007 - atomic_read(&fscache_n_retrieval_ops),
60008 - atomic_read(&fscache_n_retrieval_op_waits),
60009 - atomic_read(&fscache_n_retrievals_object_dead));
60010 + atomic_read_unchecked(&fscache_n_retrieval_ops),
60011 + atomic_read_unchecked(&fscache_n_retrieval_op_waits),
60012 + atomic_read_unchecked(&fscache_n_retrievals_object_dead));
60013
60014 seq_printf(m, "Stores : n=%u ok=%u agn=%u nbf=%u oom=%u\n",
60015 - atomic_read(&fscache_n_stores),
60016 - atomic_read(&fscache_n_stores_ok),
60017 - atomic_read(&fscache_n_stores_again),
60018 - atomic_read(&fscache_n_stores_nobufs),
60019 - atomic_read(&fscache_n_stores_oom));
60020 + atomic_read_unchecked(&fscache_n_stores),
60021 + atomic_read_unchecked(&fscache_n_stores_ok),
60022 + atomic_read_unchecked(&fscache_n_stores_again),
60023 + atomic_read_unchecked(&fscache_n_stores_nobufs),
60024 + atomic_read_unchecked(&fscache_n_stores_oom));
60025 seq_printf(m, "Stores : ops=%u run=%u pgs=%u rxd=%u olm=%u\n",
60026 - atomic_read(&fscache_n_store_ops),
60027 - atomic_read(&fscache_n_store_calls),
60028 - atomic_read(&fscache_n_store_pages),
60029 - atomic_read(&fscache_n_store_radix_deletes),
60030 - atomic_read(&fscache_n_store_pages_over_limit));
60031 + atomic_read_unchecked(&fscache_n_store_ops),
60032 + atomic_read_unchecked(&fscache_n_store_calls),
60033 + atomic_read_unchecked(&fscache_n_store_pages),
60034 + atomic_read_unchecked(&fscache_n_store_radix_deletes),
60035 + atomic_read_unchecked(&fscache_n_store_pages_over_limit));
60036
60037 seq_printf(m, "VmScan : nos=%u gon=%u bsy=%u can=%u wt=%u\n",
60038 - atomic_read(&fscache_n_store_vmscan_not_storing),
60039 - atomic_read(&fscache_n_store_vmscan_gone),
60040 - atomic_read(&fscache_n_store_vmscan_busy),
60041 - atomic_read(&fscache_n_store_vmscan_cancelled),
60042 - atomic_read(&fscache_n_store_vmscan_wait));
60043 + atomic_read_unchecked(&fscache_n_store_vmscan_not_storing),
60044 + atomic_read_unchecked(&fscache_n_store_vmscan_gone),
60045 + atomic_read_unchecked(&fscache_n_store_vmscan_busy),
60046 + atomic_read_unchecked(&fscache_n_store_vmscan_cancelled),
60047 + atomic_read_unchecked(&fscache_n_store_vmscan_wait));
60048
60049 seq_printf(m, "Ops : pend=%u run=%u enq=%u can=%u rej=%u\n",
60050 - atomic_read(&fscache_n_op_pend),
60051 - atomic_read(&fscache_n_op_run),
60052 - atomic_read(&fscache_n_op_enqueue),
60053 - atomic_read(&fscache_n_op_cancelled),
60054 - atomic_read(&fscache_n_op_rejected));
60055 + atomic_read_unchecked(&fscache_n_op_pend),
60056 + atomic_read_unchecked(&fscache_n_op_run),
60057 + atomic_read_unchecked(&fscache_n_op_enqueue),
60058 + atomic_read_unchecked(&fscache_n_op_cancelled),
60059 + atomic_read_unchecked(&fscache_n_op_rejected));
60060 seq_printf(m, "Ops : dfr=%u rel=%u gc=%u\n",
60061 - atomic_read(&fscache_n_op_deferred_release),
60062 - atomic_read(&fscache_n_op_release),
60063 - atomic_read(&fscache_n_op_gc));
60064 + atomic_read_unchecked(&fscache_n_op_deferred_release),
60065 + atomic_read_unchecked(&fscache_n_op_release),
60066 + atomic_read_unchecked(&fscache_n_op_gc));
60067
60068 seq_printf(m, "CacheOp: alo=%d luo=%d luc=%d gro=%d\n",
60069 atomic_read(&fscache_n_cop_alloc_object),
60070 diff --git a/fs/fuse/cuse.c b/fs/fuse/cuse.c
60071 index b96a49b..9bfdc47 100644
60072 --- a/fs/fuse/cuse.c
60073 +++ b/fs/fuse/cuse.c
60074 @@ -606,10 +606,12 @@ static int __init cuse_init(void)
60075 INIT_LIST_HEAD(&cuse_conntbl[i]);
60076
60077 /* inherit and extend fuse_dev_operations */
60078 - cuse_channel_fops = fuse_dev_operations;
60079 - cuse_channel_fops.owner = THIS_MODULE;
60080 - cuse_channel_fops.open = cuse_channel_open;
60081 - cuse_channel_fops.release = cuse_channel_release;
60082 + pax_open_kernel();
60083 + memcpy((void *)&cuse_channel_fops, &fuse_dev_operations, sizeof(fuse_dev_operations));
60084 + *(void **)&cuse_channel_fops.owner = THIS_MODULE;
60085 + *(void **)&cuse_channel_fops.open = cuse_channel_open;
60086 + *(void **)&cuse_channel_fops.release = cuse_channel_release;
60087 + pax_close_kernel();
60088
60089 cuse_class = class_create(THIS_MODULE, "cuse");
60090 if (IS_ERR(cuse_class))
60091 diff --git a/fs/fuse/dev.c b/fs/fuse/dev.c
60092 index fa8cb4b..4acb935 100644
60093 --- a/fs/fuse/dev.c
60094 +++ b/fs/fuse/dev.c
60095 @@ -1323,7 +1323,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
60096 ret = 0;
60097 pipe_lock(pipe);
60098
60099 - if (!pipe->readers) {
60100 + if (!atomic_read(&pipe->readers)) {
60101 send_sig(SIGPIPE, current, 0);
60102 if (!ret)
60103 ret = -EPIPE;
60104 @@ -1352,7 +1352,7 @@ static ssize_t fuse_dev_splice_read(struct file *in, loff_t *ppos,
60105 page_nr++;
60106 ret += buf->len;
60107
60108 - if (pipe->files)
60109 + if (atomic_read(&pipe->files))
60110 do_wakeup = 1;
60111 }
60112
60113 diff --git a/fs/fuse/dir.c b/fs/fuse/dir.c
60114 index c3eb2c4..98007d4 100644
60115 --- a/fs/fuse/dir.c
60116 +++ b/fs/fuse/dir.c
60117 @@ -1408,7 +1408,7 @@ static char *read_link(struct dentry *dentry)
60118 return link;
60119 }
60120
60121 -static void free_link(char *link)
60122 +static void free_link(const char *link)
60123 {
60124 if (!IS_ERR(link))
60125 free_page((unsigned long) link);
60126 diff --git a/fs/hostfs/hostfs_kern.c b/fs/hostfs/hostfs_kern.c
60127 index db23ce1..9e6cd9d 100644
60128 --- a/fs/hostfs/hostfs_kern.c
60129 +++ b/fs/hostfs/hostfs_kern.c
60130 @@ -895,7 +895,7 @@ static void *hostfs_follow_link(struct dentry *dentry, struct nameidata *nd)
60131
60132 static void hostfs_put_link(struct dentry *dentry, struct nameidata *nd, void *cookie)
60133 {
60134 - char *s = nd_get_link(nd);
60135 + const char *s = nd_get_link(nd);
60136 if (!IS_ERR(s))
60137 __putname(s);
60138 }
60139 diff --git a/fs/hugetlbfs/inode.c b/fs/hugetlbfs/inode.c
60140 index d19b30a..ef89c36 100644
60141 --- a/fs/hugetlbfs/inode.c
60142 +++ b/fs/hugetlbfs/inode.c
60143 @@ -152,6 +152,7 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
60144 struct mm_struct *mm = current->mm;
60145 struct vm_area_struct *vma;
60146 struct hstate *h = hstate_file(file);
60147 + unsigned long offset = gr_rand_threadstack_offset(mm, file, flags);
60148 struct vm_unmapped_area_info info;
60149
60150 if (len & ~huge_page_mask(h))
60151 @@ -165,17 +166,26 @@ hugetlb_get_unmapped_area(struct file *file, unsigned long addr,
60152 return addr;
60153 }
60154
60155 +#ifdef CONFIG_PAX_RANDMMAP
60156 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
60157 +#endif
60158 +
60159 if (addr) {
60160 addr = ALIGN(addr, huge_page_size(h));
60161 vma = find_vma(mm, addr);
60162 - if (TASK_SIZE - len >= addr &&
60163 - (!vma || addr + len <= vma->vm_start))
60164 + if (TASK_SIZE - len >= addr && check_heap_stack_gap(vma, addr, len, offset))
60165 return addr;
60166 }
60167
60168 info.flags = 0;
60169 info.length = len;
60170 info.low_limit = TASK_UNMAPPED_BASE;
60171 +
60172 +#ifdef CONFIG_PAX_RANDMMAP
60173 + if (mm->pax_flags & MF_PAX_RANDMMAP)
60174 + info.low_limit += mm->delta_mmap;
60175 +#endif
60176 +
60177 info.high_limit = TASK_SIZE;
60178 info.align_mask = PAGE_MASK & ~huge_page_mask(h);
60179 info.align_offset = 0;
60180 @@ -908,7 +918,7 @@ static struct file_system_type hugetlbfs_fs_type = {
60181 };
60182 MODULE_ALIAS_FS("hugetlbfs");
60183
60184 -static struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
60185 +struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
60186
60187 static int can_do_hugetlb_shm(void)
60188 {
60189 diff --git a/fs/inode.c b/fs/inode.c
60190 index 4bcdad3..1883822 100644
60191 --- a/fs/inode.c
60192 +++ b/fs/inode.c
60193 @@ -841,8 +841,8 @@ unsigned int get_next_ino(void)
60194
60195 #ifdef CONFIG_SMP
60196 if (unlikely((res & (LAST_INO_BATCH-1)) == 0)) {
60197 - static atomic_t shared_last_ino;
60198 - int next = atomic_add_return(LAST_INO_BATCH, &shared_last_ino);
60199 + static atomic_unchecked_t shared_last_ino;
60200 + int next = atomic_add_return_unchecked(LAST_INO_BATCH, &shared_last_ino);
60201
60202 res = next - LAST_INO_BATCH;
60203 }
60204 diff --git a/fs/jffs2/erase.c b/fs/jffs2/erase.c
60205 index 4a6cf28..d3a29d3 100644
60206 --- a/fs/jffs2/erase.c
60207 +++ b/fs/jffs2/erase.c
60208 @@ -452,7 +452,8 @@ static void jffs2_mark_erased_block(struct jffs2_sb_info *c, struct jffs2_eraseb
60209 struct jffs2_unknown_node marker = {
60210 .magic = cpu_to_je16(JFFS2_MAGIC_BITMASK),
60211 .nodetype = cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
60212 - .totlen = cpu_to_je32(c->cleanmarker_size)
60213 + .totlen = cpu_to_je32(c->cleanmarker_size),
60214 + .hdr_crc = cpu_to_je32(0)
60215 };
60216
60217 jffs2_prealloc_raw_node_refs(c, jeb, 1);
60218 diff --git a/fs/jffs2/wbuf.c b/fs/jffs2/wbuf.c
60219 index a6597d6..41b30ec 100644
60220 --- a/fs/jffs2/wbuf.c
60221 +++ b/fs/jffs2/wbuf.c
60222 @@ -1023,7 +1023,8 @@ static const struct jffs2_unknown_node oob_cleanmarker =
60223 {
60224 .magic = constant_cpu_to_je16(JFFS2_MAGIC_BITMASK),
60225 .nodetype = constant_cpu_to_je16(JFFS2_NODETYPE_CLEANMARKER),
60226 - .totlen = constant_cpu_to_je32(8)
60227 + .totlen = constant_cpu_to_je32(8),
60228 + .hdr_crc = constant_cpu_to_je32(0)
60229 };
60230
60231 /*
60232 diff --git a/fs/jfs/super.c b/fs/jfs/super.c
60233 index 6669aa2..36b033d 100644
60234 --- a/fs/jfs/super.c
60235 +++ b/fs/jfs/super.c
60236 @@ -882,7 +882,7 @@ static int __init init_jfs_fs(void)
60237
60238 jfs_inode_cachep =
60239 kmem_cache_create("jfs_ip", sizeof(struct jfs_inode_info), 0,
60240 - SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD,
60241 + SLAB_RECLAIM_ACCOUNT|SLAB_MEM_SPREAD|SLAB_USERCOPY,
60242 init_once);
60243 if (jfs_inode_cachep == NULL)
60244 return -ENOMEM;
60245 diff --git a/fs/libfs.c b/fs/libfs.c
60246 index a184424..944ddce 100644
60247 --- a/fs/libfs.c
60248 +++ b/fs/libfs.c
60249 @@ -159,6 +159,9 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
60250
60251 for (p = q->next; p != &dentry->d_subdirs; p = p->next) {
60252 struct dentry *next = list_entry(p, struct dentry, d_u.d_child);
60253 + char d_name[sizeof(next->d_iname)];
60254 + const unsigned char *name;
60255 +
60256 spin_lock_nested(&next->d_lock, DENTRY_D_LOCK_NESTED);
60257 if (!simple_positive(next)) {
60258 spin_unlock(&next->d_lock);
60259 @@ -167,7 +170,12 @@ int dcache_readdir(struct file *file, struct dir_context *ctx)
60260
60261 spin_unlock(&next->d_lock);
60262 spin_unlock(&dentry->d_lock);
60263 - if (!dir_emit(ctx, next->d_name.name, next->d_name.len,
60264 + name = next->d_name.name;
60265 + if (name == next->d_iname) {
60266 + memcpy(d_name, name, next->d_name.len);
60267 + name = d_name;
60268 + }
60269 + if (!dir_emit(ctx, name, next->d_name.len,
60270 next->d_inode->i_ino, dt_type(next->d_inode)))
60271 return 0;
60272 spin_lock(&dentry->d_lock);
60273 @@ -999,7 +1007,7 @@ EXPORT_SYMBOL(noop_fsync);
60274 void kfree_put_link(struct dentry *dentry, struct nameidata *nd,
60275 void *cookie)
60276 {
60277 - char *s = nd_get_link(nd);
60278 + const char *s = nd_get_link(nd);
60279 if (!IS_ERR(s))
60280 kfree(s);
60281 }
60282 diff --git a/fs/lockd/clntproc.c b/fs/lockd/clntproc.c
60283 index acd3947..1f896e2 100644
60284 --- a/fs/lockd/clntproc.c
60285 +++ b/fs/lockd/clntproc.c
60286 @@ -36,11 +36,11 @@ static const struct rpc_call_ops nlmclnt_cancel_ops;
60287 /*
60288 * Cookie counter for NLM requests
60289 */
60290 -static atomic_t nlm_cookie = ATOMIC_INIT(0x1234);
60291 +static atomic_unchecked_t nlm_cookie = ATOMIC_INIT(0x1234);
60292
60293 void nlmclnt_next_cookie(struct nlm_cookie *c)
60294 {
60295 - u32 cookie = atomic_inc_return(&nlm_cookie);
60296 + u32 cookie = atomic_inc_return_unchecked(&nlm_cookie);
60297
60298 memcpy(c->data, &cookie, 4);
60299 c->len=4;
60300 diff --git a/fs/locks.c b/fs/locks.c
60301 index 92a0f0a..45a48f0 100644
60302 --- a/fs/locks.c
60303 +++ b/fs/locks.c
60304 @@ -2219,16 +2219,16 @@ void locks_remove_flock(struct file *filp)
60305 return;
60306
60307 if (filp->f_op->flock) {
60308 - struct file_lock fl = {
60309 + struct file_lock flock = {
60310 .fl_pid = current->tgid,
60311 .fl_file = filp,
60312 .fl_flags = FL_FLOCK,
60313 .fl_type = F_UNLCK,
60314 .fl_end = OFFSET_MAX,
60315 };
60316 - filp->f_op->flock(filp, F_SETLKW, &fl);
60317 - if (fl.fl_ops && fl.fl_ops->fl_release_private)
60318 - fl.fl_ops->fl_release_private(&fl);
60319 + filp->f_op->flock(filp, F_SETLKW, &flock);
60320 + if (flock.fl_ops && flock.fl_ops->fl_release_private)
60321 + flock.fl_ops->fl_release_private(&flock);
60322 }
60323
60324 spin_lock(&inode->i_lock);
60325 diff --git a/fs/mount.h b/fs/mount.h
60326 index a17458c..e69fb5b 100644
60327 --- a/fs/mount.h
60328 +++ b/fs/mount.h
60329 @@ -11,7 +11,7 @@ struct mnt_namespace {
60330 u64 seq; /* Sequence number to prevent loops */
60331 wait_queue_head_t poll;
60332 int event;
60333 -};
60334 +} __randomize_layout;
60335
60336 struct mnt_pcp {
60337 int mnt_count;
60338 @@ -57,7 +57,7 @@ struct mount {
60339 int mnt_expiry_mark; /* true if marked for expiry */
60340 int mnt_pinned;
60341 struct path mnt_ex_mountpoint;
60342 -};
60343 +} __randomize_layout;
60344
60345 #define MNT_NS_INTERNAL ERR_PTR(-EINVAL) /* distinct from any mnt_namespace */
60346
60347 diff --git a/fs/namei.c b/fs/namei.c
60348 index 3531dee..3177227 100644
60349 --- a/fs/namei.c
60350 +++ b/fs/namei.c
60351 @@ -319,16 +319,32 @@ int generic_permission(struct inode *inode, int mask)
60352 if (ret != -EACCES)
60353 return ret;
60354
60355 +#ifdef CONFIG_GRKERNSEC
60356 + /* we'll block if we have to log due to a denied capability use */
60357 + if (mask & MAY_NOT_BLOCK)
60358 + return -ECHILD;
60359 +#endif
60360 +
60361 if (S_ISDIR(inode->i_mode)) {
60362 /* DACs are overridable for directories */
60363 - if (inode_capable(inode, CAP_DAC_OVERRIDE))
60364 - return 0;
60365 if (!(mask & MAY_WRITE))
60366 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
60367 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
60368 + inode_capable(inode, CAP_DAC_READ_SEARCH))
60369 return 0;
60370 + if (inode_capable(inode, CAP_DAC_OVERRIDE))
60371 + return 0;
60372 return -EACCES;
60373 }
60374 /*
60375 + * Searching includes executable on directories, else just read.
60376 + */
60377 + mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
60378 + if (mask == MAY_READ)
60379 + if (inode_capable_nolog(inode, CAP_DAC_OVERRIDE) ||
60380 + inode_capable(inode, CAP_DAC_READ_SEARCH))
60381 + return 0;
60382 +
60383 + /*
60384 * Read/write DACs are always overridable.
60385 * Executable DACs are overridable when there is
60386 * at least one exec bit set.
60387 @@ -337,14 +353,6 @@ int generic_permission(struct inode *inode, int mask)
60388 if (inode_capable(inode, CAP_DAC_OVERRIDE))
60389 return 0;
60390
60391 - /*
60392 - * Searching includes executable on directories, else just read.
60393 - */
60394 - mask &= MAY_READ | MAY_WRITE | MAY_EXEC;
60395 - if (mask == MAY_READ)
60396 - if (inode_capable(inode, CAP_DAC_READ_SEARCH))
60397 - return 0;
60398 -
60399 return -EACCES;
60400 }
60401
60402 @@ -810,7 +818,7 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
60403 {
60404 struct dentry *dentry = link->dentry;
60405 int error;
60406 - char *s;
60407 + const char *s;
60408
60409 BUG_ON(nd->flags & LOOKUP_RCU);
60410
60411 @@ -831,6 +839,12 @@ follow_link(struct path *link, struct nameidata *nd, void **p)
60412 if (error)
60413 goto out_put_nd_path;
60414
60415 + if (gr_handle_follow_link(dentry->d_parent->d_inode,
60416 + dentry->d_inode, dentry, nd->path.mnt)) {
60417 + error = -EACCES;
60418 + goto out_put_nd_path;
60419 + }
60420 +
60421 nd->last_type = LAST_BIND;
60422 *p = dentry->d_inode->i_op->follow_link(dentry, nd);
60423 error = PTR_ERR(*p);
60424 @@ -1582,6 +1596,8 @@ static inline int nested_symlink(struct path *path, struct nameidata *nd)
60425 if (res)
60426 break;
60427 res = walk_component(nd, path, LOOKUP_FOLLOW);
60428 + if (res >= 0 && gr_handle_symlink_owner(&link, nd->inode))
60429 + res = -EACCES;
60430 put_link(nd, &link, cookie);
60431 } while (res > 0);
60432
60433 @@ -1655,7 +1671,7 @@ EXPORT_SYMBOL(full_name_hash);
60434 static inline unsigned long hash_name(const char *name, unsigned int *hashp)
60435 {
60436 unsigned long a, b, adata, bdata, mask, hash, len;
60437 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
60438 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
60439
60440 hash = a = 0;
60441 len = -sizeof(unsigned long);
60442 @@ -1939,6 +1955,8 @@ static int path_lookupat(int dfd, const char *name,
60443 if (err)
60444 break;
60445 err = lookup_last(nd, &path);
60446 + if (!err && gr_handle_symlink_owner(&link, nd->inode))
60447 + err = -EACCES;
60448 put_link(nd, &link, cookie);
60449 }
60450 }
60451 @@ -1946,6 +1964,13 @@ static int path_lookupat(int dfd, const char *name,
60452 if (!err)
60453 err = complete_walk(nd);
60454
60455 + if (!err && !(nd->flags & LOOKUP_PARENT)) {
60456 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
60457 + path_put(&nd->path);
60458 + err = -ENOENT;
60459 + }
60460 + }
60461 +
60462 if (!err && nd->flags & LOOKUP_DIRECTORY) {
60463 if (!d_is_directory(nd->path.dentry)) {
60464 path_put(&nd->path);
60465 @@ -1973,8 +1998,15 @@ static int filename_lookup(int dfd, struct filename *name,
60466 retval = path_lookupat(dfd, name->name,
60467 flags | LOOKUP_REVAL, nd);
60468
60469 - if (likely(!retval))
60470 + if (likely(!retval)) {
60471 audit_inode(name, nd->path.dentry, flags & LOOKUP_PARENT);
60472 + if (name->name[0] != '/' && nd->path.dentry && nd->inode) {
60473 + if (!gr_chroot_fchdir(nd->path.dentry, nd->path.mnt)) {
60474 + path_put(&nd->path);
60475 + return -ENOENT;
60476 + }
60477 + }
60478 + }
60479 return retval;
60480 }
60481
60482 @@ -2548,6 +2580,13 @@ static int may_open(struct path *path, int acc_mode, int flag)
60483 if (flag & O_NOATIME && !inode_owner_or_capable(inode))
60484 return -EPERM;
60485
60486 + if (gr_handle_rofs_blockwrite(dentry, path->mnt, acc_mode))
60487 + return -EPERM;
60488 + if (gr_handle_rawio(inode))
60489 + return -EPERM;
60490 + if (!gr_acl_handle_open(dentry, path->mnt, acc_mode))
60491 + return -EACCES;
60492 +
60493 return 0;
60494 }
60495
60496 @@ -2779,7 +2818,7 @@ looked_up:
60497 * cleared otherwise prior to returning.
60498 */
60499 static int lookup_open(struct nameidata *nd, struct path *path,
60500 - struct file *file,
60501 + struct path *link, struct file *file,
60502 const struct open_flags *op,
60503 bool got_write, int *opened)
60504 {
60505 @@ -2814,6 +2853,17 @@ static int lookup_open(struct nameidata *nd, struct path *path,
60506 /* Negative dentry, just create the file */
60507 if (!dentry->d_inode && (op->open_flag & O_CREAT)) {
60508 umode_t mode = op->mode;
60509 +
60510 + if (link && gr_handle_symlink_owner(link, dir->d_inode)) {
60511 + error = -EACCES;
60512 + goto out_dput;
60513 + }
60514 +
60515 + if (!gr_acl_handle_creat(dentry, dir, nd->path.mnt, op->open_flag, op->acc_mode, mode)) {
60516 + error = -EACCES;
60517 + goto out_dput;
60518 + }
60519 +
60520 if (!IS_POSIXACL(dir->d_inode))
60521 mode &= ~current_umask();
60522 /*
60523 @@ -2835,6 +2885,8 @@ static int lookup_open(struct nameidata *nd, struct path *path,
60524 nd->flags & LOOKUP_EXCL);
60525 if (error)
60526 goto out_dput;
60527 + else
60528 + gr_handle_create(dentry, nd->path.mnt);
60529 }
60530 out_no_open:
60531 path->dentry = dentry;
60532 @@ -2849,7 +2901,7 @@ out_dput:
60533 /*
60534 * Handle the last step of open()
60535 */
60536 -static int do_last(struct nameidata *nd, struct path *path,
60537 +static int do_last(struct nameidata *nd, struct path *path, struct path *link,
60538 struct file *file, const struct open_flags *op,
60539 int *opened, struct filename *name)
60540 {
60541 @@ -2899,6 +2951,15 @@ static int do_last(struct nameidata *nd, struct path *path,
60542 if (error)
60543 return error;
60544
60545 + if (!gr_acl_handle_hidden_file(dir, nd->path.mnt)) {
60546 + error = -ENOENT;
60547 + goto out;
60548 + }
60549 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
60550 + error = -EACCES;
60551 + goto out;
60552 + }
60553 +
60554 audit_inode(name, dir, LOOKUP_PARENT);
60555 error = -EISDIR;
60556 /* trailing slashes? */
60557 @@ -2918,7 +2979,7 @@ retry_lookup:
60558 */
60559 }
60560 mutex_lock(&dir->d_inode->i_mutex);
60561 - error = lookup_open(nd, path, file, op, got_write, opened);
60562 + error = lookup_open(nd, path, link, file, op, got_write, opened);
60563 mutex_unlock(&dir->d_inode->i_mutex);
60564
60565 if (error <= 0) {
60566 @@ -2942,11 +3003,28 @@ retry_lookup:
60567 goto finish_open_created;
60568 }
60569
60570 + if (!gr_acl_handle_hidden_file(path->dentry, nd->path.mnt)) {
60571 + error = -ENOENT;
60572 + goto exit_dput;
60573 + }
60574 + if (link && gr_handle_symlink_owner(link, path->dentry->d_inode)) {
60575 + error = -EACCES;
60576 + goto exit_dput;
60577 + }
60578 +
60579 /*
60580 * create/update audit record if it already exists.
60581 */
60582 - if (d_is_positive(path->dentry))
60583 + if (d_is_positive(path->dentry)) {
60584 + /* only check if O_CREAT is specified, all other checks need to go
60585 + into may_open */
60586 + if (gr_handle_fifo(path->dentry, path->mnt, dir, open_flag, acc_mode)) {
60587 + error = -EACCES;
60588 + goto exit_dput;
60589 + }
60590 +
60591 audit_inode(name, path->dentry, 0);
60592 + }
60593
60594 /*
60595 * If atomic_open() acquired write access it is dropped now due to
60596 @@ -2987,6 +3065,11 @@ finish_lookup:
60597 }
60598 }
60599 BUG_ON(inode != path->dentry->d_inode);
60600 + /* if we're resolving a symlink to another symlink */
60601 + if (link && gr_handle_symlink_owner(link, inode)) {
60602 + error = -EACCES;
60603 + goto out;
60604 + }
60605 return 1;
60606 }
60607
60608 @@ -2996,7 +3079,6 @@ finish_lookup:
60609 save_parent.dentry = nd->path.dentry;
60610 save_parent.mnt = mntget(path->mnt);
60611 nd->path.dentry = path->dentry;
60612 -
60613 }
60614 nd->inode = inode;
60615 /* Why this, you ask? _Now_ we might have grown LOOKUP_JUMPED... */
60616 @@ -3006,7 +3088,18 @@ finish_open:
60617 path_put(&save_parent);
60618 return error;
60619 }
60620 +
60621 + if (!gr_acl_handle_hidden_file(nd->path.dentry, nd->path.mnt)) {
60622 + error = -ENOENT;
60623 + goto out;
60624 + }
60625 + if (link && gr_handle_symlink_owner(link, nd->inode)) {
60626 + error = -EACCES;
60627 + goto out;
60628 + }
60629 +
60630 audit_inode(name, nd->path.dentry, 0);
60631 +
60632 error = -EISDIR;
60633 if ((open_flag & O_CREAT) &&
60634 (d_is_directory(nd->path.dentry) || d_is_autodir(nd->path.dentry)))
60635 @@ -3170,7 +3263,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
60636 if (unlikely(error))
60637 goto out;
60638
60639 - error = do_last(nd, &path, file, op, &opened, pathname);
60640 + error = do_last(nd, &path, NULL, file, op, &opened, pathname);
60641 while (unlikely(error > 0)) { /* trailing symlink */
60642 struct path link = path;
60643 void *cookie;
60644 @@ -3188,7 +3281,7 @@ static struct file *path_openat(int dfd, struct filename *pathname,
60645 error = follow_link(&link, nd, &cookie);
60646 if (unlikely(error))
60647 break;
60648 - error = do_last(nd, &path, file, op, &opened, pathname);
60649 + error = do_last(nd, &path, &link, file, op, &opened, pathname);
60650 put_link(nd, &link, cookie);
60651 }
60652 out:
60653 @@ -3288,9 +3381,11 @@ struct dentry *kern_path_create(int dfd, const char *pathname,
60654 goto unlock;
60655
60656 error = -EEXIST;
60657 - if (d_is_positive(dentry))
60658 + if (d_is_positive(dentry)) {
60659 + if (!gr_acl_handle_hidden_file(dentry, nd.path.mnt))
60660 + error = -ENOENT;
60661 goto fail;
60662 -
60663 + }
60664 /*
60665 * Special case - lookup gave negative, but... we had foo/bar/
60666 * From the vfs_mknod() POV we just have a negative dentry -
60667 @@ -3342,6 +3437,20 @@ struct dentry *user_path_create(int dfd, const char __user *pathname,
60668 }
60669 EXPORT_SYMBOL(user_path_create);
60670
60671 +static struct dentry *user_path_create_with_name(int dfd, const char __user *pathname, struct path *path, struct filename **to, unsigned int lookup_flags)
60672 +{
60673 + struct filename *tmp = getname(pathname);
60674 + struct dentry *res;
60675 + if (IS_ERR(tmp))
60676 + return ERR_CAST(tmp);
60677 + res = kern_path_create(dfd, tmp->name, path, lookup_flags);
60678 + if (IS_ERR(res))
60679 + putname(tmp);
60680 + else
60681 + *to = tmp;
60682 + return res;
60683 +}
60684 +
60685 int vfs_mknod(struct inode *dir, struct dentry *dentry, umode_t mode, dev_t dev)
60686 {
60687 int error = may_create(dir, dentry);
60688 @@ -3404,6 +3513,17 @@ retry:
60689
60690 if (!IS_POSIXACL(path.dentry->d_inode))
60691 mode &= ~current_umask();
60692 +
60693 + if (gr_handle_chroot_mknod(dentry, path.mnt, mode)) {
60694 + error = -EPERM;
60695 + goto out;
60696 + }
60697 +
60698 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
60699 + error = -EACCES;
60700 + goto out;
60701 + }
60702 +
60703 error = security_path_mknod(&path, dentry, mode, dev);
60704 if (error)
60705 goto out;
60706 @@ -3420,6 +3540,8 @@ retry:
60707 break;
60708 }
60709 out:
60710 + if (!error)
60711 + gr_handle_create(dentry, path.mnt);
60712 done_path_create(&path, dentry);
60713 if (retry_estale(error, lookup_flags)) {
60714 lookup_flags |= LOOKUP_REVAL;
60715 @@ -3472,9 +3594,16 @@ retry:
60716
60717 if (!IS_POSIXACL(path.dentry->d_inode))
60718 mode &= ~current_umask();
60719 + if (!gr_acl_handle_mkdir(dentry, path.dentry, path.mnt)) {
60720 + error = -EACCES;
60721 + goto out;
60722 + }
60723 error = security_path_mkdir(&path, dentry, mode);
60724 if (!error)
60725 error = vfs_mkdir(path.dentry->d_inode, dentry, mode);
60726 + if (!error)
60727 + gr_handle_create(dentry, path.mnt);
60728 +out:
60729 done_path_create(&path, dentry);
60730 if (retry_estale(error, lookup_flags)) {
60731 lookup_flags |= LOOKUP_REVAL;
60732 @@ -3555,6 +3684,8 @@ static long do_rmdir(int dfd, const char __user *pathname)
60733 struct filename *name;
60734 struct dentry *dentry;
60735 struct nameidata nd;
60736 + ino_t saved_ino = 0;
60737 + dev_t saved_dev = 0;
60738 unsigned int lookup_flags = 0;
60739 retry:
60740 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
60741 @@ -3587,10 +3718,21 @@ retry:
60742 error = -ENOENT;
60743 goto exit3;
60744 }
60745 +
60746 + saved_ino = dentry->d_inode->i_ino;
60747 + saved_dev = gr_get_dev_from_dentry(dentry);
60748 +
60749 + if (!gr_acl_handle_rmdir(dentry, nd.path.mnt)) {
60750 + error = -EACCES;
60751 + goto exit3;
60752 + }
60753 +
60754 error = security_path_rmdir(&nd.path, dentry);
60755 if (error)
60756 goto exit3;
60757 error = vfs_rmdir(nd.path.dentry->d_inode, dentry);
60758 + if (!error && (saved_dev || saved_ino))
60759 + gr_handle_delete(saved_ino, saved_dev);
60760 exit3:
60761 dput(dentry);
60762 exit2:
60763 @@ -3680,6 +3822,8 @@ static long do_unlinkat(int dfd, const char __user *pathname)
60764 struct nameidata nd;
60765 struct inode *inode = NULL;
60766 struct inode *delegated_inode = NULL;
60767 + ino_t saved_ino = 0;
60768 + dev_t saved_dev = 0;
60769 unsigned int lookup_flags = 0;
60770 retry:
60771 name = user_path_parent(dfd, pathname, &nd, lookup_flags);
60772 @@ -3706,10 +3850,22 @@ retry_deleg:
60773 if (d_is_negative(dentry))
60774 goto slashes;
60775 ihold(inode);
60776 +
60777 + if (inode->i_nlink <= 1) {
60778 + saved_ino = inode->i_ino;
60779 + saved_dev = gr_get_dev_from_dentry(dentry);
60780 + }
60781 + if (!gr_acl_handle_unlink(dentry, nd.path.mnt)) {
60782 + error = -EACCES;
60783 + goto exit2;
60784 + }
60785 +
60786 error = security_path_unlink(&nd.path, dentry);
60787 if (error)
60788 goto exit2;
60789 error = vfs_unlink(nd.path.dentry->d_inode, dentry, &delegated_inode);
60790 + if (!error && (saved_ino || saved_dev))
60791 + gr_handle_delete(saved_ino, saved_dev);
60792 exit2:
60793 dput(dentry);
60794 }
60795 @@ -3797,9 +3953,17 @@ retry:
60796 if (IS_ERR(dentry))
60797 goto out_putname;
60798
60799 + if (!gr_acl_handle_symlink(dentry, path.dentry, path.mnt, from)) {
60800 + error = -EACCES;
60801 + goto out;
60802 + }
60803 +
60804 error = security_path_symlink(&path, dentry, from->name);
60805 if (!error)
60806 error = vfs_symlink(path.dentry->d_inode, dentry, from->name);
60807 + if (!error)
60808 + gr_handle_create(dentry, path.mnt);
60809 +out:
60810 done_path_create(&path, dentry);
60811 if (retry_estale(error, lookup_flags)) {
60812 lookup_flags |= LOOKUP_REVAL;
60813 @@ -3902,6 +4066,7 @@ SYSCALL_DEFINE5(linkat, int, olddfd, const char __user *, oldname,
60814 struct dentry *new_dentry;
60815 struct path old_path, new_path;
60816 struct inode *delegated_inode = NULL;
60817 + struct filename *to = NULL;
60818 int how = 0;
60819 int error;
60820
60821 @@ -3925,7 +4090,7 @@ retry:
60822 if (error)
60823 return error;
60824
60825 - new_dentry = user_path_create(newdfd, newname, &new_path,
60826 + new_dentry = user_path_create_with_name(newdfd, newname, &new_path, &to,
60827 (how & LOOKUP_REVAL));
60828 error = PTR_ERR(new_dentry);
60829 if (IS_ERR(new_dentry))
60830 @@ -3937,11 +4102,28 @@ retry:
60831 error = may_linkat(&old_path);
60832 if (unlikely(error))
60833 goto out_dput;
60834 +
60835 + if (gr_handle_hardlink(old_path.dentry, old_path.mnt,
60836 + old_path.dentry->d_inode,
60837 + old_path.dentry->d_inode->i_mode, to)) {
60838 + error = -EACCES;
60839 + goto out_dput;
60840 + }
60841 +
60842 + if (!gr_acl_handle_link(new_dentry, new_path.dentry, new_path.mnt,
60843 + old_path.dentry, old_path.mnt, to)) {
60844 + error = -EACCES;
60845 + goto out_dput;
60846 + }
60847 +
60848 error = security_path_link(old_path.dentry, &new_path, new_dentry);
60849 if (error)
60850 goto out_dput;
60851 error = vfs_link(old_path.dentry, new_path.dentry->d_inode, new_dentry, &delegated_inode);
60852 + if (!error)
60853 + gr_handle_create(new_dentry, new_path.mnt);
60854 out_dput:
60855 + putname(to);
60856 done_path_create(&new_path, new_dentry);
60857 if (delegated_inode) {
60858 error = break_deleg_wait(&delegated_inode);
60859 @@ -4225,6 +4407,12 @@ retry_deleg:
60860 if (new_dentry == trap)
60861 goto exit5;
60862
60863 + error = gr_acl_handle_rename(new_dentry, new_dir, newnd.path.mnt,
60864 + old_dentry, old_dir->d_inode, oldnd.path.mnt,
60865 + to);
60866 + if (error)
60867 + goto exit5;
60868 +
60869 error = security_path_rename(&oldnd.path, old_dentry,
60870 &newnd.path, new_dentry);
60871 if (error)
60872 @@ -4232,6 +4420,9 @@ retry_deleg:
60873 error = vfs_rename(old_dir->d_inode, old_dentry,
60874 new_dir->d_inode, new_dentry,
60875 &delegated_inode);
60876 + if (!error)
60877 + gr_handle_rename(old_dir->d_inode, new_dir->d_inode, old_dentry,
60878 + new_dentry, oldnd.path.mnt, new_dentry->d_inode ? 1 : 0);
60879 exit5:
60880 dput(new_dentry);
60881 exit4:
60882 @@ -4268,6 +4459,8 @@ SYSCALL_DEFINE2(rename, const char __user *, oldname, const char __user *, newna
60883
60884 int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const char *link)
60885 {
60886 + char tmpbuf[64];
60887 + const char *newlink;
60888 int len;
60889
60890 len = PTR_ERR(link);
60891 @@ -4277,7 +4470,14 @@ int vfs_readlink(struct dentry *dentry, char __user *buffer, int buflen, const c
60892 len = strlen(link);
60893 if (len > (unsigned) buflen)
60894 len = buflen;
60895 - if (copy_to_user(buffer, link, len))
60896 +
60897 + if (len < sizeof(tmpbuf)) {
60898 + memcpy(tmpbuf, link, len);
60899 + newlink = tmpbuf;
60900 + } else
60901 + newlink = link;
60902 +
60903 + if (copy_to_user(buffer, newlink, len))
60904 len = -EFAULT;
60905 out:
60906 return len;
60907 diff --git a/fs/namespace.c b/fs/namespace.c
60908 index be32ebc..c595734 100644
60909 --- a/fs/namespace.c
60910 +++ b/fs/namespace.c
60911 @@ -1293,6 +1293,9 @@ static int do_umount(struct mount *mnt, int flags)
60912 if (!(sb->s_flags & MS_RDONLY))
60913 retval = do_remount_sb(sb, MS_RDONLY, NULL, 0);
60914 up_write(&sb->s_umount);
60915 +
60916 + gr_log_remount(mnt->mnt_devname, retval);
60917 +
60918 return retval;
60919 }
60920
60921 @@ -1315,6 +1318,9 @@ static int do_umount(struct mount *mnt, int flags)
60922 }
60923 unlock_mount_hash();
60924 namespace_unlock();
60925 +
60926 + gr_log_unmount(mnt->mnt_devname, retval);
60927 +
60928 return retval;
60929 }
60930
60931 @@ -1334,7 +1340,7 @@ static inline bool may_mount(void)
60932 * unixes. Our API is identical to OSF/1 to avoid making a mess of AMD
60933 */
60934
60935 -SYSCALL_DEFINE2(umount, char __user *, name, int, flags)
60936 +SYSCALL_DEFINE2(umount, const char __user *, name, int, flags)
60937 {
60938 struct path path;
60939 struct mount *mnt;
60940 @@ -1376,7 +1382,7 @@ out:
60941 /*
60942 * The 2.0 compatible umount. No flags.
60943 */
60944 -SYSCALL_DEFINE1(oldumount, char __user *, name)
60945 +SYSCALL_DEFINE1(oldumount, const char __user *, name)
60946 {
60947 return sys_umount(name, 0);
60948 }
60949 @@ -2379,6 +2385,16 @@ long do_mount(const char *dev_name, const char *dir_name,
60950 MS_NOATIME | MS_NODIRATIME | MS_RELATIME| MS_KERNMOUNT |
60951 MS_STRICTATIME);
60952
60953 + if (gr_handle_rofs_mount(path.dentry, path.mnt, mnt_flags)) {
60954 + retval = -EPERM;
60955 + goto dput_out;
60956 + }
60957 +
60958 + if (gr_handle_chroot_mount(path.dentry, path.mnt, dev_name)) {
60959 + retval = -EPERM;
60960 + goto dput_out;
60961 + }
60962 +
60963 if (flags & MS_REMOUNT)
60964 retval = do_remount(&path, flags & ~MS_REMOUNT, mnt_flags,
60965 data_page);
60966 @@ -2393,6 +2409,9 @@ long do_mount(const char *dev_name, const char *dir_name,
60967 dev_name, data_page);
60968 dput_out:
60969 path_put(&path);
60970 +
60971 + gr_log_mount(dev_name, dir_name, retval);
60972 +
60973 return retval;
60974 }
60975
60976 @@ -2410,7 +2429,7 @@ static void free_mnt_ns(struct mnt_namespace *ns)
60977 * number incrementing at 10Ghz will take 12,427 years to wrap which
60978 * is effectively never, so we can ignore the possibility.
60979 */
60980 -static atomic64_t mnt_ns_seq = ATOMIC64_INIT(1);
60981 +static atomic64_unchecked_t mnt_ns_seq = ATOMIC64_INIT(1);
60982
60983 static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
60984 {
60985 @@ -2425,7 +2444,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
60986 kfree(new_ns);
60987 return ERR_PTR(ret);
60988 }
60989 - new_ns->seq = atomic64_add_return(1, &mnt_ns_seq);
60990 + new_ns->seq = atomic64_inc_return_unchecked(&mnt_ns_seq);
60991 atomic_set(&new_ns->count, 1);
60992 new_ns->root = NULL;
60993 INIT_LIST_HEAD(&new_ns->list);
60994 @@ -2435,7 +2454,7 @@ static struct mnt_namespace *alloc_mnt_ns(struct user_namespace *user_ns)
60995 return new_ns;
60996 }
60997
60998 -struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
60999 +__latent_entropy struct mnt_namespace *copy_mnt_ns(unsigned long flags, struct mnt_namespace *ns,
61000 struct user_namespace *user_ns, struct fs_struct *new_fs)
61001 {
61002 struct mnt_namespace *new_ns;
61003 @@ -2556,8 +2575,8 @@ struct dentry *mount_subtree(struct vfsmount *mnt, const char *name)
61004 }
61005 EXPORT_SYMBOL(mount_subtree);
61006
61007 -SYSCALL_DEFINE5(mount, char __user *, dev_name, char __user *, dir_name,
61008 - char __user *, type, unsigned long, flags, void __user *, data)
61009 +SYSCALL_DEFINE5(mount, const char __user *, dev_name, const char __user *, dir_name,
61010 + const char __user *, type, unsigned long, flags, void __user *, data)
61011 {
61012 int ret;
61013 char *kernel_type;
61014 @@ -2670,6 +2689,11 @@ SYSCALL_DEFINE2(pivot_root, const char __user *, new_root,
61015 if (error)
61016 goto out2;
61017
61018 + if (gr_handle_chroot_pivot()) {
61019 + error = -EPERM;
61020 + goto out2;
61021 + }
61022 +
61023 get_fs_root(current->fs, &root);
61024 old_mp = lock_mount(&old);
61025 error = PTR_ERR(old_mp);
61026 @@ -2930,7 +2954,7 @@ static int mntns_install(struct nsproxy *nsproxy, void *ns)
61027 !ns_capable(current_user_ns(), CAP_SYS_ADMIN))
61028 return -EPERM;
61029
61030 - if (fs->users != 1)
61031 + if (atomic_read(&fs->users) != 1)
61032 return -EINVAL;
61033
61034 get_mnt_ns(mnt_ns);
61035 diff --git a/fs/nfs/callback_xdr.c b/fs/nfs/callback_xdr.c
61036 index f4ccfe6..a5cf064 100644
61037 --- a/fs/nfs/callback_xdr.c
61038 +++ b/fs/nfs/callback_xdr.c
61039 @@ -51,7 +51,7 @@ struct callback_op {
61040 callback_decode_arg_t decode_args;
61041 callback_encode_res_t encode_res;
61042 long res_maxsize;
61043 -};
61044 +} __do_const;
61045
61046 static struct callback_op callback_ops[];
61047
61048 diff --git a/fs/nfs/inode.c b/fs/nfs/inode.c
61049 index 00ad1c2..2fde15e 100644
61050 --- a/fs/nfs/inode.c
61051 +++ b/fs/nfs/inode.c
61052 @@ -1146,16 +1146,16 @@ static int nfs_size_need_update(const struct inode *inode, const struct nfs_fatt
61053 return nfs_size_to_loff_t(fattr->size) > i_size_read(inode);
61054 }
61055
61056 -static atomic_long_t nfs_attr_generation_counter;
61057 +static atomic_long_unchecked_t nfs_attr_generation_counter;
61058
61059 static unsigned long nfs_read_attr_generation_counter(void)
61060 {
61061 - return atomic_long_read(&nfs_attr_generation_counter);
61062 + return atomic_long_read_unchecked(&nfs_attr_generation_counter);
61063 }
61064
61065 unsigned long nfs_inc_attr_generation_counter(void)
61066 {
61067 - return atomic_long_inc_return(&nfs_attr_generation_counter);
61068 + return atomic_long_inc_return_unchecked(&nfs_attr_generation_counter);
61069 }
61070
61071 void nfs_fattr_init(struct nfs_fattr *fattr)
61072 diff --git a/fs/nfsd/nfs4proc.c b/fs/nfsd/nfs4proc.c
61073 index 419572f..5414a23 100644
61074 --- a/fs/nfsd/nfs4proc.c
61075 +++ b/fs/nfsd/nfs4proc.c
61076 @@ -1168,7 +1168,7 @@ struct nfsd4_operation {
61077 nfsd4op_rsize op_rsize_bop;
61078 stateid_getter op_get_currentstateid;
61079 stateid_setter op_set_currentstateid;
61080 -};
61081 +} __do_const;
61082
61083 static struct nfsd4_operation nfsd4_ops[];
61084
61085 diff --git a/fs/nfsd/nfs4xdr.c b/fs/nfsd/nfs4xdr.c
61086 index ee7237f..e3ae60a 100644
61087 --- a/fs/nfsd/nfs4xdr.c
61088 +++ b/fs/nfsd/nfs4xdr.c
61089 @@ -1523,7 +1523,7 @@ nfsd4_decode_notsupp(struct nfsd4_compoundargs *argp, void *p)
61090
61091 typedef __be32(*nfsd4_dec)(struct nfsd4_compoundargs *argp, void *);
61092
61093 -static nfsd4_dec nfsd4_dec_ops[] = {
61094 +static const nfsd4_dec nfsd4_dec_ops[] = {
61095 [OP_ACCESS] = (nfsd4_dec)nfsd4_decode_access,
61096 [OP_CLOSE] = (nfsd4_dec)nfsd4_decode_close,
61097 [OP_COMMIT] = (nfsd4_dec)nfsd4_decode_commit,
61098 diff --git a/fs/nfsd/nfscache.c b/fs/nfsd/nfscache.c
61099 index b6af150..f6ec5e3 100644
61100 --- a/fs/nfsd/nfscache.c
61101 +++ b/fs/nfsd/nfscache.c
61102 @@ -547,14 +547,17 @@ nfsd_cache_update(struct svc_rqst *rqstp, int cachetype, __be32 *statp)
61103 {
61104 struct svc_cacherep *rp = rqstp->rq_cacherep;
61105 struct kvec *resv = &rqstp->rq_res.head[0], *cachv;
61106 - int len;
61107 + long len;
61108 size_t bufsize = 0;
61109
61110 if (!rp)
61111 return;
61112
61113 - len = resv->iov_len - ((char*)statp - (char*)resv->iov_base);
61114 - len >>= 2;
61115 + if (statp) {
61116 + len = (char*)statp - (char*)resv->iov_base;
61117 + len = resv->iov_len - len;
61118 + len >>= 2;
61119 + }
61120
61121 /* Don't cache excessive amounts of data and XDR failures */
61122 if (!statp || len > (256 >> 2)) {
61123 diff --git a/fs/nfsd/vfs.c b/fs/nfsd/vfs.c
61124 index 7eea63c..a35f4fb 100644
61125 --- a/fs/nfsd/vfs.c
61126 +++ b/fs/nfsd/vfs.c
61127 @@ -993,7 +993,7 @@ nfsd_vfs_read(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
61128 } else {
61129 oldfs = get_fs();
61130 set_fs(KERNEL_DS);
61131 - host_err = vfs_readv(file, (struct iovec __user *)vec, vlen, &offset);
61132 + host_err = vfs_readv(file, (struct iovec __force_user *)vec, vlen, &offset);
61133 set_fs(oldfs);
61134 }
61135
61136 @@ -1084,7 +1084,7 @@ nfsd_vfs_write(struct svc_rqst *rqstp, struct svc_fh *fhp, struct file *file,
61137
61138 /* Write the data. */
61139 oldfs = get_fs(); set_fs(KERNEL_DS);
61140 - host_err = vfs_writev(file, (struct iovec __user *)vec, vlen, &pos);
61141 + host_err = vfs_writev(file, (struct iovec __force_user *)vec, vlen, &pos);
61142 set_fs(oldfs);
61143 if (host_err < 0)
61144 goto out_nfserr;
61145 @@ -1629,7 +1629,7 @@ nfsd_readlink(struct svc_rqst *rqstp, struct svc_fh *fhp, char *buf, int *lenp)
61146 */
61147
61148 oldfs = get_fs(); set_fs(KERNEL_DS);
61149 - host_err = inode->i_op->readlink(path.dentry, (char __user *)buf, *lenp);
61150 + host_err = inode->i_op->readlink(path.dentry, (char __force_user *)buf, *lenp);
61151 set_fs(oldfs);
61152
61153 if (host_err < 0)
61154 diff --git a/fs/nls/nls_base.c b/fs/nls/nls_base.c
61155 index fea6bd5..8ee9d81 100644
61156 --- a/fs/nls/nls_base.c
61157 +++ b/fs/nls/nls_base.c
61158 @@ -234,20 +234,22 @@ EXPORT_SYMBOL(utf16s_to_utf8s);
61159
61160 int register_nls(struct nls_table * nls)
61161 {
61162 - struct nls_table ** tmp = &tables;
61163 + struct nls_table *tmp = tables;
61164
61165 if (nls->next)
61166 return -EBUSY;
61167
61168 spin_lock(&nls_lock);
61169 - while (*tmp) {
61170 - if (nls == *tmp) {
61171 + while (tmp) {
61172 + if (nls == tmp) {
61173 spin_unlock(&nls_lock);
61174 return -EBUSY;
61175 }
61176 - tmp = &(*tmp)->next;
61177 + tmp = tmp->next;
61178 }
61179 - nls->next = tables;
61180 + pax_open_kernel();
61181 + *(struct nls_table **)&nls->next = tables;
61182 + pax_close_kernel();
61183 tables = nls;
61184 spin_unlock(&nls_lock);
61185 return 0;
61186 @@ -255,12 +257,14 @@ int register_nls(struct nls_table * nls)
61187
61188 int unregister_nls(struct nls_table * nls)
61189 {
61190 - struct nls_table ** tmp = &tables;
61191 + struct nls_table * const * tmp = &tables;
61192
61193 spin_lock(&nls_lock);
61194 while (*tmp) {
61195 if (nls == *tmp) {
61196 - *tmp = nls->next;
61197 + pax_open_kernel();
61198 + *(struct nls_table **)tmp = nls->next;
61199 + pax_close_kernel();
61200 spin_unlock(&nls_lock);
61201 return 0;
61202 }
61203 diff --git a/fs/nls/nls_euc-jp.c b/fs/nls/nls_euc-jp.c
61204 index 7424929..35f6be5 100644
61205 --- a/fs/nls/nls_euc-jp.c
61206 +++ b/fs/nls/nls_euc-jp.c
61207 @@ -561,8 +561,10 @@ static int __init init_nls_euc_jp(void)
61208 p_nls = load_nls("cp932");
61209
61210 if (p_nls) {
61211 - table.charset2upper = p_nls->charset2upper;
61212 - table.charset2lower = p_nls->charset2lower;
61213 + pax_open_kernel();
61214 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
61215 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
61216 + pax_close_kernel();
61217 return register_nls(&table);
61218 }
61219
61220 diff --git a/fs/nls/nls_koi8-ru.c b/fs/nls/nls_koi8-ru.c
61221 index e7bc1d7..06bd4bb 100644
61222 --- a/fs/nls/nls_koi8-ru.c
61223 +++ b/fs/nls/nls_koi8-ru.c
61224 @@ -63,8 +63,10 @@ static int __init init_nls_koi8_ru(void)
61225 p_nls = load_nls("koi8-u");
61226
61227 if (p_nls) {
61228 - table.charset2upper = p_nls->charset2upper;
61229 - table.charset2lower = p_nls->charset2lower;
61230 + pax_open_kernel();
61231 + *(const unsigned char **)&table.charset2upper = p_nls->charset2upper;
61232 + *(const unsigned char **)&table.charset2lower = p_nls->charset2lower;
61233 + pax_close_kernel();
61234 return register_nls(&table);
61235 }
61236
61237 diff --git a/fs/notify/fanotify/fanotify_user.c b/fs/notify/fanotify/fanotify_user.c
61238 index 6663511..7668ca4 100644
61239 --- a/fs/notify/fanotify/fanotify_user.c
61240 +++ b/fs/notify/fanotify/fanotify_user.c
61241 @@ -253,8 +253,8 @@ static ssize_t copy_event_to_user(struct fsnotify_group *group,
61242
61243 fd = fanotify_event_metadata.fd;
61244 ret = -EFAULT;
61245 - if (copy_to_user(buf, &fanotify_event_metadata,
61246 - fanotify_event_metadata.event_len))
61247 + if (fanotify_event_metadata.event_len > sizeof fanotify_event_metadata ||
61248 + copy_to_user(buf, &fanotify_event_metadata, fanotify_event_metadata.event_len))
61249 goto out_close_fd;
61250
61251 ret = prepare_for_access_response(group, event, fd);
61252 diff --git a/fs/notify/notification.c b/fs/notify/notification.c
61253 index 7b51b05..5ea5ef6 100644
61254 --- a/fs/notify/notification.c
61255 +++ b/fs/notify/notification.c
61256 @@ -57,7 +57,7 @@ static struct kmem_cache *fsnotify_event_holder_cachep;
61257 * get set to 0 so it will never get 'freed'
61258 */
61259 static struct fsnotify_event *q_overflow_event;
61260 -static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
61261 +static atomic_unchecked_t fsnotify_sync_cookie = ATOMIC_INIT(0);
61262
61263 /**
61264 * fsnotify_get_cookie - return a unique cookie for use in synchronizing events.
61265 @@ -65,7 +65,7 @@ static atomic_t fsnotify_sync_cookie = ATOMIC_INIT(0);
61266 */
61267 u32 fsnotify_get_cookie(void)
61268 {
61269 - return atomic_inc_return(&fsnotify_sync_cookie);
61270 + return atomic_inc_return_unchecked(&fsnotify_sync_cookie);
61271 }
61272 EXPORT_SYMBOL_GPL(fsnotify_get_cookie);
61273
61274 diff --git a/fs/ntfs/dir.c b/fs/ntfs/dir.c
61275 index 9e38daf..5727cae 100644
61276 --- a/fs/ntfs/dir.c
61277 +++ b/fs/ntfs/dir.c
61278 @@ -1310,7 +1310,7 @@ find_next_index_buffer:
61279 ia = (INDEX_ALLOCATION*)(kaddr + (ia_pos & ~PAGE_CACHE_MASK &
61280 ~(s64)(ndir->itype.index.block_size - 1)));
61281 /* Bounds checks. */
61282 - if (unlikely((u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
61283 + if (unlikely(!kaddr || (u8*)ia < kaddr || (u8*)ia > kaddr + PAGE_CACHE_SIZE)) {
61284 ntfs_error(sb, "Out of bounds check failed. Corrupt directory "
61285 "inode 0x%lx or driver bug.", vdir->i_ino);
61286 goto err_out;
61287 diff --git a/fs/ntfs/file.c b/fs/ntfs/file.c
61288 index ea4ba9d..1e13d34 100644
61289 --- a/fs/ntfs/file.c
61290 +++ b/fs/ntfs/file.c
61291 @@ -1282,7 +1282,7 @@ static inline size_t ntfs_copy_from_user(struct page **pages,
61292 char *addr;
61293 size_t total = 0;
61294 unsigned len;
61295 - int left;
61296 + unsigned left;
61297
61298 do {
61299 len = PAGE_CACHE_SIZE - ofs;
61300 diff --git a/fs/ntfs/super.c b/fs/ntfs/super.c
61301 index 82650d5..db37dcf 100644
61302 --- a/fs/ntfs/super.c
61303 +++ b/fs/ntfs/super.c
61304 @@ -685,7 +685,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
61305 if (!silent)
61306 ntfs_error(sb, "Primary boot sector is invalid.");
61307 } else if (!silent)
61308 - ntfs_error(sb, read_err_str, "primary");
61309 + ntfs_error(sb, read_err_str, "%s", "primary");
61310 if (!(NTFS_SB(sb)->on_errors & ON_ERRORS_RECOVER)) {
61311 if (bh_primary)
61312 brelse(bh_primary);
61313 @@ -701,7 +701,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
61314 goto hotfix_primary_boot_sector;
61315 brelse(bh_backup);
61316 } else if (!silent)
61317 - ntfs_error(sb, read_err_str, "backup");
61318 + ntfs_error(sb, read_err_str, "%s", "backup");
61319 /* Try to read NT3.51- backup boot sector. */
61320 if ((bh_backup = sb_bread(sb, nr_blocks >> 1))) {
61321 if (is_boot_sector_ntfs(sb, (NTFS_BOOT_SECTOR*)
61322 @@ -712,7 +712,7 @@ static struct buffer_head *read_ntfs_boot_sector(struct super_block *sb,
61323 "sector.");
61324 brelse(bh_backup);
61325 } else if (!silent)
61326 - ntfs_error(sb, read_err_str, "backup");
61327 + ntfs_error(sb, read_err_str, "%s", "backup");
61328 /* We failed. Cleanup and return. */
61329 if (bh_primary)
61330 brelse(bh_primary);
61331 diff --git a/fs/ocfs2/localalloc.c b/fs/ocfs2/localalloc.c
61332 index cd5496b..26a1055 100644
61333 --- a/fs/ocfs2/localalloc.c
61334 +++ b/fs/ocfs2/localalloc.c
61335 @@ -1278,7 +1278,7 @@ static int ocfs2_local_alloc_slide_window(struct ocfs2_super *osb,
61336 goto bail;
61337 }
61338
61339 - atomic_inc(&osb->alloc_stats.moves);
61340 + atomic_inc_unchecked(&osb->alloc_stats.moves);
61341
61342 bail:
61343 if (handle)
61344 diff --git a/fs/ocfs2/ocfs2.h b/fs/ocfs2/ocfs2.h
61345 index 3a90347..c40bef8 100644
61346 --- a/fs/ocfs2/ocfs2.h
61347 +++ b/fs/ocfs2/ocfs2.h
61348 @@ -235,11 +235,11 @@ enum ocfs2_vol_state
61349
61350 struct ocfs2_alloc_stats
61351 {
61352 - atomic_t moves;
61353 - atomic_t local_data;
61354 - atomic_t bitmap_data;
61355 - atomic_t bg_allocs;
61356 - atomic_t bg_extends;
61357 + atomic_unchecked_t moves;
61358 + atomic_unchecked_t local_data;
61359 + atomic_unchecked_t bitmap_data;
61360 + atomic_unchecked_t bg_allocs;
61361 + atomic_unchecked_t bg_extends;
61362 };
61363
61364 enum ocfs2_local_alloc_state
61365 diff --git a/fs/ocfs2/suballoc.c b/fs/ocfs2/suballoc.c
61366 index 2c91452..77a3cd2 100644
61367 --- a/fs/ocfs2/suballoc.c
61368 +++ b/fs/ocfs2/suballoc.c
61369 @@ -872,7 +872,7 @@ static int ocfs2_reserve_suballoc_bits(struct ocfs2_super *osb,
61370 mlog_errno(status);
61371 goto bail;
61372 }
61373 - atomic_inc(&osb->alloc_stats.bg_extends);
61374 + atomic_inc_unchecked(&osb->alloc_stats.bg_extends);
61375
61376 /* You should never ask for this much metadata */
61377 BUG_ON(bits_wanted >
61378 @@ -2000,7 +2000,7 @@ int ocfs2_claim_metadata(handle_t *handle,
61379 mlog_errno(status);
61380 goto bail;
61381 }
61382 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61383 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61384
61385 *suballoc_loc = res.sr_bg_blkno;
61386 *suballoc_bit_start = res.sr_bit_offset;
61387 @@ -2164,7 +2164,7 @@ int ocfs2_claim_new_inode_at_loc(handle_t *handle,
61388 trace_ocfs2_claim_new_inode_at_loc((unsigned long long)di_blkno,
61389 res->sr_bits);
61390
61391 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61392 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61393
61394 BUG_ON(res->sr_bits != 1);
61395
61396 @@ -2206,7 +2206,7 @@ int ocfs2_claim_new_inode(handle_t *handle,
61397 mlog_errno(status);
61398 goto bail;
61399 }
61400 - atomic_inc(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61401 + atomic_inc_unchecked(&OCFS2_SB(ac->ac_inode->i_sb)->alloc_stats.bg_allocs);
61402
61403 BUG_ON(res.sr_bits != 1);
61404
61405 @@ -2310,7 +2310,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
61406 cluster_start,
61407 num_clusters);
61408 if (!status)
61409 - atomic_inc(&osb->alloc_stats.local_data);
61410 + atomic_inc_unchecked(&osb->alloc_stats.local_data);
61411 } else {
61412 if (min_clusters > (osb->bitmap_cpg - 1)) {
61413 /* The only paths asking for contiguousness
61414 @@ -2336,7 +2336,7 @@ int __ocfs2_claim_clusters(handle_t *handle,
61415 ocfs2_desc_bitmap_to_cluster_off(ac->ac_inode,
61416 res.sr_bg_blkno,
61417 res.sr_bit_offset);
61418 - atomic_inc(&osb->alloc_stats.bitmap_data);
61419 + atomic_inc_unchecked(&osb->alloc_stats.bitmap_data);
61420 *num_clusters = res.sr_bits;
61421 }
61422 }
61423 diff --git a/fs/ocfs2/super.c b/fs/ocfs2/super.c
61424 index c414929..5c9ee542 100644
61425 --- a/fs/ocfs2/super.c
61426 +++ b/fs/ocfs2/super.c
61427 @@ -300,11 +300,11 @@ static int ocfs2_osb_dump(struct ocfs2_super *osb, char *buf, int len)
61428 "%10s => GlobalAllocs: %d LocalAllocs: %d "
61429 "SubAllocs: %d LAWinMoves: %d SAExtends: %d\n",
61430 "Stats",
61431 - atomic_read(&osb->alloc_stats.bitmap_data),
61432 - atomic_read(&osb->alloc_stats.local_data),
61433 - atomic_read(&osb->alloc_stats.bg_allocs),
61434 - atomic_read(&osb->alloc_stats.moves),
61435 - atomic_read(&osb->alloc_stats.bg_extends));
61436 + atomic_read_unchecked(&osb->alloc_stats.bitmap_data),
61437 + atomic_read_unchecked(&osb->alloc_stats.local_data),
61438 + atomic_read_unchecked(&osb->alloc_stats.bg_allocs),
61439 + atomic_read_unchecked(&osb->alloc_stats.moves),
61440 + atomic_read_unchecked(&osb->alloc_stats.bg_extends));
61441
61442 out += snprintf(buf + out, len - out,
61443 "%10s => State: %u Descriptor: %llu Size: %u bits "
61444 @@ -2121,11 +2121,11 @@ static int ocfs2_initialize_super(struct super_block *sb,
61445 spin_lock_init(&osb->osb_xattr_lock);
61446 ocfs2_init_steal_slots(osb);
61447
61448 - atomic_set(&osb->alloc_stats.moves, 0);
61449 - atomic_set(&osb->alloc_stats.local_data, 0);
61450 - atomic_set(&osb->alloc_stats.bitmap_data, 0);
61451 - atomic_set(&osb->alloc_stats.bg_allocs, 0);
61452 - atomic_set(&osb->alloc_stats.bg_extends, 0);
61453 + atomic_set_unchecked(&osb->alloc_stats.moves, 0);
61454 + atomic_set_unchecked(&osb->alloc_stats.local_data, 0);
61455 + atomic_set_unchecked(&osb->alloc_stats.bitmap_data, 0);
61456 + atomic_set_unchecked(&osb->alloc_stats.bg_allocs, 0);
61457 + atomic_set_unchecked(&osb->alloc_stats.bg_extends, 0);
61458
61459 /* Copy the blockcheck stats from the superblock probe */
61460 osb->osb_ecc_stats = *stats;
61461 diff --git a/fs/open.c b/fs/open.c
61462 index 4b3e1ed..1c84599 100644
61463 --- a/fs/open.c
61464 +++ b/fs/open.c
61465 @@ -32,6 +32,8 @@
61466 #include <linux/dnotify.h>
61467 #include <linux/compat.h>
61468
61469 +#define CREATE_TRACE_POINTS
61470 +#include <trace/events/fs.h>
61471 #include "internal.h"
61472
61473 int do_truncate(struct dentry *dentry, loff_t length, unsigned int time_attrs,
61474 @@ -103,6 +105,8 @@ long vfs_truncate(struct path *path, loff_t length)
61475 error = locks_verify_truncate(inode, NULL, length);
61476 if (!error)
61477 error = security_path_truncate(path);
61478 + if (!error && !gr_acl_handle_truncate(path->dentry, path->mnt))
61479 + error = -EACCES;
61480 if (!error)
61481 error = do_truncate(path->dentry, length, 0, NULL);
61482
61483 @@ -187,6 +191,8 @@ static long do_sys_ftruncate(unsigned int fd, loff_t length, int small)
61484 error = locks_verify_truncate(inode, f.file, length);
61485 if (!error)
61486 error = security_path_truncate(&f.file->f_path);
61487 + if (!error && !gr_acl_handle_truncate(f.file->f_path.dentry, f.file->f_path.mnt))
61488 + error = -EACCES;
61489 if (!error)
61490 error = do_truncate(dentry, length, ATTR_MTIME|ATTR_CTIME, f.file);
61491 sb_end_write(inode->i_sb);
61492 @@ -361,6 +367,9 @@ retry:
61493 if (__mnt_is_readonly(path.mnt))
61494 res = -EROFS;
61495
61496 + if (!res && !gr_acl_handle_access(path.dentry, path.mnt, mode))
61497 + res = -EACCES;
61498 +
61499 out_path_release:
61500 path_put(&path);
61501 if (retry_estale(res, lookup_flags)) {
61502 @@ -392,6 +401,8 @@ retry:
61503 if (error)
61504 goto dput_and_out;
61505
61506 + gr_log_chdir(path.dentry, path.mnt);
61507 +
61508 set_fs_pwd(current->fs, &path);
61509
61510 dput_and_out:
61511 @@ -421,6 +432,13 @@ SYSCALL_DEFINE1(fchdir, unsigned int, fd)
61512 goto out_putf;
61513
61514 error = inode_permission(inode, MAY_EXEC | MAY_CHDIR);
61515 +
61516 + if (!error && !gr_chroot_fchdir(f.file->f_path.dentry, f.file->f_path.mnt))
61517 + error = -EPERM;
61518 +
61519 + if (!error)
61520 + gr_log_chdir(f.file->f_path.dentry, f.file->f_path.mnt);
61521 +
61522 if (!error)
61523 set_fs_pwd(current->fs, &f.file->f_path);
61524 out_putf:
61525 @@ -450,7 +468,13 @@ retry:
61526 if (error)
61527 goto dput_and_out;
61528
61529 + if (gr_handle_chroot_chroot(path.dentry, path.mnt))
61530 + goto dput_and_out;
61531 +
61532 set_fs_root(current->fs, &path);
61533 +
61534 + gr_handle_chroot_chdir(&path);
61535 +
61536 error = 0;
61537 dput_and_out:
61538 path_put(&path);
61539 @@ -474,6 +498,16 @@ static int chmod_common(struct path *path, umode_t mode)
61540 return error;
61541 retry_deleg:
61542 mutex_lock(&inode->i_mutex);
61543 +
61544 + if (!gr_acl_handle_chmod(path->dentry, path->mnt, &mode)) {
61545 + error = -EACCES;
61546 + goto out_unlock;
61547 + }
61548 + if (gr_handle_chroot_chmod(path->dentry, path->mnt, mode)) {
61549 + error = -EACCES;
61550 + goto out_unlock;
61551 + }
61552 +
61553 error = security_path_chmod(path, mode);
61554 if (error)
61555 goto out_unlock;
61556 @@ -539,6 +573,9 @@ static int chown_common(struct path *path, uid_t user, gid_t group)
61557 uid = make_kuid(current_user_ns(), user);
61558 gid = make_kgid(current_user_ns(), group);
61559
61560 + if (!gr_acl_handle_chown(path->dentry, path->mnt))
61561 + return -EACCES;
61562 +
61563 newattrs.ia_valid = ATTR_CTIME;
61564 if (user != (uid_t) -1) {
61565 if (!uid_valid(uid))
61566 @@ -990,6 +1027,7 @@ long do_sys_open(int dfd, const char __user *filename, int flags, umode_t mode)
61567 } else {
61568 fsnotify_open(f);
61569 fd_install(fd, f);
61570 + trace_do_sys_open(tmp->name, flags, mode);
61571 }
61572 }
61573 putname(tmp);
61574 diff --git a/fs/pipe.c b/fs/pipe.c
61575 index 0e0752e..7cfdd50 100644
61576 --- a/fs/pipe.c
61577 +++ b/fs/pipe.c
61578 @@ -56,7 +56,7 @@ unsigned int pipe_min_size = PAGE_SIZE;
61579
61580 static void pipe_lock_nested(struct pipe_inode_info *pipe, int subclass)
61581 {
61582 - if (pipe->files)
61583 + if (atomic_read(&pipe->files))
61584 mutex_lock_nested(&pipe->mutex, subclass);
61585 }
61586
61587 @@ -71,7 +71,7 @@ EXPORT_SYMBOL(pipe_lock);
61588
61589 void pipe_unlock(struct pipe_inode_info *pipe)
61590 {
61591 - if (pipe->files)
61592 + if (atomic_read(&pipe->files))
61593 mutex_unlock(&pipe->mutex);
61594 }
61595 EXPORT_SYMBOL(pipe_unlock);
61596 @@ -449,9 +449,9 @@ redo:
61597 }
61598 if (bufs) /* More to do? */
61599 continue;
61600 - if (!pipe->writers)
61601 + if (!atomic_read(&pipe->writers))
61602 break;
61603 - if (!pipe->waiting_writers) {
61604 + if (!atomic_read(&pipe->waiting_writers)) {
61605 /* syscall merging: Usually we must not sleep
61606 * if O_NONBLOCK is set, or if we got some data.
61607 * But if a writer sleeps in kernel space, then
61608 @@ -513,7 +513,7 @@ pipe_write(struct kiocb *iocb, const struct iovec *_iov,
61609 ret = 0;
61610 __pipe_lock(pipe);
61611
61612 - if (!pipe->readers) {
61613 + if (!atomic_read(&pipe->readers)) {
61614 send_sig(SIGPIPE, current, 0);
61615 ret = -EPIPE;
61616 goto out;
61617 @@ -562,7 +562,7 @@ redo1:
61618 for (;;) {
61619 int bufs;
61620
61621 - if (!pipe->readers) {
61622 + if (!atomic_read(&pipe->readers)) {
61623 send_sig(SIGPIPE, current, 0);
61624 if (!ret)
61625 ret = -EPIPE;
61626 @@ -653,9 +653,9 @@ redo2:
61627 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
61628 do_wakeup = 0;
61629 }
61630 - pipe->waiting_writers++;
61631 + atomic_inc(&pipe->waiting_writers);
61632 pipe_wait(pipe);
61633 - pipe->waiting_writers--;
61634 + atomic_dec(&pipe->waiting_writers);
61635 }
61636 out:
61637 __pipe_unlock(pipe);
61638 @@ -709,7 +709,7 @@ pipe_poll(struct file *filp, poll_table *wait)
61639 mask = 0;
61640 if (filp->f_mode & FMODE_READ) {
61641 mask = (nrbufs > 0) ? POLLIN | POLLRDNORM : 0;
61642 - if (!pipe->writers && filp->f_version != pipe->w_counter)
61643 + if (!atomic_read(&pipe->writers) && filp->f_version != pipe->w_counter)
61644 mask |= POLLHUP;
61645 }
61646
61647 @@ -719,7 +719,7 @@ pipe_poll(struct file *filp, poll_table *wait)
61648 * Most Unices do not set POLLERR for FIFOs but on Linux they
61649 * behave exactly like pipes for poll().
61650 */
61651 - if (!pipe->readers)
61652 + if (!atomic_read(&pipe->readers))
61653 mask |= POLLERR;
61654 }
61655
61656 @@ -731,7 +731,7 @@ static void put_pipe_info(struct inode *inode, struct pipe_inode_info *pipe)
61657 int kill = 0;
61658
61659 spin_lock(&inode->i_lock);
61660 - if (!--pipe->files) {
61661 + if (atomic_dec_and_test(&pipe->files)) {
61662 inode->i_pipe = NULL;
61663 kill = 1;
61664 }
61665 @@ -748,11 +748,11 @@ pipe_release(struct inode *inode, struct file *file)
61666
61667 __pipe_lock(pipe);
61668 if (file->f_mode & FMODE_READ)
61669 - pipe->readers--;
61670 + atomic_dec(&pipe->readers);
61671 if (file->f_mode & FMODE_WRITE)
61672 - pipe->writers--;
61673 + atomic_dec(&pipe->writers);
61674
61675 - if (pipe->readers || pipe->writers) {
61676 + if (atomic_read(&pipe->readers) || atomic_read(&pipe->writers)) {
61677 wake_up_interruptible_sync_poll(&pipe->wait, POLLIN | POLLOUT | POLLRDNORM | POLLWRNORM | POLLERR | POLLHUP);
61678 kill_fasync(&pipe->fasync_readers, SIGIO, POLL_IN);
61679 kill_fasync(&pipe->fasync_writers, SIGIO, POLL_OUT);
61680 @@ -817,7 +817,7 @@ void free_pipe_info(struct pipe_inode_info *pipe)
61681 kfree(pipe);
61682 }
61683
61684 -static struct vfsmount *pipe_mnt __read_mostly;
61685 +struct vfsmount *pipe_mnt __read_mostly;
61686
61687 /*
61688 * pipefs_dname() is called from d_path().
61689 @@ -847,8 +847,9 @@ static struct inode * get_pipe_inode(void)
61690 goto fail_iput;
61691
61692 inode->i_pipe = pipe;
61693 - pipe->files = 2;
61694 - pipe->readers = pipe->writers = 1;
61695 + atomic_set(&pipe->files, 2);
61696 + atomic_set(&pipe->readers, 1);
61697 + atomic_set(&pipe->writers, 1);
61698 inode->i_fop = &pipefifo_fops;
61699
61700 /*
61701 @@ -1027,17 +1028,17 @@ static int fifo_open(struct inode *inode, struct file *filp)
61702 spin_lock(&inode->i_lock);
61703 if (inode->i_pipe) {
61704 pipe = inode->i_pipe;
61705 - pipe->files++;
61706 + atomic_inc(&pipe->files);
61707 spin_unlock(&inode->i_lock);
61708 } else {
61709 spin_unlock(&inode->i_lock);
61710 pipe = alloc_pipe_info();
61711 if (!pipe)
61712 return -ENOMEM;
61713 - pipe->files = 1;
61714 + atomic_set(&pipe->files, 1);
61715 spin_lock(&inode->i_lock);
61716 if (unlikely(inode->i_pipe)) {
61717 - inode->i_pipe->files++;
61718 + atomic_inc(&inode->i_pipe->files);
61719 spin_unlock(&inode->i_lock);
61720 free_pipe_info(pipe);
61721 pipe = inode->i_pipe;
61722 @@ -1062,10 +1063,10 @@ static int fifo_open(struct inode *inode, struct file *filp)
61723 * opened, even when there is no process writing the FIFO.
61724 */
61725 pipe->r_counter++;
61726 - if (pipe->readers++ == 0)
61727 + if (atomic_inc_return(&pipe->readers) == 1)
61728 wake_up_partner(pipe);
61729
61730 - if (!is_pipe && !pipe->writers) {
61731 + if (!is_pipe && !atomic_read(&pipe->writers)) {
61732 if ((filp->f_flags & O_NONBLOCK)) {
61733 /* suppress POLLHUP until we have
61734 * seen a writer */
61735 @@ -1084,14 +1085,14 @@ static int fifo_open(struct inode *inode, struct file *filp)
61736 * errno=ENXIO when there is no process reading the FIFO.
61737 */
61738 ret = -ENXIO;
61739 - if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !pipe->readers)
61740 + if (!is_pipe && (filp->f_flags & O_NONBLOCK) && !atomic_read(&pipe->readers))
61741 goto err;
61742
61743 pipe->w_counter++;
61744 - if (!pipe->writers++)
61745 + if (atomic_inc_return(&pipe->writers) == 1)
61746 wake_up_partner(pipe);
61747
61748 - if (!is_pipe && !pipe->readers) {
61749 + if (!is_pipe && !atomic_read(&pipe->readers)) {
61750 if (wait_for_partner(pipe, &pipe->r_counter))
61751 goto err_wr;
61752 }
61753 @@ -1105,11 +1106,11 @@ static int fifo_open(struct inode *inode, struct file *filp)
61754 * the process can at least talk to itself.
61755 */
61756
61757 - pipe->readers++;
61758 - pipe->writers++;
61759 + atomic_inc(&pipe->readers);
61760 + atomic_inc(&pipe->writers);
61761 pipe->r_counter++;
61762 pipe->w_counter++;
61763 - if (pipe->readers == 1 || pipe->writers == 1)
61764 + if (atomic_read(&pipe->readers) == 1 || atomic_read(&pipe->writers) == 1)
61765 wake_up_partner(pipe);
61766 break;
61767
61768 @@ -1123,13 +1124,13 @@ static int fifo_open(struct inode *inode, struct file *filp)
61769 return 0;
61770
61771 err_rd:
61772 - if (!--pipe->readers)
61773 + if (atomic_dec_and_test(&pipe->readers))
61774 wake_up_interruptible(&pipe->wait);
61775 ret = -ERESTARTSYS;
61776 goto err;
61777
61778 err_wr:
61779 - if (!--pipe->writers)
61780 + if (atomic_dec_and_test(&pipe->writers))
61781 wake_up_interruptible(&pipe->wait);
61782 ret = -ERESTARTSYS;
61783 goto err;
61784 diff --git a/fs/proc/Kconfig b/fs/proc/Kconfig
61785 index 2183fcf..3c32a98 100644
61786 --- a/fs/proc/Kconfig
61787 +++ b/fs/proc/Kconfig
61788 @@ -30,7 +30,7 @@ config PROC_FS
61789
61790 config PROC_KCORE
61791 bool "/proc/kcore support" if !ARM
61792 - depends on PROC_FS && MMU
61793 + depends on PROC_FS && MMU && !GRKERNSEC_PROC_ADD
61794 help
61795 Provides a virtual ELF core file of the live kernel. This can
61796 be read with gdb and other ELF tools. No modifications can be
61797 @@ -38,8 +38,8 @@ config PROC_KCORE
61798
61799 config PROC_VMCORE
61800 bool "/proc/vmcore support"
61801 - depends on PROC_FS && CRASH_DUMP
61802 - default y
61803 + depends on PROC_FS && CRASH_DUMP && !GRKERNSEC
61804 + default n
61805 help
61806 Exports the dump image of crashed kernel in ELF format.
61807
61808 @@ -63,8 +63,8 @@ config PROC_SYSCTL
61809 limited in memory.
61810
61811 config PROC_PAGE_MONITOR
61812 - default y
61813 - depends on PROC_FS && MMU
61814 + default n
61815 + depends on PROC_FS && MMU && !GRKERNSEC
61816 bool "Enable /proc page monitoring" if EXPERT
61817 help
61818 Various /proc files exist to monitor process memory utilization:
61819 diff --git a/fs/proc/array.c b/fs/proc/array.c
61820 index 1bd2077..2f7cfd5 100644
61821 --- a/fs/proc/array.c
61822 +++ b/fs/proc/array.c
61823 @@ -60,6 +60,7 @@
61824 #include <linux/tty.h>
61825 #include <linux/string.h>
61826 #include <linux/mman.h>
61827 +#include <linux/grsecurity.h>
61828 #include <linux/proc_fs.h>
61829 #include <linux/ioport.h>
61830 #include <linux/uaccess.h>
61831 @@ -365,6 +366,21 @@ static void task_cpus_allowed(struct seq_file *m, struct task_struct *task)
61832 seq_putc(m, '\n');
61833 }
61834
61835 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
61836 +static inline void task_pax(struct seq_file *m, struct task_struct *p)
61837 +{
61838 + if (p->mm)
61839 + seq_printf(m, "PaX:\t%c%c%c%c%c\n",
61840 + p->mm->pax_flags & MF_PAX_PAGEEXEC ? 'P' : 'p',
61841 + p->mm->pax_flags & MF_PAX_EMUTRAMP ? 'E' : 'e',
61842 + p->mm->pax_flags & MF_PAX_MPROTECT ? 'M' : 'm',
61843 + p->mm->pax_flags & MF_PAX_RANDMMAP ? 'R' : 'r',
61844 + p->mm->pax_flags & MF_PAX_SEGMEXEC ? 'S' : 's');
61845 + else
61846 + seq_printf(m, "PaX:\t-----\n");
61847 +}
61848 +#endif
61849 +
61850 int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
61851 struct pid *pid, struct task_struct *task)
61852 {
61853 @@ -383,9 +399,24 @@ int proc_pid_status(struct seq_file *m, struct pid_namespace *ns,
61854 task_cpus_allowed(m, task);
61855 cpuset_task_status_allowed(m, task);
61856 task_context_switch_counts(m, task);
61857 +
61858 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
61859 + task_pax(m, task);
61860 +#endif
61861 +
61862 +#if defined(CONFIG_GRKERNSEC) && !defined(CONFIG_GRKERNSEC_NO_RBAC)
61863 + task_grsec_rbac(m, task);
61864 +#endif
61865 +
61866 return 0;
61867 }
61868
61869 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61870 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
61871 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
61872 + _mm->pax_flags & MF_PAX_SEGMEXEC))
61873 +#endif
61874 +
61875 static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61876 struct pid *pid, struct task_struct *task, int whole)
61877 {
61878 @@ -407,6 +438,13 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61879 char tcomm[sizeof(task->comm)];
61880 unsigned long flags;
61881
61882 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61883 + if (current->exec_id != m->exec_id) {
61884 + gr_log_badprocpid("stat");
61885 + return 0;
61886 + }
61887 +#endif
61888 +
61889 state = *get_task_state(task);
61890 vsize = eip = esp = 0;
61891 permitted = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
61892 @@ -478,6 +516,19 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61893 gtime = task_gtime(task);
61894 }
61895
61896 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61897 + if (PAX_RAND_FLAGS(mm)) {
61898 + eip = 0;
61899 + esp = 0;
61900 + wchan = 0;
61901 + }
61902 +#endif
61903 +#ifdef CONFIG_GRKERNSEC_HIDESYM
61904 + wchan = 0;
61905 + eip =0;
61906 + esp =0;
61907 +#endif
61908 +
61909 /* scale priority and nice values from timeslices to -20..20 */
61910 /* to make it look like a "normal" Unix priority/nice value */
61911 priority = task_prio(task);
61912 @@ -514,9 +565,15 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61913 seq_put_decimal_ull(m, ' ', vsize);
61914 seq_put_decimal_ull(m, ' ', mm ? get_mm_rss(mm) : 0);
61915 seq_put_decimal_ull(m, ' ', rsslim);
61916 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61917 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->start_code : 1) : 0));
61918 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 1 : (mm ? (permitted ? mm->end_code : 1) : 0));
61919 + seq_put_decimal_ull(m, ' ', PAX_RAND_FLAGS(mm) ? 0 : ((permitted && mm) ? mm->start_stack : 0));
61920 +#else
61921 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->start_code : 1) : 0);
61922 seq_put_decimal_ull(m, ' ', mm ? (permitted ? mm->end_code : 1) : 0);
61923 seq_put_decimal_ull(m, ' ', (permitted && mm) ? mm->start_stack : 0);
61924 +#endif
61925 seq_put_decimal_ull(m, ' ', esp);
61926 seq_put_decimal_ull(m, ' ', eip);
61927 /* The signal information here is obsolete.
61928 @@ -538,7 +595,11 @@ static int do_task_stat(struct seq_file *m, struct pid_namespace *ns,
61929 seq_put_decimal_ull(m, ' ', cputime_to_clock_t(gtime));
61930 seq_put_decimal_ll(m, ' ', cputime_to_clock_t(cgtime));
61931
61932 - if (mm && permitted) {
61933 + if (mm && permitted
61934 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61935 + && !PAX_RAND_FLAGS(mm)
61936 +#endif
61937 + ) {
61938 seq_put_decimal_ull(m, ' ', mm->start_data);
61939 seq_put_decimal_ull(m, ' ', mm->end_data);
61940 seq_put_decimal_ull(m, ' ', mm->start_brk);
61941 @@ -576,8 +637,15 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
61942 struct pid *pid, struct task_struct *task)
61943 {
61944 unsigned long size = 0, resident = 0, shared = 0, text = 0, data = 0;
61945 - struct mm_struct *mm = get_task_mm(task);
61946 + struct mm_struct *mm;
61947
61948 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
61949 + if (current->exec_id != m->exec_id) {
61950 + gr_log_badprocpid("statm");
61951 + return 0;
61952 + }
61953 +#endif
61954 + mm = get_task_mm(task);
61955 if (mm) {
61956 size = task_statm(mm, &shared, &text, &data, &resident);
61957 mmput(mm);
61958 @@ -600,6 +668,13 @@ int proc_pid_statm(struct seq_file *m, struct pid_namespace *ns,
61959 return 0;
61960 }
61961
61962 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
61963 +int proc_pid_ipaddr(struct task_struct *task, char *buffer)
61964 +{
61965 + return sprintf(buffer, "%pI4\n", &task->signal->curr_ip);
61966 +}
61967 +#endif
61968 +
61969 #ifdef CONFIG_CHECKPOINT_RESTORE
61970 static struct pid *
61971 get_children_pid(struct inode *inode, struct pid *pid_prev, loff_t pos)
61972 diff --git a/fs/proc/base.c b/fs/proc/base.c
61973 index 03c8d74..4efb575 100644
61974 --- a/fs/proc/base.c
61975 +++ b/fs/proc/base.c
61976 @@ -113,6 +113,14 @@ struct pid_entry {
61977 union proc_op op;
61978 };
61979
61980 +struct getdents_callback {
61981 + struct linux_dirent __user * current_dir;
61982 + struct linux_dirent __user * previous;
61983 + struct file * file;
61984 + int count;
61985 + int error;
61986 +};
61987 +
61988 #define NOD(NAME, MODE, IOP, FOP, OP) { \
61989 .name = (NAME), \
61990 .len = sizeof(NAME) - 1, \
61991 @@ -210,6 +218,9 @@ static int proc_pid_cmdline(struct task_struct *task, char * buffer)
61992 if (!mm->arg_end)
61993 goto out_mm; /* Shh! No looking before we're done */
61994
61995 + if (gr_acl_handle_procpidmem(task))
61996 + goto out_mm;
61997 +
61998 len = mm->arg_end - mm->arg_start;
61999
62000 if (len > PAGE_SIZE)
62001 @@ -237,12 +248,28 @@ out:
62002 return res;
62003 }
62004
62005 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62006 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
62007 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
62008 + _mm->pax_flags & MF_PAX_SEGMEXEC))
62009 +#endif
62010 +
62011 static int proc_pid_auxv(struct task_struct *task, char *buffer)
62012 {
62013 struct mm_struct *mm = mm_access(task, PTRACE_MODE_READ);
62014 int res = PTR_ERR(mm);
62015 if (mm && !IS_ERR(mm)) {
62016 unsigned int nwords = 0;
62017 +
62018 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62019 + /* allow if we're currently ptracing this task */
62020 + if (PAX_RAND_FLAGS(mm) &&
62021 + (!(task->ptrace & PT_PTRACED) || (task->parent != current))) {
62022 + mmput(mm);
62023 + return 0;
62024 + }
62025 +#endif
62026 +
62027 do {
62028 nwords += 2;
62029 } while (mm->saved_auxv[nwords - 2] != 0); /* AT_NULL */
62030 @@ -256,7 +283,7 @@ static int proc_pid_auxv(struct task_struct *task, char *buffer)
62031 }
62032
62033
62034 -#ifdef CONFIG_KALLSYMS
62035 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62036 /*
62037 * Provides a wchan file via kallsyms in a proper one-value-per-file format.
62038 * Returns the resolved symbol. If that fails, simply return the address.
62039 @@ -295,7 +322,7 @@ static void unlock_trace(struct task_struct *task)
62040 mutex_unlock(&task->signal->cred_guard_mutex);
62041 }
62042
62043 -#ifdef CONFIG_STACKTRACE
62044 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62045
62046 #define MAX_STACK_TRACE_DEPTH 64
62047
62048 @@ -518,7 +545,7 @@ static int proc_pid_limits(struct task_struct *task, char *buffer)
62049 return count;
62050 }
62051
62052 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
62053 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
62054 static int proc_pid_syscall(struct task_struct *task, char *buffer)
62055 {
62056 long nr;
62057 @@ -547,7 +574,7 @@ static int proc_pid_syscall(struct task_struct *task, char *buffer)
62058 /************************************************************************/
62059
62060 /* permission checks */
62061 -static int proc_fd_access_allowed(struct inode *inode)
62062 +static int proc_fd_access_allowed(struct inode *inode, unsigned int log)
62063 {
62064 struct task_struct *task;
62065 int allowed = 0;
62066 @@ -557,7 +584,10 @@ static int proc_fd_access_allowed(struct inode *inode)
62067 */
62068 task = get_proc_task(inode);
62069 if (task) {
62070 - allowed = ptrace_may_access(task, PTRACE_MODE_READ);
62071 + if (log)
62072 + allowed = ptrace_may_access(task, PTRACE_MODE_READ);
62073 + else
62074 + allowed = ptrace_may_access(task, PTRACE_MODE_READ | PTRACE_MODE_NOAUDIT);
62075 put_task_struct(task);
62076 }
62077 return allowed;
62078 @@ -588,10 +618,35 @@ static bool has_pid_permissions(struct pid_namespace *pid,
62079 struct task_struct *task,
62080 int hide_pid_min)
62081 {
62082 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
62083 + return false;
62084 +
62085 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62086 + rcu_read_lock();
62087 + {
62088 + const struct cred *tmpcred = current_cred();
62089 + const struct cred *cred = __task_cred(task);
62090 +
62091 + if (uid_eq(tmpcred->uid, GLOBAL_ROOT_UID) || uid_eq(tmpcred->uid, cred->uid)
62092 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62093 + || in_group_p(grsec_proc_gid)
62094 +#endif
62095 + ) {
62096 + rcu_read_unlock();
62097 + return true;
62098 + }
62099 + }
62100 + rcu_read_unlock();
62101 +
62102 + if (!pid->hide_pid)
62103 + return false;
62104 +#endif
62105 +
62106 if (pid->hide_pid < hide_pid_min)
62107 return true;
62108 if (in_group_p(pid->pid_gid))
62109 return true;
62110 +
62111 return ptrace_may_access(task, PTRACE_MODE_READ);
62112 }
62113
62114 @@ -609,7 +664,11 @@ static int proc_pid_permission(struct inode *inode, int mask)
62115 put_task_struct(task);
62116
62117 if (!has_perms) {
62118 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62119 + {
62120 +#else
62121 if (pid->hide_pid == 2) {
62122 +#endif
62123 /*
62124 * Let's make getdents(), stat(), and open()
62125 * consistent with each other. If a process
62126 @@ -707,6 +766,11 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
62127 if (!task)
62128 return -ESRCH;
62129
62130 + if (gr_acl_handle_procpidmem(task)) {
62131 + put_task_struct(task);
62132 + return -EPERM;
62133 + }
62134 +
62135 mm = mm_access(task, mode);
62136 put_task_struct(task);
62137
62138 @@ -722,6 +786,10 @@ static int __mem_open(struct inode *inode, struct file *file, unsigned int mode)
62139
62140 file->private_data = mm;
62141
62142 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62143 + file->f_version = current->exec_id;
62144 +#endif
62145 +
62146 return 0;
62147 }
62148
62149 @@ -743,6 +811,17 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
62150 ssize_t copied;
62151 char *page;
62152
62153 +#ifdef CONFIG_GRKERNSEC
62154 + if (write)
62155 + return -EPERM;
62156 +#endif
62157 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62158 + if (file->f_version != current->exec_id) {
62159 + gr_log_badprocpid("mem");
62160 + return 0;
62161 + }
62162 +#endif
62163 +
62164 if (!mm)
62165 return 0;
62166
62167 @@ -755,7 +834,7 @@ static ssize_t mem_rw(struct file *file, char __user *buf,
62168 goto free;
62169
62170 while (count > 0) {
62171 - int this_len = min_t(int, count, PAGE_SIZE);
62172 + ssize_t this_len = min_t(ssize_t, count, PAGE_SIZE);
62173
62174 if (write && copy_from_user(page, buf, this_len)) {
62175 copied = -EFAULT;
62176 @@ -847,6 +926,13 @@ static ssize_t environ_read(struct file *file, char __user *buf,
62177 if (!mm)
62178 return 0;
62179
62180 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62181 + if (file->f_version != current->exec_id) {
62182 + gr_log_badprocpid("environ");
62183 + return 0;
62184 + }
62185 +#endif
62186 +
62187 page = (char *)__get_free_page(GFP_TEMPORARY);
62188 if (!page)
62189 return -ENOMEM;
62190 @@ -856,7 +942,7 @@ static ssize_t environ_read(struct file *file, char __user *buf,
62191 goto free;
62192 while (count > 0) {
62193 size_t this_len, max_len;
62194 - int retval;
62195 + ssize_t retval;
62196
62197 if (src >= (mm->env_end - mm->env_start))
62198 break;
62199 @@ -1467,7 +1553,7 @@ static void *proc_pid_follow_link(struct dentry *dentry, struct nameidata *nd)
62200 int error = -EACCES;
62201
62202 /* Are we allowed to snoop on the tasks file descriptors? */
62203 - if (!proc_fd_access_allowed(inode))
62204 + if (!proc_fd_access_allowed(inode, 0))
62205 goto out;
62206
62207 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
62208 @@ -1511,8 +1597,18 @@ static int proc_pid_readlink(struct dentry * dentry, char __user * buffer, int b
62209 struct path path;
62210
62211 /* Are we allowed to snoop on the tasks file descriptors? */
62212 - if (!proc_fd_access_allowed(inode))
62213 - goto out;
62214 + /* logging this is needed for learning on chromium to work properly,
62215 + but we don't want to flood the logs from 'ps' which does a readlink
62216 + on /proc/fd/2 of tasks in the listing, nor do we want 'ps' to learn
62217 + CAP_SYS_PTRACE as it's not necessary for its basic functionality
62218 + */
62219 + if (dentry->d_name.name[0] == '2' && dentry->d_name.name[1] == '\0') {
62220 + if (!proc_fd_access_allowed(inode,0))
62221 + goto out;
62222 + } else {
62223 + if (!proc_fd_access_allowed(inode,1))
62224 + goto out;
62225 + }
62226
62227 error = PROC_I(inode)->op.proc_get_link(dentry, &path);
62228 if (error)
62229 @@ -1562,7 +1658,11 @@ struct inode *proc_pid_make_inode(struct super_block * sb, struct task_struct *t
62230 rcu_read_lock();
62231 cred = __task_cred(task);
62232 inode->i_uid = cred->euid;
62233 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62234 + inode->i_gid = grsec_proc_gid;
62235 +#else
62236 inode->i_gid = cred->egid;
62237 +#endif
62238 rcu_read_unlock();
62239 }
62240 security_task_to_inode(task, inode);
62241 @@ -1598,10 +1698,19 @@ int pid_getattr(struct vfsmount *mnt, struct dentry *dentry, struct kstat *stat)
62242 return -ENOENT;
62243 }
62244 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
62245 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62246 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
62247 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62248 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
62249 +#endif
62250 task_dumpable(task)) {
62251 cred = __task_cred(task);
62252 stat->uid = cred->euid;
62253 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62254 + stat->gid = grsec_proc_gid;
62255 +#else
62256 stat->gid = cred->egid;
62257 +#endif
62258 }
62259 }
62260 rcu_read_unlock();
62261 @@ -1639,11 +1748,20 @@ int pid_revalidate(struct dentry *dentry, unsigned int flags)
62262
62263 if (task) {
62264 if ((inode->i_mode == (S_IFDIR|S_IRUGO|S_IXUGO)) ||
62265 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62266 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IXUSR)) ||
62267 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62268 + (inode->i_mode == (S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP)) ||
62269 +#endif
62270 task_dumpable(task)) {
62271 rcu_read_lock();
62272 cred = __task_cred(task);
62273 inode->i_uid = cred->euid;
62274 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62275 + inode->i_gid = grsec_proc_gid;
62276 +#else
62277 inode->i_gid = cred->egid;
62278 +#endif
62279 rcu_read_unlock();
62280 } else {
62281 inode->i_uid = GLOBAL_ROOT_UID;
62282 @@ -2172,6 +2290,9 @@ static struct dentry *proc_pident_lookup(struct inode *dir,
62283 if (!task)
62284 goto out_no_task;
62285
62286 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
62287 + goto out;
62288 +
62289 /*
62290 * Yes, it does not scale. And it should not. Don't add
62291 * new entries into /proc/<tgid>/ without very good reasons.
62292 @@ -2202,6 +2323,9 @@ static int proc_pident_readdir(struct file *file, struct dir_context *ctx,
62293 if (!task)
62294 return -ENOENT;
62295
62296 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
62297 + goto out;
62298 +
62299 if (!dir_emit_dots(file, ctx))
62300 goto out;
62301
62302 @@ -2591,7 +2715,7 @@ static const struct pid_entry tgid_base_stuff[] = {
62303 REG("autogroup", S_IRUGO|S_IWUSR, proc_pid_sched_autogroup_operations),
62304 #endif
62305 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
62306 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
62307 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
62308 INF("syscall", S_IRUGO, proc_pid_syscall),
62309 #endif
62310 INF("cmdline", S_IRUGO, proc_pid_cmdline),
62311 @@ -2616,10 +2740,10 @@ static const struct pid_entry tgid_base_stuff[] = {
62312 #ifdef CONFIG_SECURITY
62313 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
62314 #endif
62315 -#ifdef CONFIG_KALLSYMS
62316 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62317 INF("wchan", S_IRUGO, proc_pid_wchan),
62318 #endif
62319 -#ifdef CONFIG_STACKTRACE
62320 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62321 ONE("stack", S_IRUGO, proc_pid_stack),
62322 #endif
62323 #ifdef CONFIG_SCHEDSTATS
62324 @@ -2653,6 +2777,9 @@ static const struct pid_entry tgid_base_stuff[] = {
62325 #ifdef CONFIG_HARDWALL
62326 INF("hardwall", S_IRUGO, proc_pid_hardwall),
62327 #endif
62328 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
62329 + INF("ipaddr", S_IRUSR, proc_pid_ipaddr),
62330 +#endif
62331 #ifdef CONFIG_USER_NS
62332 REG("uid_map", S_IRUGO|S_IWUSR, proc_uid_map_operations),
62333 REG("gid_map", S_IRUGO|S_IWUSR, proc_gid_map_operations),
62334 @@ -2783,7 +2910,14 @@ static int proc_pid_instantiate(struct inode *dir,
62335 if (!inode)
62336 goto out;
62337
62338 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62339 + inode->i_mode = S_IFDIR|S_IRUSR|S_IXUSR;
62340 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62341 + inode->i_gid = grsec_proc_gid;
62342 + inode->i_mode = S_IFDIR|S_IRUSR|S_IRGRP|S_IXUSR|S_IXGRP;
62343 +#else
62344 inode->i_mode = S_IFDIR|S_IRUGO|S_IXUGO;
62345 +#endif
62346 inode->i_op = &proc_tgid_base_inode_operations;
62347 inode->i_fop = &proc_tgid_base_operations;
62348 inode->i_flags|=S_IMMUTABLE;
62349 @@ -2821,7 +2955,11 @@ struct dentry *proc_pid_lookup(struct inode *dir, struct dentry * dentry, unsign
62350 if (!task)
62351 goto out;
62352
62353 + if (gr_pid_is_chrooted(task) || gr_check_hidden_task(task))
62354 + goto out_put_task;
62355 +
62356 result = proc_pid_instantiate(dir, dentry, task, NULL);
62357 +out_put_task:
62358 put_task_struct(task);
62359 out:
62360 return ERR_PTR(result);
62361 @@ -2927,7 +3065,7 @@ static const struct pid_entry tid_base_stuff[] = {
62362 REG("sched", S_IRUGO|S_IWUSR, proc_pid_sched_operations),
62363 #endif
62364 REG("comm", S_IRUGO|S_IWUSR, proc_pid_set_comm_operations),
62365 -#ifdef CONFIG_HAVE_ARCH_TRACEHOOK
62366 +#if defined(CONFIG_HAVE_ARCH_TRACEHOOK) && !defined(CONFIG_GRKERNSEC_PROC_MEMMAP)
62367 INF("syscall", S_IRUGO, proc_pid_syscall),
62368 #endif
62369 INF("cmdline", S_IRUGO, proc_pid_cmdline),
62370 @@ -2954,10 +3092,10 @@ static const struct pid_entry tid_base_stuff[] = {
62371 #ifdef CONFIG_SECURITY
62372 DIR("attr", S_IRUGO|S_IXUGO, proc_attr_dir_inode_operations, proc_attr_dir_operations),
62373 #endif
62374 -#ifdef CONFIG_KALLSYMS
62375 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62376 INF("wchan", S_IRUGO, proc_pid_wchan),
62377 #endif
62378 -#ifdef CONFIG_STACKTRACE
62379 +#if defined(CONFIG_STACKTRACE) && !defined(CONFIG_GRKERNSEC_HIDESYM)
62380 ONE("stack", S_IRUGO, proc_pid_stack),
62381 #endif
62382 #ifdef CONFIG_SCHEDSTATS
62383 diff --git a/fs/proc/cmdline.c b/fs/proc/cmdline.c
62384 index 82676e3..5f8518a 100644
62385 --- a/fs/proc/cmdline.c
62386 +++ b/fs/proc/cmdline.c
62387 @@ -23,7 +23,11 @@ static const struct file_operations cmdline_proc_fops = {
62388
62389 static int __init proc_cmdline_init(void)
62390 {
62391 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
62392 + proc_create_grsec("cmdline", 0, NULL, &cmdline_proc_fops);
62393 +#else
62394 proc_create("cmdline", 0, NULL, &cmdline_proc_fops);
62395 +#endif
62396 return 0;
62397 }
62398 module_init(proc_cmdline_init);
62399 diff --git a/fs/proc/devices.c b/fs/proc/devices.c
62400 index b143471..bb105e5 100644
62401 --- a/fs/proc/devices.c
62402 +++ b/fs/proc/devices.c
62403 @@ -64,7 +64,11 @@ static const struct file_operations proc_devinfo_operations = {
62404
62405 static int __init proc_devices_init(void)
62406 {
62407 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
62408 + proc_create_grsec("devices", 0, NULL, &proc_devinfo_operations);
62409 +#else
62410 proc_create("devices", 0, NULL, &proc_devinfo_operations);
62411 +#endif
62412 return 0;
62413 }
62414 module_init(proc_devices_init);
62415 diff --git a/fs/proc/fd.c b/fs/proc/fd.c
62416 index 985ea88..d118a0a 100644
62417 --- a/fs/proc/fd.c
62418 +++ b/fs/proc/fd.c
62419 @@ -25,7 +25,8 @@ static int seq_show(struct seq_file *m, void *v)
62420 if (!task)
62421 return -ENOENT;
62422
62423 - files = get_files_struct(task);
62424 + if (!gr_acl_handle_procpidmem(task))
62425 + files = get_files_struct(task);
62426 put_task_struct(task);
62427
62428 if (files) {
62429 @@ -283,11 +284,21 @@ static struct dentry *proc_lookupfd(struct inode *dir, struct dentry *dentry,
62430 */
62431 int proc_fd_permission(struct inode *inode, int mask)
62432 {
62433 + struct task_struct *task;
62434 int rv = generic_permission(inode, mask);
62435 - if (rv == 0)
62436 - return 0;
62437 +
62438 if (task_tgid(current) == proc_pid(inode))
62439 rv = 0;
62440 +
62441 + task = get_proc_task(inode);
62442 + if (task == NULL)
62443 + return rv;
62444 +
62445 + if (gr_acl_handle_procpidmem(task))
62446 + rv = -EACCES;
62447 +
62448 + put_task_struct(task);
62449 +
62450 return rv;
62451 }
62452
62453 diff --git a/fs/proc/inode.c b/fs/proc/inode.c
62454 index 124fc43..8afbb02 100644
62455 --- a/fs/proc/inode.c
62456 +++ b/fs/proc/inode.c
62457 @@ -23,11 +23,17 @@
62458 #include <linux/slab.h>
62459 #include <linux/mount.h>
62460 #include <linux/magic.h>
62461 +#include <linux/grsecurity.h>
62462
62463 #include <asm/uaccess.h>
62464
62465 #include "internal.h"
62466
62467 +#ifdef CONFIG_PROC_SYSCTL
62468 +extern const struct inode_operations proc_sys_inode_operations;
62469 +extern const struct inode_operations proc_sys_dir_operations;
62470 +#endif
62471 +
62472 static void proc_evict_inode(struct inode *inode)
62473 {
62474 struct proc_dir_entry *de;
62475 @@ -55,6 +61,13 @@ static void proc_evict_inode(struct inode *inode)
62476 ns = PROC_I(inode)->ns.ns;
62477 if (ns_ops && ns)
62478 ns_ops->put(ns);
62479 +
62480 +#ifdef CONFIG_PROC_SYSCTL
62481 + if (inode->i_op == &proc_sys_inode_operations ||
62482 + inode->i_op == &proc_sys_dir_operations)
62483 + gr_handle_delete(inode->i_ino, inode->i_sb->s_dev);
62484 +#endif
62485 +
62486 }
62487
62488 static struct kmem_cache * proc_inode_cachep;
62489 @@ -413,7 +426,11 @@ struct inode *proc_get_inode(struct super_block *sb, struct proc_dir_entry *de)
62490 if (de->mode) {
62491 inode->i_mode = de->mode;
62492 inode->i_uid = de->uid;
62493 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62494 + inode->i_gid = grsec_proc_gid;
62495 +#else
62496 inode->i_gid = de->gid;
62497 +#endif
62498 }
62499 if (de->size)
62500 inode->i_size = de->size;
62501 diff --git a/fs/proc/internal.h b/fs/proc/internal.h
62502 index 651d09a..3d7f0bf 100644
62503 --- a/fs/proc/internal.h
62504 +++ b/fs/proc/internal.h
62505 @@ -48,7 +48,7 @@ struct proc_dir_entry {
62506 spinlock_t pde_unload_lock; /* proc_fops checks and pde_users bumps */
62507 u8 namelen;
62508 char name[];
62509 -};
62510 +} __randomize_layout;
62511
62512 union proc_op {
62513 int (*proc_get_link)(struct dentry *, struct path *);
62514 @@ -67,7 +67,7 @@ struct proc_inode {
62515 struct ctl_table *sysctl_entry;
62516 struct proc_ns ns;
62517 struct inode vfs_inode;
62518 -};
62519 +} __randomize_layout;
62520
62521 /*
62522 * General functions
62523 @@ -155,6 +155,9 @@ extern int proc_pid_status(struct seq_file *, struct pid_namespace *,
62524 struct pid *, struct task_struct *);
62525 extern int proc_pid_statm(struct seq_file *, struct pid_namespace *,
62526 struct pid *, struct task_struct *);
62527 +#ifdef CONFIG_GRKERNSEC_PROC_IPADDR
62528 +extern int proc_pid_ipaddr(struct task_struct *task, char *buffer);
62529 +#endif
62530
62531 /*
62532 * base.c
62533 diff --git a/fs/proc/interrupts.c b/fs/proc/interrupts.c
62534 index 05029c0..7ea1987 100644
62535 --- a/fs/proc/interrupts.c
62536 +++ b/fs/proc/interrupts.c
62537 @@ -47,7 +47,11 @@ static const struct file_operations proc_interrupts_operations = {
62538
62539 static int __init proc_interrupts_init(void)
62540 {
62541 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
62542 + proc_create_grsec("interrupts", 0, NULL, &proc_interrupts_operations);
62543 +#else
62544 proc_create("interrupts", 0, NULL, &proc_interrupts_operations);
62545 +#endif
62546 return 0;
62547 }
62548 module_init(proc_interrupts_init);
62549 diff --git a/fs/proc/kcore.c b/fs/proc/kcore.c
62550 index 5ed0e52..a1c1f2e 100644
62551 --- a/fs/proc/kcore.c
62552 +++ b/fs/proc/kcore.c
62553 @@ -483,9 +483,10 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
62554 * the addresses in the elf_phdr on our list.
62555 */
62556 start = kc_offset_to_vaddr(*fpos - elf_buflen);
62557 - if ((tsz = (PAGE_SIZE - (start & ~PAGE_MASK))) > buflen)
62558 + tsz = PAGE_SIZE - (start & ~PAGE_MASK);
62559 + if (tsz > buflen)
62560 tsz = buflen;
62561 -
62562 +
62563 while (buflen) {
62564 struct kcore_list *m;
62565
62566 @@ -514,20 +515,23 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
62567 kfree(elf_buf);
62568 } else {
62569 if (kern_addr_valid(start)) {
62570 - unsigned long n;
62571 + char *elf_buf;
62572 + mm_segment_t oldfs;
62573
62574 - n = copy_to_user(buffer, (char *)start, tsz);
62575 - /*
62576 - * We cannot distinguish between fault on source
62577 - * and fault on destination. When this happens
62578 - * we clear too and hope it will trigger the
62579 - * EFAULT again.
62580 - */
62581 - if (n) {
62582 - if (clear_user(buffer + tsz - n,
62583 - n))
62584 + elf_buf = kmalloc(tsz, GFP_KERNEL);
62585 + if (!elf_buf)
62586 + return -ENOMEM;
62587 + oldfs = get_fs();
62588 + set_fs(KERNEL_DS);
62589 + if (!__copy_from_user(elf_buf, (const void __user *)start, tsz)) {
62590 + set_fs(oldfs);
62591 + if (copy_to_user(buffer, elf_buf, tsz)) {
62592 + kfree(elf_buf);
62593 return -EFAULT;
62594 + }
62595 }
62596 + set_fs(oldfs);
62597 + kfree(elf_buf);
62598 } else {
62599 if (clear_user(buffer, tsz))
62600 return -EFAULT;
62601 @@ -547,6 +551,9 @@ read_kcore(struct file *file, char __user *buffer, size_t buflen, loff_t *fpos)
62602
62603 static int open_kcore(struct inode *inode, struct file *filp)
62604 {
62605 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
62606 + return -EPERM;
62607 +#endif
62608 if (!capable(CAP_SYS_RAWIO))
62609 return -EPERM;
62610 if (kcore_need_update)
62611 diff --git a/fs/proc/meminfo.c b/fs/proc/meminfo.c
62612 index a77d2b2..a9153f0 100644
62613 --- a/fs/proc/meminfo.c
62614 +++ b/fs/proc/meminfo.c
62615 @@ -150,7 +150,7 @@ static int meminfo_proc_show(struct seq_file *m, void *v)
62616 vmi.used >> 10,
62617 vmi.largest_chunk >> 10
62618 #ifdef CONFIG_MEMORY_FAILURE
62619 - ,atomic_long_read(&num_poisoned_pages) << (PAGE_SHIFT - 10)
62620 + ,atomic_long_read_unchecked(&num_poisoned_pages) << (PAGE_SHIFT - 10)
62621 #endif
62622 #ifdef CONFIG_TRANSPARENT_HUGEPAGE
62623 ,K(global_page_state(NR_ANON_TRANSPARENT_HUGEPAGES) *
62624 diff --git a/fs/proc/nommu.c b/fs/proc/nommu.c
62625 index 5f9bc8a..5c35f08 100644
62626 --- a/fs/proc/nommu.c
62627 +++ b/fs/proc/nommu.c
62628 @@ -64,7 +64,7 @@ static int nommu_region_show(struct seq_file *m, struct vm_region *region)
62629
62630 if (file) {
62631 seq_pad(m, ' ');
62632 - seq_path(m, &file->f_path, "");
62633 + seq_path(m, &file->f_path, "\n\\");
62634 }
62635
62636 seq_putc(m, '\n');
62637 diff --git a/fs/proc/proc_net.c b/fs/proc/proc_net.c
62638 index 4677bb7..408e936 100644
62639 --- a/fs/proc/proc_net.c
62640 +++ b/fs/proc/proc_net.c
62641 @@ -23,6 +23,7 @@
62642 #include <linux/nsproxy.h>
62643 #include <net/net_namespace.h>
62644 #include <linux/seq_file.h>
62645 +#include <linux/grsecurity.h>
62646
62647 #include "internal.h"
62648
62649 @@ -109,6 +110,17 @@ static struct net *get_proc_task_net(struct inode *dir)
62650 struct task_struct *task;
62651 struct nsproxy *ns;
62652 struct net *net = NULL;
62653 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62654 + const struct cred *cred = current_cred();
62655 +#endif
62656 +
62657 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62658 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID))
62659 + return net;
62660 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62661 + if (!uid_eq(cred->fsuid, GLOBAL_ROOT_UID) && !in_group_p(grsec_proc_gid))
62662 + return net;
62663 +#endif
62664
62665 rcu_read_lock();
62666 task = pid_task(proc_pid(dir), PIDTYPE_PID);
62667 diff --git a/fs/proc/proc_sysctl.c b/fs/proc/proc_sysctl.c
62668 index 7129046..6914844 100644
62669 --- a/fs/proc/proc_sysctl.c
62670 +++ b/fs/proc/proc_sysctl.c
62671 @@ -11,13 +11,21 @@
62672 #include <linux/namei.h>
62673 #include <linux/mm.h>
62674 #include <linux/module.h>
62675 +#include <linux/nsproxy.h>
62676 +#ifdef CONFIG_GRKERNSEC
62677 +#include <net/net_namespace.h>
62678 +#endif
62679 #include "internal.h"
62680
62681 +extern int gr_handle_chroot_sysctl(const int op);
62682 +extern int gr_handle_sysctl_mod(const char *dirname, const char *name,
62683 + const int op);
62684 +
62685 static const struct dentry_operations proc_sys_dentry_operations;
62686 static const struct file_operations proc_sys_file_operations;
62687 -static const struct inode_operations proc_sys_inode_operations;
62688 +const struct inode_operations proc_sys_inode_operations;
62689 static const struct file_operations proc_sys_dir_file_operations;
62690 -static const struct inode_operations proc_sys_dir_operations;
62691 +const struct inode_operations proc_sys_dir_operations;
62692
62693 void proc_sys_poll_notify(struct ctl_table_poll *poll)
62694 {
62695 @@ -467,6 +475,9 @@ static struct dentry *proc_sys_lookup(struct inode *dir, struct dentry *dentry,
62696
62697 err = NULL;
62698 d_set_d_op(dentry, &proc_sys_dentry_operations);
62699 +
62700 + gr_handle_proc_create(dentry, inode);
62701 +
62702 d_add(dentry, inode);
62703
62704 out:
62705 @@ -482,6 +493,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
62706 struct inode *inode = file_inode(filp);
62707 struct ctl_table_header *head = grab_header(inode);
62708 struct ctl_table *table = PROC_I(inode)->sysctl_entry;
62709 + int op = write ? MAY_WRITE : MAY_READ;
62710 ssize_t error;
62711 size_t res;
62712
62713 @@ -493,7 +505,7 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
62714 * and won't be until we finish.
62715 */
62716 error = -EPERM;
62717 - if (sysctl_perm(head, table, write ? MAY_WRITE : MAY_READ))
62718 + if (sysctl_perm(head, table, op))
62719 goto out;
62720
62721 /* if that can happen at all, it should be -EINVAL, not -EISDIR */
62722 @@ -501,6 +513,27 @@ static ssize_t proc_sys_call_handler(struct file *filp, void __user *buf,
62723 if (!table->proc_handler)
62724 goto out;
62725
62726 +#ifdef CONFIG_GRKERNSEC
62727 + error = -EPERM;
62728 + if (gr_handle_chroot_sysctl(op))
62729 + goto out;
62730 + dget(filp->f_path.dentry);
62731 + if (gr_handle_sysctl_mod(filp->f_path.dentry->d_parent->d_name.name, table->procname, op)) {
62732 + dput(filp->f_path.dentry);
62733 + goto out;
62734 + }
62735 + dput(filp->f_path.dentry);
62736 + if (!gr_acl_handle_open(filp->f_path.dentry, filp->f_path.mnt, op))
62737 + goto out;
62738 + if (write) {
62739 + if (current->nsproxy->net_ns != table->extra2) {
62740 + if (!capable(CAP_SYS_ADMIN))
62741 + goto out;
62742 + } else if (!ns_capable(current->nsproxy->net_ns->user_ns, CAP_NET_ADMIN))
62743 + goto out;
62744 + }
62745 +#endif
62746 +
62747 /* careful: calling conventions are nasty here */
62748 res = count;
62749 error = table->proc_handler(table, write, buf, &res, ppos);
62750 @@ -598,6 +631,9 @@ static bool proc_sys_fill_cache(struct file *file,
62751 return false;
62752 } else {
62753 d_set_d_op(child, &proc_sys_dentry_operations);
62754 +
62755 + gr_handle_proc_create(child, inode);
62756 +
62757 d_add(child, inode);
62758 }
62759 } else {
62760 @@ -641,6 +677,9 @@ static int scan(struct ctl_table_header *head, ctl_table *table,
62761 if ((*pos)++ < ctx->pos)
62762 return true;
62763
62764 + if (!gr_acl_handle_hidden_file(file->f_path.dentry, file->f_path.mnt))
62765 + return 0;
62766 +
62767 if (unlikely(S_ISLNK(table->mode)))
62768 res = proc_sys_link_fill_cache(file, ctx, head, table);
62769 else
62770 @@ -734,6 +773,9 @@ static int proc_sys_getattr(struct vfsmount *mnt, struct dentry *dentry, struct
62771 if (IS_ERR(head))
62772 return PTR_ERR(head);
62773
62774 + if (table && !gr_acl_handle_hidden_file(dentry, mnt))
62775 + return -ENOENT;
62776 +
62777 generic_fillattr(inode, stat);
62778 if (table)
62779 stat->mode = (stat->mode & S_IFMT) | table->mode;
62780 @@ -756,13 +798,13 @@ static const struct file_operations proc_sys_dir_file_operations = {
62781 .llseek = generic_file_llseek,
62782 };
62783
62784 -static const struct inode_operations proc_sys_inode_operations = {
62785 +const struct inode_operations proc_sys_inode_operations = {
62786 .permission = proc_sys_permission,
62787 .setattr = proc_sys_setattr,
62788 .getattr = proc_sys_getattr,
62789 };
62790
62791 -static const struct inode_operations proc_sys_dir_operations = {
62792 +const struct inode_operations proc_sys_dir_operations = {
62793 .lookup = proc_sys_lookup,
62794 .permission = proc_sys_permission,
62795 .setattr = proc_sys_setattr,
62796 @@ -839,7 +881,7 @@ static struct ctl_dir *find_subdir(struct ctl_dir *dir,
62797 static struct ctl_dir *new_dir(struct ctl_table_set *set,
62798 const char *name, int namelen)
62799 {
62800 - struct ctl_table *table;
62801 + ctl_table_no_const *table;
62802 struct ctl_dir *new;
62803 struct ctl_node *node;
62804 char *new_name;
62805 @@ -851,7 +893,7 @@ static struct ctl_dir *new_dir(struct ctl_table_set *set,
62806 return NULL;
62807
62808 node = (struct ctl_node *)(new + 1);
62809 - table = (struct ctl_table *)(node + 1);
62810 + table = (ctl_table_no_const *)(node + 1);
62811 new_name = (char *)(table + 2);
62812 memcpy(new_name, name, namelen);
62813 new_name[namelen] = '\0';
62814 @@ -1020,7 +1062,8 @@ static int sysctl_check_table(const char *path, struct ctl_table *table)
62815 static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table *table,
62816 struct ctl_table_root *link_root)
62817 {
62818 - struct ctl_table *link_table, *entry, *link;
62819 + ctl_table_no_const *link_table, *link;
62820 + struct ctl_table *entry;
62821 struct ctl_table_header *links;
62822 struct ctl_node *node;
62823 char *link_name;
62824 @@ -1043,7 +1086,7 @@ static struct ctl_table_header *new_links(struct ctl_dir *dir, struct ctl_table
62825 return NULL;
62826
62827 node = (struct ctl_node *)(links + 1);
62828 - link_table = (struct ctl_table *)(node + nr_entries);
62829 + link_table = (ctl_table_no_const *)(node + nr_entries);
62830 link_name = (char *)&link_table[nr_entries + 1];
62831
62832 for (link = link_table, entry = table; entry->procname; link++, entry++) {
62833 @@ -1291,8 +1334,8 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
62834 struct ctl_table_header ***subheader, struct ctl_table_set *set,
62835 struct ctl_table *table)
62836 {
62837 - struct ctl_table *ctl_table_arg = NULL;
62838 - struct ctl_table *entry, *files;
62839 + ctl_table_no_const *ctl_table_arg = NULL, *files = NULL;
62840 + struct ctl_table *entry;
62841 int nr_files = 0;
62842 int nr_dirs = 0;
62843 int err = -ENOMEM;
62844 @@ -1304,10 +1347,9 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
62845 nr_files++;
62846 }
62847
62848 - files = table;
62849 /* If there are mixed files and directories we need a new table */
62850 if (nr_dirs && nr_files) {
62851 - struct ctl_table *new;
62852 + ctl_table_no_const *new;
62853 files = kzalloc(sizeof(struct ctl_table) * (nr_files + 1),
62854 GFP_KERNEL);
62855 if (!files)
62856 @@ -1325,7 +1367,7 @@ static int register_leaf_sysctl_tables(const char *path, char *pos,
62857 /* Register everything except a directory full of subdirectories */
62858 if (nr_files || !nr_dirs) {
62859 struct ctl_table_header *header;
62860 - header = __register_sysctl_table(set, path, files);
62861 + header = __register_sysctl_table(set, path, files ? files : table);
62862 if (!header) {
62863 kfree(ctl_table_arg);
62864 goto out;
62865 diff --git a/fs/proc/root.c b/fs/proc/root.c
62866 index 87dbcbe..55e1b4d 100644
62867 --- a/fs/proc/root.c
62868 +++ b/fs/proc/root.c
62869 @@ -186,7 +186,15 @@ void __init proc_root_init(void)
62870 #ifdef CONFIG_PROC_DEVICETREE
62871 proc_device_tree_init();
62872 #endif
62873 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
62874 +#ifdef CONFIG_GRKERNSEC_PROC_USER
62875 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR, NULL);
62876 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62877 + proc_mkdir_mode("bus", S_IRUSR | S_IXUSR | S_IRGRP | S_IXGRP, NULL);
62878 +#endif
62879 +#else
62880 proc_mkdir("bus", NULL);
62881 +#endif
62882 proc_sys_init();
62883 }
62884
62885 diff --git a/fs/proc/stat.c b/fs/proc/stat.c
62886 index 1cf86c0..0ee1ca5 100644
62887 --- a/fs/proc/stat.c
62888 +++ b/fs/proc/stat.c
62889 @@ -11,6 +11,7 @@
62890 #include <linux/irqnr.h>
62891 #include <asm/cputime.h>
62892 #include <linux/tick.h>
62893 +#include <linux/grsecurity.h>
62894
62895 #ifndef arch_irq_stat_cpu
62896 #define arch_irq_stat_cpu(cpu) 0
62897 @@ -87,6 +88,18 @@ static int show_stat(struct seq_file *p, void *v)
62898 u64 sum_softirq = 0;
62899 unsigned int per_softirq_sums[NR_SOFTIRQS] = {0};
62900 struct timespec boottime;
62901 + int unrestricted = 1;
62902 +
62903 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
62904 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
62905 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
62906 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
62907 + && !in_group_p(grsec_proc_gid)
62908 +#endif
62909 + )
62910 + unrestricted = 0;
62911 +#endif
62912 +#endif
62913
62914 user = nice = system = idle = iowait =
62915 irq = softirq = steal = 0;
62916 @@ -94,6 +107,7 @@ static int show_stat(struct seq_file *p, void *v)
62917 getboottime(&boottime);
62918 jif = boottime.tv_sec;
62919
62920 + if (unrestricted) {
62921 for_each_possible_cpu(i) {
62922 user += kcpustat_cpu(i).cpustat[CPUTIME_USER];
62923 nice += kcpustat_cpu(i).cpustat[CPUTIME_NICE];
62924 @@ -116,6 +130,7 @@ static int show_stat(struct seq_file *p, void *v)
62925 }
62926 }
62927 sum += arch_irq_stat();
62928 + }
62929
62930 seq_puts(p, "cpu ");
62931 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
62932 @@ -131,6 +146,7 @@ static int show_stat(struct seq_file *p, void *v)
62933 seq_putc(p, '\n');
62934
62935 for_each_online_cpu(i) {
62936 + if (unrestricted) {
62937 /* Copy values here to work around gcc-2.95.3, gcc-2.96 */
62938 user = kcpustat_cpu(i).cpustat[CPUTIME_USER];
62939 nice = kcpustat_cpu(i).cpustat[CPUTIME_NICE];
62940 @@ -142,6 +158,7 @@ static int show_stat(struct seq_file *p, void *v)
62941 steal = kcpustat_cpu(i).cpustat[CPUTIME_STEAL];
62942 guest = kcpustat_cpu(i).cpustat[CPUTIME_GUEST];
62943 guest_nice = kcpustat_cpu(i).cpustat[CPUTIME_GUEST_NICE];
62944 + }
62945 seq_printf(p, "cpu%d", i);
62946 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(user));
62947 seq_put_decimal_ull(p, ' ', cputime64_to_clock_t(nice));
62948 @@ -159,7 +176,7 @@ static int show_stat(struct seq_file *p, void *v)
62949
62950 /* sum again ? it could be updated? */
62951 for_each_irq_nr(j)
62952 - seq_put_decimal_ull(p, ' ', kstat_irqs(j));
62953 + seq_put_decimal_ull(p, ' ', unrestricted ? kstat_irqs(j) : 0ULL);
62954
62955 seq_printf(p,
62956 "\nctxt %llu\n"
62957 @@ -167,11 +184,11 @@ static int show_stat(struct seq_file *p, void *v)
62958 "processes %lu\n"
62959 "procs_running %lu\n"
62960 "procs_blocked %lu\n",
62961 - nr_context_switches(),
62962 + unrestricted ? nr_context_switches() : 0ULL,
62963 (unsigned long)jif,
62964 - total_forks,
62965 - nr_running(),
62966 - nr_iowait());
62967 + unrestricted ? total_forks : 0UL,
62968 + unrestricted ? nr_running() : 0UL,
62969 + unrestricted ? nr_iowait() : 0UL);
62970
62971 seq_printf(p, "softirq %llu", (unsigned long long)sum_softirq);
62972
62973 diff --git a/fs/proc/task_mmu.c b/fs/proc/task_mmu.c
62974 index fb52b54..5fc7c14 100644
62975 --- a/fs/proc/task_mmu.c
62976 +++ b/fs/proc/task_mmu.c
62977 @@ -12,12 +12,19 @@
62978 #include <linux/swap.h>
62979 #include <linux/swapops.h>
62980 #include <linux/mmu_notifier.h>
62981 +#include <linux/grsecurity.h>
62982
62983 #include <asm/elf.h>
62984 #include <asm/uaccess.h>
62985 #include <asm/tlbflush.h>
62986 #include "internal.h"
62987
62988 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
62989 +#define PAX_RAND_FLAGS(_mm) (_mm != NULL && _mm != current->mm && \
62990 + (_mm->pax_flags & MF_PAX_RANDMMAP || \
62991 + _mm->pax_flags & MF_PAX_SEGMEXEC))
62992 +#endif
62993 +
62994 void task_mem(struct seq_file *m, struct mm_struct *mm)
62995 {
62996 unsigned long data, text, lib, swap;
62997 @@ -53,8 +60,13 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
62998 "VmExe:\t%8lu kB\n"
62999 "VmLib:\t%8lu kB\n"
63000 "VmPTE:\t%8lu kB\n"
63001 - "VmSwap:\t%8lu kB\n",
63002 - hiwater_vm << (PAGE_SHIFT-10),
63003 + "VmSwap:\t%8lu kB\n"
63004 +
63005 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63006 + "CsBase:\t%8lx\nCsLim:\t%8lx\n"
63007 +#endif
63008 +
63009 + ,hiwater_vm << (PAGE_SHIFT-10),
63010 total_vm << (PAGE_SHIFT-10),
63011 mm->locked_vm << (PAGE_SHIFT-10),
63012 mm->pinned_vm << (PAGE_SHIFT-10),
63013 @@ -64,7 +76,19 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
63014 mm->stack_vm << (PAGE_SHIFT-10), text, lib,
63015 (PTRS_PER_PTE * sizeof(pte_t) *
63016 atomic_long_read(&mm->nr_ptes)) >> 10,
63017 - swap << (PAGE_SHIFT-10));
63018 + swap << (PAGE_SHIFT-10)
63019 +
63020 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
63021 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63022 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_base
63023 + , PAX_RAND_FLAGS(mm) ? 0 : mm->context.user_cs_limit
63024 +#else
63025 + , mm->context.user_cs_base
63026 + , mm->context.user_cs_limit
63027 +#endif
63028 +#endif
63029 +
63030 + );
63031 }
63032
63033 unsigned long task_vsize(struct mm_struct *mm)
63034 @@ -270,13 +294,13 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63035 pgoff = ((loff_t)vma->vm_pgoff) << PAGE_SHIFT;
63036 }
63037
63038 - /* We don't show the stack guard page in /proc/maps */
63039 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63040 + start = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_start;
63041 + end = PAX_RAND_FLAGS(mm) ? 0UL : vma->vm_end;
63042 +#else
63043 start = vma->vm_start;
63044 - if (stack_guard_page_start(vma, start))
63045 - start += PAGE_SIZE;
63046 end = vma->vm_end;
63047 - if (stack_guard_page_end(vma, end))
63048 - end -= PAGE_SIZE;
63049 +#endif
63050
63051 seq_setwidth(m, 25 + sizeof(void *) * 6 - 1);
63052 seq_printf(m, "%08lx-%08lx %c%c%c%c %08llx %02x:%02x %lu ",
63053 @@ -286,7 +310,11 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63054 flags & VM_WRITE ? 'w' : '-',
63055 flags & VM_EXEC ? 'x' : '-',
63056 flags & VM_MAYSHARE ? 's' : 'p',
63057 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63058 + PAX_RAND_FLAGS(mm) ? 0UL : pgoff,
63059 +#else
63060 pgoff,
63061 +#endif
63062 MAJOR(dev), MINOR(dev), ino);
63063
63064 /*
63065 @@ -295,7 +323,7 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63066 */
63067 if (file) {
63068 seq_pad(m, ' ');
63069 - seq_path(m, &file->f_path, "\n");
63070 + seq_path(m, &file->f_path, "\n\\");
63071 goto done;
63072 }
63073
63074 @@ -321,8 +349,9 @@ show_map_vma(struct seq_file *m, struct vm_area_struct *vma, int is_pid)
63075 * Thread stack in /proc/PID/task/TID/maps or
63076 * the main process stack.
63077 */
63078 - if (!is_pid || (vma->vm_start <= mm->start_stack &&
63079 - vma->vm_end >= mm->start_stack)) {
63080 + if (!is_pid || (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP)) ||
63081 + (vma->vm_start <= mm->start_stack &&
63082 + vma->vm_end >= mm->start_stack)) {
63083 name = "[stack]";
63084 } else {
63085 /* Thread stack in /proc/PID/maps */
63086 @@ -346,6 +375,13 @@ static int show_map(struct seq_file *m, void *v, int is_pid)
63087 struct proc_maps_private *priv = m->private;
63088 struct task_struct *task = priv->task;
63089
63090 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63091 + if (current->exec_id != m->exec_id) {
63092 + gr_log_badprocpid("maps");
63093 + return 0;
63094 + }
63095 +#endif
63096 +
63097 show_map_vma(m, vma, is_pid);
63098
63099 if (m->count < m->size) /* vma is copied successfully */
63100 @@ -586,12 +622,23 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
63101 .private = &mss,
63102 };
63103
63104 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63105 + if (current->exec_id != m->exec_id) {
63106 + gr_log_badprocpid("smaps");
63107 + return 0;
63108 + }
63109 +#endif
63110 memset(&mss, 0, sizeof mss);
63111 - mss.vma = vma;
63112 - /* mmap_sem is held in m_start */
63113 - if (vma->vm_mm && !is_vm_hugetlb_page(vma))
63114 - walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
63115 -
63116 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63117 + if (!PAX_RAND_FLAGS(vma->vm_mm)) {
63118 +#endif
63119 + mss.vma = vma;
63120 + /* mmap_sem is held in m_start */
63121 + if (vma->vm_mm && !is_vm_hugetlb_page(vma))
63122 + walk_page_range(vma->vm_start, vma->vm_end, &smaps_walk);
63123 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63124 + }
63125 +#endif
63126 show_map_vma(m, vma, is_pid);
63127
63128 seq_printf(m,
63129 @@ -609,7 +656,11 @@ static int show_smap(struct seq_file *m, void *v, int is_pid)
63130 "KernelPageSize: %8lu kB\n"
63131 "MMUPageSize: %8lu kB\n"
63132 "Locked: %8lu kB\n",
63133 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63134 + PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : (vma->vm_end - vma->vm_start) >> 10,
63135 +#else
63136 (vma->vm_end - vma->vm_start) >> 10,
63137 +#endif
63138 mss.resident >> 10,
63139 (unsigned long)(mss.pss >> (10 + PSS_SHIFT)),
63140 mss.shared_clean >> 10,
63141 @@ -1387,6 +1438,13 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
63142 char buffer[64];
63143 int nid;
63144
63145 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63146 + if (current->exec_id != m->exec_id) {
63147 + gr_log_badprocpid("numa_maps");
63148 + return 0;
63149 + }
63150 +#endif
63151 +
63152 if (!mm)
63153 return 0;
63154
63155 @@ -1404,11 +1462,15 @@ static int show_numa_map(struct seq_file *m, void *v, int is_pid)
63156 mpol_to_str(buffer, sizeof(buffer), pol);
63157 mpol_cond_put(pol);
63158
63159 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63160 + seq_printf(m, "%08lx %s", PAX_RAND_FLAGS(vma->vm_mm) ? 0UL : vma->vm_start, buffer);
63161 +#else
63162 seq_printf(m, "%08lx %s", vma->vm_start, buffer);
63163 +#endif
63164
63165 if (file) {
63166 seq_printf(m, " file=");
63167 - seq_path(m, &file->f_path, "\n\t= ");
63168 + seq_path(m, &file->f_path, "\n\t\\= ");
63169 } else if (vma->vm_start <= mm->brk && vma->vm_end >= mm->start_brk) {
63170 seq_printf(m, " heap");
63171 } else {
63172 diff --git a/fs/proc/task_nommu.c b/fs/proc/task_nommu.c
63173 index 678455d..ebd3245 100644
63174 --- a/fs/proc/task_nommu.c
63175 +++ b/fs/proc/task_nommu.c
63176 @@ -51,7 +51,7 @@ void task_mem(struct seq_file *m, struct mm_struct *mm)
63177 else
63178 bytes += kobjsize(mm);
63179
63180 - if (current->fs && current->fs->users > 1)
63181 + if (current->fs && atomic_read(&current->fs->users) > 1)
63182 sbytes += kobjsize(current->fs);
63183 else
63184 bytes += kobjsize(current->fs);
63185 @@ -161,7 +161,7 @@ static int nommu_vma_show(struct seq_file *m, struct vm_area_struct *vma,
63186
63187 if (file) {
63188 seq_pad(m, ' ');
63189 - seq_path(m, &file->f_path, "");
63190 + seq_path(m, &file->f_path, "\n\\");
63191 } else if (mm) {
63192 pid_t tid = vm_is_stack(priv->task, vma, is_pid);
63193
63194 diff --git a/fs/proc/vmcore.c b/fs/proc/vmcore.c
63195 index 9100d69..51cd925 100644
63196 --- a/fs/proc/vmcore.c
63197 +++ b/fs/proc/vmcore.c
63198 @@ -105,9 +105,13 @@ static ssize_t read_from_oldmem(char *buf, size_t count,
63199 nr_bytes = count;
63200
63201 /* If pfn is not ram, return zeros for sparse dump files */
63202 - if (pfn_is_ram(pfn) == 0)
63203 - memset(buf, 0, nr_bytes);
63204 - else {
63205 + if (pfn_is_ram(pfn) == 0) {
63206 + if (userbuf) {
63207 + if (clear_user((char __force_user *)buf, nr_bytes))
63208 + return -EFAULT;
63209 + } else
63210 + memset(buf, 0, nr_bytes);
63211 + } else {
63212 tmp = copy_oldmem_page(pfn, buf, nr_bytes,
63213 offset, userbuf);
63214 if (tmp < 0)
63215 @@ -170,7 +174,7 @@ int __weak remap_oldmem_pfn_range(struct vm_area_struct *vma,
63216 static int copy_to(void *target, void *src, size_t size, int userbuf)
63217 {
63218 if (userbuf) {
63219 - if (copy_to_user((char __user *) target, src, size))
63220 + if (copy_to_user((char __force_user *) target, src, size))
63221 return -EFAULT;
63222 } else {
63223 memcpy(target, src, size);
63224 @@ -233,7 +237,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
63225 if (*fpos < m->offset + m->size) {
63226 tsz = min_t(size_t, m->offset + m->size - *fpos, buflen);
63227 start = m->paddr + *fpos - m->offset;
63228 - tmp = read_from_oldmem(buffer, tsz, &start, userbuf);
63229 + tmp = read_from_oldmem((char __force_kernel *)buffer, tsz, &start, userbuf);
63230 if (tmp < 0)
63231 return tmp;
63232 buflen -= tsz;
63233 @@ -253,7 +257,7 @@ static ssize_t __read_vmcore(char *buffer, size_t buflen, loff_t *fpos,
63234 static ssize_t read_vmcore(struct file *file, char __user *buffer,
63235 size_t buflen, loff_t *fpos)
63236 {
63237 - return __read_vmcore((__force char *) buffer, buflen, fpos, 1);
63238 + return __read_vmcore((__force_kernel char *) buffer, buflen, fpos, 1);
63239 }
63240
63241 /*
63242 diff --git a/fs/qnx6/qnx6.h b/fs/qnx6/qnx6.h
63243 index b00fcc9..e0c6381 100644
63244 --- a/fs/qnx6/qnx6.h
63245 +++ b/fs/qnx6/qnx6.h
63246 @@ -74,7 +74,7 @@ enum {
63247 BYTESEX_BE,
63248 };
63249
63250 -static inline __u64 fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
63251 +static inline __u64 __intentional_overflow(-1) fs64_to_cpu(struct qnx6_sb_info *sbi, __fs64 n)
63252 {
63253 if (sbi->s_bytesex == BYTESEX_LE)
63254 return le64_to_cpu((__force __le64)n);
63255 @@ -90,7 +90,7 @@ static inline __fs64 cpu_to_fs64(struct qnx6_sb_info *sbi, __u64 n)
63256 return (__force __fs64)cpu_to_be64(n);
63257 }
63258
63259 -static inline __u32 fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
63260 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct qnx6_sb_info *sbi, __fs32 n)
63261 {
63262 if (sbi->s_bytesex == BYTESEX_LE)
63263 return le32_to_cpu((__force __le32)n);
63264 diff --git a/fs/quota/netlink.c b/fs/quota/netlink.c
63265 index 72d2917..c917c12 100644
63266 --- a/fs/quota/netlink.c
63267 +++ b/fs/quota/netlink.c
63268 @@ -45,7 +45,7 @@ static struct genl_family quota_genl_family = {
63269 void quota_send_warning(struct kqid qid, dev_t dev,
63270 const char warntype)
63271 {
63272 - static atomic_t seq;
63273 + static atomic_unchecked_t seq;
63274 struct sk_buff *skb;
63275 void *msg_head;
63276 int ret;
63277 @@ -61,7 +61,7 @@ void quota_send_warning(struct kqid qid, dev_t dev,
63278 "VFS: Not enough memory to send quota warning.\n");
63279 return;
63280 }
63281 - msg_head = genlmsg_put(skb, 0, atomic_add_return(1, &seq),
63282 + msg_head = genlmsg_put(skb, 0, atomic_add_return_unchecked(1, &seq),
63283 &quota_genl_family, 0, QUOTA_NL_C_WARNING);
63284 if (!msg_head) {
63285 printk(KERN_ERR
63286 diff --git a/fs/read_write.c b/fs/read_write.c
63287 index cfa18df..c110979 100644
63288 --- a/fs/read_write.c
63289 +++ b/fs/read_write.c
63290 @@ -438,7 +438,7 @@ ssize_t __kernel_write(struct file *file, const char *buf, size_t count, loff_t
63291
63292 old_fs = get_fs();
63293 set_fs(get_ds());
63294 - p = (__force const char __user *)buf;
63295 + p = (const char __force_user *)buf;
63296 if (count > MAX_RW_COUNT)
63297 count = MAX_RW_COUNT;
63298 if (file->f_op->write)
63299 diff --git a/fs/readdir.c b/fs/readdir.c
63300 index 5b53d99..a6c3049 100644
63301 --- a/fs/readdir.c
63302 +++ b/fs/readdir.c
63303 @@ -17,6 +17,7 @@
63304 #include <linux/security.h>
63305 #include <linux/syscalls.h>
63306 #include <linux/unistd.h>
63307 +#include <linux/namei.h>
63308
63309 #include <asm/uaccess.h>
63310
63311 @@ -69,6 +70,7 @@ struct old_linux_dirent {
63312 struct readdir_callback {
63313 struct dir_context ctx;
63314 struct old_linux_dirent __user * dirent;
63315 + struct file * file;
63316 int result;
63317 };
63318
63319 @@ -86,6 +88,10 @@ static int fillonedir(void * __buf, const char * name, int namlen, loff_t offset
63320 buf->result = -EOVERFLOW;
63321 return -EOVERFLOW;
63322 }
63323 +
63324 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
63325 + return 0;
63326 +
63327 buf->result++;
63328 dirent = buf->dirent;
63329 if (!access_ok(VERIFY_WRITE, dirent,
63330 @@ -117,6 +123,7 @@ SYSCALL_DEFINE3(old_readdir, unsigned int, fd,
63331 if (!f.file)
63332 return -EBADF;
63333
63334 + buf.file = f.file;
63335 error = iterate_dir(f.file, &buf.ctx);
63336 if (buf.result)
63337 error = buf.result;
63338 @@ -142,6 +149,7 @@ struct getdents_callback {
63339 struct dir_context ctx;
63340 struct linux_dirent __user * current_dir;
63341 struct linux_dirent __user * previous;
63342 + struct file * file;
63343 int count;
63344 int error;
63345 };
63346 @@ -163,6 +171,10 @@ static int filldir(void * __buf, const char * name, int namlen, loff_t offset,
63347 buf->error = -EOVERFLOW;
63348 return -EOVERFLOW;
63349 }
63350 +
63351 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
63352 + return 0;
63353 +
63354 dirent = buf->previous;
63355 if (dirent) {
63356 if (__put_user(offset, &dirent->d_off))
63357 @@ -208,6 +220,7 @@ SYSCALL_DEFINE3(getdents, unsigned int, fd,
63358 if (!f.file)
63359 return -EBADF;
63360
63361 + buf.file = f.file;
63362 error = iterate_dir(f.file, &buf.ctx);
63363 if (error >= 0)
63364 error = buf.error;
63365 @@ -226,6 +239,7 @@ struct getdents_callback64 {
63366 struct dir_context ctx;
63367 struct linux_dirent64 __user * current_dir;
63368 struct linux_dirent64 __user * previous;
63369 + struct file *file;
63370 int count;
63371 int error;
63372 };
63373 @@ -241,6 +255,10 @@ static int filldir64(void * __buf, const char * name, int namlen, loff_t offset,
63374 buf->error = -EINVAL; /* only used if we fail.. */
63375 if (reclen > buf->count)
63376 return -EINVAL;
63377 +
63378 + if (!gr_acl_handle_filldir(buf->file, name, namlen, ino))
63379 + return 0;
63380 +
63381 dirent = buf->previous;
63382 if (dirent) {
63383 if (__put_user(offset, &dirent->d_off))
63384 @@ -288,6 +306,7 @@ SYSCALL_DEFINE3(getdents64, unsigned int, fd,
63385 if (!f.file)
63386 return -EBADF;
63387
63388 + buf.file = f.file;
63389 error = iterate_dir(f.file, &buf.ctx);
63390 if (error >= 0)
63391 error = buf.error;
63392 diff --git a/fs/reiserfs/do_balan.c b/fs/reiserfs/do_balan.c
63393 index 2b7882b..1c5ef48 100644
63394 --- a/fs/reiserfs/do_balan.c
63395 +++ b/fs/reiserfs/do_balan.c
63396 @@ -2051,7 +2051,7 @@ void do_balance(struct tree_balance *tb, /* tree_balance structure */
63397 return;
63398 }
63399
63400 - atomic_inc(&(fs_generation(tb->tb_sb)));
63401 + atomic_inc_unchecked(&(fs_generation(tb->tb_sb)));
63402 do_balance_starts(tb);
63403
63404 /* balance leaf returns 0 except if combining L R and S into
63405 diff --git a/fs/reiserfs/item_ops.c b/fs/reiserfs/item_ops.c
63406 index ee382ef..f4eb6eb5 100644
63407 --- a/fs/reiserfs/item_ops.c
63408 +++ b/fs/reiserfs/item_ops.c
63409 @@ -725,18 +725,18 @@ static void errcatch_print_vi(struct virtual_item *vi)
63410 }
63411
63412 static struct item_operations errcatch_ops = {
63413 - errcatch_bytes_number,
63414 - errcatch_decrement_key,
63415 - errcatch_is_left_mergeable,
63416 - errcatch_print_item,
63417 - errcatch_check_item,
63418 + .bytes_number = errcatch_bytes_number,
63419 + .decrement_key = errcatch_decrement_key,
63420 + .is_left_mergeable = errcatch_is_left_mergeable,
63421 + .print_item = errcatch_print_item,
63422 + .check_item = errcatch_check_item,
63423
63424 - errcatch_create_vi,
63425 - errcatch_check_left,
63426 - errcatch_check_right,
63427 - errcatch_part_size,
63428 - errcatch_unit_num,
63429 - errcatch_print_vi
63430 + .create_vi = errcatch_create_vi,
63431 + .check_left = errcatch_check_left,
63432 + .check_right = errcatch_check_right,
63433 + .part_size = errcatch_part_size,
63434 + .unit_num = errcatch_unit_num,
63435 + .print_vi = errcatch_print_vi
63436 };
63437
63438 //////////////////////////////////////////////////////////////////////////////
63439 diff --git a/fs/reiserfs/procfs.c b/fs/reiserfs/procfs.c
63440 index a958444..42b2323 100644
63441 --- a/fs/reiserfs/procfs.c
63442 +++ b/fs/reiserfs/procfs.c
63443 @@ -114,7 +114,7 @@ static int show_super(struct seq_file *m, void *unused)
63444 "SMALL_TAILS " : "NO_TAILS ",
63445 replay_only(sb) ? "REPLAY_ONLY " : "",
63446 convert_reiserfs(sb) ? "CONV " : "",
63447 - atomic_read(&r->s_generation_counter),
63448 + atomic_read_unchecked(&r->s_generation_counter),
63449 SF(s_disk_reads), SF(s_disk_writes), SF(s_fix_nodes),
63450 SF(s_do_balance), SF(s_unneeded_left_neighbor),
63451 SF(s_good_search_by_key_reada), SF(s_bmaps),
63452 diff --git a/fs/reiserfs/reiserfs.h b/fs/reiserfs/reiserfs.h
63453 index f8adaee..0eeeeca 100644
63454 --- a/fs/reiserfs/reiserfs.h
63455 +++ b/fs/reiserfs/reiserfs.h
63456 @@ -453,7 +453,7 @@ struct reiserfs_sb_info {
63457 /* Comment? -Hans */
63458 wait_queue_head_t s_wait;
63459 /* To be obsoleted soon by per buffer seals.. -Hans */
63460 - atomic_t s_generation_counter; // increased by one every time the
63461 + atomic_unchecked_t s_generation_counter; // increased by one every time the
63462 // tree gets re-balanced
63463 unsigned long s_properties; /* File system properties. Currently holds
63464 on-disk FS format */
63465 @@ -1982,7 +1982,7 @@ static inline loff_t max_reiserfs_offset(struct inode *inode)
63466 #define REISERFS_USER_MEM 1 /* reiserfs user memory mode */
63467
63468 #define fs_generation(s) (REISERFS_SB(s)->s_generation_counter)
63469 -#define get_generation(s) atomic_read (&fs_generation(s))
63470 +#define get_generation(s) atomic_read_unchecked (&fs_generation(s))
63471 #define FILESYSTEM_CHANGED_TB(tb) (get_generation((tb)->tb_sb) != (tb)->fs_gen)
63472 #define __fs_changed(gen,s) (gen != get_generation (s))
63473 #define fs_changed(gen,s) \
63474 diff --git a/fs/select.c b/fs/select.c
63475 index 467bb1c..cf9d65a 100644
63476 --- a/fs/select.c
63477 +++ b/fs/select.c
63478 @@ -20,6 +20,7 @@
63479 #include <linux/export.h>
63480 #include <linux/slab.h>
63481 #include <linux/poll.h>
63482 +#include <linux/security.h>
63483 #include <linux/personality.h> /* for STICKY_TIMEOUTS */
63484 #include <linux/file.h>
63485 #include <linux/fdtable.h>
63486 @@ -880,6 +881,7 @@ int do_sys_poll(struct pollfd __user *ufds, unsigned int nfds,
63487 struct poll_list *walk = head;
63488 unsigned long todo = nfds;
63489
63490 + gr_learn_resource(current, RLIMIT_NOFILE, nfds, 1);
63491 if (nfds > rlimit(RLIMIT_NOFILE))
63492 return -EINVAL;
63493
63494 diff --git a/fs/seq_file.c b/fs/seq_file.c
63495 index 1d641bb..e600623 100644
63496 --- a/fs/seq_file.c
63497 +++ b/fs/seq_file.c
63498 @@ -10,6 +10,7 @@
63499 #include <linux/seq_file.h>
63500 #include <linux/slab.h>
63501 #include <linux/cred.h>
63502 +#include <linux/sched.h>
63503
63504 #include <asm/uaccess.h>
63505 #include <asm/page.h>
63506 @@ -60,6 +61,9 @@ int seq_open(struct file *file, const struct seq_operations *op)
63507 #ifdef CONFIG_USER_NS
63508 p->user_ns = file->f_cred->user_ns;
63509 #endif
63510 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
63511 + p->exec_id = current->exec_id;
63512 +#endif
63513
63514 /*
63515 * Wrappers around seq_open(e.g. swaps_open) need to be
63516 @@ -96,7 +100,7 @@ static int traverse(struct seq_file *m, loff_t offset)
63517 return 0;
63518 }
63519 if (!m->buf) {
63520 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
63521 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
63522 if (!m->buf)
63523 return -ENOMEM;
63524 }
63525 @@ -137,7 +141,7 @@ Eoverflow:
63526 m->op->stop(m, p);
63527 kfree(m->buf);
63528 m->count = 0;
63529 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
63530 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
63531 return !m->buf ? -ENOMEM : -EAGAIN;
63532 }
63533
63534 @@ -153,7 +157,7 @@ Eoverflow:
63535 ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
63536 {
63537 struct seq_file *m = file->private_data;
63538 - size_t copied = 0;
63539 + ssize_t copied = 0;
63540 loff_t pos;
63541 size_t n;
63542 void *p;
63543 @@ -192,7 +196,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
63544
63545 /* grab buffer if we didn't have one */
63546 if (!m->buf) {
63547 - m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL);
63548 + m->buf = kmalloc(m->size = PAGE_SIZE, GFP_KERNEL | GFP_USERCOPY);
63549 if (!m->buf)
63550 goto Enomem;
63551 }
63552 @@ -234,7 +238,7 @@ ssize_t seq_read(struct file *file, char __user *buf, size_t size, loff_t *ppos)
63553 m->op->stop(m, p);
63554 kfree(m->buf);
63555 m->count = 0;
63556 - m->buf = kmalloc(m->size <<= 1, GFP_KERNEL);
63557 + m->buf = kmalloc(m->size <<= 1, GFP_KERNEL | GFP_USERCOPY);
63558 if (!m->buf)
63559 goto Enomem;
63560 m->version = 0;
63561 @@ -584,7 +588,7 @@ static void single_stop(struct seq_file *p, void *v)
63562 int single_open(struct file *file, int (*show)(struct seq_file *, void *),
63563 void *data)
63564 {
63565 - struct seq_operations *op = kmalloc(sizeof(*op), GFP_KERNEL);
63566 + seq_operations_no_const *op = kzalloc(sizeof(*op), GFP_KERNEL);
63567 int res = -ENOMEM;
63568
63569 if (op) {
63570 diff --git a/fs/splice.c b/fs/splice.c
63571 index 12028fa..a6f2619 100644
63572 --- a/fs/splice.c
63573 +++ b/fs/splice.c
63574 @@ -196,7 +196,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
63575 pipe_lock(pipe);
63576
63577 for (;;) {
63578 - if (!pipe->readers) {
63579 + if (!atomic_read(&pipe->readers)) {
63580 send_sig(SIGPIPE, current, 0);
63581 if (!ret)
63582 ret = -EPIPE;
63583 @@ -219,7 +219,7 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
63584 page_nr++;
63585 ret += buf->len;
63586
63587 - if (pipe->files)
63588 + if (atomic_read(&pipe->files))
63589 do_wakeup = 1;
63590
63591 if (!--spd->nr_pages)
63592 @@ -250,9 +250,9 @@ ssize_t splice_to_pipe(struct pipe_inode_info *pipe,
63593 do_wakeup = 0;
63594 }
63595
63596 - pipe->waiting_writers++;
63597 + atomic_inc(&pipe->waiting_writers);
63598 pipe_wait(pipe);
63599 - pipe->waiting_writers--;
63600 + atomic_dec(&pipe->waiting_writers);
63601 }
63602
63603 pipe_unlock(pipe);
63604 @@ -583,7 +583,7 @@ static ssize_t kernel_readv(struct file *file, const struct iovec *vec,
63605 old_fs = get_fs();
63606 set_fs(get_ds());
63607 /* The cast to a user pointer is valid due to the set_fs() */
63608 - res = vfs_readv(file, (const struct iovec __user *)vec, vlen, &pos);
63609 + res = vfs_readv(file, (const struct iovec __force_user *)vec, vlen, &pos);
63610 set_fs(old_fs);
63611
63612 return res;
63613 @@ -598,7 +598,7 @@ ssize_t kernel_write(struct file *file, const char *buf, size_t count,
63614 old_fs = get_fs();
63615 set_fs(get_ds());
63616 /* The cast to a user pointer is valid due to the set_fs() */
63617 - res = vfs_write(file, (__force const char __user *)buf, count, &pos);
63618 + res = vfs_write(file, (const char __force_user *)buf, count, &pos);
63619 set_fs(old_fs);
63620
63621 return res;
63622 @@ -651,7 +651,7 @@ ssize_t default_file_splice_read(struct file *in, loff_t *ppos,
63623 goto err;
63624
63625 this_len = min_t(size_t, len, PAGE_CACHE_SIZE - offset);
63626 - vec[i].iov_base = (void __user *) page_address(page);
63627 + vec[i].iov_base = (void __force_user *) page_address(page);
63628 vec[i].iov_len = this_len;
63629 spd.pages[i] = page;
63630 spd.nr_pages++;
63631 @@ -847,7 +847,7 @@ int splice_from_pipe_feed(struct pipe_inode_info *pipe, struct splice_desc *sd,
63632 ops->release(pipe, buf);
63633 pipe->curbuf = (pipe->curbuf + 1) & (pipe->buffers - 1);
63634 pipe->nrbufs--;
63635 - if (pipe->files)
63636 + if (atomic_read(&pipe->files))
63637 sd->need_wakeup = true;
63638 }
63639
63640 @@ -872,10 +872,10 @@ EXPORT_SYMBOL(splice_from_pipe_feed);
63641 int splice_from_pipe_next(struct pipe_inode_info *pipe, struct splice_desc *sd)
63642 {
63643 while (!pipe->nrbufs) {
63644 - if (!pipe->writers)
63645 + if (!atomic_read(&pipe->writers))
63646 return 0;
63647
63648 - if (!pipe->waiting_writers && sd->num_spliced)
63649 + if (!atomic_read(&pipe->waiting_writers) && sd->num_spliced)
63650 return 0;
63651
63652 if (sd->flags & SPLICE_F_NONBLOCK)
63653 @@ -1197,7 +1197,7 @@ ssize_t splice_direct_to_actor(struct file *in, struct splice_desc *sd,
63654 * out of the pipe right after the splice_to_pipe(). So set
63655 * PIPE_READERS appropriately.
63656 */
63657 - pipe->readers = 1;
63658 + atomic_set(&pipe->readers, 1);
63659
63660 current->splice_pipe = pipe;
63661 }
63662 @@ -1493,6 +1493,7 @@ static int get_iovec_page_array(const struct iovec __user *iov,
63663
63664 partial[buffers].offset = off;
63665 partial[buffers].len = plen;
63666 + partial[buffers].private = 0;
63667
63668 off = 0;
63669 len -= plen;
63670 @@ -1795,9 +1796,9 @@ static int ipipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
63671 ret = -ERESTARTSYS;
63672 break;
63673 }
63674 - if (!pipe->writers)
63675 + if (!atomic_read(&pipe->writers))
63676 break;
63677 - if (!pipe->waiting_writers) {
63678 + if (!atomic_read(&pipe->waiting_writers)) {
63679 if (flags & SPLICE_F_NONBLOCK) {
63680 ret = -EAGAIN;
63681 break;
63682 @@ -1829,7 +1830,7 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
63683 pipe_lock(pipe);
63684
63685 while (pipe->nrbufs >= pipe->buffers) {
63686 - if (!pipe->readers) {
63687 + if (!atomic_read(&pipe->readers)) {
63688 send_sig(SIGPIPE, current, 0);
63689 ret = -EPIPE;
63690 break;
63691 @@ -1842,9 +1843,9 @@ static int opipe_prep(struct pipe_inode_info *pipe, unsigned int flags)
63692 ret = -ERESTARTSYS;
63693 break;
63694 }
63695 - pipe->waiting_writers++;
63696 + atomic_inc(&pipe->waiting_writers);
63697 pipe_wait(pipe);
63698 - pipe->waiting_writers--;
63699 + atomic_dec(&pipe->waiting_writers);
63700 }
63701
63702 pipe_unlock(pipe);
63703 @@ -1880,14 +1881,14 @@ retry:
63704 pipe_double_lock(ipipe, opipe);
63705
63706 do {
63707 - if (!opipe->readers) {
63708 + if (!atomic_read(&opipe->readers)) {
63709 send_sig(SIGPIPE, current, 0);
63710 if (!ret)
63711 ret = -EPIPE;
63712 break;
63713 }
63714
63715 - if (!ipipe->nrbufs && !ipipe->writers)
63716 + if (!ipipe->nrbufs && !atomic_read(&ipipe->writers))
63717 break;
63718
63719 /*
63720 @@ -1984,7 +1985,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
63721 pipe_double_lock(ipipe, opipe);
63722
63723 do {
63724 - if (!opipe->readers) {
63725 + if (!atomic_read(&opipe->readers)) {
63726 send_sig(SIGPIPE, current, 0);
63727 if (!ret)
63728 ret = -EPIPE;
63729 @@ -2029,7 +2030,7 @@ static int link_pipe(struct pipe_inode_info *ipipe,
63730 * return EAGAIN if we have the potential of some data in the
63731 * future, otherwise just return 0
63732 */
63733 - if (!ret && ipipe->waiting_writers && (flags & SPLICE_F_NONBLOCK))
63734 + if (!ret && atomic_read(&ipipe->waiting_writers) && (flags & SPLICE_F_NONBLOCK))
63735 ret = -EAGAIN;
63736
63737 pipe_unlock(ipipe);
63738 diff --git a/fs/stat.c b/fs/stat.c
63739 index ae0c3ce..9ee641c 100644
63740 --- a/fs/stat.c
63741 +++ b/fs/stat.c
63742 @@ -28,8 +28,13 @@ void generic_fillattr(struct inode *inode, struct kstat *stat)
63743 stat->gid = inode->i_gid;
63744 stat->rdev = inode->i_rdev;
63745 stat->size = i_size_read(inode);
63746 - stat->atime = inode->i_atime;
63747 - stat->mtime = inode->i_mtime;
63748 + if (is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
63749 + stat->atime = inode->i_ctime;
63750 + stat->mtime = inode->i_ctime;
63751 + } else {
63752 + stat->atime = inode->i_atime;
63753 + stat->mtime = inode->i_mtime;
63754 + }
63755 stat->ctime = inode->i_ctime;
63756 stat->blksize = (1 << inode->i_blkbits);
63757 stat->blocks = inode->i_blocks;
63758 @@ -52,9 +57,16 @@ EXPORT_SYMBOL(generic_fillattr);
63759 int vfs_getattr_nosec(struct path *path, struct kstat *stat)
63760 {
63761 struct inode *inode = path->dentry->d_inode;
63762 + int retval;
63763
63764 - if (inode->i_op->getattr)
63765 - return inode->i_op->getattr(path->mnt, path->dentry, stat);
63766 + if (inode->i_op->getattr) {
63767 + retval = inode->i_op->getattr(path->mnt, path->dentry, stat);
63768 + if (!retval && is_sidechannel_device(inode) && !capable_nolog(CAP_MKNOD)) {
63769 + stat->atime = stat->ctime;
63770 + stat->mtime = stat->ctime;
63771 + }
63772 + return retval;
63773 + }
63774
63775 generic_fillattr(inode, stat);
63776 return 0;
63777 diff --git a/fs/sysfs/dir.c b/fs/sysfs/dir.c
63778 index 5e73d66..4f165fd 100644
63779 --- a/fs/sysfs/dir.c
63780 +++ b/fs/sysfs/dir.c
63781 @@ -40,7 +40,7 @@ static DEFINE_IDA(sysfs_ino_ida);
63782 *
63783 * Returns 31 bit hash of ns + name (so it fits in an off_t )
63784 */
63785 -static unsigned int sysfs_name_hash(const char *name, const void *ns)
63786 +static unsigned int sysfs_name_hash(const unsigned char *name, const void *ns)
63787 {
63788 unsigned long hash = init_name_hash();
63789 unsigned int len = strlen(name);
63790 @@ -676,6 +676,18 @@ static int create_dir(struct kobject *kobj, struct sysfs_dirent *parent_sd,
63791 struct sysfs_dirent *sd;
63792 int rc;
63793
63794 +#ifdef CONFIG_GRKERNSEC_SYSFS_RESTRICT
63795 + const char *parent_name = parent_sd->s_name;
63796 +
63797 + mode = S_IFDIR | S_IRWXU;
63798 +
63799 + if ((!strcmp(parent_name, "") && (!strcmp(name, "devices") || !strcmp(name, "fs"))) ||
63800 + (!strcmp(parent_name, "devices") && !strcmp(name, "system")) ||
63801 + (!strcmp(parent_name, "fs") && (!strcmp(name, "selinux") || !strcmp(name, "fuse") || !strcmp(name, "ecryptfs"))) ||
63802 + (!strcmp(parent_name, "system") && !strcmp(name, "cpu")))
63803 + mode = S_IFDIR | S_IRWXU | S_IRUGO | S_IXUGO;
63804 +#endif
63805 +
63806 /* allocate */
63807 sd = sysfs_new_dirent(name, mode, SYSFS_DIR);
63808 if (!sd)
63809 diff --git a/fs/sysfs/file.c b/fs/sysfs/file.c
63810 index 35e7d08..4d6e676 100644
63811 --- a/fs/sysfs/file.c
63812 +++ b/fs/sysfs/file.c
63813 @@ -42,7 +42,7 @@ static DEFINE_MUTEX(sysfs_open_file_mutex);
63814
63815 struct sysfs_open_dirent {
63816 atomic_t refcnt;
63817 - atomic_t event;
63818 + atomic_unchecked_t event;
63819 wait_queue_head_t poll;
63820 struct list_head files; /* goes through sysfs_open_file.list */
63821 };
63822 @@ -112,7 +112,7 @@ static int sysfs_seq_show(struct seq_file *sf, void *v)
63823 return -ENODEV;
63824 }
63825
63826 - of->event = atomic_read(&of->sd->s_attr.open->event);
63827 + of->event = atomic_read_unchecked(&of->sd->s_attr.open->event);
63828
63829 /*
63830 * Lookup @ops and invoke show(). Control may reach here via seq
63831 @@ -365,12 +365,12 @@ static int sysfs_bin_page_mkwrite(struct vm_area_struct *vma,
63832 return ret;
63833 }
63834
63835 -static int sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr,
63836 - void *buf, int len, int write)
63837 +static ssize_t sysfs_bin_access(struct vm_area_struct *vma, unsigned long addr,
63838 + void *buf, size_t len, int write)
63839 {
63840 struct file *file = vma->vm_file;
63841 struct sysfs_open_file *of = sysfs_of(file);
63842 - int ret;
63843 + ssize_t ret;
63844
63845 if (!of->vm_ops)
63846 return -EINVAL;
63847 @@ -564,7 +564,7 @@ static int sysfs_get_open_dirent(struct sysfs_dirent *sd,
63848 return -ENOMEM;
63849
63850 atomic_set(&new_od->refcnt, 0);
63851 - atomic_set(&new_od->event, 1);
63852 + atomic_set_unchecked(&new_od->event, 1);
63853 init_waitqueue_head(&new_od->poll);
63854 INIT_LIST_HEAD(&new_od->files);
63855 goto retry;
63856 @@ -768,7 +768,7 @@ static unsigned int sysfs_poll(struct file *filp, poll_table *wait)
63857
63858 sysfs_put_active(attr_sd);
63859
63860 - if (of->event != atomic_read(&od->event))
63861 + if (of->event != atomic_read_unchecked(&od->event))
63862 goto trigger;
63863
63864 return DEFAULT_POLLMASK;
63865 @@ -787,7 +787,7 @@ void sysfs_notify_dirent(struct sysfs_dirent *sd)
63866 if (!WARN_ON(sysfs_type(sd) != SYSFS_KOBJ_ATTR)) {
63867 od = sd->s_attr.open;
63868 if (od) {
63869 - atomic_inc(&od->event);
63870 + atomic_inc_unchecked(&od->event);
63871 wake_up_interruptible(&od->poll);
63872 }
63873 }
63874 diff --git a/fs/sysfs/symlink.c b/fs/sysfs/symlink.c
63875 index 3ae3f1b..081a26c 100644
63876 --- a/fs/sysfs/symlink.c
63877 +++ b/fs/sysfs/symlink.c
63878 @@ -314,7 +314,7 @@ static void *sysfs_follow_link(struct dentry *dentry, struct nameidata *nd)
63879 static void sysfs_put_link(struct dentry *dentry, struct nameidata *nd,
63880 void *cookie)
63881 {
63882 - char *page = nd_get_link(nd);
63883 + const char *page = nd_get_link(nd);
63884 if (!IS_ERR(page))
63885 free_page((unsigned long)page);
63886 }
63887 diff --git a/fs/sysv/sysv.h b/fs/sysv/sysv.h
63888 index 69d4889..a810bd4 100644
63889 --- a/fs/sysv/sysv.h
63890 +++ b/fs/sysv/sysv.h
63891 @@ -188,7 +188,7 @@ static inline u32 PDP_swab(u32 x)
63892 #endif
63893 }
63894
63895 -static inline __u32 fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
63896 +static inline __u32 __intentional_overflow(-1) fs32_to_cpu(struct sysv_sb_info *sbi, __fs32 n)
63897 {
63898 if (sbi->s_bytesex == BYTESEX_PDP)
63899 return PDP_swab((__force __u32)n);
63900 diff --git a/fs/ubifs/io.c b/fs/ubifs/io.c
63901 index e18b988..f1d4ad0f 100644
63902 --- a/fs/ubifs/io.c
63903 +++ b/fs/ubifs/io.c
63904 @@ -155,7 +155,7 @@ int ubifs_leb_change(struct ubifs_info *c, int lnum, const void *buf, int len)
63905 return err;
63906 }
63907
63908 -int ubifs_leb_unmap(struct ubifs_info *c, int lnum)
63909 +int __intentional_overflow(-1) ubifs_leb_unmap(struct ubifs_info *c, int lnum)
63910 {
63911 int err;
63912
63913 diff --git a/fs/udf/misc.c b/fs/udf/misc.c
63914 index c175b4d..8f36a16 100644
63915 --- a/fs/udf/misc.c
63916 +++ b/fs/udf/misc.c
63917 @@ -289,7 +289,7 @@ void udf_new_tag(char *data, uint16_t ident, uint16_t version, uint16_t snum,
63918
63919 u8 udf_tag_checksum(const struct tag *t)
63920 {
63921 - u8 *data = (u8 *)t;
63922 + const u8 *data = (const u8 *)t;
63923 u8 checksum = 0;
63924 int i;
63925 for (i = 0; i < sizeof(struct tag); ++i)
63926 diff --git a/fs/ufs/swab.h b/fs/ufs/swab.h
63927 index 8d974c4..b82f6ec 100644
63928 --- a/fs/ufs/swab.h
63929 +++ b/fs/ufs/swab.h
63930 @@ -22,7 +22,7 @@ enum {
63931 BYTESEX_BE
63932 };
63933
63934 -static inline u64
63935 +static inline u64 __intentional_overflow(-1)
63936 fs64_to_cpu(struct super_block *sbp, __fs64 n)
63937 {
63938 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
63939 @@ -40,7 +40,7 @@ cpu_to_fs64(struct super_block *sbp, u64 n)
63940 return (__force __fs64)cpu_to_be64(n);
63941 }
63942
63943 -static inline u32
63944 +static inline u32 __intentional_overflow(-1)
63945 fs32_to_cpu(struct super_block *sbp, __fs32 n)
63946 {
63947 if (UFS_SB(sbp)->s_bytesex == BYTESEX_LE)
63948 diff --git a/fs/utimes.c b/fs/utimes.c
63949 index aa138d6..5f3a811 100644
63950 --- a/fs/utimes.c
63951 +++ b/fs/utimes.c
63952 @@ -1,6 +1,7 @@
63953 #include <linux/compiler.h>
63954 #include <linux/file.h>
63955 #include <linux/fs.h>
63956 +#include <linux/security.h>
63957 #include <linux/linkage.h>
63958 #include <linux/mount.h>
63959 #include <linux/namei.h>
63960 @@ -103,6 +104,12 @@ static int utimes_common(struct path *path, struct timespec *times)
63961 }
63962 }
63963 retry_deleg:
63964 +
63965 + if (!gr_acl_handle_utime(path->dentry, path->mnt)) {
63966 + error = -EACCES;
63967 + goto mnt_drop_write_and_out;
63968 + }
63969 +
63970 mutex_lock(&inode->i_mutex);
63971 error = notify_change(path->dentry, &newattrs, &delegated_inode);
63972 mutex_unlock(&inode->i_mutex);
63973 diff --git a/fs/xattr.c b/fs/xattr.c
63974 index 3377dff..f394815 100644
63975 --- a/fs/xattr.c
63976 +++ b/fs/xattr.c
63977 @@ -227,6 +227,27 @@ int vfs_xattr_cmp(struct dentry *dentry, const char *xattr_name,
63978 return rc;
63979 }
63980
63981 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
63982 +ssize_t
63983 +pax_getxattr(struct dentry *dentry, void *value, size_t size)
63984 +{
63985 + struct inode *inode = dentry->d_inode;
63986 + ssize_t error;
63987 +
63988 + error = inode_permission(inode, MAY_EXEC);
63989 + if (error)
63990 + return error;
63991 +
63992 + if (inode->i_op->getxattr)
63993 + error = inode->i_op->getxattr(dentry, XATTR_NAME_PAX_FLAGS, value, size);
63994 + else
63995 + error = -EOPNOTSUPP;
63996 +
63997 + return error;
63998 +}
63999 +EXPORT_SYMBOL(pax_getxattr);
64000 +#endif
64001 +
64002 ssize_t
64003 vfs_getxattr(struct dentry *dentry, const char *name, void *value, size_t size)
64004 {
64005 @@ -319,7 +340,7 @@ EXPORT_SYMBOL_GPL(vfs_removexattr);
64006 * Extended attribute SET operations
64007 */
64008 static long
64009 -setxattr(struct dentry *d, const char __user *name, const void __user *value,
64010 +setxattr(struct path *path, const char __user *name, const void __user *value,
64011 size_t size, int flags)
64012 {
64013 int error;
64014 @@ -355,7 +376,12 @@ setxattr(struct dentry *d, const char __user *name, const void __user *value,
64015 posix_acl_fix_xattr_from_user(kvalue, size);
64016 }
64017
64018 - error = vfs_setxattr(d, kname, kvalue, size, flags);
64019 + if (!gr_acl_handle_setxattr(path->dentry, path->mnt)) {
64020 + error = -EACCES;
64021 + goto out;
64022 + }
64023 +
64024 + error = vfs_setxattr(path->dentry, kname, kvalue, size, flags);
64025 out:
64026 if (vvalue)
64027 vfree(vvalue);
64028 @@ -377,7 +403,7 @@ retry:
64029 return error;
64030 error = mnt_want_write(path.mnt);
64031 if (!error) {
64032 - error = setxattr(path.dentry, name, value, size, flags);
64033 + error = setxattr(&path, name, value, size, flags);
64034 mnt_drop_write(path.mnt);
64035 }
64036 path_put(&path);
64037 @@ -401,7 +427,7 @@ retry:
64038 return error;
64039 error = mnt_want_write(path.mnt);
64040 if (!error) {
64041 - error = setxattr(path.dentry, name, value, size, flags);
64042 + error = setxattr(&path, name, value, size, flags);
64043 mnt_drop_write(path.mnt);
64044 }
64045 path_put(&path);
64046 @@ -416,16 +442,14 @@ SYSCALL_DEFINE5(fsetxattr, int, fd, const char __user *, name,
64047 const void __user *,value, size_t, size, int, flags)
64048 {
64049 struct fd f = fdget(fd);
64050 - struct dentry *dentry;
64051 int error = -EBADF;
64052
64053 if (!f.file)
64054 return error;
64055 - dentry = f.file->f_path.dentry;
64056 - audit_inode(NULL, dentry, 0);
64057 + audit_inode(NULL, f.file->f_path.dentry, 0);
64058 error = mnt_want_write_file(f.file);
64059 if (!error) {
64060 - error = setxattr(dentry, name, value, size, flags);
64061 + error = setxattr(&f.file->f_path, name, value, size, flags);
64062 mnt_drop_write_file(f.file);
64063 }
64064 fdput(f);
64065 @@ -626,7 +650,7 @@ SYSCALL_DEFINE3(flistxattr, int, fd, char __user *, list, size_t, size)
64066 * Extended attribute REMOVE operations
64067 */
64068 static long
64069 -removexattr(struct dentry *d, const char __user *name)
64070 +removexattr(struct path *path, const char __user *name)
64071 {
64072 int error;
64073 char kname[XATTR_NAME_MAX + 1];
64074 @@ -637,7 +661,10 @@ removexattr(struct dentry *d, const char __user *name)
64075 if (error < 0)
64076 return error;
64077
64078 - return vfs_removexattr(d, kname);
64079 + if (!gr_acl_handle_removexattr(path->dentry, path->mnt))
64080 + return -EACCES;
64081 +
64082 + return vfs_removexattr(path->dentry, kname);
64083 }
64084
64085 SYSCALL_DEFINE2(removexattr, const char __user *, pathname,
64086 @@ -652,7 +679,7 @@ retry:
64087 return error;
64088 error = mnt_want_write(path.mnt);
64089 if (!error) {
64090 - error = removexattr(path.dentry, name);
64091 + error = removexattr(&path, name);
64092 mnt_drop_write(path.mnt);
64093 }
64094 path_put(&path);
64095 @@ -675,7 +702,7 @@ retry:
64096 return error;
64097 error = mnt_want_write(path.mnt);
64098 if (!error) {
64099 - error = removexattr(path.dentry, name);
64100 + error = removexattr(&path, name);
64101 mnt_drop_write(path.mnt);
64102 }
64103 path_put(&path);
64104 @@ -689,16 +716,16 @@ retry:
64105 SYSCALL_DEFINE2(fremovexattr, int, fd, const char __user *, name)
64106 {
64107 struct fd f = fdget(fd);
64108 - struct dentry *dentry;
64109 + struct path *path;
64110 int error = -EBADF;
64111
64112 if (!f.file)
64113 return error;
64114 - dentry = f.file->f_path.dentry;
64115 - audit_inode(NULL, dentry, 0);
64116 + path = &f.file->f_path;
64117 + audit_inode(NULL, path->dentry, 0);
64118 error = mnt_want_write_file(f.file);
64119 if (!error) {
64120 - error = removexattr(dentry, name);
64121 + error = removexattr(path, name);
64122 mnt_drop_write_file(f.file);
64123 }
64124 fdput(f);
64125 diff --git a/fs/xattr_acl.c b/fs/xattr_acl.c
64126 index 9fbea87..6b19972 100644
64127 --- a/fs/xattr_acl.c
64128 +++ b/fs/xattr_acl.c
64129 @@ -76,8 +76,8 @@ struct posix_acl *
64130 posix_acl_from_xattr(struct user_namespace *user_ns,
64131 const void *value, size_t size)
64132 {
64133 - posix_acl_xattr_header *header = (posix_acl_xattr_header *)value;
64134 - posix_acl_xattr_entry *entry = (posix_acl_xattr_entry *)(header+1), *end;
64135 + const posix_acl_xattr_header *header = (const posix_acl_xattr_header *)value;
64136 + const posix_acl_xattr_entry *entry = (const posix_acl_xattr_entry *)(header+1), *end;
64137 int count;
64138 struct posix_acl *acl;
64139 struct posix_acl_entry *acl_e;
64140 diff --git a/fs/xfs/xfs_bmap.c b/fs/xfs/xfs_bmap.c
64141 index 3b2c14b..de031fe 100644
64142 --- a/fs/xfs/xfs_bmap.c
64143 +++ b/fs/xfs/xfs_bmap.c
64144 @@ -584,7 +584,7 @@ xfs_bmap_validate_ret(
64145
64146 #else
64147 #define xfs_bmap_check_leaf_extents(cur, ip, whichfork) do { } while (0)
64148 -#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap)
64149 +#define xfs_bmap_validate_ret(bno,len,flags,mval,onmap,nmap) do { } while (0)
64150 #endif /* DEBUG */
64151
64152 /*
64153 diff --git a/fs/xfs/xfs_dir2_readdir.c b/fs/xfs/xfs_dir2_readdir.c
64154 index c4e50c6..8ba93e3 100644
64155 --- a/fs/xfs/xfs_dir2_readdir.c
64156 +++ b/fs/xfs/xfs_dir2_readdir.c
64157 @@ -160,7 +160,12 @@ xfs_dir2_sf_getdents(
64158 ino = dp->d_ops->sf_get_ino(sfp, sfep);
64159 filetype = dp->d_ops->sf_get_ftype(sfep);
64160 ctx->pos = off & 0x7fffffff;
64161 - if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
64162 + if (dp->i_df.if_u1.if_data == dp->i_df.if_u2.if_inline_data) {
64163 + char name[sfep->namelen];
64164 + memcpy(name, sfep->name, sfep->namelen);
64165 + if (!dir_emit(ctx, name, sfep->namelen, ino, xfs_dir3_get_dtype(mp, filetype)))
64166 + return 0;
64167 + } else if (!dir_emit(ctx, (char *)sfep->name, sfep->namelen, ino,
64168 xfs_dir3_get_dtype(mp, filetype)))
64169 return 0;
64170 sfep = dp->d_ops->sf_nextentry(sfp, sfep);
64171 diff --git a/fs/xfs/xfs_ioctl.c b/fs/xfs/xfs_ioctl.c
64172 index 33ad9a7..82c18ba 100644
64173 --- a/fs/xfs/xfs_ioctl.c
64174 +++ b/fs/xfs/xfs_ioctl.c
64175 @@ -126,7 +126,7 @@ xfs_find_handle(
64176 }
64177
64178 error = -EFAULT;
64179 - if (copy_to_user(hreq->ohandle, &handle, hsize) ||
64180 + if (hsize > sizeof handle || copy_to_user(hreq->ohandle, &handle, hsize) ||
64181 copy_to_user(hreq->ohandlen, &hsize, sizeof(__s32)))
64182 goto out_put;
64183
64184 diff --git a/fs/xfs/xfs_iops.c b/fs/xfs/xfs_iops.c
64185 index 104455b..764c512 100644
64186 --- a/fs/xfs/xfs_iops.c
64187 +++ b/fs/xfs/xfs_iops.c
64188 @@ -397,7 +397,7 @@ xfs_vn_put_link(
64189 struct nameidata *nd,
64190 void *p)
64191 {
64192 - char *s = nd_get_link(nd);
64193 + const char *s = nd_get_link(nd);
64194
64195 if (!IS_ERR(s))
64196 kfree(s);
64197 diff --git a/grsecurity/Kconfig b/grsecurity/Kconfig
64198 new file mode 100644
64199 index 0000000..e98584b
64200 --- /dev/null
64201 +++ b/grsecurity/Kconfig
64202 @@ -0,0 +1,1147 @@
64203 +#
64204 +# grecurity configuration
64205 +#
64206 +menu "Memory Protections"
64207 +depends on GRKERNSEC
64208 +
64209 +config GRKERNSEC_KMEM
64210 + bool "Deny reading/writing to /dev/kmem, /dev/mem, and /dev/port"
64211 + default y if GRKERNSEC_CONFIG_AUTO
64212 + select STRICT_DEVMEM if (X86 || ARM || TILE || S390)
64213 + help
64214 + If you say Y here, /dev/kmem and /dev/mem won't be allowed to
64215 + be written to or read from to modify or leak the contents of the running
64216 + kernel. /dev/port will also not be allowed to be opened, and support
64217 + for /dev/cpu/*/msr and kexec will be removed. If you have module
64218 + support disabled, enabling this will close up six ways that are
64219 + currently used to insert malicious code into the running kernel.
64220 +
64221 + Even with this feature enabled, we still highly recommend that
64222 + you use the RBAC system, as it is still possible for an attacker to
64223 + modify the running kernel through other more obscure methods.
64224 +
64225 + Enabling this feature will prevent the "cpupower" and "powertop" tools
64226 + from working.
64227 +
64228 + It is highly recommended that you say Y here if you meet all the
64229 + conditions above.
64230 +
64231 +config GRKERNSEC_VM86
64232 + bool "Restrict VM86 mode"
64233 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
64234 + depends on X86_32
64235 +
64236 + help
64237 + If you say Y here, only processes with CAP_SYS_RAWIO will be able to
64238 + make use of a special execution mode on 32bit x86 processors called
64239 + Virtual 8086 (VM86) mode. XFree86 may need vm86 mode for certain
64240 + video cards and will still work with this option enabled. The purpose
64241 + of the option is to prevent exploitation of emulation errors in
64242 + virtualization of vm86 mode like the one discovered in VMWare in 2009.
64243 + Nearly all users should be able to enable this option.
64244 +
64245 +config GRKERNSEC_IO
64246 + bool "Disable privileged I/O"
64247 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
64248 + depends on X86
64249 + select RTC_CLASS
64250 + select RTC_INTF_DEV
64251 + select RTC_DRV_CMOS
64252 +
64253 + help
64254 + If you say Y here, all ioperm and iopl calls will return an error.
64255 + Ioperm and iopl can be used to modify the running kernel.
64256 + Unfortunately, some programs need this access to operate properly,
64257 + the most notable of which are XFree86 and hwclock. hwclock can be
64258 + remedied by having RTC support in the kernel, so real-time
64259 + clock support is enabled if this option is enabled, to ensure
64260 + that hwclock operates correctly.
64261 +
64262 + If you're using XFree86 or a version of Xorg from 2012 or earlier,
64263 + you may not be able to boot into a graphical environment with this
64264 + option enabled. In this case, you should use the RBAC system instead.
64265 +
64266 +config GRKERNSEC_JIT_HARDEN
64267 + bool "Harden BPF JIT against spray attacks"
64268 + default y if GRKERNSEC_CONFIG_AUTO
64269 + depends on BPF_JIT && X86
64270 + help
64271 + If you say Y here, the native code generated by the kernel's Berkeley
64272 + Packet Filter (BPF) JIT engine will be hardened against JIT-spraying
64273 + attacks that attempt to fit attacker-beneficial instructions in
64274 + 32bit immediate fields of JIT-generated native instructions. The
64275 + attacker will generally aim to cause an unintended instruction sequence
64276 + of JIT-generated native code to execute by jumping into the middle of
64277 + a generated instruction. This feature effectively randomizes the 32bit
64278 + immediate constants present in the generated code to thwart such attacks.
64279 +
64280 + If you're using KERNEXEC, it's recommended that you enable this option
64281 + to supplement the hardening of the kernel.
64282 +
64283 +config GRKERNSEC_PERF_HARDEN
64284 + bool "Disable unprivileged PERF_EVENTS usage by default"
64285 + default y if GRKERNSEC_CONFIG_AUTO
64286 + depends on PERF_EVENTS
64287 + help
64288 + If you say Y here, the range of acceptable values for the
64289 + /proc/sys/kernel/perf_event_paranoid sysctl will be expanded to allow and
64290 + default to a new value: 3. When the sysctl is set to this value, no
64291 + unprivileged use of the PERF_EVENTS syscall interface will be permitted.
64292 +
64293 + Though PERF_EVENTS can be used legitimately for performance monitoring
64294 + and low-level application profiling, it is forced on regardless of
64295 + configuration, has been at fault for several vulnerabilities, and
64296 + creates new opportunities for side channels and other information leaks.
64297 +
64298 + This feature puts PERF_EVENTS into a secure default state and permits
64299 + the administrator to change out of it temporarily if unprivileged
64300 + application profiling is needed.
64301 +
64302 +config GRKERNSEC_RAND_THREADSTACK
64303 + bool "Insert random gaps between thread stacks"
64304 + default y if GRKERNSEC_CONFIG_AUTO
64305 + depends on PAX_RANDMMAP && !PPC
64306 + help
64307 + If you say Y here, a random-sized gap will be enforced between allocated
64308 + thread stacks. Glibc's NPTL and other threading libraries that
64309 + pass MAP_STACK to the kernel for thread stack allocation are supported.
64310 + The implementation currently provides 8 bits of entropy for the gap.
64311 +
64312 + Many distributions do not compile threaded remote services with the
64313 + -fstack-check argument to GCC, causing the variable-sized stack-based
64314 + allocator, alloca(), to not probe the stack on allocation. This
64315 + permits an unbounded alloca() to skip over any guard page and potentially
64316 + modify another thread's stack reliably. An enforced random gap
64317 + reduces the reliability of such an attack and increases the chance
64318 + that such a read/write to another thread's stack instead lands in
64319 + an unmapped area, causing a crash and triggering grsecurity's
64320 + anti-bruteforcing logic.
64321 +
64322 +config GRKERNSEC_PROC_MEMMAP
64323 + bool "Harden ASLR against information leaks and entropy reduction"
64324 + default y if (GRKERNSEC_CONFIG_AUTO || PAX_NOEXEC || PAX_ASLR)
64325 + depends on PAX_NOEXEC || PAX_ASLR
64326 + help
64327 + If you say Y here, the /proc/<pid>/maps and /proc/<pid>/stat files will
64328 + give no information about the addresses of its mappings if
64329 + PaX features that rely on random addresses are enabled on the task.
64330 + In addition to sanitizing this information and disabling other
64331 + dangerous sources of information, this option causes reads of sensitive
64332 + /proc/<pid> entries where the file descriptor was opened in a different
64333 + task than the one performing the read. Such attempts are logged.
64334 + This option also limits argv/env strings for suid/sgid binaries
64335 + to 512KB to prevent a complete exhaustion of the stack entropy provided
64336 + by ASLR. Finally, it places an 8MB stack resource limit on suid/sgid
64337 + binaries to prevent alternative mmap layouts from being abused.
64338 +
64339 + If you use PaX it is essential that you say Y here as it closes up
64340 + several holes that make full ASLR useless locally.
64341 +
64342 +config GRKERNSEC_BRUTE
64343 + bool "Deter exploit bruteforcing"
64344 + default y if GRKERNSEC_CONFIG_AUTO
64345 + help
64346 + If you say Y here, attempts to bruteforce exploits against forking
64347 + daemons such as apache or sshd, as well as against suid/sgid binaries
64348 + will be deterred. When a child of a forking daemon is killed by PaX
64349 + or crashes due to an illegal instruction or other suspicious signal,
64350 + the parent process will be delayed 30 seconds upon every subsequent
64351 + fork until the administrator is able to assess the situation and
64352 + restart the daemon.
64353 + In the suid/sgid case, the attempt is logged, the user has all their
64354 + existing instances of the suid/sgid binary terminated and will
64355 + be unable to execute any suid/sgid binaries for 15 minutes.
64356 +
64357 + It is recommended that you also enable signal logging in the auditing
64358 + section so that logs are generated when a process triggers a suspicious
64359 + signal.
64360 + If the sysctl option is enabled, a sysctl option with name
64361 + "deter_bruteforce" is created.
64362 +
64363 +config GRKERNSEC_MODHARDEN
64364 + bool "Harden module auto-loading"
64365 + default y if GRKERNSEC_CONFIG_AUTO
64366 + depends on MODULES
64367 + help
64368 + If you say Y here, module auto-loading in response to use of some
64369 + feature implemented by an unloaded module will be restricted to
64370 + root users. Enabling this option helps defend against attacks
64371 + by unprivileged users who abuse the auto-loading behavior to
64372 + cause a vulnerable module to load that is then exploited.
64373 +
64374 + If this option prevents a legitimate use of auto-loading for a
64375 + non-root user, the administrator can execute modprobe manually
64376 + with the exact name of the module mentioned in the alert log.
64377 + Alternatively, the administrator can add the module to the list
64378 + of modules loaded at boot by modifying init scripts.
64379 +
64380 + Modification of init scripts will most likely be needed on
64381 + Ubuntu servers with encrypted home directory support enabled,
64382 + as the first non-root user logging in will cause the ecb(aes),
64383 + ecb(aes)-all, cbc(aes), and cbc(aes)-all modules to be loaded.
64384 +
64385 +config GRKERNSEC_HIDESYM
64386 + bool "Hide kernel symbols"
64387 + default y if GRKERNSEC_CONFIG_AUTO
64388 + select PAX_USERCOPY_SLABS
64389 + help
64390 + If you say Y here, getting information on loaded modules, and
64391 + displaying all kernel symbols through a syscall will be restricted
64392 + to users with CAP_SYS_MODULE. For software compatibility reasons,
64393 + /proc/kallsyms will be restricted to the root user. The RBAC
64394 + system can hide that entry even from root.
64395 +
64396 + This option also prevents leaking of kernel addresses through
64397 + several /proc entries.
64398 +
64399 + Note that this option is only effective provided the following
64400 + conditions are met:
64401 + 1) The kernel using grsecurity is not precompiled by some distribution
64402 + 2) You have also enabled GRKERNSEC_DMESG
64403 + 3) You are using the RBAC system and hiding other files such as your
64404 + kernel image and System.map. Alternatively, enabling this option
64405 + causes the permissions on /boot, /lib/modules, and the kernel
64406 + source directory to change at compile time to prevent
64407 + reading by non-root users.
64408 + If the above conditions are met, this option will aid in providing a
64409 + useful protection against local kernel exploitation of overflows
64410 + and arbitrary read/write vulnerabilities.
64411 +
64412 + It is highly recommended that you enable GRKERNSEC_PERF_HARDEN
64413 + in addition to this feature.
64414 +
64415 +config GRKERNSEC_RANDSTRUCT
64416 + bool "Randomize layout of sensitive kernel structures"
64417 + default y if GRKERNSEC_CONFIG_AUTO
64418 + select GRKERNSEC_HIDESYM
64419 + select MODVERSIONS if MODULES
64420 + help
64421 + If you say Y here, the layouts of a number of sensitive kernel
64422 + structures (task, fs, cred, etc) and all structures composed entirely
64423 + of function pointers (aka "ops" structs) will be randomized at compile-time.
64424 + This can introduce the requirement of an additional infoleak
64425 + vulnerability for exploits targeting these structure types.
64426 +
64427 + Enabling this feature will introduce some performance impact, slightly
64428 + increase memory usage, and prevent the use of forensic tools like
64429 + Volatility against the system (unless the kernel source tree isn't
64430 + cleaned after kernel installation).
64431 +
64432 + The seed used for compilation is located at tools/gcc/randomize_layout_seed.h.
64433 + It remains after a make clean to allow for external modules to be compiled
64434 + with the existing seed and will be removed by a make mrproper or
64435 + make distclean.
64436 +
64437 +config GRKERNSEC_RANDSTRUCT_PERFORMANCE
64438 + bool "Use cacheline-aware structure randomization"
64439 + depends on GRKERNSEC_RANDSTRUCT
64440 + default y if GRKERNSEC_CONFIG_PRIORITY_PERF
64441 + help
64442 + If you say Y here, the RANDSTRUCT randomization will make a best effort
64443 + at restricting randomization to cacheline-sized groups of elements. It
64444 + will further not randomize bitfields in structures. This reduces the
64445 + performance hit of RANDSTRUCT at the cost of weakened randomization.
64446 +
64447 +config GRKERNSEC_KERN_LOCKOUT
64448 + bool "Active kernel exploit response"
64449 + default y if GRKERNSEC_CONFIG_AUTO
64450 + depends on X86 || ARM || PPC || SPARC
64451 + help
64452 + If you say Y here, when a PaX alert is triggered due to suspicious
64453 + activity in the kernel (from KERNEXEC/UDEREF/USERCOPY)
64454 + or an OOPS occurs due to bad memory accesses, instead of just
64455 + terminating the offending process (and potentially allowing
64456 + a subsequent exploit from the same user), we will take one of two
64457 + actions:
64458 + If the user was root, we will panic the system
64459 + If the user was non-root, we will log the attempt, terminate
64460 + all processes owned by the user, then prevent them from creating
64461 + any new processes until the system is restarted
64462 + This deters repeated kernel exploitation/bruteforcing attempts
64463 + and is useful for later forensics.
64464 +
64465 +config GRKERNSEC_OLD_ARM_USERLAND
64466 + bool "Old ARM userland compatibility"
64467 + depends on ARM && (CPU_V6 || CPU_V6K || CPU_V7)
64468 + help
64469 + If you say Y here, stubs of executable code to perform such operations
64470 + as "compare-exchange" will be placed at fixed locations in the ARM vector
64471 + table. This is unfortunately needed for old ARM userland meant to run
64472 + across a wide range of processors. Without this option enabled,
64473 + the get_tls and data memory barrier stubs will be emulated by the kernel,
64474 + which is enough for Linaro userlands or other userlands designed for v6
64475 + and newer ARM CPUs. It's recommended that you try without this option enabled
64476 + first, and only enable it if your userland does not boot (it will likely fail
64477 + at init time).
64478 +
64479 +endmenu
64480 +menu "Role Based Access Control Options"
64481 +depends on GRKERNSEC
64482 +
64483 +config GRKERNSEC_RBAC_DEBUG
64484 + bool
64485 +
64486 +config GRKERNSEC_NO_RBAC
64487 + bool "Disable RBAC system"
64488 + help
64489 + If you say Y here, the /dev/grsec device will be removed from the kernel,
64490 + preventing the RBAC system from being enabled. You should only say Y
64491 + here if you have no intention of using the RBAC system, so as to prevent
64492 + an attacker with root access from misusing the RBAC system to hide files
64493 + and processes when loadable module support and /dev/[k]mem have been
64494 + locked down.
64495 +
64496 +config GRKERNSEC_ACL_HIDEKERN
64497 + bool "Hide kernel processes"
64498 + help
64499 + If you say Y here, all kernel threads will be hidden to all
64500 + processes but those whose subject has the "view hidden processes"
64501 + flag.
64502 +
64503 +config GRKERNSEC_ACL_MAXTRIES
64504 + int "Maximum tries before password lockout"
64505 + default 3
64506 + help
64507 + This option enforces the maximum number of times a user can attempt
64508 + to authorize themselves with the grsecurity RBAC system before being
64509 + denied the ability to attempt authorization again for a specified time.
64510 + The lower the number, the harder it will be to brute-force a password.
64511 +
64512 +config GRKERNSEC_ACL_TIMEOUT
64513 + int "Time to wait after max password tries, in seconds"
64514 + default 30
64515 + help
64516 + This option specifies the time the user must wait after attempting to
64517 + authorize to the RBAC system with the maximum number of invalid
64518 + passwords. The higher the number, the harder it will be to brute-force
64519 + a password.
64520 +
64521 +endmenu
64522 +menu "Filesystem Protections"
64523 +depends on GRKERNSEC
64524 +
64525 +config GRKERNSEC_PROC
64526 + bool "Proc restrictions"
64527 + default y if GRKERNSEC_CONFIG_AUTO
64528 + help
64529 + If you say Y here, the permissions of the /proc filesystem
64530 + will be altered to enhance system security and privacy. You MUST
64531 + choose either a user only restriction or a user and group restriction.
64532 + Depending upon the option you choose, you can either restrict users to
64533 + see only the processes they themselves run, or choose a group that can
64534 + view all processes and files normally restricted to root if you choose
64535 + the "restrict to user only" option. NOTE: If you're running identd or
64536 + ntpd as a non-root user, you will have to run it as the group you
64537 + specify here.
64538 +
64539 +config GRKERNSEC_PROC_USER
64540 + bool "Restrict /proc to user only"
64541 + depends on GRKERNSEC_PROC
64542 + help
64543 + If you say Y here, non-root users will only be able to view their own
64544 + processes, and restricts them from viewing network-related information,
64545 + and viewing kernel symbol and module information.
64546 +
64547 +config GRKERNSEC_PROC_USERGROUP
64548 + bool "Allow special group"
64549 + default y if GRKERNSEC_CONFIG_AUTO
64550 + depends on GRKERNSEC_PROC && !GRKERNSEC_PROC_USER
64551 + help
64552 + If you say Y here, you will be able to select a group that will be
64553 + able to view all processes and network-related information. If you've
64554 + enabled GRKERNSEC_HIDESYM, kernel and symbol information may still
64555 + remain hidden. This option is useful if you want to run identd as
64556 + a non-root user. The group you select may also be chosen at boot time
64557 + via "grsec_proc_gid=" on the kernel commandline.
64558 +
64559 +config GRKERNSEC_PROC_GID
64560 + int "GID for special group"
64561 + depends on GRKERNSEC_PROC_USERGROUP
64562 + default 1001
64563 +
64564 +config GRKERNSEC_PROC_ADD
64565 + bool "Additional restrictions"
64566 + default y if GRKERNSEC_CONFIG_AUTO
64567 + depends on GRKERNSEC_PROC_USER || GRKERNSEC_PROC_USERGROUP
64568 + help
64569 + If you say Y here, additional restrictions will be placed on
64570 + /proc that keep normal users from viewing device information and
64571 + slabinfo information that could be useful for exploits.
64572 +
64573 +config GRKERNSEC_LINK
64574 + bool "Linking restrictions"
64575 + default y if GRKERNSEC_CONFIG_AUTO
64576 + help
64577 + If you say Y here, /tmp race exploits will be prevented, since users
64578 + will no longer be able to follow symlinks owned by other users in
64579 + world-writable +t directories (e.g. /tmp), unless the owner of the
64580 + symlink is the owner of the directory. users will also not be
64581 + able to hardlink to files they do not own. If the sysctl option is
64582 + enabled, a sysctl option with name "linking_restrictions" is created.
64583 +
64584 +config GRKERNSEC_SYMLINKOWN
64585 + bool "Kernel-enforced SymlinksIfOwnerMatch"
64586 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
64587 + help
64588 + Apache's SymlinksIfOwnerMatch option has an inherent race condition
64589 + that prevents it from being used as a security feature. As Apache
64590 + verifies the symlink by performing a stat() against the target of
64591 + the symlink before it is followed, an attacker can setup a symlink
64592 + to point to a same-owned file, then replace the symlink with one
64593 + that targets another user's file just after Apache "validates" the
64594 + symlink -- a classic TOCTOU race. If you say Y here, a complete,
64595 + race-free replacement for Apache's "SymlinksIfOwnerMatch" option
64596 + will be in place for the group you specify. If the sysctl option
64597 + is enabled, a sysctl option with name "enforce_symlinksifowner" is
64598 + created.
64599 +
64600 +config GRKERNSEC_SYMLINKOWN_GID
64601 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
64602 + depends on GRKERNSEC_SYMLINKOWN
64603 + default 1006
64604 + help
64605 + Setting this GID determines what group kernel-enforced
64606 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
64607 + is enabled, a sysctl option with name "symlinkown_gid" is created.
64608 +
64609 +config GRKERNSEC_FIFO
64610 + bool "FIFO restrictions"
64611 + default y if GRKERNSEC_CONFIG_AUTO
64612 + help
64613 + If you say Y here, users will not be able to write to FIFOs they don't
64614 + own in world-writable +t directories (e.g. /tmp), unless the owner of
64615 + the FIFO is the same owner of the directory it's held in. If the sysctl
64616 + option is enabled, a sysctl option with name "fifo_restrictions" is
64617 + created.
64618 +
64619 +config GRKERNSEC_SYSFS_RESTRICT
64620 + bool "Sysfs/debugfs restriction"
64621 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER)
64622 + depends on SYSFS
64623 + help
64624 + If you say Y here, sysfs (the pseudo-filesystem mounted at /sys) and
64625 + any filesystem normally mounted under it (e.g. debugfs) will be
64626 + mostly accessible only by root. These filesystems generally provide access
64627 + to hardware and debug information that isn't appropriate for unprivileged
64628 + users of the system. Sysfs and debugfs have also become a large source
64629 + of new vulnerabilities, ranging from infoleaks to local compromise.
64630 + There has been very little oversight with an eye toward security involved
64631 + in adding new exporters of information to these filesystems, so their
64632 + use is discouraged.
64633 + For reasons of compatibility, a few directories have been whitelisted
64634 + for access by non-root users:
64635 + /sys/fs/selinux
64636 + /sys/fs/fuse
64637 + /sys/devices/system/cpu
64638 +
64639 +config GRKERNSEC_ROFS
64640 + bool "Runtime read-only mount protection"
64641 + depends on SYSCTL
64642 + help
64643 + If you say Y here, a sysctl option with name "romount_protect" will
64644 + be created. By setting this option to 1 at runtime, filesystems
64645 + will be protected in the following ways:
64646 + * No new writable mounts will be allowed
64647 + * Existing read-only mounts won't be able to be remounted read/write
64648 + * Write operations will be denied on all block devices
64649 + This option acts independently of grsec_lock: once it is set to 1,
64650 + it cannot be turned off. Therefore, please be mindful of the resulting
64651 + behavior if this option is enabled in an init script on a read-only
64652 + filesystem.
64653 + Also be aware that as with other root-focused features, GRKERNSEC_KMEM
64654 + and GRKERNSEC_IO should be enabled and module loading disabled via
64655 + config or at runtime.
64656 + This feature is mainly intended for secure embedded systems.
64657 +
64658 +
64659 +config GRKERNSEC_DEVICE_SIDECHANNEL
64660 + bool "Eliminate stat/notify-based device sidechannels"
64661 + default y if GRKERNSEC_CONFIG_AUTO
64662 + help
64663 + If you say Y here, timing analyses on block or character
64664 + devices like /dev/ptmx using stat or inotify/dnotify/fanotify
64665 + will be thwarted for unprivileged users. If a process without
64666 + CAP_MKNOD stats such a device, the last access and last modify times
64667 + will match the device's create time. No access or modify events
64668 + will be triggered through inotify/dnotify/fanotify for such devices.
64669 + This feature will prevent attacks that may at a minimum
64670 + allow an attacker to determine the administrator's password length.
64671 +
64672 +config GRKERNSEC_CHROOT
64673 + bool "Chroot jail restrictions"
64674 + default y if GRKERNSEC_CONFIG_AUTO
64675 + help
64676 + If you say Y here, you will be able to choose several options that will
64677 + make breaking out of a chrooted jail much more difficult. If you
64678 + encounter no software incompatibilities with the following options, it
64679 + is recommended that you enable each one.
64680 +
64681 +config GRKERNSEC_CHROOT_MOUNT
64682 + bool "Deny mounts"
64683 + default y if GRKERNSEC_CONFIG_AUTO
64684 + depends on GRKERNSEC_CHROOT
64685 + help
64686 + If you say Y here, processes inside a chroot will not be able to
64687 + mount or remount filesystems. If the sysctl option is enabled, a
64688 + sysctl option with name "chroot_deny_mount" is created.
64689 +
64690 +config GRKERNSEC_CHROOT_DOUBLE
64691 + bool "Deny double-chroots"
64692 + default y if GRKERNSEC_CONFIG_AUTO
64693 + depends on GRKERNSEC_CHROOT
64694 + help
64695 + If you say Y here, processes inside a chroot will not be able to chroot
64696 + again outside the chroot. This is a widely used method of breaking
64697 + out of a chroot jail and should not be allowed. If the sysctl
64698 + option is enabled, a sysctl option with name
64699 + "chroot_deny_chroot" is created.
64700 +
64701 +config GRKERNSEC_CHROOT_PIVOT
64702 + bool "Deny pivot_root in chroot"
64703 + default y if GRKERNSEC_CONFIG_AUTO
64704 + depends on GRKERNSEC_CHROOT
64705 + help
64706 + If you say Y here, processes inside a chroot will not be able to use
64707 + a function called pivot_root() that was introduced in Linux 2.3.41. It
64708 + works similar to chroot in that it changes the root filesystem. This
64709 + function could be misused in a chrooted process to attempt to break out
64710 + of the chroot, and therefore should not be allowed. If the sysctl
64711 + option is enabled, a sysctl option with name "chroot_deny_pivot" is
64712 + created.
64713 +
64714 +config GRKERNSEC_CHROOT_CHDIR
64715 + bool "Enforce chdir(\"/\") on all chroots"
64716 + default y if GRKERNSEC_CONFIG_AUTO
64717 + depends on GRKERNSEC_CHROOT
64718 + help
64719 + If you say Y here, the current working directory of all newly-chrooted
64720 + applications will be set to the the root directory of the chroot.
64721 + The man page on chroot(2) states:
64722 + Note that this call does not change the current working
64723 + directory, so that `.' can be outside the tree rooted at
64724 + `/'. In particular, the super-user can escape from a
64725 + `chroot jail' by doing `mkdir foo; chroot foo; cd ..'.
64726 +
64727 + It is recommended that you say Y here, since it's not known to break
64728 + any software. If the sysctl option is enabled, a sysctl option with
64729 + name "chroot_enforce_chdir" is created.
64730 +
64731 +config GRKERNSEC_CHROOT_CHMOD
64732 + bool "Deny (f)chmod +s"
64733 + default y if GRKERNSEC_CONFIG_AUTO
64734 + depends on GRKERNSEC_CHROOT
64735 + help
64736 + If you say Y here, processes inside a chroot will not be able to chmod
64737 + or fchmod files to make them have suid or sgid bits. This protects
64738 + against another published method of breaking a chroot. If the sysctl
64739 + option is enabled, a sysctl option with name "chroot_deny_chmod" is
64740 + created.
64741 +
64742 +config GRKERNSEC_CHROOT_FCHDIR
64743 + bool "Deny fchdir out of chroot"
64744 + default y if GRKERNSEC_CONFIG_AUTO
64745 + depends on GRKERNSEC_CHROOT
64746 + help
64747 + If you say Y here, a well-known method of breaking chroots by fchdir'ing
64748 + to a file descriptor of the chrooting process that points to a directory
64749 + outside the filesystem will be stopped. If the sysctl option
64750 + is enabled, a sysctl option with name "chroot_deny_fchdir" is created.
64751 +
64752 +config GRKERNSEC_CHROOT_MKNOD
64753 + bool "Deny mknod"
64754 + default y if GRKERNSEC_CONFIG_AUTO
64755 + depends on GRKERNSEC_CHROOT
64756 + help
64757 + If you say Y here, processes inside a chroot will not be allowed to
64758 + mknod. The problem with using mknod inside a chroot is that it
64759 + would allow an attacker to create a device entry that is the same
64760 + as one on the physical root of your system, which could range from
64761 + anything from the console device to a device for your harddrive (which
64762 + they could then use to wipe the drive or steal data). It is recommended
64763 + that you say Y here, unless you run into software incompatibilities.
64764 + If the sysctl option is enabled, a sysctl option with name
64765 + "chroot_deny_mknod" is created.
64766 +
64767 +config GRKERNSEC_CHROOT_SHMAT
64768 + bool "Deny shmat() out of chroot"
64769 + default y if GRKERNSEC_CONFIG_AUTO
64770 + depends on GRKERNSEC_CHROOT
64771 + help
64772 + If you say Y here, processes inside a chroot will not be able to attach
64773 + to shared memory segments that were created outside of the chroot jail.
64774 + It is recommended that you say Y here. If the sysctl option is enabled,
64775 + a sysctl option with name "chroot_deny_shmat" is created.
64776 +
64777 +config GRKERNSEC_CHROOT_UNIX
64778 + bool "Deny access to abstract AF_UNIX sockets out of chroot"
64779 + default y if GRKERNSEC_CONFIG_AUTO
64780 + depends on GRKERNSEC_CHROOT
64781 + help
64782 + If you say Y here, processes inside a chroot will not be able to
64783 + connect to abstract (meaning not belonging to a filesystem) Unix
64784 + domain sockets that were bound outside of a chroot. It is recommended
64785 + that you say Y here. If the sysctl option is enabled, a sysctl option
64786 + with name "chroot_deny_unix" is created.
64787 +
64788 +config GRKERNSEC_CHROOT_FINDTASK
64789 + bool "Protect outside processes"
64790 + default y if GRKERNSEC_CONFIG_AUTO
64791 + depends on GRKERNSEC_CHROOT
64792 + help
64793 + If you say Y here, processes inside a chroot will not be able to
64794 + kill, send signals with fcntl, ptrace, capget, getpgid, setpgid,
64795 + getsid, or view any process outside of the chroot. If the sysctl
64796 + option is enabled, a sysctl option with name "chroot_findtask" is
64797 + created.
64798 +
64799 +config GRKERNSEC_CHROOT_NICE
64800 + bool "Restrict priority changes"
64801 + default y if GRKERNSEC_CONFIG_AUTO
64802 + depends on GRKERNSEC_CHROOT
64803 + help
64804 + If you say Y here, processes inside a chroot will not be able to raise
64805 + the priority of processes in the chroot, or alter the priority of
64806 + processes outside the chroot. This provides more security than simply
64807 + removing CAP_SYS_NICE from the process' capability set. If the
64808 + sysctl option is enabled, a sysctl option with name "chroot_restrict_nice"
64809 + is created.
64810 +
64811 +config GRKERNSEC_CHROOT_SYSCTL
64812 + bool "Deny sysctl writes"
64813 + default y if GRKERNSEC_CONFIG_AUTO
64814 + depends on GRKERNSEC_CHROOT
64815 + help
64816 + If you say Y here, an attacker in a chroot will not be able to
64817 + write to sysctl entries, either by sysctl(2) or through a /proc
64818 + interface. It is strongly recommended that you say Y here. If the
64819 + sysctl option is enabled, a sysctl option with name
64820 + "chroot_deny_sysctl" is created.
64821 +
64822 +config GRKERNSEC_CHROOT_CAPS
64823 + bool "Capability restrictions"
64824 + default y if GRKERNSEC_CONFIG_AUTO
64825 + depends on GRKERNSEC_CHROOT
64826 + help
64827 + If you say Y here, the capabilities on all processes within a
64828 + chroot jail will be lowered to stop module insertion, raw i/o,
64829 + system and net admin tasks, rebooting the system, modifying immutable
64830 + files, modifying IPC owned by another, and changing the system time.
64831 + This is left an option because it can break some apps. Disable this
64832 + if your chrooted apps are having problems performing those kinds of
64833 + tasks. If the sysctl option is enabled, a sysctl option with
64834 + name "chroot_caps" is created.
64835 +
64836 +config GRKERNSEC_CHROOT_INITRD
64837 + bool "Exempt initrd tasks from restrictions"
64838 + default y if GRKERNSEC_CONFIG_AUTO
64839 + depends on GRKERNSEC_CHROOT && BLK_DEV_INITRD
64840 + help
64841 + If you say Y here, tasks started prior to init will be exempted from
64842 + grsecurity's chroot restrictions. This option is mainly meant to
64843 + resolve Plymouth's performing privileged operations unnecessarily
64844 + in a chroot.
64845 +
64846 +endmenu
64847 +menu "Kernel Auditing"
64848 +depends on GRKERNSEC
64849 +
64850 +config GRKERNSEC_AUDIT_GROUP
64851 + bool "Single group for auditing"
64852 + help
64853 + If you say Y here, the exec and chdir logging features will only operate
64854 + on a group you specify. This option is recommended if you only want to
64855 + watch certain users instead of having a large amount of logs from the
64856 + entire system. If the sysctl option is enabled, a sysctl option with
64857 + name "audit_group" is created.
64858 +
64859 +config GRKERNSEC_AUDIT_GID
64860 + int "GID for auditing"
64861 + depends on GRKERNSEC_AUDIT_GROUP
64862 + default 1007
64863 +
64864 +config GRKERNSEC_EXECLOG
64865 + bool "Exec logging"
64866 + help
64867 + If you say Y here, all execve() calls will be logged (since the
64868 + other exec*() calls are frontends to execve(), all execution
64869 + will be logged). Useful for shell-servers that like to keep track
64870 + of their users. If the sysctl option is enabled, a sysctl option with
64871 + name "exec_logging" is created.
64872 + WARNING: This option when enabled will produce a LOT of logs, especially
64873 + on an active system.
64874 +
64875 +config GRKERNSEC_RESLOG
64876 + bool "Resource logging"
64877 + default y if GRKERNSEC_CONFIG_AUTO
64878 + help
64879 + If you say Y here, all attempts to overstep resource limits will
64880 + be logged with the resource name, the requested size, and the current
64881 + limit. It is highly recommended that you say Y here. If the sysctl
64882 + option is enabled, a sysctl option with name "resource_logging" is
64883 + created. If the RBAC system is enabled, the sysctl value is ignored.
64884 +
64885 +config GRKERNSEC_CHROOT_EXECLOG
64886 + bool "Log execs within chroot"
64887 + help
64888 + If you say Y here, all executions inside a chroot jail will be logged
64889 + to syslog. This can cause a large amount of logs if certain
64890 + applications (eg. djb's daemontools) are installed on the system, and
64891 + is therefore left as an option. If the sysctl option is enabled, a
64892 + sysctl option with name "chroot_execlog" is created.
64893 +
64894 +config GRKERNSEC_AUDIT_PTRACE
64895 + bool "Ptrace logging"
64896 + help
64897 + If you say Y here, all attempts to attach to a process via ptrace
64898 + will be logged. If the sysctl option is enabled, a sysctl option
64899 + with name "audit_ptrace" is created.
64900 +
64901 +config GRKERNSEC_AUDIT_CHDIR
64902 + bool "Chdir logging"
64903 + help
64904 + If you say Y here, all chdir() calls will be logged. If the sysctl
64905 + option is enabled, a sysctl option with name "audit_chdir" is created.
64906 +
64907 +config GRKERNSEC_AUDIT_MOUNT
64908 + bool "(Un)Mount logging"
64909 + help
64910 + If you say Y here, all mounts and unmounts will be logged. If the
64911 + sysctl option is enabled, a sysctl option with name "audit_mount" is
64912 + created.
64913 +
64914 +config GRKERNSEC_SIGNAL
64915 + bool "Signal logging"
64916 + default y if GRKERNSEC_CONFIG_AUTO
64917 + help
64918 + If you say Y here, certain important signals will be logged, such as
64919 + SIGSEGV, which will as a result inform you of when a error in a program
64920 + occurred, which in some cases could mean a possible exploit attempt.
64921 + If the sysctl option is enabled, a sysctl option with name
64922 + "signal_logging" is created.
64923 +
64924 +config GRKERNSEC_FORKFAIL
64925 + bool "Fork failure logging"
64926 + help
64927 + If you say Y here, all failed fork() attempts will be logged.
64928 + This could suggest a fork bomb, or someone attempting to overstep
64929 + their process limit. If the sysctl option is enabled, a sysctl option
64930 + with name "forkfail_logging" is created.
64931 +
64932 +config GRKERNSEC_TIME
64933 + bool "Time change logging"
64934 + default y if GRKERNSEC_CONFIG_AUTO
64935 + help
64936 + If you say Y here, any changes of the system clock will be logged.
64937 + If the sysctl option is enabled, a sysctl option with name
64938 + "timechange_logging" is created.
64939 +
64940 +config GRKERNSEC_PROC_IPADDR
64941 + bool "/proc/<pid>/ipaddr support"
64942 + default y if GRKERNSEC_CONFIG_AUTO
64943 + help
64944 + If you say Y here, a new entry will be added to each /proc/<pid>
64945 + directory that contains the IP address of the person using the task.
64946 + The IP is carried across local TCP and AF_UNIX stream sockets.
64947 + This information can be useful for IDS/IPSes to perform remote response
64948 + to a local attack. The entry is readable by only the owner of the
64949 + process (and root if he has CAP_DAC_OVERRIDE, which can be removed via
64950 + the RBAC system), and thus does not create privacy concerns.
64951 +
64952 +config GRKERNSEC_RWXMAP_LOG
64953 + bool 'Denied RWX mmap/mprotect logging'
64954 + default y if GRKERNSEC_CONFIG_AUTO
64955 + depends on PAX_MPROTECT && !PAX_EMUPLT && !PAX_EMUSIGRT
64956 + help
64957 + If you say Y here, calls to mmap() and mprotect() with explicit
64958 + usage of PROT_WRITE and PROT_EXEC together will be logged when
64959 + denied by the PAX_MPROTECT feature. This feature will also
64960 + log other problematic scenarios that can occur when PAX_MPROTECT
64961 + is enabled on a binary, like textrels and PT_GNU_STACK. If the
64962 + sysctl option is enabled, a sysctl option with name "rwxmap_logging"
64963 + is created.
64964 +
64965 +endmenu
64966 +
64967 +menu "Executable Protections"
64968 +depends on GRKERNSEC
64969 +
64970 +config GRKERNSEC_DMESG
64971 + bool "Dmesg(8) restriction"
64972 + default y if GRKERNSEC_CONFIG_AUTO
64973 + help
64974 + If you say Y here, non-root users will not be able to use dmesg(8)
64975 + to view the contents of the kernel's circular log buffer.
64976 + The kernel's log buffer often contains kernel addresses and other
64977 + identifying information useful to an attacker in fingerprinting a
64978 + system for a targeted exploit.
64979 + If the sysctl option is enabled, a sysctl option with name "dmesg" is
64980 + created.
64981 +
64982 +config GRKERNSEC_HARDEN_PTRACE
64983 + bool "Deter ptrace-based process snooping"
64984 + default y if GRKERNSEC_CONFIG_AUTO
64985 + help
64986 + If you say Y here, TTY sniffers and other malicious monitoring
64987 + programs implemented through ptrace will be defeated. If you
64988 + have been using the RBAC system, this option has already been
64989 + enabled for several years for all users, with the ability to make
64990 + fine-grained exceptions.
64991 +
64992 + This option only affects the ability of non-root users to ptrace
64993 + processes that are not a descendent of the ptracing process.
64994 + This means that strace ./binary and gdb ./binary will still work,
64995 + but attaching to arbitrary processes will not. If the sysctl
64996 + option is enabled, a sysctl option with name "harden_ptrace" is
64997 + created.
64998 +
64999 +config GRKERNSEC_PTRACE_READEXEC
65000 + bool "Require read access to ptrace sensitive binaries"
65001 + default y if GRKERNSEC_CONFIG_AUTO
65002 + help
65003 + If you say Y here, unprivileged users will not be able to ptrace unreadable
65004 + binaries. This option is useful in environments that
65005 + remove the read bits (e.g. file mode 4711) from suid binaries to
65006 + prevent infoleaking of their contents. This option adds
65007 + consistency to the use of that file mode, as the binary could normally
65008 + be read out when run without privileges while ptracing.
65009 +
65010 + If the sysctl option is enabled, a sysctl option with name "ptrace_readexec"
65011 + is created.
65012 +
65013 +config GRKERNSEC_SETXID
65014 + bool "Enforce consistent multithreaded privileges"
65015 + default y if GRKERNSEC_CONFIG_AUTO
65016 + depends on (X86 || SPARC64 || PPC || ARM || MIPS)
65017 + help
65018 + If you say Y here, a change from a root uid to a non-root uid
65019 + in a multithreaded application will cause the resulting uids,
65020 + gids, supplementary groups, and capabilities in that thread
65021 + to be propagated to the other threads of the process. In most
65022 + cases this is unnecessary, as glibc will emulate this behavior
65023 + on behalf of the application. Other libcs do not act in the
65024 + same way, allowing the other threads of the process to continue
65025 + running with root privileges. If the sysctl option is enabled,
65026 + a sysctl option with name "consistent_setxid" is created.
65027 +
65028 +config GRKERNSEC_HARDEN_IPC
65029 + bool "Disallow access to overly-permissive IPC objects"
65030 + default y if GRKERNSEC_CONFIG_AUTO
65031 + depends on SYSVIPC
65032 + help
65033 + If you say Y here, access to overly-permissive IPC objects (shared
65034 + memory, message queues, and semaphores) will be denied for processes
65035 + given the following criteria beyond normal permission checks:
65036 + 1) If the IPC object is world-accessible and the euid doesn't match
65037 + that of the creator or current uid for the IPC object
65038 + 2) If the IPC object is group-accessible and the egid doesn't
65039 + match that of the creator or current gid for the IPC object
65040 + It's a common error to grant too much permission to these objects,
65041 + with impact ranging from denial of service and information leaking to
65042 + privilege escalation. This feature was developed in response to
65043 + research by Tim Brown:
65044 + http://labs.portcullis.co.uk/whitepapers/memory-squatting-attacks-on-system-v-shared-memory/
65045 + who found hundreds of such insecure usages. Processes with
65046 + CAP_IPC_OWNER are still permitted to access these IPC objects.
65047 + If the sysctl option is enabled, a sysctl option with name
65048 + "harden_ipc" is created.
65049 +
65050 +config GRKERNSEC_TPE
65051 + bool "Trusted Path Execution (TPE)"
65052 + default y if GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_SERVER
65053 + help
65054 + If you say Y here, you will be able to choose a gid to add to the
65055 + supplementary groups of users you want to mark as "untrusted."
65056 + These users will not be able to execute any files that are not in
65057 + root-owned directories writable only by root. If the sysctl option
65058 + is enabled, a sysctl option with name "tpe" is created.
65059 +
65060 +config GRKERNSEC_TPE_ALL
65061 + bool "Partially restrict all non-root users"
65062 + depends on GRKERNSEC_TPE
65063 + help
65064 + If you say Y here, all non-root users will be covered under
65065 + a weaker TPE restriction. This is separate from, and in addition to,
65066 + the main TPE options that you have selected elsewhere. Thus, if a
65067 + "trusted" GID is chosen, this restriction applies to even that GID.
65068 + Under this restriction, all non-root users will only be allowed to
65069 + execute files in directories they own that are not group or
65070 + world-writable, or in directories owned by root and writable only by
65071 + root. If the sysctl option is enabled, a sysctl option with name
65072 + "tpe_restrict_all" is created.
65073 +
65074 +config GRKERNSEC_TPE_INVERT
65075 + bool "Invert GID option"
65076 + depends on GRKERNSEC_TPE
65077 + help
65078 + If you say Y here, the group you specify in the TPE configuration will
65079 + decide what group TPE restrictions will be *disabled* for. This
65080 + option is useful if you want TPE restrictions to be applied to most
65081 + users on the system. If the sysctl option is enabled, a sysctl option
65082 + with name "tpe_invert" is created. Unlike other sysctl options, this
65083 + entry will default to on for backward-compatibility.
65084 +
65085 +config GRKERNSEC_TPE_GID
65086 + int
65087 + default GRKERNSEC_TPE_UNTRUSTED_GID if (GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT)
65088 + default GRKERNSEC_TPE_TRUSTED_GID if (GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT)
65089 +
65090 +config GRKERNSEC_TPE_UNTRUSTED_GID
65091 + int "GID for TPE-untrusted users"
65092 + depends on GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
65093 + default 1005
65094 + help
65095 + Setting this GID determines what group TPE restrictions will be
65096 + *enabled* for. If the sysctl option is enabled, a sysctl option
65097 + with name "tpe_gid" is created.
65098 +
65099 +config GRKERNSEC_TPE_TRUSTED_GID
65100 + int "GID for TPE-trusted users"
65101 + depends on GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
65102 + default 1005
65103 + help
65104 + Setting this GID determines what group TPE restrictions will be
65105 + *disabled* for. If the sysctl option is enabled, a sysctl option
65106 + with name "tpe_gid" is created.
65107 +
65108 +endmenu
65109 +menu "Network Protections"
65110 +depends on GRKERNSEC
65111 +
65112 +config GRKERNSEC_RANDNET
65113 + bool "Larger entropy pools"
65114 + default y if GRKERNSEC_CONFIG_AUTO
65115 + help
65116 + If you say Y here, the entropy pools used for many features of Linux
65117 + and grsecurity will be doubled in size. Since several grsecurity
65118 + features use additional randomness, it is recommended that you say Y
65119 + here. Saying Y here has a similar effect as modifying
65120 + /proc/sys/kernel/random/poolsize.
65121 +
65122 +config GRKERNSEC_BLACKHOLE
65123 + bool "TCP/UDP blackhole and LAST_ACK DoS prevention"
65124 + default y if GRKERNSEC_CONFIG_AUTO
65125 + depends on NET
65126 + help
65127 + If you say Y here, neither TCP resets nor ICMP
65128 + destination-unreachable packets will be sent in response to packets
65129 + sent to ports for which no associated listening process exists.
65130 + This feature supports both IPV4 and IPV6 and exempts the
65131 + loopback interface from blackholing. Enabling this feature
65132 + makes a host more resilient to DoS attacks and reduces network
65133 + visibility against scanners.
65134 +
65135 + The blackhole feature as-implemented is equivalent to the FreeBSD
65136 + blackhole feature, as it prevents RST responses to all packets, not
65137 + just SYNs. Under most application behavior this causes no
65138 + problems, but applications (like haproxy) may not close certain
65139 + connections in a way that cleanly terminates them on the remote
65140 + end, leaving the remote host in LAST_ACK state. Because of this
65141 + side-effect and to prevent intentional LAST_ACK DoSes, this
65142 + feature also adds automatic mitigation against such attacks.
65143 + The mitigation drastically reduces the amount of time a socket
65144 + can spend in LAST_ACK state. If you're using haproxy and not
65145 + all servers it connects to have this option enabled, consider
65146 + disabling this feature on the haproxy host.
65147 +
65148 + If the sysctl option is enabled, two sysctl options with names
65149 + "ip_blackhole" and "lastack_retries" will be created.
65150 + While "ip_blackhole" takes the standard zero/non-zero on/off
65151 + toggle, "lastack_retries" uses the same kinds of values as
65152 + "tcp_retries1" and "tcp_retries2". The default value of 4
65153 + prevents a socket from lasting more than 45 seconds in LAST_ACK
65154 + state.
65155 +
65156 +config GRKERNSEC_NO_SIMULT_CONNECT
65157 + bool "Disable TCP Simultaneous Connect"
65158 + default y if GRKERNSEC_CONFIG_AUTO
65159 + depends on NET
65160 + help
65161 + If you say Y here, a feature by Willy Tarreau will be enabled that
65162 + removes a weakness in Linux's strict implementation of TCP that
65163 + allows two clients to connect to each other without either entering
65164 + a listening state. The weakness allows an attacker to easily prevent
65165 + a client from connecting to a known server provided the source port
65166 + for the connection is guessed correctly.
65167 +
65168 + As the weakness could be used to prevent an antivirus or IPS from
65169 + fetching updates, or prevent an SSL gateway from fetching a CRL,
65170 + it should be eliminated by enabling this option. Though Linux is
65171 + one of few operating systems supporting simultaneous connect, it
65172 + has no legitimate use in practice and is rarely supported by firewalls.
65173 +
65174 +config GRKERNSEC_SOCKET
65175 + bool "Socket restrictions"
65176 + depends on NET
65177 + help
65178 + If you say Y here, you will be able to choose from several options.
65179 + If you assign a GID on your system and add it to the supplementary
65180 + groups of users you want to restrict socket access to, this patch
65181 + will perform up to three things, based on the option(s) you choose.
65182 +
65183 +config GRKERNSEC_SOCKET_ALL
65184 + bool "Deny any sockets to group"
65185 + depends on GRKERNSEC_SOCKET
65186 + help
65187 + If you say Y here, you will be able to choose a GID of whose users will
65188 + be unable to connect to other hosts from your machine or run server
65189 + applications from your machine. If the sysctl option is enabled, a
65190 + sysctl option with name "socket_all" is created.
65191 +
65192 +config GRKERNSEC_SOCKET_ALL_GID
65193 + int "GID to deny all sockets for"
65194 + depends on GRKERNSEC_SOCKET_ALL
65195 + default 1004
65196 + help
65197 + Here you can choose the GID to disable socket access for. Remember to
65198 + add the users you want socket access disabled for to the GID
65199 + specified here. If the sysctl option is enabled, a sysctl option
65200 + with name "socket_all_gid" is created.
65201 +
65202 +config GRKERNSEC_SOCKET_CLIENT
65203 + bool "Deny client sockets to group"
65204 + depends on GRKERNSEC_SOCKET
65205 + help
65206 + If you say Y here, you will be able to choose a GID of whose users will
65207 + be unable to connect to other hosts from your machine, but will be
65208 + able to run servers. If this option is enabled, all users in the group
65209 + you specify will have to use passive mode when initiating ftp transfers
65210 + from the shell on your machine. If the sysctl option is enabled, a
65211 + sysctl option with name "socket_client" is created.
65212 +
65213 +config GRKERNSEC_SOCKET_CLIENT_GID
65214 + int "GID to deny client sockets for"
65215 + depends on GRKERNSEC_SOCKET_CLIENT
65216 + default 1003
65217 + help
65218 + Here you can choose the GID to disable client socket access for.
65219 + Remember to add the users you want client socket access disabled for to
65220 + the GID specified here. If the sysctl option is enabled, a sysctl
65221 + option with name "socket_client_gid" is created.
65222 +
65223 +config GRKERNSEC_SOCKET_SERVER
65224 + bool "Deny server sockets to group"
65225 + depends on GRKERNSEC_SOCKET
65226 + help
65227 + If you say Y here, you will be able to choose a GID of whose users will
65228 + be unable to run server applications from your machine. If the sysctl
65229 + option is enabled, a sysctl option with name "socket_server" is created.
65230 +
65231 +config GRKERNSEC_SOCKET_SERVER_GID
65232 + int "GID to deny server sockets for"
65233 + depends on GRKERNSEC_SOCKET_SERVER
65234 + default 1002
65235 + help
65236 + Here you can choose the GID to disable server socket access for.
65237 + Remember to add the users you want server socket access disabled for to
65238 + the GID specified here. If the sysctl option is enabled, a sysctl
65239 + option with name "socket_server_gid" is created.
65240 +
65241 +endmenu
65242 +
65243 +menu "Physical Protections"
65244 +depends on GRKERNSEC
65245 +
65246 +config GRKERNSEC_DENYUSB
65247 + bool "Deny new USB connections after toggle"
65248 + default y if GRKERNSEC_CONFIG_AUTO
65249 + depends on SYSCTL && USB_SUPPORT
65250 + help
65251 + If you say Y here, a new sysctl option with name "deny_new_usb"
65252 + will be created. Setting its value to 1 will prevent any new
65253 + USB devices from being recognized by the OS. Any attempted USB
65254 + device insertion will be logged. This option is intended to be
65255 + used against custom USB devices designed to exploit vulnerabilities
65256 + in various USB device drivers.
65257 +
65258 + For greatest effectiveness, this sysctl should be set after any
65259 + relevant init scripts. This option is safe to enable in distros
65260 + as each user can choose whether or not to toggle the sysctl.
65261 +
65262 +config GRKERNSEC_DENYUSB_FORCE
65263 + bool "Reject all USB devices not connected at boot"
65264 + select USB
65265 + depends on GRKERNSEC_DENYUSB
65266 + help
65267 + If you say Y here, a variant of GRKERNSEC_DENYUSB will be enabled
65268 + that doesn't involve a sysctl entry. This option should only be
65269 + enabled if you're sure you want to deny all new USB connections
65270 + at runtime and don't want to modify init scripts. This should not
65271 + be enabled by distros. It forces the core USB code to be built
65272 + into the kernel image so that all devices connected at boot time
65273 + can be recognized and new USB device connections can be prevented
65274 + prior to init running.
65275 +
65276 +endmenu
65277 +
65278 +menu "Sysctl Support"
65279 +depends on GRKERNSEC && SYSCTL
65280 +
65281 +config GRKERNSEC_SYSCTL
65282 + bool "Sysctl support"
65283 + default y if GRKERNSEC_CONFIG_AUTO
65284 + help
65285 + If you say Y here, you will be able to change the options that
65286 + grsecurity runs with at bootup, without having to recompile your
65287 + kernel. You can echo values to files in /proc/sys/kernel/grsecurity
65288 + to enable (1) or disable (0) various features. All the sysctl entries
65289 + are mutable until the "grsec_lock" entry is set to a non-zero value.
65290 + All features enabled in the kernel configuration are disabled at boot
65291 + if you do not say Y to the "Turn on features by default" option.
65292 + All options should be set at startup, and the grsec_lock entry should
65293 + be set to a non-zero value after all the options are set.
65294 + *THIS IS EXTREMELY IMPORTANT*
65295 +
65296 +config GRKERNSEC_SYSCTL_DISTRO
65297 + bool "Extra sysctl support for distro makers (READ HELP)"
65298 + depends on GRKERNSEC_SYSCTL && GRKERNSEC_IO
65299 + help
65300 + If you say Y here, additional sysctl options will be created
65301 + for features that affect processes running as root. Therefore,
65302 + it is critical when using this option that the grsec_lock entry be
65303 + enabled after boot. Only distros with prebuilt kernel packages
65304 + with this option enabled that can ensure grsec_lock is enabled
65305 + after boot should use this option.
65306 + *Failure to set grsec_lock after boot makes all grsec features
65307 + this option covers useless*
65308 +
65309 + Currently this option creates the following sysctl entries:
65310 + "Disable Privileged I/O": "disable_priv_io"
65311 +
65312 +config GRKERNSEC_SYSCTL_ON
65313 + bool "Turn on features by default"
65314 + default y if GRKERNSEC_CONFIG_AUTO
65315 + depends on GRKERNSEC_SYSCTL
65316 + help
65317 + If you say Y here, instead of having all features enabled in the
65318 + kernel configuration disabled at boot time, the features will be
65319 + enabled at boot time. It is recommended you say Y here unless
65320 + there is some reason you would want all sysctl-tunable features to
65321 + be disabled by default. As mentioned elsewhere, it is important
65322 + to enable the grsec_lock entry once you have finished modifying
65323 + the sysctl entries.
65324 +
65325 +endmenu
65326 +menu "Logging Options"
65327 +depends on GRKERNSEC
65328 +
65329 +config GRKERNSEC_FLOODTIME
65330 + int "Seconds in between log messages (minimum)"
65331 + default 10
65332 + help
65333 + This option allows you to enforce the number of seconds between
65334 + grsecurity log messages. The default should be suitable for most
65335 + people, however, if you choose to change it, choose a value small enough
65336 + to allow informative logs to be produced, but large enough to
65337 + prevent flooding.
65338 +
65339 +config GRKERNSEC_FLOODBURST
65340 + int "Number of messages in a burst (maximum)"
65341 + default 6
65342 + help
65343 + This option allows you to choose the maximum number of messages allowed
65344 + within the flood time interval you chose in a separate option. The
65345 + default should be suitable for most people, however if you find that
65346 + many of your logs are being interpreted as flooding, you may want to
65347 + raise this value.
65348 +
65349 +endmenu
65350 diff --git a/grsecurity/Makefile b/grsecurity/Makefile
65351 new file mode 100644
65352 index 0000000..5307c8a
65353 --- /dev/null
65354 +++ b/grsecurity/Makefile
65355 @@ -0,0 +1,54 @@
65356 +# grsecurity – access control and security hardening for Linux
65357 +# All code in this directory and various hooks located throughout the Linux kernel are
65358 +# Copyright (C) 2001-2014 Bradley Spengler, Open Source Security, Inc.
65359 +# http://www.grsecurity.net spender@grsecurity.net
65360 +#
65361 +# This program is free software; you can redistribute it and/or
65362 +# modify it under the terms of the GNU General Public License version 2
65363 +# as published by the Free Software Foundation.
65364 +#
65365 +# This program is distributed in the hope that it will be useful,
65366 +# but WITHOUT ANY WARRANTY; without even the implied warranty of
65367 +# MERCHANTABILITY or FITNESS FOR A PARTICULAR PURPOSE. See the
65368 +# GNU General Public License for more details.
65369 +#
65370 +# You should have received a copy of the GNU General Public License
65371 +# along with this program; if not, write to the Free Software
65372 +# Foundation, Inc., 51 Franklin Street, Fifth Floor, Boston, MA 02110-1301, USA.
65373 +
65374 +KBUILD_CFLAGS += -Werror
65375 +
65376 +obj-y = grsec_chdir.o grsec_chroot.o grsec_exec.o grsec_fifo.o grsec_fork.o \
65377 + grsec_mount.o grsec_sig.o grsec_sysctl.o \
65378 + grsec_time.o grsec_tpe.o grsec_link.o grsec_pax.o grsec_ptrace.o \
65379 + grsec_usb.o grsec_ipc.o
65380 +
65381 +obj-$(CONFIG_GRKERNSEC) += grsec_init.o grsum.o gracl.o gracl_segv.o \
65382 + gracl_cap.o gracl_alloc.o gracl_shm.o grsec_mem.o gracl_fs.o \
65383 + gracl_learn.o grsec_log.o gracl_policy.o
65384 +ifdef CONFIG_COMPAT
65385 +obj-$(CONFIG_GRKERNSEC) += gracl_compat.o
65386 +endif
65387 +
65388 +obj-$(CONFIG_GRKERNSEC_RESLOG) += gracl_res.o
65389 +
65390 +ifdef CONFIG_NET
65391 +obj-y += grsec_sock.o
65392 +obj-$(CONFIG_GRKERNSEC) += gracl_ip.o
65393 +endif
65394 +
65395 +ifndef CONFIG_GRKERNSEC
65396 +obj-y += grsec_disabled.o
65397 +endif
65398 +
65399 +ifdef CONFIG_GRKERNSEC_HIDESYM
65400 +extra-y := grsec_hidesym.o
65401 +$(obj)/grsec_hidesym.o:
65402 + @-chmod -f 500 /boot
65403 + @-chmod -f 500 /lib/modules
65404 + @-chmod -f 500 /lib64/modules
65405 + @-chmod -f 500 /lib32/modules
65406 + @-chmod -f 700 .
65407 + @-chmod -f 700 $(objtree)
65408 + @echo ' grsec: protected kernel image paths'
65409 +endif
65410 diff --git a/grsecurity/gracl.c b/grsecurity/gracl.c
65411 new file mode 100644
65412 index 0000000..364a9d7
65413 --- /dev/null
65414 +++ b/grsecurity/gracl.c
65415 @@ -0,0 +1,2678 @@
65416 +#include <linux/kernel.h>
65417 +#include <linux/module.h>
65418 +#include <linux/sched.h>
65419 +#include <linux/mm.h>
65420 +#include <linux/file.h>
65421 +#include <linux/fs.h>
65422 +#include <linux/namei.h>
65423 +#include <linux/mount.h>
65424 +#include <linux/tty.h>
65425 +#include <linux/proc_fs.h>
65426 +#include <linux/lglock.h>
65427 +#include <linux/slab.h>
65428 +#include <linux/vmalloc.h>
65429 +#include <linux/types.h>
65430 +#include <linux/sysctl.h>
65431 +#include <linux/netdevice.h>
65432 +#include <linux/ptrace.h>
65433 +#include <linux/gracl.h>
65434 +#include <linux/gralloc.h>
65435 +#include <linux/security.h>
65436 +#include <linux/grinternal.h>
65437 +#include <linux/pid_namespace.h>
65438 +#include <linux/stop_machine.h>
65439 +#include <linux/fdtable.h>
65440 +#include <linux/percpu.h>
65441 +#include <linux/lglock.h>
65442 +#include <linux/hugetlb.h>
65443 +#include <linux/posix-timers.h>
65444 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
65445 +#include <linux/magic.h>
65446 +#include <linux/pagemap.h>
65447 +#include "../fs/btrfs/async-thread.h"
65448 +#include "../fs/btrfs/ctree.h"
65449 +#include "../fs/btrfs/btrfs_inode.h"
65450 +#endif
65451 +#include "../fs/mount.h"
65452 +
65453 +#include <asm/uaccess.h>
65454 +#include <asm/errno.h>
65455 +#include <asm/mman.h>
65456 +
65457 +#define FOR_EACH_ROLE_START(role) \
65458 + role = running_polstate.role_list; \
65459 + while (role) {
65460 +
65461 +#define FOR_EACH_ROLE_END(role) \
65462 + role = role->prev; \
65463 + }
65464 +
65465 +extern struct path gr_real_root;
65466 +
65467 +static struct gr_policy_state running_polstate;
65468 +struct gr_policy_state *polstate = &running_polstate;
65469 +extern struct gr_alloc_state *current_alloc_state;
65470 +
65471 +extern char *gr_shared_page[4];
65472 +DEFINE_RWLOCK(gr_inode_lock);
65473 +
65474 +static unsigned int gr_status __read_only = GR_STATUS_INIT;
65475 +
65476 +#ifdef CONFIG_NET
65477 +extern struct vfsmount *sock_mnt;
65478 +#endif
65479 +
65480 +extern struct vfsmount *pipe_mnt;
65481 +extern struct vfsmount *shm_mnt;
65482 +
65483 +#ifdef CONFIG_HUGETLBFS
65484 +extern struct vfsmount *hugetlbfs_vfsmount[HUGE_MAX_HSTATE];
65485 +#endif
65486 +
65487 +extern u16 acl_sp_role_value;
65488 +extern struct acl_object_label *fakefs_obj_rw;
65489 +extern struct acl_object_label *fakefs_obj_rwx;
65490 +
65491 +int gr_acl_is_enabled(void)
65492 +{
65493 + return (gr_status & GR_READY);
65494 +}
65495 +
65496 +void gr_enable_rbac_system(void)
65497 +{
65498 + pax_open_kernel();
65499 + gr_status |= GR_READY;
65500 + pax_close_kernel();
65501 +}
65502 +
65503 +int gr_rbac_disable(void *unused)
65504 +{
65505 + pax_open_kernel();
65506 + gr_status &= ~GR_READY;
65507 + pax_close_kernel();
65508 +
65509 + return 0;
65510 +}
65511 +
65512 +static inline dev_t __get_dev(const struct dentry *dentry)
65513 +{
65514 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
65515 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
65516 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
65517 + else
65518 +#endif
65519 + return dentry->d_sb->s_dev;
65520 +}
65521 +
65522 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
65523 +{
65524 + return __get_dev(dentry);
65525 +}
65526 +
65527 +static char gr_task_roletype_to_char(struct task_struct *task)
65528 +{
65529 + switch (task->role->roletype &
65530 + (GR_ROLE_DEFAULT | GR_ROLE_USER | GR_ROLE_GROUP |
65531 + GR_ROLE_SPECIAL)) {
65532 + case GR_ROLE_DEFAULT:
65533 + return 'D';
65534 + case GR_ROLE_USER:
65535 + return 'U';
65536 + case GR_ROLE_GROUP:
65537 + return 'G';
65538 + case GR_ROLE_SPECIAL:
65539 + return 'S';
65540 + }
65541 +
65542 + return 'X';
65543 +}
65544 +
65545 +char gr_roletype_to_char(void)
65546 +{
65547 + return gr_task_roletype_to_char(current);
65548 +}
65549 +
65550 +__inline__ int
65551 +gr_acl_tpe_check(void)
65552 +{
65553 + if (unlikely(!(gr_status & GR_READY)))
65554 + return 0;
65555 + if (current->role->roletype & GR_ROLE_TPE)
65556 + return 1;
65557 + else
65558 + return 0;
65559 +}
65560 +
65561 +int
65562 +gr_handle_rawio(const struct inode *inode)
65563 +{
65564 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
65565 + if (inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR)) &&
65566 + grsec_enable_chroot_caps && proc_is_chrooted(current) &&
65567 + !capable(CAP_SYS_RAWIO))
65568 + return 1;
65569 +#endif
65570 + return 0;
65571 +}
65572 +
65573 +int
65574 +gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb)
65575 +{
65576 + if (likely(lena != lenb))
65577 + return 0;
65578 +
65579 + return !memcmp(a, b, lena);
65580 +}
65581 +
65582 +static int prepend(char **buffer, int *buflen, const char *str, int namelen)
65583 +{
65584 + *buflen -= namelen;
65585 + if (*buflen < 0)
65586 + return -ENAMETOOLONG;
65587 + *buffer -= namelen;
65588 + memcpy(*buffer, str, namelen);
65589 + return 0;
65590 +}
65591 +
65592 +static int prepend_name(char **buffer, int *buflen, struct qstr *name)
65593 +{
65594 + return prepend(buffer, buflen, name->name, name->len);
65595 +}
65596 +
65597 +static int prepend_path(const struct path *path, struct path *root,
65598 + char **buffer, int *buflen)
65599 +{
65600 + struct dentry *dentry = path->dentry;
65601 + struct vfsmount *vfsmnt = path->mnt;
65602 + struct mount *mnt = real_mount(vfsmnt);
65603 + bool slash = false;
65604 + int error = 0;
65605 +
65606 + while (dentry != root->dentry || vfsmnt != root->mnt) {
65607 + struct dentry * parent;
65608 +
65609 + if (dentry == vfsmnt->mnt_root || IS_ROOT(dentry)) {
65610 + /* Global root? */
65611 + if (!mnt_has_parent(mnt)) {
65612 + goto out;
65613 + }
65614 + dentry = mnt->mnt_mountpoint;
65615 + mnt = mnt->mnt_parent;
65616 + vfsmnt = &mnt->mnt;
65617 + continue;
65618 + }
65619 + parent = dentry->d_parent;
65620 + prefetch(parent);
65621 + spin_lock(&dentry->d_lock);
65622 + error = prepend_name(buffer, buflen, &dentry->d_name);
65623 + spin_unlock(&dentry->d_lock);
65624 + if (!error)
65625 + error = prepend(buffer, buflen, "/", 1);
65626 + if (error)
65627 + break;
65628 +
65629 + slash = true;
65630 + dentry = parent;
65631 + }
65632 +
65633 +out:
65634 + if (!error && !slash)
65635 + error = prepend(buffer, buflen, "/", 1);
65636 +
65637 + return error;
65638 +}
65639 +
65640 +/* this must be called with mount_lock and rename_lock held */
65641 +
65642 +static char *__our_d_path(const struct path *path, struct path *root,
65643 + char *buf, int buflen)
65644 +{
65645 + char *res = buf + buflen;
65646 + int error;
65647 +
65648 + prepend(&res, &buflen, "\0", 1);
65649 + error = prepend_path(path, root, &res, &buflen);
65650 + if (error)
65651 + return ERR_PTR(error);
65652 +
65653 + return res;
65654 +}
65655 +
65656 +static char *
65657 +gen_full_path(struct path *path, struct path *root, char *buf, int buflen)
65658 +{
65659 + char *retval;
65660 +
65661 + retval = __our_d_path(path, root, buf, buflen);
65662 + if (unlikely(IS_ERR(retval)))
65663 + retval = strcpy(buf, "<path too long>");
65664 + else if (unlikely(retval[1] == '/' && retval[2] == '\0'))
65665 + retval[1] = '\0';
65666 +
65667 + return retval;
65668 +}
65669 +
65670 +static char *
65671 +__d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
65672 + char *buf, int buflen)
65673 +{
65674 + struct path path;
65675 + char *res;
65676 +
65677 + path.dentry = (struct dentry *)dentry;
65678 + path.mnt = (struct vfsmount *)vfsmnt;
65679 +
65680 + /* we can use gr_real_root.dentry, gr_real_root.mnt, because this is only called
65681 + by the RBAC system */
65682 + res = gen_full_path(&path, &gr_real_root, buf, buflen);
65683 +
65684 + return res;
65685 +}
65686 +
65687 +static char *
65688 +d_real_path(const struct dentry *dentry, const struct vfsmount *vfsmnt,
65689 + char *buf, int buflen)
65690 +{
65691 + char *res;
65692 + struct path path;
65693 + struct path root;
65694 + struct task_struct *reaper = init_pid_ns.child_reaper;
65695 +
65696 + path.dentry = (struct dentry *)dentry;
65697 + path.mnt = (struct vfsmount *)vfsmnt;
65698 +
65699 + /* we can't use gr_real_root.dentry, gr_real_root.mnt, because they belong only to the RBAC system */
65700 + get_fs_root(reaper->fs, &root);
65701 +
65702 + read_seqlock_excl(&mount_lock);
65703 + write_seqlock(&rename_lock);
65704 + res = gen_full_path(&path, &root, buf, buflen);
65705 + write_sequnlock(&rename_lock);
65706 + read_sequnlock_excl(&mount_lock);
65707 +
65708 + path_put(&root);
65709 + return res;
65710 +}
65711 +
65712 +char *
65713 +gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
65714 +{
65715 + char *ret;
65716 + read_seqlock_excl(&mount_lock);
65717 + write_seqlock(&rename_lock);
65718 + ret = __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
65719 + PAGE_SIZE);
65720 + write_sequnlock(&rename_lock);
65721 + read_sequnlock_excl(&mount_lock);
65722 + return ret;
65723 +}
65724 +
65725 +static char *
65726 +gr_to_proc_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt)
65727 +{
65728 + char *ret;
65729 + char *buf;
65730 + int buflen;
65731 +
65732 + read_seqlock_excl(&mount_lock);
65733 + write_seqlock(&rename_lock);
65734 + buf = per_cpu_ptr(gr_shared_page[0], smp_processor_id());
65735 + ret = __d_real_path(dentry, mnt, buf, PAGE_SIZE - 6);
65736 + buflen = (int)(ret - buf);
65737 + if (buflen >= 5)
65738 + prepend(&ret, &buflen, "/proc", 5);
65739 + else
65740 + ret = strcpy(buf, "<path too long>");
65741 + write_sequnlock(&rename_lock);
65742 + read_sequnlock_excl(&mount_lock);
65743 + return ret;
65744 +}
65745 +
65746 +char *
65747 +gr_to_filename_nolock(const struct dentry *dentry, const struct vfsmount *mnt)
65748 +{
65749 + return __d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0],smp_processor_id()),
65750 + PAGE_SIZE);
65751 +}
65752 +
65753 +char *
65754 +gr_to_filename(const struct dentry *dentry, const struct vfsmount *mnt)
65755 +{
65756 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
65757 + PAGE_SIZE);
65758 +}
65759 +
65760 +char *
65761 +gr_to_filename1(const struct dentry *dentry, const struct vfsmount *mnt)
65762 +{
65763 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[1], smp_processor_id()),
65764 + PAGE_SIZE);
65765 +}
65766 +
65767 +char *
65768 +gr_to_filename2(const struct dentry *dentry, const struct vfsmount *mnt)
65769 +{
65770 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[2], smp_processor_id()),
65771 + PAGE_SIZE);
65772 +}
65773 +
65774 +char *
65775 +gr_to_filename3(const struct dentry *dentry, const struct vfsmount *mnt)
65776 +{
65777 + return d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[3], smp_processor_id()),
65778 + PAGE_SIZE);
65779 +}
65780 +
65781 +__inline__ __u32
65782 +to_gr_audit(const __u32 reqmode)
65783 +{
65784 + /* masks off auditable permission flags, then shifts them to create
65785 + auditing flags, and adds the special case of append auditing if
65786 + we're requesting write */
65787 + return (((reqmode & ~GR_AUDITS) << 10) | ((reqmode & GR_WRITE) ? GR_AUDIT_APPEND : 0));
65788 +}
65789 +
65790 +struct acl_role_label *
65791 +__lookup_acl_role_label(const struct gr_policy_state *state, const struct task_struct *task, const uid_t uid,
65792 + const gid_t gid)
65793 +{
65794 + unsigned int index = gr_rhash(uid, GR_ROLE_USER, state->acl_role_set.r_size);
65795 + struct acl_role_label *match;
65796 + struct role_allowed_ip *ipp;
65797 + unsigned int x;
65798 + u32 curr_ip = task->signal->saved_ip;
65799 +
65800 + match = state->acl_role_set.r_hash[index];
65801 +
65802 + while (match) {
65803 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_USER)) == (GR_ROLE_DOMAIN | GR_ROLE_USER)) {
65804 + for (x = 0; x < match->domain_child_num; x++) {
65805 + if (match->domain_children[x] == uid)
65806 + goto found;
65807 + }
65808 + } else if (match->uidgid == uid && match->roletype & GR_ROLE_USER)
65809 + break;
65810 + match = match->next;
65811 + }
65812 +found:
65813 + if (match == NULL) {
65814 + try_group:
65815 + index = gr_rhash(gid, GR_ROLE_GROUP, state->acl_role_set.r_size);
65816 + match = state->acl_role_set.r_hash[index];
65817 +
65818 + while (match) {
65819 + if ((match->roletype & (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) == (GR_ROLE_DOMAIN | GR_ROLE_GROUP)) {
65820 + for (x = 0; x < match->domain_child_num; x++) {
65821 + if (match->domain_children[x] == gid)
65822 + goto found2;
65823 + }
65824 + } else if (match->uidgid == gid && match->roletype & GR_ROLE_GROUP)
65825 + break;
65826 + match = match->next;
65827 + }
65828 +found2:
65829 + if (match == NULL)
65830 + match = state->default_role;
65831 + if (match->allowed_ips == NULL)
65832 + return match;
65833 + else {
65834 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
65835 + if (likely
65836 + ((ntohl(curr_ip) & ipp->netmask) ==
65837 + (ntohl(ipp->addr) & ipp->netmask)))
65838 + return match;
65839 + }
65840 + match = state->default_role;
65841 + }
65842 + } else if (match->allowed_ips == NULL) {
65843 + return match;
65844 + } else {
65845 + for (ipp = match->allowed_ips; ipp; ipp = ipp->next) {
65846 + if (likely
65847 + ((ntohl(curr_ip) & ipp->netmask) ==
65848 + (ntohl(ipp->addr) & ipp->netmask)))
65849 + return match;
65850 + }
65851 + goto try_group;
65852 + }
65853 +
65854 + return match;
65855 +}
65856 +
65857 +static struct acl_role_label *
65858 +lookup_acl_role_label(const struct task_struct *task, const uid_t uid,
65859 + const gid_t gid)
65860 +{
65861 + return __lookup_acl_role_label(&running_polstate, task, uid, gid);
65862 +}
65863 +
65864 +struct acl_subject_label *
65865 +lookup_acl_subj_label(const ino_t ino, const dev_t dev,
65866 + const struct acl_role_label *role)
65867 +{
65868 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
65869 + struct acl_subject_label *match;
65870 +
65871 + match = role->subj_hash[index];
65872 +
65873 + while (match && (match->inode != ino || match->device != dev ||
65874 + (match->mode & GR_DELETED))) {
65875 + match = match->next;
65876 + }
65877 +
65878 + if (match && !(match->mode & GR_DELETED))
65879 + return match;
65880 + else
65881 + return NULL;
65882 +}
65883 +
65884 +struct acl_subject_label *
65885 +lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev,
65886 + const struct acl_role_label *role)
65887 +{
65888 + unsigned int index = gr_fhash(ino, dev, role->subj_hash_size);
65889 + struct acl_subject_label *match;
65890 +
65891 + match = role->subj_hash[index];
65892 +
65893 + while (match && (match->inode != ino || match->device != dev ||
65894 + !(match->mode & GR_DELETED))) {
65895 + match = match->next;
65896 + }
65897 +
65898 + if (match && (match->mode & GR_DELETED))
65899 + return match;
65900 + else
65901 + return NULL;
65902 +}
65903 +
65904 +static struct acl_object_label *
65905 +lookup_acl_obj_label(const ino_t ino, const dev_t dev,
65906 + const struct acl_subject_label *subj)
65907 +{
65908 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
65909 + struct acl_object_label *match;
65910 +
65911 + match = subj->obj_hash[index];
65912 +
65913 + while (match && (match->inode != ino || match->device != dev ||
65914 + (match->mode & GR_DELETED))) {
65915 + match = match->next;
65916 + }
65917 +
65918 + if (match && !(match->mode & GR_DELETED))
65919 + return match;
65920 + else
65921 + return NULL;
65922 +}
65923 +
65924 +static struct acl_object_label *
65925 +lookup_acl_obj_label_create(const ino_t ino, const dev_t dev,
65926 + const struct acl_subject_label *subj)
65927 +{
65928 + unsigned int index = gr_fhash(ino, dev, subj->obj_hash_size);
65929 + struct acl_object_label *match;
65930 +
65931 + match = subj->obj_hash[index];
65932 +
65933 + while (match && (match->inode != ino || match->device != dev ||
65934 + !(match->mode & GR_DELETED))) {
65935 + match = match->next;
65936 + }
65937 +
65938 + if (match && (match->mode & GR_DELETED))
65939 + return match;
65940 +
65941 + match = subj->obj_hash[index];
65942 +
65943 + while (match && (match->inode != ino || match->device != dev ||
65944 + (match->mode & GR_DELETED))) {
65945 + match = match->next;
65946 + }
65947 +
65948 + if (match && !(match->mode & GR_DELETED))
65949 + return match;
65950 + else
65951 + return NULL;
65952 +}
65953 +
65954 +struct name_entry *
65955 +__lookup_name_entry(const struct gr_policy_state *state, const char *name)
65956 +{
65957 + unsigned int len = strlen(name);
65958 + unsigned int key = full_name_hash(name, len);
65959 + unsigned int index = key % state->name_set.n_size;
65960 + struct name_entry *match;
65961 +
65962 + match = state->name_set.n_hash[index];
65963 +
65964 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len)))
65965 + match = match->next;
65966 +
65967 + return match;
65968 +}
65969 +
65970 +static struct name_entry *
65971 +lookup_name_entry(const char *name)
65972 +{
65973 + return __lookup_name_entry(&running_polstate, name);
65974 +}
65975 +
65976 +static struct name_entry *
65977 +lookup_name_entry_create(const char *name)
65978 +{
65979 + unsigned int len = strlen(name);
65980 + unsigned int key = full_name_hash(name, len);
65981 + unsigned int index = key % running_polstate.name_set.n_size;
65982 + struct name_entry *match;
65983 +
65984 + match = running_polstate.name_set.n_hash[index];
65985 +
65986 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
65987 + !match->deleted))
65988 + match = match->next;
65989 +
65990 + if (match && match->deleted)
65991 + return match;
65992 +
65993 + match = running_polstate.name_set.n_hash[index];
65994 +
65995 + while (match && (match->key != key || !gr_streq(match->name, name, match->len, len) ||
65996 + match->deleted))
65997 + match = match->next;
65998 +
65999 + if (match && !match->deleted)
66000 + return match;
66001 + else
66002 + return NULL;
66003 +}
66004 +
66005 +static struct inodev_entry *
66006 +lookup_inodev_entry(const ino_t ino, const dev_t dev)
66007 +{
66008 + unsigned int index = gr_fhash(ino, dev, running_polstate.inodev_set.i_size);
66009 + struct inodev_entry *match;
66010 +
66011 + match = running_polstate.inodev_set.i_hash[index];
66012 +
66013 + while (match && (match->nentry->inode != ino || match->nentry->device != dev))
66014 + match = match->next;
66015 +
66016 + return match;
66017 +}
66018 +
66019 +void
66020 +__insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry)
66021 +{
66022 + unsigned int index = gr_fhash(entry->nentry->inode, entry->nentry->device,
66023 + state->inodev_set.i_size);
66024 + struct inodev_entry **curr;
66025 +
66026 + entry->prev = NULL;
66027 +
66028 + curr = &state->inodev_set.i_hash[index];
66029 + if (*curr != NULL)
66030 + (*curr)->prev = entry;
66031 +
66032 + entry->next = *curr;
66033 + *curr = entry;
66034 +
66035 + return;
66036 +}
66037 +
66038 +static void
66039 +insert_inodev_entry(struct inodev_entry *entry)
66040 +{
66041 + __insert_inodev_entry(&running_polstate, entry);
66042 +}
66043 +
66044 +void
66045 +insert_acl_obj_label(struct acl_object_label *obj,
66046 + struct acl_subject_label *subj)
66047 +{
66048 + unsigned int index =
66049 + gr_fhash(obj->inode, obj->device, subj->obj_hash_size);
66050 + struct acl_object_label **curr;
66051 +
66052 + obj->prev = NULL;
66053 +
66054 + curr = &subj->obj_hash[index];
66055 + if (*curr != NULL)
66056 + (*curr)->prev = obj;
66057 +
66058 + obj->next = *curr;
66059 + *curr = obj;
66060 +
66061 + return;
66062 +}
66063 +
66064 +void
66065 +insert_acl_subj_label(struct acl_subject_label *obj,
66066 + struct acl_role_label *role)
66067 +{
66068 + unsigned int index = gr_fhash(obj->inode, obj->device, role->subj_hash_size);
66069 + struct acl_subject_label **curr;
66070 +
66071 + obj->prev = NULL;
66072 +
66073 + curr = &role->subj_hash[index];
66074 + if (*curr != NULL)
66075 + (*curr)->prev = obj;
66076 +
66077 + obj->next = *curr;
66078 + *curr = obj;
66079 +
66080 + return;
66081 +}
66082 +
66083 +/* derived from glibc fnmatch() 0: match, 1: no match*/
66084 +
66085 +static int
66086 +glob_match(const char *p, const char *n)
66087 +{
66088 + char c;
66089 +
66090 + while ((c = *p++) != '\0') {
66091 + switch (c) {
66092 + case '?':
66093 + if (*n == '\0')
66094 + return 1;
66095 + else if (*n == '/')
66096 + return 1;
66097 + break;
66098 + case '\\':
66099 + if (*n != c)
66100 + return 1;
66101 + break;
66102 + case '*':
66103 + for (c = *p++; c == '?' || c == '*'; c = *p++) {
66104 + if (*n == '/')
66105 + return 1;
66106 + else if (c == '?') {
66107 + if (*n == '\0')
66108 + return 1;
66109 + else
66110 + ++n;
66111 + }
66112 + }
66113 + if (c == '\0') {
66114 + return 0;
66115 + } else {
66116 + const char *endp;
66117 +
66118 + if ((endp = strchr(n, '/')) == NULL)
66119 + endp = n + strlen(n);
66120 +
66121 + if (c == '[') {
66122 + for (--p; n < endp; ++n)
66123 + if (!glob_match(p, n))
66124 + return 0;
66125 + } else if (c == '/') {
66126 + while (*n != '\0' && *n != '/')
66127 + ++n;
66128 + if (*n == '/' && !glob_match(p, n + 1))
66129 + return 0;
66130 + } else {
66131 + for (--p; n < endp; ++n)
66132 + if (*n == c && !glob_match(p, n))
66133 + return 0;
66134 + }
66135 +
66136 + return 1;
66137 + }
66138 + case '[':
66139 + {
66140 + int not;
66141 + char cold;
66142 +
66143 + if (*n == '\0' || *n == '/')
66144 + return 1;
66145 +
66146 + not = (*p == '!' || *p == '^');
66147 + if (not)
66148 + ++p;
66149 +
66150 + c = *p++;
66151 + for (;;) {
66152 + unsigned char fn = (unsigned char)*n;
66153 +
66154 + if (c == '\0')
66155 + return 1;
66156 + else {
66157 + if (c == fn)
66158 + goto matched;
66159 + cold = c;
66160 + c = *p++;
66161 +
66162 + if (c == '-' && *p != ']') {
66163 + unsigned char cend = *p++;
66164 +
66165 + if (cend == '\0')
66166 + return 1;
66167 +
66168 + if (cold <= fn && fn <= cend)
66169 + goto matched;
66170 +
66171 + c = *p++;
66172 + }
66173 + }
66174 +
66175 + if (c == ']')
66176 + break;
66177 + }
66178 + if (!not)
66179 + return 1;
66180 + break;
66181 + matched:
66182 + while (c != ']') {
66183 + if (c == '\0')
66184 + return 1;
66185 +
66186 + c = *p++;
66187 + }
66188 + if (not)
66189 + return 1;
66190 + }
66191 + break;
66192 + default:
66193 + if (c != *n)
66194 + return 1;
66195 + }
66196 +
66197 + ++n;
66198 + }
66199 +
66200 + if (*n == '\0')
66201 + return 0;
66202 +
66203 + if (*n == '/')
66204 + return 0;
66205 +
66206 + return 1;
66207 +}
66208 +
66209 +static struct acl_object_label *
66210 +chk_glob_label(struct acl_object_label *globbed,
66211 + const struct dentry *dentry, const struct vfsmount *mnt, char **path)
66212 +{
66213 + struct acl_object_label *tmp;
66214 +
66215 + if (*path == NULL)
66216 + *path = gr_to_filename_nolock(dentry, mnt);
66217 +
66218 + tmp = globbed;
66219 +
66220 + while (tmp) {
66221 + if (!glob_match(tmp->filename, *path))
66222 + return tmp;
66223 + tmp = tmp->next;
66224 + }
66225 +
66226 + return NULL;
66227 +}
66228 +
66229 +static struct acl_object_label *
66230 +__full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
66231 + const ino_t curr_ino, const dev_t curr_dev,
66232 + const struct acl_subject_label *subj, char **path, const int checkglob)
66233 +{
66234 + struct acl_subject_label *tmpsubj;
66235 + struct acl_object_label *retval;
66236 + struct acl_object_label *retval2;
66237 +
66238 + tmpsubj = (struct acl_subject_label *) subj;
66239 + read_lock(&gr_inode_lock);
66240 + do {
66241 + retval = lookup_acl_obj_label(curr_ino, curr_dev, tmpsubj);
66242 + if (retval) {
66243 + if (checkglob && retval->globbed) {
66244 + retval2 = chk_glob_label(retval->globbed, orig_dentry, orig_mnt, path);
66245 + if (retval2)
66246 + retval = retval2;
66247 + }
66248 + break;
66249 + }
66250 + } while ((tmpsubj = tmpsubj->parent_subject));
66251 + read_unlock(&gr_inode_lock);
66252 +
66253 + return retval;
66254 +}
66255 +
66256 +static __inline__ struct acl_object_label *
66257 +full_lookup(const struct dentry *orig_dentry, const struct vfsmount *orig_mnt,
66258 + struct dentry *curr_dentry,
66259 + const struct acl_subject_label *subj, char **path, const int checkglob)
66260 +{
66261 + int newglob = checkglob;
66262 + ino_t inode;
66263 + dev_t device;
66264 +
66265 + /* if we aren't checking a subdirectory of the original path yet, don't do glob checking
66266 + as we don't want a / * rule to match instead of the / object
66267 + don't do this for create lookups that call this function though, since they're looking up
66268 + on the parent and thus need globbing checks on all paths
66269 + */
66270 + if (orig_dentry == curr_dentry && newglob != GR_CREATE_GLOB)
66271 + newglob = GR_NO_GLOB;
66272 +
66273 + spin_lock(&curr_dentry->d_lock);
66274 + inode = curr_dentry->d_inode->i_ino;
66275 + device = __get_dev(curr_dentry);
66276 + spin_unlock(&curr_dentry->d_lock);
66277 +
66278 + return __full_lookup(orig_dentry, orig_mnt, inode, device, subj, path, newglob);
66279 +}
66280 +
66281 +#ifdef CONFIG_HUGETLBFS
66282 +static inline bool
66283 +is_hugetlbfs_mnt(const struct vfsmount *mnt)
66284 +{
66285 + int i;
66286 + for (i = 0; i < HUGE_MAX_HSTATE; i++) {
66287 + if (unlikely(hugetlbfs_vfsmount[i] == mnt))
66288 + return true;
66289 + }
66290 +
66291 + return false;
66292 +}
66293 +#endif
66294 +
66295 +static struct acl_object_label *
66296 +__chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66297 + const struct acl_subject_label *subj, char *path, const int checkglob)
66298 +{
66299 + struct dentry *dentry = (struct dentry *) l_dentry;
66300 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
66301 + struct mount *real_mnt = real_mount(mnt);
66302 + struct acl_object_label *retval;
66303 + struct dentry *parent;
66304 +
66305 + read_seqlock_excl(&mount_lock);
66306 + write_seqlock(&rename_lock);
66307 +
66308 + if (unlikely((mnt == shm_mnt && dentry->d_inode->i_nlink == 0) || mnt == pipe_mnt ||
66309 +#ifdef CONFIG_NET
66310 + mnt == sock_mnt ||
66311 +#endif
66312 +#ifdef CONFIG_HUGETLBFS
66313 + (is_hugetlbfs_mnt(mnt) && dentry->d_inode->i_nlink == 0) ||
66314 +#endif
66315 + /* ignore Eric Biederman */
66316 + IS_PRIVATE(l_dentry->d_inode))) {
66317 + retval = (subj->mode & GR_SHMEXEC) ? fakefs_obj_rwx : fakefs_obj_rw;
66318 + goto out;
66319 + }
66320 +
66321 + for (;;) {
66322 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
66323 + break;
66324 +
66325 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
66326 + if (!mnt_has_parent(real_mnt))
66327 + break;
66328 +
66329 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
66330 + if (retval != NULL)
66331 + goto out;
66332 +
66333 + dentry = real_mnt->mnt_mountpoint;
66334 + real_mnt = real_mnt->mnt_parent;
66335 + mnt = &real_mnt->mnt;
66336 + continue;
66337 + }
66338 +
66339 + parent = dentry->d_parent;
66340 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
66341 + if (retval != NULL)
66342 + goto out;
66343 +
66344 + dentry = parent;
66345 + }
66346 +
66347 + retval = full_lookup(l_dentry, l_mnt, dentry, subj, &path, checkglob);
66348 +
66349 + /* gr_real_root is pinned so we don't have to hold a reference */
66350 + if (retval == NULL)
66351 + retval = full_lookup(l_dentry, l_mnt, gr_real_root.dentry, subj, &path, checkglob);
66352 +out:
66353 + write_sequnlock(&rename_lock);
66354 + read_sequnlock_excl(&mount_lock);
66355 +
66356 + BUG_ON(retval == NULL);
66357 +
66358 + return retval;
66359 +}
66360 +
66361 +static __inline__ struct acl_object_label *
66362 +chk_obj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66363 + const struct acl_subject_label *subj)
66364 +{
66365 + char *path = NULL;
66366 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_REG_GLOB);
66367 +}
66368 +
66369 +static __inline__ struct acl_object_label *
66370 +chk_obj_label_noglob(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66371 + const struct acl_subject_label *subj)
66372 +{
66373 + char *path = NULL;
66374 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_NO_GLOB);
66375 +}
66376 +
66377 +static __inline__ struct acl_object_label *
66378 +chk_obj_create_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66379 + const struct acl_subject_label *subj, char *path)
66380 +{
66381 + return __chk_obj_label(l_dentry, l_mnt, subj, path, GR_CREATE_GLOB);
66382 +}
66383 +
66384 +struct acl_subject_label *
66385 +chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt,
66386 + const struct acl_role_label *role)
66387 +{
66388 + struct dentry *dentry = (struct dentry *) l_dentry;
66389 + struct vfsmount *mnt = (struct vfsmount *) l_mnt;
66390 + struct mount *real_mnt = real_mount(mnt);
66391 + struct acl_subject_label *retval;
66392 + struct dentry *parent;
66393 +
66394 + read_seqlock_excl(&mount_lock);
66395 + write_seqlock(&rename_lock);
66396 +
66397 + for (;;) {
66398 + if (dentry == gr_real_root.dentry && mnt == gr_real_root.mnt)
66399 + break;
66400 + if (dentry == mnt->mnt_root || IS_ROOT(dentry)) {
66401 + if (!mnt_has_parent(real_mnt))
66402 + break;
66403 +
66404 + spin_lock(&dentry->d_lock);
66405 + read_lock(&gr_inode_lock);
66406 + retval =
66407 + lookup_acl_subj_label(dentry->d_inode->i_ino,
66408 + __get_dev(dentry), role);
66409 + read_unlock(&gr_inode_lock);
66410 + spin_unlock(&dentry->d_lock);
66411 + if (retval != NULL)
66412 + goto out;
66413 +
66414 + dentry = real_mnt->mnt_mountpoint;
66415 + real_mnt = real_mnt->mnt_parent;
66416 + mnt = &real_mnt->mnt;
66417 + continue;
66418 + }
66419 +
66420 + spin_lock(&dentry->d_lock);
66421 + read_lock(&gr_inode_lock);
66422 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
66423 + __get_dev(dentry), role);
66424 + read_unlock(&gr_inode_lock);
66425 + parent = dentry->d_parent;
66426 + spin_unlock(&dentry->d_lock);
66427 +
66428 + if (retval != NULL)
66429 + goto out;
66430 +
66431 + dentry = parent;
66432 + }
66433 +
66434 + spin_lock(&dentry->d_lock);
66435 + read_lock(&gr_inode_lock);
66436 + retval = lookup_acl_subj_label(dentry->d_inode->i_ino,
66437 + __get_dev(dentry), role);
66438 + read_unlock(&gr_inode_lock);
66439 + spin_unlock(&dentry->d_lock);
66440 +
66441 + if (unlikely(retval == NULL)) {
66442 + /* gr_real_root is pinned, we don't need to hold a reference */
66443 + read_lock(&gr_inode_lock);
66444 + retval = lookup_acl_subj_label(gr_real_root.dentry->d_inode->i_ino,
66445 + __get_dev(gr_real_root.dentry), role);
66446 + read_unlock(&gr_inode_lock);
66447 + }
66448 +out:
66449 + write_sequnlock(&rename_lock);
66450 + read_sequnlock_excl(&mount_lock);
66451 +
66452 + BUG_ON(retval == NULL);
66453 +
66454 + return retval;
66455 +}
66456 +
66457 +void
66458 +assign_special_role(const char *rolename)
66459 +{
66460 + struct acl_object_label *obj;
66461 + struct acl_role_label *r;
66462 + struct acl_role_label *assigned = NULL;
66463 + struct task_struct *tsk;
66464 + struct file *filp;
66465 +
66466 + FOR_EACH_ROLE_START(r)
66467 + if (!strcmp(rolename, r->rolename) &&
66468 + (r->roletype & GR_ROLE_SPECIAL)) {
66469 + assigned = r;
66470 + break;
66471 + }
66472 + FOR_EACH_ROLE_END(r)
66473 +
66474 + if (!assigned)
66475 + return;
66476 +
66477 + read_lock(&tasklist_lock);
66478 + read_lock(&grsec_exec_file_lock);
66479 +
66480 + tsk = current->real_parent;
66481 + if (tsk == NULL)
66482 + goto out_unlock;
66483 +
66484 + filp = tsk->exec_file;
66485 + if (filp == NULL)
66486 + goto out_unlock;
66487 +
66488 + tsk->is_writable = 0;
66489 + tsk->inherited = 0;
66490 +
66491 + tsk->acl_sp_role = 1;
66492 + tsk->acl_role_id = ++acl_sp_role_value;
66493 + tsk->role = assigned;
66494 + tsk->acl = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role);
66495 +
66496 + /* ignore additional mmap checks for processes that are writable
66497 + by the default ACL */
66498 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
66499 + if (unlikely(obj->mode & GR_WRITE))
66500 + tsk->is_writable = 1;
66501 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, tsk->role->root_label);
66502 + if (unlikely(obj->mode & GR_WRITE))
66503 + tsk->is_writable = 1;
66504 +
66505 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
66506 + printk(KERN_ALERT "Assigning special role:%s subject:%s to process (%s:%d)\n", tsk->role->rolename,
66507 + tsk->acl->filename, tsk->comm, task_pid_nr(tsk));
66508 +#endif
66509 +
66510 +out_unlock:
66511 + read_unlock(&grsec_exec_file_lock);
66512 + read_unlock(&tasklist_lock);
66513 + return;
66514 +}
66515 +
66516 +
66517 +static void
66518 +gr_log_learn(const struct dentry *dentry, const struct vfsmount *mnt, const __u32 mode)
66519 +{
66520 + struct task_struct *task = current;
66521 + const struct cred *cred = current_cred();
66522 +
66523 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename, task->role->roletype,
66524 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
66525 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
66526 + 1UL, 1UL, gr_to_filename(dentry, mnt), (unsigned long) mode, &task->signal->saved_ip);
66527 +
66528 + return;
66529 +}
66530 +
66531 +static void
66532 +gr_log_learn_uid_change(const kuid_t real, const kuid_t effective, const kuid_t fs)
66533 +{
66534 + struct task_struct *task = current;
66535 + const struct cred *cred = current_cred();
66536 +
66537 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
66538 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
66539 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
66540 + 'u', GR_GLOBAL_UID(real), GR_GLOBAL_UID(effective), GR_GLOBAL_UID(fs), &task->signal->saved_ip);
66541 +
66542 + return;
66543 +}
66544 +
66545 +static void
66546 +gr_log_learn_gid_change(const kgid_t real, const kgid_t effective, const kgid_t fs)
66547 +{
66548 + struct task_struct *task = current;
66549 + const struct cred *cred = current_cred();
66550 +
66551 + security_learn(GR_ID_LEARN_MSG, task->role->rolename, task->role->roletype,
66552 + GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), task->exec_file ? gr_to_filename1(task->exec_file->f_path.dentry,
66553 + task->exec_file->f_path.mnt) : task->acl->filename, task->acl->filename,
66554 + 'g', GR_GLOBAL_GID(real), GR_GLOBAL_GID(effective), GR_GLOBAL_GID(fs), &task->signal->saved_ip);
66555 +
66556 + return;
66557 +}
66558 +
66559 +static void
66560 +gr_set_proc_res(struct task_struct *task)
66561 +{
66562 + struct acl_subject_label *proc;
66563 + unsigned short i;
66564 +
66565 + proc = task->acl;
66566 +
66567 + if (proc->mode & (GR_LEARN | GR_INHERITLEARN))
66568 + return;
66569 +
66570 + for (i = 0; i < RLIM_NLIMITS; i++) {
66571 + if (!(proc->resmask & (1U << i)))
66572 + continue;
66573 +
66574 + task->signal->rlim[i].rlim_cur = proc->res[i].rlim_cur;
66575 + task->signal->rlim[i].rlim_max = proc->res[i].rlim_max;
66576 +
66577 + if (i == RLIMIT_CPU)
66578 + update_rlimit_cpu(task, proc->res[i].rlim_cur);
66579 + }
66580 +
66581 + return;
66582 +}
66583 +
66584 +/* both of the below must be called with
66585 + rcu_read_lock();
66586 + read_lock(&tasklist_lock);
66587 + read_lock(&grsec_exec_file_lock);
66588 +*/
66589 +
66590 +struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename)
66591 +{
66592 + char *tmpname;
66593 + struct acl_subject_label *tmpsubj;
66594 + struct file *filp;
66595 + struct name_entry *nmatch;
66596 +
66597 + filp = task->exec_file;
66598 + if (filp == NULL)
66599 + return NULL;
66600 +
66601 + /* the following is to apply the correct subject
66602 + on binaries running when the RBAC system
66603 + is enabled, when the binaries have been
66604 + replaced or deleted since their execution
66605 + -----
66606 + when the RBAC system starts, the inode/dev
66607 + from exec_file will be one the RBAC system
66608 + is unaware of. It only knows the inode/dev
66609 + of the present file on disk, or the absence
66610 + of it.
66611 + */
66612 +
66613 + if (filename)
66614 + nmatch = __lookup_name_entry(state, filename);
66615 + else {
66616 + preempt_disable();
66617 + tmpname = gr_to_filename_rbac(filp->f_path.dentry, filp->f_path.mnt);
66618 +
66619 + nmatch = __lookup_name_entry(state, tmpname);
66620 + preempt_enable();
66621 + }
66622 + tmpsubj = NULL;
66623 + if (nmatch) {
66624 + if (nmatch->deleted)
66625 + tmpsubj = lookup_acl_subj_label_deleted(nmatch->inode, nmatch->device, task->role);
66626 + else
66627 + tmpsubj = lookup_acl_subj_label(nmatch->inode, nmatch->device, task->role);
66628 + }
66629 + /* this also works for the reload case -- if we don't match a potentially inherited subject
66630 + then we fall back to a normal lookup based on the binary's ino/dev
66631 + */
66632 + if (tmpsubj == NULL)
66633 + tmpsubj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, task->role);
66634 +
66635 + return tmpsubj;
66636 +}
66637 +
66638 +static struct acl_subject_label *gr_get_subject_for_task(struct task_struct *task, const char *filename)
66639 +{
66640 + return __gr_get_subject_for_task(&running_polstate, task, filename);
66641 +}
66642 +
66643 +void __gr_apply_subject_to_task(const struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj)
66644 +{
66645 + struct acl_object_label *obj;
66646 + struct file *filp;
66647 +
66648 + filp = task->exec_file;
66649 +
66650 + task->acl = subj;
66651 + task->is_writable = 0;
66652 + /* ignore additional mmap checks for processes that are writable
66653 + by the default ACL */
66654 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, state->default_role->root_label);
66655 + if (unlikely(obj->mode & GR_WRITE))
66656 + task->is_writable = 1;
66657 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
66658 + if (unlikely(obj->mode & GR_WRITE))
66659 + task->is_writable = 1;
66660 +
66661 + gr_set_proc_res(task);
66662 +
66663 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
66664 + 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);
66665 +#endif
66666 +}
66667 +
66668 +static void gr_apply_subject_to_task(struct task_struct *task, struct acl_subject_label *subj)
66669 +{
66670 + __gr_apply_subject_to_task(&running_polstate, task, subj);
66671 +}
66672 +
66673 +__u32
66674 +gr_search_file(const struct dentry * dentry, const __u32 mode,
66675 + const struct vfsmount * mnt)
66676 +{
66677 + __u32 retval = mode;
66678 + struct acl_subject_label *curracl;
66679 + struct acl_object_label *currobj;
66680 +
66681 + if (unlikely(!(gr_status & GR_READY)))
66682 + return (mode & ~GR_AUDITS);
66683 +
66684 + curracl = current->acl;
66685 +
66686 + currobj = chk_obj_label(dentry, mnt, curracl);
66687 + retval = currobj->mode & mode;
66688 +
66689 + /* if we're opening a specified transfer file for writing
66690 + (e.g. /dev/initctl), then transfer our role to init
66691 + */
66692 + if (unlikely(currobj->mode & GR_INIT_TRANSFER && retval & GR_WRITE &&
66693 + current->role->roletype & GR_ROLE_PERSIST)) {
66694 + struct task_struct *task = init_pid_ns.child_reaper;
66695 +
66696 + if (task->role != current->role) {
66697 + struct acl_subject_label *subj;
66698 +
66699 + task->acl_sp_role = 0;
66700 + task->acl_role_id = current->acl_role_id;
66701 + task->role = current->role;
66702 + rcu_read_lock();
66703 + read_lock(&grsec_exec_file_lock);
66704 + subj = gr_get_subject_for_task(task, NULL);
66705 + gr_apply_subject_to_task(task, subj);
66706 + read_unlock(&grsec_exec_file_lock);
66707 + rcu_read_unlock();
66708 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_INIT_TRANSFER_MSG);
66709 + }
66710 + }
66711 +
66712 + if (unlikely
66713 + ((curracl->mode & (GR_LEARN | GR_INHERITLEARN)) && !(mode & GR_NOPTRACE)
66714 + && (retval != (mode & ~(GR_AUDITS | GR_SUPPRESS))))) {
66715 + __u32 new_mode = mode;
66716 +
66717 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
66718 +
66719 + retval = new_mode;
66720 +
66721 + if (new_mode & GR_EXEC && curracl->mode & GR_INHERITLEARN)
66722 + new_mode |= GR_INHERIT;
66723 +
66724 + if (!(mode & GR_NOLEARN))
66725 + gr_log_learn(dentry, mnt, new_mode);
66726 + }
66727 +
66728 + return retval;
66729 +}
66730 +
66731 +struct acl_object_label *gr_get_create_object(const struct dentry *new_dentry,
66732 + const struct dentry *parent,
66733 + const struct vfsmount *mnt)
66734 +{
66735 + struct name_entry *match;
66736 + struct acl_object_label *matchpo;
66737 + struct acl_subject_label *curracl;
66738 + char *path;
66739 +
66740 + if (unlikely(!(gr_status & GR_READY)))
66741 + return NULL;
66742 +
66743 + preempt_disable();
66744 + path = gr_to_filename_rbac(new_dentry, mnt);
66745 + match = lookup_name_entry_create(path);
66746 +
66747 + curracl = current->acl;
66748 +
66749 + if (match) {
66750 + read_lock(&gr_inode_lock);
66751 + matchpo = lookup_acl_obj_label_create(match->inode, match->device, curracl);
66752 + read_unlock(&gr_inode_lock);
66753 +
66754 + if (matchpo) {
66755 + preempt_enable();
66756 + return matchpo;
66757 + }
66758 + }
66759 +
66760 + // lookup parent
66761 +
66762 + matchpo = chk_obj_create_label(parent, mnt, curracl, path);
66763 +
66764 + preempt_enable();
66765 + return matchpo;
66766 +}
66767 +
66768 +__u32
66769 +gr_check_create(const struct dentry * new_dentry, const struct dentry * parent,
66770 + const struct vfsmount * mnt, const __u32 mode)
66771 +{
66772 + struct acl_object_label *matchpo;
66773 + __u32 retval;
66774 +
66775 + if (unlikely(!(gr_status & GR_READY)))
66776 + return (mode & ~GR_AUDITS);
66777 +
66778 + matchpo = gr_get_create_object(new_dentry, parent, mnt);
66779 +
66780 + retval = matchpo->mode & mode;
66781 +
66782 + if ((retval != (mode & ~(GR_AUDITS | GR_SUPPRESS)))
66783 + && (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
66784 + __u32 new_mode = mode;
66785 +
66786 + new_mode &= ~(GR_AUDITS | GR_SUPPRESS);
66787 +
66788 + gr_log_learn(new_dentry, mnt, new_mode);
66789 + return new_mode;
66790 + }
66791 +
66792 + return retval;
66793 +}
66794 +
66795 +__u32
66796 +gr_check_link(const struct dentry * new_dentry,
66797 + const struct dentry * parent_dentry,
66798 + const struct vfsmount * parent_mnt,
66799 + const struct dentry * old_dentry, const struct vfsmount * old_mnt)
66800 +{
66801 + struct acl_object_label *obj;
66802 + __u32 oldmode, newmode;
66803 + __u32 needmode;
66804 + __u32 checkmodes = GR_FIND | GR_APPEND | GR_WRITE | GR_EXEC | GR_SETID | GR_READ |
66805 + GR_DELETE | GR_INHERIT;
66806 +
66807 + if (unlikely(!(gr_status & GR_READY)))
66808 + return (GR_CREATE | GR_LINK);
66809 +
66810 + obj = chk_obj_label(old_dentry, old_mnt, current->acl);
66811 + oldmode = obj->mode;
66812 +
66813 + obj = gr_get_create_object(new_dentry, parent_dentry, parent_mnt);
66814 + newmode = obj->mode;
66815 +
66816 + needmode = newmode & checkmodes;
66817 +
66818 + // old name for hardlink must have at least the permissions of the new name
66819 + if ((oldmode & needmode) != needmode)
66820 + goto bad;
66821 +
66822 + // if old name had restrictions/auditing, make sure the new name does as well
66823 + needmode = oldmode & (GR_NOPTRACE | GR_PTRACERD | GR_INHERIT | GR_AUDITS);
66824 +
66825 + // don't allow hardlinking of suid/sgid/fcapped files without permission
66826 + if (is_privileged_binary(old_dentry))
66827 + needmode |= GR_SETID;
66828 +
66829 + if ((newmode & needmode) != needmode)
66830 + goto bad;
66831 +
66832 + // enforce minimum permissions
66833 + if ((newmode & (GR_CREATE | GR_LINK)) == (GR_CREATE | GR_LINK))
66834 + return newmode;
66835 +bad:
66836 + needmode = oldmode;
66837 + if (is_privileged_binary(old_dentry))
66838 + needmode |= GR_SETID;
66839 +
66840 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN)) {
66841 + gr_log_learn(old_dentry, old_mnt, needmode | GR_CREATE | GR_LINK);
66842 + return (GR_CREATE | GR_LINK);
66843 + } else if (newmode & GR_SUPPRESS)
66844 + return GR_SUPPRESS;
66845 + else
66846 + return 0;
66847 +}
66848 +
66849 +int
66850 +gr_check_hidden_task(const struct task_struct *task)
66851 +{
66852 + if (unlikely(!(gr_status & GR_READY)))
66853 + return 0;
66854 +
66855 + if (!(task->acl->mode & GR_PROCFIND) && !(current->acl->mode & GR_VIEW))
66856 + return 1;
66857 +
66858 + return 0;
66859 +}
66860 +
66861 +int
66862 +gr_check_protected_task(const struct task_struct *task)
66863 +{
66864 + if (unlikely(!(gr_status & GR_READY) || !task))
66865 + return 0;
66866 +
66867 + if ((task->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
66868 + task->acl != current->acl)
66869 + return 1;
66870 +
66871 + return 0;
66872 +}
66873 +
66874 +int
66875 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
66876 +{
66877 + struct task_struct *p;
66878 + int ret = 0;
66879 +
66880 + if (unlikely(!(gr_status & GR_READY) || !pid))
66881 + return ret;
66882 +
66883 + read_lock(&tasklist_lock);
66884 + do_each_pid_task(pid, type, p) {
66885 + if ((p->acl->mode & GR_PROTECTED) && !(current->acl->mode & GR_KILL) &&
66886 + p->acl != current->acl) {
66887 + ret = 1;
66888 + goto out;
66889 + }
66890 + } while_each_pid_task(pid, type, p);
66891 +out:
66892 + read_unlock(&tasklist_lock);
66893 +
66894 + return ret;
66895 +}
66896 +
66897 +void
66898 +gr_copy_label(struct task_struct *tsk)
66899 +{
66900 + struct task_struct *p = current;
66901 +
66902 + tsk->inherited = p->inherited;
66903 + tsk->acl_sp_role = 0;
66904 + tsk->acl_role_id = p->acl_role_id;
66905 + tsk->acl = p->acl;
66906 + tsk->role = p->role;
66907 + tsk->signal->used_accept = 0;
66908 + tsk->signal->curr_ip = p->signal->curr_ip;
66909 + tsk->signal->saved_ip = p->signal->saved_ip;
66910 + if (p->exec_file)
66911 + get_file(p->exec_file);
66912 + tsk->exec_file = p->exec_file;
66913 + tsk->is_writable = p->is_writable;
66914 + if (unlikely(p->signal->used_accept)) {
66915 + p->signal->curr_ip = 0;
66916 + p->signal->saved_ip = 0;
66917 + }
66918 +
66919 + return;
66920 +}
66921 +
66922 +extern int gr_process_kernel_setuid_ban(struct user_struct *user);
66923 +
66924 +int
66925 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
66926 +{
66927 + unsigned int i;
66928 + __u16 num;
66929 + uid_t *uidlist;
66930 + uid_t curuid;
66931 + int realok = 0;
66932 + int effectiveok = 0;
66933 + int fsok = 0;
66934 + uid_t globalreal, globaleffective, globalfs;
66935 +
66936 +#if defined(CONFIG_GRKERNSEC_KERN_LOCKOUT)
66937 + struct user_struct *user;
66938 +
66939 + if (!uid_valid(real))
66940 + goto skipit;
66941 +
66942 + /* find user based on global namespace */
66943 +
66944 + globalreal = GR_GLOBAL_UID(real);
66945 +
66946 + user = find_user(make_kuid(&init_user_ns, globalreal));
66947 + if (user == NULL)
66948 + goto skipit;
66949 +
66950 + if (gr_process_kernel_setuid_ban(user)) {
66951 + /* for find_user */
66952 + free_uid(user);
66953 + return 1;
66954 + }
66955 +
66956 + /* for find_user */
66957 + free_uid(user);
66958 +
66959 +skipit:
66960 +#endif
66961 +
66962 + if (unlikely(!(gr_status & GR_READY)))
66963 + return 0;
66964 +
66965 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
66966 + gr_log_learn_uid_change(real, effective, fs);
66967 +
66968 + num = current->acl->user_trans_num;
66969 + uidlist = current->acl->user_transitions;
66970 +
66971 + if (uidlist == NULL)
66972 + return 0;
66973 +
66974 + if (!uid_valid(real)) {
66975 + realok = 1;
66976 + globalreal = (uid_t)-1;
66977 + } else {
66978 + globalreal = GR_GLOBAL_UID(real);
66979 + }
66980 + if (!uid_valid(effective)) {
66981 + effectiveok = 1;
66982 + globaleffective = (uid_t)-1;
66983 + } else {
66984 + globaleffective = GR_GLOBAL_UID(effective);
66985 + }
66986 + if (!uid_valid(fs)) {
66987 + fsok = 1;
66988 + globalfs = (uid_t)-1;
66989 + } else {
66990 + globalfs = GR_GLOBAL_UID(fs);
66991 + }
66992 +
66993 + if (current->acl->user_trans_type & GR_ID_ALLOW) {
66994 + for (i = 0; i < num; i++) {
66995 + curuid = uidlist[i];
66996 + if (globalreal == curuid)
66997 + realok = 1;
66998 + if (globaleffective == curuid)
66999 + effectiveok = 1;
67000 + if (globalfs == curuid)
67001 + fsok = 1;
67002 + }
67003 + } else if (current->acl->user_trans_type & GR_ID_DENY) {
67004 + for (i = 0; i < num; i++) {
67005 + curuid = uidlist[i];
67006 + if (globalreal == curuid)
67007 + break;
67008 + if (globaleffective == curuid)
67009 + break;
67010 + if (globalfs == curuid)
67011 + break;
67012 + }
67013 + /* not in deny list */
67014 + if (i == num) {
67015 + realok = 1;
67016 + effectiveok = 1;
67017 + fsok = 1;
67018 + }
67019 + }
67020 +
67021 + if (realok && effectiveok && fsok)
67022 + return 0;
67023 + else {
67024 + gr_log_int(GR_DONT_AUDIT, GR_USRCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
67025 + return 1;
67026 + }
67027 +}
67028 +
67029 +int
67030 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
67031 +{
67032 + unsigned int i;
67033 + __u16 num;
67034 + gid_t *gidlist;
67035 + gid_t curgid;
67036 + int realok = 0;
67037 + int effectiveok = 0;
67038 + int fsok = 0;
67039 + gid_t globalreal, globaleffective, globalfs;
67040 +
67041 + if (unlikely(!(gr_status & GR_READY)))
67042 + return 0;
67043 +
67044 + if (current->acl->mode & (GR_LEARN | GR_INHERITLEARN))
67045 + gr_log_learn_gid_change(real, effective, fs);
67046 +
67047 + num = current->acl->group_trans_num;
67048 + gidlist = current->acl->group_transitions;
67049 +
67050 + if (gidlist == NULL)
67051 + return 0;
67052 +
67053 + if (!gid_valid(real)) {
67054 + realok = 1;
67055 + globalreal = (gid_t)-1;
67056 + } else {
67057 + globalreal = GR_GLOBAL_GID(real);
67058 + }
67059 + if (!gid_valid(effective)) {
67060 + effectiveok = 1;
67061 + globaleffective = (gid_t)-1;
67062 + } else {
67063 + globaleffective = GR_GLOBAL_GID(effective);
67064 + }
67065 + if (!gid_valid(fs)) {
67066 + fsok = 1;
67067 + globalfs = (gid_t)-1;
67068 + } else {
67069 + globalfs = GR_GLOBAL_GID(fs);
67070 + }
67071 +
67072 + if (current->acl->group_trans_type & GR_ID_ALLOW) {
67073 + for (i = 0; i < num; i++) {
67074 + curgid = gidlist[i];
67075 + if (globalreal == curgid)
67076 + realok = 1;
67077 + if (globaleffective == curgid)
67078 + effectiveok = 1;
67079 + if (globalfs == curgid)
67080 + fsok = 1;
67081 + }
67082 + } else if (current->acl->group_trans_type & GR_ID_DENY) {
67083 + for (i = 0; i < num; i++) {
67084 + curgid = gidlist[i];
67085 + if (globalreal == curgid)
67086 + break;
67087 + if (globaleffective == curgid)
67088 + break;
67089 + if (globalfs == curgid)
67090 + break;
67091 + }
67092 + /* not in deny list */
67093 + if (i == num) {
67094 + realok = 1;
67095 + effectiveok = 1;
67096 + fsok = 1;
67097 + }
67098 + }
67099 +
67100 + if (realok && effectiveok && fsok)
67101 + return 0;
67102 + else {
67103 + gr_log_int(GR_DONT_AUDIT, GR_GRPCHANGE_ACL_MSG, realok ? (effectiveok ? (fsok ? 0 : globalfs) : globaleffective) : globalreal);
67104 + return 1;
67105 + }
67106 +}
67107 +
67108 +extern int gr_acl_is_capable(const int cap);
67109 +
67110 +void
67111 +gr_set_role_label(struct task_struct *task, const kuid_t kuid, const kgid_t kgid)
67112 +{
67113 + struct acl_role_label *role = task->role;
67114 + struct acl_subject_label *subj = NULL;
67115 + struct acl_object_label *obj;
67116 + struct file *filp;
67117 + uid_t uid;
67118 + gid_t gid;
67119 +
67120 + if (unlikely(!(gr_status & GR_READY)))
67121 + return;
67122 +
67123 + uid = GR_GLOBAL_UID(kuid);
67124 + gid = GR_GLOBAL_GID(kgid);
67125 +
67126 + filp = task->exec_file;
67127 +
67128 + /* kernel process, we'll give them the kernel role */
67129 + if (unlikely(!filp)) {
67130 + task->role = running_polstate.kernel_role;
67131 + task->acl = running_polstate.kernel_role->root_label;
67132 + return;
67133 + } else if (!task->role || !(task->role->roletype & GR_ROLE_SPECIAL)) {
67134 + /* save the current ip at time of role lookup so that the proper
67135 + IP will be learned for role_allowed_ip */
67136 + task->signal->saved_ip = task->signal->curr_ip;
67137 + role = lookup_acl_role_label(task, uid, gid);
67138 + }
67139 +
67140 + /* don't change the role if we're not a privileged process */
67141 + if (role && task->role != role &&
67142 + (((role->roletype & GR_ROLE_USER) && !gr_acl_is_capable(CAP_SETUID)) ||
67143 + ((role->roletype & GR_ROLE_GROUP) && !gr_acl_is_capable(CAP_SETGID))))
67144 + return;
67145 +
67146 + /* perform subject lookup in possibly new role
67147 + we can use this result below in the case where role == task->role
67148 + */
67149 + subj = chk_subj_label(filp->f_path.dentry, filp->f_path.mnt, role);
67150 +
67151 + /* if we changed uid/gid, but result in the same role
67152 + and are using inheritance, don't lose the inherited subject
67153 + if current subject is other than what normal lookup
67154 + would result in, we arrived via inheritance, don't
67155 + lose subject
67156 + */
67157 + if (role != task->role || (!(task->acl->mode & GR_INHERITLEARN) &&
67158 + (subj == task->acl)))
67159 + task->acl = subj;
67160 +
67161 + /* leave task->inherited unaffected */
67162 +
67163 + task->role = role;
67164 +
67165 + task->is_writable = 0;
67166 +
67167 + /* ignore additional mmap checks for processes that are writable
67168 + by the default ACL */
67169 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67170 + if (unlikely(obj->mode & GR_WRITE))
67171 + task->is_writable = 1;
67172 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, task->role->root_label);
67173 + if (unlikely(obj->mode & GR_WRITE))
67174 + task->is_writable = 1;
67175 +
67176 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67177 + 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);
67178 +#endif
67179 +
67180 + gr_set_proc_res(task);
67181 +
67182 + return;
67183 +}
67184 +
67185 +int
67186 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
67187 + const int unsafe_flags)
67188 +{
67189 + struct task_struct *task = current;
67190 + struct acl_subject_label *newacl;
67191 + struct acl_object_label *obj;
67192 + __u32 retmode;
67193 +
67194 + if (unlikely(!(gr_status & GR_READY)))
67195 + return 0;
67196 +
67197 + newacl = chk_subj_label(dentry, mnt, task->role);
67198 +
67199 + /* special handling for if we did an strace -f -p <pid> from an admin role, where pid then
67200 + did an exec
67201 + */
67202 + rcu_read_lock();
67203 + read_lock(&tasklist_lock);
67204 + if (task->ptrace && task->parent && ((task->parent->role->roletype & GR_ROLE_GOD) ||
67205 + (task->parent->acl->mode & GR_POVERRIDE))) {
67206 + read_unlock(&tasklist_lock);
67207 + rcu_read_unlock();
67208 + goto skip_check;
67209 + }
67210 + read_unlock(&tasklist_lock);
67211 + rcu_read_unlock();
67212 +
67213 + if (unsafe_flags && !(task->acl->mode & GR_POVERRIDE) && (task->acl != newacl) &&
67214 + !(task->role->roletype & GR_ROLE_GOD) &&
67215 + !gr_search_file(dentry, GR_PTRACERD, mnt) &&
67216 + !(task->acl->mode & (GR_LEARN | GR_INHERITLEARN))) {
67217 + if (unsafe_flags & LSM_UNSAFE_SHARE)
67218 + gr_log_fs_generic(GR_DONT_AUDIT, GR_UNSAFESHARE_EXEC_ACL_MSG, dentry, mnt);
67219 + else
67220 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_EXEC_ACL_MSG, dentry, mnt);
67221 + return -EACCES;
67222 + }
67223 +
67224 +skip_check:
67225 +
67226 + obj = chk_obj_label(dentry, mnt, task->acl);
67227 + retmode = obj->mode & (GR_INHERIT | GR_AUDIT_INHERIT);
67228 +
67229 + if (!(task->acl->mode & GR_INHERITLEARN) &&
67230 + ((newacl->mode & GR_LEARN) || !(retmode & GR_INHERIT))) {
67231 + if (obj->nested)
67232 + task->acl = obj->nested;
67233 + else
67234 + task->acl = newacl;
67235 + task->inherited = 0;
67236 + } else {
67237 + task->inherited = 1;
67238 + if (retmode & GR_INHERIT && retmode & GR_AUDIT_INHERIT)
67239 + gr_log_str_fs(GR_DO_AUDIT, GR_INHERIT_ACL_MSG, task->acl->filename, dentry, mnt);
67240 + }
67241 +
67242 + task->is_writable = 0;
67243 +
67244 + /* ignore additional mmap checks for processes that are writable
67245 + by the default ACL */
67246 + obj = chk_obj_label(dentry, mnt, running_polstate.default_role->root_label);
67247 + if (unlikely(obj->mode & GR_WRITE))
67248 + task->is_writable = 1;
67249 + obj = chk_obj_label(dentry, mnt, task->role->root_label);
67250 + if (unlikely(obj->mode & GR_WRITE))
67251 + task->is_writable = 1;
67252 +
67253 + gr_set_proc_res(task);
67254 +
67255 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
67256 + 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);
67257 +#endif
67258 + return 0;
67259 +}
67260 +
67261 +/* always called with valid inodev ptr */
67262 +static void
67263 +do_handle_delete(struct inodev_entry *inodev, const ino_t ino, const dev_t dev)
67264 +{
67265 + struct acl_object_label *matchpo;
67266 + struct acl_subject_label *matchps;
67267 + struct acl_subject_label *subj;
67268 + struct acl_role_label *role;
67269 + unsigned int x;
67270 +
67271 + FOR_EACH_ROLE_START(role)
67272 + FOR_EACH_SUBJECT_START(role, subj, x)
67273 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
67274 + matchpo->mode |= GR_DELETED;
67275 + FOR_EACH_SUBJECT_END(subj,x)
67276 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
67277 + /* nested subjects aren't in the role's subj_hash table */
67278 + if ((matchpo = lookup_acl_obj_label(ino, dev, subj)) != NULL)
67279 + matchpo->mode |= GR_DELETED;
67280 + FOR_EACH_NESTED_SUBJECT_END(subj)
67281 + if ((matchps = lookup_acl_subj_label(ino, dev, role)) != NULL)
67282 + matchps->mode |= GR_DELETED;
67283 + FOR_EACH_ROLE_END(role)
67284 +
67285 + inodev->nentry->deleted = 1;
67286 +
67287 + return;
67288 +}
67289 +
67290 +void
67291 +gr_handle_delete(const ino_t ino, const dev_t dev)
67292 +{
67293 + struct inodev_entry *inodev;
67294 +
67295 + if (unlikely(!(gr_status & GR_READY)))
67296 + return;
67297 +
67298 + write_lock(&gr_inode_lock);
67299 + inodev = lookup_inodev_entry(ino, dev);
67300 + if (inodev != NULL)
67301 + do_handle_delete(inodev, ino, dev);
67302 + write_unlock(&gr_inode_lock);
67303 +
67304 + return;
67305 +}
67306 +
67307 +static void
67308 +update_acl_obj_label(const ino_t oldinode, const dev_t olddevice,
67309 + const ino_t newinode, const dev_t newdevice,
67310 + struct acl_subject_label *subj)
67311 +{
67312 + unsigned int index = gr_fhash(oldinode, olddevice, subj->obj_hash_size);
67313 + struct acl_object_label *match;
67314 +
67315 + match = subj->obj_hash[index];
67316 +
67317 + while (match && (match->inode != oldinode ||
67318 + match->device != olddevice ||
67319 + !(match->mode & GR_DELETED)))
67320 + match = match->next;
67321 +
67322 + if (match && (match->inode == oldinode)
67323 + && (match->device == olddevice)
67324 + && (match->mode & GR_DELETED)) {
67325 + if (match->prev == NULL) {
67326 + subj->obj_hash[index] = match->next;
67327 + if (match->next != NULL)
67328 + match->next->prev = NULL;
67329 + } else {
67330 + match->prev->next = match->next;
67331 + if (match->next != NULL)
67332 + match->next->prev = match->prev;
67333 + }
67334 + match->prev = NULL;
67335 + match->next = NULL;
67336 + match->inode = newinode;
67337 + match->device = newdevice;
67338 + match->mode &= ~GR_DELETED;
67339 +
67340 + insert_acl_obj_label(match, subj);
67341 + }
67342 +
67343 + return;
67344 +}
67345 +
67346 +static void
67347 +update_acl_subj_label(const ino_t oldinode, const dev_t olddevice,
67348 + const ino_t newinode, const dev_t newdevice,
67349 + struct acl_role_label *role)
67350 +{
67351 + unsigned int index = gr_fhash(oldinode, olddevice, role->subj_hash_size);
67352 + struct acl_subject_label *match;
67353 +
67354 + match = role->subj_hash[index];
67355 +
67356 + while (match && (match->inode != oldinode ||
67357 + match->device != olddevice ||
67358 + !(match->mode & GR_DELETED)))
67359 + match = match->next;
67360 +
67361 + if (match && (match->inode == oldinode)
67362 + && (match->device == olddevice)
67363 + && (match->mode & GR_DELETED)) {
67364 + if (match->prev == NULL) {
67365 + role->subj_hash[index] = match->next;
67366 + if (match->next != NULL)
67367 + match->next->prev = NULL;
67368 + } else {
67369 + match->prev->next = match->next;
67370 + if (match->next != NULL)
67371 + match->next->prev = match->prev;
67372 + }
67373 + match->prev = NULL;
67374 + match->next = NULL;
67375 + match->inode = newinode;
67376 + match->device = newdevice;
67377 + match->mode &= ~GR_DELETED;
67378 +
67379 + insert_acl_subj_label(match, role);
67380 + }
67381 +
67382 + return;
67383 +}
67384 +
67385 +static void
67386 +update_inodev_entry(const ino_t oldinode, const dev_t olddevice,
67387 + const ino_t newinode, const dev_t newdevice)
67388 +{
67389 + unsigned int index = gr_fhash(oldinode, olddevice, running_polstate.inodev_set.i_size);
67390 + struct inodev_entry *match;
67391 +
67392 + match = running_polstate.inodev_set.i_hash[index];
67393 +
67394 + while (match && (match->nentry->inode != oldinode ||
67395 + match->nentry->device != olddevice || !match->nentry->deleted))
67396 + match = match->next;
67397 +
67398 + if (match && (match->nentry->inode == oldinode)
67399 + && (match->nentry->device == olddevice) &&
67400 + match->nentry->deleted) {
67401 + if (match->prev == NULL) {
67402 + running_polstate.inodev_set.i_hash[index] = match->next;
67403 + if (match->next != NULL)
67404 + match->next->prev = NULL;
67405 + } else {
67406 + match->prev->next = match->next;
67407 + if (match->next != NULL)
67408 + match->next->prev = match->prev;
67409 + }
67410 + match->prev = NULL;
67411 + match->next = NULL;
67412 + match->nentry->inode = newinode;
67413 + match->nentry->device = newdevice;
67414 + match->nentry->deleted = 0;
67415 +
67416 + insert_inodev_entry(match);
67417 + }
67418 +
67419 + return;
67420 +}
67421 +
67422 +static void
67423 +__do_handle_create(const struct name_entry *matchn, ino_t ino, dev_t dev)
67424 +{
67425 + struct acl_subject_label *subj;
67426 + struct acl_role_label *role;
67427 + unsigned int x;
67428 +
67429 + FOR_EACH_ROLE_START(role)
67430 + update_acl_subj_label(matchn->inode, matchn->device, ino, dev, role);
67431 +
67432 + FOR_EACH_NESTED_SUBJECT_START(role, subj)
67433 + if ((subj->inode == ino) && (subj->device == dev)) {
67434 + subj->inode = ino;
67435 + subj->device = dev;
67436 + }
67437 + /* nested subjects aren't in the role's subj_hash table */
67438 + update_acl_obj_label(matchn->inode, matchn->device,
67439 + ino, dev, subj);
67440 + FOR_EACH_NESTED_SUBJECT_END(subj)
67441 + FOR_EACH_SUBJECT_START(role, subj, x)
67442 + update_acl_obj_label(matchn->inode, matchn->device,
67443 + ino, dev, subj);
67444 + FOR_EACH_SUBJECT_END(subj,x)
67445 + FOR_EACH_ROLE_END(role)
67446 +
67447 + update_inodev_entry(matchn->inode, matchn->device, ino, dev);
67448 +
67449 + return;
67450 +}
67451 +
67452 +static void
67453 +do_handle_create(const struct name_entry *matchn, const struct dentry *dentry,
67454 + const struct vfsmount *mnt)
67455 +{
67456 + ino_t ino = dentry->d_inode->i_ino;
67457 + dev_t dev = __get_dev(dentry);
67458 +
67459 + __do_handle_create(matchn, ino, dev);
67460 +
67461 + return;
67462 +}
67463 +
67464 +void
67465 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
67466 +{
67467 + struct name_entry *matchn;
67468 +
67469 + if (unlikely(!(gr_status & GR_READY)))
67470 + return;
67471 +
67472 + preempt_disable();
67473 + matchn = lookup_name_entry(gr_to_filename_rbac(dentry, mnt));
67474 +
67475 + if (unlikely((unsigned long)matchn)) {
67476 + write_lock(&gr_inode_lock);
67477 + do_handle_create(matchn, dentry, mnt);
67478 + write_unlock(&gr_inode_lock);
67479 + }
67480 + preempt_enable();
67481 +
67482 + return;
67483 +}
67484 +
67485 +void
67486 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
67487 +{
67488 + struct name_entry *matchn;
67489 +
67490 + if (unlikely(!(gr_status & GR_READY)))
67491 + return;
67492 +
67493 + preempt_disable();
67494 + matchn = lookup_name_entry(gr_to_proc_filename_rbac(dentry, init_pid_ns.proc_mnt));
67495 +
67496 + if (unlikely((unsigned long)matchn)) {
67497 + write_lock(&gr_inode_lock);
67498 + __do_handle_create(matchn, inode->i_ino, inode->i_sb->s_dev);
67499 + write_unlock(&gr_inode_lock);
67500 + }
67501 + preempt_enable();
67502 +
67503 + return;
67504 +}
67505 +
67506 +void
67507 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
67508 + struct dentry *old_dentry,
67509 + struct dentry *new_dentry,
67510 + struct vfsmount *mnt, const __u8 replace)
67511 +{
67512 + struct name_entry *matchn;
67513 + struct inodev_entry *inodev;
67514 + struct inode *inode = new_dentry->d_inode;
67515 + ino_t old_ino = old_dentry->d_inode->i_ino;
67516 + dev_t old_dev = __get_dev(old_dentry);
67517 +
67518 + /* vfs_rename swaps the name and parent link for old_dentry and
67519 + new_dentry
67520 + at this point, old_dentry has the new name, parent link, and inode
67521 + for the renamed file
67522 + if a file is being replaced by a rename, new_dentry has the inode
67523 + and name for the replaced file
67524 + */
67525 +
67526 + if (unlikely(!(gr_status & GR_READY)))
67527 + return;
67528 +
67529 + preempt_disable();
67530 + matchn = lookup_name_entry(gr_to_filename_rbac(old_dentry, mnt));
67531 +
67532 + /* we wouldn't have to check d_inode if it weren't for
67533 + NFS silly-renaming
67534 + */
67535 +
67536 + write_lock(&gr_inode_lock);
67537 + if (unlikely(replace && inode)) {
67538 + ino_t new_ino = inode->i_ino;
67539 + dev_t new_dev = __get_dev(new_dentry);
67540 +
67541 + inodev = lookup_inodev_entry(new_ino, new_dev);
67542 + if (inodev != NULL && ((inode->i_nlink <= 1) || S_ISDIR(inode->i_mode)))
67543 + do_handle_delete(inodev, new_ino, new_dev);
67544 + }
67545 +
67546 + inodev = lookup_inodev_entry(old_ino, old_dev);
67547 + if (inodev != NULL && ((old_dentry->d_inode->i_nlink <= 1) || S_ISDIR(old_dentry->d_inode->i_mode)))
67548 + do_handle_delete(inodev, old_ino, old_dev);
67549 +
67550 + if (unlikely((unsigned long)matchn))
67551 + do_handle_create(matchn, old_dentry, mnt);
67552 +
67553 + write_unlock(&gr_inode_lock);
67554 + preempt_enable();
67555 +
67556 + return;
67557 +}
67558 +
67559 +#if defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC)
67560 +static const unsigned long res_learn_bumps[GR_NLIMITS] = {
67561 + [RLIMIT_CPU] = GR_RLIM_CPU_BUMP,
67562 + [RLIMIT_FSIZE] = GR_RLIM_FSIZE_BUMP,
67563 + [RLIMIT_DATA] = GR_RLIM_DATA_BUMP,
67564 + [RLIMIT_STACK] = GR_RLIM_STACK_BUMP,
67565 + [RLIMIT_CORE] = GR_RLIM_CORE_BUMP,
67566 + [RLIMIT_RSS] = GR_RLIM_RSS_BUMP,
67567 + [RLIMIT_NPROC] = GR_RLIM_NPROC_BUMP,
67568 + [RLIMIT_NOFILE] = GR_RLIM_NOFILE_BUMP,
67569 + [RLIMIT_MEMLOCK] = GR_RLIM_MEMLOCK_BUMP,
67570 + [RLIMIT_AS] = GR_RLIM_AS_BUMP,
67571 + [RLIMIT_LOCKS] = GR_RLIM_LOCKS_BUMP,
67572 + [RLIMIT_SIGPENDING] = GR_RLIM_SIGPENDING_BUMP,
67573 + [RLIMIT_MSGQUEUE] = GR_RLIM_MSGQUEUE_BUMP,
67574 + [RLIMIT_NICE] = GR_RLIM_NICE_BUMP,
67575 + [RLIMIT_RTPRIO] = GR_RLIM_RTPRIO_BUMP,
67576 + [RLIMIT_RTTIME] = GR_RLIM_RTTIME_BUMP
67577 +};
67578 +
67579 +void
67580 +gr_learn_resource(const struct task_struct *task,
67581 + const int res, const unsigned long wanted, const int gt)
67582 +{
67583 + struct acl_subject_label *acl;
67584 + const struct cred *cred;
67585 +
67586 + if (unlikely((gr_status & GR_READY) &&
67587 + task->acl && (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))))
67588 + goto skip_reslog;
67589 +
67590 + gr_log_resource(task, res, wanted, gt);
67591 +skip_reslog:
67592 +
67593 + if (unlikely(!(gr_status & GR_READY) || !wanted || res >= GR_NLIMITS))
67594 + return;
67595 +
67596 + acl = task->acl;
67597 +
67598 + if (likely(!acl || !(acl->mode & (GR_LEARN | GR_INHERITLEARN)) ||
67599 + !(acl->resmask & (1U << (unsigned short) res))))
67600 + return;
67601 +
67602 + if (wanted >= acl->res[res].rlim_cur) {
67603 + unsigned long res_add;
67604 +
67605 + res_add = wanted + res_learn_bumps[res];
67606 +
67607 + acl->res[res].rlim_cur = res_add;
67608 +
67609 + if (wanted > acl->res[res].rlim_max)
67610 + acl->res[res].rlim_max = res_add;
67611 +
67612 + /* only log the subject filename, since resource logging is supported for
67613 + single-subject learning only */
67614 + rcu_read_lock();
67615 + cred = __task_cred(task);
67616 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
67617 + task->role->roletype, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid), acl->filename,
67618 + acl->filename, acl->res[res].rlim_cur, acl->res[res].rlim_max,
67619 + "", (unsigned long) res, &task->signal->saved_ip);
67620 + rcu_read_unlock();
67621 + }
67622 +
67623 + return;
67624 +}
67625 +EXPORT_SYMBOL_GPL(gr_learn_resource);
67626 +#endif
67627 +
67628 +#if defined(CONFIG_PAX_HAVE_ACL_FLAGS) && (defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR))
67629 +void
67630 +pax_set_initial_flags(struct linux_binprm *bprm)
67631 +{
67632 + struct task_struct *task = current;
67633 + struct acl_subject_label *proc;
67634 + unsigned long flags;
67635 +
67636 + if (unlikely(!(gr_status & GR_READY)))
67637 + return;
67638 +
67639 + flags = pax_get_flags(task);
67640 +
67641 + proc = task->acl;
67642 +
67643 + if (proc->pax_flags & GR_PAX_DISABLE_PAGEEXEC)
67644 + flags &= ~MF_PAX_PAGEEXEC;
67645 + if (proc->pax_flags & GR_PAX_DISABLE_SEGMEXEC)
67646 + flags &= ~MF_PAX_SEGMEXEC;
67647 + if (proc->pax_flags & GR_PAX_DISABLE_RANDMMAP)
67648 + flags &= ~MF_PAX_RANDMMAP;
67649 + if (proc->pax_flags & GR_PAX_DISABLE_EMUTRAMP)
67650 + flags &= ~MF_PAX_EMUTRAMP;
67651 + if (proc->pax_flags & GR_PAX_DISABLE_MPROTECT)
67652 + flags &= ~MF_PAX_MPROTECT;
67653 +
67654 + if (proc->pax_flags & GR_PAX_ENABLE_PAGEEXEC)
67655 + flags |= MF_PAX_PAGEEXEC;
67656 + if (proc->pax_flags & GR_PAX_ENABLE_SEGMEXEC)
67657 + flags |= MF_PAX_SEGMEXEC;
67658 + if (proc->pax_flags & GR_PAX_ENABLE_RANDMMAP)
67659 + flags |= MF_PAX_RANDMMAP;
67660 + if (proc->pax_flags & GR_PAX_ENABLE_EMUTRAMP)
67661 + flags |= MF_PAX_EMUTRAMP;
67662 + if (proc->pax_flags & GR_PAX_ENABLE_MPROTECT)
67663 + flags |= MF_PAX_MPROTECT;
67664 +
67665 + pax_set_flags(task, flags);
67666 +
67667 + return;
67668 +}
67669 +#endif
67670 +
67671 +int
67672 +gr_handle_proc_ptrace(struct task_struct *task)
67673 +{
67674 + struct file *filp;
67675 + struct task_struct *tmp = task;
67676 + struct task_struct *curtemp = current;
67677 + __u32 retmode;
67678 +
67679 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
67680 + if (unlikely(!(gr_status & GR_READY)))
67681 + return 0;
67682 +#endif
67683 +
67684 + read_lock(&tasklist_lock);
67685 + read_lock(&grsec_exec_file_lock);
67686 + filp = task->exec_file;
67687 +
67688 + while (task_pid_nr(tmp) > 0) {
67689 + if (tmp == curtemp)
67690 + break;
67691 + tmp = tmp->real_parent;
67692 + }
67693 +
67694 + if (!filp || (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
67695 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE))))) {
67696 + read_unlock(&grsec_exec_file_lock);
67697 + read_unlock(&tasklist_lock);
67698 + return 1;
67699 + }
67700 +
67701 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
67702 + if (!(gr_status & GR_READY)) {
67703 + read_unlock(&grsec_exec_file_lock);
67704 + read_unlock(&tasklist_lock);
67705 + return 0;
67706 + }
67707 +#endif
67708 +
67709 + retmode = gr_search_file(filp->f_path.dentry, GR_NOPTRACE, filp->f_path.mnt);
67710 + read_unlock(&grsec_exec_file_lock);
67711 + read_unlock(&tasklist_lock);
67712 +
67713 + if (retmode & GR_NOPTRACE)
67714 + return 1;
67715 +
67716 + if (!(current->acl->mode & GR_POVERRIDE) && !(current->role->roletype & GR_ROLE_GOD)
67717 + && (current->acl != task->acl || (current->acl != current->role->root_label
67718 + && task_pid_nr(current) != task_pid_nr(task))))
67719 + return 1;
67720 +
67721 + return 0;
67722 +}
67723 +
67724 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p)
67725 +{
67726 + if (unlikely(!(gr_status & GR_READY)))
67727 + return;
67728 +
67729 + if (!(current->role->roletype & GR_ROLE_GOD))
67730 + return;
67731 +
67732 + seq_printf(m, "RBAC:\t%.64s:%c:%.950s\n",
67733 + p->role->rolename, gr_task_roletype_to_char(p),
67734 + p->acl->filename);
67735 +}
67736 +
67737 +int
67738 +gr_handle_ptrace(struct task_struct *task, const long request)
67739 +{
67740 + struct task_struct *tmp = task;
67741 + struct task_struct *curtemp = current;
67742 + __u32 retmode;
67743 +
67744 +#ifndef CONFIG_GRKERNSEC_HARDEN_PTRACE
67745 + if (unlikely(!(gr_status & GR_READY)))
67746 + return 0;
67747 +#endif
67748 + if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
67749 + read_lock(&tasklist_lock);
67750 + while (task_pid_nr(tmp) > 0) {
67751 + if (tmp == curtemp)
67752 + break;
67753 + tmp = tmp->real_parent;
67754 + }
67755 +
67756 + if (task_pid_nr(tmp) == 0 && ((grsec_enable_harden_ptrace && gr_is_global_nonroot(current_uid()) && !(gr_status & GR_READY)) ||
67757 + ((gr_status & GR_READY) && !(current->acl->mode & GR_RELAXPTRACE)))) {
67758 + read_unlock(&tasklist_lock);
67759 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67760 + return 1;
67761 + }
67762 + read_unlock(&tasklist_lock);
67763 + }
67764 +
67765 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
67766 + if (!(gr_status & GR_READY))
67767 + return 0;
67768 +#endif
67769 +
67770 + read_lock(&grsec_exec_file_lock);
67771 + if (unlikely(!task->exec_file)) {
67772 + read_unlock(&grsec_exec_file_lock);
67773 + return 0;
67774 + }
67775 +
67776 + retmode = gr_search_file(task->exec_file->f_path.dentry, GR_PTRACERD | GR_NOPTRACE, task->exec_file->f_path.mnt);
67777 + read_unlock(&grsec_exec_file_lock);
67778 +
67779 + if (retmode & GR_NOPTRACE) {
67780 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67781 + return 1;
67782 + }
67783 +
67784 + if (retmode & GR_PTRACERD) {
67785 + switch (request) {
67786 + case PTRACE_SEIZE:
67787 + case PTRACE_POKETEXT:
67788 + case PTRACE_POKEDATA:
67789 + case PTRACE_POKEUSR:
67790 +#if !defined(CONFIG_PPC32) && !defined(CONFIG_PPC64) && !defined(CONFIG_PARISC) && !defined(CONFIG_ALPHA) && !defined(CONFIG_IA64)
67791 + case PTRACE_SETREGS:
67792 + case PTRACE_SETFPREGS:
67793 +#endif
67794 +#ifdef CONFIG_X86
67795 + case PTRACE_SETFPXREGS:
67796 +#endif
67797 +#ifdef CONFIG_ALTIVEC
67798 + case PTRACE_SETVRREGS:
67799 +#endif
67800 + return 1;
67801 + default:
67802 + return 0;
67803 + }
67804 + } else if (!(current->acl->mode & GR_POVERRIDE) &&
67805 + !(current->role->roletype & GR_ROLE_GOD) &&
67806 + (current->acl != task->acl)) {
67807 + gr_log_ptrace(GR_DONT_AUDIT, GR_PTRACE_ACL_MSG, task);
67808 + return 1;
67809 + }
67810 +
67811 + return 0;
67812 +}
67813 +
67814 +static int is_writable_mmap(const struct file *filp)
67815 +{
67816 + struct task_struct *task = current;
67817 + struct acl_object_label *obj, *obj2;
67818 +
67819 + if (gr_status & GR_READY && !(task->acl->mode & GR_OVERRIDE) &&
67820 + !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))) {
67821 + obj = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt, running_polstate.default_role->root_label);
67822 + obj2 = chk_obj_label(filp->f_path.dentry, filp->f_path.mnt,
67823 + task->role->root_label);
67824 + if (unlikely((obj->mode & GR_WRITE) || (obj2->mode & GR_WRITE))) {
67825 + gr_log_fs_generic(GR_DONT_AUDIT, GR_WRITLIB_ACL_MSG, filp->f_path.dentry, filp->f_path.mnt);
67826 + return 1;
67827 + }
67828 + }
67829 + return 0;
67830 +}
67831 +
67832 +int
67833 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot)
67834 +{
67835 + __u32 mode;
67836 +
67837 + if (unlikely(!file || !(prot & PROT_EXEC)))
67838 + return 1;
67839 +
67840 + if (is_writable_mmap(file))
67841 + return 0;
67842 +
67843 + mode =
67844 + gr_search_file(file->f_path.dentry,
67845 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
67846 + file->f_path.mnt);
67847 +
67848 + if (!gr_tpe_allow(file))
67849 + return 0;
67850 +
67851 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
67852 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67853 + return 0;
67854 + } else if (unlikely(!(mode & GR_EXEC))) {
67855 + return 0;
67856 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
67857 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MMAP_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67858 + return 1;
67859 + }
67860 +
67861 + return 1;
67862 +}
67863 +
67864 +int
67865 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
67866 +{
67867 + __u32 mode;
67868 +
67869 + if (unlikely(!file || !(prot & PROT_EXEC)))
67870 + return 1;
67871 +
67872 + if (is_writable_mmap(file))
67873 + return 0;
67874 +
67875 + mode =
67876 + gr_search_file(file->f_path.dentry,
67877 + GR_EXEC | GR_AUDIT_EXEC | GR_SUPPRESS,
67878 + file->f_path.mnt);
67879 +
67880 + if (!gr_tpe_allow(file))
67881 + return 0;
67882 +
67883 + if (unlikely(!(mode & GR_EXEC) && !(mode & GR_SUPPRESS))) {
67884 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67885 + return 0;
67886 + } else if (unlikely(!(mode & GR_EXEC))) {
67887 + return 0;
67888 + } else if (unlikely(mode & GR_EXEC && mode & GR_AUDIT_EXEC)) {
67889 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_MPROTECT_ACL_MSG, file->f_path.dentry, file->f_path.mnt);
67890 + return 1;
67891 + }
67892 +
67893 + return 1;
67894 +}
67895 +
67896 +void
67897 +gr_acl_handle_psacct(struct task_struct *task, const long code)
67898 +{
67899 + unsigned long runtime, cputime;
67900 + cputime_t utime, stime;
67901 + unsigned int wday, cday;
67902 + __u8 whr, chr;
67903 + __u8 wmin, cmin;
67904 + __u8 wsec, csec;
67905 + struct timespec timeval;
67906 +
67907 + if (unlikely(!(gr_status & GR_READY) || !task->acl ||
67908 + !(task->acl->mode & GR_PROCACCT)))
67909 + return;
67910 +
67911 + do_posix_clock_monotonic_gettime(&timeval);
67912 + runtime = timeval.tv_sec - task->start_time.tv_sec;
67913 + wday = runtime / (60 * 60 * 24);
67914 + runtime -= wday * (60 * 60 * 24);
67915 + whr = runtime / (60 * 60);
67916 + runtime -= whr * (60 * 60);
67917 + wmin = runtime / 60;
67918 + runtime -= wmin * 60;
67919 + wsec = runtime;
67920 +
67921 + task_cputime(task, &utime, &stime);
67922 + cputime = cputime_to_secs(utime + stime);
67923 + cday = cputime / (60 * 60 * 24);
67924 + cputime -= cday * (60 * 60 * 24);
67925 + chr = cputime / (60 * 60);
67926 + cputime -= chr * (60 * 60);
67927 + cmin = cputime / 60;
67928 + cputime -= cmin * 60;
67929 + csec = cputime;
67930 +
67931 + gr_log_procacct(GR_DO_AUDIT, GR_ACL_PROCACCT_MSG, task, wday, whr, wmin, wsec, cday, chr, cmin, csec, code);
67932 +
67933 + return;
67934 +}
67935 +
67936 +#ifdef CONFIG_TASKSTATS
67937 +int gr_is_taskstats_denied(int pid)
67938 +{
67939 + struct task_struct *task;
67940 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67941 + const struct cred *cred;
67942 +#endif
67943 + int ret = 0;
67944 +
67945 + /* restrict taskstats viewing to un-chrooted root users
67946 + who have the 'view' subject flag if the RBAC system is enabled
67947 + */
67948 +
67949 + rcu_read_lock();
67950 + read_lock(&tasklist_lock);
67951 + task = find_task_by_vpid(pid);
67952 + if (task) {
67953 +#ifdef CONFIG_GRKERNSEC_CHROOT
67954 + if (proc_is_chrooted(task))
67955 + ret = -EACCES;
67956 +#endif
67957 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67958 + cred = __task_cred(task);
67959 +#ifdef CONFIG_GRKERNSEC_PROC_USER
67960 + if (gr_is_global_nonroot(cred->uid))
67961 + ret = -EACCES;
67962 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
67963 + if (gr_is_global_nonroot(cred->uid) && !groups_search(cred->group_info, grsec_proc_gid))
67964 + ret = -EACCES;
67965 +#endif
67966 +#endif
67967 + if (gr_status & GR_READY) {
67968 + if (!(task->acl->mode & GR_VIEW))
67969 + ret = -EACCES;
67970 + }
67971 + } else
67972 + ret = -ENOENT;
67973 +
67974 + read_unlock(&tasklist_lock);
67975 + rcu_read_unlock();
67976 +
67977 + return ret;
67978 +}
67979 +#endif
67980 +
67981 +/* AUXV entries are filled via a descendant of search_binary_handler
67982 + after we've already applied the subject for the target
67983 +*/
67984 +int gr_acl_enable_at_secure(void)
67985 +{
67986 + if (unlikely(!(gr_status & GR_READY)))
67987 + return 0;
67988 +
67989 + if (current->acl->mode & GR_ATSECURE)
67990 + return 1;
67991 +
67992 + return 0;
67993 +}
67994 +
67995 +int gr_acl_handle_filldir(const struct file *file, const char *name, const unsigned int namelen, const ino_t ino)
67996 +{
67997 + struct task_struct *task = current;
67998 + struct dentry *dentry = file->f_path.dentry;
67999 + struct vfsmount *mnt = file->f_path.mnt;
68000 + struct acl_object_label *obj, *tmp;
68001 + struct acl_subject_label *subj;
68002 + unsigned int bufsize;
68003 + int is_not_root;
68004 + char *path;
68005 + dev_t dev = __get_dev(dentry);
68006 +
68007 + if (unlikely(!(gr_status & GR_READY)))
68008 + return 1;
68009 +
68010 + if (task->acl->mode & (GR_LEARN | GR_INHERITLEARN))
68011 + return 1;
68012 +
68013 + /* ignore Eric Biederman */
68014 + if (IS_PRIVATE(dentry->d_inode))
68015 + return 1;
68016 +
68017 + subj = task->acl;
68018 + read_lock(&gr_inode_lock);
68019 + do {
68020 + obj = lookup_acl_obj_label(ino, dev, subj);
68021 + if (obj != NULL) {
68022 + read_unlock(&gr_inode_lock);
68023 + return (obj->mode & GR_FIND) ? 1 : 0;
68024 + }
68025 + } while ((subj = subj->parent_subject));
68026 + read_unlock(&gr_inode_lock);
68027 +
68028 + /* this is purely an optimization since we're looking for an object
68029 + for the directory we're doing a readdir on
68030 + if it's possible for any globbed object to match the entry we're
68031 + filling into the directory, then the object we find here will be
68032 + an anchor point with attached globbed objects
68033 + */
68034 + obj = chk_obj_label_noglob(dentry, mnt, task->acl);
68035 + if (obj->globbed == NULL)
68036 + return (obj->mode & GR_FIND) ? 1 : 0;
68037 +
68038 + is_not_root = ((obj->filename[0] == '/') &&
68039 + (obj->filename[1] == '\0')) ? 0 : 1;
68040 + bufsize = PAGE_SIZE - namelen - is_not_root;
68041 +
68042 + /* check bufsize > PAGE_SIZE || bufsize == 0 */
68043 + if (unlikely((bufsize - 1) > (PAGE_SIZE - 1)))
68044 + return 1;
68045 +
68046 + preempt_disable();
68047 + path = d_real_path(dentry, mnt, per_cpu_ptr(gr_shared_page[0], smp_processor_id()),
68048 + bufsize);
68049 +
68050 + bufsize = strlen(path);
68051 +
68052 + /* if base is "/", don't append an additional slash */
68053 + if (is_not_root)
68054 + *(path + bufsize) = '/';
68055 + memcpy(path + bufsize + is_not_root, name, namelen);
68056 + *(path + bufsize + namelen + is_not_root) = '\0';
68057 +
68058 + tmp = obj->globbed;
68059 + while (tmp) {
68060 + if (!glob_match(tmp->filename, path)) {
68061 + preempt_enable();
68062 + return (tmp->mode & GR_FIND) ? 1 : 0;
68063 + }
68064 + tmp = tmp->next;
68065 + }
68066 + preempt_enable();
68067 + return (obj->mode & GR_FIND) ? 1 : 0;
68068 +}
68069 +
68070 +void gr_put_exec_file(struct task_struct *task)
68071 +{
68072 + struct file *filp;
68073 +
68074 + write_lock(&grsec_exec_file_lock);
68075 + filp = task->exec_file;
68076 + task->exec_file = NULL;
68077 + write_unlock(&grsec_exec_file_lock);
68078 +
68079 + if (filp)
68080 + fput(filp);
68081 +
68082 + return;
68083 +}
68084 +
68085 +
68086 +#ifdef CONFIG_NETFILTER_XT_MATCH_GRADM_MODULE
68087 +EXPORT_SYMBOL_GPL(gr_acl_is_enabled);
68088 +#endif
68089 +#ifdef CONFIG_SECURITY
68090 +EXPORT_SYMBOL_GPL(gr_check_user_change);
68091 +EXPORT_SYMBOL_GPL(gr_check_group_change);
68092 +#endif
68093 +
68094 diff --git a/grsecurity/gracl_alloc.c b/grsecurity/gracl_alloc.c
68095 new file mode 100644
68096 index 0000000..18ffbbd
68097 --- /dev/null
68098 +++ b/grsecurity/gracl_alloc.c
68099 @@ -0,0 +1,105 @@
68100 +#include <linux/kernel.h>
68101 +#include <linux/mm.h>
68102 +#include <linux/slab.h>
68103 +#include <linux/vmalloc.h>
68104 +#include <linux/gracl.h>
68105 +#include <linux/grsecurity.h>
68106 +
68107 +static struct gr_alloc_state __current_alloc_state = { 1, 1, NULL };
68108 +struct gr_alloc_state *current_alloc_state = &__current_alloc_state;
68109 +
68110 +static __inline__ int
68111 +alloc_pop(void)
68112 +{
68113 + if (current_alloc_state->alloc_stack_next == 1)
68114 + return 0;
68115 +
68116 + kfree(current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 2]);
68117 +
68118 + current_alloc_state->alloc_stack_next--;
68119 +
68120 + return 1;
68121 +}
68122 +
68123 +static __inline__ int
68124 +alloc_push(void *buf)
68125 +{
68126 + if (current_alloc_state->alloc_stack_next >= current_alloc_state->alloc_stack_size)
68127 + return 1;
68128 +
68129 + current_alloc_state->alloc_stack[current_alloc_state->alloc_stack_next - 1] = buf;
68130 +
68131 + current_alloc_state->alloc_stack_next++;
68132 +
68133 + return 0;
68134 +}
68135 +
68136 +void *
68137 +acl_alloc(unsigned long len)
68138 +{
68139 + void *ret = NULL;
68140 +
68141 + if (!len || len > PAGE_SIZE)
68142 + goto out;
68143 +
68144 + ret = kmalloc(len, GFP_KERNEL);
68145 +
68146 + if (ret) {
68147 + if (alloc_push(ret)) {
68148 + kfree(ret);
68149 + ret = NULL;
68150 + }
68151 + }
68152 +
68153 +out:
68154 + return ret;
68155 +}
68156 +
68157 +void *
68158 +acl_alloc_num(unsigned long num, unsigned long len)
68159 +{
68160 + if (!len || (num > (PAGE_SIZE / len)))
68161 + return NULL;
68162 +
68163 + return acl_alloc(num * len);
68164 +}
68165 +
68166 +void
68167 +acl_free_all(void)
68168 +{
68169 + if (!current_alloc_state->alloc_stack)
68170 + return;
68171 +
68172 + while (alloc_pop()) ;
68173 +
68174 + if (current_alloc_state->alloc_stack) {
68175 + if ((current_alloc_state->alloc_stack_size * sizeof (void *)) <= PAGE_SIZE)
68176 + kfree(current_alloc_state->alloc_stack);
68177 + else
68178 + vfree(current_alloc_state->alloc_stack);
68179 + }
68180 +
68181 + current_alloc_state->alloc_stack = NULL;
68182 + current_alloc_state->alloc_stack_size = 1;
68183 + current_alloc_state->alloc_stack_next = 1;
68184 +
68185 + return;
68186 +}
68187 +
68188 +int
68189 +acl_alloc_stack_init(unsigned long size)
68190 +{
68191 + if ((size * sizeof (void *)) <= PAGE_SIZE)
68192 + current_alloc_state->alloc_stack =
68193 + (void **) kmalloc(size * sizeof (void *), GFP_KERNEL);
68194 + else
68195 + current_alloc_state->alloc_stack = (void **) vmalloc(size * sizeof (void *));
68196 +
68197 + current_alloc_state->alloc_stack_size = size;
68198 + current_alloc_state->alloc_stack_next = 1;
68199 +
68200 + if (!current_alloc_state->alloc_stack)
68201 + return 0;
68202 + else
68203 + return 1;
68204 +}
68205 diff --git a/grsecurity/gracl_cap.c b/grsecurity/gracl_cap.c
68206 new file mode 100644
68207 index 0000000..bdd51ea
68208 --- /dev/null
68209 +++ b/grsecurity/gracl_cap.c
68210 @@ -0,0 +1,110 @@
68211 +#include <linux/kernel.h>
68212 +#include <linux/module.h>
68213 +#include <linux/sched.h>
68214 +#include <linux/gracl.h>
68215 +#include <linux/grsecurity.h>
68216 +#include <linux/grinternal.h>
68217 +
68218 +extern const char *captab_log[];
68219 +extern int captab_log_entries;
68220 +
68221 +int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
68222 +{
68223 + struct acl_subject_label *curracl;
68224 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
68225 + kernel_cap_t cap_audit = __cap_empty_set;
68226 +
68227 + if (!gr_acl_is_enabled())
68228 + return 1;
68229 +
68230 + curracl = task->acl;
68231 +
68232 + cap_drop = curracl->cap_lower;
68233 + cap_mask = curracl->cap_mask;
68234 + cap_audit = curracl->cap_invert_audit;
68235 +
68236 + while ((curracl = curracl->parent_subject)) {
68237 + /* if the cap isn't specified in the current computed mask but is specified in the
68238 + current level subject, and is lowered in the current level subject, then add
68239 + it to the set of dropped capabilities
68240 + otherwise, add the current level subject's mask to the current computed mask
68241 + */
68242 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
68243 + cap_raise(cap_mask, cap);
68244 + if (cap_raised(curracl->cap_lower, cap))
68245 + cap_raise(cap_drop, cap);
68246 + if (cap_raised(curracl->cap_invert_audit, cap))
68247 + cap_raise(cap_audit, cap);
68248 + }
68249 + }
68250 +
68251 + if (!cap_raised(cap_drop, cap)) {
68252 + if (cap_raised(cap_audit, cap))
68253 + gr_log_cap(GR_DO_AUDIT, GR_CAP_ACL_MSG2, task, captab_log[cap]);
68254 + return 1;
68255 + }
68256 +
68257 + curracl = task->acl;
68258 +
68259 + if ((curracl->mode & (GR_LEARN | GR_INHERITLEARN))
68260 + && cap_raised(cred->cap_effective, cap)) {
68261 + security_learn(GR_LEARN_AUDIT_MSG, task->role->rolename,
68262 + task->role->roletype, GR_GLOBAL_UID(cred->uid),
68263 + GR_GLOBAL_GID(cred->gid), task->exec_file ?
68264 + gr_to_filename(task->exec_file->f_path.dentry,
68265 + task->exec_file->f_path.mnt) : curracl->filename,
68266 + curracl->filename, 0UL,
68267 + 0UL, "", (unsigned long) cap, &task->signal->saved_ip);
68268 + return 1;
68269 + }
68270 +
68271 + if ((cap >= 0) && (cap < captab_log_entries) && cap_raised(cred->cap_effective, cap) && !cap_raised(cap_audit, cap))
68272 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_ACL_MSG, task, captab_log[cap]);
68273 +
68274 + return 0;
68275 +}
68276 +
68277 +int
68278 +gr_acl_is_capable(const int cap)
68279 +{
68280 + return gr_task_acl_is_capable(current, current_cred(), cap);
68281 +}
68282 +
68283 +int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap)
68284 +{
68285 + struct acl_subject_label *curracl;
68286 + kernel_cap_t cap_drop = __cap_empty_set, cap_mask = __cap_empty_set;
68287 +
68288 + if (!gr_acl_is_enabled())
68289 + return 1;
68290 +
68291 + curracl = task->acl;
68292 +
68293 + cap_drop = curracl->cap_lower;
68294 + cap_mask = curracl->cap_mask;
68295 +
68296 + while ((curracl = curracl->parent_subject)) {
68297 + /* if the cap isn't specified in the current computed mask but is specified in the
68298 + current level subject, and is lowered in the current level subject, then add
68299 + it to the set of dropped capabilities
68300 + otherwise, add the current level subject's mask to the current computed mask
68301 + */
68302 + if (!cap_raised(cap_mask, cap) && cap_raised(curracl->cap_mask, cap)) {
68303 + cap_raise(cap_mask, cap);
68304 + if (cap_raised(curracl->cap_lower, cap))
68305 + cap_raise(cap_drop, cap);
68306 + }
68307 + }
68308 +
68309 + if (!cap_raised(cap_drop, cap))
68310 + return 1;
68311 +
68312 + return 0;
68313 +}
68314 +
68315 +int
68316 +gr_acl_is_capable_nolog(const int cap)
68317 +{
68318 + return gr_task_acl_is_capable_nolog(current, cap);
68319 +}
68320 +
68321 diff --git a/grsecurity/gracl_compat.c b/grsecurity/gracl_compat.c
68322 new file mode 100644
68323 index 0000000..ca25605
68324 --- /dev/null
68325 +++ b/grsecurity/gracl_compat.c
68326 @@ -0,0 +1,270 @@
68327 +#include <linux/kernel.h>
68328 +#include <linux/gracl.h>
68329 +#include <linux/compat.h>
68330 +#include <linux/gracl_compat.h>
68331 +
68332 +#include <asm/uaccess.h>
68333 +
68334 +int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap)
68335 +{
68336 + struct gr_arg_wrapper_compat uwrapcompat;
68337 +
68338 + if (copy_from_user(&uwrapcompat, buf, sizeof(uwrapcompat)))
68339 + return -EFAULT;
68340 +
68341 + if (((uwrapcompat.version != GRSECURITY_VERSION) &&
68342 + (uwrapcompat.version != 0x2901)) ||
68343 + (uwrapcompat.size != sizeof(struct gr_arg_compat)))
68344 + return -EINVAL;
68345 +
68346 + uwrap->arg = compat_ptr(uwrapcompat.arg);
68347 + uwrap->version = uwrapcompat.version;
68348 + uwrap->size = sizeof(struct gr_arg);
68349 +
68350 + return 0;
68351 +}
68352 +
68353 +int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg)
68354 +{
68355 + struct gr_arg_compat argcompat;
68356 +
68357 + if (copy_from_user(&argcompat, buf, sizeof(argcompat)))
68358 + return -EFAULT;
68359 +
68360 + arg->role_db.r_table = compat_ptr(argcompat.role_db.r_table);
68361 + arg->role_db.num_pointers = argcompat.role_db.num_pointers;
68362 + arg->role_db.num_roles = argcompat.role_db.num_roles;
68363 + arg->role_db.num_domain_children = argcompat.role_db.num_domain_children;
68364 + arg->role_db.num_subjects = argcompat.role_db.num_subjects;
68365 + arg->role_db.num_objects = argcompat.role_db.num_objects;
68366 +
68367 + memcpy(&arg->pw, &argcompat.pw, sizeof(arg->pw));
68368 + memcpy(&arg->salt, &argcompat.salt, sizeof(arg->salt));
68369 + memcpy(&arg->sum, &argcompat.sum, sizeof(arg->sum));
68370 + memcpy(&arg->sp_role, &argcompat.sp_role, sizeof(arg->sp_role));
68371 + arg->sprole_pws = compat_ptr(argcompat.sprole_pws);
68372 + arg->segv_device = argcompat.segv_device;
68373 + arg->segv_inode = argcompat.segv_inode;
68374 + arg->segv_uid = argcompat.segv_uid;
68375 + arg->num_sprole_pws = argcompat.num_sprole_pws;
68376 + arg->mode = argcompat.mode;
68377 +
68378 + return 0;
68379 +}
68380 +
68381 +int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp)
68382 +{
68383 + struct acl_object_label_compat objcompat;
68384 +
68385 + if (copy_from_user(&objcompat, userp, sizeof(objcompat)))
68386 + return -EFAULT;
68387 +
68388 + obj->filename = compat_ptr(objcompat.filename);
68389 + obj->inode = objcompat.inode;
68390 + obj->device = objcompat.device;
68391 + obj->mode = objcompat.mode;
68392 +
68393 + obj->nested = compat_ptr(objcompat.nested);
68394 + obj->globbed = compat_ptr(objcompat.globbed);
68395 +
68396 + obj->prev = compat_ptr(objcompat.prev);
68397 + obj->next = compat_ptr(objcompat.next);
68398 +
68399 + return 0;
68400 +}
68401 +
68402 +int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp)
68403 +{
68404 + unsigned int i;
68405 + struct acl_subject_label_compat subjcompat;
68406 +
68407 + if (copy_from_user(&subjcompat, userp, sizeof(subjcompat)))
68408 + return -EFAULT;
68409 +
68410 + subj->filename = compat_ptr(subjcompat.filename);
68411 + subj->inode = subjcompat.inode;
68412 + subj->device = subjcompat.device;
68413 + subj->mode = subjcompat.mode;
68414 + subj->cap_mask = subjcompat.cap_mask;
68415 + subj->cap_lower = subjcompat.cap_lower;
68416 + subj->cap_invert_audit = subjcompat.cap_invert_audit;
68417 +
68418 + for (i = 0; i < GR_NLIMITS; i++) {
68419 + if (subjcompat.res[i].rlim_cur == COMPAT_RLIM_INFINITY)
68420 + subj->res[i].rlim_cur = RLIM_INFINITY;
68421 + else
68422 + subj->res[i].rlim_cur = subjcompat.res[i].rlim_cur;
68423 + if (subjcompat.res[i].rlim_max == COMPAT_RLIM_INFINITY)
68424 + subj->res[i].rlim_max = RLIM_INFINITY;
68425 + else
68426 + subj->res[i].rlim_max = subjcompat.res[i].rlim_max;
68427 + }
68428 + subj->resmask = subjcompat.resmask;
68429 +
68430 + subj->user_trans_type = subjcompat.user_trans_type;
68431 + subj->group_trans_type = subjcompat.group_trans_type;
68432 + subj->user_transitions = compat_ptr(subjcompat.user_transitions);
68433 + subj->group_transitions = compat_ptr(subjcompat.group_transitions);
68434 + subj->user_trans_num = subjcompat.user_trans_num;
68435 + subj->group_trans_num = subjcompat.group_trans_num;
68436 +
68437 + memcpy(&subj->sock_families, &subjcompat.sock_families, sizeof(subj->sock_families));
68438 + memcpy(&subj->ip_proto, &subjcompat.ip_proto, sizeof(subj->ip_proto));
68439 + subj->ip_type = subjcompat.ip_type;
68440 + subj->ips = compat_ptr(subjcompat.ips);
68441 + subj->ip_num = subjcompat.ip_num;
68442 + subj->inaddr_any_override = subjcompat.inaddr_any_override;
68443 +
68444 + subj->crashes = subjcompat.crashes;
68445 + subj->expires = subjcompat.expires;
68446 +
68447 + subj->parent_subject = compat_ptr(subjcompat.parent_subject);
68448 + subj->hash = compat_ptr(subjcompat.hash);
68449 + subj->prev = compat_ptr(subjcompat.prev);
68450 + subj->next = compat_ptr(subjcompat.next);
68451 +
68452 + subj->obj_hash = compat_ptr(subjcompat.obj_hash);
68453 + subj->obj_hash_size = subjcompat.obj_hash_size;
68454 + subj->pax_flags = subjcompat.pax_flags;
68455 +
68456 + return 0;
68457 +}
68458 +
68459 +int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp)
68460 +{
68461 + struct acl_role_label_compat rolecompat;
68462 +
68463 + if (copy_from_user(&rolecompat, userp, sizeof(rolecompat)))
68464 + return -EFAULT;
68465 +
68466 + role->rolename = compat_ptr(rolecompat.rolename);
68467 + role->uidgid = rolecompat.uidgid;
68468 + role->roletype = rolecompat.roletype;
68469 +
68470 + role->auth_attempts = rolecompat.auth_attempts;
68471 + role->expires = rolecompat.expires;
68472 +
68473 + role->root_label = compat_ptr(rolecompat.root_label);
68474 + role->hash = compat_ptr(rolecompat.hash);
68475 +
68476 + role->prev = compat_ptr(rolecompat.prev);
68477 + role->next = compat_ptr(rolecompat.next);
68478 +
68479 + role->transitions = compat_ptr(rolecompat.transitions);
68480 + role->allowed_ips = compat_ptr(rolecompat.allowed_ips);
68481 + role->domain_children = compat_ptr(rolecompat.domain_children);
68482 + role->domain_child_num = rolecompat.domain_child_num;
68483 +
68484 + role->umask = rolecompat.umask;
68485 +
68486 + role->subj_hash = compat_ptr(rolecompat.subj_hash);
68487 + role->subj_hash_size = rolecompat.subj_hash_size;
68488 +
68489 + return 0;
68490 +}
68491 +
68492 +int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
68493 +{
68494 + struct role_allowed_ip_compat roleip_compat;
68495 +
68496 + if (copy_from_user(&roleip_compat, userp, sizeof(roleip_compat)))
68497 + return -EFAULT;
68498 +
68499 + roleip->addr = roleip_compat.addr;
68500 + roleip->netmask = roleip_compat.netmask;
68501 +
68502 + roleip->prev = compat_ptr(roleip_compat.prev);
68503 + roleip->next = compat_ptr(roleip_compat.next);
68504 +
68505 + return 0;
68506 +}
68507 +
68508 +int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp)
68509 +{
68510 + struct role_transition_compat trans_compat;
68511 +
68512 + if (copy_from_user(&trans_compat, userp, sizeof(trans_compat)))
68513 + return -EFAULT;
68514 +
68515 + trans->rolename = compat_ptr(trans_compat.rolename);
68516 +
68517 + trans->prev = compat_ptr(trans_compat.prev);
68518 + trans->next = compat_ptr(trans_compat.next);
68519 +
68520 + return 0;
68521 +
68522 +}
68523 +
68524 +int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
68525 +{
68526 + struct gr_hash_struct_compat hash_compat;
68527 +
68528 + if (copy_from_user(&hash_compat, userp, sizeof(hash_compat)))
68529 + return -EFAULT;
68530 +
68531 + hash->table = compat_ptr(hash_compat.table);
68532 + hash->nametable = compat_ptr(hash_compat.nametable);
68533 + hash->first = compat_ptr(hash_compat.first);
68534 +
68535 + hash->table_size = hash_compat.table_size;
68536 + hash->used_size = hash_compat.used_size;
68537 +
68538 + hash->type = hash_compat.type;
68539 +
68540 + return 0;
68541 +}
68542 +
68543 +int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp)
68544 +{
68545 + compat_uptr_t ptrcompat;
68546 +
68547 + if (copy_from_user(&ptrcompat, userp + (idx * sizeof(ptrcompat)), sizeof(ptrcompat)))
68548 + return -EFAULT;
68549 +
68550 + *(void **)ptr = compat_ptr(ptrcompat);
68551 +
68552 + return 0;
68553 +}
68554 +
68555 +int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp)
68556 +{
68557 + struct acl_ip_label_compat ip_compat;
68558 +
68559 + if (copy_from_user(&ip_compat, userp, sizeof(ip_compat)))
68560 + return -EFAULT;
68561 +
68562 + ip->iface = compat_ptr(ip_compat.iface);
68563 + ip->addr = ip_compat.addr;
68564 + ip->netmask = ip_compat.netmask;
68565 + ip->low = ip_compat.low;
68566 + ip->high = ip_compat.high;
68567 + ip->mode = ip_compat.mode;
68568 + ip->type = ip_compat.type;
68569 +
68570 + memcpy(&ip->proto, &ip_compat.proto, sizeof(ip->proto));
68571 +
68572 + ip->prev = compat_ptr(ip_compat.prev);
68573 + ip->next = compat_ptr(ip_compat.next);
68574 +
68575 + return 0;
68576 +}
68577 +
68578 +int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
68579 +{
68580 + struct sprole_pw_compat pw_compat;
68581 +
68582 + if (copy_from_user(&pw_compat, (const void *)userp + (sizeof(pw_compat) * idx), sizeof(pw_compat)))
68583 + return -EFAULT;
68584 +
68585 + pw->rolename = compat_ptr(pw_compat.rolename);
68586 + memcpy(&pw->salt, pw_compat.salt, sizeof(pw->salt));
68587 + memcpy(&pw->sum, pw_compat.sum, sizeof(pw->sum));
68588 +
68589 + return 0;
68590 +}
68591 +
68592 +size_t get_gr_arg_wrapper_size_compat(void)
68593 +{
68594 + return sizeof(struct gr_arg_wrapper_compat);
68595 +}
68596 +
68597 diff --git a/grsecurity/gracl_fs.c b/grsecurity/gracl_fs.c
68598 new file mode 100644
68599 index 0000000..a89b1f4
68600 --- /dev/null
68601 +++ b/grsecurity/gracl_fs.c
68602 @@ -0,0 +1,437 @@
68603 +#include <linux/kernel.h>
68604 +#include <linux/sched.h>
68605 +#include <linux/types.h>
68606 +#include <linux/fs.h>
68607 +#include <linux/file.h>
68608 +#include <linux/stat.h>
68609 +#include <linux/grsecurity.h>
68610 +#include <linux/grinternal.h>
68611 +#include <linux/gracl.h>
68612 +
68613 +umode_t
68614 +gr_acl_umask(void)
68615 +{
68616 + if (unlikely(!gr_acl_is_enabled()))
68617 + return 0;
68618 +
68619 + return current->role->umask;
68620 +}
68621 +
68622 +__u32
68623 +gr_acl_handle_hidden_file(const struct dentry * dentry,
68624 + const struct vfsmount * mnt)
68625 +{
68626 + __u32 mode;
68627 +
68628 + if (unlikely(d_is_negative(dentry)))
68629 + return GR_FIND;
68630 +
68631 + mode =
68632 + gr_search_file(dentry, GR_FIND | GR_AUDIT_FIND | GR_SUPPRESS, mnt);
68633 +
68634 + if (unlikely(mode & GR_FIND && mode & GR_AUDIT_FIND)) {
68635 + gr_log_fs_rbac_generic(GR_DO_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
68636 + return mode;
68637 + } else if (unlikely(!(mode & GR_FIND) && !(mode & GR_SUPPRESS))) {
68638 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, GR_HIDDEN_ACL_MSG, dentry, mnt);
68639 + return 0;
68640 + } else if (unlikely(!(mode & GR_FIND)))
68641 + return 0;
68642 +
68643 + return GR_FIND;
68644 +}
68645 +
68646 +__u32
68647 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
68648 + int acc_mode)
68649 +{
68650 + __u32 reqmode = GR_FIND;
68651 + __u32 mode;
68652 +
68653 + if (unlikely(d_is_negative(dentry)))
68654 + return reqmode;
68655 +
68656 + if (acc_mode & MAY_APPEND)
68657 + reqmode |= GR_APPEND;
68658 + else if (acc_mode & MAY_WRITE)
68659 + reqmode |= GR_WRITE;
68660 + if ((acc_mode & MAY_READ) && !S_ISDIR(dentry->d_inode->i_mode))
68661 + reqmode |= GR_READ;
68662 +
68663 + mode =
68664 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
68665 + mnt);
68666 +
68667 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68668 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
68669 + reqmode & GR_READ ? " reading" : "",
68670 + reqmode & GR_WRITE ? " writing" : reqmode &
68671 + GR_APPEND ? " appending" : "");
68672 + return reqmode;
68673 + } else
68674 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68675 + {
68676 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_OPEN_ACL_MSG, dentry, mnt,
68677 + reqmode & GR_READ ? " reading" : "",
68678 + reqmode & GR_WRITE ? " writing" : reqmode &
68679 + GR_APPEND ? " appending" : "");
68680 + return 0;
68681 + } else if (unlikely((mode & reqmode) != reqmode))
68682 + return 0;
68683 +
68684 + return reqmode;
68685 +}
68686 +
68687 +__u32
68688 +gr_acl_handle_creat(const struct dentry * dentry,
68689 + const struct dentry * p_dentry,
68690 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
68691 + const int imode)
68692 +{
68693 + __u32 reqmode = GR_WRITE | GR_CREATE;
68694 + __u32 mode;
68695 +
68696 + if (acc_mode & MAY_APPEND)
68697 + reqmode |= GR_APPEND;
68698 + // if a directory was required or the directory already exists, then
68699 + // don't count this open as a read
68700 + if ((acc_mode & MAY_READ) &&
68701 + !((open_flags & O_DIRECTORY) || (dentry->d_inode && S_ISDIR(dentry->d_inode->i_mode))))
68702 + reqmode |= GR_READ;
68703 + if ((open_flags & O_CREAT) &&
68704 + ((imode & S_ISUID) || ((imode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
68705 + reqmode |= GR_SETID;
68706 +
68707 + mode =
68708 + gr_check_create(dentry, p_dentry, p_mnt,
68709 + reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
68710 +
68711 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68712 + gr_log_fs_rbac_mode2(GR_DO_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
68713 + reqmode & GR_READ ? " reading" : "",
68714 + reqmode & GR_WRITE ? " writing" : reqmode &
68715 + GR_APPEND ? " appending" : "");
68716 + return reqmode;
68717 + } else
68718 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68719 + {
68720 + gr_log_fs_rbac_mode2(GR_DONT_AUDIT, GR_CREATE_ACL_MSG, dentry, p_mnt,
68721 + reqmode & GR_READ ? " reading" : "",
68722 + reqmode & GR_WRITE ? " writing" : reqmode &
68723 + GR_APPEND ? " appending" : "");
68724 + return 0;
68725 + } else if (unlikely((mode & reqmode) != reqmode))
68726 + return 0;
68727 +
68728 + return reqmode;
68729 +}
68730 +
68731 +__u32
68732 +gr_acl_handle_access(const struct dentry * dentry, const struct vfsmount * mnt,
68733 + const int fmode)
68734 +{
68735 + __u32 mode, reqmode = GR_FIND;
68736 +
68737 + if ((fmode & S_IXOTH) && !S_ISDIR(dentry->d_inode->i_mode))
68738 + reqmode |= GR_EXEC;
68739 + if (fmode & S_IWOTH)
68740 + reqmode |= GR_WRITE;
68741 + if (fmode & S_IROTH)
68742 + reqmode |= GR_READ;
68743 +
68744 + mode =
68745 + gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS,
68746 + mnt);
68747 +
68748 + if (unlikely(((mode & reqmode) == reqmode) && mode & GR_AUDITS)) {
68749 + gr_log_fs_rbac_mode3(GR_DO_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
68750 + reqmode & GR_READ ? " reading" : "",
68751 + reqmode & GR_WRITE ? " writing" : "",
68752 + reqmode & GR_EXEC ? " executing" : "");
68753 + return reqmode;
68754 + } else
68755 + if (unlikely((mode & reqmode) != reqmode && !(mode & GR_SUPPRESS)))
68756 + {
68757 + gr_log_fs_rbac_mode3(GR_DONT_AUDIT, GR_ACCESS_ACL_MSG, dentry, mnt,
68758 + reqmode & GR_READ ? " reading" : "",
68759 + reqmode & GR_WRITE ? " writing" : "",
68760 + reqmode & GR_EXEC ? " executing" : "");
68761 + return 0;
68762 + } else if (unlikely((mode & reqmode) != reqmode))
68763 + return 0;
68764 +
68765 + return reqmode;
68766 +}
68767 +
68768 +static __u32 generic_fs_handler(const struct dentry *dentry, const struct vfsmount *mnt, __u32 reqmode, const char *fmt)
68769 +{
68770 + __u32 mode;
68771 +
68772 + mode = gr_search_file(dentry, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS, mnt);
68773 +
68774 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
68775 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, dentry, mnt);
68776 + return mode;
68777 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
68778 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, dentry, mnt);
68779 + return 0;
68780 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
68781 + return 0;
68782 +
68783 + return (reqmode);
68784 +}
68785 +
68786 +__u32
68787 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
68788 +{
68789 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_RMDIR_ACL_MSG);
68790 +}
68791 +
68792 +__u32
68793 +gr_acl_handle_unlink(const struct dentry *dentry, const struct vfsmount *mnt)
68794 +{
68795 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_DELETE , GR_UNLINK_ACL_MSG);
68796 +}
68797 +
68798 +__u32
68799 +gr_acl_handle_truncate(const struct dentry *dentry, const struct vfsmount *mnt)
68800 +{
68801 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_TRUNCATE_ACL_MSG);
68802 +}
68803 +
68804 +__u32
68805 +gr_acl_handle_utime(const struct dentry *dentry, const struct vfsmount *mnt)
68806 +{
68807 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_ATIME_ACL_MSG);
68808 +}
68809 +
68810 +__u32
68811 +gr_acl_handle_chmod(const struct dentry *dentry, const struct vfsmount *mnt,
68812 + umode_t *modeptr)
68813 +{
68814 + umode_t mode;
68815 +
68816 + *modeptr &= ~gr_acl_umask();
68817 + mode = *modeptr;
68818 +
68819 + if (unlikely(dentry->d_inode && S_ISSOCK(dentry->d_inode->i_mode)))
68820 + return 1;
68821 +
68822 + if (unlikely(dentry->d_inode && !S_ISDIR(dentry->d_inode->i_mode) &&
68823 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))) {
68824 + return generic_fs_handler(dentry, mnt, GR_WRITE | GR_SETID,
68825 + GR_CHMOD_ACL_MSG);
68826 + } else {
68827 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHMOD_ACL_MSG);
68828 + }
68829 +}
68830 +
68831 +__u32
68832 +gr_acl_handle_chown(const struct dentry *dentry, const struct vfsmount *mnt)
68833 +{
68834 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_CHOWN_ACL_MSG);
68835 +}
68836 +
68837 +__u32
68838 +gr_acl_handle_setxattr(const struct dentry *dentry, const struct vfsmount *mnt)
68839 +{
68840 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_SETXATTR_ACL_MSG);
68841 +}
68842 +
68843 +__u32
68844 +gr_acl_handle_removexattr(const struct dentry *dentry, const struct vfsmount *mnt)
68845 +{
68846 + return generic_fs_handler(dentry, mnt, GR_WRITE, GR_REMOVEXATTR_ACL_MSG);
68847 +}
68848 +
68849 +__u32
68850 +gr_acl_handle_execve(const struct dentry *dentry, const struct vfsmount *mnt)
68851 +{
68852 + return generic_fs_handler(dentry, mnt, GR_EXEC, GR_EXEC_ACL_MSG);
68853 +}
68854 +
68855 +__u32
68856 +gr_acl_handle_unix(const struct dentry *dentry, const struct vfsmount *mnt)
68857 +{
68858 + return generic_fs_handler(dentry, mnt, GR_READ | GR_WRITE,
68859 + GR_UNIXCONNECT_ACL_MSG);
68860 +}
68861 +
68862 +/* hardlinks require at minimum create and link permission,
68863 + any additional privilege required is based on the
68864 + privilege of the file being linked to
68865 +*/
68866 +__u32
68867 +gr_acl_handle_link(const struct dentry * new_dentry,
68868 + const struct dentry * parent_dentry,
68869 + const struct vfsmount * parent_mnt,
68870 + const struct dentry * old_dentry,
68871 + const struct vfsmount * old_mnt, const struct filename *to)
68872 +{
68873 + __u32 mode;
68874 + __u32 needmode = GR_CREATE | GR_LINK;
68875 + __u32 needaudit = GR_AUDIT_CREATE | GR_AUDIT_LINK;
68876 +
68877 + mode =
68878 + gr_check_link(new_dentry, parent_dentry, parent_mnt, old_dentry,
68879 + old_mnt);
68880 +
68881 + if (unlikely(((mode & needmode) == needmode) && (mode & needaudit))) {
68882 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
68883 + return mode;
68884 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
68885 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_LINK_ACL_MSG, old_dentry, old_mnt, to->name);
68886 + return 0;
68887 + } else if (unlikely((mode & needmode) != needmode))
68888 + return 0;
68889 +
68890 + return 1;
68891 +}
68892 +
68893 +__u32
68894 +gr_acl_handle_symlink(const struct dentry * new_dentry,
68895 + const struct dentry * parent_dentry,
68896 + const struct vfsmount * parent_mnt, const struct filename *from)
68897 +{
68898 + __u32 needmode = GR_WRITE | GR_CREATE;
68899 + __u32 mode;
68900 +
68901 + mode =
68902 + gr_check_create(new_dentry, parent_dentry, parent_mnt,
68903 + GR_CREATE | GR_AUDIT_CREATE |
68904 + GR_WRITE | GR_AUDIT_WRITE | GR_SUPPRESS);
68905 +
68906 + if (unlikely(mode & GR_WRITE && mode & GR_AUDITS)) {
68907 + gr_log_fs_str_rbac(GR_DO_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
68908 + return mode;
68909 + } else if (unlikely(((mode & needmode) != needmode) && !(mode & GR_SUPPRESS))) {
68910 + gr_log_fs_str_rbac(GR_DONT_AUDIT, GR_SYMLINK_ACL_MSG, from->name, new_dentry, parent_mnt);
68911 + return 0;
68912 + } else if (unlikely((mode & needmode) != needmode))
68913 + return 0;
68914 +
68915 + return (GR_WRITE | GR_CREATE);
68916 +}
68917 +
68918 +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)
68919 +{
68920 + __u32 mode;
68921 +
68922 + mode = gr_check_create(new_dentry, parent_dentry, parent_mnt, reqmode | to_gr_audit(reqmode) | GR_SUPPRESS);
68923 +
68924 + if (unlikely(((mode & (reqmode)) == (reqmode)) && mode & GR_AUDITS)) {
68925 + gr_log_fs_rbac_generic(GR_DO_AUDIT, fmt, new_dentry, parent_mnt);
68926 + return mode;
68927 + } else if (unlikely((mode & (reqmode)) != (reqmode) && !(mode & GR_SUPPRESS))) {
68928 + gr_log_fs_rbac_generic(GR_DONT_AUDIT, fmt, new_dentry, parent_mnt);
68929 + return 0;
68930 + } else if (unlikely((mode & (reqmode)) != (reqmode)))
68931 + return 0;
68932 +
68933 + return (reqmode);
68934 +}
68935 +
68936 +__u32
68937 +gr_acl_handle_mknod(const struct dentry * new_dentry,
68938 + const struct dentry * parent_dentry,
68939 + const struct vfsmount * parent_mnt,
68940 + const int mode)
68941 +{
68942 + __u32 reqmode = GR_WRITE | GR_CREATE;
68943 + if (unlikely((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))))
68944 + reqmode |= GR_SETID;
68945 +
68946 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
68947 + reqmode, GR_MKNOD_ACL_MSG);
68948 +}
68949 +
68950 +__u32
68951 +gr_acl_handle_mkdir(const struct dentry *new_dentry,
68952 + const struct dentry *parent_dentry,
68953 + const struct vfsmount *parent_mnt)
68954 +{
68955 + return generic_fs_create_handler(new_dentry, parent_dentry, parent_mnt,
68956 + GR_WRITE | GR_CREATE, GR_MKDIR_ACL_MSG);
68957 +}
68958 +
68959 +#define RENAME_CHECK_SUCCESS(old, new) \
68960 + (((old & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)) && \
68961 + ((new & (GR_WRITE | GR_READ)) == (GR_WRITE | GR_READ)))
68962 +
68963 +int
68964 +gr_acl_handle_rename(struct dentry *new_dentry,
68965 + struct dentry *parent_dentry,
68966 + const struct vfsmount *parent_mnt,
68967 + struct dentry *old_dentry,
68968 + struct inode *old_parent_inode,
68969 + struct vfsmount *old_mnt, const struct filename *newname)
68970 +{
68971 + __u32 comp1, comp2;
68972 + int error = 0;
68973 +
68974 + if (unlikely(!gr_acl_is_enabled()))
68975 + return 0;
68976 +
68977 + if (d_is_negative(new_dentry)) {
68978 + comp1 = gr_check_create(new_dentry, parent_dentry, parent_mnt,
68979 + GR_READ | GR_WRITE | GR_CREATE | GR_AUDIT_READ |
68980 + GR_AUDIT_WRITE | GR_AUDIT_CREATE | GR_SUPPRESS);
68981 + comp2 = gr_search_file(old_dentry, GR_READ | GR_WRITE |
68982 + GR_DELETE | GR_AUDIT_DELETE |
68983 + GR_AUDIT_READ | GR_AUDIT_WRITE |
68984 + GR_SUPPRESS, old_mnt);
68985 + } else {
68986 + comp1 = gr_search_file(new_dentry, GR_READ | GR_WRITE |
68987 + GR_CREATE | GR_DELETE |
68988 + GR_AUDIT_CREATE | GR_AUDIT_DELETE |
68989 + GR_AUDIT_READ | GR_AUDIT_WRITE |
68990 + GR_SUPPRESS, parent_mnt);
68991 + comp2 =
68992 + gr_search_file(old_dentry,
68993 + GR_READ | GR_WRITE | GR_AUDIT_READ |
68994 + GR_DELETE | GR_AUDIT_DELETE |
68995 + GR_AUDIT_WRITE | GR_SUPPRESS, old_mnt);
68996 + }
68997 +
68998 + if (RENAME_CHECK_SUCCESS(comp1, comp2) &&
68999 + ((comp1 & GR_AUDITS) || (comp2 & GR_AUDITS)))
69000 + gr_log_fs_rbac_str(GR_DO_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
69001 + else if (!RENAME_CHECK_SUCCESS(comp1, comp2) && !(comp1 & GR_SUPPRESS)
69002 + && !(comp2 & GR_SUPPRESS)) {
69003 + gr_log_fs_rbac_str(GR_DONT_AUDIT, GR_RENAME_ACL_MSG, old_dentry, old_mnt, newname->name);
69004 + error = -EACCES;
69005 + } else if (unlikely(!RENAME_CHECK_SUCCESS(comp1, comp2)))
69006 + error = -EACCES;
69007 +
69008 + return error;
69009 +}
69010 +
69011 +void
69012 +gr_acl_handle_exit(void)
69013 +{
69014 + u16 id;
69015 + char *rolename;
69016 +
69017 + if (unlikely(current->acl_sp_role && gr_acl_is_enabled() &&
69018 + !(current->role->roletype & GR_ROLE_PERSIST))) {
69019 + id = current->acl_role_id;
69020 + rolename = current->role->rolename;
69021 + gr_set_acls(1);
69022 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLEL_ACL_MSG, rolename, id);
69023 + }
69024 +
69025 + gr_put_exec_file(current);
69026 + return;
69027 +}
69028 +
69029 +int
69030 +gr_acl_handle_procpidmem(const struct task_struct *task)
69031 +{
69032 + if (unlikely(!gr_acl_is_enabled()))
69033 + return 0;
69034 +
69035 + if (task != current && task->acl->mode & GR_PROTPROCFD)
69036 + return -EACCES;
69037 +
69038 + return 0;
69039 +}
69040 diff --git a/grsecurity/gracl_ip.c b/grsecurity/gracl_ip.c
69041 new file mode 100644
69042 index 0000000..f056b81
69043 --- /dev/null
69044 +++ b/grsecurity/gracl_ip.c
69045 @@ -0,0 +1,386 @@
69046 +#include <linux/kernel.h>
69047 +#include <asm/uaccess.h>
69048 +#include <asm/errno.h>
69049 +#include <net/sock.h>
69050 +#include <linux/file.h>
69051 +#include <linux/fs.h>
69052 +#include <linux/net.h>
69053 +#include <linux/in.h>
69054 +#include <linux/skbuff.h>
69055 +#include <linux/ip.h>
69056 +#include <linux/udp.h>
69057 +#include <linux/types.h>
69058 +#include <linux/sched.h>
69059 +#include <linux/netdevice.h>
69060 +#include <linux/inetdevice.h>
69061 +#include <linux/gracl.h>
69062 +#include <linux/grsecurity.h>
69063 +#include <linux/grinternal.h>
69064 +
69065 +#define GR_BIND 0x01
69066 +#define GR_CONNECT 0x02
69067 +#define GR_INVERT 0x04
69068 +#define GR_BINDOVERRIDE 0x08
69069 +#define GR_CONNECTOVERRIDE 0x10
69070 +#define GR_SOCK_FAMILY 0x20
69071 +
69072 +static const char * gr_protocols[IPPROTO_MAX] = {
69073 + "ip", "icmp", "igmp", "ggp", "ipencap", "st", "tcp", "cbt",
69074 + "egp", "igp", "bbn-rcc", "nvp", "pup", "argus", "emcon", "xnet",
69075 + "chaos", "udp", "mux", "dcn", "hmp", "prm", "xns-idp", "trunk-1",
69076 + "trunk-2", "leaf-1", "leaf-2", "rdp", "irtp", "iso-tp4", "netblt", "mfe-nsp",
69077 + "merit-inp", "sep", "3pc", "idpr", "xtp", "ddp", "idpr-cmtp", "tp++",
69078 + "il", "ipv6", "sdrp", "ipv6-route", "ipv6-frag", "idrp", "rsvp", "gre",
69079 + "mhrp", "bna", "ipv6-crypt", "ipv6-auth", "i-nlsp", "swipe", "narp", "mobile",
69080 + "tlsp", "skip", "ipv6-icmp", "ipv6-nonxt", "ipv6-opts", "unknown:61", "cftp", "unknown:63",
69081 + "sat-expak", "kryptolan", "rvd", "ippc", "unknown:68", "sat-mon", "visa", "ipcv",
69082 + "cpnx", "cphb", "wsn", "pvp", "br-sat-mon", "sun-nd", "wb-mon", "wb-expak",
69083 + "iso-ip", "vmtp", "secure-vmtp", "vines", "ttp", "nfsnet-igp", "dgp", "tcf",
69084 + "eigrp", "ospf", "sprite-rpc", "larp", "mtp", "ax.25", "ipip", "micp",
69085 + "scc-sp", "etherip", "encap", "unknown:99", "gmtp", "ifmp", "pnni", "pim",
69086 + "aris", "scps", "qnx", "a/n", "ipcomp", "snp", "compaq-peer", "ipx-in-ip",
69087 + "vrrp", "pgm", "unknown:114", "l2tp", "ddx", "iatp", "stp", "srp",
69088 + "uti", "smp", "sm", "ptp", "isis", "fire", "crtp", "crdup",
69089 + "sscopmce", "iplt", "sps", "pipe", "sctp", "fc", "unkown:134", "unknown:135",
69090 + "unknown:136", "unknown:137", "unknown:138", "unknown:139", "unknown:140", "unknown:141", "unknown:142", "unknown:143",
69091 + "unknown:144", "unknown:145", "unknown:146", "unknown:147", "unknown:148", "unknown:149", "unknown:150", "unknown:151",
69092 + "unknown:152", "unknown:153", "unknown:154", "unknown:155", "unknown:156", "unknown:157", "unknown:158", "unknown:159",
69093 + "unknown:160", "unknown:161", "unknown:162", "unknown:163", "unknown:164", "unknown:165", "unknown:166", "unknown:167",
69094 + "unknown:168", "unknown:169", "unknown:170", "unknown:171", "unknown:172", "unknown:173", "unknown:174", "unknown:175",
69095 + "unknown:176", "unknown:177", "unknown:178", "unknown:179", "unknown:180", "unknown:181", "unknown:182", "unknown:183",
69096 + "unknown:184", "unknown:185", "unknown:186", "unknown:187", "unknown:188", "unknown:189", "unknown:190", "unknown:191",
69097 + "unknown:192", "unknown:193", "unknown:194", "unknown:195", "unknown:196", "unknown:197", "unknown:198", "unknown:199",
69098 + "unknown:200", "unknown:201", "unknown:202", "unknown:203", "unknown:204", "unknown:205", "unknown:206", "unknown:207",
69099 + "unknown:208", "unknown:209", "unknown:210", "unknown:211", "unknown:212", "unknown:213", "unknown:214", "unknown:215",
69100 + "unknown:216", "unknown:217", "unknown:218", "unknown:219", "unknown:220", "unknown:221", "unknown:222", "unknown:223",
69101 + "unknown:224", "unknown:225", "unknown:226", "unknown:227", "unknown:228", "unknown:229", "unknown:230", "unknown:231",
69102 + "unknown:232", "unknown:233", "unknown:234", "unknown:235", "unknown:236", "unknown:237", "unknown:238", "unknown:239",
69103 + "unknown:240", "unknown:241", "unknown:242", "unknown:243", "unknown:244", "unknown:245", "unknown:246", "unknown:247",
69104 + "unknown:248", "unknown:249", "unknown:250", "unknown:251", "unknown:252", "unknown:253", "unknown:254", "unknown:255",
69105 + };
69106 +
69107 +static const char * gr_socktypes[SOCK_MAX] = {
69108 + "unknown:0", "stream", "dgram", "raw", "rdm", "seqpacket", "unknown:6",
69109 + "unknown:7", "unknown:8", "unknown:9", "packet"
69110 + };
69111 +
69112 +static const char * gr_sockfamilies[AF_MAX+1] = {
69113 + "unspec", "unix", "inet", "ax25", "ipx", "appletalk", "netrom", "bridge", "atmpvc", "x25",
69114 + "inet6", "rose", "decnet", "netbeui", "security", "key", "netlink", "packet", "ash",
69115 + "econet", "atmsvc", "rds", "sna", "irda", "ppox", "wanpipe", "llc", "fam_27", "fam_28",
69116 + "tipc", "bluetooth", "iucv", "rxrpc", "isdn", "phonet", "ieee802154", "ciaf"
69117 + };
69118 +
69119 +const char *
69120 +gr_proto_to_name(unsigned char proto)
69121 +{
69122 + return gr_protocols[proto];
69123 +}
69124 +
69125 +const char *
69126 +gr_socktype_to_name(unsigned char type)
69127 +{
69128 + return gr_socktypes[type];
69129 +}
69130 +
69131 +const char *
69132 +gr_sockfamily_to_name(unsigned char family)
69133 +{
69134 + return gr_sockfamilies[family];
69135 +}
69136 +
69137 +extern const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
69138 +
69139 +int
69140 +gr_search_socket(const int domain, const int type, const int protocol)
69141 +{
69142 + struct acl_subject_label *curr;
69143 + const struct cred *cred = current_cred();
69144 +
69145 + if (unlikely(!gr_acl_is_enabled()))
69146 + goto exit;
69147 +
69148 + if ((domain < 0) || (type < 0) || (protocol < 0) ||
69149 + (domain >= AF_MAX) || (type >= SOCK_MAX) || (protocol >= IPPROTO_MAX))
69150 + goto exit; // let the kernel handle it
69151 +
69152 + curr = current->acl;
69153 +
69154 + if (curr->sock_families[domain / 32] & (1U << (domain % 32))) {
69155 + /* the family is allowed, if this is PF_INET allow it only if
69156 + the extra sock type/protocol checks pass */
69157 + if (domain == PF_INET)
69158 + goto inet_check;
69159 + goto exit;
69160 + } else {
69161 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
69162 + __u32 fakeip = 0;
69163 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69164 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
69165 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
69166 + gr_to_filename(current->exec_file->f_path.dentry,
69167 + current->exec_file->f_path.mnt) :
69168 + curr->filename, curr->filename,
69169 + &fakeip, domain, 0, 0, GR_SOCK_FAMILY,
69170 + &current->signal->saved_ip);
69171 + goto exit;
69172 + }
69173 + goto exit_fail;
69174 + }
69175 +
69176 +inet_check:
69177 + /* the rest of this checking is for IPv4 only */
69178 + if (!curr->ips)
69179 + goto exit;
69180 +
69181 + if ((curr->ip_type & (1U << type)) &&
69182 + (curr->ip_proto[protocol / 32] & (1U << (protocol % 32))))
69183 + goto exit;
69184 +
69185 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
69186 + /* we don't place acls on raw sockets , and sometimes
69187 + dgram/ip sockets are opened for ioctl and not
69188 + bind/connect, so we'll fake a bind learn log */
69189 + if (type == SOCK_RAW || type == SOCK_PACKET) {
69190 + __u32 fakeip = 0;
69191 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69192 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
69193 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
69194 + gr_to_filename(current->exec_file->f_path.dentry,
69195 + current->exec_file->f_path.mnt) :
69196 + curr->filename, curr->filename,
69197 + &fakeip, 0, type,
69198 + protocol, GR_CONNECT, &current->signal->saved_ip);
69199 + } else if ((type == SOCK_DGRAM) && (protocol == IPPROTO_IP)) {
69200 + __u32 fakeip = 0;
69201 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69202 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
69203 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
69204 + gr_to_filename(current->exec_file->f_path.dentry,
69205 + current->exec_file->f_path.mnt) :
69206 + curr->filename, curr->filename,
69207 + &fakeip, 0, type,
69208 + protocol, GR_BIND, &current->signal->saved_ip);
69209 + }
69210 + /* we'll log when they use connect or bind */
69211 + goto exit;
69212 + }
69213 +
69214 +exit_fail:
69215 + if (domain == PF_INET)
69216 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(domain),
69217 + gr_socktype_to_name(type), gr_proto_to_name(protocol));
69218 + else if (rcu_access_pointer(net_families[domain]) != NULL)
69219 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(domain),
69220 + gr_socktype_to_name(type), protocol);
69221 +
69222 + return 0;
69223 +exit:
69224 + return 1;
69225 +}
69226 +
69227 +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)
69228 +{
69229 + if ((ip->mode & mode) &&
69230 + (ip_port >= ip->low) &&
69231 + (ip_port <= ip->high) &&
69232 + ((ntohl(ip_addr) & our_netmask) ==
69233 + (ntohl(our_addr) & our_netmask))
69234 + && (ip->proto[protocol / 32] & (1U << (protocol % 32)))
69235 + && (ip->type & (1U << type))) {
69236 + if (ip->mode & GR_INVERT)
69237 + return 2; // specifically denied
69238 + else
69239 + return 1; // allowed
69240 + }
69241 +
69242 + return 0; // not specifically allowed, may continue parsing
69243 +}
69244 +
69245 +static int
69246 +gr_search_connectbind(const int full_mode, struct sock *sk,
69247 + struct sockaddr_in *addr, const int type)
69248 +{
69249 + char iface[IFNAMSIZ] = {0};
69250 + struct acl_subject_label *curr;
69251 + struct acl_ip_label *ip;
69252 + struct inet_sock *isk;
69253 + struct net_device *dev;
69254 + struct in_device *idev;
69255 + unsigned long i;
69256 + int ret;
69257 + int mode = full_mode & (GR_BIND | GR_CONNECT);
69258 + __u32 ip_addr = 0;
69259 + __u32 our_addr;
69260 + __u32 our_netmask;
69261 + char *p;
69262 + __u16 ip_port = 0;
69263 + const struct cred *cred = current_cred();
69264 +
69265 + if (unlikely(!gr_acl_is_enabled() || sk->sk_family != PF_INET))
69266 + return 0;
69267 +
69268 + curr = current->acl;
69269 + isk = inet_sk(sk);
69270 +
69271 + /* INADDR_ANY overriding for binds, inaddr_any_override is already in network order */
69272 + if ((full_mode & GR_BINDOVERRIDE) && addr->sin_addr.s_addr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0)
69273 + addr->sin_addr.s_addr = curr->inaddr_any_override;
69274 + if ((full_mode & GR_CONNECT) && isk->inet_saddr == htonl(INADDR_ANY) && curr->inaddr_any_override != 0) {
69275 + struct sockaddr_in saddr;
69276 + int err;
69277 +
69278 + saddr.sin_family = AF_INET;
69279 + saddr.sin_addr.s_addr = curr->inaddr_any_override;
69280 + saddr.sin_port = isk->inet_sport;
69281 +
69282 + err = security_socket_bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
69283 + if (err)
69284 + return err;
69285 +
69286 + err = sk->sk_socket->ops->bind(sk->sk_socket, (struct sockaddr *)&saddr, sizeof(struct sockaddr_in));
69287 + if (err)
69288 + return err;
69289 + }
69290 +
69291 + if (!curr->ips)
69292 + return 0;
69293 +
69294 + ip_addr = addr->sin_addr.s_addr;
69295 + ip_port = ntohs(addr->sin_port);
69296 +
69297 + if (curr->mode & (GR_LEARN | GR_INHERITLEARN)) {
69298 + security_learn(GR_IP_LEARN_MSG, current->role->rolename,
69299 + current->role->roletype, GR_GLOBAL_UID(cred->uid),
69300 + GR_GLOBAL_GID(cred->gid), current->exec_file ?
69301 + gr_to_filename(current->exec_file->f_path.dentry,
69302 + current->exec_file->f_path.mnt) :
69303 + curr->filename, curr->filename,
69304 + &ip_addr, ip_port, type,
69305 + sk->sk_protocol, mode, &current->signal->saved_ip);
69306 + return 0;
69307 + }
69308 +
69309 + for (i = 0; i < curr->ip_num; i++) {
69310 + ip = *(curr->ips + i);
69311 + if (ip->iface != NULL) {
69312 + strncpy(iface, ip->iface, IFNAMSIZ - 1);
69313 + p = strchr(iface, ':');
69314 + if (p != NULL)
69315 + *p = '\0';
69316 + dev = dev_get_by_name(sock_net(sk), iface);
69317 + if (dev == NULL)
69318 + continue;
69319 + idev = in_dev_get(dev);
69320 + if (idev == NULL) {
69321 + dev_put(dev);
69322 + continue;
69323 + }
69324 + rcu_read_lock();
69325 + for_ifa(idev) {
69326 + if (!strcmp(ip->iface, ifa->ifa_label)) {
69327 + our_addr = ifa->ifa_address;
69328 + our_netmask = 0xffffffff;
69329 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
69330 + if (ret == 1) {
69331 + rcu_read_unlock();
69332 + in_dev_put(idev);
69333 + dev_put(dev);
69334 + return 0;
69335 + } else if (ret == 2) {
69336 + rcu_read_unlock();
69337 + in_dev_put(idev);
69338 + dev_put(dev);
69339 + goto denied;
69340 + }
69341 + }
69342 + } endfor_ifa(idev);
69343 + rcu_read_unlock();
69344 + in_dev_put(idev);
69345 + dev_put(dev);
69346 + } else {
69347 + our_addr = ip->addr;
69348 + our_netmask = ip->netmask;
69349 + ret = check_ip_policy(ip, ip_addr, ip_port, sk->sk_protocol, mode, type, our_addr, our_netmask);
69350 + if (ret == 1)
69351 + return 0;
69352 + else if (ret == 2)
69353 + goto denied;
69354 + }
69355 + }
69356 +
69357 +denied:
69358 + if (mode == GR_BIND)
69359 + 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));
69360 + else if (mode == GR_CONNECT)
69361 + 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));
69362 +
69363 + return -EACCES;
69364 +}
69365 +
69366 +int
69367 +gr_search_connect(struct socket *sock, struct sockaddr_in *addr)
69368 +{
69369 + /* always allow disconnection of dgram sockets with connect */
69370 + if (addr->sin_family == AF_UNSPEC)
69371 + return 0;
69372 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sock->sk, addr, sock->type);
69373 +}
69374 +
69375 +int
69376 +gr_search_bind(struct socket *sock, struct sockaddr_in *addr)
69377 +{
69378 + return gr_search_connectbind(GR_BIND | GR_BINDOVERRIDE, sock->sk, addr, sock->type);
69379 +}
69380 +
69381 +int gr_search_listen(struct socket *sock)
69382 +{
69383 + struct sock *sk = sock->sk;
69384 + struct sockaddr_in addr;
69385 +
69386 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
69387 + addr.sin_port = inet_sk(sk)->inet_sport;
69388 +
69389 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
69390 +}
69391 +
69392 +int gr_search_accept(struct socket *sock)
69393 +{
69394 + struct sock *sk = sock->sk;
69395 + struct sockaddr_in addr;
69396 +
69397 + addr.sin_addr.s_addr = inet_sk(sk)->inet_saddr;
69398 + addr.sin_port = inet_sk(sk)->inet_sport;
69399 +
69400 + return gr_search_connectbind(GR_BIND | GR_CONNECTOVERRIDE, sock->sk, &addr, sock->type);
69401 +}
69402 +
69403 +int
69404 +gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr)
69405 +{
69406 + if (addr)
69407 + return gr_search_connectbind(GR_CONNECT, sk, addr, SOCK_DGRAM);
69408 + else {
69409 + struct sockaddr_in sin;
69410 + const struct inet_sock *inet = inet_sk(sk);
69411 +
69412 + sin.sin_addr.s_addr = inet->inet_daddr;
69413 + sin.sin_port = inet->inet_dport;
69414 +
69415 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
69416 + }
69417 +}
69418 +
69419 +int
69420 +gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb)
69421 +{
69422 + struct sockaddr_in sin;
69423 +
69424 + if (unlikely(skb->len < sizeof (struct udphdr)))
69425 + return 0; // skip this packet
69426 +
69427 + sin.sin_addr.s_addr = ip_hdr(skb)->saddr;
69428 + sin.sin_port = udp_hdr(skb)->source;
69429 +
69430 + return gr_search_connectbind(GR_CONNECT | GR_CONNECTOVERRIDE, sk, &sin, SOCK_DGRAM);
69431 +}
69432 diff --git a/grsecurity/gracl_learn.c b/grsecurity/gracl_learn.c
69433 new file mode 100644
69434 index 0000000..25f54ef
69435 --- /dev/null
69436 +++ b/grsecurity/gracl_learn.c
69437 @@ -0,0 +1,207 @@
69438 +#include <linux/kernel.h>
69439 +#include <linux/mm.h>
69440 +#include <linux/sched.h>
69441 +#include <linux/poll.h>
69442 +#include <linux/string.h>
69443 +#include <linux/file.h>
69444 +#include <linux/types.h>
69445 +#include <linux/vmalloc.h>
69446 +#include <linux/grinternal.h>
69447 +
69448 +extern ssize_t write_grsec_handler(struct file * file, const char __user * buf,
69449 + size_t count, loff_t *ppos);
69450 +extern int gr_acl_is_enabled(void);
69451 +
69452 +static DECLARE_WAIT_QUEUE_HEAD(learn_wait);
69453 +static int gr_learn_attached;
69454 +
69455 +/* use a 512k buffer */
69456 +#define LEARN_BUFFER_SIZE (512 * 1024)
69457 +
69458 +static DEFINE_SPINLOCK(gr_learn_lock);
69459 +static DEFINE_MUTEX(gr_learn_user_mutex);
69460 +
69461 +/* we need to maintain two buffers, so that the kernel context of grlearn
69462 + uses a semaphore around the userspace copying, and the other kernel contexts
69463 + use a spinlock when copying into the buffer, since they cannot sleep
69464 +*/
69465 +static char *learn_buffer;
69466 +static char *learn_buffer_user;
69467 +static int learn_buffer_len;
69468 +static int learn_buffer_user_len;
69469 +
69470 +static ssize_t
69471 +read_learn(struct file *file, char __user * buf, size_t count, loff_t * ppos)
69472 +{
69473 + DECLARE_WAITQUEUE(wait, current);
69474 + ssize_t retval = 0;
69475 +
69476 + add_wait_queue(&learn_wait, &wait);
69477 + set_current_state(TASK_INTERRUPTIBLE);
69478 + do {
69479 + mutex_lock(&gr_learn_user_mutex);
69480 + spin_lock(&gr_learn_lock);
69481 + if (learn_buffer_len)
69482 + break;
69483 + spin_unlock(&gr_learn_lock);
69484 + mutex_unlock(&gr_learn_user_mutex);
69485 + if (file->f_flags & O_NONBLOCK) {
69486 + retval = -EAGAIN;
69487 + goto out;
69488 + }
69489 + if (signal_pending(current)) {
69490 + retval = -ERESTARTSYS;
69491 + goto out;
69492 + }
69493 +
69494 + schedule();
69495 + } while (1);
69496 +
69497 + memcpy(learn_buffer_user, learn_buffer, learn_buffer_len);
69498 + learn_buffer_user_len = learn_buffer_len;
69499 + retval = learn_buffer_len;
69500 + learn_buffer_len = 0;
69501 +
69502 + spin_unlock(&gr_learn_lock);
69503 +
69504 + if (copy_to_user(buf, learn_buffer_user, learn_buffer_user_len))
69505 + retval = -EFAULT;
69506 +
69507 + mutex_unlock(&gr_learn_user_mutex);
69508 +out:
69509 + set_current_state(TASK_RUNNING);
69510 + remove_wait_queue(&learn_wait, &wait);
69511 + return retval;
69512 +}
69513 +
69514 +static unsigned int
69515 +poll_learn(struct file * file, poll_table * wait)
69516 +{
69517 + poll_wait(file, &learn_wait, wait);
69518 +
69519 + if (learn_buffer_len)
69520 + return (POLLIN | POLLRDNORM);
69521 +
69522 + return 0;
69523 +}
69524 +
69525 +void
69526 +gr_clear_learn_entries(void)
69527 +{
69528 + char *tmp;
69529 +
69530 + mutex_lock(&gr_learn_user_mutex);
69531 + spin_lock(&gr_learn_lock);
69532 + tmp = learn_buffer;
69533 + learn_buffer = NULL;
69534 + spin_unlock(&gr_learn_lock);
69535 + if (tmp)
69536 + vfree(tmp);
69537 + if (learn_buffer_user != NULL) {
69538 + vfree(learn_buffer_user);
69539 + learn_buffer_user = NULL;
69540 + }
69541 + learn_buffer_len = 0;
69542 + mutex_unlock(&gr_learn_user_mutex);
69543 +
69544 + return;
69545 +}
69546 +
69547 +void
69548 +gr_add_learn_entry(const char *fmt, ...)
69549 +{
69550 + va_list args;
69551 + unsigned int len;
69552 +
69553 + if (!gr_learn_attached)
69554 + return;
69555 +
69556 + spin_lock(&gr_learn_lock);
69557 +
69558 + /* leave a gap at the end so we know when it's "full" but don't have to
69559 + compute the exact length of the string we're trying to append
69560 + */
69561 + if (learn_buffer_len > LEARN_BUFFER_SIZE - 16384) {
69562 + spin_unlock(&gr_learn_lock);
69563 + wake_up_interruptible(&learn_wait);
69564 + return;
69565 + }
69566 + if (learn_buffer == NULL) {
69567 + spin_unlock(&gr_learn_lock);
69568 + return;
69569 + }
69570 +
69571 + va_start(args, fmt);
69572 + len = vsnprintf(learn_buffer + learn_buffer_len, LEARN_BUFFER_SIZE - learn_buffer_len, fmt, args);
69573 + va_end(args);
69574 +
69575 + learn_buffer_len += len + 1;
69576 +
69577 + spin_unlock(&gr_learn_lock);
69578 + wake_up_interruptible(&learn_wait);
69579 +
69580 + return;
69581 +}
69582 +
69583 +static int
69584 +open_learn(struct inode *inode, struct file *file)
69585 +{
69586 + if (file->f_mode & FMODE_READ && gr_learn_attached)
69587 + return -EBUSY;
69588 + if (file->f_mode & FMODE_READ) {
69589 + int retval = 0;
69590 + mutex_lock(&gr_learn_user_mutex);
69591 + if (learn_buffer == NULL)
69592 + learn_buffer = vmalloc(LEARN_BUFFER_SIZE);
69593 + if (learn_buffer_user == NULL)
69594 + learn_buffer_user = vmalloc(LEARN_BUFFER_SIZE);
69595 + if (learn_buffer == NULL) {
69596 + retval = -ENOMEM;
69597 + goto out_error;
69598 + }
69599 + if (learn_buffer_user == NULL) {
69600 + retval = -ENOMEM;
69601 + goto out_error;
69602 + }
69603 + learn_buffer_len = 0;
69604 + learn_buffer_user_len = 0;
69605 + gr_learn_attached = 1;
69606 +out_error:
69607 + mutex_unlock(&gr_learn_user_mutex);
69608 + return retval;
69609 + }
69610 + return 0;
69611 +}
69612 +
69613 +static int
69614 +close_learn(struct inode *inode, struct file *file)
69615 +{
69616 + if (file->f_mode & FMODE_READ) {
69617 + char *tmp = NULL;
69618 + mutex_lock(&gr_learn_user_mutex);
69619 + spin_lock(&gr_learn_lock);
69620 + tmp = learn_buffer;
69621 + learn_buffer = NULL;
69622 + spin_unlock(&gr_learn_lock);
69623 + if (tmp)
69624 + vfree(tmp);
69625 + if (learn_buffer_user != NULL) {
69626 + vfree(learn_buffer_user);
69627 + learn_buffer_user = NULL;
69628 + }
69629 + learn_buffer_len = 0;
69630 + learn_buffer_user_len = 0;
69631 + gr_learn_attached = 0;
69632 + mutex_unlock(&gr_learn_user_mutex);
69633 + }
69634 +
69635 + return 0;
69636 +}
69637 +
69638 +const struct file_operations grsec_fops = {
69639 + .read = read_learn,
69640 + .write = write_grsec_handler,
69641 + .open = open_learn,
69642 + .release = close_learn,
69643 + .poll = poll_learn,
69644 +};
69645 diff --git a/grsecurity/gracl_policy.c b/grsecurity/gracl_policy.c
69646 new file mode 100644
69647 index 0000000..361a099
69648 --- /dev/null
69649 +++ b/grsecurity/gracl_policy.c
69650 @@ -0,0 +1,1782 @@
69651 +#include <linux/kernel.h>
69652 +#include <linux/module.h>
69653 +#include <linux/sched.h>
69654 +#include <linux/mm.h>
69655 +#include <linux/file.h>
69656 +#include <linux/fs.h>
69657 +#include <linux/namei.h>
69658 +#include <linux/mount.h>
69659 +#include <linux/tty.h>
69660 +#include <linux/proc_fs.h>
69661 +#include <linux/lglock.h>
69662 +#include <linux/slab.h>
69663 +#include <linux/vmalloc.h>
69664 +#include <linux/types.h>
69665 +#include <linux/sysctl.h>
69666 +#include <linux/netdevice.h>
69667 +#include <linux/ptrace.h>
69668 +#include <linux/gracl.h>
69669 +#include <linux/gralloc.h>
69670 +#include <linux/security.h>
69671 +#include <linux/grinternal.h>
69672 +#include <linux/pid_namespace.h>
69673 +#include <linux/stop_machine.h>
69674 +#include <linux/fdtable.h>
69675 +#include <linux/percpu.h>
69676 +#include <linux/lglock.h>
69677 +#include <linux/hugetlb.h>
69678 +#include <linux/posix-timers.h>
69679 +#include "../fs/mount.h"
69680 +
69681 +#include <asm/uaccess.h>
69682 +#include <asm/errno.h>
69683 +#include <asm/mman.h>
69684 +
69685 +extern struct gr_policy_state *polstate;
69686 +
69687 +#define FOR_EACH_ROLE_START(role) \
69688 + role = polstate->role_list; \
69689 + while (role) {
69690 +
69691 +#define FOR_EACH_ROLE_END(role) \
69692 + role = role->prev; \
69693 + }
69694 +
69695 +struct path gr_real_root;
69696 +
69697 +extern struct gr_alloc_state *current_alloc_state;
69698 +
69699 +u16 acl_sp_role_value;
69700 +
69701 +static DEFINE_MUTEX(gr_dev_mutex);
69702 +
69703 +extern int chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum);
69704 +extern void gr_clear_learn_entries(void);
69705 +
69706 +static struct gr_arg gr_usermode;
69707 +static unsigned char gr_system_salt[GR_SALT_LEN];
69708 +static unsigned char gr_system_sum[GR_SHA_LEN];
69709 +
69710 +static unsigned int gr_auth_attempts = 0;
69711 +static unsigned long gr_auth_expires = 0UL;
69712 +
69713 +struct acl_object_label *fakefs_obj_rw;
69714 +struct acl_object_label *fakefs_obj_rwx;
69715 +
69716 +extern int gr_init_uidset(void);
69717 +extern void gr_free_uidset(void);
69718 +extern void gr_remove_uid(uid_t uid);
69719 +extern int gr_find_uid(uid_t uid);
69720 +
69721 +extern struct acl_subject_label *__gr_get_subject_for_task(const struct gr_policy_state *state, struct task_struct *task, const char *filename);
69722 +extern void __gr_apply_subject_to_task(struct gr_policy_state *state, struct task_struct *task, struct acl_subject_label *subj);
69723 +extern int gr_streq(const char *a, const char *b, const unsigned int lena, const unsigned int lenb);
69724 +extern void __insert_inodev_entry(const struct gr_policy_state *state, struct inodev_entry *entry);
69725 +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);
69726 +extern void insert_acl_obj_label(struct acl_object_label *obj, struct acl_subject_label *subj);
69727 +extern void insert_acl_subj_label(struct acl_subject_label *obj, struct acl_role_label *role);
69728 +extern struct name_entry * __lookup_name_entry(const struct gr_policy_state *state, const char *name);
69729 +extern char *gr_to_filename_rbac(const struct dentry *dentry, const struct vfsmount *mnt);
69730 +extern struct acl_subject_label *lookup_acl_subj_label(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
69731 +extern struct acl_subject_label *lookup_acl_subj_label_deleted(const ino_t ino, const dev_t dev, const struct acl_role_label *role);
69732 +extern void assign_special_role(const char *rolename);
69733 +extern struct acl_subject_label *chk_subj_label(const struct dentry *l_dentry, const struct vfsmount *l_mnt, const struct acl_role_label *role);
69734 +extern int gr_rbac_disable(void *unused);
69735 +extern void gr_enable_rbac_system(void);
69736 +
69737 +static int copy_acl_object_label_normal(struct acl_object_label *obj, const struct acl_object_label *userp)
69738 +{
69739 + if (copy_from_user(obj, userp, sizeof(struct acl_object_label)))
69740 + return -EFAULT;
69741 +
69742 + return 0;
69743 +}
69744 +
69745 +static int copy_acl_ip_label_normal(struct acl_ip_label *ip, const struct acl_ip_label *userp)
69746 +{
69747 + if (copy_from_user(ip, userp, sizeof(struct acl_ip_label)))
69748 + return -EFAULT;
69749 +
69750 + return 0;
69751 +}
69752 +
69753 +static int copy_acl_subject_label_normal(struct acl_subject_label *subj, const struct acl_subject_label *userp)
69754 +{
69755 + if (copy_from_user(subj, userp, sizeof(struct acl_subject_label)))
69756 + return -EFAULT;
69757 +
69758 + return 0;
69759 +}
69760 +
69761 +static int copy_acl_role_label_normal(struct acl_role_label *role, const struct acl_role_label *userp)
69762 +{
69763 + if (copy_from_user(role, userp, sizeof(struct acl_role_label)))
69764 + return -EFAULT;
69765 +
69766 + return 0;
69767 +}
69768 +
69769 +static int copy_role_allowed_ip_normal(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp)
69770 +{
69771 + if (copy_from_user(roleip, userp, sizeof(struct role_allowed_ip)))
69772 + return -EFAULT;
69773 +
69774 + return 0;
69775 +}
69776 +
69777 +static int copy_sprole_pw_normal(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp)
69778 +{
69779 + if (copy_from_user(pw, userp + idx, sizeof(struct sprole_pw)))
69780 + return -EFAULT;
69781 +
69782 + return 0;
69783 +}
69784 +
69785 +static int copy_gr_hash_struct_normal(struct gr_hash_struct *hash, const struct gr_hash_struct *userp)
69786 +{
69787 + if (copy_from_user(hash, userp, sizeof(struct gr_hash_struct)))
69788 + return -EFAULT;
69789 +
69790 + return 0;
69791 +}
69792 +
69793 +static int copy_role_transition_normal(struct role_transition *trans, const struct role_transition *userp)
69794 +{
69795 + if (copy_from_user(trans, userp, sizeof(struct role_transition)))
69796 + return -EFAULT;
69797 +
69798 + return 0;
69799 +}
69800 +
69801 +int copy_pointer_from_array_normal(void *ptr, unsigned long idx, const void *userp)
69802 +{
69803 + if (copy_from_user(ptr, userp + (idx * sizeof(void *)), sizeof(void *)))
69804 + return -EFAULT;
69805 +
69806 + return 0;
69807 +}
69808 +
69809 +static int copy_gr_arg_wrapper_normal(const char __user *buf, struct gr_arg_wrapper *uwrap)
69810 +{
69811 + if (copy_from_user(uwrap, buf, sizeof (struct gr_arg_wrapper)))
69812 + return -EFAULT;
69813 +
69814 + if (((uwrap->version != GRSECURITY_VERSION) &&
69815 + (uwrap->version != 0x2901)) ||
69816 + (uwrap->size != sizeof(struct gr_arg)))
69817 + return -EINVAL;
69818 +
69819 + return 0;
69820 +}
69821 +
69822 +static int copy_gr_arg_normal(const struct gr_arg __user *buf, struct gr_arg *arg)
69823 +{
69824 + if (copy_from_user(arg, buf, sizeof (struct gr_arg)))
69825 + return -EFAULT;
69826 +
69827 + return 0;
69828 +}
69829 +
69830 +static size_t get_gr_arg_wrapper_size_normal(void)
69831 +{
69832 + return sizeof(struct gr_arg_wrapper);
69833 +}
69834 +
69835 +#ifdef CONFIG_COMPAT
69836 +extern int copy_gr_arg_wrapper_compat(const char *buf, struct gr_arg_wrapper *uwrap);
69837 +extern int copy_gr_arg_compat(const struct gr_arg __user *buf, struct gr_arg *arg);
69838 +extern int copy_acl_object_label_compat(struct acl_object_label *obj, const struct acl_object_label *userp);
69839 +extern int copy_acl_subject_label_compat(struct acl_subject_label *subj, const struct acl_subject_label *userp);
69840 +extern int copy_acl_role_label_compat(struct acl_role_label *role, const struct acl_role_label *userp);
69841 +extern int copy_role_allowed_ip_compat(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp);
69842 +extern int copy_role_transition_compat(struct role_transition *trans, const struct role_transition *userp);
69843 +extern int copy_gr_hash_struct_compat(struct gr_hash_struct *hash, const struct gr_hash_struct *userp);
69844 +extern int copy_pointer_from_array_compat(void *ptr, unsigned long idx, const void *userp);
69845 +extern int copy_acl_ip_label_compat(struct acl_ip_label *ip, const struct acl_ip_label *userp);
69846 +extern int copy_sprole_pw_compat(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp);
69847 +extern size_t get_gr_arg_wrapper_size_compat(void);
69848 +
69849 +int (* copy_gr_arg_wrapper)(const char *buf, struct gr_arg_wrapper *uwrap) __read_only;
69850 +int (* copy_gr_arg)(const struct gr_arg *buf, struct gr_arg *arg) __read_only;
69851 +int (* copy_acl_object_label)(struct acl_object_label *obj, const struct acl_object_label *userp) __read_only;
69852 +int (* copy_acl_subject_label)(struct acl_subject_label *subj, const struct acl_subject_label *userp) __read_only;
69853 +int (* copy_acl_role_label)(struct acl_role_label *role, const struct acl_role_label *userp) __read_only;
69854 +int (* copy_acl_ip_label)(struct acl_ip_label *ip, const struct acl_ip_label *userp) __read_only;
69855 +int (* copy_pointer_from_array)(void *ptr, unsigned long idx, const void *userp) __read_only;
69856 +int (* copy_sprole_pw)(struct sprole_pw *pw, unsigned long idx, const struct sprole_pw *userp) __read_only;
69857 +int (* copy_gr_hash_struct)(struct gr_hash_struct *hash, const struct gr_hash_struct *userp) __read_only;
69858 +int (* copy_role_transition)(struct role_transition *trans, const struct role_transition *userp) __read_only;
69859 +int (* copy_role_allowed_ip)(struct role_allowed_ip *roleip, const struct role_allowed_ip *userp) __read_only;
69860 +size_t (* get_gr_arg_wrapper_size)(void) __read_only;
69861 +
69862 +#else
69863 +#define copy_gr_arg_wrapper copy_gr_arg_wrapper_normal
69864 +#define copy_gr_arg copy_gr_arg_normal
69865 +#define copy_gr_hash_struct copy_gr_hash_struct_normal
69866 +#define copy_acl_object_label copy_acl_object_label_normal
69867 +#define copy_acl_subject_label copy_acl_subject_label_normal
69868 +#define copy_acl_role_label copy_acl_role_label_normal
69869 +#define copy_acl_ip_label copy_acl_ip_label_normal
69870 +#define copy_pointer_from_array copy_pointer_from_array_normal
69871 +#define copy_sprole_pw copy_sprole_pw_normal
69872 +#define copy_role_transition copy_role_transition_normal
69873 +#define copy_role_allowed_ip copy_role_allowed_ip_normal
69874 +#define get_gr_arg_wrapper_size get_gr_arg_wrapper_size_normal
69875 +#endif
69876 +
69877 +static struct acl_subject_label *
69878 +lookup_subject_map(const struct acl_subject_label *userp)
69879 +{
69880 + unsigned int index = gr_shash(userp, polstate->subj_map_set.s_size);
69881 + struct subject_map *match;
69882 +
69883 + match = polstate->subj_map_set.s_hash[index];
69884 +
69885 + while (match && match->user != userp)
69886 + match = match->next;
69887 +
69888 + if (match != NULL)
69889 + return match->kernel;
69890 + else
69891 + return NULL;
69892 +}
69893 +
69894 +static void
69895 +insert_subj_map_entry(struct subject_map *subjmap)
69896 +{
69897 + unsigned int index = gr_shash(subjmap->user, polstate->subj_map_set.s_size);
69898 + struct subject_map **curr;
69899 +
69900 + subjmap->prev = NULL;
69901 +
69902 + curr = &polstate->subj_map_set.s_hash[index];
69903 + if (*curr != NULL)
69904 + (*curr)->prev = subjmap;
69905 +
69906 + subjmap->next = *curr;
69907 + *curr = subjmap;
69908 +
69909 + return;
69910 +}
69911 +
69912 +static void
69913 +__insert_acl_role_label(struct acl_role_label *role, uid_t uidgid)
69914 +{
69915 + unsigned int index =
69916 + gr_rhash(uidgid, role->roletype & (GR_ROLE_USER | GR_ROLE_GROUP), polstate->acl_role_set.r_size);
69917 + struct acl_role_label **curr;
69918 + struct acl_role_label *tmp, *tmp2;
69919 +
69920 + curr = &polstate->acl_role_set.r_hash[index];
69921 +
69922 + /* simple case, slot is empty, just set it to our role */
69923 + if (*curr == NULL) {
69924 + *curr = role;
69925 + } else {
69926 + /* example:
69927 + 1 -> 2 -> 3 (adding 2 -> 3 to here)
69928 + 2 -> 3
69929 + */
69930 + /* first check to see if we can already be reached via this slot */
69931 + tmp = *curr;
69932 + while (tmp && tmp != role)
69933 + tmp = tmp->next;
69934 + if (tmp == role) {
69935 + /* we don't need to add ourselves to this slot's chain */
69936 + return;
69937 + }
69938 + /* we need to add ourselves to this chain, two cases */
69939 + if (role->next == NULL) {
69940 + /* simple case, append the current chain to our role */
69941 + role->next = *curr;
69942 + *curr = role;
69943 + } else {
69944 + /* 1 -> 2 -> 3 -> 4
69945 + 2 -> 3 -> 4
69946 + 3 -> 4 (adding 1 -> 2 -> 3 -> 4 to here)
69947 + */
69948 + /* trickier case: walk our role's chain until we find
69949 + the role for the start of the current slot's chain */
69950 + tmp = role;
69951 + tmp2 = *curr;
69952 + while (tmp->next && tmp->next != tmp2)
69953 + tmp = tmp->next;
69954 + if (tmp->next == tmp2) {
69955 + /* from example above, we found 3, so just
69956 + replace this slot's chain with ours */
69957 + *curr = role;
69958 + } else {
69959 + /* we didn't find a subset of our role's chain
69960 + in the current slot's chain, so append their
69961 + chain to ours, and set us as the first role in
69962 + the slot's chain
69963 +
69964 + we could fold this case with the case above,
69965 + but making it explicit for clarity
69966 + */
69967 + tmp->next = tmp2;
69968 + *curr = role;
69969 + }
69970 + }
69971 + }
69972 +
69973 + return;
69974 +}
69975 +
69976 +static void
69977 +insert_acl_role_label(struct acl_role_label *role)
69978 +{
69979 + int i;
69980 +
69981 + if (polstate->role_list == NULL) {
69982 + polstate->role_list = role;
69983 + role->prev = NULL;
69984 + } else {
69985 + role->prev = polstate->role_list;
69986 + polstate->role_list = role;
69987 + }
69988 +
69989 + /* used for hash chains */
69990 + role->next = NULL;
69991 +
69992 + if (role->roletype & GR_ROLE_DOMAIN) {
69993 + for (i = 0; i < role->domain_child_num; i++)
69994 + __insert_acl_role_label(role, role->domain_children[i]);
69995 + } else
69996 + __insert_acl_role_label(role, role->uidgid);
69997 +}
69998 +
69999 +static int
70000 +insert_name_entry(char *name, const ino_t inode, const dev_t device, __u8 deleted)
70001 +{
70002 + struct name_entry **curr, *nentry;
70003 + struct inodev_entry *ientry;
70004 + unsigned int len = strlen(name);
70005 + unsigned int key = full_name_hash(name, len);
70006 + unsigned int index = key % polstate->name_set.n_size;
70007 +
70008 + curr = &polstate->name_set.n_hash[index];
70009 +
70010 + while (*curr && ((*curr)->key != key || !gr_streq((*curr)->name, name, (*curr)->len, len)))
70011 + curr = &((*curr)->next);
70012 +
70013 + if (*curr != NULL)
70014 + return 1;
70015 +
70016 + nentry = acl_alloc(sizeof (struct name_entry));
70017 + if (nentry == NULL)
70018 + return 0;
70019 + ientry = acl_alloc(sizeof (struct inodev_entry));
70020 + if (ientry == NULL)
70021 + return 0;
70022 + ientry->nentry = nentry;
70023 +
70024 + nentry->key = key;
70025 + nentry->name = name;
70026 + nentry->inode = inode;
70027 + nentry->device = device;
70028 + nentry->len = len;
70029 + nentry->deleted = deleted;
70030 +
70031 + nentry->prev = NULL;
70032 + curr = &polstate->name_set.n_hash[index];
70033 + if (*curr != NULL)
70034 + (*curr)->prev = nentry;
70035 + nentry->next = *curr;
70036 + *curr = nentry;
70037 +
70038 + /* insert us into the table searchable by inode/dev */
70039 + __insert_inodev_entry(polstate, ientry);
70040 +
70041 + return 1;
70042 +}
70043 +
70044 +/* allocating chained hash tables, so optimal size is where lambda ~ 1 */
70045 +
70046 +static void *
70047 +create_table(__u32 * len, int elementsize)
70048 +{
70049 + unsigned int table_sizes[] = {
70050 + 7, 13, 31, 61, 127, 251, 509, 1021, 2039, 4093, 8191, 16381,
70051 + 32749, 65521, 131071, 262139, 524287, 1048573, 2097143,
70052 + 4194301, 8388593, 16777213, 33554393, 67108859
70053 + };
70054 + void *newtable = NULL;
70055 + unsigned int pwr = 0;
70056 +
70057 + while ((pwr < ((sizeof (table_sizes) / sizeof (table_sizes[0])) - 1)) &&
70058 + table_sizes[pwr] <= *len)
70059 + pwr++;
70060 +
70061 + if (table_sizes[pwr] <= *len || (table_sizes[pwr] > ULONG_MAX / elementsize))
70062 + return newtable;
70063 +
70064 + if ((table_sizes[pwr] * elementsize) <= PAGE_SIZE)
70065 + newtable =
70066 + kmalloc(table_sizes[pwr] * elementsize, GFP_KERNEL);
70067 + else
70068 + newtable = vmalloc(table_sizes[pwr] * elementsize);
70069 +
70070 + *len = table_sizes[pwr];
70071 +
70072 + return newtable;
70073 +}
70074 +
70075 +static int
70076 +init_variables(const struct gr_arg *arg, bool reload)
70077 +{
70078 + struct task_struct *reaper = init_pid_ns.child_reaper;
70079 + unsigned int stacksize;
70080 +
70081 + polstate->subj_map_set.s_size = arg->role_db.num_subjects;
70082 + polstate->acl_role_set.r_size = arg->role_db.num_roles + arg->role_db.num_domain_children;
70083 + polstate->name_set.n_size = arg->role_db.num_objects;
70084 + polstate->inodev_set.i_size = arg->role_db.num_objects;
70085 +
70086 + if (!polstate->subj_map_set.s_size || !polstate->acl_role_set.r_size ||
70087 + !polstate->name_set.n_size || !polstate->inodev_set.i_size)
70088 + return 1;
70089 +
70090 + if (!reload) {
70091 + if (!gr_init_uidset())
70092 + return 1;
70093 + }
70094 +
70095 + /* set up the stack that holds allocation info */
70096 +
70097 + stacksize = arg->role_db.num_pointers + 5;
70098 +
70099 + if (!acl_alloc_stack_init(stacksize))
70100 + return 1;
70101 +
70102 + if (!reload) {
70103 + /* grab reference for the real root dentry and vfsmount */
70104 + get_fs_root(reaper->fs, &gr_real_root);
70105 +
70106 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70107 + 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);
70108 +#endif
70109 +
70110 + fakefs_obj_rw = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
70111 + if (fakefs_obj_rw == NULL)
70112 + return 1;
70113 + fakefs_obj_rw->mode = GR_FIND | GR_READ | GR_WRITE;
70114 +
70115 + fakefs_obj_rwx = kzalloc(sizeof(struct acl_object_label), GFP_KERNEL);
70116 + if (fakefs_obj_rwx == NULL)
70117 + return 1;
70118 + fakefs_obj_rwx->mode = GR_FIND | GR_READ | GR_WRITE | GR_EXEC;
70119 + }
70120 +
70121 + polstate->subj_map_set.s_hash =
70122 + (struct subject_map **) create_table(&polstate->subj_map_set.s_size, sizeof(void *));
70123 + polstate->acl_role_set.r_hash =
70124 + (struct acl_role_label **) create_table(&polstate->acl_role_set.r_size, sizeof(void *));
70125 + polstate->name_set.n_hash = (struct name_entry **) create_table(&polstate->name_set.n_size, sizeof(void *));
70126 + polstate->inodev_set.i_hash =
70127 + (struct inodev_entry **) create_table(&polstate->inodev_set.i_size, sizeof(void *));
70128 +
70129 + if (!polstate->subj_map_set.s_hash || !polstate->acl_role_set.r_hash ||
70130 + !polstate->name_set.n_hash || !polstate->inodev_set.i_hash)
70131 + return 1;
70132 +
70133 + memset(polstate->subj_map_set.s_hash, 0,
70134 + sizeof(struct subject_map *) * polstate->subj_map_set.s_size);
70135 + memset(polstate->acl_role_set.r_hash, 0,
70136 + sizeof (struct acl_role_label *) * polstate->acl_role_set.r_size);
70137 + memset(polstate->name_set.n_hash, 0,
70138 + sizeof (struct name_entry *) * polstate->name_set.n_size);
70139 + memset(polstate->inodev_set.i_hash, 0,
70140 + sizeof (struct inodev_entry *) * polstate->inodev_set.i_size);
70141 +
70142 + return 0;
70143 +}
70144 +
70145 +/* free information not needed after startup
70146 + currently contains user->kernel pointer mappings for subjects
70147 +*/
70148 +
70149 +static void
70150 +free_init_variables(void)
70151 +{
70152 + __u32 i;
70153 +
70154 + if (polstate->subj_map_set.s_hash) {
70155 + for (i = 0; i < polstate->subj_map_set.s_size; i++) {
70156 + if (polstate->subj_map_set.s_hash[i]) {
70157 + kfree(polstate->subj_map_set.s_hash[i]);
70158 + polstate->subj_map_set.s_hash[i] = NULL;
70159 + }
70160 + }
70161 +
70162 + if ((polstate->subj_map_set.s_size * sizeof (struct subject_map *)) <=
70163 + PAGE_SIZE)
70164 + kfree(polstate->subj_map_set.s_hash);
70165 + else
70166 + vfree(polstate->subj_map_set.s_hash);
70167 + }
70168 +
70169 + return;
70170 +}
70171 +
70172 +static void
70173 +free_variables(bool reload)
70174 +{
70175 + struct acl_subject_label *s;
70176 + struct acl_role_label *r;
70177 + struct task_struct *task, *task2;
70178 + unsigned int x;
70179 +
70180 + if (!reload) {
70181 + gr_clear_learn_entries();
70182 +
70183 + read_lock(&tasklist_lock);
70184 + do_each_thread(task2, task) {
70185 + task->acl_sp_role = 0;
70186 + task->acl_role_id = 0;
70187 + task->inherited = 0;
70188 + task->acl = NULL;
70189 + task->role = NULL;
70190 + } while_each_thread(task2, task);
70191 + read_unlock(&tasklist_lock);
70192 +
70193 + kfree(fakefs_obj_rw);
70194 + fakefs_obj_rw = NULL;
70195 + kfree(fakefs_obj_rwx);
70196 + fakefs_obj_rwx = NULL;
70197 +
70198 + /* release the reference to the real root dentry and vfsmount */
70199 + path_put(&gr_real_root);
70200 + memset(&gr_real_root, 0, sizeof(gr_real_root));
70201 + }
70202 +
70203 + /* free all object hash tables */
70204 +
70205 + FOR_EACH_ROLE_START(r)
70206 + if (r->subj_hash == NULL)
70207 + goto next_role;
70208 + FOR_EACH_SUBJECT_START(r, s, x)
70209 + if (s->obj_hash == NULL)
70210 + break;
70211 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
70212 + kfree(s->obj_hash);
70213 + else
70214 + vfree(s->obj_hash);
70215 + FOR_EACH_SUBJECT_END(s, x)
70216 + FOR_EACH_NESTED_SUBJECT_START(r, s)
70217 + if (s->obj_hash == NULL)
70218 + break;
70219 + if ((s->obj_hash_size * sizeof (struct acl_object_label *)) <= PAGE_SIZE)
70220 + kfree(s->obj_hash);
70221 + else
70222 + vfree(s->obj_hash);
70223 + FOR_EACH_NESTED_SUBJECT_END(s)
70224 + if ((r->subj_hash_size * sizeof (struct acl_subject_label *)) <= PAGE_SIZE)
70225 + kfree(r->subj_hash);
70226 + else
70227 + vfree(r->subj_hash);
70228 + r->subj_hash = NULL;
70229 +next_role:
70230 + FOR_EACH_ROLE_END(r)
70231 +
70232 + acl_free_all();
70233 +
70234 + if (polstate->acl_role_set.r_hash) {
70235 + if ((polstate->acl_role_set.r_size * sizeof (struct acl_role_label *)) <=
70236 + PAGE_SIZE)
70237 + kfree(polstate->acl_role_set.r_hash);
70238 + else
70239 + vfree(polstate->acl_role_set.r_hash);
70240 + }
70241 + if (polstate->name_set.n_hash) {
70242 + if ((polstate->name_set.n_size * sizeof (struct name_entry *)) <=
70243 + PAGE_SIZE)
70244 + kfree(polstate->name_set.n_hash);
70245 + else
70246 + vfree(polstate->name_set.n_hash);
70247 + }
70248 +
70249 + if (polstate->inodev_set.i_hash) {
70250 + if ((polstate->inodev_set.i_size * sizeof (struct inodev_entry *)) <=
70251 + PAGE_SIZE)
70252 + kfree(polstate->inodev_set.i_hash);
70253 + else
70254 + vfree(polstate->inodev_set.i_hash);
70255 + }
70256 +
70257 + if (!reload)
70258 + gr_free_uidset();
70259 +
70260 + memset(&polstate->name_set, 0, sizeof (struct name_db));
70261 + memset(&polstate->inodev_set, 0, sizeof (struct inodev_db));
70262 + memset(&polstate->acl_role_set, 0, sizeof (struct acl_role_db));
70263 + memset(&polstate->subj_map_set, 0, sizeof (struct acl_subj_map_db));
70264 +
70265 + polstate->default_role = NULL;
70266 + polstate->kernel_role = NULL;
70267 + polstate->role_list = NULL;
70268 +
70269 + return;
70270 +}
70271 +
70272 +static struct acl_subject_label *
70273 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied);
70274 +
70275 +static int alloc_and_copy_string(char **name, unsigned int maxlen)
70276 +{
70277 + unsigned int len = strnlen_user(*name, maxlen);
70278 + char *tmp;
70279 +
70280 + if (!len || len >= maxlen)
70281 + return -EINVAL;
70282 +
70283 + if ((tmp = (char *) acl_alloc(len)) == NULL)
70284 + return -ENOMEM;
70285 +
70286 + if (copy_from_user(tmp, *name, len))
70287 + return -EFAULT;
70288 +
70289 + tmp[len-1] = '\0';
70290 + *name = tmp;
70291 +
70292 + return 0;
70293 +}
70294 +
70295 +static int
70296 +copy_user_glob(struct acl_object_label *obj)
70297 +{
70298 + struct acl_object_label *g_tmp, **guser;
70299 + int error;
70300 +
70301 + if (obj->globbed == NULL)
70302 + return 0;
70303 +
70304 + guser = &obj->globbed;
70305 + while (*guser) {
70306 + g_tmp = (struct acl_object_label *)
70307 + acl_alloc(sizeof (struct acl_object_label));
70308 + if (g_tmp == NULL)
70309 + return -ENOMEM;
70310 +
70311 + if (copy_acl_object_label(g_tmp, *guser))
70312 + return -EFAULT;
70313 +
70314 + error = alloc_and_copy_string(&g_tmp->filename, PATH_MAX);
70315 + if (error)
70316 + return error;
70317 +
70318 + *guser = g_tmp;
70319 + guser = &(g_tmp->next);
70320 + }
70321 +
70322 + return 0;
70323 +}
70324 +
70325 +static int
70326 +copy_user_objs(struct acl_object_label *userp, struct acl_subject_label *subj,
70327 + struct acl_role_label *role)
70328 +{
70329 + struct acl_object_label *o_tmp;
70330 + int ret;
70331 +
70332 + while (userp) {
70333 + if ((o_tmp = (struct acl_object_label *)
70334 + acl_alloc(sizeof (struct acl_object_label))) == NULL)
70335 + return -ENOMEM;
70336 +
70337 + if (copy_acl_object_label(o_tmp, userp))
70338 + return -EFAULT;
70339 +
70340 + userp = o_tmp->prev;
70341 +
70342 + ret = alloc_and_copy_string(&o_tmp->filename, PATH_MAX);
70343 + if (ret)
70344 + return ret;
70345 +
70346 + insert_acl_obj_label(o_tmp, subj);
70347 + if (!insert_name_entry(o_tmp->filename, o_tmp->inode,
70348 + o_tmp->device, (o_tmp->mode & GR_DELETED) ? 1 : 0))
70349 + return -ENOMEM;
70350 +
70351 + ret = copy_user_glob(o_tmp);
70352 + if (ret)
70353 + return ret;
70354 +
70355 + if (o_tmp->nested) {
70356 + int already_copied;
70357 +
70358 + o_tmp->nested = do_copy_user_subj(o_tmp->nested, role, &already_copied);
70359 + if (IS_ERR(o_tmp->nested))
70360 + return PTR_ERR(o_tmp->nested);
70361 +
70362 + /* insert into nested subject list if we haven't copied this one yet
70363 + to prevent duplicate entries */
70364 + if (!already_copied) {
70365 + o_tmp->nested->next = role->hash->first;
70366 + role->hash->first = o_tmp->nested;
70367 + }
70368 + }
70369 + }
70370 +
70371 + return 0;
70372 +}
70373 +
70374 +static __u32
70375 +count_user_subjs(struct acl_subject_label *userp)
70376 +{
70377 + struct acl_subject_label s_tmp;
70378 + __u32 num = 0;
70379 +
70380 + while (userp) {
70381 + if (copy_acl_subject_label(&s_tmp, userp))
70382 + break;
70383 +
70384 + userp = s_tmp.prev;
70385 + }
70386 +
70387 + return num;
70388 +}
70389 +
70390 +static int
70391 +copy_user_allowedips(struct acl_role_label *rolep)
70392 +{
70393 + struct role_allowed_ip *ruserip, *rtmp = NULL, *rlast;
70394 +
70395 + ruserip = rolep->allowed_ips;
70396 +
70397 + while (ruserip) {
70398 + rlast = rtmp;
70399 +
70400 + if ((rtmp = (struct role_allowed_ip *)
70401 + acl_alloc(sizeof (struct role_allowed_ip))) == NULL)
70402 + return -ENOMEM;
70403 +
70404 + if (copy_role_allowed_ip(rtmp, ruserip))
70405 + return -EFAULT;
70406 +
70407 + ruserip = rtmp->prev;
70408 +
70409 + if (!rlast) {
70410 + rtmp->prev = NULL;
70411 + rolep->allowed_ips = rtmp;
70412 + } else {
70413 + rlast->next = rtmp;
70414 + rtmp->prev = rlast;
70415 + }
70416 +
70417 + if (!ruserip)
70418 + rtmp->next = NULL;
70419 + }
70420 +
70421 + return 0;
70422 +}
70423 +
70424 +static int
70425 +copy_user_transitions(struct acl_role_label *rolep)
70426 +{
70427 + struct role_transition *rusertp, *rtmp = NULL, *rlast;
70428 + int error;
70429 +
70430 + rusertp = rolep->transitions;
70431 +
70432 + while (rusertp) {
70433 + rlast = rtmp;
70434 +
70435 + if ((rtmp = (struct role_transition *)
70436 + acl_alloc(sizeof (struct role_transition))) == NULL)
70437 + return -ENOMEM;
70438 +
70439 + if (copy_role_transition(rtmp, rusertp))
70440 + return -EFAULT;
70441 +
70442 + rusertp = rtmp->prev;
70443 +
70444 + error = alloc_and_copy_string(&rtmp->rolename, GR_SPROLE_LEN);
70445 + if (error)
70446 + return error;
70447 +
70448 + if (!rlast) {
70449 + rtmp->prev = NULL;
70450 + rolep->transitions = rtmp;
70451 + } else {
70452 + rlast->next = rtmp;
70453 + rtmp->prev = rlast;
70454 + }
70455 +
70456 + if (!rusertp)
70457 + rtmp->next = NULL;
70458 + }
70459 +
70460 + return 0;
70461 +}
70462 +
70463 +static __u32 count_user_objs(const struct acl_object_label __user *userp)
70464 +{
70465 + struct acl_object_label o_tmp;
70466 + __u32 num = 0;
70467 +
70468 + while (userp) {
70469 + if (copy_acl_object_label(&o_tmp, userp))
70470 + break;
70471 +
70472 + userp = o_tmp.prev;
70473 + num++;
70474 + }
70475 +
70476 + return num;
70477 +}
70478 +
70479 +static struct acl_subject_label *
70480 +do_copy_user_subj(struct acl_subject_label *userp, struct acl_role_label *role, int *already_copied)
70481 +{
70482 + struct acl_subject_label *s_tmp = NULL, *s_tmp2;
70483 + __u32 num_objs;
70484 + struct acl_ip_label **i_tmp, *i_utmp2;
70485 + struct gr_hash_struct ghash;
70486 + struct subject_map *subjmap;
70487 + unsigned int i_num;
70488 + int err;
70489 +
70490 + if (already_copied != NULL)
70491 + *already_copied = 0;
70492 +
70493 + s_tmp = lookup_subject_map(userp);
70494 +
70495 + /* we've already copied this subject into the kernel, just return
70496 + the reference to it, and don't copy it over again
70497 + */
70498 + if (s_tmp) {
70499 + if (already_copied != NULL)
70500 + *already_copied = 1;
70501 + return(s_tmp);
70502 + }
70503 +
70504 + if ((s_tmp = (struct acl_subject_label *)
70505 + acl_alloc(sizeof (struct acl_subject_label))) == NULL)
70506 + return ERR_PTR(-ENOMEM);
70507 +
70508 + subjmap = (struct subject_map *)kmalloc(sizeof (struct subject_map), GFP_KERNEL);
70509 + if (subjmap == NULL)
70510 + return ERR_PTR(-ENOMEM);
70511 +
70512 + subjmap->user = userp;
70513 + subjmap->kernel = s_tmp;
70514 + insert_subj_map_entry(subjmap);
70515 +
70516 + if (copy_acl_subject_label(s_tmp, userp))
70517 + return ERR_PTR(-EFAULT);
70518 +
70519 + err = alloc_and_copy_string(&s_tmp->filename, PATH_MAX);
70520 + if (err)
70521 + return ERR_PTR(err);
70522 +
70523 + if (!strcmp(s_tmp->filename, "/"))
70524 + role->root_label = s_tmp;
70525 +
70526 + if (copy_gr_hash_struct(&ghash, s_tmp->hash))
70527 + return ERR_PTR(-EFAULT);
70528 +
70529 + /* copy user and group transition tables */
70530 +
70531 + if (s_tmp->user_trans_num) {
70532 + uid_t *uidlist;
70533 +
70534 + uidlist = (uid_t *)acl_alloc_num(s_tmp->user_trans_num, sizeof(uid_t));
70535 + if (uidlist == NULL)
70536 + return ERR_PTR(-ENOMEM);
70537 + if (copy_from_user(uidlist, s_tmp->user_transitions, s_tmp->user_trans_num * sizeof(uid_t)))
70538 + return ERR_PTR(-EFAULT);
70539 +
70540 + s_tmp->user_transitions = uidlist;
70541 + }
70542 +
70543 + if (s_tmp->group_trans_num) {
70544 + gid_t *gidlist;
70545 +
70546 + gidlist = (gid_t *)acl_alloc_num(s_tmp->group_trans_num, sizeof(gid_t));
70547 + if (gidlist == NULL)
70548 + return ERR_PTR(-ENOMEM);
70549 + if (copy_from_user(gidlist, s_tmp->group_transitions, s_tmp->group_trans_num * sizeof(gid_t)))
70550 + return ERR_PTR(-EFAULT);
70551 +
70552 + s_tmp->group_transitions = gidlist;
70553 + }
70554 +
70555 + /* set up object hash table */
70556 + num_objs = count_user_objs(ghash.first);
70557 +
70558 + s_tmp->obj_hash_size = num_objs;
70559 + s_tmp->obj_hash =
70560 + (struct acl_object_label **)
70561 + create_table(&(s_tmp->obj_hash_size), sizeof(void *));
70562 +
70563 + if (!s_tmp->obj_hash)
70564 + return ERR_PTR(-ENOMEM);
70565 +
70566 + memset(s_tmp->obj_hash, 0,
70567 + s_tmp->obj_hash_size *
70568 + sizeof (struct acl_object_label *));
70569 +
70570 + /* add in objects */
70571 + err = copy_user_objs(ghash.first, s_tmp, role);
70572 +
70573 + if (err)
70574 + return ERR_PTR(err);
70575 +
70576 + /* set pointer for parent subject */
70577 + if (s_tmp->parent_subject) {
70578 + s_tmp2 = do_copy_user_subj(s_tmp->parent_subject, role, NULL);
70579 +
70580 + if (IS_ERR(s_tmp2))
70581 + return s_tmp2;
70582 +
70583 + s_tmp->parent_subject = s_tmp2;
70584 + }
70585 +
70586 + /* add in ip acls */
70587 +
70588 + if (!s_tmp->ip_num) {
70589 + s_tmp->ips = NULL;
70590 + goto insert;
70591 + }
70592 +
70593 + i_tmp =
70594 + (struct acl_ip_label **) acl_alloc_num(s_tmp->ip_num,
70595 + sizeof (struct acl_ip_label *));
70596 +
70597 + if (!i_tmp)
70598 + return ERR_PTR(-ENOMEM);
70599 +
70600 + for (i_num = 0; i_num < s_tmp->ip_num; i_num++) {
70601 + *(i_tmp + i_num) =
70602 + (struct acl_ip_label *)
70603 + acl_alloc(sizeof (struct acl_ip_label));
70604 + if (!*(i_tmp + i_num))
70605 + return ERR_PTR(-ENOMEM);
70606 +
70607 + if (copy_pointer_from_array(&i_utmp2, i_num, s_tmp->ips))
70608 + return ERR_PTR(-EFAULT);
70609 +
70610 + if (copy_acl_ip_label(*(i_tmp + i_num), i_utmp2))
70611 + return ERR_PTR(-EFAULT);
70612 +
70613 + if ((*(i_tmp + i_num))->iface == NULL)
70614 + continue;
70615 +
70616 + err = alloc_and_copy_string(&(*(i_tmp + i_num))->iface, IFNAMSIZ);
70617 + if (err)
70618 + return ERR_PTR(err);
70619 + }
70620 +
70621 + s_tmp->ips = i_tmp;
70622 +
70623 +insert:
70624 + if (!insert_name_entry(s_tmp->filename, s_tmp->inode,
70625 + s_tmp->device, (s_tmp->mode & GR_DELETED) ? 1 : 0))
70626 + return ERR_PTR(-ENOMEM);
70627 +
70628 + return s_tmp;
70629 +}
70630 +
70631 +static int
70632 +copy_user_subjs(struct acl_subject_label *userp, struct acl_role_label *role)
70633 +{
70634 + struct acl_subject_label s_pre;
70635 + struct acl_subject_label * ret;
70636 + int err;
70637 +
70638 + while (userp) {
70639 + if (copy_acl_subject_label(&s_pre, userp))
70640 + return -EFAULT;
70641 +
70642 + ret = do_copy_user_subj(userp, role, NULL);
70643 +
70644 + err = PTR_ERR(ret);
70645 + if (IS_ERR(ret))
70646 + return err;
70647 +
70648 + insert_acl_subj_label(ret, role);
70649 +
70650 + userp = s_pre.prev;
70651 + }
70652 +
70653 + return 0;
70654 +}
70655 +
70656 +static int
70657 +copy_user_acl(struct gr_arg *arg)
70658 +{
70659 + struct acl_role_label *r_tmp = NULL, **r_utmp, *r_utmp2;
70660 + struct acl_subject_label *subj_list;
70661 + struct sprole_pw *sptmp;
70662 + struct gr_hash_struct *ghash;
70663 + uid_t *domainlist;
70664 + unsigned int r_num;
70665 + int err = 0;
70666 + __u16 i;
70667 + __u32 num_subjs;
70668 +
70669 + /* we need a default and kernel role */
70670 + if (arg->role_db.num_roles < 2)
70671 + return -EINVAL;
70672 +
70673 + /* copy special role authentication info from userspace */
70674 +
70675 + polstate->num_sprole_pws = arg->num_sprole_pws;
70676 + polstate->acl_special_roles = (struct sprole_pw **) acl_alloc_num(polstate->num_sprole_pws, sizeof(struct sprole_pw *));
70677 +
70678 + if (!polstate->acl_special_roles && polstate->num_sprole_pws)
70679 + return -ENOMEM;
70680 +
70681 + for (i = 0; i < polstate->num_sprole_pws; i++) {
70682 + sptmp = (struct sprole_pw *) acl_alloc(sizeof(struct sprole_pw));
70683 + if (!sptmp)
70684 + return -ENOMEM;
70685 + if (copy_sprole_pw(sptmp, i, arg->sprole_pws))
70686 + return -EFAULT;
70687 +
70688 + err = alloc_and_copy_string((char **)&sptmp->rolename, GR_SPROLE_LEN);
70689 + if (err)
70690 + return err;
70691 +
70692 +#ifdef CONFIG_GRKERNSEC_RBAC_DEBUG
70693 + printk(KERN_ALERT "Copying special role %s\n", sptmp->rolename);
70694 +#endif
70695 +
70696 + polstate->acl_special_roles[i] = sptmp;
70697 + }
70698 +
70699 + r_utmp = (struct acl_role_label **) arg->role_db.r_table;
70700 +
70701 + for (r_num = 0; r_num < arg->role_db.num_roles; r_num++) {
70702 + r_tmp = acl_alloc(sizeof (struct acl_role_label));
70703 +
70704 + if (!r_tmp)
70705 + return -ENOMEM;
70706 +
70707 + if (copy_pointer_from_array(&r_utmp2, r_num, r_utmp))
70708 + return -EFAULT;
70709 +
70710 + if (copy_acl_role_label(r_tmp, r_utmp2))
70711 + return -EFAULT;
70712 +
70713 + err = alloc_and_copy_string(&r_tmp->rolename, GR_SPROLE_LEN);
70714 + if (err)
70715 + return err;
70716 +
70717 + if (!strcmp(r_tmp->rolename, "default")
70718 + && (r_tmp->roletype & GR_ROLE_DEFAULT)) {
70719 + polstate->default_role = r_tmp;
70720 + } else if (!strcmp(r_tmp->rolename, ":::kernel:::")) {
70721 + polstate->kernel_role = r_tmp;
70722 + }
70723 +
70724 + if ((ghash = (struct gr_hash_struct *) acl_alloc(sizeof(struct gr_hash_struct))) == NULL)
70725 + return -ENOMEM;
70726 +
70727 + if (copy_gr_hash_struct(ghash, r_tmp->hash))
70728 + return -EFAULT;
70729 +
70730 + r_tmp->hash = ghash;
70731 +
70732 + num_subjs = count_user_subjs(r_tmp->hash->first);
70733 +
70734 + r_tmp->subj_hash_size = num_subjs;
70735 + r_tmp->subj_hash =
70736 + (struct acl_subject_label **)
70737 + create_table(&(r_tmp->subj_hash_size), sizeof(void *));
70738 +
70739 + if (!r_tmp->subj_hash)
70740 + return -ENOMEM;
70741 +
70742 + err = copy_user_allowedips(r_tmp);
70743 + if (err)
70744 + return err;
70745 +
70746 + /* copy domain info */
70747 + if (r_tmp->domain_children != NULL) {
70748 + domainlist = acl_alloc_num(r_tmp->domain_child_num, sizeof(uid_t));
70749 + if (domainlist == NULL)
70750 + return -ENOMEM;
70751 +
70752 + if (copy_from_user(domainlist, r_tmp->domain_children, r_tmp->domain_child_num * sizeof(uid_t)))
70753 + return -EFAULT;
70754 +
70755 + r_tmp->domain_children = domainlist;
70756 + }
70757 +
70758 + err = copy_user_transitions(r_tmp);
70759 + if (err)
70760 + return err;
70761 +
70762 + memset(r_tmp->subj_hash, 0,
70763 + r_tmp->subj_hash_size *
70764 + sizeof (struct acl_subject_label *));
70765 +
70766 + /* acquire the list of subjects, then NULL out
70767 + the list prior to parsing the subjects for this role,
70768 + as during this parsing the list is replaced with a list
70769 + of *nested* subjects for the role
70770 + */
70771 + subj_list = r_tmp->hash->first;
70772 +
70773 + /* set nested subject list to null */
70774 + r_tmp->hash->first = NULL;
70775 +
70776 + err = copy_user_subjs(subj_list, r_tmp);
70777 +
70778 + if (err)
70779 + return err;
70780 +
70781 + insert_acl_role_label(r_tmp);
70782 + }
70783 +
70784 + if (polstate->default_role == NULL || polstate->kernel_role == NULL)
70785 + return -EINVAL;
70786 +
70787 + return err;
70788 +}
70789 +
70790 +static int gracl_reload_apply_policies(void *reload)
70791 +{
70792 + struct gr_reload_state *reload_state = (struct gr_reload_state *)reload;
70793 + struct task_struct *task, *task2;
70794 + struct acl_role_label *role, *rtmp;
70795 + struct acl_subject_label *subj;
70796 + const struct cred *cred;
70797 + int role_applied;
70798 + int ret = 0;
70799 +
70800 + memcpy(&reload_state->oldpolicy, reload_state->oldpolicy_ptr, sizeof(struct gr_policy_state));
70801 + memcpy(&reload_state->oldalloc, reload_state->oldalloc_ptr, sizeof(struct gr_alloc_state));
70802 +
70803 + /* first make sure we'll be able to apply the new policy cleanly */
70804 + do_each_thread(task2, task) {
70805 + if (task->exec_file == NULL)
70806 + continue;
70807 + role_applied = 0;
70808 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
70809 + /* preserve special roles */
70810 + FOR_EACH_ROLE_START(role)
70811 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
70812 + rtmp = task->role;
70813 + task->role = role;
70814 + role_applied = 1;
70815 + break;
70816 + }
70817 + FOR_EACH_ROLE_END(role)
70818 + }
70819 + if (!role_applied) {
70820 + cred = __task_cred(task);
70821 + rtmp = task->role;
70822 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
70823 + }
70824 + /* this handles non-nested inherited subjects, nested subjects will still
70825 + be dropped currently */
70826 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
70827 + task->tmpacl = __gr_get_subject_for_task(polstate, task, NULL);
70828 + /* change the role back so that we've made no modifications to the policy */
70829 + task->role = rtmp;
70830 +
70831 + if (subj == NULL || task->tmpacl == NULL) {
70832 + ret = -EINVAL;
70833 + goto out;
70834 + }
70835 + } while_each_thread(task2, task);
70836 +
70837 + /* now actually apply the policy */
70838 +
70839 + do_each_thread(task2, task) {
70840 + if (task->exec_file) {
70841 + role_applied = 0;
70842 + if (!reload_state->oldmode && task->role->roletype & GR_ROLE_SPECIAL) {
70843 + /* preserve special roles */
70844 + FOR_EACH_ROLE_START(role)
70845 + if ((role->roletype & GR_ROLE_SPECIAL) && !strcmp(task->role->rolename, role->rolename)) {
70846 + task->role = role;
70847 + role_applied = 1;
70848 + break;
70849 + }
70850 + FOR_EACH_ROLE_END(role)
70851 + }
70852 + if (!role_applied) {
70853 + cred = __task_cred(task);
70854 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
70855 + }
70856 + /* this handles non-nested inherited subjects, nested subjects will still
70857 + be dropped currently */
70858 + if (!reload_state->oldmode && task->inherited)
70859 + subj = __gr_get_subject_for_task(polstate, task, task->acl->filename);
70860 + else {
70861 + /* looked up and tagged to the task previously */
70862 + subj = task->tmpacl;
70863 + }
70864 + /* subj will be non-null */
70865 + __gr_apply_subject_to_task(polstate, task, subj);
70866 + if (reload_state->oldmode) {
70867 + task->acl_role_id = 0;
70868 + task->acl_sp_role = 0;
70869 + task->inherited = 0;
70870 + }
70871 + } else {
70872 + // it's a kernel process
70873 + task->role = polstate->kernel_role;
70874 + task->acl = polstate->kernel_role->root_label;
70875 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
70876 + task->acl->mode &= ~GR_PROCFIND;
70877 +#endif
70878 + }
70879 + } while_each_thread(task2, task);
70880 +
70881 + memcpy(reload_state->oldpolicy_ptr, &reload_state->newpolicy, sizeof(struct gr_policy_state));
70882 + memcpy(reload_state->oldalloc_ptr, &reload_state->newalloc, sizeof(struct gr_alloc_state));
70883 +
70884 +out:
70885 +
70886 + return ret;
70887 +}
70888 +
70889 +static int gracl_reload(struct gr_arg *args, unsigned char oldmode)
70890 +{
70891 + struct gr_reload_state new_reload_state = { };
70892 + int err;
70893 +
70894 + new_reload_state.oldpolicy_ptr = polstate;
70895 + new_reload_state.oldalloc_ptr = current_alloc_state;
70896 + new_reload_state.oldmode = oldmode;
70897 +
70898 + current_alloc_state = &new_reload_state.newalloc;
70899 + polstate = &new_reload_state.newpolicy;
70900 +
70901 + /* everything relevant is now saved off, copy in the new policy */
70902 + if (init_variables(args, true)) {
70903 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
70904 + err = -ENOMEM;
70905 + goto error;
70906 + }
70907 +
70908 + err = copy_user_acl(args);
70909 + free_init_variables();
70910 + if (err)
70911 + goto error;
70912 + /* the new policy is copied in, with the old policy available via saved_state
70913 + first go through applying roles, making sure to preserve special roles
70914 + then apply new subjects, making sure to preserve inherited and nested subjects,
70915 + though currently only inherited subjects will be preserved
70916 + */
70917 + err = stop_machine(gracl_reload_apply_policies, &new_reload_state, NULL);
70918 + if (err)
70919 + goto error;
70920 +
70921 + /* we've now applied the new policy, so restore the old policy state to free it */
70922 + polstate = &new_reload_state.oldpolicy;
70923 + current_alloc_state = &new_reload_state.oldalloc;
70924 + free_variables(true);
70925 +
70926 + /* oldpolicy/oldalloc_ptr point to the new policy/alloc states as they were copied
70927 + to running_polstate/current_alloc_state inside stop_machine
70928 + */
70929 + err = 0;
70930 + goto out;
70931 +error:
70932 + /* on error of loading the new policy, we'll just keep the previous
70933 + policy set around
70934 + */
70935 + free_variables(true);
70936 +
70937 + /* doesn't affect runtime, but maintains consistent state */
70938 +out:
70939 + polstate = new_reload_state.oldpolicy_ptr;
70940 + current_alloc_state = new_reload_state.oldalloc_ptr;
70941 +
70942 + return err;
70943 +}
70944 +
70945 +static int
70946 +gracl_init(struct gr_arg *args)
70947 +{
70948 + int error = 0;
70949 +
70950 + memcpy(&gr_system_salt, args->salt, sizeof(gr_system_salt));
70951 + memcpy(&gr_system_sum, args->sum, sizeof(gr_system_sum));
70952 +
70953 + if (init_variables(args, false)) {
70954 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_INITF_ACL_MSG, GR_VERSION);
70955 + error = -ENOMEM;
70956 + goto out;
70957 + }
70958 +
70959 + error = copy_user_acl(args);
70960 + free_init_variables();
70961 + if (error)
70962 + goto out;
70963 +
70964 + error = gr_set_acls(0);
70965 + if (error)
70966 + goto out;
70967 +
70968 + gr_enable_rbac_system();
70969 +
70970 + return 0;
70971 +
70972 +out:
70973 + free_variables(false);
70974 + return error;
70975 +}
70976 +
70977 +static int
70978 +lookup_special_role_auth(__u16 mode, const char *rolename, unsigned char **salt,
70979 + unsigned char **sum)
70980 +{
70981 + struct acl_role_label *r;
70982 + struct role_allowed_ip *ipp;
70983 + struct role_transition *trans;
70984 + unsigned int i;
70985 + int found = 0;
70986 + u32 curr_ip = current->signal->curr_ip;
70987 +
70988 + current->signal->saved_ip = curr_ip;
70989 +
70990 + /* check transition table */
70991 +
70992 + for (trans = current->role->transitions; trans; trans = trans->next) {
70993 + if (!strcmp(rolename, trans->rolename)) {
70994 + found = 1;
70995 + break;
70996 + }
70997 + }
70998 +
70999 + if (!found)
71000 + return 0;
71001 +
71002 + /* handle special roles that do not require authentication
71003 + and check ip */
71004 +
71005 + FOR_EACH_ROLE_START(r)
71006 + if (!strcmp(rolename, r->rolename) &&
71007 + (r->roletype & GR_ROLE_SPECIAL)) {
71008 + found = 0;
71009 + if (r->allowed_ips != NULL) {
71010 + for (ipp = r->allowed_ips; ipp; ipp = ipp->next) {
71011 + if ((ntohl(curr_ip) & ipp->netmask) ==
71012 + (ntohl(ipp->addr) & ipp->netmask))
71013 + found = 1;
71014 + }
71015 + } else
71016 + found = 2;
71017 + if (!found)
71018 + return 0;
71019 +
71020 + if (((mode == GR_SPROLE) && (r->roletype & GR_ROLE_NOPW)) ||
71021 + ((mode == GR_SPROLEPAM) && (r->roletype & GR_ROLE_PAM))) {
71022 + *salt = NULL;
71023 + *sum = NULL;
71024 + return 1;
71025 + }
71026 + }
71027 + FOR_EACH_ROLE_END(r)
71028 +
71029 + for (i = 0; i < polstate->num_sprole_pws; i++) {
71030 + if (!strcmp(rolename, polstate->acl_special_roles[i]->rolename)) {
71031 + *salt = polstate->acl_special_roles[i]->salt;
71032 + *sum = polstate->acl_special_roles[i]->sum;
71033 + return 1;
71034 + }
71035 + }
71036 +
71037 + return 0;
71038 +}
71039 +
71040 +int gr_check_secure_terminal(struct task_struct *task)
71041 +{
71042 + struct task_struct *p, *p2, *p3;
71043 + struct files_struct *files;
71044 + struct fdtable *fdt;
71045 + struct file *our_file = NULL, *file;
71046 + int i;
71047 +
71048 + if (task->signal->tty == NULL)
71049 + return 1;
71050 +
71051 + files = get_files_struct(task);
71052 + if (files != NULL) {
71053 + rcu_read_lock();
71054 + fdt = files_fdtable(files);
71055 + for (i=0; i < fdt->max_fds; i++) {
71056 + file = fcheck_files(files, i);
71057 + if (file && (our_file == NULL) && (file->private_data == task->signal->tty)) {
71058 + get_file(file);
71059 + our_file = file;
71060 + }
71061 + }
71062 + rcu_read_unlock();
71063 + put_files_struct(files);
71064 + }
71065 +
71066 + if (our_file == NULL)
71067 + return 1;
71068 +
71069 + read_lock(&tasklist_lock);
71070 + do_each_thread(p2, p) {
71071 + files = get_files_struct(p);
71072 + if (files == NULL ||
71073 + (p->signal && p->signal->tty == task->signal->tty)) {
71074 + if (files != NULL)
71075 + put_files_struct(files);
71076 + continue;
71077 + }
71078 + rcu_read_lock();
71079 + fdt = files_fdtable(files);
71080 + for (i=0; i < fdt->max_fds; i++) {
71081 + file = fcheck_files(files, i);
71082 + if (file && S_ISCHR(file->f_path.dentry->d_inode->i_mode) &&
71083 + file->f_path.dentry->d_inode->i_rdev == our_file->f_path.dentry->d_inode->i_rdev) {
71084 + p3 = task;
71085 + while (task_pid_nr(p3) > 0) {
71086 + if (p3 == p)
71087 + break;
71088 + p3 = p3->real_parent;
71089 + }
71090 + if (p3 == p)
71091 + break;
71092 + gr_log_ttysniff(GR_DONT_AUDIT_GOOD, GR_TTYSNIFF_ACL_MSG, p);
71093 + gr_handle_alertkill(p);
71094 + rcu_read_unlock();
71095 + put_files_struct(files);
71096 + read_unlock(&tasklist_lock);
71097 + fput(our_file);
71098 + return 0;
71099 + }
71100 + }
71101 + rcu_read_unlock();
71102 + put_files_struct(files);
71103 + } while_each_thread(p2, p);
71104 + read_unlock(&tasklist_lock);
71105 +
71106 + fput(our_file);
71107 + return 1;
71108 +}
71109 +
71110 +ssize_t
71111 +write_grsec_handler(struct file *file, const char __user * buf, size_t count, loff_t *ppos)
71112 +{
71113 + struct gr_arg_wrapper uwrap;
71114 + unsigned char *sprole_salt = NULL;
71115 + unsigned char *sprole_sum = NULL;
71116 + int error = 0;
71117 + int error2 = 0;
71118 + size_t req_count = 0;
71119 + unsigned char oldmode = 0;
71120 +
71121 + mutex_lock(&gr_dev_mutex);
71122 +
71123 + if (gr_acl_is_enabled() && !(current->acl->mode & GR_KERNELAUTH)) {
71124 + error = -EPERM;
71125 + goto out;
71126 + }
71127 +
71128 +#ifdef CONFIG_COMPAT
71129 + pax_open_kernel();
71130 + if (is_compat_task()) {
71131 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_compat;
71132 + copy_gr_arg = &copy_gr_arg_compat;
71133 + copy_acl_object_label = &copy_acl_object_label_compat;
71134 + copy_acl_subject_label = &copy_acl_subject_label_compat;
71135 + copy_acl_role_label = &copy_acl_role_label_compat;
71136 + copy_acl_ip_label = &copy_acl_ip_label_compat;
71137 + copy_role_allowed_ip = &copy_role_allowed_ip_compat;
71138 + copy_role_transition = &copy_role_transition_compat;
71139 + copy_sprole_pw = &copy_sprole_pw_compat;
71140 + copy_gr_hash_struct = &copy_gr_hash_struct_compat;
71141 + copy_pointer_from_array = &copy_pointer_from_array_compat;
71142 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_compat;
71143 + } else {
71144 + copy_gr_arg_wrapper = &copy_gr_arg_wrapper_normal;
71145 + copy_gr_arg = &copy_gr_arg_normal;
71146 + copy_acl_object_label = &copy_acl_object_label_normal;
71147 + copy_acl_subject_label = &copy_acl_subject_label_normal;
71148 + copy_acl_role_label = &copy_acl_role_label_normal;
71149 + copy_acl_ip_label = &copy_acl_ip_label_normal;
71150 + copy_role_allowed_ip = &copy_role_allowed_ip_normal;
71151 + copy_role_transition = &copy_role_transition_normal;
71152 + copy_sprole_pw = &copy_sprole_pw_normal;
71153 + copy_gr_hash_struct = &copy_gr_hash_struct_normal;
71154 + copy_pointer_from_array = &copy_pointer_from_array_normal;
71155 + get_gr_arg_wrapper_size = &get_gr_arg_wrapper_size_normal;
71156 + }
71157 + pax_close_kernel();
71158 +#endif
71159 +
71160 + req_count = get_gr_arg_wrapper_size();
71161 +
71162 + if (count != req_count) {
71163 + gr_log_int_int(GR_DONT_AUDIT_GOOD, GR_DEV_ACL_MSG, (int)count, (int)req_count);
71164 + error = -EINVAL;
71165 + goto out;
71166 + }
71167 +
71168 +
71169 + if (gr_auth_expires && time_after_eq(get_seconds(), gr_auth_expires)) {
71170 + gr_auth_expires = 0;
71171 + gr_auth_attempts = 0;
71172 + }
71173 +
71174 + error = copy_gr_arg_wrapper(buf, &uwrap);
71175 + if (error)
71176 + goto out;
71177 +
71178 + error = copy_gr_arg(uwrap.arg, &gr_usermode);
71179 + if (error)
71180 + goto out;
71181 +
71182 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_SPROLEPAM &&
71183 + gr_auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
71184 + time_after(gr_auth_expires, get_seconds())) {
71185 + error = -EBUSY;
71186 + goto out;
71187 + }
71188 +
71189 + /* if non-root trying to do anything other than use a special role,
71190 + do not attempt authentication, do not count towards authentication
71191 + locking
71192 + */
71193 +
71194 + if (gr_usermode.mode != GR_SPROLE && gr_usermode.mode != GR_STATUS &&
71195 + gr_usermode.mode != GR_UNSPROLE && gr_usermode.mode != GR_SPROLEPAM &&
71196 + gr_is_global_nonroot(current_uid())) {
71197 + error = -EPERM;
71198 + goto out;
71199 + }
71200 +
71201 + /* ensure pw and special role name are null terminated */
71202 +
71203 + gr_usermode.pw[GR_PW_LEN - 1] = '\0';
71204 + gr_usermode.sp_role[GR_SPROLE_LEN - 1] = '\0';
71205 +
71206 + /* Okay.
71207 + * We have our enough of the argument structure..(we have yet
71208 + * to copy_from_user the tables themselves) . Copy the tables
71209 + * only if we need them, i.e. for loading operations. */
71210 +
71211 + switch (gr_usermode.mode) {
71212 + case GR_STATUS:
71213 + if (gr_acl_is_enabled()) {
71214 + error = 1;
71215 + if (!gr_check_secure_terminal(current))
71216 + error = 3;
71217 + } else
71218 + error = 2;
71219 + goto out;
71220 + case GR_SHUTDOWN:
71221 + if (gr_acl_is_enabled() && !(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
71222 + stop_machine(gr_rbac_disable, NULL, NULL);
71223 + free_variables(false);
71224 + memset(&gr_usermode, 0, sizeof(gr_usermode));
71225 + memset(&gr_system_salt, 0, sizeof(gr_system_salt));
71226 + memset(&gr_system_sum, 0, sizeof(gr_system_sum));
71227 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTS_ACL_MSG);
71228 + } else if (gr_acl_is_enabled()) {
71229 + gr_log_noargs(GR_DONT_AUDIT, GR_SHUTF_ACL_MSG);
71230 + error = -EPERM;
71231 + } else {
71232 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SHUTI_ACL_MSG);
71233 + error = -EAGAIN;
71234 + }
71235 + break;
71236 + case GR_ENABLE:
71237 + if (!gr_acl_is_enabled() && !(error2 = gracl_init(&gr_usermode)))
71238 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_ENABLE_ACL_MSG, GR_VERSION);
71239 + else {
71240 + if (gr_acl_is_enabled())
71241 + error = -EAGAIN;
71242 + else
71243 + error = error2;
71244 + gr_log_str(GR_DONT_AUDIT, GR_ENABLEF_ACL_MSG, GR_VERSION);
71245 + }
71246 + break;
71247 + case GR_OLDRELOAD:
71248 + oldmode = 1;
71249 + case GR_RELOAD:
71250 + if (!gr_acl_is_enabled()) {
71251 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOADI_ACL_MSG, GR_VERSION);
71252 + error = -EAGAIN;
71253 + } else if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
71254 + error2 = gracl_reload(&gr_usermode, oldmode);
71255 + if (!error2)
71256 + gr_log_str(GR_DONT_AUDIT_GOOD, GR_RELOAD_ACL_MSG, GR_VERSION);
71257 + else {
71258 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
71259 + error = error2;
71260 + }
71261 + } else {
71262 + gr_log_str(GR_DONT_AUDIT, GR_RELOADF_ACL_MSG, GR_VERSION);
71263 + error = -EPERM;
71264 + }
71265 + break;
71266 + case GR_SEGVMOD:
71267 + if (unlikely(!gr_acl_is_enabled())) {
71268 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODI_ACL_MSG);
71269 + error = -EAGAIN;
71270 + break;
71271 + }
71272 +
71273 + if (!(chkpw(&gr_usermode, (unsigned char *)&gr_system_salt, (unsigned char *)&gr_system_sum))) {
71274 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SEGVMODS_ACL_MSG);
71275 + if (gr_usermode.segv_device && gr_usermode.segv_inode) {
71276 + struct acl_subject_label *segvacl;
71277 + segvacl =
71278 + lookup_acl_subj_label(gr_usermode.segv_inode,
71279 + gr_usermode.segv_device,
71280 + current->role);
71281 + if (segvacl) {
71282 + segvacl->crashes = 0;
71283 + segvacl->expires = 0;
71284 + }
71285 + } else if (gr_find_uid(gr_usermode.segv_uid) >= 0) {
71286 + gr_remove_uid(gr_usermode.segv_uid);
71287 + }
71288 + } else {
71289 + gr_log_noargs(GR_DONT_AUDIT, GR_SEGVMODF_ACL_MSG);
71290 + error = -EPERM;
71291 + }
71292 + break;
71293 + case GR_SPROLE:
71294 + case GR_SPROLEPAM:
71295 + if (unlikely(!gr_acl_is_enabled())) {
71296 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_SPROLEI_ACL_MSG);
71297 + error = -EAGAIN;
71298 + break;
71299 + }
71300 +
71301 + if (current->role->expires && time_after_eq(get_seconds(), current->role->expires)) {
71302 + current->role->expires = 0;
71303 + current->role->auth_attempts = 0;
71304 + }
71305 +
71306 + if (current->role->auth_attempts >= CONFIG_GRKERNSEC_ACL_MAXTRIES &&
71307 + time_after(current->role->expires, get_seconds())) {
71308 + error = -EBUSY;
71309 + goto out;
71310 + }
71311 +
71312 + if (lookup_special_role_auth
71313 + (gr_usermode.mode, gr_usermode.sp_role, &sprole_salt, &sprole_sum)
71314 + && ((!sprole_salt && !sprole_sum)
71315 + || !(chkpw(&gr_usermode, sprole_salt, sprole_sum)))) {
71316 + char *p = "";
71317 + assign_special_role(gr_usermode.sp_role);
71318 + read_lock(&tasklist_lock);
71319 + if (current->real_parent)
71320 + p = current->real_parent->role->rolename;
71321 + read_unlock(&tasklist_lock);
71322 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_SPROLES_ACL_MSG,
71323 + p, acl_sp_role_value);
71324 + } else {
71325 + gr_log_str(GR_DONT_AUDIT, GR_SPROLEF_ACL_MSG, gr_usermode.sp_role);
71326 + error = -EPERM;
71327 + if(!(current->role->auth_attempts++))
71328 + current->role->expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
71329 +
71330 + goto out;
71331 + }
71332 + break;
71333 + case GR_UNSPROLE:
71334 + if (unlikely(!gr_acl_is_enabled())) {
71335 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_UNSPROLEI_ACL_MSG);
71336 + error = -EAGAIN;
71337 + break;
71338 + }
71339 +
71340 + if (current->role->roletype & GR_ROLE_SPECIAL) {
71341 + char *p = "";
71342 + int i = 0;
71343 +
71344 + read_lock(&tasklist_lock);
71345 + if (current->real_parent) {
71346 + p = current->real_parent->role->rolename;
71347 + i = current->real_parent->acl_role_id;
71348 + }
71349 + read_unlock(&tasklist_lock);
71350 +
71351 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_UNSPROLES_ACL_MSG, p, i);
71352 + gr_set_acls(1);
71353 + } else {
71354 + error = -EPERM;
71355 + goto out;
71356 + }
71357 + break;
71358 + default:
71359 + gr_log_int(GR_DONT_AUDIT, GR_INVMODE_ACL_MSG, gr_usermode.mode);
71360 + error = -EINVAL;
71361 + break;
71362 + }
71363 +
71364 + if (error != -EPERM)
71365 + goto out;
71366 +
71367 + if(!(gr_auth_attempts++))
71368 + gr_auth_expires = get_seconds() + CONFIG_GRKERNSEC_ACL_TIMEOUT;
71369 +
71370 + out:
71371 + mutex_unlock(&gr_dev_mutex);
71372 +
71373 + if (!error)
71374 + error = req_count;
71375 +
71376 + return error;
71377 +}
71378 +
71379 +int
71380 +gr_set_acls(const int type)
71381 +{
71382 + struct task_struct *task, *task2;
71383 + struct acl_role_label *role = current->role;
71384 + struct acl_subject_label *subj;
71385 + __u16 acl_role_id = current->acl_role_id;
71386 + const struct cred *cred;
71387 + int ret;
71388 +
71389 + rcu_read_lock();
71390 + read_lock(&tasklist_lock);
71391 + read_lock(&grsec_exec_file_lock);
71392 + do_each_thread(task2, task) {
71393 + /* check to see if we're called from the exit handler,
71394 + if so, only replace ACLs that have inherited the admin
71395 + ACL */
71396 +
71397 + if (type && (task->role != role ||
71398 + task->acl_role_id != acl_role_id))
71399 + continue;
71400 +
71401 + task->acl_role_id = 0;
71402 + task->acl_sp_role = 0;
71403 + task->inherited = 0;
71404 +
71405 + if (task->exec_file) {
71406 + cred = __task_cred(task);
71407 + task->role = __lookup_acl_role_label(polstate, task, GR_GLOBAL_UID(cred->uid), GR_GLOBAL_GID(cred->gid));
71408 + subj = __gr_get_subject_for_task(polstate, task, NULL);
71409 + if (subj == NULL) {
71410 + ret = -EINVAL;
71411 + read_unlock(&grsec_exec_file_lock);
71412 + read_unlock(&tasklist_lock);
71413 + rcu_read_unlock();
71414 + gr_log_str_int(GR_DONT_AUDIT_GOOD, GR_DEFACL_MSG, task->comm, task_pid_nr(task));
71415 + return ret;
71416 + }
71417 + __gr_apply_subject_to_task(polstate, task, subj);
71418 + } else {
71419 + // it's a kernel process
71420 + task->role = polstate->kernel_role;
71421 + task->acl = polstate->kernel_role->root_label;
71422 +#ifdef CONFIG_GRKERNSEC_ACL_HIDEKERN
71423 + task->acl->mode &= ~GR_PROCFIND;
71424 +#endif
71425 + }
71426 + } while_each_thread(task2, task);
71427 + read_unlock(&grsec_exec_file_lock);
71428 + read_unlock(&tasklist_lock);
71429 + rcu_read_unlock();
71430 +
71431 + return 0;
71432 +}
71433 diff --git a/grsecurity/gracl_res.c b/grsecurity/gracl_res.c
71434 new file mode 100644
71435 index 0000000..39645c9
71436 --- /dev/null
71437 +++ b/grsecurity/gracl_res.c
71438 @@ -0,0 +1,68 @@
71439 +#include <linux/kernel.h>
71440 +#include <linux/sched.h>
71441 +#include <linux/gracl.h>
71442 +#include <linux/grinternal.h>
71443 +
71444 +static const char *restab_log[] = {
71445 + [RLIMIT_CPU] = "RLIMIT_CPU",
71446 + [RLIMIT_FSIZE] = "RLIMIT_FSIZE",
71447 + [RLIMIT_DATA] = "RLIMIT_DATA",
71448 + [RLIMIT_STACK] = "RLIMIT_STACK",
71449 + [RLIMIT_CORE] = "RLIMIT_CORE",
71450 + [RLIMIT_RSS] = "RLIMIT_RSS",
71451 + [RLIMIT_NPROC] = "RLIMIT_NPROC",
71452 + [RLIMIT_NOFILE] = "RLIMIT_NOFILE",
71453 + [RLIMIT_MEMLOCK] = "RLIMIT_MEMLOCK",
71454 + [RLIMIT_AS] = "RLIMIT_AS",
71455 + [RLIMIT_LOCKS] = "RLIMIT_LOCKS",
71456 + [RLIMIT_SIGPENDING] = "RLIMIT_SIGPENDING",
71457 + [RLIMIT_MSGQUEUE] = "RLIMIT_MSGQUEUE",
71458 + [RLIMIT_NICE] = "RLIMIT_NICE",
71459 + [RLIMIT_RTPRIO] = "RLIMIT_RTPRIO",
71460 + [RLIMIT_RTTIME] = "RLIMIT_RTTIME",
71461 + [GR_CRASH_RES] = "RLIMIT_CRASH"
71462 +};
71463 +
71464 +void
71465 +gr_log_resource(const struct task_struct *task,
71466 + const int res, const unsigned long wanted, const int gt)
71467 +{
71468 + const struct cred *cred;
71469 + unsigned long rlim;
71470 +
71471 + if (!gr_acl_is_enabled() && !grsec_resource_logging)
71472 + return;
71473 +
71474 + // not yet supported resource
71475 + if (unlikely(!restab_log[res]))
71476 + return;
71477 +
71478 + if (res == RLIMIT_CPU || res == RLIMIT_RTTIME)
71479 + rlim = task_rlimit_max(task, res);
71480 + else
71481 + rlim = task_rlimit(task, res);
71482 +
71483 + if (likely((rlim == RLIM_INFINITY) || (gt && wanted <= rlim) || (!gt && wanted < rlim)))
71484 + return;
71485 +
71486 + rcu_read_lock();
71487 + cred = __task_cred(task);
71488 +
71489 + if (res == RLIMIT_NPROC &&
71490 + (cap_raised(cred->cap_effective, CAP_SYS_ADMIN) ||
71491 + cap_raised(cred->cap_effective, CAP_SYS_RESOURCE)))
71492 + goto out_rcu_unlock;
71493 + else if (res == RLIMIT_MEMLOCK &&
71494 + cap_raised(cred->cap_effective, CAP_IPC_LOCK))
71495 + goto out_rcu_unlock;
71496 + else if (res == RLIMIT_NICE && cap_raised(cred->cap_effective, CAP_SYS_NICE))
71497 + goto out_rcu_unlock;
71498 + rcu_read_unlock();
71499 +
71500 + gr_log_res_ulong2_str(GR_DONT_AUDIT, GR_RESOURCE_MSG, task, wanted, restab_log[res], rlim);
71501 +
71502 + return;
71503 +out_rcu_unlock:
71504 + rcu_read_unlock();
71505 + return;
71506 +}
71507 diff --git a/grsecurity/gracl_segv.c b/grsecurity/gracl_segv.c
71508 new file mode 100644
71509 index 0000000..2040e61
71510 --- /dev/null
71511 +++ b/grsecurity/gracl_segv.c
71512 @@ -0,0 +1,313 @@
71513 +#include <linux/kernel.h>
71514 +#include <linux/mm.h>
71515 +#include <asm/uaccess.h>
71516 +#include <asm/errno.h>
71517 +#include <asm/mman.h>
71518 +#include <net/sock.h>
71519 +#include <linux/file.h>
71520 +#include <linux/fs.h>
71521 +#include <linux/net.h>
71522 +#include <linux/in.h>
71523 +#include <linux/slab.h>
71524 +#include <linux/types.h>
71525 +#include <linux/sched.h>
71526 +#include <linux/timer.h>
71527 +#include <linux/gracl.h>
71528 +#include <linux/grsecurity.h>
71529 +#include <linux/grinternal.h>
71530 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
71531 +#include <linux/magic.h>
71532 +#include <linux/pagemap.h>
71533 +#include "../fs/btrfs/async-thread.h"
71534 +#include "../fs/btrfs/ctree.h"
71535 +#include "../fs/btrfs/btrfs_inode.h"
71536 +#endif
71537 +
71538 +static struct crash_uid *uid_set;
71539 +static unsigned short uid_used;
71540 +static DEFINE_SPINLOCK(gr_uid_lock);
71541 +extern rwlock_t gr_inode_lock;
71542 +extern struct acl_subject_label *
71543 + lookup_acl_subj_label(const ino_t inode, const dev_t dev,
71544 + struct acl_role_label *role);
71545 +
71546 +static inline dev_t __get_dev(const struct dentry *dentry)
71547 +{
71548 +#if defined(CONFIG_BTRFS_FS) || defined(CONFIG_BTRFS_FS_MODULE)
71549 + if (dentry->d_sb->s_magic == BTRFS_SUPER_MAGIC)
71550 + return BTRFS_I(dentry->d_inode)->root->anon_dev;
71551 + else
71552 +#endif
71553 + return dentry->d_sb->s_dev;
71554 +}
71555 +
71556 +int
71557 +gr_init_uidset(void)
71558 +{
71559 + uid_set =
71560 + kmalloc(GR_UIDTABLE_MAX * sizeof (struct crash_uid), GFP_KERNEL);
71561 + uid_used = 0;
71562 +
71563 + return uid_set ? 1 : 0;
71564 +}
71565 +
71566 +void
71567 +gr_free_uidset(void)
71568 +{
71569 + if (uid_set) {
71570 + struct crash_uid *tmpset;
71571 + spin_lock(&gr_uid_lock);
71572 + tmpset = uid_set;
71573 + uid_set = NULL;
71574 + uid_used = 0;
71575 + spin_unlock(&gr_uid_lock);
71576 + if (tmpset)
71577 + kfree(tmpset);
71578 + }
71579 +
71580 + return;
71581 +}
71582 +
71583 +int
71584 +gr_find_uid(const uid_t uid)
71585 +{
71586 + struct crash_uid *tmp = uid_set;
71587 + uid_t buid;
71588 + int low = 0, high = uid_used - 1, mid;
71589 +
71590 + while (high >= low) {
71591 + mid = (low + high) >> 1;
71592 + buid = tmp[mid].uid;
71593 + if (buid == uid)
71594 + return mid;
71595 + if (buid > uid)
71596 + high = mid - 1;
71597 + if (buid < uid)
71598 + low = mid + 1;
71599 + }
71600 +
71601 + return -1;
71602 +}
71603 +
71604 +static __inline__ void
71605 +gr_insertsort(void)
71606 +{
71607 + unsigned short i, j;
71608 + struct crash_uid index;
71609 +
71610 + for (i = 1; i < uid_used; i++) {
71611 + index = uid_set[i];
71612 + j = i;
71613 + while ((j > 0) && uid_set[j - 1].uid > index.uid) {
71614 + uid_set[j] = uid_set[j - 1];
71615 + j--;
71616 + }
71617 + uid_set[j] = index;
71618 + }
71619 +
71620 + return;
71621 +}
71622 +
71623 +static __inline__ void
71624 +gr_insert_uid(const kuid_t kuid, const unsigned long expires)
71625 +{
71626 + int loc;
71627 + uid_t uid = GR_GLOBAL_UID(kuid);
71628 +
71629 + if (uid_used == GR_UIDTABLE_MAX)
71630 + return;
71631 +
71632 + loc = gr_find_uid(uid);
71633 +
71634 + if (loc >= 0) {
71635 + uid_set[loc].expires = expires;
71636 + return;
71637 + }
71638 +
71639 + uid_set[uid_used].uid = uid;
71640 + uid_set[uid_used].expires = expires;
71641 + uid_used++;
71642 +
71643 + gr_insertsort();
71644 +
71645 + return;
71646 +}
71647 +
71648 +void
71649 +gr_remove_uid(const unsigned short loc)
71650 +{
71651 + unsigned short i;
71652 +
71653 + for (i = loc + 1; i < uid_used; i++)
71654 + uid_set[i - 1] = uid_set[i];
71655 +
71656 + uid_used--;
71657 +
71658 + return;
71659 +}
71660 +
71661 +int
71662 +gr_check_crash_uid(const kuid_t kuid)
71663 +{
71664 + int loc;
71665 + int ret = 0;
71666 + uid_t uid;
71667 +
71668 + if (unlikely(!gr_acl_is_enabled()))
71669 + return 0;
71670 +
71671 + uid = GR_GLOBAL_UID(kuid);
71672 +
71673 + spin_lock(&gr_uid_lock);
71674 + loc = gr_find_uid(uid);
71675 +
71676 + if (loc < 0)
71677 + goto out_unlock;
71678 +
71679 + if (time_before_eq(uid_set[loc].expires, get_seconds()))
71680 + gr_remove_uid(loc);
71681 + else
71682 + ret = 1;
71683 +
71684 +out_unlock:
71685 + spin_unlock(&gr_uid_lock);
71686 + return ret;
71687 +}
71688 +
71689 +static __inline__ int
71690 +proc_is_setxid(const struct cred *cred)
71691 +{
71692 + if (!uid_eq(cred->uid, cred->euid) || !uid_eq(cred->uid, cred->suid) ||
71693 + !uid_eq(cred->uid, cred->fsuid))
71694 + return 1;
71695 + if (!gid_eq(cred->gid, cred->egid) || !gid_eq(cred->gid, cred->sgid) ||
71696 + !gid_eq(cred->gid, cred->fsgid))
71697 + return 1;
71698 +
71699 + return 0;
71700 +}
71701 +
71702 +extern int gr_fake_force_sig(int sig, struct task_struct *t);
71703 +
71704 +void
71705 +gr_handle_crash(struct task_struct *task, const int sig)
71706 +{
71707 + struct acl_subject_label *curr;
71708 + struct task_struct *tsk, *tsk2;
71709 + const struct cred *cred;
71710 + const struct cred *cred2;
71711 +
71712 + if (sig != SIGSEGV && sig != SIGKILL && sig != SIGBUS && sig != SIGILL)
71713 + return;
71714 +
71715 + if (unlikely(!gr_acl_is_enabled()))
71716 + return;
71717 +
71718 + curr = task->acl;
71719 +
71720 + if (!(curr->resmask & (1U << GR_CRASH_RES)))
71721 + return;
71722 +
71723 + if (time_before_eq(curr->expires, get_seconds())) {
71724 + curr->expires = 0;
71725 + curr->crashes = 0;
71726 + }
71727 +
71728 + curr->crashes++;
71729 +
71730 + if (!curr->expires)
71731 + curr->expires = get_seconds() + curr->res[GR_CRASH_RES].rlim_max;
71732 +
71733 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
71734 + time_after(curr->expires, get_seconds())) {
71735 + rcu_read_lock();
71736 + cred = __task_cred(task);
71737 + if (gr_is_global_nonroot(cred->uid) && proc_is_setxid(cred)) {
71738 + gr_log_crash1(GR_DONT_AUDIT, GR_SEGVSTART_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
71739 + spin_lock(&gr_uid_lock);
71740 + gr_insert_uid(cred->uid, curr->expires);
71741 + spin_unlock(&gr_uid_lock);
71742 + curr->expires = 0;
71743 + curr->crashes = 0;
71744 + read_lock(&tasklist_lock);
71745 + do_each_thread(tsk2, tsk) {
71746 + cred2 = __task_cred(tsk);
71747 + if (tsk != task && uid_eq(cred2->uid, cred->uid))
71748 + gr_fake_force_sig(SIGKILL, tsk);
71749 + } while_each_thread(tsk2, tsk);
71750 + read_unlock(&tasklist_lock);
71751 + } else {
71752 + gr_log_crash2(GR_DONT_AUDIT, GR_SEGVNOSUID_ACL_MSG, task, curr->res[GR_CRASH_RES].rlim_max);
71753 + read_lock(&tasklist_lock);
71754 + read_lock(&grsec_exec_file_lock);
71755 + do_each_thread(tsk2, tsk) {
71756 + if (likely(tsk != task)) {
71757 + // if this thread has the same subject as the one that triggered
71758 + // RES_CRASH and it's the same binary, kill it
71759 + if (tsk->acl == task->acl && gr_is_same_file(tsk->exec_file, task->exec_file))
71760 + gr_fake_force_sig(SIGKILL, tsk);
71761 + }
71762 + } while_each_thread(tsk2, tsk);
71763 + read_unlock(&grsec_exec_file_lock);
71764 + read_unlock(&tasklist_lock);
71765 + }
71766 + rcu_read_unlock();
71767 + }
71768 +
71769 + return;
71770 +}
71771 +
71772 +int
71773 +gr_check_crash_exec(const struct file *filp)
71774 +{
71775 + struct acl_subject_label *curr;
71776 +
71777 + if (unlikely(!gr_acl_is_enabled()))
71778 + return 0;
71779 +
71780 + read_lock(&gr_inode_lock);
71781 + curr = lookup_acl_subj_label(filp->f_path.dentry->d_inode->i_ino,
71782 + __get_dev(filp->f_path.dentry),
71783 + current->role);
71784 + read_unlock(&gr_inode_lock);
71785 +
71786 + if (!curr || !(curr->resmask & (1U << GR_CRASH_RES)) ||
71787 + (!curr->crashes && !curr->expires))
71788 + return 0;
71789 +
71790 + if ((curr->crashes >= curr->res[GR_CRASH_RES].rlim_cur) &&
71791 + time_after(curr->expires, get_seconds()))
71792 + return 1;
71793 + else if (time_before_eq(curr->expires, get_seconds())) {
71794 + curr->crashes = 0;
71795 + curr->expires = 0;
71796 + }
71797 +
71798 + return 0;
71799 +}
71800 +
71801 +void
71802 +gr_handle_alertkill(struct task_struct *task)
71803 +{
71804 + struct acl_subject_label *curracl;
71805 + __u32 curr_ip;
71806 + struct task_struct *p, *p2;
71807 +
71808 + if (unlikely(!gr_acl_is_enabled()))
71809 + return;
71810 +
71811 + curracl = task->acl;
71812 + curr_ip = task->signal->curr_ip;
71813 +
71814 + if ((curracl->mode & GR_KILLIPPROC) && curr_ip) {
71815 + read_lock(&tasklist_lock);
71816 + do_each_thread(p2, p) {
71817 + if (p->signal->curr_ip == curr_ip)
71818 + gr_fake_force_sig(SIGKILL, p);
71819 + } while_each_thread(p2, p);
71820 + read_unlock(&tasklist_lock);
71821 + } else if (curracl->mode & GR_KILLPROC)
71822 + gr_fake_force_sig(SIGKILL, task);
71823 +
71824 + return;
71825 +}
71826 diff --git a/grsecurity/gracl_shm.c b/grsecurity/gracl_shm.c
71827 new file mode 100644
71828 index 0000000..98011b0
71829 --- /dev/null
71830 +++ b/grsecurity/gracl_shm.c
71831 @@ -0,0 +1,40 @@
71832 +#include <linux/kernel.h>
71833 +#include <linux/mm.h>
71834 +#include <linux/sched.h>
71835 +#include <linux/file.h>
71836 +#include <linux/ipc.h>
71837 +#include <linux/gracl.h>
71838 +#include <linux/grsecurity.h>
71839 +#include <linux/grinternal.h>
71840 +
71841 +int
71842 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
71843 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
71844 +{
71845 + struct task_struct *task;
71846 +
71847 + if (!gr_acl_is_enabled())
71848 + return 1;
71849 +
71850 + rcu_read_lock();
71851 + read_lock(&tasklist_lock);
71852 +
71853 + task = find_task_by_vpid(shm_cprid);
71854 +
71855 + if (unlikely(!task))
71856 + task = find_task_by_vpid(shm_lapid);
71857 +
71858 + if (unlikely(task && (time_before_eq((unsigned long)task->start_time.tv_sec, (unsigned long)shm_createtime) ||
71859 + (task_pid_nr(task) == shm_lapid)) &&
71860 + (task->acl->mode & GR_PROTSHM) &&
71861 + (task->acl != current->acl))) {
71862 + read_unlock(&tasklist_lock);
71863 + rcu_read_unlock();
71864 + gr_log_int3(GR_DONT_AUDIT, GR_SHMAT_ACL_MSG, GR_GLOBAL_UID(cuid), shm_cprid, shmid);
71865 + return 0;
71866 + }
71867 + read_unlock(&tasklist_lock);
71868 + rcu_read_unlock();
71869 +
71870 + return 1;
71871 +}
71872 diff --git a/grsecurity/grsec_chdir.c b/grsecurity/grsec_chdir.c
71873 new file mode 100644
71874 index 0000000..bc0be01
71875 --- /dev/null
71876 +++ b/grsecurity/grsec_chdir.c
71877 @@ -0,0 +1,19 @@
71878 +#include <linux/kernel.h>
71879 +#include <linux/sched.h>
71880 +#include <linux/fs.h>
71881 +#include <linux/file.h>
71882 +#include <linux/grsecurity.h>
71883 +#include <linux/grinternal.h>
71884 +
71885 +void
71886 +gr_log_chdir(const struct dentry *dentry, const struct vfsmount *mnt)
71887 +{
71888 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
71889 + if ((grsec_enable_chdir && grsec_enable_group &&
71890 + in_group_p(grsec_audit_gid)) || (grsec_enable_chdir &&
71891 + !grsec_enable_group)) {
71892 + gr_log_fs_generic(GR_DO_AUDIT, GR_CHDIR_AUDIT_MSG, dentry, mnt);
71893 + }
71894 +#endif
71895 + return;
71896 +}
71897 diff --git a/grsecurity/grsec_chroot.c b/grsecurity/grsec_chroot.c
71898 new file mode 100644
71899 index 0000000..651d6c2
71900 --- /dev/null
71901 +++ b/grsecurity/grsec_chroot.c
71902 @@ -0,0 +1,370 @@
71903 +#include <linux/kernel.h>
71904 +#include <linux/module.h>
71905 +#include <linux/sched.h>
71906 +#include <linux/file.h>
71907 +#include <linux/fs.h>
71908 +#include <linux/mount.h>
71909 +#include <linux/types.h>
71910 +#include "../fs/mount.h"
71911 +#include <linux/grsecurity.h>
71912 +#include <linux/grinternal.h>
71913 +
71914 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
71915 +int gr_init_ran;
71916 +#endif
71917 +
71918 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path)
71919 +{
71920 +#ifdef CONFIG_GRKERNSEC
71921 + if (task_pid_nr(task) > 1 && path->dentry != init_task.fs->root.dentry &&
71922 + path->dentry != task->nsproxy->mnt_ns->root->mnt.mnt_root
71923 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
71924 + && gr_init_ran
71925 +#endif
71926 + )
71927 + task->gr_is_chrooted = 1;
71928 + else {
71929 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
71930 + if (task_pid_nr(task) == 1 && !gr_init_ran)
71931 + gr_init_ran = 1;
71932 +#endif
71933 + task->gr_is_chrooted = 0;
71934 + }
71935 +
71936 + task->gr_chroot_dentry = path->dentry;
71937 +#endif
71938 + return;
71939 +}
71940 +
71941 +void gr_clear_chroot_entries(struct task_struct *task)
71942 +{
71943 +#ifdef CONFIG_GRKERNSEC
71944 + task->gr_is_chrooted = 0;
71945 + task->gr_chroot_dentry = NULL;
71946 +#endif
71947 + return;
71948 +}
71949 +
71950 +int
71951 +gr_handle_chroot_unix(const pid_t pid)
71952 +{
71953 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
71954 + struct task_struct *p;
71955 +
71956 + if (unlikely(!grsec_enable_chroot_unix))
71957 + return 1;
71958 +
71959 + if (likely(!proc_is_chrooted(current)))
71960 + return 1;
71961 +
71962 + rcu_read_lock();
71963 + read_lock(&tasklist_lock);
71964 + p = find_task_by_vpid_unrestricted(pid);
71965 + if (unlikely(p && !have_same_root(current, p))) {
71966 + read_unlock(&tasklist_lock);
71967 + rcu_read_unlock();
71968 + gr_log_noargs(GR_DONT_AUDIT, GR_UNIX_CHROOT_MSG);
71969 + return 0;
71970 + }
71971 + read_unlock(&tasklist_lock);
71972 + rcu_read_unlock();
71973 +#endif
71974 + return 1;
71975 +}
71976 +
71977 +int
71978 +gr_handle_chroot_nice(void)
71979 +{
71980 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
71981 + if (grsec_enable_chroot_nice && proc_is_chrooted(current)) {
71982 + gr_log_noargs(GR_DONT_AUDIT, GR_NICE_CHROOT_MSG);
71983 + return -EPERM;
71984 + }
71985 +#endif
71986 + return 0;
71987 +}
71988 +
71989 +int
71990 +gr_handle_chroot_setpriority(struct task_struct *p, const int niceval)
71991 +{
71992 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
71993 + if (grsec_enable_chroot_nice && (niceval < task_nice(p))
71994 + && proc_is_chrooted(current)) {
71995 + gr_log_str_int(GR_DONT_AUDIT, GR_PRIORITY_CHROOT_MSG, p->comm, task_pid_nr(p));
71996 + return -EACCES;
71997 + }
71998 +#endif
71999 + return 0;
72000 +}
72001 +
72002 +int
72003 +gr_handle_chroot_fowner(struct pid *pid, enum pid_type type)
72004 +{
72005 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72006 + struct task_struct *p;
72007 + int ret = 0;
72008 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || !pid)
72009 + return ret;
72010 +
72011 + read_lock(&tasklist_lock);
72012 + do_each_pid_task(pid, type, p) {
72013 + if (!have_same_root(current, p)) {
72014 + ret = 1;
72015 + goto out;
72016 + }
72017 + } while_each_pid_task(pid, type, p);
72018 +out:
72019 + read_unlock(&tasklist_lock);
72020 + return ret;
72021 +#endif
72022 + return 0;
72023 +}
72024 +
72025 +int
72026 +gr_pid_is_chrooted(struct task_struct *p)
72027 +{
72028 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
72029 + if (!grsec_enable_chroot_findtask || !proc_is_chrooted(current) || p == NULL)
72030 + return 0;
72031 +
72032 + if ((p->exit_state & (EXIT_ZOMBIE | EXIT_DEAD)) ||
72033 + !have_same_root(current, p)) {
72034 + return 1;
72035 + }
72036 +#endif
72037 + return 0;
72038 +}
72039 +
72040 +EXPORT_SYMBOL_GPL(gr_pid_is_chrooted);
72041 +
72042 +#if defined(CONFIG_GRKERNSEC_CHROOT_DOUBLE) || defined(CONFIG_GRKERNSEC_CHROOT_FCHDIR)
72043 +int gr_is_outside_chroot(const struct dentry *u_dentry, const struct vfsmount *u_mnt)
72044 +{
72045 + struct path path, currentroot;
72046 + int ret = 0;
72047 +
72048 + path.dentry = (struct dentry *)u_dentry;
72049 + path.mnt = (struct vfsmount *)u_mnt;
72050 + get_fs_root(current->fs, &currentroot);
72051 + if (path_is_under(&path, &currentroot))
72052 + ret = 1;
72053 + path_put(&currentroot);
72054 +
72055 + return ret;
72056 +}
72057 +#endif
72058 +
72059 +int
72060 +gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt)
72061 +{
72062 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
72063 + if (!grsec_enable_chroot_fchdir)
72064 + return 1;
72065 +
72066 + if (!proc_is_chrooted(current))
72067 + return 1;
72068 + else if (!gr_is_outside_chroot(u_dentry, u_mnt)) {
72069 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_FCHDIR_MSG, u_dentry, u_mnt);
72070 + return 0;
72071 + }
72072 +#endif
72073 + return 1;
72074 +}
72075 +
72076 +int
72077 +gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72078 + const time_t shm_createtime)
72079 +{
72080 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
72081 + struct task_struct *p;
72082 + time_t starttime;
72083 +
72084 + if (unlikely(!grsec_enable_chroot_shmat))
72085 + return 1;
72086 +
72087 + if (likely(!proc_is_chrooted(current)))
72088 + return 1;
72089 +
72090 + rcu_read_lock();
72091 + read_lock(&tasklist_lock);
72092 +
72093 + if ((p = find_task_by_vpid_unrestricted(shm_cprid))) {
72094 + starttime = p->start_time.tv_sec;
72095 + if (time_before_eq((unsigned long)starttime, (unsigned long)shm_createtime)) {
72096 + if (have_same_root(current, p)) {
72097 + goto allow;
72098 + } else {
72099 + read_unlock(&tasklist_lock);
72100 + rcu_read_unlock();
72101 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
72102 + return 0;
72103 + }
72104 + }
72105 + /* creator exited, pid reuse, fall through to next check */
72106 + }
72107 + if ((p = find_task_by_vpid_unrestricted(shm_lapid))) {
72108 + if (unlikely(!have_same_root(current, p))) {
72109 + read_unlock(&tasklist_lock);
72110 + rcu_read_unlock();
72111 + gr_log_noargs(GR_DONT_AUDIT, GR_SHMAT_CHROOT_MSG);
72112 + return 0;
72113 + }
72114 + }
72115 +
72116 +allow:
72117 + read_unlock(&tasklist_lock);
72118 + rcu_read_unlock();
72119 +#endif
72120 + return 1;
72121 +}
72122 +
72123 +void
72124 +gr_log_chroot_exec(const struct dentry *dentry, const struct vfsmount *mnt)
72125 +{
72126 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
72127 + if (grsec_enable_chroot_execlog && proc_is_chrooted(current))
72128 + gr_log_fs_generic(GR_DO_AUDIT, GR_EXEC_CHROOT_MSG, dentry, mnt);
72129 +#endif
72130 + return;
72131 +}
72132 +
72133 +int
72134 +gr_handle_chroot_mknod(const struct dentry *dentry,
72135 + const struct vfsmount *mnt, const int mode)
72136 +{
72137 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
72138 + if (grsec_enable_chroot_mknod && !S_ISFIFO(mode) && !S_ISREG(mode) &&
72139 + proc_is_chrooted(current)) {
72140 + gr_log_fs_generic(GR_DONT_AUDIT, GR_MKNOD_CHROOT_MSG, dentry, mnt);
72141 + return -EPERM;
72142 + }
72143 +#endif
72144 + return 0;
72145 +}
72146 +
72147 +int
72148 +gr_handle_chroot_mount(const struct dentry *dentry,
72149 + const struct vfsmount *mnt, const char *dev_name)
72150 +{
72151 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
72152 + if (grsec_enable_chroot_mount && proc_is_chrooted(current)) {
72153 + gr_log_str_fs(GR_DONT_AUDIT, GR_MOUNT_CHROOT_MSG, dev_name ? dev_name : "none", dentry, mnt);
72154 + return -EPERM;
72155 + }
72156 +#endif
72157 + return 0;
72158 +}
72159 +
72160 +int
72161 +gr_handle_chroot_pivot(void)
72162 +{
72163 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
72164 + if (grsec_enable_chroot_pivot && proc_is_chrooted(current)) {
72165 + gr_log_noargs(GR_DONT_AUDIT, GR_PIVOT_CHROOT_MSG);
72166 + return -EPERM;
72167 + }
72168 +#endif
72169 + return 0;
72170 +}
72171 +
72172 +int
72173 +gr_handle_chroot_chroot(const struct dentry *dentry, const struct vfsmount *mnt)
72174 +{
72175 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
72176 + if (grsec_enable_chroot_double && proc_is_chrooted(current) &&
72177 + !gr_is_outside_chroot(dentry, mnt)) {
72178 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHROOT_CHROOT_MSG, dentry, mnt);
72179 + return -EPERM;
72180 + }
72181 +#endif
72182 + return 0;
72183 +}
72184 +
72185 +extern const char *captab_log[];
72186 +extern int captab_log_entries;
72187 +
72188 +int
72189 +gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72190 +{
72191 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72192 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
72193 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
72194 + if (cap_raised(chroot_caps, cap)) {
72195 + if (cap_raised(cred->cap_effective, cap) && cap < captab_log_entries) {
72196 + gr_log_cap(GR_DONT_AUDIT, GR_CAP_CHROOT_MSG, task, captab_log[cap]);
72197 + }
72198 + return 0;
72199 + }
72200 + }
72201 +#endif
72202 + return 1;
72203 +}
72204 +
72205 +int
72206 +gr_chroot_is_capable(const int cap)
72207 +{
72208 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72209 + return gr_task_chroot_is_capable(current, current_cred(), cap);
72210 +#endif
72211 + return 1;
72212 +}
72213 +
72214 +int
72215 +gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap)
72216 +{
72217 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72218 + if (grsec_enable_chroot_caps && proc_is_chrooted(task)) {
72219 + kernel_cap_t chroot_caps = GR_CHROOT_CAPS;
72220 + if (cap_raised(chroot_caps, cap)) {
72221 + return 0;
72222 + }
72223 + }
72224 +#endif
72225 + return 1;
72226 +}
72227 +
72228 +int
72229 +gr_chroot_is_capable_nolog(const int cap)
72230 +{
72231 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
72232 + return gr_task_chroot_is_capable_nolog(current, cap);
72233 +#endif
72234 + return 1;
72235 +}
72236 +
72237 +int
72238 +gr_handle_chroot_sysctl(const int op)
72239 +{
72240 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
72241 + if (grsec_enable_chroot_sysctl && (op & MAY_WRITE) &&
72242 + proc_is_chrooted(current))
72243 + return -EACCES;
72244 +#endif
72245 + return 0;
72246 +}
72247 +
72248 +void
72249 +gr_handle_chroot_chdir(const struct path *path)
72250 +{
72251 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
72252 + if (grsec_enable_chroot_chdir)
72253 + set_fs_pwd(current->fs, path);
72254 +#endif
72255 + return;
72256 +}
72257 +
72258 +int
72259 +gr_handle_chroot_chmod(const struct dentry *dentry,
72260 + const struct vfsmount *mnt, const int mode)
72261 +{
72262 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
72263 + /* allow chmod +s on directories, but not files */
72264 + if (grsec_enable_chroot_chmod && !S_ISDIR(dentry->d_inode->i_mode) &&
72265 + ((mode & S_ISUID) || ((mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))) &&
72266 + proc_is_chrooted(current)) {
72267 + gr_log_fs_generic(GR_DONT_AUDIT, GR_CHMOD_CHROOT_MSG, dentry, mnt);
72268 + return -EPERM;
72269 + }
72270 +#endif
72271 + return 0;
72272 +}
72273 diff --git a/grsecurity/grsec_disabled.c b/grsecurity/grsec_disabled.c
72274 new file mode 100644
72275 index 0000000..4d6fce8
72276 --- /dev/null
72277 +++ b/grsecurity/grsec_disabled.c
72278 @@ -0,0 +1,433 @@
72279 +#include <linux/kernel.h>
72280 +#include <linux/module.h>
72281 +#include <linux/sched.h>
72282 +#include <linux/file.h>
72283 +#include <linux/fs.h>
72284 +#include <linux/kdev_t.h>
72285 +#include <linux/net.h>
72286 +#include <linux/in.h>
72287 +#include <linux/ip.h>
72288 +#include <linux/skbuff.h>
72289 +#include <linux/sysctl.h>
72290 +
72291 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
72292 +void
72293 +pax_set_initial_flags(struct linux_binprm *bprm)
72294 +{
72295 + return;
72296 +}
72297 +#endif
72298 +
72299 +#ifdef CONFIG_SYSCTL
72300 +__u32
72301 +gr_handle_sysctl(const struct ctl_table * table, const int op)
72302 +{
72303 + return 0;
72304 +}
72305 +#endif
72306 +
72307 +#ifdef CONFIG_TASKSTATS
72308 +int gr_is_taskstats_denied(int pid)
72309 +{
72310 + return 0;
72311 +}
72312 +#endif
72313 +
72314 +int
72315 +gr_acl_is_enabled(void)
72316 +{
72317 + return 0;
72318 +}
72319 +
72320 +void
72321 +gr_handle_proc_create(const struct dentry *dentry, const struct inode *inode)
72322 +{
72323 + return;
72324 +}
72325 +
72326 +int
72327 +gr_handle_rawio(const struct inode *inode)
72328 +{
72329 + return 0;
72330 +}
72331 +
72332 +void
72333 +gr_acl_handle_psacct(struct task_struct *task, const long code)
72334 +{
72335 + return;
72336 +}
72337 +
72338 +int
72339 +gr_handle_ptrace(struct task_struct *task, const long request)
72340 +{
72341 + return 0;
72342 +}
72343 +
72344 +int
72345 +gr_handle_proc_ptrace(struct task_struct *task)
72346 +{
72347 + return 0;
72348 +}
72349 +
72350 +int
72351 +gr_set_acls(const int type)
72352 +{
72353 + return 0;
72354 +}
72355 +
72356 +int
72357 +gr_check_hidden_task(const struct task_struct *tsk)
72358 +{
72359 + return 0;
72360 +}
72361 +
72362 +int
72363 +gr_check_protected_task(const struct task_struct *task)
72364 +{
72365 + return 0;
72366 +}
72367 +
72368 +int
72369 +gr_check_protected_task_fowner(struct pid *pid, enum pid_type type)
72370 +{
72371 + return 0;
72372 +}
72373 +
72374 +void
72375 +gr_copy_label(struct task_struct *tsk)
72376 +{
72377 + return;
72378 +}
72379 +
72380 +void
72381 +gr_set_pax_flags(struct task_struct *task)
72382 +{
72383 + return;
72384 +}
72385 +
72386 +int
72387 +gr_set_proc_label(const struct dentry *dentry, const struct vfsmount *mnt,
72388 + const int unsafe_share)
72389 +{
72390 + return 0;
72391 +}
72392 +
72393 +void
72394 +gr_handle_delete(const ino_t ino, const dev_t dev)
72395 +{
72396 + return;
72397 +}
72398 +
72399 +void
72400 +gr_handle_create(const struct dentry *dentry, const struct vfsmount *mnt)
72401 +{
72402 + return;
72403 +}
72404 +
72405 +void
72406 +gr_handle_crash(struct task_struct *task, const int sig)
72407 +{
72408 + return;
72409 +}
72410 +
72411 +int
72412 +gr_check_crash_exec(const struct file *filp)
72413 +{
72414 + return 0;
72415 +}
72416 +
72417 +int
72418 +gr_check_crash_uid(const kuid_t uid)
72419 +{
72420 + return 0;
72421 +}
72422 +
72423 +void
72424 +gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
72425 + struct dentry *old_dentry,
72426 + struct dentry *new_dentry,
72427 + struct vfsmount *mnt, const __u8 replace)
72428 +{
72429 + return;
72430 +}
72431 +
72432 +int
72433 +gr_search_socket(const int family, const int type, const int protocol)
72434 +{
72435 + return 1;
72436 +}
72437 +
72438 +int
72439 +gr_search_connectbind(const int mode, const struct socket *sock,
72440 + const struct sockaddr_in *addr)
72441 +{
72442 + return 0;
72443 +}
72444 +
72445 +void
72446 +gr_handle_alertkill(struct task_struct *task)
72447 +{
72448 + return;
72449 +}
72450 +
72451 +__u32
72452 +gr_acl_handle_execve(const struct dentry * dentry, const struct vfsmount * mnt)
72453 +{
72454 + return 1;
72455 +}
72456 +
72457 +__u32
72458 +gr_acl_handle_hidden_file(const struct dentry * dentry,
72459 + const struct vfsmount * mnt)
72460 +{
72461 + return 1;
72462 +}
72463 +
72464 +__u32
72465 +gr_acl_handle_open(const struct dentry * dentry, const struct vfsmount * mnt,
72466 + int acc_mode)
72467 +{
72468 + return 1;
72469 +}
72470 +
72471 +__u32
72472 +gr_acl_handle_rmdir(const struct dentry * dentry, const struct vfsmount * mnt)
72473 +{
72474 + return 1;
72475 +}
72476 +
72477 +__u32
72478 +gr_acl_handle_unlink(const struct dentry * dentry, const struct vfsmount * mnt)
72479 +{
72480 + return 1;
72481 +}
72482 +
72483 +int
72484 +gr_acl_handle_mmap(const struct file *file, const unsigned long prot,
72485 + unsigned int *vm_flags)
72486 +{
72487 + return 1;
72488 +}
72489 +
72490 +__u32
72491 +gr_acl_handle_truncate(const struct dentry * dentry,
72492 + const struct vfsmount * mnt)
72493 +{
72494 + return 1;
72495 +}
72496 +
72497 +__u32
72498 +gr_acl_handle_utime(const struct dentry * dentry, const struct vfsmount * mnt)
72499 +{
72500 + return 1;
72501 +}
72502 +
72503 +__u32
72504 +gr_acl_handle_access(const struct dentry * dentry,
72505 + const struct vfsmount * mnt, const int fmode)
72506 +{
72507 + return 1;
72508 +}
72509 +
72510 +__u32
72511 +gr_acl_handle_chmod(const struct dentry * dentry, const struct vfsmount * mnt,
72512 + umode_t *mode)
72513 +{
72514 + return 1;
72515 +}
72516 +
72517 +__u32
72518 +gr_acl_handle_chown(const struct dentry * dentry, const struct vfsmount * mnt)
72519 +{
72520 + return 1;
72521 +}
72522 +
72523 +__u32
72524 +gr_acl_handle_setxattr(const struct dentry * dentry, const struct vfsmount * mnt)
72525 +{
72526 + return 1;
72527 +}
72528 +
72529 +__u32
72530 +gr_acl_handle_removexattr(const struct dentry * dentry, const struct vfsmount * mnt)
72531 +{
72532 + return 1;
72533 +}
72534 +
72535 +void
72536 +grsecurity_init(void)
72537 +{
72538 + return;
72539 +}
72540 +
72541 +umode_t gr_acl_umask(void)
72542 +{
72543 + return 0;
72544 +}
72545 +
72546 +__u32
72547 +gr_acl_handle_mknod(const struct dentry * new_dentry,
72548 + const struct dentry * parent_dentry,
72549 + const struct vfsmount * parent_mnt,
72550 + const int mode)
72551 +{
72552 + return 1;
72553 +}
72554 +
72555 +__u32
72556 +gr_acl_handle_mkdir(const struct dentry * new_dentry,
72557 + const struct dentry * parent_dentry,
72558 + const struct vfsmount * parent_mnt)
72559 +{
72560 + return 1;
72561 +}
72562 +
72563 +__u32
72564 +gr_acl_handle_symlink(const struct dentry * new_dentry,
72565 + const struct dentry * parent_dentry,
72566 + const struct vfsmount * parent_mnt, const struct filename *from)
72567 +{
72568 + return 1;
72569 +}
72570 +
72571 +__u32
72572 +gr_acl_handle_link(const struct dentry * new_dentry,
72573 + const struct dentry * parent_dentry,
72574 + const struct vfsmount * parent_mnt,
72575 + const struct dentry * old_dentry,
72576 + const struct vfsmount * old_mnt, const struct filename *to)
72577 +{
72578 + return 1;
72579 +}
72580 +
72581 +int
72582 +gr_acl_handle_rename(const struct dentry *new_dentry,
72583 + const struct dentry *parent_dentry,
72584 + const struct vfsmount *parent_mnt,
72585 + const struct dentry *old_dentry,
72586 + const struct inode *old_parent_inode,
72587 + const struct vfsmount *old_mnt, const struct filename *newname)
72588 +{
72589 + return 0;
72590 +}
72591 +
72592 +int
72593 +gr_acl_handle_filldir(const struct file *file, const char *name,
72594 + const int namelen, const ino_t ino)
72595 +{
72596 + return 1;
72597 +}
72598 +
72599 +int
72600 +gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
72601 + const time_t shm_createtime, const kuid_t cuid, const int shmid)
72602 +{
72603 + return 1;
72604 +}
72605 +
72606 +int
72607 +gr_search_bind(const struct socket *sock, const struct sockaddr_in *addr)
72608 +{
72609 + return 0;
72610 +}
72611 +
72612 +int
72613 +gr_search_accept(const struct socket *sock)
72614 +{
72615 + return 0;
72616 +}
72617 +
72618 +int
72619 +gr_search_listen(const struct socket *sock)
72620 +{
72621 + return 0;
72622 +}
72623 +
72624 +int
72625 +gr_search_connect(const struct socket *sock, const struct sockaddr_in *addr)
72626 +{
72627 + return 0;
72628 +}
72629 +
72630 +__u32
72631 +gr_acl_handle_unix(const struct dentry * dentry, const struct vfsmount * mnt)
72632 +{
72633 + return 1;
72634 +}
72635 +
72636 +__u32
72637 +gr_acl_handle_creat(const struct dentry * dentry,
72638 + const struct dentry * p_dentry,
72639 + const struct vfsmount * p_mnt, int open_flags, int acc_mode,
72640 + const int imode)
72641 +{
72642 + return 1;
72643 +}
72644 +
72645 +void
72646 +gr_acl_handle_exit(void)
72647 +{
72648 + return;
72649 +}
72650 +
72651 +int
72652 +gr_acl_handle_mprotect(const struct file *file, const unsigned long prot)
72653 +{
72654 + return 1;
72655 +}
72656 +
72657 +void
72658 +gr_set_role_label(const kuid_t uid, const kgid_t gid)
72659 +{
72660 + return;
72661 +}
72662 +
72663 +int
72664 +gr_acl_handle_procpidmem(const struct task_struct *task)
72665 +{
72666 + return 0;
72667 +}
72668 +
72669 +int
72670 +gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb)
72671 +{
72672 + return 0;
72673 +}
72674 +
72675 +int
72676 +gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr)
72677 +{
72678 + return 0;
72679 +}
72680 +
72681 +int
72682 +gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs)
72683 +{
72684 + return 0;
72685 +}
72686 +
72687 +int
72688 +gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs)
72689 +{
72690 + return 0;
72691 +}
72692 +
72693 +int gr_acl_enable_at_secure(void)
72694 +{
72695 + return 0;
72696 +}
72697 +
72698 +dev_t gr_get_dev_from_dentry(struct dentry *dentry)
72699 +{
72700 + return dentry->d_sb->s_dev;
72701 +}
72702 +
72703 +void gr_put_exec_file(struct task_struct *task)
72704 +{
72705 + return;
72706 +}
72707 +
72708 +#ifdef CONFIG_SECURITY
72709 +EXPORT_SYMBOL_GPL(gr_check_user_change);
72710 +EXPORT_SYMBOL_GPL(gr_check_group_change);
72711 +#endif
72712 diff --git a/grsecurity/grsec_exec.c b/grsecurity/grsec_exec.c
72713 new file mode 100644
72714 index 0000000..f35f454
72715 --- /dev/null
72716 +++ b/grsecurity/grsec_exec.c
72717 @@ -0,0 +1,187 @@
72718 +#include <linux/kernel.h>
72719 +#include <linux/sched.h>
72720 +#include <linux/file.h>
72721 +#include <linux/binfmts.h>
72722 +#include <linux/fs.h>
72723 +#include <linux/types.h>
72724 +#include <linux/grdefs.h>
72725 +#include <linux/grsecurity.h>
72726 +#include <linux/grinternal.h>
72727 +#include <linux/capability.h>
72728 +#include <linux/module.h>
72729 +#include <linux/compat.h>
72730 +
72731 +#include <asm/uaccess.h>
72732 +
72733 +#ifdef CONFIG_GRKERNSEC_EXECLOG
72734 +static char gr_exec_arg_buf[132];
72735 +static DEFINE_MUTEX(gr_exec_arg_mutex);
72736 +#endif
72737 +
72738 +struct user_arg_ptr {
72739 +#ifdef CONFIG_COMPAT
72740 + bool is_compat;
72741 +#endif
72742 + union {
72743 + const char __user *const __user *native;
72744 +#ifdef CONFIG_COMPAT
72745 + const compat_uptr_t __user *compat;
72746 +#endif
72747 + } ptr;
72748 +};
72749 +
72750 +extern const char __user *get_user_arg_ptr(struct user_arg_ptr argv, int nr);
72751 +
72752 +void
72753 +gr_handle_exec_args(struct linux_binprm *bprm, struct user_arg_ptr argv)
72754 +{
72755 +#ifdef CONFIG_GRKERNSEC_EXECLOG
72756 + char *grarg = gr_exec_arg_buf;
72757 + unsigned int i, x, execlen = 0;
72758 + char c;
72759 +
72760 + if (!((grsec_enable_execlog && grsec_enable_group &&
72761 + in_group_p(grsec_audit_gid))
72762 + || (grsec_enable_execlog && !grsec_enable_group)))
72763 + return;
72764 +
72765 + mutex_lock(&gr_exec_arg_mutex);
72766 + memset(grarg, 0, sizeof(gr_exec_arg_buf));
72767 +
72768 + for (i = 0; i < bprm->argc && execlen < 128; i++) {
72769 + const char __user *p;
72770 + unsigned int len;
72771 +
72772 + p = get_user_arg_ptr(argv, i);
72773 + if (IS_ERR(p))
72774 + goto log;
72775 +
72776 + len = strnlen_user(p, 128 - execlen);
72777 + if (len > 128 - execlen)
72778 + len = 128 - execlen;
72779 + else if (len > 0)
72780 + len--;
72781 + if (copy_from_user(grarg + execlen, p, len))
72782 + goto log;
72783 +
72784 + /* rewrite unprintable characters */
72785 + for (x = 0; x < len; x++) {
72786 + c = *(grarg + execlen + x);
72787 + if (c < 32 || c > 126)
72788 + *(grarg + execlen + x) = ' ';
72789 + }
72790 +
72791 + execlen += len;
72792 + *(grarg + execlen) = ' ';
72793 + *(grarg + execlen + 1) = '\0';
72794 + execlen++;
72795 + }
72796 +
72797 + log:
72798 + gr_log_fs_str(GR_DO_AUDIT, GR_EXEC_AUDIT_MSG, bprm->file->f_path.dentry,
72799 + bprm->file->f_path.mnt, grarg);
72800 + mutex_unlock(&gr_exec_arg_mutex);
72801 +#endif
72802 + return;
72803 +}
72804 +
72805 +#ifdef CONFIG_GRKERNSEC
72806 +extern int gr_acl_is_capable(const int cap);
72807 +extern int gr_acl_is_capable_nolog(const int cap);
72808 +extern int gr_task_acl_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
72809 +extern int gr_task_acl_is_capable_nolog(const struct task_struct *task, const int cap);
72810 +extern int gr_chroot_is_capable(const int cap);
72811 +extern int gr_chroot_is_capable_nolog(const int cap);
72812 +extern int gr_task_chroot_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
72813 +extern int gr_task_chroot_is_capable_nolog(const struct task_struct *task, const int cap);
72814 +#endif
72815 +
72816 +const char *captab_log[] = {
72817 + "CAP_CHOWN",
72818 + "CAP_DAC_OVERRIDE",
72819 + "CAP_DAC_READ_SEARCH",
72820 + "CAP_FOWNER",
72821 + "CAP_FSETID",
72822 + "CAP_KILL",
72823 + "CAP_SETGID",
72824 + "CAP_SETUID",
72825 + "CAP_SETPCAP",
72826 + "CAP_LINUX_IMMUTABLE",
72827 + "CAP_NET_BIND_SERVICE",
72828 + "CAP_NET_BROADCAST",
72829 + "CAP_NET_ADMIN",
72830 + "CAP_NET_RAW",
72831 + "CAP_IPC_LOCK",
72832 + "CAP_IPC_OWNER",
72833 + "CAP_SYS_MODULE",
72834 + "CAP_SYS_RAWIO",
72835 + "CAP_SYS_CHROOT",
72836 + "CAP_SYS_PTRACE",
72837 + "CAP_SYS_PACCT",
72838 + "CAP_SYS_ADMIN",
72839 + "CAP_SYS_BOOT",
72840 + "CAP_SYS_NICE",
72841 + "CAP_SYS_RESOURCE",
72842 + "CAP_SYS_TIME",
72843 + "CAP_SYS_TTY_CONFIG",
72844 + "CAP_MKNOD",
72845 + "CAP_LEASE",
72846 + "CAP_AUDIT_WRITE",
72847 + "CAP_AUDIT_CONTROL",
72848 + "CAP_SETFCAP",
72849 + "CAP_MAC_OVERRIDE",
72850 + "CAP_MAC_ADMIN",
72851 + "CAP_SYSLOG",
72852 + "CAP_WAKE_ALARM"
72853 +};
72854 +
72855 +int captab_log_entries = sizeof(captab_log)/sizeof(captab_log[0]);
72856 +
72857 +int gr_is_capable(const int cap)
72858 +{
72859 +#ifdef CONFIG_GRKERNSEC
72860 + if (gr_acl_is_capable(cap) && gr_chroot_is_capable(cap))
72861 + return 1;
72862 + return 0;
72863 +#else
72864 + return 1;
72865 +#endif
72866 +}
72867 +
72868 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap)
72869 +{
72870 +#ifdef CONFIG_GRKERNSEC
72871 + if (gr_task_acl_is_capable(task, cred, cap) && gr_task_chroot_is_capable(task, cred, cap))
72872 + return 1;
72873 + return 0;
72874 +#else
72875 + return 1;
72876 +#endif
72877 +}
72878 +
72879 +int gr_is_capable_nolog(const int cap)
72880 +{
72881 +#ifdef CONFIG_GRKERNSEC
72882 + if (gr_acl_is_capable_nolog(cap) && gr_chroot_is_capable_nolog(cap))
72883 + return 1;
72884 + return 0;
72885 +#else
72886 + return 1;
72887 +#endif
72888 +}
72889 +
72890 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap)
72891 +{
72892 +#ifdef CONFIG_GRKERNSEC
72893 + if (gr_task_acl_is_capable_nolog(task, cap) && gr_task_chroot_is_capable_nolog(task, cap))
72894 + return 1;
72895 + return 0;
72896 +#else
72897 + return 1;
72898 +#endif
72899 +}
72900 +
72901 +EXPORT_SYMBOL_GPL(gr_is_capable);
72902 +EXPORT_SYMBOL_GPL(gr_is_capable_nolog);
72903 +EXPORT_SYMBOL_GPL(gr_task_is_capable);
72904 +EXPORT_SYMBOL_GPL(gr_task_is_capable_nolog);
72905 diff --git a/grsecurity/grsec_fifo.c b/grsecurity/grsec_fifo.c
72906 new file mode 100644
72907 index 0000000..06cc6ea
72908 --- /dev/null
72909 +++ b/grsecurity/grsec_fifo.c
72910 @@ -0,0 +1,24 @@
72911 +#include <linux/kernel.h>
72912 +#include <linux/sched.h>
72913 +#include <linux/fs.h>
72914 +#include <linux/file.h>
72915 +#include <linux/grinternal.h>
72916 +
72917 +int
72918 +gr_handle_fifo(const struct dentry *dentry, const struct vfsmount *mnt,
72919 + const struct dentry *dir, const int flag, const int acc_mode)
72920 +{
72921 +#ifdef CONFIG_GRKERNSEC_FIFO
72922 + const struct cred *cred = current_cred();
72923 +
72924 + if (grsec_enable_fifo && S_ISFIFO(dentry->d_inode->i_mode) &&
72925 + !(flag & O_EXCL) && (dir->d_inode->i_mode & S_ISVTX) &&
72926 + !uid_eq(dentry->d_inode->i_uid, dir->d_inode->i_uid) &&
72927 + !uid_eq(cred->fsuid, dentry->d_inode->i_uid)) {
72928 + if (!inode_permission(dentry->d_inode, acc_mode))
72929 + 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));
72930 + return -EACCES;
72931 + }
72932 +#endif
72933 + return 0;
72934 +}
72935 diff --git a/grsecurity/grsec_fork.c b/grsecurity/grsec_fork.c
72936 new file mode 100644
72937 index 0000000..8ca18bf
72938 --- /dev/null
72939 +++ b/grsecurity/grsec_fork.c
72940 @@ -0,0 +1,23 @@
72941 +#include <linux/kernel.h>
72942 +#include <linux/sched.h>
72943 +#include <linux/grsecurity.h>
72944 +#include <linux/grinternal.h>
72945 +#include <linux/errno.h>
72946 +
72947 +void
72948 +gr_log_forkfail(const int retval)
72949 +{
72950 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
72951 + if (grsec_enable_forkfail && (retval == -EAGAIN || retval == -ENOMEM)) {
72952 + switch (retval) {
72953 + case -EAGAIN:
72954 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "EAGAIN");
72955 + break;
72956 + case -ENOMEM:
72957 + gr_log_str(GR_DONT_AUDIT, GR_FAILFORK_MSG, "ENOMEM");
72958 + break;
72959 + }
72960 + }
72961 +#endif
72962 + return;
72963 +}
72964 diff --git a/grsecurity/grsec_init.c b/grsecurity/grsec_init.c
72965 new file mode 100644
72966 index 0000000..ae6c028
72967 --- /dev/null
72968 +++ b/grsecurity/grsec_init.c
72969 @@ -0,0 +1,272 @@
72970 +#include <linux/kernel.h>
72971 +#include <linux/sched.h>
72972 +#include <linux/mm.h>
72973 +#include <linux/gracl.h>
72974 +#include <linux/slab.h>
72975 +#include <linux/vmalloc.h>
72976 +#include <linux/percpu.h>
72977 +#include <linux/module.h>
72978 +
72979 +int grsec_enable_ptrace_readexec;
72980 +int grsec_enable_setxid;
72981 +int grsec_enable_symlinkown;
72982 +kgid_t grsec_symlinkown_gid;
72983 +int grsec_enable_brute;
72984 +int grsec_enable_link;
72985 +int grsec_enable_dmesg;
72986 +int grsec_enable_harden_ptrace;
72987 +int grsec_enable_harden_ipc;
72988 +int grsec_enable_fifo;
72989 +int grsec_enable_execlog;
72990 +int grsec_enable_signal;
72991 +int grsec_enable_forkfail;
72992 +int grsec_enable_audit_ptrace;
72993 +int grsec_enable_time;
72994 +int grsec_enable_group;
72995 +kgid_t grsec_audit_gid;
72996 +int grsec_enable_chdir;
72997 +int grsec_enable_mount;
72998 +int grsec_enable_rofs;
72999 +int grsec_deny_new_usb;
73000 +int grsec_enable_chroot_findtask;
73001 +int grsec_enable_chroot_mount;
73002 +int grsec_enable_chroot_shmat;
73003 +int grsec_enable_chroot_fchdir;
73004 +int grsec_enable_chroot_double;
73005 +int grsec_enable_chroot_pivot;
73006 +int grsec_enable_chroot_chdir;
73007 +int grsec_enable_chroot_chmod;
73008 +int grsec_enable_chroot_mknod;
73009 +int grsec_enable_chroot_nice;
73010 +int grsec_enable_chroot_execlog;
73011 +int grsec_enable_chroot_caps;
73012 +int grsec_enable_chroot_sysctl;
73013 +int grsec_enable_chroot_unix;
73014 +int grsec_enable_tpe;
73015 +kgid_t grsec_tpe_gid;
73016 +int grsec_enable_blackhole;
73017 +#ifdef CONFIG_IPV6_MODULE
73018 +EXPORT_SYMBOL_GPL(grsec_enable_blackhole);
73019 +#endif
73020 +int grsec_lastack_retries;
73021 +int grsec_enable_tpe_all;
73022 +int grsec_enable_tpe_invert;
73023 +int grsec_enable_socket_all;
73024 +kgid_t grsec_socket_all_gid;
73025 +int grsec_enable_socket_client;
73026 +kgid_t grsec_socket_client_gid;
73027 +int grsec_enable_socket_server;
73028 +kgid_t grsec_socket_server_gid;
73029 +int grsec_resource_logging;
73030 +int grsec_disable_privio;
73031 +int grsec_enable_log_rwxmaps;
73032 +int grsec_lock;
73033 +
73034 +DEFINE_SPINLOCK(grsec_alert_lock);
73035 +unsigned long grsec_alert_wtime = 0;
73036 +unsigned long grsec_alert_fyet = 0;
73037 +
73038 +DEFINE_SPINLOCK(grsec_audit_lock);
73039 +
73040 +DEFINE_RWLOCK(grsec_exec_file_lock);
73041 +
73042 +char *gr_shared_page[4];
73043 +
73044 +char *gr_alert_log_fmt;
73045 +char *gr_audit_log_fmt;
73046 +char *gr_alert_log_buf;
73047 +char *gr_audit_log_buf;
73048 +
73049 +void __init
73050 +grsecurity_init(void)
73051 +{
73052 + int j;
73053 + /* create the per-cpu shared pages */
73054 +
73055 +#ifdef CONFIG_X86
73056 + memset((char *)(0x41a + PAGE_OFFSET), 0, 36);
73057 +#endif
73058 +
73059 + for (j = 0; j < 4; j++) {
73060 + gr_shared_page[j] = (char *)__alloc_percpu(PAGE_SIZE, __alignof__(unsigned long long));
73061 + if (gr_shared_page[j] == NULL) {
73062 + panic("Unable to allocate grsecurity shared page");
73063 + return;
73064 + }
73065 + }
73066 +
73067 + /* allocate log buffers */
73068 + gr_alert_log_fmt = kmalloc(512, GFP_KERNEL);
73069 + if (!gr_alert_log_fmt) {
73070 + panic("Unable to allocate grsecurity alert log format buffer");
73071 + return;
73072 + }
73073 + gr_audit_log_fmt = kmalloc(512, GFP_KERNEL);
73074 + if (!gr_audit_log_fmt) {
73075 + panic("Unable to allocate grsecurity audit log format buffer");
73076 + return;
73077 + }
73078 + gr_alert_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
73079 + if (!gr_alert_log_buf) {
73080 + panic("Unable to allocate grsecurity alert log buffer");
73081 + return;
73082 + }
73083 + gr_audit_log_buf = (char *) get_zeroed_page(GFP_KERNEL);
73084 + if (!gr_audit_log_buf) {
73085 + panic("Unable to allocate grsecurity audit log buffer");
73086 + return;
73087 + }
73088 +
73089 +#ifdef CONFIG_GRKERNSEC_IO
73090 +#if !defined(CONFIG_GRKERNSEC_SYSCTL_DISTRO)
73091 + grsec_disable_privio = 1;
73092 +#elif defined(CONFIG_GRKERNSEC_SYSCTL_ON)
73093 + grsec_disable_privio = 1;
73094 +#else
73095 + grsec_disable_privio = 0;
73096 +#endif
73097 +#endif
73098 +
73099 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
73100 + /* for backward compatibility, tpe_invert always defaults to on if
73101 + enabled in the kernel
73102 + */
73103 + grsec_enable_tpe_invert = 1;
73104 +#endif
73105 +
73106 +#if !defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_SYSCTL_ON)
73107 +#ifndef CONFIG_GRKERNSEC_SYSCTL
73108 + grsec_lock = 1;
73109 +#endif
73110 +
73111 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73112 + grsec_enable_log_rwxmaps = 1;
73113 +#endif
73114 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
73115 + grsec_enable_group = 1;
73116 + grsec_audit_gid = KGIDT_INIT(CONFIG_GRKERNSEC_AUDIT_GID);
73117 +#endif
73118 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
73119 + grsec_enable_ptrace_readexec = 1;
73120 +#endif
73121 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
73122 + grsec_enable_chdir = 1;
73123 +#endif
73124 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
73125 + grsec_enable_harden_ptrace = 1;
73126 +#endif
73127 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
73128 + grsec_enable_harden_ipc = 1;
73129 +#endif
73130 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73131 + grsec_enable_mount = 1;
73132 +#endif
73133 +#ifdef CONFIG_GRKERNSEC_LINK
73134 + grsec_enable_link = 1;
73135 +#endif
73136 +#ifdef CONFIG_GRKERNSEC_BRUTE
73137 + grsec_enable_brute = 1;
73138 +#endif
73139 +#ifdef CONFIG_GRKERNSEC_DMESG
73140 + grsec_enable_dmesg = 1;
73141 +#endif
73142 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
73143 + grsec_enable_blackhole = 1;
73144 + grsec_lastack_retries = 4;
73145 +#endif
73146 +#ifdef CONFIG_GRKERNSEC_FIFO
73147 + grsec_enable_fifo = 1;
73148 +#endif
73149 +#ifdef CONFIG_GRKERNSEC_EXECLOG
73150 + grsec_enable_execlog = 1;
73151 +#endif
73152 +#ifdef CONFIG_GRKERNSEC_SETXID
73153 + grsec_enable_setxid = 1;
73154 +#endif
73155 +#ifdef CONFIG_GRKERNSEC_SIGNAL
73156 + grsec_enable_signal = 1;
73157 +#endif
73158 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
73159 + grsec_enable_forkfail = 1;
73160 +#endif
73161 +#ifdef CONFIG_GRKERNSEC_TIME
73162 + grsec_enable_time = 1;
73163 +#endif
73164 +#ifdef CONFIG_GRKERNSEC_RESLOG
73165 + grsec_resource_logging = 1;
73166 +#endif
73167 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
73168 + grsec_enable_chroot_findtask = 1;
73169 +#endif
73170 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
73171 + grsec_enable_chroot_unix = 1;
73172 +#endif
73173 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
73174 + grsec_enable_chroot_mount = 1;
73175 +#endif
73176 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
73177 + grsec_enable_chroot_fchdir = 1;
73178 +#endif
73179 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
73180 + grsec_enable_chroot_shmat = 1;
73181 +#endif
73182 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
73183 + grsec_enable_audit_ptrace = 1;
73184 +#endif
73185 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
73186 + grsec_enable_chroot_double = 1;
73187 +#endif
73188 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
73189 + grsec_enable_chroot_pivot = 1;
73190 +#endif
73191 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
73192 + grsec_enable_chroot_chdir = 1;
73193 +#endif
73194 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
73195 + grsec_enable_chroot_chmod = 1;
73196 +#endif
73197 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
73198 + grsec_enable_chroot_mknod = 1;
73199 +#endif
73200 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
73201 + grsec_enable_chroot_nice = 1;
73202 +#endif
73203 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
73204 + grsec_enable_chroot_execlog = 1;
73205 +#endif
73206 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
73207 + grsec_enable_chroot_caps = 1;
73208 +#endif
73209 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
73210 + grsec_enable_chroot_sysctl = 1;
73211 +#endif
73212 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
73213 + grsec_enable_symlinkown = 1;
73214 + grsec_symlinkown_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SYMLINKOWN_GID);
73215 +#endif
73216 +#ifdef CONFIG_GRKERNSEC_TPE
73217 + grsec_enable_tpe = 1;
73218 + grsec_tpe_gid = KGIDT_INIT(CONFIG_GRKERNSEC_TPE_GID);
73219 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
73220 + grsec_enable_tpe_all = 1;
73221 +#endif
73222 +#endif
73223 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
73224 + grsec_enable_socket_all = 1;
73225 + grsec_socket_all_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_ALL_GID);
73226 +#endif
73227 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
73228 + grsec_enable_socket_client = 1;
73229 + grsec_socket_client_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_CLIENT_GID);
73230 +#endif
73231 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
73232 + grsec_enable_socket_server = 1;
73233 + grsec_socket_server_gid = KGIDT_INIT(CONFIG_GRKERNSEC_SOCKET_SERVER_GID);
73234 +#endif
73235 +#endif
73236 +#ifdef CONFIG_GRKERNSEC_DENYUSB_FORCE
73237 + grsec_deny_new_usb = 1;
73238 +#endif
73239 +
73240 + return;
73241 +}
73242 diff --git a/grsecurity/grsec_ipc.c b/grsecurity/grsec_ipc.c
73243 new file mode 100644
73244 index 0000000..78d1680
73245 --- /dev/null
73246 +++ b/grsecurity/grsec_ipc.c
73247 @@ -0,0 +1,48 @@
73248 +#include <linux/kernel.h>
73249 +#include <linux/mm.h>
73250 +#include <linux/sched.h>
73251 +#include <linux/file.h>
73252 +#include <linux/ipc.h>
73253 +#include <linux/ipc_namespace.h>
73254 +#include <linux/grsecurity.h>
73255 +#include <linux/grinternal.h>
73256 +
73257 +int
73258 +gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode)
73259 +{
73260 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
73261 + int write;
73262 + int orig_granted_mode;
73263 + kuid_t euid;
73264 + kgid_t egid;
73265 +
73266 + if (!grsec_enable_harden_ipc)
73267 + return 0;
73268 +
73269 + euid = current_euid();
73270 + egid = current_egid();
73271 +
73272 + write = requested_mode & 00002;
73273 + orig_granted_mode = ipcp->mode;
73274 +
73275 + if (uid_eq(euid, ipcp->cuid) || uid_eq(euid, ipcp->uid))
73276 + orig_granted_mode >>= 6;
73277 + else {
73278 + /* if likely wrong permissions, lock to user */
73279 + if (orig_granted_mode & 0007)
73280 + orig_granted_mode = 0;
73281 + /* otherwise do a egid-only check */
73282 + else if (gid_eq(egid, ipcp->cgid) || gid_eq(egid, ipcp->gid))
73283 + orig_granted_mode >>= 3;
73284 + /* otherwise, no access */
73285 + else
73286 + orig_granted_mode = 0;
73287 + }
73288 + if (!(requested_mode & ~granted_mode & 0007) && (requested_mode & ~orig_granted_mode & 0007) &&
73289 + !ns_capable_nolog(ns->user_ns, CAP_IPC_OWNER)) {
73290 + gr_log_str_int(GR_DONT_AUDIT, GR_IPC_DENIED_MSG, write ? "write" : "read", GR_GLOBAL_UID(ipcp->cuid));
73291 + return 0;
73292 + }
73293 +#endif
73294 + return 1;
73295 +}
73296 diff --git a/grsecurity/grsec_link.c b/grsecurity/grsec_link.c
73297 new file mode 100644
73298 index 0000000..5e05e20
73299 --- /dev/null
73300 +++ b/grsecurity/grsec_link.c
73301 @@ -0,0 +1,58 @@
73302 +#include <linux/kernel.h>
73303 +#include <linux/sched.h>
73304 +#include <linux/fs.h>
73305 +#include <linux/file.h>
73306 +#include <linux/grinternal.h>
73307 +
73308 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target)
73309 +{
73310 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
73311 + const struct inode *link_inode = link->dentry->d_inode;
73312 +
73313 + if (grsec_enable_symlinkown && in_group_p(grsec_symlinkown_gid) &&
73314 + /* ignore root-owned links, e.g. /proc/self */
73315 + gr_is_global_nonroot(link_inode->i_uid) && target &&
73316 + !uid_eq(link_inode->i_uid, target->i_uid)) {
73317 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINKOWNER_MSG, link->dentry, link->mnt, link_inode->i_uid, target->i_uid);
73318 + return 1;
73319 + }
73320 +#endif
73321 + return 0;
73322 +}
73323 +
73324 +int
73325 +gr_handle_follow_link(const struct inode *parent,
73326 + const struct inode *inode,
73327 + const struct dentry *dentry, const struct vfsmount *mnt)
73328 +{
73329 +#ifdef CONFIG_GRKERNSEC_LINK
73330 + const struct cred *cred = current_cred();
73331 +
73332 + if (grsec_enable_link && S_ISLNK(inode->i_mode) &&
73333 + (parent->i_mode & S_ISVTX) && !uid_eq(parent->i_uid, inode->i_uid) &&
73334 + (parent->i_mode & S_IWOTH) && !uid_eq(cred->fsuid, inode->i_uid)) {
73335 + gr_log_fs_int2(GR_DONT_AUDIT, GR_SYMLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid);
73336 + return -EACCES;
73337 + }
73338 +#endif
73339 + return 0;
73340 +}
73341 +
73342 +int
73343 +gr_handle_hardlink(const struct dentry *dentry,
73344 + const struct vfsmount *mnt,
73345 + struct inode *inode, const int mode, const struct filename *to)
73346 +{
73347 +#ifdef CONFIG_GRKERNSEC_LINK
73348 + const struct cred *cred = current_cred();
73349 +
73350 + if (grsec_enable_link && !uid_eq(cred->fsuid, inode->i_uid) &&
73351 + (!S_ISREG(mode) || is_privileged_binary(dentry) ||
73352 + (inode_permission(inode, MAY_READ | MAY_WRITE))) &&
73353 + !capable(CAP_FOWNER) && gr_is_global_nonroot(cred->uid)) {
73354 + gr_log_fs_int2_str(GR_DONT_AUDIT, GR_HARDLINK_MSG, dentry, mnt, inode->i_uid, inode->i_gid, to->name);
73355 + return -EPERM;
73356 + }
73357 +#endif
73358 + return 0;
73359 +}
73360 diff --git a/grsecurity/grsec_log.c b/grsecurity/grsec_log.c
73361 new file mode 100644
73362 index 0000000..dbe0a6b
73363 --- /dev/null
73364 +++ b/grsecurity/grsec_log.c
73365 @@ -0,0 +1,341 @@
73366 +#include <linux/kernel.h>
73367 +#include <linux/sched.h>
73368 +#include <linux/file.h>
73369 +#include <linux/tty.h>
73370 +#include <linux/fs.h>
73371 +#include <linux/mm.h>
73372 +#include <linux/grinternal.h>
73373 +
73374 +#ifdef CONFIG_TREE_PREEMPT_RCU
73375 +#define DISABLE_PREEMPT() preempt_disable()
73376 +#define ENABLE_PREEMPT() preempt_enable()
73377 +#else
73378 +#define DISABLE_PREEMPT()
73379 +#define ENABLE_PREEMPT()
73380 +#endif
73381 +
73382 +#define BEGIN_LOCKS(x) \
73383 + DISABLE_PREEMPT(); \
73384 + rcu_read_lock(); \
73385 + read_lock(&tasklist_lock); \
73386 + read_lock(&grsec_exec_file_lock); \
73387 + if (x != GR_DO_AUDIT) \
73388 + spin_lock(&grsec_alert_lock); \
73389 + else \
73390 + spin_lock(&grsec_audit_lock)
73391 +
73392 +#define END_LOCKS(x) \
73393 + if (x != GR_DO_AUDIT) \
73394 + spin_unlock(&grsec_alert_lock); \
73395 + else \
73396 + spin_unlock(&grsec_audit_lock); \
73397 + read_unlock(&grsec_exec_file_lock); \
73398 + read_unlock(&tasklist_lock); \
73399 + rcu_read_unlock(); \
73400 + ENABLE_PREEMPT(); \
73401 + if (x == GR_DONT_AUDIT) \
73402 + gr_handle_alertkill(current)
73403 +
73404 +enum {
73405 + FLOODING,
73406 + NO_FLOODING
73407 +};
73408 +
73409 +extern char *gr_alert_log_fmt;
73410 +extern char *gr_audit_log_fmt;
73411 +extern char *gr_alert_log_buf;
73412 +extern char *gr_audit_log_buf;
73413 +
73414 +static int gr_log_start(int audit)
73415 +{
73416 + char *loglevel = (audit == GR_DO_AUDIT) ? KERN_INFO : KERN_ALERT;
73417 + char *fmt = (audit == GR_DO_AUDIT) ? gr_audit_log_fmt : gr_alert_log_fmt;
73418 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73419 +#if (CONFIG_GRKERNSEC_FLOODTIME > 0 && CONFIG_GRKERNSEC_FLOODBURST > 0)
73420 + unsigned long curr_secs = get_seconds();
73421 +
73422 + if (audit == GR_DO_AUDIT)
73423 + goto set_fmt;
73424 +
73425 + if (!grsec_alert_wtime || time_after(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)) {
73426 + grsec_alert_wtime = curr_secs;
73427 + grsec_alert_fyet = 0;
73428 + } else if (time_before_eq(curr_secs, grsec_alert_wtime + CONFIG_GRKERNSEC_FLOODTIME)
73429 + && (grsec_alert_fyet < CONFIG_GRKERNSEC_FLOODBURST)) {
73430 + grsec_alert_fyet++;
73431 + } else if (grsec_alert_fyet == CONFIG_GRKERNSEC_FLOODBURST) {
73432 + grsec_alert_wtime = curr_secs;
73433 + grsec_alert_fyet++;
73434 + printk(KERN_ALERT "grsec: more alerts, logging disabled for %d seconds\n", CONFIG_GRKERNSEC_FLOODTIME);
73435 + return FLOODING;
73436 + }
73437 + else return FLOODING;
73438 +
73439 +set_fmt:
73440 +#endif
73441 + memset(buf, 0, PAGE_SIZE);
73442 + if (current->signal->curr_ip && gr_acl_is_enabled()) {
73443 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: (%.64s:%c:%.950s) ");
73444 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
73445 + } else if (current->signal->curr_ip) {
73446 + sprintf(fmt, "%s%s", loglevel, "grsec: From %pI4: ");
73447 + snprintf(buf, PAGE_SIZE - 1, fmt, &current->signal->curr_ip);
73448 + } else if (gr_acl_is_enabled()) {
73449 + sprintf(fmt, "%s%s", loglevel, "grsec: (%.64s:%c:%.950s) ");
73450 + snprintf(buf, PAGE_SIZE - 1, fmt, current->role->rolename, gr_roletype_to_char(), current->acl->filename);
73451 + } else {
73452 + sprintf(fmt, "%s%s", loglevel, "grsec: ");
73453 + strcpy(buf, fmt);
73454 + }
73455 +
73456 + return NO_FLOODING;
73457 +}
73458 +
73459 +static void gr_log_middle(int audit, const char *msg, va_list ap)
73460 + __attribute__ ((format (printf, 2, 0)));
73461 +
73462 +static void gr_log_middle(int audit, const char *msg, va_list ap)
73463 +{
73464 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73465 + unsigned int len = strlen(buf);
73466 +
73467 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
73468 +
73469 + return;
73470 +}
73471 +
73472 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
73473 + __attribute__ ((format (printf, 2, 3)));
73474 +
73475 +static void gr_log_middle_varargs(int audit, const char *msg, ...)
73476 +{
73477 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73478 + unsigned int len = strlen(buf);
73479 + va_list ap;
73480 +
73481 + va_start(ap, msg);
73482 + vsnprintf(buf + len, PAGE_SIZE - len - 1, msg, ap);
73483 + va_end(ap);
73484 +
73485 + return;
73486 +}
73487 +
73488 +static void gr_log_end(int audit, int append_default)
73489 +{
73490 + char *buf = (audit == GR_DO_AUDIT) ? gr_audit_log_buf : gr_alert_log_buf;
73491 + if (append_default) {
73492 + struct task_struct *task = current;
73493 + struct task_struct *parent = task->real_parent;
73494 + const struct cred *cred = __task_cred(task);
73495 + const struct cred *pcred = __task_cred(parent);
73496 + unsigned int len = strlen(buf);
73497 +
73498 + 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));
73499 + }
73500 +
73501 + printk("%s\n", buf);
73502 +
73503 + return;
73504 +}
73505 +
73506 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...)
73507 +{
73508 + int logtype;
73509 + char *result = (audit == GR_DO_AUDIT) ? "successful" : "denied";
73510 + char *str1 = NULL, *str2 = NULL, *str3 = NULL;
73511 + void *voidptr = NULL;
73512 + int num1 = 0, num2 = 0;
73513 + unsigned long ulong1 = 0, ulong2 = 0;
73514 + struct dentry *dentry = NULL;
73515 + struct vfsmount *mnt = NULL;
73516 + struct file *file = NULL;
73517 + struct task_struct *task = NULL;
73518 + struct vm_area_struct *vma = NULL;
73519 + const struct cred *cred, *pcred;
73520 + va_list ap;
73521 +
73522 + BEGIN_LOCKS(audit);
73523 + logtype = gr_log_start(audit);
73524 + if (logtype == FLOODING) {
73525 + END_LOCKS(audit);
73526 + return;
73527 + }
73528 + va_start(ap, argtypes);
73529 + switch (argtypes) {
73530 + case GR_TTYSNIFF:
73531 + task = va_arg(ap, struct task_struct *);
73532 + 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));
73533 + break;
73534 + case GR_SYSCTL_HIDDEN:
73535 + str1 = va_arg(ap, char *);
73536 + gr_log_middle_varargs(audit, msg, result, str1);
73537 + break;
73538 + case GR_RBAC:
73539 + dentry = va_arg(ap, struct dentry *);
73540 + mnt = va_arg(ap, struct vfsmount *);
73541 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt));
73542 + break;
73543 + case GR_RBAC_STR:
73544 + dentry = va_arg(ap, struct dentry *);
73545 + mnt = va_arg(ap, struct vfsmount *);
73546 + str1 = va_arg(ap, char *);
73547 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1);
73548 + break;
73549 + case GR_STR_RBAC:
73550 + str1 = va_arg(ap, char *);
73551 + dentry = va_arg(ap, struct dentry *);
73552 + mnt = va_arg(ap, struct vfsmount *);
73553 + gr_log_middle_varargs(audit, msg, result, str1, gr_to_filename(dentry, mnt));
73554 + break;
73555 + case GR_RBAC_MODE2:
73556 + dentry = va_arg(ap, struct dentry *);
73557 + mnt = va_arg(ap, struct vfsmount *);
73558 + str1 = va_arg(ap, char *);
73559 + str2 = va_arg(ap, char *);
73560 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2);
73561 + break;
73562 + case GR_RBAC_MODE3:
73563 + dentry = va_arg(ap, struct dentry *);
73564 + mnt = va_arg(ap, struct vfsmount *);
73565 + str1 = va_arg(ap, char *);
73566 + str2 = va_arg(ap, char *);
73567 + str3 = va_arg(ap, char *);
73568 + gr_log_middle_varargs(audit, msg, result, gr_to_filename(dentry, mnt), str1, str2, str3);
73569 + break;
73570 + case GR_FILENAME:
73571 + dentry = va_arg(ap, struct dentry *);
73572 + mnt = va_arg(ap, struct vfsmount *);
73573 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt));
73574 + break;
73575 + case GR_STR_FILENAME:
73576 + str1 = va_arg(ap, char *);
73577 + dentry = va_arg(ap, struct dentry *);
73578 + mnt = va_arg(ap, struct vfsmount *);
73579 + gr_log_middle_varargs(audit, msg, str1, gr_to_filename(dentry, mnt));
73580 + break;
73581 + case GR_FILENAME_STR:
73582 + dentry = va_arg(ap, struct dentry *);
73583 + mnt = va_arg(ap, struct vfsmount *);
73584 + str1 = va_arg(ap, char *);
73585 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), str1);
73586 + break;
73587 + case GR_FILENAME_TWO_INT:
73588 + dentry = va_arg(ap, struct dentry *);
73589 + mnt = va_arg(ap, struct vfsmount *);
73590 + num1 = va_arg(ap, int);
73591 + num2 = va_arg(ap, int);
73592 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2);
73593 + break;
73594 + case GR_FILENAME_TWO_INT_STR:
73595 + dentry = va_arg(ap, struct dentry *);
73596 + mnt = va_arg(ap, struct vfsmount *);
73597 + num1 = va_arg(ap, int);
73598 + num2 = va_arg(ap, int);
73599 + str1 = va_arg(ap, char *);
73600 + gr_log_middle_varargs(audit, msg, gr_to_filename(dentry, mnt), num1, num2, str1);
73601 + break;
73602 + case GR_TEXTREL:
73603 + file = va_arg(ap, struct file *);
73604 + ulong1 = va_arg(ap, unsigned long);
73605 + ulong2 = va_arg(ap, unsigned long);
73606 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>", ulong1, ulong2);
73607 + break;
73608 + case GR_PTRACE:
73609 + task = va_arg(ap, struct task_struct *);
73610 + 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));
73611 + break;
73612 + case GR_RESOURCE:
73613 + task = va_arg(ap, struct task_struct *);
73614 + cred = __task_cred(task);
73615 + pcred = __task_cred(task->real_parent);
73616 + ulong1 = va_arg(ap, unsigned long);
73617 + str1 = va_arg(ap, char *);
73618 + ulong2 = va_arg(ap, unsigned long);
73619 + 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));
73620 + break;
73621 + case GR_CAP:
73622 + task = va_arg(ap, struct task_struct *);
73623 + cred = __task_cred(task);
73624 + pcred = __task_cred(task->real_parent);
73625 + str1 = va_arg(ap, char *);
73626 + 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));
73627 + break;
73628 + case GR_SIG:
73629 + str1 = va_arg(ap, char *);
73630 + voidptr = va_arg(ap, void *);
73631 + gr_log_middle_varargs(audit, msg, str1, voidptr);
73632 + break;
73633 + case GR_SIG2:
73634 + task = va_arg(ap, struct task_struct *);
73635 + cred = __task_cred(task);
73636 + pcred = __task_cred(task->real_parent);
73637 + num1 = va_arg(ap, int);
73638 + 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));
73639 + break;
73640 + case GR_CRASH1:
73641 + task = va_arg(ap, struct task_struct *);
73642 + cred = __task_cred(task);
73643 + pcred = __task_cred(task->real_parent);
73644 + ulong1 = va_arg(ap, unsigned long);
73645 + 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);
73646 + break;
73647 + case GR_CRASH2:
73648 + task = va_arg(ap, struct task_struct *);
73649 + cred = __task_cred(task);
73650 + pcred = __task_cred(task->real_parent);
73651 + ulong1 = va_arg(ap, unsigned long);
73652 + 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);
73653 + break;
73654 + case GR_RWXMAP:
73655 + file = va_arg(ap, struct file *);
73656 + gr_log_middle_varargs(audit, msg, file ? gr_to_filename(file->f_path.dentry, file->f_path.mnt) : "<anonymous mapping>");
73657 + break;
73658 + case GR_RWXMAPVMA:
73659 + vma = va_arg(ap, struct vm_area_struct *);
73660 + if (vma->vm_file)
73661 + str1 = gr_to_filename(vma->vm_file->f_path.dentry, vma->vm_file->f_path.mnt);
73662 + else if (vma->vm_flags & (VM_GROWSDOWN | VM_GROWSUP))
73663 + str1 = "<stack>";
73664 + else if (vma->vm_start <= current->mm->brk &&
73665 + vma->vm_end >= current->mm->start_brk)
73666 + str1 = "<heap>";
73667 + else
73668 + str1 = "<anonymous mapping>";
73669 + gr_log_middle_varargs(audit, msg, str1);
73670 + break;
73671 + case GR_PSACCT:
73672 + {
73673 + unsigned int wday, cday;
73674 + __u8 whr, chr;
73675 + __u8 wmin, cmin;
73676 + __u8 wsec, csec;
73677 + char cur_tty[64] = { 0 };
73678 + char parent_tty[64] = { 0 };
73679 +
73680 + task = va_arg(ap, struct task_struct *);
73681 + wday = va_arg(ap, unsigned int);
73682 + cday = va_arg(ap, unsigned int);
73683 + whr = va_arg(ap, int);
73684 + chr = va_arg(ap, int);
73685 + wmin = va_arg(ap, int);
73686 + cmin = va_arg(ap, int);
73687 + wsec = va_arg(ap, int);
73688 + csec = va_arg(ap, int);
73689 + ulong1 = va_arg(ap, unsigned long);
73690 + cred = __task_cred(task);
73691 + pcred = __task_cred(task->real_parent);
73692 +
73693 + 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));
73694 + }
73695 + break;
73696 + default:
73697 + gr_log_middle(audit, msg, ap);
73698 + }
73699 + va_end(ap);
73700 + // these don't need DEFAULTSECARGS printed on the end
73701 + if (argtypes == GR_CRASH1 || argtypes == GR_CRASH2)
73702 + gr_log_end(audit, 0);
73703 + else
73704 + gr_log_end(audit, 1);
73705 + END_LOCKS(audit);
73706 +}
73707 diff --git a/grsecurity/grsec_mem.c b/grsecurity/grsec_mem.c
73708 new file mode 100644
73709 index 0000000..0e39d8c
73710 --- /dev/null
73711 +++ b/grsecurity/grsec_mem.c
73712 @@ -0,0 +1,48 @@
73713 +#include <linux/kernel.h>
73714 +#include <linux/sched.h>
73715 +#include <linux/mm.h>
73716 +#include <linux/mman.h>
73717 +#include <linux/module.h>
73718 +#include <linux/grinternal.h>
73719 +
73720 +void gr_handle_msr_write(void)
73721 +{
73722 + gr_log_noargs(GR_DONT_AUDIT, GR_MSRWRITE_MSG);
73723 + return;
73724 +}
73725 +EXPORT_SYMBOL_GPL(gr_handle_msr_write);
73726 +
73727 +void
73728 +gr_handle_ioperm(void)
73729 +{
73730 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPERM_MSG);
73731 + return;
73732 +}
73733 +
73734 +void
73735 +gr_handle_iopl(void)
73736 +{
73737 + gr_log_noargs(GR_DONT_AUDIT, GR_IOPL_MSG);
73738 + return;
73739 +}
73740 +
73741 +void
73742 +gr_handle_mem_readwrite(u64 from, u64 to)
73743 +{
73744 + gr_log_two_u64(GR_DONT_AUDIT, GR_MEM_READWRITE_MSG, from, to);
73745 + return;
73746 +}
73747 +
73748 +void
73749 +gr_handle_vm86(void)
73750 +{
73751 + gr_log_noargs(GR_DONT_AUDIT, GR_VM86_MSG);
73752 + return;
73753 +}
73754 +
73755 +void
73756 +gr_log_badprocpid(const char *entry)
73757 +{
73758 + gr_log_str(GR_DONT_AUDIT, GR_BADPROCPID_MSG, entry);
73759 + return;
73760 +}
73761 diff --git a/grsecurity/grsec_mount.c b/grsecurity/grsec_mount.c
73762 new file mode 100644
73763 index 0000000..cd9e124
73764 --- /dev/null
73765 +++ b/grsecurity/grsec_mount.c
73766 @@ -0,0 +1,65 @@
73767 +#include <linux/kernel.h>
73768 +#include <linux/sched.h>
73769 +#include <linux/mount.h>
73770 +#include <linux/major.h>
73771 +#include <linux/grsecurity.h>
73772 +#include <linux/grinternal.h>
73773 +
73774 +void
73775 +gr_log_remount(const char *devname, const int retval)
73776 +{
73777 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73778 + if (grsec_enable_mount && (retval >= 0))
73779 + gr_log_str(GR_DO_AUDIT, GR_REMOUNT_AUDIT_MSG, devname ? devname : "none");
73780 +#endif
73781 + return;
73782 +}
73783 +
73784 +void
73785 +gr_log_unmount(const char *devname, const int retval)
73786 +{
73787 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73788 + if (grsec_enable_mount && (retval >= 0))
73789 + gr_log_str(GR_DO_AUDIT, GR_UNMOUNT_AUDIT_MSG, devname ? devname : "none");
73790 +#endif
73791 + return;
73792 +}
73793 +
73794 +void
73795 +gr_log_mount(const char *from, const char *to, const int retval)
73796 +{
73797 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
73798 + if (grsec_enable_mount && (retval >= 0))
73799 + gr_log_str_str(GR_DO_AUDIT, GR_MOUNT_AUDIT_MSG, from ? from : "none", to);
73800 +#endif
73801 + return;
73802 +}
73803 +
73804 +int
73805 +gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags)
73806 +{
73807 +#ifdef CONFIG_GRKERNSEC_ROFS
73808 + if (grsec_enable_rofs && !(mnt_flags & MNT_READONLY)) {
73809 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_MOUNT_MSG, dentry, mnt);
73810 + return -EPERM;
73811 + } else
73812 + return 0;
73813 +#endif
73814 + return 0;
73815 +}
73816 +
73817 +int
73818 +gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode)
73819 +{
73820 +#ifdef CONFIG_GRKERNSEC_ROFS
73821 + struct inode *inode = dentry->d_inode;
73822 +
73823 + if (grsec_enable_rofs && (acc_mode & MAY_WRITE) &&
73824 + inode && (S_ISBLK(inode->i_mode) || (S_ISCHR(inode->i_mode) && imajor(inode) == RAW_MAJOR))) {
73825 + gr_log_fs_generic(GR_DO_AUDIT, GR_ROFS_BLOCKWRITE_MSG, dentry, mnt);
73826 + return -EPERM;
73827 + } else
73828 + return 0;
73829 +#endif
73830 + return 0;
73831 +}
73832 diff --git a/grsecurity/grsec_pax.c b/grsecurity/grsec_pax.c
73833 new file mode 100644
73834 index 0000000..6ee9d50
73835 --- /dev/null
73836 +++ b/grsecurity/grsec_pax.c
73837 @@ -0,0 +1,45 @@
73838 +#include <linux/kernel.h>
73839 +#include <linux/sched.h>
73840 +#include <linux/mm.h>
73841 +#include <linux/file.h>
73842 +#include <linux/grinternal.h>
73843 +#include <linux/grsecurity.h>
73844 +
73845 +void
73846 +gr_log_textrel(struct vm_area_struct * vma)
73847 +{
73848 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73849 + if (grsec_enable_log_rwxmaps)
73850 + gr_log_textrel_ulong_ulong(GR_DONT_AUDIT, GR_TEXTREL_AUDIT_MSG, vma->vm_file, vma->vm_start, vma->vm_pgoff);
73851 +#endif
73852 + return;
73853 +}
73854 +
73855 +void gr_log_ptgnustack(struct file *file)
73856 +{
73857 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73858 + if (grsec_enable_log_rwxmaps)
73859 + gr_log_rwxmap(GR_DONT_AUDIT, GR_PTGNUSTACK_MSG, file);
73860 +#endif
73861 + return;
73862 +}
73863 +
73864 +void
73865 +gr_log_rwxmmap(struct file *file)
73866 +{
73867 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73868 + if (grsec_enable_log_rwxmaps)
73869 + gr_log_rwxmap(GR_DONT_AUDIT, GR_RWXMMAP_MSG, file);
73870 +#endif
73871 + return;
73872 +}
73873 +
73874 +void
73875 +gr_log_rwxmprotect(struct vm_area_struct *vma)
73876 +{
73877 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
73878 + if (grsec_enable_log_rwxmaps)
73879 + gr_log_rwxmap_vma(GR_DONT_AUDIT, GR_RWXMPROTECT_MSG, vma);
73880 +#endif
73881 + return;
73882 +}
73883 diff --git a/grsecurity/grsec_ptrace.c b/grsecurity/grsec_ptrace.c
73884 new file mode 100644
73885 index 0000000..f7f29aa
73886 --- /dev/null
73887 +++ b/grsecurity/grsec_ptrace.c
73888 @@ -0,0 +1,30 @@
73889 +#include <linux/kernel.h>
73890 +#include <linux/sched.h>
73891 +#include <linux/grinternal.h>
73892 +#include <linux/security.h>
73893 +
73894 +void
73895 +gr_audit_ptrace(struct task_struct *task)
73896 +{
73897 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
73898 + if (grsec_enable_audit_ptrace)
73899 + gr_log_ptrace(GR_DO_AUDIT, GR_PTRACE_AUDIT_MSG, task);
73900 +#endif
73901 + return;
73902 +}
73903 +
73904 +int
73905 +gr_ptrace_readexec(struct file *file, int unsafe_flags)
73906 +{
73907 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
73908 + const struct dentry *dentry = file->f_path.dentry;
73909 + const struct vfsmount *mnt = file->f_path.mnt;
73910 +
73911 + if (grsec_enable_ptrace_readexec && (unsafe_flags & LSM_UNSAFE_PTRACE) &&
73912 + (inode_permission(dentry->d_inode, MAY_READ) || !gr_acl_handle_open(dentry, mnt, MAY_READ))) {
73913 + gr_log_fs_generic(GR_DONT_AUDIT, GR_PTRACE_READEXEC_MSG, dentry, mnt);
73914 + return -EACCES;
73915 + }
73916 +#endif
73917 + return 0;
73918 +}
73919 diff --git a/grsecurity/grsec_sig.c b/grsecurity/grsec_sig.c
73920 new file mode 100644
73921 index 0000000..3860c7e
73922 --- /dev/null
73923 +++ b/grsecurity/grsec_sig.c
73924 @@ -0,0 +1,236 @@
73925 +#include <linux/kernel.h>
73926 +#include <linux/sched.h>
73927 +#include <linux/fs.h>
73928 +#include <linux/delay.h>
73929 +#include <linux/grsecurity.h>
73930 +#include <linux/grinternal.h>
73931 +#include <linux/hardirq.h>
73932 +
73933 +char *signames[] = {
73934 + [SIGSEGV] = "Segmentation fault",
73935 + [SIGILL] = "Illegal instruction",
73936 + [SIGABRT] = "Abort",
73937 + [SIGBUS] = "Invalid alignment/Bus error"
73938 +};
73939 +
73940 +void
73941 +gr_log_signal(const int sig, const void *addr, const struct task_struct *t)
73942 +{
73943 +#ifdef CONFIG_GRKERNSEC_SIGNAL
73944 + if (grsec_enable_signal && ((sig == SIGSEGV) || (sig == SIGILL) ||
73945 + (sig == SIGABRT) || (sig == SIGBUS))) {
73946 + if (task_pid_nr(t) == task_pid_nr(current)) {
73947 + gr_log_sig_addr(GR_DONT_AUDIT_GOOD, GR_UNISIGLOG_MSG, signames[sig], addr);
73948 + } else {
73949 + gr_log_sig_task(GR_DONT_AUDIT_GOOD, GR_DUALSIGLOG_MSG, t, sig);
73950 + }
73951 + }
73952 +#endif
73953 + return;
73954 +}
73955 +
73956 +int
73957 +gr_handle_signal(const struct task_struct *p, const int sig)
73958 +{
73959 +#ifdef CONFIG_GRKERNSEC
73960 + /* ignore the 0 signal for protected task checks */
73961 + if (task_pid_nr(current) > 1 && sig && gr_check_protected_task(p)) {
73962 + gr_log_sig_task(GR_DONT_AUDIT, GR_SIG_ACL_MSG, p, sig);
73963 + return -EPERM;
73964 + } else if (gr_pid_is_chrooted((struct task_struct *)p)) {
73965 + return -EPERM;
73966 + }
73967 +#endif
73968 + return 0;
73969 +}
73970 +
73971 +#ifdef CONFIG_GRKERNSEC
73972 +extern int specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t);
73973 +
73974 +int gr_fake_force_sig(int sig, struct task_struct *t)
73975 +{
73976 + unsigned long int flags;
73977 + int ret, blocked, ignored;
73978 + struct k_sigaction *action;
73979 +
73980 + spin_lock_irqsave(&t->sighand->siglock, flags);
73981 + action = &t->sighand->action[sig-1];
73982 + ignored = action->sa.sa_handler == SIG_IGN;
73983 + blocked = sigismember(&t->blocked, sig);
73984 + if (blocked || ignored) {
73985 + action->sa.sa_handler = SIG_DFL;
73986 + if (blocked) {
73987 + sigdelset(&t->blocked, sig);
73988 + recalc_sigpending_and_wake(t);
73989 + }
73990 + }
73991 + if (action->sa.sa_handler == SIG_DFL)
73992 + t->signal->flags &= ~SIGNAL_UNKILLABLE;
73993 + ret = specific_send_sig_info(sig, SEND_SIG_PRIV, t);
73994 +
73995 + spin_unlock_irqrestore(&t->sighand->siglock, flags);
73996 +
73997 + return ret;
73998 +}
73999 +#endif
74000 +
74001 +#define GR_USER_BAN_TIME (15 * 60)
74002 +#define GR_DAEMON_BRUTE_TIME (30 * 60)
74003 +
74004 +void gr_handle_brute_attach(int dumpable)
74005 +{
74006 +#ifdef CONFIG_GRKERNSEC_BRUTE
74007 + struct task_struct *p = current;
74008 + kuid_t uid = GLOBAL_ROOT_UID;
74009 + int daemon = 0;
74010 +
74011 + if (!grsec_enable_brute)
74012 + return;
74013 +
74014 + rcu_read_lock();
74015 + read_lock(&tasklist_lock);
74016 + read_lock(&grsec_exec_file_lock);
74017 + if (p->real_parent && gr_is_same_file(p->real_parent->exec_file, p->exec_file)) {
74018 + p->real_parent->brute_expires = get_seconds() + GR_DAEMON_BRUTE_TIME;
74019 + p->real_parent->brute = 1;
74020 + daemon = 1;
74021 + } else {
74022 + const struct cred *cred = __task_cred(p), *cred2;
74023 + struct task_struct *tsk, *tsk2;
74024 +
74025 + if (dumpable != SUID_DUMP_USER && gr_is_global_nonroot(cred->uid)) {
74026 + struct user_struct *user;
74027 +
74028 + uid = cred->uid;
74029 +
74030 + /* this is put upon execution past expiration */
74031 + user = find_user(uid);
74032 + if (user == NULL)
74033 + goto unlock;
74034 + user->suid_banned = 1;
74035 + user->suid_ban_expires = get_seconds() + GR_USER_BAN_TIME;
74036 + if (user->suid_ban_expires == ~0UL)
74037 + user->suid_ban_expires--;
74038 +
74039 + /* only kill other threads of the same binary, from the same user */
74040 + do_each_thread(tsk2, tsk) {
74041 + cred2 = __task_cred(tsk);
74042 + if (tsk != p && uid_eq(cred2->uid, uid) && gr_is_same_file(tsk->exec_file, p->exec_file))
74043 + gr_fake_force_sig(SIGKILL, tsk);
74044 + } while_each_thread(tsk2, tsk);
74045 + }
74046 + }
74047 +unlock:
74048 + read_unlock(&grsec_exec_file_lock);
74049 + read_unlock(&tasklist_lock);
74050 + rcu_read_unlock();
74051 +
74052 + if (gr_is_global_nonroot(uid))
74053 + 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);
74054 + else if (daemon)
74055 + gr_log_noargs(GR_DONT_AUDIT, GR_BRUTE_DAEMON_MSG);
74056 +
74057 +#endif
74058 + return;
74059 +}
74060 +
74061 +void gr_handle_brute_check(void)
74062 +{
74063 +#ifdef CONFIG_GRKERNSEC_BRUTE
74064 + struct task_struct *p = current;
74065 +
74066 + if (unlikely(p->brute)) {
74067 + if (!grsec_enable_brute)
74068 + p->brute = 0;
74069 + else if (time_before(get_seconds(), p->brute_expires))
74070 + msleep(30 * 1000);
74071 + }
74072 +#endif
74073 + return;
74074 +}
74075 +
74076 +void gr_handle_kernel_exploit(void)
74077 +{
74078 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74079 + const struct cred *cred;
74080 + struct task_struct *tsk, *tsk2;
74081 + struct user_struct *user;
74082 + kuid_t uid;
74083 +
74084 + if (in_irq() || in_serving_softirq() || in_nmi())
74085 + panic("grsec: halting the system due to suspicious kernel crash caused in interrupt context");
74086 +
74087 + uid = current_uid();
74088 +
74089 + if (gr_is_global_root(uid))
74090 + panic("grsec: halting the system due to suspicious kernel crash caused by root");
74091 + else {
74092 + /* kill all the processes of this user, hold a reference
74093 + to their creds struct, and prevent them from creating
74094 + another process until system reset
74095 + */
74096 + printk(KERN_ALERT "grsec: banning user with uid %u until system restart for suspicious kernel crash\n",
74097 + GR_GLOBAL_UID(uid));
74098 + /* we intentionally leak this ref */
74099 + user = get_uid(current->cred->user);
74100 + if (user)
74101 + user->kernel_banned = 1;
74102 +
74103 + /* kill all processes of this user */
74104 + read_lock(&tasklist_lock);
74105 + do_each_thread(tsk2, tsk) {
74106 + cred = __task_cred(tsk);
74107 + if (uid_eq(cred->uid, uid))
74108 + gr_fake_force_sig(SIGKILL, tsk);
74109 + } while_each_thread(tsk2, tsk);
74110 + read_unlock(&tasklist_lock);
74111 + }
74112 +#endif
74113 +}
74114 +
74115 +#ifdef CONFIG_GRKERNSEC_BRUTE
74116 +static bool suid_ban_expired(struct user_struct *user)
74117 +{
74118 + if (user->suid_ban_expires != ~0UL && time_after_eq(get_seconds(), user->suid_ban_expires)) {
74119 + user->suid_banned = 0;
74120 + user->suid_ban_expires = 0;
74121 + free_uid(user);
74122 + return true;
74123 + }
74124 +
74125 + return false;
74126 +}
74127 +#endif
74128 +
74129 +int gr_process_kernel_exec_ban(void)
74130 +{
74131 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74132 + if (unlikely(current->cred->user->kernel_banned))
74133 + return -EPERM;
74134 +#endif
74135 + return 0;
74136 +}
74137 +
74138 +int gr_process_kernel_setuid_ban(struct user_struct *user)
74139 +{
74140 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
74141 + if (unlikely(user->kernel_banned))
74142 + gr_fake_force_sig(SIGKILL, current);
74143 +#endif
74144 + return 0;
74145 +}
74146 +
74147 +int gr_process_suid_exec_ban(const struct linux_binprm *bprm)
74148 +{
74149 +#ifdef CONFIG_GRKERNSEC_BRUTE
74150 + struct user_struct *user = current->cred->user;
74151 + if (unlikely(user->suid_banned)) {
74152 + if (suid_ban_expired(user))
74153 + return 0;
74154 + /* disallow execution of suid binaries only */
74155 + else if (!uid_eq(bprm->cred->euid, current->cred->uid))
74156 + return -EPERM;
74157 + }
74158 +#endif
74159 + return 0;
74160 +}
74161 diff --git a/grsecurity/grsec_sock.c b/grsecurity/grsec_sock.c
74162 new file mode 100644
74163 index 0000000..c0aef3a
74164 --- /dev/null
74165 +++ b/grsecurity/grsec_sock.c
74166 @@ -0,0 +1,244 @@
74167 +#include <linux/kernel.h>
74168 +#include <linux/module.h>
74169 +#include <linux/sched.h>
74170 +#include <linux/file.h>
74171 +#include <linux/net.h>
74172 +#include <linux/in.h>
74173 +#include <linux/ip.h>
74174 +#include <net/sock.h>
74175 +#include <net/inet_sock.h>
74176 +#include <linux/grsecurity.h>
74177 +#include <linux/grinternal.h>
74178 +#include <linux/gracl.h>
74179 +
74180 +extern int gr_search_udp_recvmsg(const struct sock *sk, const struct sk_buff *skb);
74181 +extern int gr_search_udp_sendmsg(const struct sock *sk, const struct sockaddr_in *addr);
74182 +
74183 +EXPORT_SYMBOL_GPL(gr_search_udp_recvmsg);
74184 +EXPORT_SYMBOL_GPL(gr_search_udp_sendmsg);
74185 +
74186 +#ifdef CONFIG_UNIX_MODULE
74187 +EXPORT_SYMBOL_GPL(gr_acl_handle_unix);
74188 +EXPORT_SYMBOL_GPL(gr_acl_handle_mknod);
74189 +EXPORT_SYMBOL_GPL(gr_handle_chroot_unix);
74190 +EXPORT_SYMBOL_GPL(gr_handle_create);
74191 +#endif
74192 +
74193 +#ifdef CONFIG_GRKERNSEC
74194 +#define gr_conn_table_size 32749
74195 +struct conn_table_entry {
74196 + struct conn_table_entry *next;
74197 + struct signal_struct *sig;
74198 +};
74199 +
74200 +struct conn_table_entry *gr_conn_table[gr_conn_table_size];
74201 +DEFINE_SPINLOCK(gr_conn_table_lock);
74202 +
74203 +extern const char * gr_socktype_to_name(unsigned char type);
74204 +extern const char * gr_proto_to_name(unsigned char proto);
74205 +extern const char * gr_sockfamily_to_name(unsigned char family);
74206 +
74207 +static __inline__ int
74208 +conn_hash(__u32 saddr, __u32 daddr, __u16 sport, __u16 dport, unsigned int size)
74209 +{
74210 + return ((daddr + saddr + (sport << 8) + (dport << 16)) % size);
74211 +}
74212 +
74213 +static __inline__ int
74214 +conn_match(const struct signal_struct *sig, __u32 saddr, __u32 daddr,
74215 + __u16 sport, __u16 dport)
74216 +{
74217 + if (unlikely(sig->gr_saddr == saddr && sig->gr_daddr == daddr &&
74218 + sig->gr_sport == sport && sig->gr_dport == dport))
74219 + return 1;
74220 + else
74221 + return 0;
74222 +}
74223 +
74224 +static void gr_add_to_task_ip_table_nolock(struct signal_struct *sig, struct conn_table_entry *newent)
74225 +{
74226 + struct conn_table_entry **match;
74227 + unsigned int index;
74228 +
74229 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
74230 + sig->gr_sport, sig->gr_dport,
74231 + gr_conn_table_size);
74232 +
74233 + newent->sig = sig;
74234 +
74235 + match = &gr_conn_table[index];
74236 + newent->next = *match;
74237 + *match = newent;
74238 +
74239 + return;
74240 +}
74241 +
74242 +static void gr_del_task_from_ip_table_nolock(struct signal_struct *sig)
74243 +{
74244 + struct conn_table_entry *match, *last = NULL;
74245 + unsigned int index;
74246 +
74247 + index = conn_hash(sig->gr_saddr, sig->gr_daddr,
74248 + sig->gr_sport, sig->gr_dport,
74249 + gr_conn_table_size);
74250 +
74251 + match = gr_conn_table[index];
74252 + while (match && !conn_match(match->sig,
74253 + sig->gr_saddr, sig->gr_daddr, sig->gr_sport,
74254 + sig->gr_dport)) {
74255 + last = match;
74256 + match = match->next;
74257 + }
74258 +
74259 + if (match) {
74260 + if (last)
74261 + last->next = match->next;
74262 + else
74263 + gr_conn_table[index] = NULL;
74264 + kfree(match);
74265 + }
74266 +
74267 + return;
74268 +}
74269 +
74270 +static struct signal_struct * gr_lookup_task_ip_table(__u32 saddr, __u32 daddr,
74271 + __u16 sport, __u16 dport)
74272 +{
74273 + struct conn_table_entry *match;
74274 + unsigned int index;
74275 +
74276 + index = conn_hash(saddr, daddr, sport, dport, gr_conn_table_size);
74277 +
74278 + match = gr_conn_table[index];
74279 + while (match && !conn_match(match->sig, saddr, daddr, sport, dport))
74280 + match = match->next;
74281 +
74282 + if (match)
74283 + return match->sig;
74284 + else
74285 + return NULL;
74286 +}
74287 +
74288 +#endif
74289 +
74290 +void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet)
74291 +{
74292 +#ifdef CONFIG_GRKERNSEC
74293 + struct signal_struct *sig = task->signal;
74294 + struct conn_table_entry *newent;
74295 +
74296 + newent = kmalloc(sizeof(struct conn_table_entry), GFP_ATOMIC);
74297 + if (newent == NULL)
74298 + return;
74299 + /* no bh lock needed since we are called with bh disabled */
74300 + spin_lock(&gr_conn_table_lock);
74301 + gr_del_task_from_ip_table_nolock(sig);
74302 + sig->gr_saddr = inet->inet_rcv_saddr;
74303 + sig->gr_daddr = inet->inet_daddr;
74304 + sig->gr_sport = inet->inet_sport;
74305 + sig->gr_dport = inet->inet_dport;
74306 + gr_add_to_task_ip_table_nolock(sig, newent);
74307 + spin_unlock(&gr_conn_table_lock);
74308 +#endif
74309 + return;
74310 +}
74311 +
74312 +void gr_del_task_from_ip_table(struct task_struct *task)
74313 +{
74314 +#ifdef CONFIG_GRKERNSEC
74315 + spin_lock_bh(&gr_conn_table_lock);
74316 + gr_del_task_from_ip_table_nolock(task->signal);
74317 + spin_unlock_bh(&gr_conn_table_lock);
74318 +#endif
74319 + return;
74320 +}
74321 +
74322 +void
74323 +gr_attach_curr_ip(const struct sock *sk)
74324 +{
74325 +#ifdef CONFIG_GRKERNSEC
74326 + struct signal_struct *p, *set;
74327 + const struct inet_sock *inet = inet_sk(sk);
74328 +
74329 + if (unlikely(sk->sk_protocol != IPPROTO_TCP))
74330 + return;
74331 +
74332 + set = current->signal;
74333 +
74334 + spin_lock_bh(&gr_conn_table_lock);
74335 + p = gr_lookup_task_ip_table(inet->inet_daddr, inet->inet_rcv_saddr,
74336 + inet->inet_dport, inet->inet_sport);
74337 + if (unlikely(p != NULL)) {
74338 + set->curr_ip = p->curr_ip;
74339 + set->used_accept = 1;
74340 + gr_del_task_from_ip_table_nolock(p);
74341 + spin_unlock_bh(&gr_conn_table_lock);
74342 + return;
74343 + }
74344 + spin_unlock_bh(&gr_conn_table_lock);
74345 +
74346 + set->curr_ip = inet->inet_daddr;
74347 + set->used_accept = 1;
74348 +#endif
74349 + return;
74350 +}
74351 +
74352 +int
74353 +gr_handle_sock_all(const int family, const int type, const int protocol)
74354 +{
74355 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74356 + if (grsec_enable_socket_all && in_group_p(grsec_socket_all_gid) &&
74357 + (family != AF_UNIX)) {
74358 + if (family == AF_INET)
74359 + gr_log_str3(GR_DONT_AUDIT, GR_SOCK_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), gr_proto_to_name(protocol));
74360 + else
74361 + gr_log_str2_int(GR_DONT_AUDIT, GR_SOCK_NOINET_MSG, gr_sockfamily_to_name(family), gr_socktype_to_name(type), protocol);
74362 + return -EACCES;
74363 + }
74364 +#endif
74365 + return 0;
74366 +}
74367 +
74368 +int
74369 +gr_handle_sock_server(const struct sockaddr *sck)
74370 +{
74371 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74372 + if (grsec_enable_socket_server &&
74373 + in_group_p(grsec_socket_server_gid) &&
74374 + sck && (sck->sa_family != AF_UNIX) &&
74375 + (sck->sa_family != AF_LOCAL)) {
74376 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
74377 + return -EACCES;
74378 + }
74379 +#endif
74380 + return 0;
74381 +}
74382 +
74383 +int
74384 +gr_handle_sock_server_other(const struct sock *sck)
74385 +{
74386 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74387 + if (grsec_enable_socket_server &&
74388 + in_group_p(grsec_socket_server_gid) &&
74389 + sck && (sck->sk_family != AF_UNIX) &&
74390 + (sck->sk_family != AF_LOCAL)) {
74391 + gr_log_noargs(GR_DONT_AUDIT, GR_BIND_MSG);
74392 + return -EACCES;
74393 + }
74394 +#endif
74395 + return 0;
74396 +}
74397 +
74398 +int
74399 +gr_handle_sock_client(const struct sockaddr *sck)
74400 +{
74401 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74402 + if (grsec_enable_socket_client && in_group_p(grsec_socket_client_gid) &&
74403 + sck && (sck->sa_family != AF_UNIX) &&
74404 + (sck->sa_family != AF_LOCAL)) {
74405 + gr_log_noargs(GR_DONT_AUDIT, GR_CONNECT_MSG);
74406 + return -EACCES;
74407 + }
74408 +#endif
74409 + return 0;
74410 +}
74411 diff --git a/grsecurity/grsec_sysctl.c b/grsecurity/grsec_sysctl.c
74412 new file mode 100644
74413 index 0000000..8159888
74414 --- /dev/null
74415 +++ b/grsecurity/grsec_sysctl.c
74416 @@ -0,0 +1,479 @@
74417 +#include <linux/kernel.h>
74418 +#include <linux/sched.h>
74419 +#include <linux/sysctl.h>
74420 +#include <linux/grsecurity.h>
74421 +#include <linux/grinternal.h>
74422 +
74423 +int
74424 +gr_handle_sysctl_mod(const char *dirname, const char *name, const int op)
74425 +{
74426 +#ifdef CONFIG_GRKERNSEC_SYSCTL
74427 + if (dirname == NULL || name == NULL)
74428 + return 0;
74429 + if (!strcmp(dirname, "grsecurity") && grsec_lock && (op & MAY_WRITE)) {
74430 + gr_log_str(GR_DONT_AUDIT, GR_SYSCTL_MSG, name);
74431 + return -EACCES;
74432 + }
74433 +#endif
74434 + return 0;
74435 +}
74436 +
74437 +#if defined(CONFIG_GRKERNSEC_ROFS) || defined(CONFIG_GRKERNSEC_DENYUSB)
74438 +static int __maybe_unused __read_only one = 1;
74439 +#endif
74440 +
74441 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS) || \
74442 + defined(CONFIG_GRKERNSEC_DENYUSB)
74443 +struct ctl_table grsecurity_table[] = {
74444 +#ifdef CONFIG_GRKERNSEC_SYSCTL
74445 +#ifdef CONFIG_GRKERNSEC_SYSCTL_DISTRO
74446 +#ifdef CONFIG_GRKERNSEC_IO
74447 + {
74448 + .procname = "disable_priv_io",
74449 + .data = &grsec_disable_privio,
74450 + .maxlen = sizeof(int),
74451 + .mode = 0600,
74452 + .proc_handler = &proc_dointvec,
74453 + },
74454 +#endif
74455 +#endif
74456 +#ifdef CONFIG_GRKERNSEC_LINK
74457 + {
74458 + .procname = "linking_restrictions",
74459 + .data = &grsec_enable_link,
74460 + .maxlen = sizeof(int),
74461 + .mode = 0600,
74462 + .proc_handler = &proc_dointvec,
74463 + },
74464 +#endif
74465 +#ifdef CONFIG_GRKERNSEC_SYMLINKOWN
74466 + {
74467 + .procname = "enforce_symlinksifowner",
74468 + .data = &grsec_enable_symlinkown,
74469 + .maxlen = sizeof(int),
74470 + .mode = 0600,
74471 + .proc_handler = &proc_dointvec,
74472 + },
74473 + {
74474 + .procname = "symlinkown_gid",
74475 + .data = &grsec_symlinkown_gid,
74476 + .maxlen = sizeof(int),
74477 + .mode = 0600,
74478 + .proc_handler = &proc_dointvec,
74479 + },
74480 +#endif
74481 +#ifdef CONFIG_GRKERNSEC_BRUTE
74482 + {
74483 + .procname = "deter_bruteforce",
74484 + .data = &grsec_enable_brute,
74485 + .maxlen = sizeof(int),
74486 + .mode = 0600,
74487 + .proc_handler = &proc_dointvec,
74488 + },
74489 +#endif
74490 +#ifdef CONFIG_GRKERNSEC_FIFO
74491 + {
74492 + .procname = "fifo_restrictions",
74493 + .data = &grsec_enable_fifo,
74494 + .maxlen = sizeof(int),
74495 + .mode = 0600,
74496 + .proc_handler = &proc_dointvec,
74497 + },
74498 +#endif
74499 +#ifdef CONFIG_GRKERNSEC_PTRACE_READEXEC
74500 + {
74501 + .procname = "ptrace_readexec",
74502 + .data = &grsec_enable_ptrace_readexec,
74503 + .maxlen = sizeof(int),
74504 + .mode = 0600,
74505 + .proc_handler = &proc_dointvec,
74506 + },
74507 +#endif
74508 +#ifdef CONFIG_GRKERNSEC_SETXID
74509 + {
74510 + .procname = "consistent_setxid",
74511 + .data = &grsec_enable_setxid,
74512 + .maxlen = sizeof(int),
74513 + .mode = 0600,
74514 + .proc_handler = &proc_dointvec,
74515 + },
74516 +#endif
74517 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
74518 + {
74519 + .procname = "ip_blackhole",
74520 + .data = &grsec_enable_blackhole,
74521 + .maxlen = sizeof(int),
74522 + .mode = 0600,
74523 + .proc_handler = &proc_dointvec,
74524 + },
74525 + {
74526 + .procname = "lastack_retries",
74527 + .data = &grsec_lastack_retries,
74528 + .maxlen = sizeof(int),
74529 + .mode = 0600,
74530 + .proc_handler = &proc_dointvec,
74531 + },
74532 +#endif
74533 +#ifdef CONFIG_GRKERNSEC_EXECLOG
74534 + {
74535 + .procname = "exec_logging",
74536 + .data = &grsec_enable_execlog,
74537 + .maxlen = sizeof(int),
74538 + .mode = 0600,
74539 + .proc_handler = &proc_dointvec,
74540 + },
74541 +#endif
74542 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
74543 + {
74544 + .procname = "rwxmap_logging",
74545 + .data = &grsec_enable_log_rwxmaps,
74546 + .maxlen = sizeof(int),
74547 + .mode = 0600,
74548 + .proc_handler = &proc_dointvec,
74549 + },
74550 +#endif
74551 +#ifdef CONFIG_GRKERNSEC_SIGNAL
74552 + {
74553 + .procname = "signal_logging",
74554 + .data = &grsec_enable_signal,
74555 + .maxlen = sizeof(int),
74556 + .mode = 0600,
74557 + .proc_handler = &proc_dointvec,
74558 + },
74559 +#endif
74560 +#ifdef CONFIG_GRKERNSEC_FORKFAIL
74561 + {
74562 + .procname = "forkfail_logging",
74563 + .data = &grsec_enable_forkfail,
74564 + .maxlen = sizeof(int),
74565 + .mode = 0600,
74566 + .proc_handler = &proc_dointvec,
74567 + },
74568 +#endif
74569 +#ifdef CONFIG_GRKERNSEC_TIME
74570 + {
74571 + .procname = "timechange_logging",
74572 + .data = &grsec_enable_time,
74573 + .maxlen = sizeof(int),
74574 + .mode = 0600,
74575 + .proc_handler = &proc_dointvec,
74576 + },
74577 +#endif
74578 +#ifdef CONFIG_GRKERNSEC_CHROOT_SHMAT
74579 + {
74580 + .procname = "chroot_deny_shmat",
74581 + .data = &grsec_enable_chroot_shmat,
74582 + .maxlen = sizeof(int),
74583 + .mode = 0600,
74584 + .proc_handler = &proc_dointvec,
74585 + },
74586 +#endif
74587 +#ifdef CONFIG_GRKERNSEC_CHROOT_UNIX
74588 + {
74589 + .procname = "chroot_deny_unix",
74590 + .data = &grsec_enable_chroot_unix,
74591 + .maxlen = sizeof(int),
74592 + .mode = 0600,
74593 + .proc_handler = &proc_dointvec,
74594 + },
74595 +#endif
74596 +#ifdef CONFIG_GRKERNSEC_CHROOT_MOUNT
74597 + {
74598 + .procname = "chroot_deny_mount",
74599 + .data = &grsec_enable_chroot_mount,
74600 + .maxlen = sizeof(int),
74601 + .mode = 0600,
74602 + .proc_handler = &proc_dointvec,
74603 + },
74604 +#endif
74605 +#ifdef CONFIG_GRKERNSEC_CHROOT_FCHDIR
74606 + {
74607 + .procname = "chroot_deny_fchdir",
74608 + .data = &grsec_enable_chroot_fchdir,
74609 + .maxlen = sizeof(int),
74610 + .mode = 0600,
74611 + .proc_handler = &proc_dointvec,
74612 + },
74613 +#endif
74614 +#ifdef CONFIG_GRKERNSEC_CHROOT_DOUBLE
74615 + {
74616 + .procname = "chroot_deny_chroot",
74617 + .data = &grsec_enable_chroot_double,
74618 + .maxlen = sizeof(int),
74619 + .mode = 0600,
74620 + .proc_handler = &proc_dointvec,
74621 + },
74622 +#endif
74623 +#ifdef CONFIG_GRKERNSEC_CHROOT_PIVOT
74624 + {
74625 + .procname = "chroot_deny_pivot",
74626 + .data = &grsec_enable_chroot_pivot,
74627 + .maxlen = sizeof(int),
74628 + .mode = 0600,
74629 + .proc_handler = &proc_dointvec,
74630 + },
74631 +#endif
74632 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHDIR
74633 + {
74634 + .procname = "chroot_enforce_chdir",
74635 + .data = &grsec_enable_chroot_chdir,
74636 + .maxlen = sizeof(int),
74637 + .mode = 0600,
74638 + .proc_handler = &proc_dointvec,
74639 + },
74640 +#endif
74641 +#ifdef CONFIG_GRKERNSEC_CHROOT_CHMOD
74642 + {
74643 + .procname = "chroot_deny_chmod",
74644 + .data = &grsec_enable_chroot_chmod,
74645 + .maxlen = sizeof(int),
74646 + .mode = 0600,
74647 + .proc_handler = &proc_dointvec,
74648 + },
74649 +#endif
74650 +#ifdef CONFIG_GRKERNSEC_CHROOT_MKNOD
74651 + {
74652 + .procname = "chroot_deny_mknod",
74653 + .data = &grsec_enable_chroot_mknod,
74654 + .maxlen = sizeof(int),
74655 + .mode = 0600,
74656 + .proc_handler = &proc_dointvec,
74657 + },
74658 +#endif
74659 +#ifdef CONFIG_GRKERNSEC_CHROOT_NICE
74660 + {
74661 + .procname = "chroot_restrict_nice",
74662 + .data = &grsec_enable_chroot_nice,
74663 + .maxlen = sizeof(int),
74664 + .mode = 0600,
74665 + .proc_handler = &proc_dointvec,
74666 + },
74667 +#endif
74668 +#ifdef CONFIG_GRKERNSEC_CHROOT_EXECLOG
74669 + {
74670 + .procname = "chroot_execlog",
74671 + .data = &grsec_enable_chroot_execlog,
74672 + .maxlen = sizeof(int),
74673 + .mode = 0600,
74674 + .proc_handler = &proc_dointvec,
74675 + },
74676 +#endif
74677 +#ifdef CONFIG_GRKERNSEC_CHROOT_CAPS
74678 + {
74679 + .procname = "chroot_caps",
74680 + .data = &grsec_enable_chroot_caps,
74681 + .maxlen = sizeof(int),
74682 + .mode = 0600,
74683 + .proc_handler = &proc_dointvec,
74684 + },
74685 +#endif
74686 +#ifdef CONFIG_GRKERNSEC_CHROOT_SYSCTL
74687 + {
74688 + .procname = "chroot_deny_sysctl",
74689 + .data = &grsec_enable_chroot_sysctl,
74690 + .maxlen = sizeof(int),
74691 + .mode = 0600,
74692 + .proc_handler = &proc_dointvec,
74693 + },
74694 +#endif
74695 +#ifdef CONFIG_GRKERNSEC_TPE
74696 + {
74697 + .procname = "tpe",
74698 + .data = &grsec_enable_tpe,
74699 + .maxlen = sizeof(int),
74700 + .mode = 0600,
74701 + .proc_handler = &proc_dointvec,
74702 + },
74703 + {
74704 + .procname = "tpe_gid",
74705 + .data = &grsec_tpe_gid,
74706 + .maxlen = sizeof(int),
74707 + .mode = 0600,
74708 + .proc_handler = &proc_dointvec,
74709 + },
74710 +#endif
74711 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74712 + {
74713 + .procname = "tpe_invert",
74714 + .data = &grsec_enable_tpe_invert,
74715 + .maxlen = sizeof(int),
74716 + .mode = 0600,
74717 + .proc_handler = &proc_dointvec,
74718 + },
74719 +#endif
74720 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
74721 + {
74722 + .procname = "tpe_restrict_all",
74723 + .data = &grsec_enable_tpe_all,
74724 + .maxlen = sizeof(int),
74725 + .mode = 0600,
74726 + .proc_handler = &proc_dointvec,
74727 + },
74728 +#endif
74729 +#ifdef CONFIG_GRKERNSEC_SOCKET_ALL
74730 + {
74731 + .procname = "socket_all",
74732 + .data = &grsec_enable_socket_all,
74733 + .maxlen = sizeof(int),
74734 + .mode = 0600,
74735 + .proc_handler = &proc_dointvec,
74736 + },
74737 + {
74738 + .procname = "socket_all_gid",
74739 + .data = &grsec_socket_all_gid,
74740 + .maxlen = sizeof(int),
74741 + .mode = 0600,
74742 + .proc_handler = &proc_dointvec,
74743 + },
74744 +#endif
74745 +#ifdef CONFIG_GRKERNSEC_SOCKET_CLIENT
74746 + {
74747 + .procname = "socket_client",
74748 + .data = &grsec_enable_socket_client,
74749 + .maxlen = sizeof(int),
74750 + .mode = 0600,
74751 + .proc_handler = &proc_dointvec,
74752 + },
74753 + {
74754 + .procname = "socket_client_gid",
74755 + .data = &grsec_socket_client_gid,
74756 + .maxlen = sizeof(int),
74757 + .mode = 0600,
74758 + .proc_handler = &proc_dointvec,
74759 + },
74760 +#endif
74761 +#ifdef CONFIG_GRKERNSEC_SOCKET_SERVER
74762 + {
74763 + .procname = "socket_server",
74764 + .data = &grsec_enable_socket_server,
74765 + .maxlen = sizeof(int),
74766 + .mode = 0600,
74767 + .proc_handler = &proc_dointvec,
74768 + },
74769 + {
74770 + .procname = "socket_server_gid",
74771 + .data = &grsec_socket_server_gid,
74772 + .maxlen = sizeof(int),
74773 + .mode = 0600,
74774 + .proc_handler = &proc_dointvec,
74775 + },
74776 +#endif
74777 +#ifdef CONFIG_GRKERNSEC_AUDIT_GROUP
74778 + {
74779 + .procname = "audit_group",
74780 + .data = &grsec_enable_group,
74781 + .maxlen = sizeof(int),
74782 + .mode = 0600,
74783 + .proc_handler = &proc_dointvec,
74784 + },
74785 + {
74786 + .procname = "audit_gid",
74787 + .data = &grsec_audit_gid,
74788 + .maxlen = sizeof(int),
74789 + .mode = 0600,
74790 + .proc_handler = &proc_dointvec,
74791 + },
74792 +#endif
74793 +#ifdef CONFIG_GRKERNSEC_AUDIT_CHDIR
74794 + {
74795 + .procname = "audit_chdir",
74796 + .data = &grsec_enable_chdir,
74797 + .maxlen = sizeof(int),
74798 + .mode = 0600,
74799 + .proc_handler = &proc_dointvec,
74800 + },
74801 +#endif
74802 +#ifdef CONFIG_GRKERNSEC_AUDIT_MOUNT
74803 + {
74804 + .procname = "audit_mount",
74805 + .data = &grsec_enable_mount,
74806 + .maxlen = sizeof(int),
74807 + .mode = 0600,
74808 + .proc_handler = &proc_dointvec,
74809 + },
74810 +#endif
74811 +#ifdef CONFIG_GRKERNSEC_DMESG
74812 + {
74813 + .procname = "dmesg",
74814 + .data = &grsec_enable_dmesg,
74815 + .maxlen = sizeof(int),
74816 + .mode = 0600,
74817 + .proc_handler = &proc_dointvec,
74818 + },
74819 +#endif
74820 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
74821 + {
74822 + .procname = "chroot_findtask",
74823 + .data = &grsec_enable_chroot_findtask,
74824 + .maxlen = sizeof(int),
74825 + .mode = 0600,
74826 + .proc_handler = &proc_dointvec,
74827 + },
74828 +#endif
74829 +#ifdef CONFIG_GRKERNSEC_RESLOG
74830 + {
74831 + .procname = "resource_logging",
74832 + .data = &grsec_resource_logging,
74833 + .maxlen = sizeof(int),
74834 + .mode = 0600,
74835 + .proc_handler = &proc_dointvec,
74836 + },
74837 +#endif
74838 +#ifdef CONFIG_GRKERNSEC_AUDIT_PTRACE
74839 + {
74840 + .procname = "audit_ptrace",
74841 + .data = &grsec_enable_audit_ptrace,
74842 + .maxlen = sizeof(int),
74843 + .mode = 0600,
74844 + .proc_handler = &proc_dointvec,
74845 + },
74846 +#endif
74847 +#ifdef CONFIG_GRKERNSEC_HARDEN_PTRACE
74848 + {
74849 + .procname = "harden_ptrace",
74850 + .data = &grsec_enable_harden_ptrace,
74851 + .maxlen = sizeof(int),
74852 + .mode = 0600,
74853 + .proc_handler = &proc_dointvec,
74854 + },
74855 +#endif
74856 +#ifdef CONFIG_GRKERNSEC_HARDEN_IPC
74857 + {
74858 + .procname = "harden_ipc",
74859 + .data = &grsec_enable_harden_ipc,
74860 + .maxlen = sizeof(int),
74861 + .mode = 0600,
74862 + .proc_handler = &proc_dointvec,
74863 + },
74864 +#endif
74865 + {
74866 + .procname = "grsec_lock",
74867 + .data = &grsec_lock,
74868 + .maxlen = sizeof(int),
74869 + .mode = 0600,
74870 + .proc_handler = &proc_dointvec,
74871 + },
74872 +#endif
74873 +#ifdef CONFIG_GRKERNSEC_ROFS
74874 + {
74875 + .procname = "romount_protect",
74876 + .data = &grsec_enable_rofs,
74877 + .maxlen = sizeof(int),
74878 + .mode = 0600,
74879 + .proc_handler = &proc_dointvec_minmax,
74880 + .extra1 = &one,
74881 + .extra2 = &one,
74882 + },
74883 +#endif
74884 +#if defined(CONFIG_GRKERNSEC_DENYUSB) && !defined(CONFIG_GRKERNSEC_DENYUSB_FORCE)
74885 + {
74886 + .procname = "deny_new_usb",
74887 + .data = &grsec_deny_new_usb,
74888 + .maxlen = sizeof(int),
74889 + .mode = 0600,
74890 + .proc_handler = &proc_dointvec,
74891 + },
74892 +#endif
74893 + { }
74894 +};
74895 +#endif
74896 diff --git a/grsecurity/grsec_time.c b/grsecurity/grsec_time.c
74897 new file mode 100644
74898 index 0000000..61b514e
74899 --- /dev/null
74900 +++ b/grsecurity/grsec_time.c
74901 @@ -0,0 +1,16 @@
74902 +#include <linux/kernel.h>
74903 +#include <linux/sched.h>
74904 +#include <linux/grinternal.h>
74905 +#include <linux/module.h>
74906 +
74907 +void
74908 +gr_log_timechange(void)
74909 +{
74910 +#ifdef CONFIG_GRKERNSEC_TIME
74911 + if (grsec_enable_time)
74912 + gr_log_noargs(GR_DONT_AUDIT_GOOD, GR_TIME_MSG);
74913 +#endif
74914 + return;
74915 +}
74916 +
74917 +EXPORT_SYMBOL_GPL(gr_log_timechange);
74918 diff --git a/grsecurity/grsec_tpe.c b/grsecurity/grsec_tpe.c
74919 new file mode 100644
74920 index 0000000..ee57dcf
74921 --- /dev/null
74922 +++ b/grsecurity/grsec_tpe.c
74923 @@ -0,0 +1,73 @@
74924 +#include <linux/kernel.h>
74925 +#include <linux/sched.h>
74926 +#include <linux/file.h>
74927 +#include <linux/fs.h>
74928 +#include <linux/grinternal.h>
74929 +
74930 +extern int gr_acl_tpe_check(void);
74931 +
74932 +int
74933 +gr_tpe_allow(const struct file *file)
74934 +{
74935 +#ifdef CONFIG_GRKERNSEC
74936 + struct inode *inode = file->f_path.dentry->d_parent->d_inode;
74937 + const struct cred *cred = current_cred();
74938 + char *msg = NULL;
74939 + char *msg2 = NULL;
74940 +
74941 + // never restrict root
74942 + if (gr_is_global_root(cred->uid))
74943 + return 1;
74944 +
74945 + if (grsec_enable_tpe) {
74946 +#ifdef CONFIG_GRKERNSEC_TPE_INVERT
74947 + if (grsec_enable_tpe_invert && !in_group_p(grsec_tpe_gid))
74948 + msg = "not being in trusted group";
74949 + else if (!grsec_enable_tpe_invert && in_group_p(grsec_tpe_gid))
74950 + msg = "being in untrusted group";
74951 +#else
74952 + if (in_group_p(grsec_tpe_gid))
74953 + msg = "being in untrusted group";
74954 +#endif
74955 + }
74956 + if (!msg && gr_acl_tpe_check())
74957 + msg = "being in untrusted role";
74958 +
74959 + // not in any affected group/role
74960 + if (!msg)
74961 + goto next_check;
74962 +
74963 + if (gr_is_global_nonroot(inode->i_uid))
74964 + msg2 = "file in non-root-owned directory";
74965 + else if (inode->i_mode & S_IWOTH)
74966 + msg2 = "file in world-writable directory";
74967 + else if (inode->i_mode & S_IWGRP)
74968 + msg2 = "file in group-writable directory";
74969 +
74970 + if (msg && msg2) {
74971 + char fullmsg[70] = {0};
74972 + snprintf(fullmsg, sizeof(fullmsg)-1, "%s and %s", msg, msg2);
74973 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, fullmsg, file->f_path.dentry, file->f_path.mnt);
74974 + return 0;
74975 + }
74976 + msg = NULL;
74977 +next_check:
74978 +#ifdef CONFIG_GRKERNSEC_TPE_ALL
74979 + if (!grsec_enable_tpe || !grsec_enable_tpe_all)
74980 + return 1;
74981 +
74982 + if (gr_is_global_nonroot(inode->i_uid) && !uid_eq(inode->i_uid, cred->uid))
74983 + msg = "directory not owned by user";
74984 + else if (inode->i_mode & S_IWOTH)
74985 + msg = "file in world-writable directory";
74986 + else if (inode->i_mode & S_IWGRP)
74987 + msg = "file in group-writable directory";
74988 +
74989 + if (msg) {
74990 + gr_log_str_fs(GR_DONT_AUDIT, GR_EXEC_TPE_MSG, msg, file->f_path.dentry, file->f_path.mnt);
74991 + return 0;
74992 + }
74993 +#endif
74994 +#endif
74995 + return 1;
74996 +}
74997 diff --git a/grsecurity/grsec_usb.c b/grsecurity/grsec_usb.c
74998 new file mode 100644
74999 index 0000000..ae02d8e
75000 --- /dev/null
75001 +++ b/grsecurity/grsec_usb.c
75002 @@ -0,0 +1,15 @@
75003 +#include <linux/kernel.h>
75004 +#include <linux/grinternal.h>
75005 +#include <linux/module.h>
75006 +
75007 +int gr_handle_new_usb(void)
75008 +{
75009 +#ifdef CONFIG_GRKERNSEC_DENYUSB
75010 + if (grsec_deny_new_usb) {
75011 + printk(KERN_ALERT "grsec: denied insert of new USB device\n");
75012 + return 1;
75013 + }
75014 +#endif
75015 + return 0;
75016 +}
75017 +EXPORT_SYMBOL_GPL(gr_handle_new_usb);
75018 diff --git a/grsecurity/grsum.c b/grsecurity/grsum.c
75019 new file mode 100644
75020 index 0000000..9f7b1ac
75021 --- /dev/null
75022 +++ b/grsecurity/grsum.c
75023 @@ -0,0 +1,61 @@
75024 +#include <linux/err.h>
75025 +#include <linux/kernel.h>
75026 +#include <linux/sched.h>
75027 +#include <linux/mm.h>
75028 +#include <linux/scatterlist.h>
75029 +#include <linux/crypto.h>
75030 +#include <linux/gracl.h>
75031 +
75032 +
75033 +#if !defined(CONFIG_CRYPTO) || defined(CONFIG_CRYPTO_MODULE) || !defined(CONFIG_CRYPTO_SHA256) || defined(CONFIG_CRYPTO_SHA256_MODULE)
75034 +#error "crypto and sha256 must be built into the kernel"
75035 +#endif
75036 +
75037 +int
75038 +chkpw(struct gr_arg *entry, unsigned char *salt, unsigned char *sum)
75039 +{
75040 + char *p;
75041 + struct crypto_hash *tfm;
75042 + struct hash_desc desc;
75043 + struct scatterlist sg;
75044 + unsigned char temp_sum[GR_SHA_LEN];
75045 + volatile int retval = 0;
75046 + volatile int dummy = 0;
75047 + unsigned int i;
75048 +
75049 + sg_init_table(&sg, 1);
75050 +
75051 + tfm = crypto_alloc_hash("sha256", 0, CRYPTO_ALG_ASYNC);
75052 + if (IS_ERR(tfm)) {
75053 + /* should never happen, since sha256 should be built in */
75054 + return 1;
75055 + }
75056 +
75057 + desc.tfm = tfm;
75058 + desc.flags = 0;
75059 +
75060 + crypto_hash_init(&desc);
75061 +
75062 + p = salt;
75063 + sg_set_buf(&sg, p, GR_SALT_LEN);
75064 + crypto_hash_update(&desc, &sg, sg.length);
75065 +
75066 + p = entry->pw;
75067 + sg_set_buf(&sg, p, strlen(p));
75068 +
75069 + crypto_hash_update(&desc, &sg, sg.length);
75070 +
75071 + crypto_hash_final(&desc, temp_sum);
75072 +
75073 + memset(entry->pw, 0, GR_PW_LEN);
75074 +
75075 + for (i = 0; i < GR_SHA_LEN; i++)
75076 + if (sum[i] != temp_sum[i])
75077 + retval = 1;
75078 + else
75079 + dummy = 1; // waste a cycle
75080 +
75081 + crypto_free_hash(tfm);
75082 +
75083 + return retval;
75084 +}
75085 diff --git a/include/asm-generic/4level-fixup.h b/include/asm-generic/4level-fixup.h
75086 index 77ff547..181834f 100644
75087 --- a/include/asm-generic/4level-fixup.h
75088 +++ b/include/asm-generic/4level-fixup.h
75089 @@ -13,8 +13,10 @@
75090 #define pmd_alloc(mm, pud, address) \
75091 ((unlikely(pgd_none(*(pud))) && __pmd_alloc(mm, pud, address))? \
75092 NULL: pmd_offset(pud, address))
75093 +#define pmd_alloc_kernel(mm, pud, address) pmd_alloc((mm), (pud), (address))
75094
75095 #define pud_alloc(mm, pgd, address) (pgd)
75096 +#define pud_alloc_kernel(mm, pgd, address) pud_alloc((mm), (pgd), (address))
75097 #define pud_offset(pgd, start) (pgd)
75098 #define pud_none(pud) 0
75099 #define pud_bad(pud) 0
75100 diff --git a/include/asm-generic/atomic-long.h b/include/asm-generic/atomic-long.h
75101 index b7babf0..97f4c4f 100644
75102 --- a/include/asm-generic/atomic-long.h
75103 +++ b/include/asm-generic/atomic-long.h
75104 @@ -22,6 +22,12 @@
75105
75106 typedef atomic64_t atomic_long_t;
75107
75108 +#ifdef CONFIG_PAX_REFCOUNT
75109 +typedef atomic64_unchecked_t atomic_long_unchecked_t;
75110 +#else
75111 +typedef atomic64_t atomic_long_unchecked_t;
75112 +#endif
75113 +
75114 #define ATOMIC_LONG_INIT(i) ATOMIC64_INIT(i)
75115
75116 static inline long atomic_long_read(atomic_long_t *l)
75117 @@ -31,6 +37,15 @@ static inline long atomic_long_read(atomic_long_t *l)
75118 return (long)atomic64_read(v);
75119 }
75120
75121 +#ifdef CONFIG_PAX_REFCOUNT
75122 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
75123 +{
75124 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75125 +
75126 + return (long)atomic64_read_unchecked(v);
75127 +}
75128 +#endif
75129 +
75130 static inline void atomic_long_set(atomic_long_t *l, long i)
75131 {
75132 atomic64_t *v = (atomic64_t *)l;
75133 @@ -38,6 +53,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
75134 atomic64_set(v, i);
75135 }
75136
75137 +#ifdef CONFIG_PAX_REFCOUNT
75138 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
75139 +{
75140 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75141 +
75142 + atomic64_set_unchecked(v, i);
75143 +}
75144 +#endif
75145 +
75146 static inline void atomic_long_inc(atomic_long_t *l)
75147 {
75148 atomic64_t *v = (atomic64_t *)l;
75149 @@ -45,6 +69,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
75150 atomic64_inc(v);
75151 }
75152
75153 +#ifdef CONFIG_PAX_REFCOUNT
75154 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
75155 +{
75156 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75157 +
75158 + atomic64_inc_unchecked(v);
75159 +}
75160 +#endif
75161 +
75162 static inline void atomic_long_dec(atomic_long_t *l)
75163 {
75164 atomic64_t *v = (atomic64_t *)l;
75165 @@ -52,6 +85,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
75166 atomic64_dec(v);
75167 }
75168
75169 +#ifdef CONFIG_PAX_REFCOUNT
75170 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
75171 +{
75172 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75173 +
75174 + atomic64_dec_unchecked(v);
75175 +}
75176 +#endif
75177 +
75178 static inline void atomic_long_add(long i, atomic_long_t *l)
75179 {
75180 atomic64_t *v = (atomic64_t *)l;
75181 @@ -59,6 +101,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
75182 atomic64_add(i, v);
75183 }
75184
75185 +#ifdef CONFIG_PAX_REFCOUNT
75186 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
75187 +{
75188 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75189 +
75190 + atomic64_add_unchecked(i, v);
75191 +}
75192 +#endif
75193 +
75194 static inline void atomic_long_sub(long i, atomic_long_t *l)
75195 {
75196 atomic64_t *v = (atomic64_t *)l;
75197 @@ -66,6 +117,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
75198 atomic64_sub(i, v);
75199 }
75200
75201 +#ifdef CONFIG_PAX_REFCOUNT
75202 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
75203 +{
75204 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75205 +
75206 + atomic64_sub_unchecked(i, v);
75207 +}
75208 +#endif
75209 +
75210 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
75211 {
75212 atomic64_t *v = (atomic64_t *)l;
75213 @@ -94,13 +154,22 @@ static inline int atomic_long_add_negative(long i, atomic_long_t *l)
75214 return atomic64_add_negative(i, v);
75215 }
75216
75217 -static inline long atomic_long_add_return(long i, atomic_long_t *l)
75218 +static inline long __intentional_overflow(-1) atomic_long_add_return(long i, atomic_long_t *l)
75219 {
75220 atomic64_t *v = (atomic64_t *)l;
75221
75222 return (long)atomic64_add_return(i, v);
75223 }
75224
75225 +#ifdef CONFIG_PAX_REFCOUNT
75226 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
75227 +{
75228 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75229 +
75230 + return (long)atomic64_add_return_unchecked(i, v);
75231 +}
75232 +#endif
75233 +
75234 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
75235 {
75236 atomic64_t *v = (atomic64_t *)l;
75237 @@ -115,6 +184,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
75238 return (long)atomic64_inc_return(v);
75239 }
75240
75241 +#ifdef CONFIG_PAX_REFCOUNT
75242 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
75243 +{
75244 + atomic64_unchecked_t *v = (atomic64_unchecked_t *)l;
75245 +
75246 + return (long)atomic64_inc_return_unchecked(v);
75247 +}
75248 +#endif
75249 +
75250 static inline long atomic_long_dec_return(atomic_long_t *l)
75251 {
75252 atomic64_t *v = (atomic64_t *)l;
75253 @@ -140,6 +218,12 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
75254
75255 typedef atomic_t atomic_long_t;
75256
75257 +#ifdef CONFIG_PAX_REFCOUNT
75258 +typedef atomic_unchecked_t atomic_long_unchecked_t;
75259 +#else
75260 +typedef atomic_t atomic_long_unchecked_t;
75261 +#endif
75262 +
75263 #define ATOMIC_LONG_INIT(i) ATOMIC_INIT(i)
75264 static inline long atomic_long_read(atomic_long_t *l)
75265 {
75266 @@ -148,6 +232,15 @@ static inline long atomic_long_read(atomic_long_t *l)
75267 return (long)atomic_read(v);
75268 }
75269
75270 +#ifdef CONFIG_PAX_REFCOUNT
75271 +static inline long atomic_long_read_unchecked(atomic_long_unchecked_t *l)
75272 +{
75273 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75274 +
75275 + return (long)atomic_read_unchecked(v);
75276 +}
75277 +#endif
75278 +
75279 static inline void atomic_long_set(atomic_long_t *l, long i)
75280 {
75281 atomic_t *v = (atomic_t *)l;
75282 @@ -155,6 +248,15 @@ static inline void atomic_long_set(atomic_long_t *l, long i)
75283 atomic_set(v, i);
75284 }
75285
75286 +#ifdef CONFIG_PAX_REFCOUNT
75287 +static inline void atomic_long_set_unchecked(atomic_long_unchecked_t *l, long i)
75288 +{
75289 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75290 +
75291 + atomic_set_unchecked(v, i);
75292 +}
75293 +#endif
75294 +
75295 static inline void atomic_long_inc(atomic_long_t *l)
75296 {
75297 atomic_t *v = (atomic_t *)l;
75298 @@ -162,6 +264,15 @@ static inline void atomic_long_inc(atomic_long_t *l)
75299 atomic_inc(v);
75300 }
75301
75302 +#ifdef CONFIG_PAX_REFCOUNT
75303 +static inline void atomic_long_inc_unchecked(atomic_long_unchecked_t *l)
75304 +{
75305 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75306 +
75307 + atomic_inc_unchecked(v);
75308 +}
75309 +#endif
75310 +
75311 static inline void atomic_long_dec(atomic_long_t *l)
75312 {
75313 atomic_t *v = (atomic_t *)l;
75314 @@ -169,6 +280,15 @@ static inline void atomic_long_dec(atomic_long_t *l)
75315 atomic_dec(v);
75316 }
75317
75318 +#ifdef CONFIG_PAX_REFCOUNT
75319 +static inline void atomic_long_dec_unchecked(atomic_long_unchecked_t *l)
75320 +{
75321 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75322 +
75323 + atomic_dec_unchecked(v);
75324 +}
75325 +#endif
75326 +
75327 static inline void atomic_long_add(long i, atomic_long_t *l)
75328 {
75329 atomic_t *v = (atomic_t *)l;
75330 @@ -176,6 +296,15 @@ static inline void atomic_long_add(long i, atomic_long_t *l)
75331 atomic_add(i, v);
75332 }
75333
75334 +#ifdef CONFIG_PAX_REFCOUNT
75335 +static inline void atomic_long_add_unchecked(long i, atomic_long_unchecked_t *l)
75336 +{
75337 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75338 +
75339 + atomic_add_unchecked(i, v);
75340 +}
75341 +#endif
75342 +
75343 static inline void atomic_long_sub(long i, atomic_long_t *l)
75344 {
75345 atomic_t *v = (atomic_t *)l;
75346 @@ -183,6 +312,15 @@ static inline void atomic_long_sub(long i, atomic_long_t *l)
75347 atomic_sub(i, v);
75348 }
75349
75350 +#ifdef CONFIG_PAX_REFCOUNT
75351 +static inline void atomic_long_sub_unchecked(long i, atomic_long_unchecked_t *l)
75352 +{
75353 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75354 +
75355 + atomic_sub_unchecked(i, v);
75356 +}
75357 +#endif
75358 +
75359 static inline int atomic_long_sub_and_test(long i, atomic_long_t *l)
75360 {
75361 atomic_t *v = (atomic_t *)l;
75362 @@ -218,6 +356,16 @@ static inline long atomic_long_add_return(long i, atomic_long_t *l)
75363 return (long)atomic_add_return(i, v);
75364 }
75365
75366 +#ifdef CONFIG_PAX_REFCOUNT
75367 +static inline long atomic_long_add_return_unchecked(long i, atomic_long_unchecked_t *l)
75368 +{
75369 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75370 +
75371 + return (long)atomic_add_return_unchecked(i, v);
75372 +}
75373 +
75374 +#endif
75375 +
75376 static inline long atomic_long_sub_return(long i, atomic_long_t *l)
75377 {
75378 atomic_t *v = (atomic_t *)l;
75379 @@ -232,6 +380,15 @@ static inline long atomic_long_inc_return(atomic_long_t *l)
75380 return (long)atomic_inc_return(v);
75381 }
75382
75383 +#ifdef CONFIG_PAX_REFCOUNT
75384 +static inline long atomic_long_inc_return_unchecked(atomic_long_unchecked_t *l)
75385 +{
75386 + atomic_unchecked_t *v = (atomic_unchecked_t *)l;
75387 +
75388 + return (long)atomic_inc_return_unchecked(v);
75389 +}
75390 +#endif
75391 +
75392 static inline long atomic_long_dec_return(atomic_long_t *l)
75393 {
75394 atomic_t *v = (atomic_t *)l;
75395 @@ -255,4 +412,57 @@ static inline long atomic_long_add_unless(atomic_long_t *l, long a, long u)
75396
75397 #endif /* BITS_PER_LONG == 64 */
75398
75399 +#ifdef CONFIG_PAX_REFCOUNT
75400 +static inline void pax_refcount_needs_these_functions(void)
75401 +{
75402 + atomic_read_unchecked((atomic_unchecked_t *)NULL);
75403 + atomic_set_unchecked((atomic_unchecked_t *)NULL, 0);
75404 + atomic_add_unchecked(0, (atomic_unchecked_t *)NULL);
75405 + atomic_sub_unchecked(0, (atomic_unchecked_t *)NULL);
75406 + atomic_inc_unchecked((atomic_unchecked_t *)NULL);
75407 + (void)atomic_inc_and_test_unchecked((atomic_unchecked_t *)NULL);
75408 + atomic_inc_return_unchecked((atomic_unchecked_t *)NULL);
75409 + atomic_add_return_unchecked(0, (atomic_unchecked_t *)NULL);
75410 + atomic_dec_unchecked((atomic_unchecked_t *)NULL);
75411 + atomic_cmpxchg_unchecked((atomic_unchecked_t *)NULL, 0, 0);
75412 + (void)atomic_xchg_unchecked((atomic_unchecked_t *)NULL, 0);
75413 +#ifdef CONFIG_X86
75414 + atomic_clear_mask_unchecked(0, NULL);
75415 + atomic_set_mask_unchecked(0, NULL);
75416 +#endif
75417 +
75418 + atomic_long_read_unchecked((atomic_long_unchecked_t *)NULL);
75419 + atomic_long_set_unchecked((atomic_long_unchecked_t *)NULL, 0);
75420 + atomic_long_add_unchecked(0, (atomic_long_unchecked_t *)NULL);
75421 + atomic_long_sub_unchecked(0, (atomic_long_unchecked_t *)NULL);
75422 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)NULL);
75423 + atomic_long_add_return_unchecked(0, (atomic_long_unchecked_t *)NULL);
75424 + atomic_long_inc_return_unchecked((atomic_long_unchecked_t *)NULL);
75425 + atomic_long_dec_unchecked((atomic_long_unchecked_t *)NULL);
75426 +}
75427 +#else
75428 +#define atomic_read_unchecked(v) atomic_read(v)
75429 +#define atomic_set_unchecked(v, i) atomic_set((v), (i))
75430 +#define atomic_add_unchecked(i, v) atomic_add((i), (v))
75431 +#define atomic_sub_unchecked(i, v) atomic_sub((i), (v))
75432 +#define atomic_inc_unchecked(v) atomic_inc(v)
75433 +#define atomic_inc_and_test_unchecked(v) atomic_inc_and_test(v)
75434 +#define atomic_inc_return_unchecked(v) atomic_inc_return(v)
75435 +#define atomic_add_return_unchecked(i, v) atomic_add_return((i), (v))
75436 +#define atomic_dec_unchecked(v) atomic_dec(v)
75437 +#define atomic_cmpxchg_unchecked(v, o, n) atomic_cmpxchg((v), (o), (n))
75438 +#define atomic_xchg_unchecked(v, i) atomic_xchg((v), (i))
75439 +#define atomic_clear_mask_unchecked(mask, v) atomic_clear_mask((mask), (v))
75440 +#define atomic_set_mask_unchecked(mask, v) atomic_set_mask((mask), (v))
75441 +
75442 +#define atomic_long_read_unchecked(v) atomic_long_read(v)
75443 +#define atomic_long_set_unchecked(v, i) atomic_long_set((v), (i))
75444 +#define atomic_long_add_unchecked(i, v) atomic_long_add((i), (v))
75445 +#define atomic_long_sub_unchecked(i, v) atomic_long_sub((i), (v))
75446 +#define atomic_long_inc_unchecked(v) atomic_long_inc(v)
75447 +#define atomic_long_add_return_unchecked(i, v) atomic_long_add_return((i), (v))
75448 +#define atomic_long_inc_return_unchecked(v) atomic_long_inc_return(v)
75449 +#define atomic_long_dec_unchecked(v) atomic_long_dec(v)
75450 +#endif
75451 +
75452 #endif /* _ASM_GENERIC_ATOMIC_LONG_H */
75453 diff --git a/include/asm-generic/atomic.h b/include/asm-generic/atomic.h
75454 index 33bd2de..f31bff97 100644
75455 --- a/include/asm-generic/atomic.h
75456 +++ b/include/asm-generic/atomic.h
75457 @@ -153,7 +153,7 @@ static inline int __atomic_add_unless(atomic_t *v, int a, int u)
75458 * Atomically clears the bits set in @mask from @v
75459 */
75460 #ifndef atomic_clear_mask
75461 -static inline void atomic_clear_mask(unsigned long mask, atomic_t *v)
75462 +static inline void atomic_clear_mask(unsigned int mask, atomic_t *v)
75463 {
75464 unsigned long flags;
75465
75466 diff --git a/include/asm-generic/atomic64.h b/include/asm-generic/atomic64.h
75467 index b18ce4f..2ee2843 100644
75468 --- a/include/asm-generic/atomic64.h
75469 +++ b/include/asm-generic/atomic64.h
75470 @@ -16,6 +16,8 @@ typedef struct {
75471 long long counter;
75472 } atomic64_t;
75473
75474 +typedef atomic64_t atomic64_unchecked_t;
75475 +
75476 #define ATOMIC64_INIT(i) { (i) }
75477
75478 extern long long atomic64_read(const atomic64_t *v);
75479 @@ -39,4 +41,14 @@ extern int atomic64_add_unless(atomic64_t *v, long long a, long long u);
75480 #define atomic64_dec_and_test(v) (atomic64_dec_return((v)) == 0)
75481 #define atomic64_inc_not_zero(v) atomic64_add_unless((v), 1LL, 0LL)
75482
75483 +#define atomic64_read_unchecked(v) atomic64_read(v)
75484 +#define atomic64_set_unchecked(v, i) atomic64_set((v), (i))
75485 +#define atomic64_add_unchecked(a, v) atomic64_add((a), (v))
75486 +#define atomic64_add_return_unchecked(a, v) atomic64_add_return((a), (v))
75487 +#define atomic64_sub_unchecked(a, v) atomic64_sub((a), (v))
75488 +#define atomic64_inc_unchecked(v) atomic64_inc(v)
75489 +#define atomic64_inc_return_unchecked(v) atomic64_inc_return(v)
75490 +#define atomic64_dec_unchecked(v) atomic64_dec(v)
75491 +#define atomic64_cmpxchg_unchecked(v, o, n) atomic64_cmpxchg((v), (o), (n))
75492 +
75493 #endif /* _ASM_GENERIC_ATOMIC64_H */
75494 diff --git a/include/asm-generic/bitops/__fls.h b/include/asm-generic/bitops/__fls.h
75495 index a60a7cc..0fe12f2 100644
75496 --- a/include/asm-generic/bitops/__fls.h
75497 +++ b/include/asm-generic/bitops/__fls.h
75498 @@ -9,7 +9,7 @@
75499 *
75500 * Undefined if no set bit exists, so code should check against 0 first.
75501 */
75502 -static __always_inline unsigned long __fls(unsigned long word)
75503 +static __always_inline unsigned long __intentional_overflow(-1) __fls(unsigned long word)
75504 {
75505 int num = BITS_PER_LONG - 1;
75506
75507 diff --git a/include/asm-generic/bitops/fls.h b/include/asm-generic/bitops/fls.h
75508 index 0576d1f..dad6c71 100644
75509 --- a/include/asm-generic/bitops/fls.h
75510 +++ b/include/asm-generic/bitops/fls.h
75511 @@ -9,7 +9,7 @@
75512 * Note fls(0) = 0, fls(1) = 1, fls(0x80000000) = 32.
75513 */
75514
75515 -static __always_inline int fls(int x)
75516 +static __always_inline int __intentional_overflow(-1) fls(int x)
75517 {
75518 int r = 32;
75519
75520 diff --git a/include/asm-generic/bitops/fls64.h b/include/asm-generic/bitops/fls64.h
75521 index b097cf8..3d40e14 100644
75522 --- a/include/asm-generic/bitops/fls64.h
75523 +++ b/include/asm-generic/bitops/fls64.h
75524 @@ -15,7 +15,7 @@
75525 * at position 64.
75526 */
75527 #if BITS_PER_LONG == 32
75528 -static __always_inline int fls64(__u64 x)
75529 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
75530 {
75531 __u32 h = x >> 32;
75532 if (h)
75533 @@ -23,7 +23,7 @@ static __always_inline int fls64(__u64 x)
75534 return fls(x);
75535 }
75536 #elif BITS_PER_LONG == 64
75537 -static __always_inline int fls64(__u64 x)
75538 +static __always_inline int __intentional_overflow(-1) fls64(__u64 x)
75539 {
75540 if (x == 0)
75541 return 0;
75542 diff --git a/include/asm-generic/cache.h b/include/asm-generic/cache.h
75543 index 1bfcfe5..e04c5c9 100644
75544 --- a/include/asm-generic/cache.h
75545 +++ b/include/asm-generic/cache.h
75546 @@ -6,7 +6,7 @@
75547 * cache lines need to provide their own cache.h.
75548 */
75549
75550 -#define L1_CACHE_SHIFT 5
75551 -#define L1_CACHE_BYTES (1 << L1_CACHE_SHIFT)
75552 +#define L1_CACHE_SHIFT 5UL
75553 +#define L1_CACHE_BYTES (1UL << L1_CACHE_SHIFT)
75554
75555 #endif /* __ASM_GENERIC_CACHE_H */
75556 diff --git a/include/asm-generic/emergency-restart.h b/include/asm-generic/emergency-restart.h
75557 index 0d68a1e..b74a761 100644
75558 --- a/include/asm-generic/emergency-restart.h
75559 +++ b/include/asm-generic/emergency-restart.h
75560 @@ -1,7 +1,7 @@
75561 #ifndef _ASM_GENERIC_EMERGENCY_RESTART_H
75562 #define _ASM_GENERIC_EMERGENCY_RESTART_H
75563
75564 -static inline void machine_emergency_restart(void)
75565 +static inline __noreturn void machine_emergency_restart(void)
75566 {
75567 machine_restart(NULL);
75568 }
75569 diff --git a/include/asm-generic/kmap_types.h b/include/asm-generic/kmap_types.h
75570 index 90f99c7..00ce236 100644
75571 --- a/include/asm-generic/kmap_types.h
75572 +++ b/include/asm-generic/kmap_types.h
75573 @@ -2,9 +2,9 @@
75574 #define _ASM_GENERIC_KMAP_TYPES_H
75575
75576 #ifdef __WITH_KM_FENCE
75577 -# define KM_TYPE_NR 41
75578 +# define KM_TYPE_NR 42
75579 #else
75580 -# define KM_TYPE_NR 20
75581 +# define KM_TYPE_NR 21
75582 #endif
75583
75584 #endif
75585 diff --git a/include/asm-generic/local.h b/include/asm-generic/local.h
75586 index 9ceb03b..62b0b8f 100644
75587 --- a/include/asm-generic/local.h
75588 +++ b/include/asm-generic/local.h
75589 @@ -23,24 +23,37 @@ typedef struct
75590 atomic_long_t a;
75591 } local_t;
75592
75593 +typedef struct {
75594 + atomic_long_unchecked_t a;
75595 +} local_unchecked_t;
75596 +
75597 #define LOCAL_INIT(i) { ATOMIC_LONG_INIT(i) }
75598
75599 #define local_read(l) atomic_long_read(&(l)->a)
75600 +#define local_read_unchecked(l) atomic_long_read_unchecked(&(l)->a)
75601 #define local_set(l,i) atomic_long_set((&(l)->a),(i))
75602 +#define local_set_unchecked(l,i) atomic_long_set_unchecked((&(l)->a),(i))
75603 #define local_inc(l) atomic_long_inc(&(l)->a)
75604 +#define local_inc_unchecked(l) atomic_long_inc_unchecked(&(l)->a)
75605 #define local_dec(l) atomic_long_dec(&(l)->a)
75606 +#define local_dec_unchecked(l) atomic_long_dec_unchecked(&(l)->a)
75607 #define local_add(i,l) atomic_long_add((i),(&(l)->a))
75608 +#define local_add_unchecked(i,l) atomic_long_add_unchecked((i),(&(l)->a))
75609 #define local_sub(i,l) atomic_long_sub((i),(&(l)->a))
75610 +#define local_sub_unchecked(i,l) atomic_long_sub_unchecked((i),(&(l)->a))
75611
75612 #define local_sub_and_test(i, l) atomic_long_sub_and_test((i), (&(l)->a))
75613 #define local_dec_and_test(l) atomic_long_dec_and_test(&(l)->a)
75614 #define local_inc_and_test(l) atomic_long_inc_and_test(&(l)->a)
75615 #define local_add_negative(i, l) atomic_long_add_negative((i), (&(l)->a))
75616 #define local_add_return(i, l) atomic_long_add_return((i), (&(l)->a))
75617 +#define local_add_return_unchecked(i, l) atomic_long_add_return_unchecked((i), (&(l)->a))
75618 #define local_sub_return(i, l) atomic_long_sub_return((i), (&(l)->a))
75619 #define local_inc_return(l) atomic_long_inc_return(&(l)->a)
75620 +#define local_dec_return(l) atomic_long_dec_return(&(l)->a)
75621
75622 #define local_cmpxchg(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
75623 +#define local_cmpxchg_unchecked(l, o, n) atomic_long_cmpxchg((&(l)->a), (o), (n))
75624 #define local_xchg(l, n) atomic_long_xchg((&(l)->a), (n))
75625 #define local_add_unless(l, _a, u) atomic_long_add_unless((&(l)->a), (_a), (u))
75626 #define local_inc_not_zero(l) atomic_long_inc_not_zero(&(l)->a)
75627 diff --git a/include/asm-generic/pgtable-nopmd.h b/include/asm-generic/pgtable-nopmd.h
75628 index 725612b..9cc513a 100644
75629 --- a/include/asm-generic/pgtable-nopmd.h
75630 +++ b/include/asm-generic/pgtable-nopmd.h
75631 @@ -1,14 +1,19 @@
75632 #ifndef _PGTABLE_NOPMD_H
75633 #define _PGTABLE_NOPMD_H
75634
75635 -#ifndef __ASSEMBLY__
75636 -
75637 #include <asm-generic/pgtable-nopud.h>
75638
75639 -struct mm_struct;
75640 -
75641 #define __PAGETABLE_PMD_FOLDED
75642
75643 +#define PMD_SHIFT PUD_SHIFT
75644 +#define PTRS_PER_PMD 1
75645 +#define PMD_SIZE (_AC(1,UL) << PMD_SHIFT)
75646 +#define PMD_MASK (~(PMD_SIZE-1))
75647 +
75648 +#ifndef __ASSEMBLY__
75649 +
75650 +struct mm_struct;
75651 +
75652 /*
75653 * Having the pmd type consist of a pud gets the size right, and allows
75654 * us to conceptually access the pud entry that this pmd is folded into
75655 @@ -16,11 +21,6 @@ struct mm_struct;
75656 */
75657 typedef struct { pud_t pud; } pmd_t;
75658
75659 -#define PMD_SHIFT PUD_SHIFT
75660 -#define PTRS_PER_PMD 1
75661 -#define PMD_SIZE (1UL << PMD_SHIFT)
75662 -#define PMD_MASK (~(PMD_SIZE-1))
75663 -
75664 /*
75665 * The "pud_xxx()" functions here are trivial for a folded two-level
75666 * setup: the pmd is never bad, and a pmd always exists (as it's folded
75667 diff --git a/include/asm-generic/pgtable-nopud.h b/include/asm-generic/pgtable-nopud.h
75668 index 810431d..0ec4804f 100644
75669 --- a/include/asm-generic/pgtable-nopud.h
75670 +++ b/include/asm-generic/pgtable-nopud.h
75671 @@ -1,10 +1,15 @@
75672 #ifndef _PGTABLE_NOPUD_H
75673 #define _PGTABLE_NOPUD_H
75674
75675 -#ifndef __ASSEMBLY__
75676 -
75677 #define __PAGETABLE_PUD_FOLDED
75678
75679 +#define PUD_SHIFT PGDIR_SHIFT
75680 +#define PTRS_PER_PUD 1
75681 +#define PUD_SIZE (_AC(1,UL) << PUD_SHIFT)
75682 +#define PUD_MASK (~(PUD_SIZE-1))
75683 +
75684 +#ifndef __ASSEMBLY__
75685 +
75686 /*
75687 * Having the pud type consist of a pgd gets the size right, and allows
75688 * us to conceptually access the pgd entry that this pud is folded into
75689 @@ -12,11 +17,6 @@
75690 */
75691 typedef struct { pgd_t pgd; } pud_t;
75692
75693 -#define PUD_SHIFT PGDIR_SHIFT
75694 -#define PTRS_PER_PUD 1
75695 -#define PUD_SIZE (1UL << PUD_SHIFT)
75696 -#define PUD_MASK (~(PUD_SIZE-1))
75697 -
75698 /*
75699 * The "pgd_xxx()" functions here are trivial for a folded two-level
75700 * setup: the pud is never bad, and a pud always exists (as it's folded
75701 @@ -29,6 +29,7 @@ static inline void pgd_clear(pgd_t *pgd) { }
75702 #define pud_ERROR(pud) (pgd_ERROR((pud).pgd))
75703
75704 #define pgd_populate(mm, pgd, pud) do { } while (0)
75705 +#define pgd_populate_kernel(mm, pgd, pud) do { } while (0)
75706 /*
75707 * (puds are folded into pgds so this doesn't get actually called,
75708 * but the define is needed for a generic inline function.)
75709 diff --git a/include/asm-generic/pgtable.h b/include/asm-generic/pgtable.h
75710 index 8e4f41d..c5e9afd 100644
75711 --- a/include/asm-generic/pgtable.h
75712 +++ b/include/asm-generic/pgtable.h
75713 @@ -748,6 +748,22 @@ static inline pmd_t pmd_mknuma(pmd_t pmd)
75714 }
75715 #endif /* CONFIG_NUMA_BALANCING */
75716
75717 +#ifndef __HAVE_ARCH_PAX_OPEN_KERNEL
75718 +#ifdef CONFIG_PAX_KERNEXEC
75719 +#error KERNEXEC requires pax_open_kernel
75720 +#else
75721 +static inline unsigned long pax_open_kernel(void) { return 0; }
75722 +#endif
75723 +#endif
75724 +
75725 +#ifndef __HAVE_ARCH_PAX_CLOSE_KERNEL
75726 +#ifdef CONFIG_PAX_KERNEXEC
75727 +#error KERNEXEC requires pax_close_kernel
75728 +#else
75729 +static inline unsigned long pax_close_kernel(void) { return 0; }
75730 +#endif
75731 +#endif
75732 +
75733 #endif /* CONFIG_MMU */
75734
75735 #endif /* !__ASSEMBLY__ */
75736 diff --git a/include/asm-generic/uaccess.h b/include/asm-generic/uaccess.h
75737 index dc1269c..48a4f51 100644
75738 --- a/include/asm-generic/uaccess.h
75739 +++ b/include/asm-generic/uaccess.h
75740 @@ -343,4 +343,20 @@ clear_user(void __user *to, unsigned long n)
75741 return __clear_user(to, n);
75742 }
75743
75744 +#ifndef __HAVE_ARCH_PAX_OPEN_USERLAND
75745 +#ifdef CONFIG_PAX_MEMORY_UDEREF
75746 +#error UDEREF requires pax_open_userland
75747 +#else
75748 +static inline unsigned long pax_open_userland(void) { return 0; }
75749 +#endif
75750 +#endif
75751 +
75752 +#ifndef __HAVE_ARCH_PAX_CLOSE_USERLAND
75753 +#ifdef CONFIG_PAX_MEMORY_UDEREF
75754 +#error UDEREF requires pax_close_userland
75755 +#else
75756 +static inline unsigned long pax_close_userland(void) { return 0; }
75757 +#endif
75758 +#endif
75759 +
75760 #endif /* __ASM_GENERIC_UACCESS_H */
75761 diff --git a/include/asm-generic/vmlinux.lds.h b/include/asm-generic/vmlinux.lds.h
75762 index bc2121f..2f41f9a 100644
75763 --- a/include/asm-generic/vmlinux.lds.h
75764 +++ b/include/asm-generic/vmlinux.lds.h
75765 @@ -232,6 +232,7 @@
75766 .rodata : AT(ADDR(.rodata) - LOAD_OFFSET) { \
75767 VMLINUX_SYMBOL(__start_rodata) = .; \
75768 *(.rodata) *(.rodata.*) \
75769 + *(.data..read_only) \
75770 *(__vermagic) /* Kernel version magic */ \
75771 . = ALIGN(8); \
75772 VMLINUX_SYMBOL(__start___tracepoints_ptrs) = .; \
75773 @@ -716,17 +717,18 @@
75774 * section in the linker script will go there too. @phdr should have
75775 * a leading colon.
75776 *
75777 - * Note that this macros defines __per_cpu_load as an absolute symbol.
75778 + * Note that this macros defines per_cpu_load as an absolute symbol.
75779 * If there is no need to put the percpu section at a predetermined
75780 * address, use PERCPU_SECTION.
75781 */
75782 #define PERCPU_VADDR(cacheline, vaddr, phdr) \
75783 - VMLINUX_SYMBOL(__per_cpu_load) = .; \
75784 - .data..percpu vaddr : AT(VMLINUX_SYMBOL(__per_cpu_load) \
75785 + per_cpu_load = .; \
75786 + .data..percpu vaddr : AT(VMLINUX_SYMBOL(per_cpu_load) \
75787 - LOAD_OFFSET) { \
75788 + VMLINUX_SYMBOL(__per_cpu_load) = . + per_cpu_load; \
75789 PERCPU_INPUT(cacheline) \
75790 } phdr \
75791 - . = VMLINUX_SYMBOL(__per_cpu_load) + SIZEOF(.data..percpu);
75792 + . = VMLINUX_SYMBOL(per_cpu_load) + SIZEOF(.data..percpu);
75793
75794 /**
75795 * PERCPU_SECTION - define output section for percpu area, simple version
75796 diff --git a/include/crypto/algapi.h b/include/crypto/algapi.h
75797 index e73c19e..5b89e00 100644
75798 --- a/include/crypto/algapi.h
75799 +++ b/include/crypto/algapi.h
75800 @@ -34,7 +34,7 @@ struct crypto_type {
75801 unsigned int maskclear;
75802 unsigned int maskset;
75803 unsigned int tfmsize;
75804 -};
75805 +} __do_const;
75806
75807 struct crypto_instance {
75808 struct crypto_alg alg;
75809 diff --git a/include/drm/drmP.h b/include/drm/drmP.h
75810 index 1d4a920..da65658 100644
75811 --- a/include/drm/drmP.h
75812 +++ b/include/drm/drmP.h
75813 @@ -66,6 +66,7 @@
75814 #include <linux/workqueue.h>
75815 #include <linux/poll.h>
75816 #include <asm/pgalloc.h>
75817 +#include <asm/local.h>
75818 #include <drm/drm.h>
75819 #include <drm/drm_sarea.h>
75820 #include <drm/drm_vma_manager.h>
75821 @@ -278,10 +279,12 @@ do { \
75822 * \param cmd command.
75823 * \param arg argument.
75824 */
75825 -typedef int drm_ioctl_t(struct drm_device *dev, void *data,
75826 +typedef int (* const drm_ioctl_t)(struct drm_device *dev, void *data,
75827 + struct drm_file *file_priv);
75828 +typedef int (* drm_ioctl_no_const_t)(struct drm_device *dev, void *data,
75829 struct drm_file *file_priv);
75830
75831 -typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
75832 +typedef int (* const drm_ioctl_compat_t)(struct file *filp, unsigned int cmd,
75833 unsigned long arg);
75834
75835 #define DRM_IOCTL_NR(n) _IOC_NR(n)
75836 @@ -297,10 +300,10 @@ typedef int drm_ioctl_compat_t(struct file *filp, unsigned int cmd,
75837 struct drm_ioctl_desc {
75838 unsigned int cmd;
75839 int flags;
75840 - drm_ioctl_t *func;
75841 + drm_ioctl_t func;
75842 unsigned int cmd_drv;
75843 const char *name;
75844 -};
75845 +} __do_const;
75846
75847 /**
75848 * Creates a driver or general drm_ioctl_desc array entry for the given
75849 @@ -1013,7 +1016,8 @@ struct drm_info_list {
75850 int (*show)(struct seq_file*, void*); /** show callback */
75851 u32 driver_features; /**< Required driver features for this entry */
75852 void *data;
75853 -};
75854 +} __do_const;
75855 +typedef struct drm_info_list __no_const drm_info_list_no_const;
75856
75857 /**
75858 * debugfs node structure. This structure represents a debugfs file.
75859 @@ -1097,7 +1101,7 @@ struct drm_device {
75860
75861 /** \name Usage Counters */
75862 /*@{ */
75863 - int open_count; /**< Outstanding files open */
75864 + local_t open_count; /**< Outstanding files open */
75865 atomic_t ioctl_count; /**< Outstanding IOCTLs pending */
75866 atomic_t vma_count; /**< Outstanding vma areas open */
75867 int buf_use; /**< Buffers in use -- cannot alloc */
75868 diff --git a/include/drm/drm_crtc_helper.h b/include/drm/drm_crtc_helper.h
75869 index ef6ad3a..be34b16 100644
75870 --- a/include/drm/drm_crtc_helper.h
75871 +++ b/include/drm/drm_crtc_helper.h
75872 @@ -109,7 +109,7 @@ struct drm_encoder_helper_funcs {
75873 struct drm_connector *connector);
75874 /* disable encoder when not in use - more explicit than dpms off */
75875 void (*disable)(struct drm_encoder *encoder);
75876 -};
75877 +} __no_const;
75878
75879 /**
75880 * drm_connector_helper_funcs - helper operations for connectors
75881 diff --git a/include/drm/i915_pciids.h b/include/drm/i915_pciids.h
75882 index 940ece4..8cb727f 100644
75883 --- a/include/drm/i915_pciids.h
75884 +++ b/include/drm/i915_pciids.h
75885 @@ -37,7 +37,7 @@
75886 */
75887 #define INTEL_VGA_DEVICE(id, info) { \
75888 0x8086, id, \
75889 - ~0, ~0, \
75890 + PCI_ANY_ID, PCI_ANY_ID, \
75891 0x030000, 0xff0000, \
75892 (unsigned long) info }
75893
75894 diff --git a/include/drm/ttm/ttm_memory.h b/include/drm/ttm/ttm_memory.h
75895 index 72dcbe8..8db58d7 100644
75896 --- a/include/drm/ttm/ttm_memory.h
75897 +++ b/include/drm/ttm/ttm_memory.h
75898 @@ -48,7 +48,7 @@
75899
75900 struct ttm_mem_shrink {
75901 int (*do_shrink) (struct ttm_mem_shrink *);
75902 -};
75903 +} __no_const;
75904
75905 /**
75906 * struct ttm_mem_global - Global memory accounting structure.
75907 diff --git a/include/drm/ttm/ttm_page_alloc.h b/include/drm/ttm/ttm_page_alloc.h
75908 index d1f61bf..2239439 100644
75909 --- a/include/drm/ttm/ttm_page_alloc.h
75910 +++ b/include/drm/ttm/ttm_page_alloc.h
75911 @@ -78,6 +78,7 @@ void ttm_dma_page_alloc_fini(void);
75912 */
75913 extern int ttm_dma_page_alloc_debugfs(struct seq_file *m, void *data);
75914
75915 +struct device;
75916 extern int ttm_dma_populate(struct ttm_dma_tt *ttm_dma, struct device *dev);
75917 extern void ttm_dma_unpopulate(struct ttm_dma_tt *ttm_dma, struct device *dev);
75918
75919 diff --git a/include/keys/asymmetric-subtype.h b/include/keys/asymmetric-subtype.h
75920 index 4b840e8..155d235 100644
75921 --- a/include/keys/asymmetric-subtype.h
75922 +++ b/include/keys/asymmetric-subtype.h
75923 @@ -37,7 +37,7 @@ struct asymmetric_key_subtype {
75924 /* Verify the signature on a key of this subtype (optional) */
75925 int (*verify_signature)(const struct key *key,
75926 const struct public_key_signature *sig);
75927 -};
75928 +} __do_const;
75929
75930 /**
75931 * asymmetric_key_subtype - Get the subtype from an asymmetric key
75932 diff --git a/include/linux/atmdev.h b/include/linux/atmdev.h
75933 index c1da539..1dcec55 100644
75934 --- a/include/linux/atmdev.h
75935 +++ b/include/linux/atmdev.h
75936 @@ -28,7 +28,7 @@ struct compat_atm_iobuf {
75937 #endif
75938
75939 struct k_atm_aal_stats {
75940 -#define __HANDLE_ITEM(i) atomic_t i
75941 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
75942 __AAL_STAT_ITEMS
75943 #undef __HANDLE_ITEM
75944 };
75945 @@ -200,7 +200,7 @@ struct atmdev_ops { /* only send is required */
75946 int (*change_qos)(struct atm_vcc *vcc,struct atm_qos *qos,int flags);
75947 int (*proc_read)(struct atm_dev *dev,loff_t *pos,char *page);
75948 struct module *owner;
75949 -};
75950 +} __do_const ;
75951
75952 struct atmphy_ops {
75953 int (*start)(struct atm_dev *dev);
75954 diff --git a/include/linux/audit.h b/include/linux/audit.h
75955 index bf1ef22..2a55e1b 100644
75956 --- a/include/linux/audit.h
75957 +++ b/include/linux/audit.h
75958 @@ -195,7 +195,7 @@ static inline void audit_ptrace(struct task_struct *t)
75959 extern unsigned int audit_serial(void);
75960 extern int auditsc_get_stamp(struct audit_context *ctx,
75961 struct timespec *t, unsigned int *serial);
75962 -extern int audit_set_loginuid(kuid_t loginuid);
75963 +extern int __intentional_overflow(-1) audit_set_loginuid(kuid_t loginuid);
75964
75965 static inline kuid_t audit_get_loginuid(struct task_struct *tsk)
75966 {
75967 diff --git a/include/linux/binfmts.h b/include/linux/binfmts.h
75968 index fd8bf32..2cccd5a 100644
75969 --- a/include/linux/binfmts.h
75970 +++ b/include/linux/binfmts.h
75971 @@ -74,8 +74,10 @@ struct linux_binfmt {
75972 int (*load_binary)(struct linux_binprm *);
75973 int (*load_shlib)(struct file *);
75974 int (*core_dump)(struct coredump_params *cprm);
75975 + void (*handle_mprotect)(struct vm_area_struct *vma, unsigned long newflags);
75976 + void (*handle_mmap)(struct file *);
75977 unsigned long min_coredump; /* minimal dump size */
75978 -};
75979 +} __do_const;
75980
75981 extern void __register_binfmt(struct linux_binfmt *fmt, int insert);
75982
75983 diff --git a/include/linux/bitops.h b/include/linux/bitops.h
75984 index abc9ca7..e54ee27 100644
75985 --- a/include/linux/bitops.h
75986 +++ b/include/linux/bitops.h
75987 @@ -102,7 +102,7 @@ static inline __u64 ror64(__u64 word, unsigned int shift)
75988 * @word: value to rotate
75989 * @shift: bits to roll
75990 */
75991 -static inline __u32 rol32(__u32 word, unsigned int shift)
75992 +static inline __u32 __intentional_overflow(-1) rol32(__u32 word, unsigned int shift)
75993 {
75994 return (word << shift) | (word >> (32 - shift));
75995 }
75996 @@ -112,7 +112,7 @@ static inline __u32 rol32(__u32 word, unsigned int shift)
75997 * @word: value to rotate
75998 * @shift: bits to roll
75999 */
76000 -static inline __u32 ror32(__u32 word, unsigned int shift)
76001 +static inline __u32 __intentional_overflow(-1) ror32(__u32 word, unsigned int shift)
76002 {
76003 return (word >> shift) | (word << (32 - shift));
76004 }
76005 @@ -168,7 +168,7 @@ static inline __s32 sign_extend32(__u32 value, int index)
76006 return (__s32)(value << shift) >> shift;
76007 }
76008
76009 -static inline unsigned fls_long(unsigned long l)
76010 +static inline unsigned __intentional_overflow(-1) fls_long(unsigned long l)
76011 {
76012 if (sizeof(l) == 4)
76013 return fls(l);
76014 diff --git a/include/linux/blkdev.h b/include/linux/blkdev.h
76015 index 1b135d4..59fc876 100644
76016 --- a/include/linux/blkdev.h
76017 +++ b/include/linux/blkdev.h
76018 @@ -1578,7 +1578,7 @@ struct block_device_operations {
76019 /* this callback is with swap_lock and sometimes page table lock held */
76020 void (*swap_slot_free_notify) (struct block_device *, unsigned long);
76021 struct module *owner;
76022 -};
76023 +} __do_const;
76024
76025 extern int __blkdev_driver_ioctl(struct block_device *, fmode_t, unsigned int,
76026 unsigned long);
76027 diff --git a/include/linux/blktrace_api.h b/include/linux/blktrace_api.h
76028 index afc1343..9735539 100644
76029 --- a/include/linux/blktrace_api.h
76030 +++ b/include/linux/blktrace_api.h
76031 @@ -25,7 +25,7 @@ struct blk_trace {
76032 struct dentry *dropped_file;
76033 struct dentry *msg_file;
76034 struct list_head running_list;
76035 - atomic_t dropped;
76036 + atomic_unchecked_t dropped;
76037 };
76038
76039 extern int blk_trace_ioctl(struct block_device *, unsigned, char __user *);
76040 diff --git a/include/linux/cache.h b/include/linux/cache.h
76041 index 4c57065..40346da 100644
76042 --- a/include/linux/cache.h
76043 +++ b/include/linux/cache.h
76044 @@ -16,6 +16,14 @@
76045 #define __read_mostly
76046 #endif
76047
76048 +#ifndef __read_only
76049 +#ifdef CONFIG_PAX_KERNEXEC
76050 +#error KERNEXEC requires __read_only
76051 +#else
76052 +#define __read_only __read_mostly
76053 +#endif
76054 +#endif
76055 +
76056 #ifndef ____cacheline_aligned
76057 #define ____cacheline_aligned __attribute__((__aligned__(SMP_CACHE_BYTES)))
76058 #endif
76059 diff --git a/include/linux/capability.h b/include/linux/capability.h
76060 index a6ee1f9..e1ca49d 100644
76061 --- a/include/linux/capability.h
76062 +++ b/include/linux/capability.h
76063 @@ -212,8 +212,13 @@ extern bool capable(int cap);
76064 extern bool ns_capable(struct user_namespace *ns, int cap);
76065 extern bool inode_capable(const struct inode *inode, int cap);
76066 extern bool file_ns_capable(const struct file *file, struct user_namespace *ns, int cap);
76067 +extern bool capable_nolog(int cap);
76068 +extern bool ns_capable_nolog(struct user_namespace *ns, int cap);
76069 +extern bool inode_capable_nolog(const struct inode *inode, int cap);
76070
76071 /* audit system wants to get cap info from files as well */
76072 extern int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data *cpu_caps);
76073
76074 +extern int is_privileged_binary(const struct dentry *dentry);
76075 +
76076 #endif /* !_LINUX_CAPABILITY_H */
76077 diff --git a/include/linux/cdrom.h b/include/linux/cdrom.h
76078 index 8609d57..86e4d79 100644
76079 --- a/include/linux/cdrom.h
76080 +++ b/include/linux/cdrom.h
76081 @@ -87,7 +87,6 @@ struct cdrom_device_ops {
76082
76083 /* driver specifications */
76084 const int capability; /* capability flags */
76085 - int n_minors; /* number of active minor devices */
76086 /* handle uniform packets for scsi type devices (scsi,atapi) */
76087 int (*generic_packet) (struct cdrom_device_info *,
76088 struct packet_command *);
76089 diff --git a/include/linux/cleancache.h b/include/linux/cleancache.h
76090 index 4ce9056..86caac6 100644
76091 --- a/include/linux/cleancache.h
76092 +++ b/include/linux/cleancache.h
76093 @@ -31,7 +31,7 @@ struct cleancache_ops {
76094 void (*invalidate_page)(int, struct cleancache_filekey, pgoff_t);
76095 void (*invalidate_inode)(int, struct cleancache_filekey);
76096 void (*invalidate_fs)(int);
76097 -};
76098 +} __no_const;
76099
76100 extern struct cleancache_ops *
76101 cleancache_register_ops(struct cleancache_ops *ops);
76102 diff --git a/include/linux/clk-provider.h b/include/linux/clk-provider.h
76103 index 7e59253..d6e4cae 100644
76104 --- a/include/linux/clk-provider.h
76105 +++ b/include/linux/clk-provider.h
76106 @@ -141,6 +141,7 @@ struct clk_ops {
76107 unsigned long);
76108 void (*init)(struct clk_hw *hw);
76109 };
76110 +typedef struct clk_ops __no_const clk_ops_no_const;
76111
76112 /**
76113 * struct clk_init_data - holds init data that's common to all clocks and is
76114 diff --git a/include/linux/compat.h b/include/linux/compat.h
76115 index 19f6003..90b64f4 100644
76116 --- a/include/linux/compat.h
76117 +++ b/include/linux/compat.h
76118 @@ -313,7 +313,7 @@ compat_sys_get_robust_list(int pid, compat_uptr_t __user *head_ptr,
76119 compat_size_t __user *len_ptr);
76120
76121 asmlinkage long compat_sys_ipc(u32, int, int, u32, compat_uptr_t, u32);
76122 -asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg);
76123 +asmlinkage long compat_sys_shmat(int shmid, compat_uptr_t shmaddr, int shmflg) __intentional_overflow(0);
76124 asmlinkage long compat_sys_semctl(int semid, int semnum, int cmd, int arg);
76125 asmlinkage long compat_sys_msgsnd(int msqid, compat_uptr_t msgp,
76126 compat_ssize_t msgsz, int msgflg);
76127 @@ -420,7 +420,7 @@ extern int compat_ptrace_request(struct task_struct *child,
76128 extern long compat_arch_ptrace(struct task_struct *child, compat_long_t request,
76129 compat_ulong_t addr, compat_ulong_t data);
76130 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
76131 - compat_long_t addr, compat_long_t data);
76132 + compat_ulong_t addr, compat_ulong_t data);
76133
76134 asmlinkage long compat_sys_lookup_dcookie(u32, u32, char __user *, compat_size_t);
76135 /*
76136 diff --git a/include/linux/compiler-gcc4.h b/include/linux/compiler-gcc4.h
76137 index ded4299..ddcbe31 100644
76138 --- a/include/linux/compiler-gcc4.h
76139 +++ b/include/linux/compiler-gcc4.h
76140 @@ -39,9 +39,34 @@
76141 # define __compiletime_warning(message) __attribute__((warning(message)))
76142 # define __compiletime_error(message) __attribute__((error(message)))
76143 #endif /* __CHECKER__ */
76144 +
76145 +#define __alloc_size(...) __attribute((alloc_size(__VA_ARGS__)))
76146 +#define __bos(ptr, arg) __builtin_object_size((ptr), (arg))
76147 +#define __bos0(ptr) __bos((ptr), 0)
76148 +#define __bos1(ptr) __bos((ptr), 1)
76149 #endif /* GCC_VERSION >= 40300 */
76150
76151 #if GCC_VERSION >= 40500
76152 +
76153 +#ifdef RANDSTRUCT_PLUGIN
76154 +#define __randomize_layout __attribute__((randomize_layout))
76155 +#define __no_randomize_layout __attribute__((no_randomize_layout))
76156 +#endif
76157 +
76158 +#ifdef CONSTIFY_PLUGIN
76159 +#define __no_const __attribute__((no_const))
76160 +#define __do_const __attribute__((do_const))
76161 +#endif
76162 +
76163 +#ifdef SIZE_OVERFLOW_PLUGIN
76164 +#define __size_overflow(...) __attribute__((size_overflow(__VA_ARGS__)))
76165 +#define __intentional_overflow(...) __attribute__((intentional_overflow(__VA_ARGS__)))
76166 +#endif
76167 +
76168 +#ifdef LATENT_ENTROPY_PLUGIN
76169 +#define __latent_entropy __attribute__((latent_entropy))
76170 +#endif
76171 +
76172 /*
76173 * Mark a position in code as unreachable. This can be used to
76174 * suppress control flow warnings after asm blocks that transfer
76175 diff --git a/include/linux/compiler.h b/include/linux/compiler.h
76176 index 92669cd..cc564c0 100644
76177 --- a/include/linux/compiler.h
76178 +++ b/include/linux/compiler.h
76179 @@ -5,11 +5,14 @@
76180
76181 #ifdef __CHECKER__
76182 # define __user __attribute__((noderef, address_space(1)))
76183 +# define __force_user __force __user
76184 # define __kernel __attribute__((address_space(0)))
76185 +# define __force_kernel __force __kernel
76186 # define __safe __attribute__((safe))
76187 # define __force __attribute__((force))
76188 # define __nocast __attribute__((nocast))
76189 # define __iomem __attribute__((noderef, address_space(2)))
76190 +# define __force_iomem __force __iomem
76191 # define __must_hold(x) __attribute__((context(x,1,1)))
76192 # define __acquires(x) __attribute__((context(x,0,1)))
76193 # define __releases(x) __attribute__((context(x,1,0)))
76194 @@ -17,20 +20,37 @@
76195 # define __release(x) __context__(x,-1)
76196 # define __cond_lock(x,c) ((c) ? ({ __acquire(x); 1; }) : 0)
76197 # define __percpu __attribute__((noderef, address_space(3)))
76198 +# define __force_percpu __force __percpu
76199 #ifdef CONFIG_SPARSE_RCU_POINTER
76200 # define __rcu __attribute__((noderef, address_space(4)))
76201 +# define __force_rcu __force __rcu
76202 #else
76203 # define __rcu
76204 +# define __force_rcu
76205 #endif
76206 extern void __chk_user_ptr(const volatile void __user *);
76207 extern void __chk_io_ptr(const volatile void __iomem *);
76208 #else
76209 -# define __user
76210 -# define __kernel
76211 +# ifdef CHECKER_PLUGIN
76212 +//# define __user
76213 +//# define __force_user
76214 +//# define __kernel
76215 +//# define __force_kernel
76216 +# else
76217 +# ifdef STRUCTLEAK_PLUGIN
76218 +# define __user __attribute__((user))
76219 +# else
76220 +# define __user
76221 +# endif
76222 +# define __force_user
76223 +# define __kernel
76224 +# define __force_kernel
76225 +# endif
76226 # define __safe
76227 # define __force
76228 # define __nocast
76229 # define __iomem
76230 +# define __force_iomem
76231 # define __chk_user_ptr(x) (void)0
76232 # define __chk_io_ptr(x) (void)0
76233 # define __builtin_warning(x, y...) (1)
76234 @@ -41,7 +61,9 @@ extern void __chk_io_ptr(const volatile void __iomem *);
76235 # define __release(x) (void)0
76236 # define __cond_lock(x,c) (c)
76237 # define __percpu
76238 +# define __force_percpu
76239 # define __rcu
76240 +# define __force_rcu
76241 #endif
76242
76243 /* Indirect macros required for expanded argument pasting, eg. __LINE__. */
76244 @@ -275,6 +297,34 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
76245 # define __attribute_const__ /* unimplemented */
76246 #endif
76247
76248 +#ifndef __randomize_layout
76249 +# define __randomize_layout
76250 +#endif
76251 +
76252 +#ifndef __no_randomize_layout
76253 +# define __no_randomize_layout
76254 +#endif
76255 +
76256 +#ifndef __no_const
76257 +# define __no_const
76258 +#endif
76259 +
76260 +#ifndef __do_const
76261 +# define __do_const
76262 +#endif
76263 +
76264 +#ifndef __size_overflow
76265 +# define __size_overflow(...)
76266 +#endif
76267 +
76268 +#ifndef __intentional_overflow
76269 +# define __intentional_overflow(...)
76270 +#endif
76271 +
76272 +#ifndef __latent_entropy
76273 +# define __latent_entropy
76274 +#endif
76275 +
76276 /*
76277 * Tell gcc if a function is cold. The compiler will assume any path
76278 * directly leading to the call is unlikely.
76279 @@ -284,6 +334,22 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
76280 #define __cold
76281 #endif
76282
76283 +#ifndef __alloc_size
76284 +#define __alloc_size(...)
76285 +#endif
76286 +
76287 +#ifndef __bos
76288 +#define __bos(ptr, arg)
76289 +#endif
76290 +
76291 +#ifndef __bos0
76292 +#define __bos0(ptr)
76293 +#endif
76294 +
76295 +#ifndef __bos1
76296 +#define __bos1(ptr)
76297 +#endif
76298 +
76299 /* Simple shorthand for a section definition */
76300 #ifndef __section
76301 # define __section(S) __attribute__ ((__section__(#S)))
76302 @@ -349,7 +415,8 @@ void ftrace_likely_update(struct ftrace_branch_data *f, int val, int expect);
76303 * use is to mediate communication between process-level code and irq/NMI
76304 * handlers, all running on the same CPU.
76305 */
76306 -#define ACCESS_ONCE(x) (*(volatile typeof(x) *)&(x))
76307 +#define ACCESS_ONCE(x) (*(volatile const typeof(x) *)&(x))
76308 +#define ACCESS_ONCE_RW(x) (*(volatile typeof(x) *)&(x))
76309
76310 /* Ignore/forbid kprobes attach on very low level functions marked by this attribute: */
76311 #ifdef CONFIG_KPROBES
76312 diff --git a/include/linux/completion.h b/include/linux/completion.h
76313 index 5d5aaae..0ea9b84 100644
76314 --- a/include/linux/completion.h
76315 +++ b/include/linux/completion.h
76316 @@ -90,16 +90,16 @@ static inline void reinit_completion(struct completion *x)
76317
76318 extern void wait_for_completion(struct completion *);
76319 extern void wait_for_completion_io(struct completion *);
76320 -extern int wait_for_completion_interruptible(struct completion *x);
76321 -extern int wait_for_completion_killable(struct completion *x);
76322 +extern int wait_for_completion_interruptible(struct completion *x) __intentional_overflow(-1);
76323 +extern int wait_for_completion_killable(struct completion *x) __intentional_overflow(-1);
76324 extern unsigned long wait_for_completion_timeout(struct completion *x,
76325 - unsigned long timeout);
76326 + unsigned long timeout) __intentional_overflow(-1);
76327 extern unsigned long wait_for_completion_io_timeout(struct completion *x,
76328 - unsigned long timeout);
76329 + unsigned long timeout) __intentional_overflow(-1);
76330 extern long wait_for_completion_interruptible_timeout(
76331 - struct completion *x, unsigned long timeout);
76332 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
76333 extern long wait_for_completion_killable_timeout(
76334 - struct completion *x, unsigned long timeout);
76335 + struct completion *x, unsigned long timeout) __intentional_overflow(-1);
76336 extern bool try_wait_for_completion(struct completion *x);
76337 extern bool completion_done(struct completion *x);
76338
76339 diff --git a/include/linux/configfs.h b/include/linux/configfs.h
76340 index 34025df..d94bbbc 100644
76341 --- a/include/linux/configfs.h
76342 +++ b/include/linux/configfs.h
76343 @@ -125,7 +125,7 @@ struct configfs_attribute {
76344 const char *ca_name;
76345 struct module *ca_owner;
76346 umode_t ca_mode;
76347 -};
76348 +} __do_const;
76349
76350 /*
76351 * Users often need to create attribute structures for their configurable
76352 diff --git a/include/linux/cpufreq.h b/include/linux/cpufreq.h
76353 index dc196bb..c55a50f 100644
76354 --- a/include/linux/cpufreq.h
76355 +++ b/include/linux/cpufreq.h
76356 @@ -189,6 +189,7 @@ struct global_attr {
76357 ssize_t (*store)(struct kobject *a, struct attribute *b,
76358 const char *c, size_t count);
76359 };
76360 +typedef struct global_attr __no_const global_attr_no_const;
76361
76362 #define define_one_global_ro(_name) \
76363 static struct global_attr _name = \
76364 @@ -225,7 +226,7 @@ struct cpufreq_driver {
76365 int (*suspend) (struct cpufreq_policy *policy);
76366 int (*resume) (struct cpufreq_policy *policy);
76367 struct freq_attr **attr;
76368 -};
76369 +} __do_const;
76370
76371 /* flags */
76372 #define CPUFREQ_STICKY (1 << 0) /* driver isn't removed even if
76373 diff --git a/include/linux/cpuidle.h b/include/linux/cpuidle.h
76374 index 50fcbb0..9d2dbd9 100644
76375 --- a/include/linux/cpuidle.h
76376 +++ b/include/linux/cpuidle.h
76377 @@ -50,7 +50,8 @@ struct cpuidle_state {
76378 int index);
76379
76380 int (*enter_dead) (struct cpuidle_device *dev, int index);
76381 -};
76382 +} __do_const;
76383 +typedef struct cpuidle_state __no_const cpuidle_state_no_const;
76384
76385 /* Idle State Flags */
76386 #define CPUIDLE_FLAG_TIME_VALID (0x01) /* is residency time measurable? */
76387 @@ -192,7 +193,7 @@ struct cpuidle_governor {
76388 void (*reflect) (struct cpuidle_device *dev, int index);
76389
76390 struct module *owner;
76391 -};
76392 +} __do_const;
76393
76394 #ifdef CONFIG_CPU_IDLE
76395 extern int cpuidle_register_governor(struct cpuidle_governor *gov);
76396 diff --git a/include/linux/cpumask.h b/include/linux/cpumask.h
76397 index d08e4d2..95fad61 100644
76398 --- a/include/linux/cpumask.h
76399 +++ b/include/linux/cpumask.h
76400 @@ -118,17 +118,17 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
76401 }
76402
76403 /* Valid inputs for n are -1 and 0. */
76404 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
76405 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
76406 {
76407 return n+1;
76408 }
76409
76410 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
76411 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
76412 {
76413 return n+1;
76414 }
76415
76416 -static inline unsigned int cpumask_next_and(int n,
76417 +static inline unsigned int __intentional_overflow(-1) cpumask_next_and(int n,
76418 const struct cpumask *srcp,
76419 const struct cpumask *andp)
76420 {
76421 @@ -167,7 +167,7 @@ static inline unsigned int cpumask_first(const struct cpumask *srcp)
76422 *
76423 * Returns >= nr_cpu_ids if no further cpus set.
76424 */
76425 -static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
76426 +static inline unsigned int __intentional_overflow(-1) cpumask_next(int n, const struct cpumask *srcp)
76427 {
76428 /* -1 is a legal arg here. */
76429 if (n != -1)
76430 @@ -182,7 +182,7 @@ static inline unsigned int cpumask_next(int n, const struct cpumask *srcp)
76431 *
76432 * Returns >= nr_cpu_ids if no further cpus unset.
76433 */
76434 -static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
76435 +static inline unsigned int __intentional_overflow(-1) cpumask_next_zero(int n, const struct cpumask *srcp)
76436 {
76437 /* -1 is a legal arg here. */
76438 if (n != -1)
76439 @@ -190,7 +190,7 @@ static inline unsigned int cpumask_next_zero(int n, const struct cpumask *srcp)
76440 return find_next_zero_bit(cpumask_bits(srcp), nr_cpumask_bits, n+1);
76441 }
76442
76443 -int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *);
76444 +int cpumask_next_and(int n, const struct cpumask *, const struct cpumask *) __intentional_overflow(-1);
76445 int cpumask_any_but(const struct cpumask *mask, unsigned int cpu);
76446
76447 /**
76448 diff --git a/include/linux/cred.h b/include/linux/cred.h
76449 index 04421e8..117e17a 100644
76450 --- a/include/linux/cred.h
76451 +++ b/include/linux/cred.h
76452 @@ -35,7 +35,7 @@ struct group_info {
76453 int nblocks;
76454 kgid_t small_block[NGROUPS_SMALL];
76455 kgid_t *blocks[0];
76456 -};
76457 +} __randomize_layout;
76458
76459 /**
76460 * get_group_info - Get a reference to a group info structure
76461 @@ -136,7 +136,7 @@ struct cred {
76462 struct user_namespace *user_ns; /* user_ns the caps and keyrings are relative to. */
76463 struct group_info *group_info; /* supplementary groups for euid/fsgid */
76464 struct rcu_head rcu; /* RCU deletion hook */
76465 -};
76466 +} __randomize_layout;
76467
76468 extern void __put_cred(struct cred *);
76469 extern void exit_creds(struct task_struct *);
76470 @@ -194,6 +194,9 @@ static inline void validate_creds_for_do_exit(struct task_struct *tsk)
76471 static inline void validate_process_creds(void)
76472 {
76473 }
76474 +static inline void validate_task_creds(struct task_struct *task)
76475 +{
76476 +}
76477 #endif
76478
76479 /**
76480 diff --git a/include/linux/crypto.h b/include/linux/crypto.h
76481 index b92eadf..b4ecdc1 100644
76482 --- a/include/linux/crypto.h
76483 +++ b/include/linux/crypto.h
76484 @@ -373,7 +373,7 @@ struct cipher_tfm {
76485 const u8 *key, unsigned int keylen);
76486 void (*cit_encrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
76487 void (*cit_decrypt_one)(struct crypto_tfm *tfm, u8 *dst, const u8 *src);
76488 -};
76489 +} __no_const;
76490
76491 struct hash_tfm {
76492 int (*init)(struct hash_desc *desc);
76493 @@ -394,13 +394,13 @@ struct compress_tfm {
76494 int (*cot_decompress)(struct crypto_tfm *tfm,
76495 const u8 *src, unsigned int slen,
76496 u8 *dst, unsigned int *dlen);
76497 -};
76498 +} __no_const;
76499
76500 struct rng_tfm {
76501 int (*rng_gen_random)(struct crypto_rng *tfm, u8 *rdata,
76502 unsigned int dlen);
76503 int (*rng_reset)(struct crypto_rng *tfm, u8 *seed, unsigned int slen);
76504 -};
76505 +} __no_const;
76506
76507 #define crt_ablkcipher crt_u.ablkcipher
76508 #define crt_aead crt_u.aead
76509 diff --git a/include/linux/ctype.h b/include/linux/ctype.h
76510 index 653589e..4ef254a 100644
76511 --- a/include/linux/ctype.h
76512 +++ b/include/linux/ctype.h
76513 @@ -56,7 +56,7 @@ static inline unsigned char __toupper(unsigned char c)
76514 * Fast implementation of tolower() for internal usage. Do not use in your
76515 * code.
76516 */
76517 -static inline char _tolower(const char c)
76518 +static inline unsigned char _tolower(const unsigned char c)
76519 {
76520 return c | 0x20;
76521 }
76522 diff --git a/include/linux/dcache.h b/include/linux/dcache.h
76523 index bf72e9a..4ca7927 100644
76524 --- a/include/linux/dcache.h
76525 +++ b/include/linux/dcache.h
76526 @@ -133,7 +133,7 @@ struct dentry {
76527 } d_u;
76528 struct list_head d_subdirs; /* our children */
76529 struct hlist_node d_alias; /* inode alias list */
76530 -};
76531 +} __randomize_layout;
76532
76533 /*
76534 * dentry->d_lock spinlock nesting subclasses:
76535 diff --git a/include/linux/decompress/mm.h b/include/linux/decompress/mm.h
76536 index 7925bf0..d5143d2 100644
76537 --- a/include/linux/decompress/mm.h
76538 +++ b/include/linux/decompress/mm.h
76539 @@ -77,7 +77,7 @@ static void free(void *where)
76540 * warnings when not needed (indeed large_malloc / large_free are not
76541 * needed by inflate */
76542
76543 -#define malloc(a) kmalloc(a, GFP_KERNEL)
76544 +#define malloc(a) kmalloc((a), GFP_KERNEL)
76545 #define free(a) kfree(a)
76546
76547 #define large_malloc(a) vmalloc(a)
76548 diff --git a/include/linux/devfreq.h b/include/linux/devfreq.h
76549 index d48dc00..211ee54 100644
76550 --- a/include/linux/devfreq.h
76551 +++ b/include/linux/devfreq.h
76552 @@ -114,7 +114,7 @@ struct devfreq_governor {
76553 int (*get_target_freq)(struct devfreq *this, unsigned long *freq);
76554 int (*event_handler)(struct devfreq *devfreq,
76555 unsigned int event, void *data);
76556 -};
76557 +} __do_const;
76558
76559 /**
76560 * struct devfreq - Device devfreq structure
76561 diff --git a/include/linux/device.h b/include/linux/device.h
76562 index 952b010..d5b7691 100644
76563 --- a/include/linux/device.h
76564 +++ b/include/linux/device.h
76565 @@ -310,7 +310,7 @@ struct subsys_interface {
76566 struct list_head node;
76567 int (*add_dev)(struct device *dev, struct subsys_interface *sif);
76568 int (*remove_dev)(struct device *dev, struct subsys_interface *sif);
76569 -};
76570 +} __do_const;
76571
76572 int subsys_interface_register(struct subsys_interface *sif);
76573 void subsys_interface_unregister(struct subsys_interface *sif);
76574 @@ -506,7 +506,7 @@ struct device_type {
76575 void (*release)(struct device *dev);
76576
76577 const struct dev_pm_ops *pm;
76578 -};
76579 +} __do_const;
76580
76581 /* interface for exporting device attributes */
76582 struct device_attribute {
76583 @@ -516,11 +516,12 @@ struct device_attribute {
76584 ssize_t (*store)(struct device *dev, struct device_attribute *attr,
76585 const char *buf, size_t count);
76586 };
76587 +typedef struct device_attribute __no_const device_attribute_no_const;
76588
76589 struct dev_ext_attribute {
76590 struct device_attribute attr;
76591 void *var;
76592 -};
76593 +} __do_const;
76594
76595 ssize_t device_show_ulong(struct device *dev, struct device_attribute *attr,
76596 char *buf);
76597 diff --git a/include/linux/dma-mapping.h b/include/linux/dma-mapping.h
76598 index fd4aee2..1f28db9 100644
76599 --- a/include/linux/dma-mapping.h
76600 +++ b/include/linux/dma-mapping.h
76601 @@ -54,7 +54,7 @@ struct dma_map_ops {
76602 u64 (*get_required_mask)(struct device *dev);
76603 #endif
76604 int is_phys;
76605 -};
76606 +} __do_const;
76607
76608 #define DMA_BIT_MASK(n) (((n) == 64) ? ~0ULL : ((1ULL<<(n))-1))
76609
76610 diff --git a/include/linux/dmaengine.h b/include/linux/dmaengine.h
76611 index 41cf0c3..f3b771c 100644
76612 --- a/include/linux/dmaengine.h
76613 +++ b/include/linux/dmaengine.h
76614 @@ -1114,9 +1114,9 @@ struct dma_pinned_list {
76615 struct dma_pinned_list *dma_pin_iovec_pages(struct iovec *iov, size_t len);
76616 void dma_unpin_iovec_pages(struct dma_pinned_list* pinned_list);
76617
76618 -dma_cookie_t dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
76619 +dma_cookie_t __intentional_overflow(0) dma_memcpy_to_iovec(struct dma_chan *chan, struct iovec *iov,
76620 struct dma_pinned_list *pinned_list, unsigned char *kdata, size_t len);
76621 -dma_cookie_t dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
76622 +dma_cookie_t __intentional_overflow(0) dma_memcpy_pg_to_iovec(struct dma_chan *chan, struct iovec *iov,
76623 struct dma_pinned_list *pinned_list, struct page *page,
76624 unsigned int offset, size_t len);
76625
76626 diff --git a/include/linux/efi.h b/include/linux/efi.h
76627 index 11ce678..7b8c69c 100644
76628 --- a/include/linux/efi.h
76629 +++ b/include/linux/efi.h
76630 @@ -764,6 +764,7 @@ struct efivar_operations {
76631 efi_set_variable_t *set_variable;
76632 efi_query_variable_store_t *query_variable_store;
76633 };
76634 +typedef struct efivar_operations __no_const efivar_operations_no_const;
76635
76636 struct efivars {
76637 /*
76638 diff --git a/include/linux/elf.h b/include/linux/elf.h
76639 index 67a5fa7..b817372 100644
76640 --- a/include/linux/elf.h
76641 +++ b/include/linux/elf.h
76642 @@ -24,6 +24,7 @@ extern Elf32_Dyn _DYNAMIC [];
76643 #define elf_note elf32_note
76644 #define elf_addr_t Elf32_Off
76645 #define Elf_Half Elf32_Half
76646 +#define elf_dyn Elf32_Dyn
76647
76648 #else
76649
76650 @@ -34,6 +35,7 @@ extern Elf64_Dyn _DYNAMIC [];
76651 #define elf_note elf64_note
76652 #define elf_addr_t Elf64_Off
76653 #define Elf_Half Elf64_Half
76654 +#define elf_dyn Elf64_Dyn
76655
76656 #endif
76657
76658 diff --git a/include/linux/err.h b/include/linux/err.h
76659 index 15f92e0..e825a8e 100644
76660 --- a/include/linux/err.h
76661 +++ b/include/linux/err.h
76662 @@ -19,12 +19,12 @@
76663
76664 #define IS_ERR_VALUE(x) unlikely((x) >= (unsigned long)-MAX_ERRNO)
76665
76666 -static inline void * __must_check ERR_PTR(long error)
76667 +static inline void * __must_check __intentional_overflow(-1) ERR_PTR(long error)
76668 {
76669 return (void *) error;
76670 }
76671
76672 -static inline long __must_check PTR_ERR(__force const void *ptr)
76673 +static inline long __must_check __intentional_overflow(-1) PTR_ERR(__force const void *ptr)
76674 {
76675 return (long) ptr;
76676 }
76677 diff --git a/include/linux/extcon.h b/include/linux/extcon.h
76678 index 21c59af..6057a03 100644
76679 --- a/include/linux/extcon.h
76680 +++ b/include/linux/extcon.h
76681 @@ -135,7 +135,7 @@ struct extcon_dev {
76682 /* /sys/class/extcon/.../mutually_exclusive/... */
76683 struct attribute_group attr_g_muex;
76684 struct attribute **attrs_muex;
76685 - struct device_attribute *d_attrs_muex;
76686 + device_attribute_no_const *d_attrs_muex;
76687 };
76688
76689 /**
76690 diff --git a/include/linux/fb.h b/include/linux/fb.h
76691 index 70c4836..ff3daec 100644
76692 --- a/include/linux/fb.h
76693 +++ b/include/linux/fb.h
76694 @@ -304,7 +304,7 @@ struct fb_ops {
76695 /* called at KDB enter and leave time to prepare the console */
76696 int (*fb_debug_enter)(struct fb_info *info);
76697 int (*fb_debug_leave)(struct fb_info *info);
76698 -};
76699 +} __do_const;
76700
76701 #ifdef CONFIG_FB_TILEBLITTING
76702 #define FB_TILE_CURSOR_NONE 0
76703 diff --git a/include/linux/fdtable.h b/include/linux/fdtable.h
76704 index 085197b..0fa6f0b 100644
76705 --- a/include/linux/fdtable.h
76706 +++ b/include/linux/fdtable.h
76707 @@ -95,7 +95,7 @@ struct files_struct *get_files_struct(struct task_struct *);
76708 void put_files_struct(struct files_struct *fs);
76709 void reset_files_struct(struct files_struct *);
76710 int unshare_files(struct files_struct **);
76711 -struct files_struct *dup_fd(struct files_struct *, int *);
76712 +struct files_struct *dup_fd(struct files_struct *, int *) __latent_entropy;
76713 void do_close_on_exec(struct files_struct *);
76714 int iterate_fd(struct files_struct *, unsigned,
76715 int (*)(const void *, struct file *, unsigned),
76716 diff --git a/include/linux/frontswap.h b/include/linux/frontswap.h
76717 index 8293262..2b3b8bd 100644
76718 --- a/include/linux/frontswap.h
76719 +++ b/include/linux/frontswap.h
76720 @@ -11,7 +11,7 @@ struct frontswap_ops {
76721 int (*load)(unsigned, pgoff_t, struct page *);
76722 void (*invalidate_page)(unsigned, pgoff_t);
76723 void (*invalidate_area)(unsigned);
76724 -};
76725 +} __no_const;
76726
76727 extern bool frontswap_enabled;
76728 extern struct frontswap_ops *
76729 diff --git a/include/linux/fs.h b/include/linux/fs.h
76730 index 121f11f..0f2a863 100644
76731 --- a/include/linux/fs.h
76732 +++ b/include/linux/fs.h
76733 @@ -423,7 +423,7 @@ struct address_space {
76734 spinlock_t private_lock; /* for use by the address_space */
76735 struct list_head private_list; /* ditto */
76736 void *private_data; /* ditto */
76737 -} __attribute__((aligned(sizeof(long))));
76738 +} __attribute__((aligned(sizeof(long)))) __randomize_layout;
76739 /*
76740 * On most architectures that alignment is already the case; but
76741 * must be enforced here for CRIS, to let the least significant bit
76742 @@ -466,7 +466,7 @@ struct block_device {
76743 int bd_fsfreeze_count;
76744 /* Mutex for freeze */
76745 struct mutex bd_fsfreeze_mutex;
76746 -};
76747 +} __randomize_layout;
76748
76749 /*
76750 * Radix-tree tags, for tagging dirty and writeback pages within the pagecache
76751 @@ -610,7 +610,7 @@ struct inode {
76752 atomic_t i_readcount; /* struct files open RO */
76753 #endif
76754 void *i_private; /* fs or device private pointer */
76755 -};
76756 +} __randomize_layout;
76757
76758 static inline int inode_unhashed(struct inode *inode)
76759 {
76760 @@ -808,7 +808,7 @@ struct file {
76761 #ifdef CONFIG_DEBUG_WRITECOUNT
76762 unsigned long f_mnt_write_state;
76763 #endif
76764 -};
76765 +} __randomize_layout;
76766
76767 struct file_handle {
76768 __u32 handle_bytes;
76769 @@ -978,7 +978,7 @@ struct file_lock {
76770 int state; /* state of grant or error if -ve */
76771 } afs;
76772 } fl_u;
76773 -};
76774 +} __randomize_layout;
76775
76776 /* The following constant reflects the upper bound of the file/locking space */
76777 #ifndef OFFSET_MAX
76778 @@ -1325,7 +1325,7 @@ struct super_block {
76779 struct list_lru s_dentry_lru ____cacheline_aligned_in_smp;
76780 struct list_lru s_inode_lru ____cacheline_aligned_in_smp;
76781 struct rcu_head rcu;
76782 -};
76783 +} __randomize_layout;
76784
76785 extern struct timespec current_fs_time(struct super_block *sb);
76786
76787 @@ -1547,7 +1547,8 @@ struct file_operations {
76788 long (*fallocate)(struct file *file, int mode, loff_t offset,
76789 loff_t len);
76790 int (*show_fdinfo)(struct seq_file *m, struct file *f);
76791 -};
76792 +} __do_const __randomize_layout;
76793 +typedef struct file_operations __no_const file_operations_no_const;
76794
76795 struct inode_operations {
76796 struct dentry * (*lookup) (struct inode *,struct dentry *, unsigned int);
76797 @@ -2808,4 +2809,14 @@ static inline bool dir_relax(struct inode *inode)
76798 return !IS_DEADDIR(inode);
76799 }
76800
76801 +static inline bool is_sidechannel_device(const struct inode *inode)
76802 +{
76803 +#ifdef CONFIG_GRKERNSEC_DEVICE_SIDECHANNEL
76804 + umode_t mode = inode->i_mode;
76805 + return ((S_ISCHR(mode) || S_ISBLK(mode)) && (mode & (S_IROTH | S_IWOTH)));
76806 +#else
76807 + return false;
76808 +#endif
76809 +}
76810 +
76811 #endif /* _LINUX_FS_H */
76812 diff --git a/include/linux/fs_struct.h b/include/linux/fs_struct.h
76813 index 0efc3e6..fd23610 100644
76814 --- a/include/linux/fs_struct.h
76815 +++ b/include/linux/fs_struct.h
76816 @@ -6,13 +6,13 @@
76817 #include <linux/seqlock.h>
76818
76819 struct fs_struct {
76820 - int users;
76821 + atomic_t users;
76822 spinlock_t lock;
76823 seqcount_t seq;
76824 int umask;
76825 int in_exec;
76826 struct path root, pwd;
76827 -};
76828 +} __randomize_layout;
76829
76830 extern struct kmem_cache *fs_cachep;
76831
76832 diff --git a/include/linux/fscache-cache.h b/include/linux/fscache-cache.h
76833 index 7714849..a4a5c7a 100644
76834 --- a/include/linux/fscache-cache.h
76835 +++ b/include/linux/fscache-cache.h
76836 @@ -113,7 +113,7 @@ struct fscache_operation {
76837 fscache_operation_release_t release;
76838 };
76839
76840 -extern atomic_t fscache_op_debug_id;
76841 +extern atomic_unchecked_t fscache_op_debug_id;
76842 extern void fscache_op_work_func(struct work_struct *work);
76843
76844 extern void fscache_enqueue_operation(struct fscache_operation *);
76845 @@ -135,7 +135,7 @@ static inline void fscache_operation_init(struct fscache_operation *op,
76846 INIT_WORK(&op->work, fscache_op_work_func);
76847 atomic_set(&op->usage, 1);
76848 op->state = FSCACHE_OP_ST_INITIALISED;
76849 - op->debug_id = atomic_inc_return(&fscache_op_debug_id);
76850 + op->debug_id = atomic_inc_return_unchecked(&fscache_op_debug_id);
76851 op->processor = processor;
76852 op->release = release;
76853 INIT_LIST_HEAD(&op->pend_link);
76854 diff --git a/include/linux/fscache.h b/include/linux/fscache.h
76855 index 115bb81..e7b812b 100644
76856 --- a/include/linux/fscache.h
76857 +++ b/include/linux/fscache.h
76858 @@ -152,7 +152,7 @@ struct fscache_cookie_def {
76859 * - this is mandatory for any object that may have data
76860 */
76861 void (*now_uncached)(void *cookie_netfs_data);
76862 -};
76863 +} __do_const;
76864
76865 /*
76866 * fscache cached network filesystem type
76867 diff --git a/include/linux/fsnotify.h b/include/linux/fsnotify.h
76868 index 1c804b0..1432c2b 100644
76869 --- a/include/linux/fsnotify.h
76870 +++ b/include/linux/fsnotify.h
76871 @@ -195,6 +195,9 @@ static inline void fsnotify_access(struct file *file)
76872 struct inode *inode = file_inode(file);
76873 __u32 mask = FS_ACCESS;
76874
76875 + if (is_sidechannel_device(inode))
76876 + return;
76877 +
76878 if (S_ISDIR(inode->i_mode))
76879 mask |= FS_ISDIR;
76880
76881 @@ -213,6 +216,9 @@ static inline void fsnotify_modify(struct file *file)
76882 struct inode *inode = file_inode(file);
76883 __u32 mask = FS_MODIFY;
76884
76885 + if (is_sidechannel_device(inode))
76886 + return;
76887 +
76888 if (S_ISDIR(inode->i_mode))
76889 mask |= FS_ISDIR;
76890
76891 @@ -315,7 +321,7 @@ static inline void fsnotify_change(struct dentry *dentry, unsigned int ia_valid)
76892 */
76893 static inline const unsigned char *fsnotify_oldname_init(const unsigned char *name)
76894 {
76895 - return kstrdup(name, GFP_KERNEL);
76896 + return (const unsigned char *)kstrdup((const char *)name, GFP_KERNEL);
76897 }
76898
76899 /*
76900 diff --git a/include/linux/genhd.h b/include/linux/genhd.h
76901 index 9f3c275..8bdff5d 100644
76902 --- a/include/linux/genhd.h
76903 +++ b/include/linux/genhd.h
76904 @@ -194,7 +194,7 @@ struct gendisk {
76905 struct kobject *slave_dir;
76906
76907 struct timer_rand_state *random;
76908 - atomic_t sync_io; /* RAID */
76909 + atomic_unchecked_t sync_io; /* RAID */
76910 struct disk_events *ev;
76911 #ifdef CONFIG_BLK_DEV_INTEGRITY
76912 struct blk_integrity *integrity;
76913 @@ -435,7 +435,7 @@ extern void disk_flush_events(struct gendisk *disk, unsigned int mask);
76914 extern unsigned int disk_clear_events(struct gendisk *disk, unsigned int mask);
76915
76916 /* drivers/char/random.c */
76917 -extern void add_disk_randomness(struct gendisk *disk);
76918 +extern void add_disk_randomness(struct gendisk *disk) __latent_entropy;
76919 extern void rand_initialize_disk(struct gendisk *disk);
76920
76921 static inline sector_t get_start_sect(struct block_device *bdev)
76922 diff --git a/include/linux/genl_magic_func.h b/include/linux/genl_magic_func.h
76923 index c0894dd..2fbf10c 100644
76924 --- a/include/linux/genl_magic_func.h
76925 +++ b/include/linux/genl_magic_func.h
76926 @@ -246,7 +246,7 @@ const char *CONCAT_(GENL_MAGIC_FAMILY, _genl_cmd_to_str)(__u8 cmd)
76927 },
76928
76929 #define ZZZ_genl_ops CONCAT_(GENL_MAGIC_FAMILY, _genl_ops)
76930 -static struct genl_ops ZZZ_genl_ops[] __read_mostly = {
76931 +static struct genl_ops ZZZ_genl_ops[] = {
76932 #include GENL_MAGIC_INCLUDE_FILE
76933 };
76934
76935 diff --git a/include/linux/gfp.h b/include/linux/gfp.h
76936 index 9b4dd49..61fd41d 100644
76937 --- a/include/linux/gfp.h
76938 +++ b/include/linux/gfp.h
76939 @@ -35,6 +35,13 @@ struct vm_area_struct;
76940 #define ___GFP_NO_KSWAPD 0x400000u
76941 #define ___GFP_OTHER_NODE 0x800000u
76942 #define ___GFP_WRITE 0x1000000u
76943 +
76944 +#ifdef CONFIG_PAX_USERCOPY_SLABS
76945 +#define ___GFP_USERCOPY 0x2000000u
76946 +#else
76947 +#define ___GFP_USERCOPY 0
76948 +#endif
76949 +
76950 /* If the above are modified, __GFP_BITS_SHIFT may need updating */
76951
76952 /*
76953 @@ -92,6 +99,7 @@ struct vm_area_struct;
76954 #define __GFP_OTHER_NODE ((__force gfp_t)___GFP_OTHER_NODE) /* On behalf of other node */
76955 #define __GFP_KMEMCG ((__force gfp_t)___GFP_KMEMCG) /* Allocation comes from a memcg-accounted resource */
76956 #define __GFP_WRITE ((__force gfp_t)___GFP_WRITE) /* Allocator intends to dirty page */
76957 +#define __GFP_USERCOPY ((__force gfp_t)___GFP_USERCOPY)/* Allocator intends to copy page to/from userland */
76958
76959 /*
76960 * This may seem redundant, but it's a way of annotating false positives vs.
76961 @@ -99,7 +107,7 @@ struct vm_area_struct;
76962 */
76963 #define __GFP_NOTRACK_FALSE_POSITIVE (__GFP_NOTRACK)
76964
76965 -#define __GFP_BITS_SHIFT 25 /* Room for N __GFP_FOO bits */
76966 +#define __GFP_BITS_SHIFT 26 /* Room for N __GFP_FOO bits */
76967 #define __GFP_BITS_MASK ((__force gfp_t)((1 << __GFP_BITS_SHIFT) - 1))
76968
76969 /* This equals 0, but use constants in case they ever change */
76970 @@ -153,6 +161,8 @@ struct vm_area_struct;
76971 /* 4GB DMA on some platforms */
76972 #define GFP_DMA32 __GFP_DMA32
76973
76974 +#define GFP_USERCOPY __GFP_USERCOPY
76975 +
76976 /* Convert GFP flags to their corresponding migrate type */
76977 static inline int allocflags_to_migratetype(gfp_t gfp_flags)
76978 {
76979 diff --git a/include/linux/gracl.h b/include/linux/gracl.h
76980 new file mode 100644
76981 index 0000000..edb2cb6
76982 --- /dev/null
76983 +++ b/include/linux/gracl.h
76984 @@ -0,0 +1,340 @@
76985 +#ifndef GR_ACL_H
76986 +#define GR_ACL_H
76987 +
76988 +#include <linux/grdefs.h>
76989 +#include <linux/resource.h>
76990 +#include <linux/capability.h>
76991 +#include <linux/dcache.h>
76992 +#include <asm/resource.h>
76993 +
76994 +/* Major status information */
76995 +
76996 +#define GR_VERSION "grsecurity 3.0"
76997 +#define GRSECURITY_VERSION 0x3000
76998 +
76999 +enum {
77000 + GR_SHUTDOWN = 0,
77001 + GR_ENABLE = 1,
77002 + GR_SPROLE = 2,
77003 + GR_OLDRELOAD = 3,
77004 + GR_SEGVMOD = 4,
77005 + GR_STATUS = 5,
77006 + GR_UNSPROLE = 6,
77007 + GR_PASSSET = 7,
77008 + GR_SPROLEPAM = 8,
77009 + GR_RELOAD = 9,
77010 +};
77011 +
77012 +/* Password setup definitions
77013 + * kernel/grhash.c */
77014 +enum {
77015 + GR_PW_LEN = 128,
77016 + GR_SALT_LEN = 16,
77017 + GR_SHA_LEN = 32,
77018 +};
77019 +
77020 +enum {
77021 + GR_SPROLE_LEN = 64,
77022 +};
77023 +
77024 +enum {
77025 + GR_NO_GLOB = 0,
77026 + GR_REG_GLOB,
77027 + GR_CREATE_GLOB
77028 +};
77029 +
77030 +#define GR_NLIMITS 32
77031 +
77032 +/* Begin Data Structures */
77033 +
77034 +struct sprole_pw {
77035 + unsigned char *rolename;
77036 + unsigned char salt[GR_SALT_LEN];
77037 + unsigned char sum[GR_SHA_LEN]; /* 256-bit SHA hash of the password */
77038 +};
77039 +
77040 +struct name_entry {
77041 + __u32 key;
77042 + ino_t inode;
77043 + dev_t device;
77044 + char *name;
77045 + __u16 len;
77046 + __u8 deleted;
77047 + struct name_entry *prev;
77048 + struct name_entry *next;
77049 +};
77050 +
77051 +struct inodev_entry {
77052 + struct name_entry *nentry;
77053 + struct inodev_entry *prev;
77054 + struct inodev_entry *next;
77055 +};
77056 +
77057 +struct acl_role_db {
77058 + struct acl_role_label **r_hash;
77059 + __u32 r_size;
77060 +};
77061 +
77062 +struct inodev_db {
77063 + struct inodev_entry **i_hash;
77064 + __u32 i_size;
77065 +};
77066 +
77067 +struct name_db {
77068 + struct name_entry **n_hash;
77069 + __u32 n_size;
77070 +};
77071 +
77072 +struct crash_uid {
77073 + uid_t uid;
77074 + unsigned long expires;
77075 +};
77076 +
77077 +struct gr_hash_struct {
77078 + void **table;
77079 + void **nametable;
77080 + void *first;
77081 + __u32 table_size;
77082 + __u32 used_size;
77083 + int type;
77084 +};
77085 +
77086 +/* Userspace Grsecurity ACL data structures */
77087 +
77088 +struct acl_subject_label {
77089 + char *filename;
77090 + ino_t inode;
77091 + dev_t device;
77092 + __u32 mode;
77093 + kernel_cap_t cap_mask;
77094 + kernel_cap_t cap_lower;
77095 + kernel_cap_t cap_invert_audit;
77096 +
77097 + struct rlimit res[GR_NLIMITS];
77098 + __u32 resmask;
77099 +
77100 + __u8 user_trans_type;
77101 + __u8 group_trans_type;
77102 + uid_t *user_transitions;
77103 + gid_t *group_transitions;
77104 + __u16 user_trans_num;
77105 + __u16 group_trans_num;
77106 +
77107 + __u32 sock_families[2];
77108 + __u32 ip_proto[8];
77109 + __u32 ip_type;
77110 + struct acl_ip_label **ips;
77111 + __u32 ip_num;
77112 + __u32 inaddr_any_override;
77113 +
77114 + __u32 crashes;
77115 + unsigned long expires;
77116 +
77117 + struct acl_subject_label *parent_subject;
77118 + struct gr_hash_struct *hash;
77119 + struct acl_subject_label *prev;
77120 + struct acl_subject_label *next;
77121 +
77122 + struct acl_object_label **obj_hash;
77123 + __u32 obj_hash_size;
77124 + __u16 pax_flags;
77125 +};
77126 +
77127 +struct role_allowed_ip {
77128 + __u32 addr;
77129 + __u32 netmask;
77130 +
77131 + struct role_allowed_ip *prev;
77132 + struct role_allowed_ip *next;
77133 +};
77134 +
77135 +struct role_transition {
77136 + char *rolename;
77137 +
77138 + struct role_transition *prev;
77139 + struct role_transition *next;
77140 +};
77141 +
77142 +struct acl_role_label {
77143 + char *rolename;
77144 + uid_t uidgid;
77145 + __u16 roletype;
77146 +
77147 + __u16 auth_attempts;
77148 + unsigned long expires;
77149 +
77150 + struct acl_subject_label *root_label;
77151 + struct gr_hash_struct *hash;
77152 +
77153 + struct acl_role_label *prev;
77154 + struct acl_role_label *next;
77155 +
77156 + struct role_transition *transitions;
77157 + struct role_allowed_ip *allowed_ips;
77158 + uid_t *domain_children;
77159 + __u16 domain_child_num;
77160 +
77161 + umode_t umask;
77162 +
77163 + struct acl_subject_label **subj_hash;
77164 + __u32 subj_hash_size;
77165 +};
77166 +
77167 +struct user_acl_role_db {
77168 + struct acl_role_label **r_table;
77169 + __u32 num_pointers; /* Number of allocations to track */
77170 + __u32 num_roles; /* Number of roles */
77171 + __u32 num_domain_children; /* Number of domain children */
77172 + __u32 num_subjects; /* Number of subjects */
77173 + __u32 num_objects; /* Number of objects */
77174 +};
77175 +
77176 +struct acl_object_label {
77177 + char *filename;
77178 + ino_t inode;
77179 + dev_t device;
77180 + __u32 mode;
77181 +
77182 + struct acl_subject_label *nested;
77183 + struct acl_object_label *globbed;
77184 +
77185 + /* next two structures not used */
77186 +
77187 + struct acl_object_label *prev;
77188 + struct acl_object_label *next;
77189 +};
77190 +
77191 +struct acl_ip_label {
77192 + char *iface;
77193 + __u32 addr;
77194 + __u32 netmask;
77195 + __u16 low, high;
77196 + __u8 mode;
77197 + __u32 type;
77198 + __u32 proto[8];
77199 +
77200 + /* next two structures not used */
77201 +
77202 + struct acl_ip_label *prev;
77203 + struct acl_ip_label *next;
77204 +};
77205 +
77206 +struct gr_arg {
77207 + struct user_acl_role_db role_db;
77208 + unsigned char pw[GR_PW_LEN];
77209 + unsigned char salt[GR_SALT_LEN];
77210 + unsigned char sum[GR_SHA_LEN];
77211 + unsigned char sp_role[GR_SPROLE_LEN];
77212 + struct sprole_pw *sprole_pws;
77213 + dev_t segv_device;
77214 + ino_t segv_inode;
77215 + uid_t segv_uid;
77216 + __u16 num_sprole_pws;
77217 + __u16 mode;
77218 +};
77219 +
77220 +struct gr_arg_wrapper {
77221 + struct gr_arg *arg;
77222 + __u32 version;
77223 + __u32 size;
77224 +};
77225 +
77226 +struct subject_map {
77227 + struct acl_subject_label *user;
77228 + struct acl_subject_label *kernel;
77229 + struct subject_map *prev;
77230 + struct subject_map *next;
77231 +};
77232 +
77233 +struct acl_subj_map_db {
77234 + struct subject_map **s_hash;
77235 + __u32 s_size;
77236 +};
77237 +
77238 +struct gr_policy_state {
77239 + struct sprole_pw **acl_special_roles;
77240 + __u16 num_sprole_pws;
77241 + struct acl_role_label *kernel_role;
77242 + struct acl_role_label *role_list;
77243 + struct acl_role_label *default_role;
77244 + struct acl_role_db acl_role_set;
77245 + struct acl_subj_map_db subj_map_set;
77246 + struct name_db name_set;
77247 + struct inodev_db inodev_set;
77248 +};
77249 +
77250 +struct gr_alloc_state {
77251 + unsigned long alloc_stack_next;
77252 + unsigned long alloc_stack_size;
77253 + void **alloc_stack;
77254 +};
77255 +
77256 +struct gr_reload_state {
77257 + struct gr_policy_state oldpolicy;
77258 + struct gr_alloc_state oldalloc;
77259 + struct gr_policy_state newpolicy;
77260 + struct gr_alloc_state newalloc;
77261 + struct gr_policy_state *oldpolicy_ptr;
77262 + struct gr_alloc_state *oldalloc_ptr;
77263 + unsigned char oldmode;
77264 +};
77265 +
77266 +/* End Data Structures Section */
77267 +
77268 +/* Hash functions generated by empirical testing by Brad Spengler
77269 + Makes good use of the low bits of the inode. Generally 0-1 times
77270 + in loop for successful match. 0-3 for unsuccessful match.
77271 + Shift/add algorithm with modulus of table size and an XOR*/
77272 +
77273 +static __inline__ unsigned int
77274 +gr_rhash(const uid_t uid, const __u16 type, const unsigned int sz)
77275 +{
77276 + return ((((uid + type) << (16 + type)) ^ uid) % sz);
77277 +}
77278 +
77279 + static __inline__ unsigned int
77280 +gr_shash(const struct acl_subject_label *userp, const unsigned int sz)
77281 +{
77282 + return ((const unsigned long)userp % sz);
77283 +}
77284 +
77285 +static __inline__ unsigned int
77286 +gr_fhash(const ino_t ino, const dev_t dev, const unsigned int sz)
77287 +{
77288 + return (((ino + dev) ^ ((ino << 13) + (ino << 23) + (dev << 9))) % sz);
77289 +}
77290 +
77291 +static __inline__ unsigned int
77292 +gr_nhash(const char *name, const __u16 len, const unsigned int sz)
77293 +{
77294 + return full_name_hash((const unsigned char *)name, len) % sz;
77295 +}
77296 +
77297 +#define FOR_EACH_SUBJECT_START(role,subj,iter) \
77298 + subj = NULL; \
77299 + iter = 0; \
77300 + while (iter < role->subj_hash_size) { \
77301 + if (subj == NULL) \
77302 + subj = role->subj_hash[iter]; \
77303 + if (subj == NULL) { \
77304 + iter++; \
77305 + continue; \
77306 + }
77307 +
77308 +#define FOR_EACH_SUBJECT_END(subj,iter) \
77309 + subj = subj->next; \
77310 + if (subj == NULL) \
77311 + iter++; \
77312 + }
77313 +
77314 +
77315 +#define FOR_EACH_NESTED_SUBJECT_START(role,subj) \
77316 + subj = role->hash->first; \
77317 + while (subj != NULL) {
77318 +
77319 +#define FOR_EACH_NESTED_SUBJECT_END(subj) \
77320 + subj = subj->next; \
77321 + }
77322 +
77323 +#endif
77324 +
77325 diff --git a/include/linux/gracl_compat.h b/include/linux/gracl_compat.h
77326 new file mode 100644
77327 index 0000000..33ebd1f
77328 --- /dev/null
77329 +++ b/include/linux/gracl_compat.h
77330 @@ -0,0 +1,156 @@
77331 +#ifndef GR_ACL_COMPAT_H
77332 +#define GR_ACL_COMPAT_H
77333 +
77334 +#include <linux/resource.h>
77335 +#include <asm/resource.h>
77336 +
77337 +struct sprole_pw_compat {
77338 + compat_uptr_t rolename;
77339 + unsigned char salt[GR_SALT_LEN];
77340 + unsigned char sum[GR_SHA_LEN];
77341 +};
77342 +
77343 +struct gr_hash_struct_compat {
77344 + compat_uptr_t table;
77345 + compat_uptr_t nametable;
77346 + compat_uptr_t first;
77347 + __u32 table_size;
77348 + __u32 used_size;
77349 + int type;
77350 +};
77351 +
77352 +struct acl_subject_label_compat {
77353 + compat_uptr_t filename;
77354 + compat_ino_t inode;
77355 + __u32 device;
77356 + __u32 mode;
77357 + kernel_cap_t cap_mask;
77358 + kernel_cap_t cap_lower;
77359 + kernel_cap_t cap_invert_audit;
77360 +
77361 + struct compat_rlimit res[GR_NLIMITS];
77362 + __u32 resmask;
77363 +
77364 + __u8 user_trans_type;
77365 + __u8 group_trans_type;
77366 + compat_uptr_t user_transitions;
77367 + compat_uptr_t group_transitions;
77368 + __u16 user_trans_num;
77369 + __u16 group_trans_num;
77370 +
77371 + __u32 sock_families[2];
77372 + __u32 ip_proto[8];
77373 + __u32 ip_type;
77374 + compat_uptr_t ips;
77375 + __u32 ip_num;
77376 + __u32 inaddr_any_override;
77377 +
77378 + __u32 crashes;
77379 + compat_ulong_t expires;
77380 +
77381 + compat_uptr_t parent_subject;
77382 + compat_uptr_t hash;
77383 + compat_uptr_t prev;
77384 + compat_uptr_t next;
77385 +
77386 + compat_uptr_t obj_hash;
77387 + __u32 obj_hash_size;
77388 + __u16 pax_flags;
77389 +};
77390 +
77391 +struct role_allowed_ip_compat {
77392 + __u32 addr;
77393 + __u32 netmask;
77394 +
77395 + compat_uptr_t prev;
77396 + compat_uptr_t next;
77397 +};
77398 +
77399 +struct role_transition_compat {
77400 + compat_uptr_t rolename;
77401 +
77402 + compat_uptr_t prev;
77403 + compat_uptr_t next;
77404 +};
77405 +
77406 +struct acl_role_label_compat {
77407 + compat_uptr_t rolename;
77408 + uid_t uidgid;
77409 + __u16 roletype;
77410 +
77411 + __u16 auth_attempts;
77412 + compat_ulong_t expires;
77413 +
77414 + compat_uptr_t root_label;
77415 + compat_uptr_t hash;
77416 +
77417 + compat_uptr_t prev;
77418 + compat_uptr_t next;
77419 +
77420 + compat_uptr_t transitions;
77421 + compat_uptr_t allowed_ips;
77422 + compat_uptr_t domain_children;
77423 + __u16 domain_child_num;
77424 +
77425 + umode_t umask;
77426 +
77427 + compat_uptr_t subj_hash;
77428 + __u32 subj_hash_size;
77429 +};
77430 +
77431 +struct user_acl_role_db_compat {
77432 + compat_uptr_t r_table;
77433 + __u32 num_pointers;
77434 + __u32 num_roles;
77435 + __u32 num_domain_children;
77436 + __u32 num_subjects;
77437 + __u32 num_objects;
77438 +};
77439 +
77440 +struct acl_object_label_compat {
77441 + compat_uptr_t filename;
77442 + compat_ino_t inode;
77443 + __u32 device;
77444 + __u32 mode;
77445 +
77446 + compat_uptr_t nested;
77447 + compat_uptr_t globbed;
77448 +
77449 + compat_uptr_t prev;
77450 + compat_uptr_t next;
77451 +};
77452 +
77453 +struct acl_ip_label_compat {
77454 + compat_uptr_t iface;
77455 + __u32 addr;
77456 + __u32 netmask;
77457 + __u16 low, high;
77458 + __u8 mode;
77459 + __u32 type;
77460 + __u32 proto[8];
77461 +
77462 + compat_uptr_t prev;
77463 + compat_uptr_t next;
77464 +};
77465 +
77466 +struct gr_arg_compat {
77467 + struct user_acl_role_db_compat role_db;
77468 + unsigned char pw[GR_PW_LEN];
77469 + unsigned char salt[GR_SALT_LEN];
77470 + unsigned char sum[GR_SHA_LEN];
77471 + unsigned char sp_role[GR_SPROLE_LEN];
77472 + compat_uptr_t sprole_pws;
77473 + __u32 segv_device;
77474 + compat_ino_t segv_inode;
77475 + uid_t segv_uid;
77476 + __u16 num_sprole_pws;
77477 + __u16 mode;
77478 +};
77479 +
77480 +struct gr_arg_wrapper_compat {
77481 + compat_uptr_t arg;
77482 + __u32 version;
77483 + __u32 size;
77484 +};
77485 +
77486 +#endif
77487 diff --git a/include/linux/gralloc.h b/include/linux/gralloc.h
77488 new file mode 100644
77489 index 0000000..323ecf2
77490 --- /dev/null
77491 +++ b/include/linux/gralloc.h
77492 @@ -0,0 +1,9 @@
77493 +#ifndef __GRALLOC_H
77494 +#define __GRALLOC_H
77495 +
77496 +void acl_free_all(void);
77497 +int acl_alloc_stack_init(unsigned long size);
77498 +void *acl_alloc(unsigned long len);
77499 +void *acl_alloc_num(unsigned long num, unsigned long len);
77500 +
77501 +#endif
77502 diff --git a/include/linux/grdefs.h b/include/linux/grdefs.h
77503 new file mode 100644
77504 index 0000000..be66033
77505 --- /dev/null
77506 +++ b/include/linux/grdefs.h
77507 @@ -0,0 +1,140 @@
77508 +#ifndef GRDEFS_H
77509 +#define GRDEFS_H
77510 +
77511 +/* Begin grsecurity status declarations */
77512 +
77513 +enum {
77514 + GR_READY = 0x01,
77515 + GR_STATUS_INIT = 0x00 // disabled state
77516 +};
77517 +
77518 +/* Begin ACL declarations */
77519 +
77520 +/* Role flags */
77521 +
77522 +enum {
77523 + GR_ROLE_USER = 0x0001,
77524 + GR_ROLE_GROUP = 0x0002,
77525 + GR_ROLE_DEFAULT = 0x0004,
77526 + GR_ROLE_SPECIAL = 0x0008,
77527 + GR_ROLE_AUTH = 0x0010,
77528 + GR_ROLE_NOPW = 0x0020,
77529 + GR_ROLE_GOD = 0x0040,
77530 + GR_ROLE_LEARN = 0x0080,
77531 + GR_ROLE_TPE = 0x0100,
77532 + GR_ROLE_DOMAIN = 0x0200,
77533 + GR_ROLE_PAM = 0x0400,
77534 + GR_ROLE_PERSIST = 0x0800
77535 +};
77536 +
77537 +/* ACL Subject and Object mode flags */
77538 +enum {
77539 + GR_DELETED = 0x80000000
77540 +};
77541 +
77542 +/* ACL Object-only mode flags */
77543 +enum {
77544 + GR_READ = 0x00000001,
77545 + GR_APPEND = 0x00000002,
77546 + GR_WRITE = 0x00000004,
77547 + GR_EXEC = 0x00000008,
77548 + GR_FIND = 0x00000010,
77549 + GR_INHERIT = 0x00000020,
77550 + GR_SETID = 0x00000040,
77551 + GR_CREATE = 0x00000080,
77552 + GR_DELETE = 0x00000100,
77553 + GR_LINK = 0x00000200,
77554 + GR_AUDIT_READ = 0x00000400,
77555 + GR_AUDIT_APPEND = 0x00000800,
77556 + GR_AUDIT_WRITE = 0x00001000,
77557 + GR_AUDIT_EXEC = 0x00002000,
77558 + GR_AUDIT_FIND = 0x00004000,
77559 + GR_AUDIT_INHERIT= 0x00008000,
77560 + GR_AUDIT_SETID = 0x00010000,
77561 + GR_AUDIT_CREATE = 0x00020000,
77562 + GR_AUDIT_DELETE = 0x00040000,
77563 + GR_AUDIT_LINK = 0x00080000,
77564 + GR_PTRACERD = 0x00100000,
77565 + GR_NOPTRACE = 0x00200000,
77566 + GR_SUPPRESS = 0x00400000,
77567 + GR_NOLEARN = 0x00800000,
77568 + GR_INIT_TRANSFER= 0x01000000
77569 +};
77570 +
77571 +#define GR_AUDITS (GR_AUDIT_READ | GR_AUDIT_WRITE | GR_AUDIT_APPEND | GR_AUDIT_EXEC | \
77572 + GR_AUDIT_FIND | GR_AUDIT_INHERIT | GR_AUDIT_SETID | \
77573 + GR_AUDIT_CREATE | GR_AUDIT_DELETE | GR_AUDIT_LINK)
77574 +
77575 +/* ACL subject-only mode flags */
77576 +enum {
77577 + GR_KILL = 0x00000001,
77578 + GR_VIEW = 0x00000002,
77579 + GR_PROTECTED = 0x00000004,
77580 + GR_LEARN = 0x00000008,
77581 + GR_OVERRIDE = 0x00000010,
77582 + /* just a placeholder, this mode is only used in userspace */
77583 + GR_DUMMY = 0x00000020,
77584 + GR_PROTSHM = 0x00000040,
77585 + GR_KILLPROC = 0x00000080,
77586 + GR_KILLIPPROC = 0x00000100,
77587 + /* just a placeholder, this mode is only used in userspace */
77588 + GR_NOTROJAN = 0x00000200,
77589 + GR_PROTPROCFD = 0x00000400,
77590 + GR_PROCACCT = 0x00000800,
77591 + GR_RELAXPTRACE = 0x00001000,
77592 + //GR_NESTED = 0x00002000,
77593 + GR_INHERITLEARN = 0x00004000,
77594 + GR_PROCFIND = 0x00008000,
77595 + GR_POVERRIDE = 0x00010000,
77596 + GR_KERNELAUTH = 0x00020000,
77597 + GR_ATSECURE = 0x00040000,
77598 + GR_SHMEXEC = 0x00080000
77599 +};
77600 +
77601 +enum {
77602 + GR_PAX_ENABLE_SEGMEXEC = 0x0001,
77603 + GR_PAX_ENABLE_PAGEEXEC = 0x0002,
77604 + GR_PAX_ENABLE_MPROTECT = 0x0004,
77605 + GR_PAX_ENABLE_RANDMMAP = 0x0008,
77606 + GR_PAX_ENABLE_EMUTRAMP = 0x0010,
77607 + GR_PAX_DISABLE_SEGMEXEC = 0x0100,
77608 + GR_PAX_DISABLE_PAGEEXEC = 0x0200,
77609 + GR_PAX_DISABLE_MPROTECT = 0x0400,
77610 + GR_PAX_DISABLE_RANDMMAP = 0x0800,
77611 + GR_PAX_DISABLE_EMUTRAMP = 0x1000,
77612 +};
77613 +
77614 +enum {
77615 + GR_ID_USER = 0x01,
77616 + GR_ID_GROUP = 0x02,
77617 +};
77618 +
77619 +enum {
77620 + GR_ID_ALLOW = 0x01,
77621 + GR_ID_DENY = 0x02,
77622 +};
77623 +
77624 +#define GR_CRASH_RES 31
77625 +#define GR_UIDTABLE_MAX 500
77626 +
77627 +/* begin resource learning section */
77628 +enum {
77629 + GR_RLIM_CPU_BUMP = 60,
77630 + GR_RLIM_FSIZE_BUMP = 50000,
77631 + GR_RLIM_DATA_BUMP = 10000,
77632 + GR_RLIM_STACK_BUMP = 1000,
77633 + GR_RLIM_CORE_BUMP = 10000,
77634 + GR_RLIM_RSS_BUMP = 500000,
77635 + GR_RLIM_NPROC_BUMP = 1,
77636 + GR_RLIM_NOFILE_BUMP = 5,
77637 + GR_RLIM_MEMLOCK_BUMP = 50000,
77638 + GR_RLIM_AS_BUMP = 500000,
77639 + GR_RLIM_LOCKS_BUMP = 2,
77640 + GR_RLIM_SIGPENDING_BUMP = 5,
77641 + GR_RLIM_MSGQUEUE_BUMP = 10000,
77642 + GR_RLIM_NICE_BUMP = 1,
77643 + GR_RLIM_RTPRIO_BUMP = 1,
77644 + GR_RLIM_RTTIME_BUMP = 1000000
77645 +};
77646 +
77647 +#endif
77648 diff --git a/include/linux/grinternal.h b/include/linux/grinternal.h
77649 new file mode 100644
77650 index 0000000..d25522e
77651 --- /dev/null
77652 +++ b/include/linux/grinternal.h
77653 @@ -0,0 +1,229 @@
77654 +#ifndef __GRINTERNAL_H
77655 +#define __GRINTERNAL_H
77656 +
77657 +#ifdef CONFIG_GRKERNSEC
77658 +
77659 +#include <linux/fs.h>
77660 +#include <linux/mnt_namespace.h>
77661 +#include <linux/nsproxy.h>
77662 +#include <linux/gracl.h>
77663 +#include <linux/grdefs.h>
77664 +#include <linux/grmsg.h>
77665 +
77666 +void gr_add_learn_entry(const char *fmt, ...)
77667 + __attribute__ ((format (printf, 1, 2)));
77668 +__u32 gr_search_file(const struct dentry *dentry, const __u32 mode,
77669 + const struct vfsmount *mnt);
77670 +__u32 gr_check_create(const struct dentry *new_dentry,
77671 + const struct dentry *parent,
77672 + const struct vfsmount *mnt, const __u32 mode);
77673 +int gr_check_protected_task(const struct task_struct *task);
77674 +__u32 to_gr_audit(const __u32 reqmode);
77675 +int gr_set_acls(const int type);
77676 +int gr_acl_is_enabled(void);
77677 +char gr_roletype_to_char(void);
77678 +
77679 +void gr_handle_alertkill(struct task_struct *task);
77680 +char *gr_to_filename(const struct dentry *dentry,
77681 + const struct vfsmount *mnt);
77682 +char *gr_to_filename1(const struct dentry *dentry,
77683 + const struct vfsmount *mnt);
77684 +char *gr_to_filename2(const struct dentry *dentry,
77685 + const struct vfsmount *mnt);
77686 +char *gr_to_filename3(const struct dentry *dentry,
77687 + const struct vfsmount *mnt);
77688 +
77689 +extern int grsec_enable_ptrace_readexec;
77690 +extern int grsec_enable_harden_ptrace;
77691 +extern int grsec_enable_link;
77692 +extern int grsec_enable_fifo;
77693 +extern int grsec_enable_execve;
77694 +extern int grsec_enable_shm;
77695 +extern int grsec_enable_execlog;
77696 +extern int grsec_enable_signal;
77697 +extern int grsec_enable_audit_ptrace;
77698 +extern int grsec_enable_forkfail;
77699 +extern int grsec_enable_time;
77700 +extern int grsec_enable_rofs;
77701 +extern int grsec_deny_new_usb;
77702 +extern int grsec_enable_chroot_shmat;
77703 +extern int grsec_enable_chroot_mount;
77704 +extern int grsec_enable_chroot_double;
77705 +extern int grsec_enable_chroot_pivot;
77706 +extern int grsec_enable_chroot_chdir;
77707 +extern int grsec_enable_chroot_chmod;
77708 +extern int grsec_enable_chroot_mknod;
77709 +extern int grsec_enable_chroot_fchdir;
77710 +extern int grsec_enable_chroot_nice;
77711 +extern int grsec_enable_chroot_execlog;
77712 +extern int grsec_enable_chroot_caps;
77713 +extern int grsec_enable_chroot_sysctl;
77714 +extern int grsec_enable_chroot_unix;
77715 +extern int grsec_enable_symlinkown;
77716 +extern kgid_t grsec_symlinkown_gid;
77717 +extern int grsec_enable_tpe;
77718 +extern kgid_t grsec_tpe_gid;
77719 +extern int grsec_enable_tpe_all;
77720 +extern int grsec_enable_tpe_invert;
77721 +extern int grsec_enable_socket_all;
77722 +extern kgid_t grsec_socket_all_gid;
77723 +extern int grsec_enable_socket_client;
77724 +extern kgid_t grsec_socket_client_gid;
77725 +extern int grsec_enable_socket_server;
77726 +extern kgid_t grsec_socket_server_gid;
77727 +extern kgid_t grsec_audit_gid;
77728 +extern int grsec_enable_group;
77729 +extern int grsec_enable_log_rwxmaps;
77730 +extern int grsec_enable_mount;
77731 +extern int grsec_enable_chdir;
77732 +extern int grsec_resource_logging;
77733 +extern int grsec_enable_blackhole;
77734 +extern int grsec_lastack_retries;
77735 +extern int grsec_enable_brute;
77736 +extern int grsec_enable_harden_ipc;
77737 +extern int grsec_lock;
77738 +
77739 +extern spinlock_t grsec_alert_lock;
77740 +extern unsigned long grsec_alert_wtime;
77741 +extern unsigned long grsec_alert_fyet;
77742 +
77743 +extern spinlock_t grsec_audit_lock;
77744 +
77745 +extern rwlock_t grsec_exec_file_lock;
77746 +
77747 +#define gr_task_fullpath(tsk) ((tsk)->exec_file ? \
77748 + gr_to_filename2((tsk)->exec_file->f_path.dentry, \
77749 + (tsk)->exec_file->f_path.mnt) : "/")
77750 +
77751 +#define gr_parent_task_fullpath(tsk) ((tsk)->real_parent->exec_file ? \
77752 + gr_to_filename3((tsk)->real_parent->exec_file->f_path.dentry, \
77753 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
77754 +
77755 +#define gr_task_fullpath0(tsk) ((tsk)->exec_file ? \
77756 + gr_to_filename((tsk)->exec_file->f_path.dentry, \
77757 + (tsk)->exec_file->f_path.mnt) : "/")
77758 +
77759 +#define gr_parent_task_fullpath0(tsk) ((tsk)->real_parent->exec_file ? \
77760 + gr_to_filename1((tsk)->real_parent->exec_file->f_path.dentry, \
77761 + (tsk)->real_parent->exec_file->f_path.mnt) : "/")
77762 +
77763 +#define proc_is_chrooted(tsk_a) ((tsk_a)->gr_is_chrooted)
77764 +
77765 +#define have_same_root(tsk_a,tsk_b) ((tsk_a)->gr_chroot_dentry == (tsk_b)->gr_chroot_dentry)
77766 +
77767 +static inline bool gr_is_same_file(const struct file *file1, const struct file *file2)
77768 +{
77769 + if (file1 && file2) {
77770 + const struct inode *inode1 = file1->f_path.dentry->d_inode;
77771 + const struct inode *inode2 = file2->f_path.dentry->d_inode;
77772 + if (inode1->i_ino == inode2->i_ino && inode1->i_sb->s_dev == inode2->i_sb->s_dev)
77773 + return true;
77774 + }
77775 +
77776 + return false;
77777 +}
77778 +
77779 +#define GR_CHROOT_CAPS {{ \
77780 + CAP_TO_MASK(CAP_LINUX_IMMUTABLE) | CAP_TO_MASK(CAP_NET_ADMIN) | \
77781 + CAP_TO_MASK(CAP_SYS_MODULE) | CAP_TO_MASK(CAP_SYS_RAWIO) | \
77782 + CAP_TO_MASK(CAP_SYS_PACCT) | CAP_TO_MASK(CAP_SYS_ADMIN) | \
77783 + CAP_TO_MASK(CAP_SYS_BOOT) | CAP_TO_MASK(CAP_SYS_TIME) | \
77784 + CAP_TO_MASK(CAP_NET_RAW) | CAP_TO_MASK(CAP_SYS_TTY_CONFIG) | \
77785 + CAP_TO_MASK(CAP_IPC_OWNER) | CAP_TO_MASK(CAP_SETFCAP), \
77786 + CAP_TO_MASK(CAP_SYSLOG) | CAP_TO_MASK(CAP_MAC_ADMIN) }}
77787 +
77788 +#define security_learn(normal_msg,args...) \
77789 +({ \
77790 + read_lock(&grsec_exec_file_lock); \
77791 + gr_add_learn_entry(normal_msg "\n", ## args); \
77792 + read_unlock(&grsec_exec_file_lock); \
77793 +})
77794 +
77795 +enum {
77796 + GR_DO_AUDIT,
77797 + GR_DONT_AUDIT,
77798 + /* used for non-audit messages that we shouldn't kill the task on */
77799 + GR_DONT_AUDIT_GOOD
77800 +};
77801 +
77802 +enum {
77803 + GR_TTYSNIFF,
77804 + GR_RBAC,
77805 + GR_RBAC_STR,
77806 + GR_STR_RBAC,
77807 + GR_RBAC_MODE2,
77808 + GR_RBAC_MODE3,
77809 + GR_FILENAME,
77810 + GR_SYSCTL_HIDDEN,
77811 + GR_NOARGS,
77812 + GR_ONE_INT,
77813 + GR_ONE_INT_TWO_STR,
77814 + GR_ONE_STR,
77815 + GR_STR_INT,
77816 + GR_TWO_STR_INT,
77817 + GR_TWO_INT,
77818 + GR_TWO_U64,
77819 + GR_THREE_INT,
77820 + GR_FIVE_INT_TWO_STR,
77821 + GR_TWO_STR,
77822 + GR_THREE_STR,
77823 + GR_FOUR_STR,
77824 + GR_STR_FILENAME,
77825 + GR_FILENAME_STR,
77826 + GR_FILENAME_TWO_INT,
77827 + GR_FILENAME_TWO_INT_STR,
77828 + GR_TEXTREL,
77829 + GR_PTRACE,
77830 + GR_RESOURCE,
77831 + GR_CAP,
77832 + GR_SIG,
77833 + GR_SIG2,
77834 + GR_CRASH1,
77835 + GR_CRASH2,
77836 + GR_PSACCT,
77837 + GR_RWXMAP,
77838 + GR_RWXMAPVMA
77839 +};
77840 +
77841 +#define gr_log_hidden_sysctl(audit, msg, str) gr_log_varargs(audit, msg, GR_SYSCTL_HIDDEN, str)
77842 +#define gr_log_ttysniff(audit, msg, task) gr_log_varargs(audit, msg, GR_TTYSNIFF, task)
77843 +#define gr_log_fs_rbac_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_RBAC, dentry, mnt)
77844 +#define gr_log_fs_rbac_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_RBAC_STR, dentry, mnt, str)
77845 +#define gr_log_fs_str_rbac(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_RBAC, str, dentry, mnt)
77846 +#define gr_log_fs_rbac_mode2(audit, msg, dentry, mnt, str1, str2) gr_log_varargs(audit, msg, GR_RBAC_MODE2, dentry, mnt, str1, str2)
77847 +#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)
77848 +#define gr_log_fs_generic(audit, msg, dentry, mnt) gr_log_varargs(audit, msg, GR_FILENAME, dentry, mnt)
77849 +#define gr_log_noargs(audit, msg) gr_log_varargs(audit, msg, GR_NOARGS)
77850 +#define gr_log_int(audit, msg, num) gr_log_varargs(audit, msg, GR_ONE_INT, num)
77851 +#define gr_log_int_str2(audit, msg, num, str1, str2) gr_log_varargs(audit, msg, GR_ONE_INT_TWO_STR, num, str1, str2)
77852 +#define gr_log_str(audit, msg, str) gr_log_varargs(audit, msg, GR_ONE_STR, str)
77853 +#define gr_log_str_int(audit, msg, str, num) gr_log_varargs(audit, msg, GR_STR_INT, str, num)
77854 +#define gr_log_int_int(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_INT, num1, num2)
77855 +#define gr_log_two_u64(audit, msg, num1, num2) gr_log_varargs(audit, msg, GR_TWO_U64, num1, num2)
77856 +#define gr_log_int3(audit, msg, num1, num2, num3) gr_log_varargs(audit, msg, GR_THREE_INT, num1, num2, num3)
77857 +#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)
77858 +#define gr_log_str_str(audit, msg, str1, str2) gr_log_varargs(audit, msg, GR_TWO_STR, str1, str2)
77859 +#define gr_log_str2_int(audit, msg, str1, str2, num) gr_log_varargs(audit, msg, GR_TWO_STR_INT, str1, str2, num)
77860 +#define gr_log_str3(audit, msg, str1, str2, str3) gr_log_varargs(audit, msg, GR_THREE_STR, str1, str2, str3)
77861 +#define gr_log_str4(audit, msg, str1, str2, str3, str4) gr_log_varargs(audit, msg, GR_FOUR_STR, str1, str2, str3, str4)
77862 +#define gr_log_str_fs(audit, msg, str, dentry, mnt) gr_log_varargs(audit, msg, GR_STR_FILENAME, str, dentry, mnt)
77863 +#define gr_log_fs_str(audit, msg, dentry, mnt, str) gr_log_varargs(audit, msg, GR_FILENAME_STR, dentry, mnt, str)
77864 +#define gr_log_fs_int2(audit, msg, dentry, mnt, num1, num2) gr_log_varargs(audit, msg, GR_FILENAME_TWO_INT, dentry, mnt, num1, num2)
77865 +#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)
77866 +#define gr_log_textrel_ulong_ulong(audit, msg, file, ulong1, ulong2) gr_log_varargs(audit, msg, GR_TEXTREL, file, ulong1, ulong2)
77867 +#define gr_log_ptrace(audit, msg, task) gr_log_varargs(audit, msg, GR_PTRACE, task)
77868 +#define gr_log_res_ulong2_str(audit, msg, task, ulong1, str, ulong2) gr_log_varargs(audit, msg, GR_RESOURCE, task, ulong1, str, ulong2)
77869 +#define gr_log_cap(audit, msg, task, str) gr_log_varargs(audit, msg, GR_CAP, task, str)
77870 +#define gr_log_sig_addr(audit, msg, str, addr) gr_log_varargs(audit, msg, GR_SIG, str, addr)
77871 +#define gr_log_sig_task(audit, msg, task, num) gr_log_varargs(audit, msg, GR_SIG2, task, num)
77872 +#define gr_log_crash1(audit, msg, task, ulong) gr_log_varargs(audit, msg, GR_CRASH1, task, ulong)
77873 +#define gr_log_crash2(audit, msg, task, ulong1) gr_log_varargs(audit, msg, GR_CRASH2, task, ulong1)
77874 +#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)
77875 +#define gr_log_rwxmap(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAP, str)
77876 +#define gr_log_rwxmap_vma(audit, msg, str) gr_log_varargs(audit, msg, GR_RWXMAPVMA, str)
77877 +
77878 +void gr_log_varargs(int audit, const char *msg, int argtypes, ...);
77879 +
77880 +#endif
77881 +
77882 +#endif
77883 diff --git a/include/linux/grmsg.h b/include/linux/grmsg.h
77884 new file mode 100644
77885 index 0000000..ba93581
77886 --- /dev/null
77887 +++ b/include/linux/grmsg.h
77888 @@ -0,0 +1,116 @@
77889 +#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"
77890 +#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"
77891 +#define GR_PTRACE_ACL_MSG "denied ptrace of %.950s(%.16s:%d) by "
77892 +#define GR_STOPMOD_MSG "denied modification of module state by "
77893 +#define GR_ROFS_BLOCKWRITE_MSG "denied write to block device %.950s by "
77894 +#define GR_ROFS_MOUNT_MSG "denied writable mount of %.950s by "
77895 +#define GR_IOPERM_MSG "denied use of ioperm() by "
77896 +#define GR_IOPL_MSG "denied use of iopl() by "
77897 +#define GR_SHMAT_ACL_MSG "denied attach of shared memory of UID %u, PID %d, ID %u by "
77898 +#define GR_UNIX_CHROOT_MSG "denied connect() to abstract AF_UNIX socket outside of chroot by "
77899 +#define GR_SHMAT_CHROOT_MSG "denied attach of shared memory outside of chroot by "
77900 +#define GR_MEM_READWRITE_MSG "denied access of range %Lx -> %Lx in /dev/mem by "
77901 +#define GR_SYMLINK_MSG "not following symlink %.950s owned by %d.%d by "
77902 +#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"
77903 +#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"
77904 +#define GR_HIDDEN_ACL_MSG "%s access to hidden file %.950s by "
77905 +#define GR_OPEN_ACL_MSG "%s open of %.950s for%s%s by "
77906 +#define GR_CREATE_ACL_MSG "%s create of %.950s for%s%s by "
77907 +#define GR_FIFO_MSG "denied writing FIFO %.950s of %d.%d by "
77908 +#define GR_MKNOD_CHROOT_MSG "denied mknod of %.950s from chroot by "
77909 +#define GR_MKNOD_ACL_MSG "%s mknod of %.950s by "
77910 +#define GR_UNIXCONNECT_ACL_MSG "%s connect() to the unix domain socket %.950s by "
77911 +#define GR_TTYSNIFF_ACL_MSG "terminal being sniffed by IP:%pI4 %.480s[%.16s:%d], parent %.480s[%.16s:%d] against "
77912 +#define GR_MKDIR_ACL_MSG "%s mkdir of %.950s by "
77913 +#define GR_RMDIR_ACL_MSG "%s rmdir of %.950s by "
77914 +#define GR_UNLINK_ACL_MSG "%s unlink of %.950s by "
77915 +#define GR_SYMLINK_ACL_MSG "%s symlink from %.480s to %.480s by "
77916 +#define GR_HARDLINK_MSG "denied hardlink of %.930s (owned by %d.%d) to %.30s for "
77917 +#define GR_LINK_ACL_MSG "%s link of %.480s to %.480s by "
77918 +#define GR_INHERIT_ACL_MSG "successful inherit of %.480s's ACL for %.480s by "
77919 +#define GR_RENAME_ACL_MSG "%s rename of %.480s to %.480s by "
77920 +#define GR_UNSAFESHARE_EXEC_ACL_MSG "denied exec with cloned fs of %.950s by "
77921 +#define GR_PTRACE_EXEC_ACL_MSG "denied ptrace of %.950s by "
77922 +#define GR_EXEC_ACL_MSG "%s execution of %.950s by "
77923 +#define GR_EXEC_TPE_MSG "denied untrusted exec (due to %.70s) of %.950s by "
77924 +#define GR_SEGVSTART_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning uid %u from login for %lu seconds"
77925 +#define GR_SEGVNOSUID_ACL_MSG "possible exploit bruteforcing on " DEFAULTSECMSG " banning execution for %lu seconds"
77926 +#define GR_MOUNT_CHROOT_MSG "denied mount of %.256s as %.930s from chroot by "
77927 +#define GR_PIVOT_CHROOT_MSG "denied pivot_root from chroot by "
77928 +#define GR_TRUNCATE_ACL_MSG "%s truncate of %.950s by "
77929 +#define GR_ATIME_ACL_MSG "%s access time change of %.950s by "
77930 +#define GR_ACCESS_ACL_MSG "%s access of %.950s for%s%s%s by "
77931 +#define GR_CHROOT_CHROOT_MSG "denied double chroot to %.950s by "
77932 +#define GR_CHMOD_CHROOT_MSG "denied chmod +s of %.950s by "
77933 +#define GR_CHMOD_ACL_MSG "%s chmod of %.950s by "
77934 +#define GR_CHROOT_FCHDIR_MSG "denied fchdir outside of chroot to %.950s by "
77935 +#define GR_CHOWN_ACL_MSG "%s chown of %.950s by "
77936 +#define GR_SETXATTR_ACL_MSG "%s setting extended attribute of %.950s by "
77937 +#define GR_REMOVEXATTR_ACL_MSG "%s removing extended attribute of %.950s by "
77938 +#define GR_WRITLIB_ACL_MSG "denied load of writable library %.950s by "
77939 +#define GR_INITF_ACL_MSG "init_variables() failed %s by "
77940 +#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"
77941 +#define GR_DEV_ACL_MSG "/dev/grsec: %d bytes sent %d required, being fed garbage by "
77942 +#define GR_SHUTS_ACL_MSG "shutdown auth success for "
77943 +#define GR_SHUTF_ACL_MSG "shutdown auth failure for "
77944 +#define GR_SHUTI_ACL_MSG "ignoring shutdown for disabled RBAC system for "
77945 +#define GR_SEGVMODS_ACL_MSG "segvmod auth success for "
77946 +#define GR_SEGVMODF_ACL_MSG "segvmod auth failure for "
77947 +#define GR_SEGVMODI_ACL_MSG "ignoring segvmod for disabled RBAC system for "
77948 +#define GR_ENABLE_ACL_MSG "%s RBAC system loaded by "
77949 +#define GR_ENABLEF_ACL_MSG "unable to load %s for "
77950 +#define GR_RELOADI_ACL_MSG "ignoring reload request for disabled RBAC system"
77951 +#define GR_RELOAD_ACL_MSG "%s RBAC system reloaded by "
77952 +#define GR_RELOADF_ACL_MSG "failed reload of %s for "
77953 +#define GR_SPROLEI_ACL_MSG "ignoring change to special role for disabled RBAC system for "
77954 +#define GR_SPROLES_ACL_MSG "successful change to special role %s (id %d) by "
77955 +#define GR_SPROLEL_ACL_MSG "special role %s (id %d) exited by "
77956 +#define GR_SPROLEF_ACL_MSG "special role %s failure for "
77957 +#define GR_UNSPROLEI_ACL_MSG "ignoring unauth of special role for disabled RBAC system for "
77958 +#define GR_UNSPROLES_ACL_MSG "successful unauth of special role %s (id %d) by "
77959 +#define GR_INVMODE_ACL_MSG "invalid mode %d by "
77960 +#define GR_PRIORITY_CHROOT_MSG "denied priority change of process (%.16s:%d) by "
77961 +#define GR_FAILFORK_MSG "failed fork with errno %s by "
77962 +#define GR_NICE_CHROOT_MSG "denied priority change by "
77963 +#define GR_UNISIGLOG_MSG "%.32s occurred at %p in "
77964 +#define GR_DUALSIGLOG_MSG "signal %d sent to " DEFAULTSECMSG " by "
77965 +#define GR_SIG_ACL_MSG "denied send of signal %d to protected task " DEFAULTSECMSG " by "
77966 +#define GR_SYSCTL_MSG "denied modification of grsecurity sysctl value : %.32s by "
77967 +#define GR_SYSCTL_ACL_MSG "%s sysctl of %.950s for%s%s by "
77968 +#define GR_TIME_MSG "time set by "
77969 +#define GR_DEFACL_MSG "fatal: unable to find subject for (%.16s:%d), loaded by "
77970 +#define GR_MMAP_ACL_MSG "%s executable mmap of %.950s by "
77971 +#define GR_MPROTECT_ACL_MSG "%s executable mprotect of %.950s by "
77972 +#define GR_SOCK_MSG "denied socket(%.16s,%.16s,%.16s) by "
77973 +#define GR_SOCK_NOINET_MSG "denied socket(%.16s,%.16s,%d) by "
77974 +#define GR_BIND_MSG "denied bind() by "
77975 +#define GR_CONNECT_MSG "denied connect() by "
77976 +#define GR_BIND_ACL_MSG "denied bind() to %pI4 port %u sock type %.16s protocol %.16s by "
77977 +#define GR_CONNECT_ACL_MSG "denied connect() to %pI4 port %u sock type %.16s protocol %.16s by "
77978 +#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"
77979 +#define GR_EXEC_CHROOT_MSG "exec of %.980s within chroot by process "
77980 +#define GR_CAP_ACL_MSG "use of %s denied for "
77981 +#define GR_CAP_CHROOT_MSG "use of %s in chroot denied for "
77982 +#define GR_CAP_ACL_MSG2 "use of %s permitted for "
77983 +#define GR_USRCHANGE_ACL_MSG "change to uid %u denied for "
77984 +#define GR_GRPCHANGE_ACL_MSG "change to gid %u denied for "
77985 +#define GR_REMOUNT_AUDIT_MSG "remount of %.256s by "
77986 +#define GR_UNMOUNT_AUDIT_MSG "unmount of %.256s by "
77987 +#define GR_MOUNT_AUDIT_MSG "mount of %.256s to %.256s by "
77988 +#define GR_CHDIR_AUDIT_MSG "chdir to %.980s by "
77989 +#define GR_EXEC_AUDIT_MSG "exec of %.930s (%.128s) by "
77990 +#define GR_RESOURCE_MSG "denied resource overstep by requesting %lu for %.16s against limit %lu for "
77991 +#define GR_RWXMMAP_MSG "denied RWX mmap of %.950s by "
77992 +#define GR_RWXMPROTECT_MSG "denied RWX mprotect of %.950s by "
77993 +#define GR_TEXTREL_AUDIT_MSG "denied text relocation in %.950s, VMA:0x%08lx 0x%08lx by "
77994 +#define GR_PTGNUSTACK_MSG "denied marking stack executable as requested by PT_GNU_STACK marking in %.950s by "
77995 +#define GR_VM86_MSG "denied use of vm86 by "
77996 +#define GR_PTRACE_AUDIT_MSG "process %.950s(%.16s:%d) attached to via ptrace by "
77997 +#define GR_PTRACE_READEXEC_MSG "denied ptrace of unreadable binary %.950s by "
77998 +#define GR_INIT_TRANSFER_MSG "persistent special role transferred privilege to init by "
77999 +#define GR_BADPROCPID_MSG "denied read of sensitive /proc/pid/%s entry via fd passed across exec by "
78000 +#define GR_SYMLINKOWNER_MSG "denied following symlink %.950s since symlink owner %u does not match target owner %u, by "
78001 +#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 "
78002 +#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 "
78003 +#define GR_IPC_DENIED_MSG "denied %s of overly-permissive IPC object with creator uid %u by "
78004 +#define GR_MSRWRITE_MSG "denied write to CPU MSR by "
78005 diff --git a/include/linux/grsecurity.h b/include/linux/grsecurity.h
78006 new file mode 100644
78007 index 0000000..8108301
78008 --- /dev/null
78009 +++ b/include/linux/grsecurity.h
78010 @@ -0,0 +1,246 @@
78011 +#ifndef GR_SECURITY_H
78012 +#define GR_SECURITY_H
78013 +#include <linux/fs.h>
78014 +#include <linux/fs_struct.h>
78015 +#include <linux/binfmts.h>
78016 +#include <linux/gracl.h>
78017 +
78018 +/* notify of brain-dead configs */
78019 +#if defined(CONFIG_GRKERNSEC_PROC_USER) && defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
78020 +#error "CONFIG_GRKERNSEC_PROC_USER and CONFIG_GRKERNSEC_PROC_USERGROUP cannot both be enabled."
78021 +#endif
78022 +#if defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_PAGEEXEC) && !defined(CONFIG_PAX_SEGMEXEC) && !defined(CONFIG_PAX_KERNEXEC)
78023 +#error "CONFIG_PAX_NOEXEC enabled, but PAGEEXEC, SEGMEXEC, and KERNEXEC are disabled."
78024 +#endif
78025 +#if defined(CONFIG_PAX_ASLR) && !defined(CONFIG_PAX_RANDKSTACK) && !defined(CONFIG_PAX_RANDUSTACK) && !defined(CONFIG_PAX_RANDMMAP)
78026 +#error "CONFIG_PAX_ASLR enabled, but RANDKSTACK, RANDUSTACK, and RANDMMAP are disabled."
78027 +#endif
78028 +#if defined(CONFIG_PAX) && !defined(CONFIG_PAX_NOEXEC) && !defined(CONFIG_PAX_ASLR)
78029 +#error "CONFIG_PAX enabled, but no PaX options are enabled."
78030 +#endif
78031 +
78032 +int gr_handle_new_usb(void);
78033 +
78034 +void gr_handle_brute_attach(int dumpable);
78035 +void gr_handle_brute_check(void);
78036 +void gr_handle_kernel_exploit(void);
78037 +
78038 +char gr_roletype_to_char(void);
78039 +
78040 +int gr_acl_enable_at_secure(void);
78041 +
78042 +int gr_check_user_change(kuid_t real, kuid_t effective, kuid_t fs);
78043 +int gr_check_group_change(kgid_t real, kgid_t effective, kgid_t fs);
78044 +
78045 +void gr_del_task_from_ip_table(struct task_struct *p);
78046 +
78047 +int gr_pid_is_chrooted(struct task_struct *p);
78048 +int gr_handle_chroot_fowner(struct pid *pid, enum pid_type type);
78049 +int gr_handle_chroot_nice(void);
78050 +int gr_handle_chroot_sysctl(const int op);
78051 +int gr_handle_chroot_setpriority(struct task_struct *p,
78052 + const int niceval);
78053 +int gr_chroot_fchdir(struct dentry *u_dentry, struct vfsmount *u_mnt);
78054 +int gr_handle_chroot_chroot(const struct dentry *dentry,
78055 + const struct vfsmount *mnt);
78056 +void gr_handle_chroot_chdir(const struct path *path);
78057 +int gr_handle_chroot_chmod(const struct dentry *dentry,
78058 + const struct vfsmount *mnt, const int mode);
78059 +int gr_handle_chroot_mknod(const struct dentry *dentry,
78060 + const struct vfsmount *mnt, const int mode);
78061 +int gr_handle_chroot_mount(const struct dentry *dentry,
78062 + const struct vfsmount *mnt,
78063 + const char *dev_name);
78064 +int gr_handle_chroot_pivot(void);
78065 +int gr_handle_chroot_unix(const pid_t pid);
78066 +
78067 +int gr_handle_rawio(const struct inode *inode);
78068 +
78069 +void gr_handle_ioperm(void);
78070 +void gr_handle_iopl(void);
78071 +void gr_handle_msr_write(void);
78072 +
78073 +umode_t gr_acl_umask(void);
78074 +
78075 +int gr_tpe_allow(const struct file *file);
78076 +
78077 +void gr_set_chroot_entries(struct task_struct *task, const struct path *path);
78078 +void gr_clear_chroot_entries(struct task_struct *task);
78079 +
78080 +void gr_log_forkfail(const int retval);
78081 +void gr_log_timechange(void);
78082 +void gr_log_signal(const int sig, const void *addr, const struct task_struct *t);
78083 +void gr_log_chdir(const struct dentry *dentry,
78084 + const struct vfsmount *mnt);
78085 +void gr_log_chroot_exec(const struct dentry *dentry,
78086 + const struct vfsmount *mnt);
78087 +void gr_log_remount(const char *devname, const int retval);
78088 +void gr_log_unmount(const char *devname, const int retval);
78089 +void gr_log_mount(const char *from, const char *to, const int retval);
78090 +void gr_log_textrel(struct vm_area_struct *vma);
78091 +void gr_log_ptgnustack(struct file *file);
78092 +void gr_log_rwxmmap(struct file *file);
78093 +void gr_log_rwxmprotect(struct vm_area_struct *vma);
78094 +
78095 +int gr_handle_follow_link(const struct inode *parent,
78096 + const struct inode *inode,
78097 + const struct dentry *dentry,
78098 + const struct vfsmount *mnt);
78099 +int gr_handle_fifo(const struct dentry *dentry,
78100 + const struct vfsmount *mnt,
78101 + const struct dentry *dir, const int flag,
78102 + const int acc_mode);
78103 +int gr_handle_hardlink(const struct dentry *dentry,
78104 + const struct vfsmount *mnt,
78105 + struct inode *inode,
78106 + const int mode, const struct filename *to);
78107 +
78108 +int gr_is_capable(const int cap);
78109 +int gr_is_capable_nolog(const int cap);
78110 +int gr_task_is_capable(const struct task_struct *task, const struct cred *cred, const int cap);
78111 +int gr_task_is_capable_nolog(const struct task_struct *task, const int cap);
78112 +
78113 +void gr_copy_label(struct task_struct *tsk);
78114 +void gr_handle_crash(struct task_struct *task, const int sig);
78115 +int gr_handle_signal(const struct task_struct *p, const int sig);
78116 +int gr_check_crash_uid(const kuid_t uid);
78117 +int gr_check_protected_task(const struct task_struct *task);
78118 +int gr_check_protected_task_fowner(struct pid *pid, enum pid_type type);
78119 +int gr_acl_handle_mmap(const struct file *file,
78120 + const unsigned long prot);
78121 +int gr_acl_handle_mprotect(const struct file *file,
78122 + const unsigned long prot);
78123 +int gr_check_hidden_task(const struct task_struct *tsk);
78124 +__u32 gr_acl_handle_truncate(const struct dentry *dentry,
78125 + const struct vfsmount *mnt);
78126 +__u32 gr_acl_handle_utime(const struct dentry *dentry,
78127 + const struct vfsmount *mnt);
78128 +__u32 gr_acl_handle_access(const struct dentry *dentry,
78129 + const struct vfsmount *mnt, const int fmode);
78130 +__u32 gr_acl_handle_chmod(const struct dentry *dentry,
78131 + const struct vfsmount *mnt, umode_t *mode);
78132 +__u32 gr_acl_handle_chown(const struct dentry *dentry,
78133 + const struct vfsmount *mnt);
78134 +__u32 gr_acl_handle_setxattr(const struct dentry *dentry,
78135 + const struct vfsmount *mnt);
78136 +__u32 gr_acl_handle_removexattr(const struct dentry *dentry,
78137 + const struct vfsmount *mnt);
78138 +int gr_handle_ptrace(struct task_struct *task, const long request);
78139 +int gr_handle_proc_ptrace(struct task_struct *task);
78140 +__u32 gr_acl_handle_execve(const struct dentry *dentry,
78141 + const struct vfsmount *mnt);
78142 +int gr_check_crash_exec(const struct file *filp);
78143 +int gr_acl_is_enabled(void);
78144 +void gr_set_role_label(struct task_struct *task, const kuid_t uid,
78145 + const kgid_t gid);
78146 +int gr_set_proc_label(const struct dentry *dentry,
78147 + const struct vfsmount *mnt,
78148 + const int unsafe_flags);
78149 +__u32 gr_acl_handle_hidden_file(const struct dentry *dentry,
78150 + const struct vfsmount *mnt);
78151 +__u32 gr_acl_handle_open(const struct dentry *dentry,
78152 + const struct vfsmount *mnt, int acc_mode);
78153 +__u32 gr_acl_handle_creat(const struct dentry *dentry,
78154 + const struct dentry *p_dentry,
78155 + const struct vfsmount *p_mnt,
78156 + int open_flags, int acc_mode, const int imode);
78157 +void gr_handle_create(const struct dentry *dentry,
78158 + const struct vfsmount *mnt);
78159 +void gr_handle_proc_create(const struct dentry *dentry,
78160 + const struct inode *inode);
78161 +__u32 gr_acl_handle_mknod(const struct dentry *new_dentry,
78162 + const struct dentry *parent_dentry,
78163 + const struct vfsmount *parent_mnt,
78164 + const int mode);
78165 +__u32 gr_acl_handle_mkdir(const struct dentry *new_dentry,
78166 + const struct dentry *parent_dentry,
78167 + const struct vfsmount *parent_mnt);
78168 +__u32 gr_acl_handle_rmdir(const struct dentry *dentry,
78169 + const struct vfsmount *mnt);
78170 +void gr_handle_delete(const ino_t ino, const dev_t dev);
78171 +__u32 gr_acl_handle_unlink(const struct dentry *dentry,
78172 + const struct vfsmount *mnt);
78173 +__u32 gr_acl_handle_symlink(const struct dentry *new_dentry,
78174 + const struct dentry *parent_dentry,
78175 + const struct vfsmount *parent_mnt,
78176 + const struct filename *from);
78177 +__u32 gr_acl_handle_link(const struct dentry *new_dentry,
78178 + const struct dentry *parent_dentry,
78179 + const struct vfsmount *parent_mnt,
78180 + const struct dentry *old_dentry,
78181 + const struct vfsmount *old_mnt, const struct filename *to);
78182 +int gr_handle_symlink_owner(const struct path *link, const struct inode *target);
78183 +int gr_acl_handle_rename(struct dentry *new_dentry,
78184 + struct dentry *parent_dentry,
78185 + const struct vfsmount *parent_mnt,
78186 + struct dentry *old_dentry,
78187 + struct inode *old_parent_inode,
78188 + struct vfsmount *old_mnt, const struct filename *newname);
78189 +void gr_handle_rename(struct inode *old_dir, struct inode *new_dir,
78190 + struct dentry *old_dentry,
78191 + struct dentry *new_dentry,
78192 + struct vfsmount *mnt, const __u8 replace);
78193 +__u32 gr_check_link(const struct dentry *new_dentry,
78194 + const struct dentry *parent_dentry,
78195 + const struct vfsmount *parent_mnt,
78196 + const struct dentry *old_dentry,
78197 + const struct vfsmount *old_mnt);
78198 +int gr_acl_handle_filldir(const struct file *file, const char *name,
78199 + const unsigned int namelen, const ino_t ino);
78200 +
78201 +__u32 gr_acl_handle_unix(const struct dentry *dentry,
78202 + const struct vfsmount *mnt);
78203 +void gr_acl_handle_exit(void);
78204 +void gr_acl_handle_psacct(struct task_struct *task, const long code);
78205 +int gr_acl_handle_procpidmem(const struct task_struct *task);
78206 +int gr_handle_rofs_mount(struct dentry *dentry, struct vfsmount *mnt, int mnt_flags);
78207 +int gr_handle_rofs_blockwrite(struct dentry *dentry, struct vfsmount *mnt, int acc_mode);
78208 +void gr_audit_ptrace(struct task_struct *task);
78209 +dev_t gr_get_dev_from_dentry(struct dentry *dentry);
78210 +void gr_put_exec_file(struct task_struct *task);
78211 +
78212 +int gr_ptrace_readexec(struct file *file, int unsafe_flags);
78213 +
78214 +#if defined(CONFIG_GRKERNSEC) && (defined(CONFIG_GRKERNSEC_RESLOG) || !defined(CONFIG_GRKERNSEC_NO_RBAC))
78215 +extern void gr_learn_resource(const struct task_struct *task, const int res,
78216 + const unsigned long wanted, const int gt);
78217 +#else
78218 +static inline void gr_learn_resource(const struct task_struct *task, const int res,
78219 + const unsigned long wanted, const int gt)
78220 +{
78221 +}
78222 +#endif
78223 +
78224 +#ifdef CONFIG_GRKERNSEC_RESLOG
78225 +extern void gr_log_resource(const struct task_struct *task, const int res,
78226 + const unsigned long wanted, const int gt);
78227 +#else
78228 +static inline void gr_log_resource(const struct task_struct *task, const int res,
78229 + const unsigned long wanted, const int gt)
78230 +{
78231 +}
78232 +#endif
78233 +
78234 +#ifdef CONFIG_GRKERNSEC
78235 +void task_grsec_rbac(struct seq_file *m, struct task_struct *p);
78236 +void gr_handle_vm86(void);
78237 +void gr_handle_mem_readwrite(u64 from, u64 to);
78238 +
78239 +void gr_log_badprocpid(const char *entry);
78240 +
78241 +extern int grsec_enable_dmesg;
78242 +extern int grsec_disable_privio;
78243 +
78244 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
78245 +extern kgid_t grsec_proc_gid;
78246 +#endif
78247 +
78248 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
78249 +extern int grsec_enable_chroot_findtask;
78250 +#endif
78251 +#ifdef CONFIG_GRKERNSEC_SETXID
78252 +extern int grsec_enable_setxid;
78253 +#endif
78254 +#endif
78255 +
78256 +#endif
78257 diff --git a/include/linux/grsock.h b/include/linux/grsock.h
78258 new file mode 100644
78259 index 0000000..e7ffaaf
78260 --- /dev/null
78261 +++ b/include/linux/grsock.h
78262 @@ -0,0 +1,19 @@
78263 +#ifndef __GRSOCK_H
78264 +#define __GRSOCK_H
78265 +
78266 +extern void gr_attach_curr_ip(const struct sock *sk);
78267 +extern int gr_handle_sock_all(const int family, const int type,
78268 + const int protocol);
78269 +extern int gr_handle_sock_server(const struct sockaddr *sck);
78270 +extern int gr_handle_sock_server_other(const struct sock *sck);
78271 +extern int gr_handle_sock_client(const struct sockaddr *sck);
78272 +extern int gr_search_connect(struct socket * sock,
78273 + struct sockaddr_in * addr);
78274 +extern int gr_search_bind(struct socket * sock,
78275 + struct sockaddr_in * addr);
78276 +extern int gr_search_listen(struct socket * sock);
78277 +extern int gr_search_accept(struct socket * sock);
78278 +extern int gr_search_socket(const int domain, const int type,
78279 + const int protocol);
78280 +
78281 +#endif
78282 diff --git a/include/linux/highmem.h b/include/linux/highmem.h
78283 index 7fb31da..08b5114 100644
78284 --- a/include/linux/highmem.h
78285 +++ b/include/linux/highmem.h
78286 @@ -189,6 +189,18 @@ static inline void clear_highpage(struct page *page)
78287 kunmap_atomic(kaddr);
78288 }
78289
78290 +static inline void sanitize_highpage(struct page *page)
78291 +{
78292 + void *kaddr;
78293 + unsigned long flags;
78294 +
78295 + local_irq_save(flags);
78296 + kaddr = kmap_atomic(page);
78297 + clear_page(kaddr);
78298 + kunmap_atomic(kaddr);
78299 + local_irq_restore(flags);
78300 +}
78301 +
78302 static inline void zero_user_segments(struct page *page,
78303 unsigned start1, unsigned end1,
78304 unsigned start2, unsigned end2)
78305 diff --git a/include/linux/hwmon-sysfs.h b/include/linux/hwmon-sysfs.h
78306 index 1c7b89a..7dda400 100644
78307 --- a/include/linux/hwmon-sysfs.h
78308 +++ b/include/linux/hwmon-sysfs.h
78309 @@ -25,7 +25,8 @@
78310 struct sensor_device_attribute{
78311 struct device_attribute dev_attr;
78312 int index;
78313 -};
78314 +} __do_const;
78315 +typedef struct sensor_device_attribute __no_const sensor_device_attribute_no_const;
78316 #define to_sensor_dev_attr(_dev_attr) \
78317 container_of(_dev_attr, struct sensor_device_attribute, dev_attr)
78318
78319 @@ -41,7 +42,8 @@ struct sensor_device_attribute_2 {
78320 struct device_attribute dev_attr;
78321 u8 index;
78322 u8 nr;
78323 -};
78324 +} __do_const;
78325 +typedef struct sensor_device_attribute_2 __no_const sensor_device_attribute_2_no_const;
78326 #define to_sensor_dev_attr_2(_dev_attr) \
78327 container_of(_dev_attr, struct sensor_device_attribute_2, dev_attr)
78328
78329 diff --git a/include/linux/i2c.h b/include/linux/i2c.h
78330 index d9c8dbd3..def6e5a 100644
78331 --- a/include/linux/i2c.h
78332 +++ b/include/linux/i2c.h
78333 @@ -364,6 +364,7 @@ struct i2c_algorithm {
78334 /* To determine what the adapter supports */
78335 u32 (*functionality) (struct i2c_adapter *);
78336 };
78337 +typedef struct i2c_algorithm __no_const i2c_algorithm_no_const;
78338
78339 /**
78340 * struct i2c_bus_recovery_info - I2C bus recovery information
78341 diff --git a/include/linux/i2o.h b/include/linux/i2o.h
78342 index d23c3c2..eb63c81 100644
78343 --- a/include/linux/i2o.h
78344 +++ b/include/linux/i2o.h
78345 @@ -565,7 +565,7 @@ struct i2o_controller {
78346 struct i2o_device *exec; /* Executive */
78347 #if BITS_PER_LONG == 64
78348 spinlock_t context_list_lock; /* lock for context_list */
78349 - atomic_t context_list_counter; /* needed for unique contexts */
78350 + atomic_unchecked_t context_list_counter; /* needed for unique contexts */
78351 struct list_head context_list; /* list of context id's
78352 and pointers */
78353 #endif
78354 diff --git a/include/linux/if_pppox.h b/include/linux/if_pppox.h
78355 index aff7ad8..3942bbd 100644
78356 --- a/include/linux/if_pppox.h
78357 +++ b/include/linux/if_pppox.h
78358 @@ -76,7 +76,7 @@ struct pppox_proto {
78359 int (*ioctl)(struct socket *sock, unsigned int cmd,
78360 unsigned long arg);
78361 struct module *owner;
78362 -};
78363 +} __do_const;
78364
78365 extern int register_pppox_proto(int proto_num, const struct pppox_proto *pp);
78366 extern void unregister_pppox_proto(int proto_num);
78367 diff --git a/include/linux/init.h b/include/linux/init.h
78368 index 8e68a64..3f977a0 100644
78369 --- a/include/linux/init.h
78370 +++ b/include/linux/init.h
78371 @@ -37,9 +37,17 @@
78372 * section.
78373 */
78374
78375 +#define add_init_latent_entropy __latent_entropy
78376 +
78377 +#ifdef CONFIG_MEMORY_HOTPLUG
78378 +#define add_meminit_latent_entropy
78379 +#else
78380 +#define add_meminit_latent_entropy __latent_entropy
78381 +#endif
78382 +
78383 /* These are for everybody (although not all archs will actually
78384 discard it in modules) */
78385 -#define __init __section(.init.text) __cold notrace
78386 +#define __init __section(.init.text) __cold notrace add_init_latent_entropy
78387 #define __initdata __section(.init.data)
78388 #define __initconst __constsection(.init.rodata)
78389 #define __exitdata __section(.exit.data)
78390 @@ -100,7 +108,7 @@
78391 #define __cpuexitconst
78392
78393 /* Used for MEMORY_HOTPLUG */
78394 -#define __meminit __section(.meminit.text) __cold notrace
78395 +#define __meminit __section(.meminit.text) __cold notrace add_meminit_latent_entropy
78396 #define __meminitdata __section(.meminit.data)
78397 #define __meminitconst __constsection(.meminit.rodata)
78398 #define __memexit __section(.memexit.text) __exitused __cold notrace
78399 diff --git a/include/linux/init_task.h b/include/linux/init_task.h
78400 index b0ed422..d79ea23 100644
78401 --- a/include/linux/init_task.h
78402 +++ b/include/linux/init_task.h
78403 @@ -154,6 +154,12 @@ extern struct task_group root_task_group;
78404
78405 #define INIT_TASK_COMM "swapper"
78406
78407 +#ifdef CONFIG_X86
78408 +#define INIT_TASK_THREAD_INFO .tinfo = INIT_THREAD_INFO,
78409 +#else
78410 +#define INIT_TASK_THREAD_INFO
78411 +#endif
78412 +
78413 /*
78414 * INIT_TASK is used to set up the first task table, touch at
78415 * your own risk!. Base=0, limit=0x1fffff (=2MB)
78416 @@ -193,6 +199,7 @@ extern struct task_group root_task_group;
78417 RCU_POINTER_INITIALIZER(cred, &init_cred), \
78418 .comm = INIT_TASK_COMM, \
78419 .thread = INIT_THREAD, \
78420 + INIT_TASK_THREAD_INFO \
78421 .fs = &init_fs, \
78422 .files = &init_files, \
78423 .signal = &init_signals, \
78424 diff --git a/include/linux/interrupt.h b/include/linux/interrupt.h
78425 index db43b58..5d5084b 100644
78426 --- a/include/linux/interrupt.h
78427 +++ b/include/linux/interrupt.h
78428 @@ -360,7 +360,7 @@ enum
78429 /* map softirq index to softirq name. update 'softirq_to_name' in
78430 * kernel/softirq.c when adding a new softirq.
78431 */
78432 -extern char *softirq_to_name[NR_SOFTIRQS];
78433 +extern const char * const softirq_to_name[NR_SOFTIRQS];
78434
78435 /* softirq mask and active fields moved to irq_cpustat_t in
78436 * asm/hardirq.h to get better cache usage. KAO
78437 @@ -368,8 +368,8 @@ extern char *softirq_to_name[NR_SOFTIRQS];
78438
78439 struct softirq_action
78440 {
78441 - void (*action)(struct softirq_action *);
78442 -};
78443 + void (*action)(void);
78444 +} __no_const;
78445
78446 asmlinkage void do_softirq(void);
78447 asmlinkage void __do_softirq(void);
78448 @@ -383,7 +383,7 @@ static inline void do_softirq_own_stack(void)
78449 }
78450 #endif
78451
78452 -extern void open_softirq(int nr, void (*action)(struct softirq_action *));
78453 +extern void open_softirq(int nr, void (*action)(void));
78454 extern void softirq_init(void);
78455 extern void __raise_softirq_irqoff(unsigned int nr);
78456
78457 diff --git a/include/linux/iommu.h b/include/linux/iommu.h
78458 index a444c79..8c41ea9 100644
78459 --- a/include/linux/iommu.h
78460 +++ b/include/linux/iommu.h
78461 @@ -130,7 +130,7 @@ struct iommu_ops {
78462 u32 (*domain_get_windows)(struct iommu_domain *domain);
78463
78464 unsigned long pgsize_bitmap;
78465 -};
78466 +} __do_const;
78467
78468 #define IOMMU_GROUP_NOTIFY_ADD_DEVICE 1 /* Device added */
78469 #define IOMMU_GROUP_NOTIFY_DEL_DEVICE 2 /* Pre Device removed */
78470 diff --git a/include/linux/ioport.h b/include/linux/ioport.h
78471 index 89b7c24..382af74 100644
78472 --- a/include/linux/ioport.h
78473 +++ b/include/linux/ioport.h
78474 @@ -161,7 +161,7 @@ struct resource *lookup_resource(struct resource *root, resource_size_t start);
78475 int adjust_resource(struct resource *res, resource_size_t start,
78476 resource_size_t size);
78477 resource_size_t resource_alignment(struct resource *res);
78478 -static inline resource_size_t resource_size(const struct resource *res)
78479 +static inline resource_size_t __intentional_overflow(-1) resource_size(const struct resource *res)
78480 {
78481 return res->end - res->start + 1;
78482 }
78483 diff --git a/include/linux/ipc_namespace.h b/include/linux/ipc_namespace.h
78484 index f6c82de..de8619e 100644
78485 --- a/include/linux/ipc_namespace.h
78486 +++ b/include/linux/ipc_namespace.h
78487 @@ -70,7 +70,7 @@ struct ipc_namespace {
78488 struct user_namespace *user_ns;
78489
78490 unsigned int proc_inum;
78491 -};
78492 +} __randomize_layout;
78493
78494 extern struct ipc_namespace init_ipc_ns;
78495 extern atomic_t nr_ipc_ns;
78496 diff --git a/include/linux/irq.h b/include/linux/irq.h
78497 index 7dc1003..407327b 100644
78498 --- a/include/linux/irq.h
78499 +++ b/include/linux/irq.h
78500 @@ -338,7 +338,8 @@ struct irq_chip {
78501 void (*irq_print_chip)(struct irq_data *data, struct seq_file *p);
78502
78503 unsigned long flags;
78504 -};
78505 +} __do_const;
78506 +typedef struct irq_chip __no_const irq_chip_no_const;
78507
78508 /*
78509 * irq_chip specific flags
78510 diff --git a/include/linux/irqchip/arm-gic.h b/include/linux/irqchip/arm-gic.h
78511 index cac496b..ffa0567 100644
78512 --- a/include/linux/irqchip/arm-gic.h
78513 +++ b/include/linux/irqchip/arm-gic.h
78514 @@ -61,9 +61,11 @@
78515
78516 #ifndef __ASSEMBLY__
78517
78518 +#include <linux/irq.h>
78519 +
78520 struct device_node;
78521
78522 -extern struct irq_chip gic_arch_extn;
78523 +extern irq_chip_no_const gic_arch_extn;
78524
78525 void gic_init_bases(unsigned int, int, void __iomem *, void __iomem *,
78526 u32 offset, struct device_node *);
78527 diff --git a/include/linux/jiffies.h b/include/linux/jiffies.h
78528 index d235e88..8ccbe74 100644
78529 --- a/include/linux/jiffies.h
78530 +++ b/include/linux/jiffies.h
78531 @@ -292,14 +292,14 @@ extern unsigned long preset_lpj;
78532 /*
78533 * Convert various time units to each other:
78534 */
78535 -extern unsigned int jiffies_to_msecs(const unsigned long j);
78536 -extern unsigned int jiffies_to_usecs(const unsigned long j);
78537 -extern unsigned long msecs_to_jiffies(const unsigned int m);
78538 -extern unsigned long usecs_to_jiffies(const unsigned int u);
78539 -extern unsigned long timespec_to_jiffies(const struct timespec *value);
78540 +extern unsigned int jiffies_to_msecs(const unsigned long j) __intentional_overflow(-1);
78541 +extern unsigned int jiffies_to_usecs(const unsigned long j) __intentional_overflow(-1);
78542 +extern unsigned long msecs_to_jiffies(const unsigned int m) __intentional_overflow(-1);
78543 +extern unsigned long usecs_to_jiffies(const unsigned int u) __intentional_overflow(-1);
78544 +extern unsigned long timespec_to_jiffies(const struct timespec *value) __intentional_overflow(-1);
78545 extern void jiffies_to_timespec(const unsigned long jiffies,
78546 struct timespec *value);
78547 -extern unsigned long timeval_to_jiffies(const struct timeval *value);
78548 +extern unsigned long timeval_to_jiffies(const struct timeval *value) __intentional_overflow(-1);
78549 extern void jiffies_to_timeval(const unsigned long jiffies,
78550 struct timeval *value);
78551
78552 diff --git a/include/linux/kallsyms.h b/include/linux/kallsyms.h
78553 index 6883e19..e854fcb 100644
78554 --- a/include/linux/kallsyms.h
78555 +++ b/include/linux/kallsyms.h
78556 @@ -15,7 +15,8 @@
78557
78558 struct module;
78559
78560 -#ifdef CONFIG_KALLSYMS
78561 +#if !defined(__INCLUDED_BY_HIDESYM) || !defined(CONFIG_KALLSYMS)
78562 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
78563 /* Lookup the address for a symbol. Returns 0 if not found. */
78564 unsigned long kallsyms_lookup_name(const char *name);
78565
78566 @@ -106,6 +107,21 @@ static inline int lookup_symbol_attrs(unsigned long addr, unsigned long *size, u
78567 /* Stupid that this does nothing, but I didn't create this mess. */
78568 #define __print_symbol(fmt, addr)
78569 #endif /*CONFIG_KALLSYMS*/
78570 +#else /* when included by kallsyms.c, vsnprintf.c, kprobes.c, or
78571 + arch/x86/kernel/dumpstack.c, with HIDESYM enabled */
78572 +extern unsigned long kallsyms_lookup_name(const char *name);
78573 +extern void __print_symbol(const char *fmt, unsigned long address);
78574 +extern int sprint_backtrace(char *buffer, unsigned long address);
78575 +extern int sprint_symbol(char *buffer, unsigned long address);
78576 +extern int sprint_symbol_no_offset(char *buffer, unsigned long address);
78577 +const char *kallsyms_lookup(unsigned long addr,
78578 + unsigned long *symbolsize,
78579 + unsigned long *offset,
78580 + char **modname, char *namebuf);
78581 +extern int kallsyms_lookup_size_offset(unsigned long addr,
78582 + unsigned long *symbolsize,
78583 + unsigned long *offset);
78584 +#endif
78585
78586 /* This macro allows us to keep printk typechecking */
78587 static __printf(1, 2)
78588 diff --git a/include/linux/key-type.h b/include/linux/key-type.h
78589 index a74c3a8..28d3f21 100644
78590 --- a/include/linux/key-type.h
78591 +++ b/include/linux/key-type.h
78592 @@ -131,7 +131,7 @@ struct key_type {
78593 /* internal fields */
78594 struct list_head link; /* link in types list */
78595 struct lock_class_key lock_class; /* key->sem lock class */
78596 -};
78597 +} __do_const;
78598
78599 extern struct key_type key_type_keyring;
78600
78601 diff --git a/include/linux/kgdb.h b/include/linux/kgdb.h
78602 index dfb4f2f..7927e62 100644
78603 --- a/include/linux/kgdb.h
78604 +++ b/include/linux/kgdb.h
78605 @@ -52,7 +52,7 @@ extern int kgdb_connected;
78606 extern int kgdb_io_module_registered;
78607
78608 extern atomic_t kgdb_setting_breakpoint;
78609 -extern atomic_t kgdb_cpu_doing_single_step;
78610 +extern atomic_unchecked_t kgdb_cpu_doing_single_step;
78611
78612 extern struct task_struct *kgdb_usethread;
78613 extern struct task_struct *kgdb_contthread;
78614 @@ -254,7 +254,7 @@ struct kgdb_arch {
78615 void (*correct_hw_break)(void);
78616
78617 void (*enable_nmi)(bool on);
78618 -};
78619 +} __do_const;
78620
78621 /**
78622 * struct kgdb_io - Describe the interface for an I/O driver to talk with KGDB.
78623 @@ -279,7 +279,7 @@ struct kgdb_io {
78624 void (*pre_exception) (void);
78625 void (*post_exception) (void);
78626 int is_console;
78627 -};
78628 +} __do_const;
78629
78630 extern struct kgdb_arch arch_kgdb_ops;
78631
78632 diff --git a/include/linux/kmod.h b/include/linux/kmod.h
78633 index 0555cc6..40116ce 100644
78634 --- a/include/linux/kmod.h
78635 +++ b/include/linux/kmod.h
78636 @@ -34,6 +34,8 @@ extern char modprobe_path[]; /* for sysctl */
78637 * usually useless though. */
78638 extern __printf(2, 3)
78639 int __request_module(bool wait, const char *name, ...);
78640 +extern __printf(3, 4)
78641 +int ___request_module(bool wait, char *param_name, const char *name, ...);
78642 #define request_module(mod...) __request_module(true, mod)
78643 #define request_module_nowait(mod...) __request_module(false, mod)
78644 #define try_then_request_module(x, mod...) \
78645 @@ -57,6 +59,9 @@ struct subprocess_info {
78646 struct work_struct work;
78647 struct completion *complete;
78648 char *path;
78649 +#ifdef CONFIG_GRKERNSEC
78650 + char *origpath;
78651 +#endif
78652 char **argv;
78653 char **envp;
78654 int wait;
78655 diff --git a/include/linux/kobject.h b/include/linux/kobject.h
78656 index e7ba650..0af3acb 100644
78657 --- a/include/linux/kobject.h
78658 +++ b/include/linux/kobject.h
78659 @@ -116,7 +116,7 @@ struct kobj_type {
78660 struct attribute **default_attrs;
78661 const struct kobj_ns_type_operations *(*child_ns_type)(struct kobject *kobj);
78662 const void *(*namespace)(struct kobject *kobj);
78663 -};
78664 +} __do_const;
78665
78666 struct kobj_uevent_env {
78667 char *envp[UEVENT_NUM_ENVP];
78668 @@ -139,6 +139,7 @@ struct kobj_attribute {
78669 ssize_t (*store)(struct kobject *kobj, struct kobj_attribute *attr,
78670 const char *buf, size_t count);
78671 };
78672 +typedef struct kobj_attribute __no_const kobj_attribute_no_const;
78673
78674 extern const struct sysfs_ops kobj_sysfs_ops;
78675
78676 @@ -166,7 +167,7 @@ struct kset {
78677 spinlock_t list_lock;
78678 struct kobject kobj;
78679 const struct kset_uevent_ops *uevent_ops;
78680 -};
78681 +} __randomize_layout;
78682
78683 extern void kset_init(struct kset *kset);
78684 extern int __must_check kset_register(struct kset *kset);
78685 diff --git a/include/linux/kobject_ns.h b/include/linux/kobject_ns.h
78686 index df32d25..fb52e27 100644
78687 --- a/include/linux/kobject_ns.h
78688 +++ b/include/linux/kobject_ns.h
78689 @@ -44,7 +44,7 @@ struct kobj_ns_type_operations {
78690 const void *(*netlink_ns)(struct sock *sk);
78691 const void *(*initial_ns)(void);
78692 void (*drop_ns)(void *);
78693 -};
78694 +} __do_const;
78695
78696 int kobj_ns_type_register(const struct kobj_ns_type_operations *ops);
78697 int kobj_ns_type_registered(enum kobj_ns_type type);
78698 diff --git a/include/linux/kref.h b/include/linux/kref.h
78699 index 484604d..0f6c5b6 100644
78700 --- a/include/linux/kref.h
78701 +++ b/include/linux/kref.h
78702 @@ -68,7 +68,7 @@ static inline void kref_get(struct kref *kref)
78703 static inline int kref_sub(struct kref *kref, unsigned int count,
78704 void (*release)(struct kref *kref))
78705 {
78706 - WARN_ON(release == NULL);
78707 + BUG_ON(release == NULL);
78708
78709 if (atomic_sub_and_test((int) count, &kref->refcount)) {
78710 release(kref);
78711 diff --git a/include/linux/kvm_host.h b/include/linux/kvm_host.h
78712 index 9523d2a..16c0424 100644
78713 --- a/include/linux/kvm_host.h
78714 +++ b/include/linux/kvm_host.h
78715 @@ -457,7 +457,7 @@ static inline void kvm_irqfd_exit(void)
78716 {
78717 }
78718 #endif
78719 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
78720 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
78721 struct module *module);
78722 void kvm_exit(void);
78723
78724 @@ -632,7 +632,7 @@ int kvm_arch_vcpu_ioctl_set_guest_debug(struct kvm_vcpu *vcpu,
78725 struct kvm_guest_debug *dbg);
78726 int kvm_arch_vcpu_ioctl_run(struct kvm_vcpu *vcpu, struct kvm_run *kvm_run);
78727
78728 -int kvm_arch_init(void *opaque);
78729 +int kvm_arch_init(const void *opaque);
78730 void kvm_arch_exit(void);
78731
78732 int kvm_arch_vcpu_init(struct kvm_vcpu *vcpu);
78733 diff --git a/include/linux/libata.h b/include/linux/libata.h
78734 index bec6dbe..2873d64 100644
78735 --- a/include/linux/libata.h
78736 +++ b/include/linux/libata.h
78737 @@ -975,7 +975,7 @@ struct ata_port_operations {
78738 * fields must be pointers.
78739 */
78740 const struct ata_port_operations *inherits;
78741 -};
78742 +} __do_const;
78743
78744 struct ata_port_info {
78745 unsigned long flags;
78746 diff --git a/include/linux/linkage.h b/include/linux/linkage.h
78747 index d3e8ad2..a949f68 100644
78748 --- a/include/linux/linkage.h
78749 +++ b/include/linux/linkage.h
78750 @@ -31,6 +31,7 @@
78751 #endif
78752
78753 #define __page_aligned_data __section(.data..page_aligned) __aligned(PAGE_SIZE)
78754 +#define __page_aligned_rodata __read_only __aligned(PAGE_SIZE)
78755 #define __page_aligned_bss __section(.bss..page_aligned) __aligned(PAGE_SIZE)
78756
78757 /*
78758 diff --git a/include/linux/list.h b/include/linux/list.h
78759 index ef95941..82db65a 100644
78760 --- a/include/linux/list.h
78761 +++ b/include/linux/list.h
78762 @@ -112,6 +112,19 @@ extern void __list_del_entry(struct list_head *entry);
78763 extern void list_del(struct list_head *entry);
78764 #endif
78765
78766 +extern void __pax_list_add(struct list_head *new,
78767 + struct list_head *prev,
78768 + struct list_head *next);
78769 +static inline void pax_list_add(struct list_head *new, struct list_head *head)
78770 +{
78771 + __pax_list_add(new, head, head->next);
78772 +}
78773 +static inline void pax_list_add_tail(struct list_head *new, struct list_head *head)
78774 +{
78775 + __pax_list_add(new, head->prev, head);
78776 +}
78777 +extern void pax_list_del(struct list_head *entry);
78778 +
78779 /**
78780 * list_replace - replace old entry by new one
78781 * @old : the element to be replaced
78782 @@ -145,6 +158,8 @@ static inline void list_del_init(struct list_head *entry)
78783 INIT_LIST_HEAD(entry);
78784 }
78785
78786 +extern void pax_list_del_init(struct list_head *entry);
78787 +
78788 /**
78789 * list_move - delete from one list and add as another's head
78790 * @list: the entry to move
78791 diff --git a/include/linux/math64.h b/include/linux/math64.h
78792 index c45c089..298841c 100644
78793 --- a/include/linux/math64.h
78794 +++ b/include/linux/math64.h
78795 @@ -15,7 +15,7 @@
78796 * This is commonly provided by 32bit archs to provide an optimized 64bit
78797 * divide.
78798 */
78799 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78800 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78801 {
78802 *remainder = dividend % divisor;
78803 return dividend / divisor;
78804 @@ -42,7 +42,7 @@ static inline u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder)
78805 /**
78806 * div64_u64 - unsigned 64bit divide with 64bit divisor
78807 */
78808 -static inline u64 div64_u64(u64 dividend, u64 divisor)
78809 +static inline u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
78810 {
78811 return dividend / divisor;
78812 }
78813 @@ -61,7 +61,7 @@ static inline s64 div64_s64(s64 dividend, s64 divisor)
78814 #define div64_ul(x, y) div_u64((x), (y))
78815
78816 #ifndef div_u64_rem
78817 -static inline u64 div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78818 +static inline u64 __intentional_overflow(-1) div_u64_rem(u64 dividend, u32 divisor, u32 *remainder)
78819 {
78820 *remainder = do_div(dividend, divisor);
78821 return dividend;
78822 @@ -77,7 +77,7 @@ extern u64 div64_u64_rem(u64 dividend, u64 divisor, u64 *remainder);
78823 #endif
78824
78825 #ifndef div64_u64
78826 -extern u64 div64_u64(u64 dividend, u64 divisor);
78827 +extern u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor);
78828 #endif
78829
78830 #ifndef div64_s64
78831 @@ -94,7 +94,7 @@ extern s64 div64_s64(s64 dividend, s64 divisor);
78832 * divide.
78833 */
78834 #ifndef div_u64
78835 -static inline u64 div_u64(u64 dividend, u32 divisor)
78836 +static inline u64 __intentional_overflow(-1) div_u64(u64 dividend, u32 divisor)
78837 {
78838 u32 remainder;
78839 return div_u64_rem(dividend, divisor, &remainder);
78840 diff --git a/include/linux/mempolicy.h b/include/linux/mempolicy.h
78841 index 9fe426b..8148be6 100644
78842 --- a/include/linux/mempolicy.h
78843 +++ b/include/linux/mempolicy.h
78844 @@ -91,6 +91,10 @@ static inline struct mempolicy *mpol_dup(struct mempolicy *pol)
78845 }
78846
78847 #define vma_policy(vma) ((vma)->vm_policy)
78848 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
78849 +{
78850 + vma->vm_policy = pol;
78851 +}
78852
78853 static inline void mpol_get(struct mempolicy *pol)
78854 {
78855 @@ -241,6 +245,9 @@ mpol_shared_policy_lookup(struct shared_policy *sp, unsigned long idx)
78856 }
78857
78858 #define vma_policy(vma) NULL
78859 +static inline void set_vma_policy(struct vm_area_struct *vma, struct mempolicy *pol)
78860 +{
78861 +}
78862
78863 static inline int
78864 vma_dup_policy(struct vm_area_struct *src, struct vm_area_struct *dst)
78865 diff --git a/include/linux/mm.h b/include/linux/mm.h
78866 index 9fac6dd..158ca43 100644
78867 --- a/include/linux/mm.h
78868 +++ b/include/linux/mm.h
78869 @@ -117,6 +117,11 @@ extern unsigned int kobjsize(const void *objp);
78870 #define VM_HUGETLB 0x00400000 /* Huge TLB Page VM */
78871 #define VM_NONLINEAR 0x00800000 /* Is non-linear (remap_file_pages) */
78872 #define VM_ARCH_1 0x01000000 /* Architecture-specific flag */
78873 +
78874 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
78875 +#define VM_PAGEEXEC 0x02000000 /* vma->vm_page_prot needs special handling */
78876 +#endif
78877 +
78878 #define VM_DONTDUMP 0x04000000 /* Do not include in the core dump */
78879
78880 #ifdef CONFIG_MEM_SOFT_DIRTY
78881 @@ -219,8 +224,8 @@ struct vm_operations_struct {
78882 /* called by access_process_vm when get_user_pages() fails, typically
78883 * for use by special VMAs that can switch between memory and hardware
78884 */
78885 - int (*access)(struct vm_area_struct *vma, unsigned long addr,
78886 - void *buf, int len, int write);
78887 + ssize_t (*access)(struct vm_area_struct *vma, unsigned long addr,
78888 + void *buf, size_t len, int write);
78889 #ifdef CONFIG_NUMA
78890 /*
78891 * set_policy() op must add a reference to any non-NULL @new mempolicy
78892 @@ -250,6 +255,7 @@ struct vm_operations_struct {
78893 int (*remap_pages)(struct vm_area_struct *vma, unsigned long addr,
78894 unsigned long size, pgoff_t pgoff);
78895 };
78896 +typedef struct vm_operations_struct __no_const vm_operations_struct_no_const;
78897
78898 struct mmu_gather;
78899 struct inode;
78900 @@ -1064,8 +1070,8 @@ int follow_pfn(struct vm_area_struct *vma, unsigned long address,
78901 unsigned long *pfn);
78902 int follow_phys(struct vm_area_struct *vma, unsigned long address,
78903 unsigned int flags, unsigned long *prot, resource_size_t *phys);
78904 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
78905 - void *buf, int len, int write);
78906 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
78907 + void *buf, size_t len, int write);
78908
78909 static inline void unmap_shared_mapping_range(struct address_space *mapping,
78910 loff_t const holebegin, loff_t const holelen)
78911 @@ -1104,9 +1110,9 @@ static inline int fixup_user_fault(struct task_struct *tsk,
78912 }
78913 #endif
78914
78915 -extern int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write);
78916 -extern int access_remote_vm(struct mm_struct *mm, unsigned long addr,
78917 - void *buf, int len, int write);
78918 +extern ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write);
78919 +extern ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
78920 + void *buf, size_t len, int write);
78921
78922 long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
78923 unsigned long start, unsigned long nr_pages,
78924 @@ -1138,34 +1144,6 @@ int set_page_dirty(struct page *page);
78925 int set_page_dirty_lock(struct page *page);
78926 int clear_page_dirty_for_io(struct page *page);
78927
78928 -/* Is the vma a continuation of the stack vma above it? */
78929 -static inline int vma_growsdown(struct vm_area_struct *vma, unsigned long addr)
78930 -{
78931 - return vma && (vma->vm_end == addr) && (vma->vm_flags & VM_GROWSDOWN);
78932 -}
78933 -
78934 -static inline int stack_guard_page_start(struct vm_area_struct *vma,
78935 - unsigned long addr)
78936 -{
78937 - return (vma->vm_flags & VM_GROWSDOWN) &&
78938 - (vma->vm_start == addr) &&
78939 - !vma_growsdown(vma->vm_prev, addr);
78940 -}
78941 -
78942 -/* Is the vma a continuation of the stack vma below it? */
78943 -static inline int vma_growsup(struct vm_area_struct *vma, unsigned long addr)
78944 -{
78945 - return vma && (vma->vm_start == addr) && (vma->vm_flags & VM_GROWSUP);
78946 -}
78947 -
78948 -static inline int stack_guard_page_end(struct vm_area_struct *vma,
78949 - unsigned long addr)
78950 -{
78951 - return (vma->vm_flags & VM_GROWSUP) &&
78952 - (vma->vm_end == addr) &&
78953 - !vma_growsup(vma->vm_next, addr);
78954 -}
78955 -
78956 extern pid_t
78957 vm_is_stack(struct task_struct *task, struct vm_area_struct *vma, int in_group);
78958
78959 @@ -1265,6 +1243,15 @@ static inline void sync_mm_rss(struct mm_struct *mm)
78960 }
78961 #endif
78962
78963 +#ifdef CONFIG_MMU
78964 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags);
78965 +#else
78966 +static inline pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
78967 +{
78968 + return __pgprot(0);
78969 +}
78970 +#endif
78971 +
78972 int vma_wants_writenotify(struct vm_area_struct *vma);
78973
78974 extern pte_t *__get_locked_pte(struct mm_struct *mm, unsigned long addr,
78975 @@ -1283,8 +1270,15 @@ static inline int __pud_alloc(struct mm_struct *mm, pgd_t *pgd,
78976 {
78977 return 0;
78978 }
78979 +
78980 +static inline int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd,
78981 + unsigned long address)
78982 +{
78983 + return 0;
78984 +}
78985 #else
78986 int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
78987 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address);
78988 #endif
78989
78990 #ifdef __PAGETABLE_PMD_FOLDED
78991 @@ -1293,8 +1287,15 @@ static inline int __pmd_alloc(struct mm_struct *mm, pud_t *pud,
78992 {
78993 return 0;
78994 }
78995 +
78996 +static inline int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud,
78997 + unsigned long address)
78998 +{
78999 + return 0;
79000 +}
79001 #else
79002 int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address);
79003 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address);
79004 #endif
79005
79006 int __pte_alloc(struct mm_struct *mm, struct vm_area_struct *vma,
79007 @@ -1312,11 +1313,23 @@ static inline pud_t *pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long a
79008 NULL: pud_offset(pgd, address);
79009 }
79010
79011 +static inline pud_t *pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
79012 +{
79013 + return (unlikely(pgd_none(*pgd)) && __pud_alloc_kernel(mm, pgd, address))?
79014 + NULL: pud_offset(pgd, address);
79015 +}
79016 +
79017 static inline pmd_t *pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
79018 {
79019 return (unlikely(pud_none(*pud)) && __pmd_alloc(mm, pud, address))?
79020 NULL: pmd_offset(pud, address);
79021 }
79022 +
79023 +static inline pmd_t *pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
79024 +{
79025 + return (unlikely(pud_none(*pud)) && __pmd_alloc_kernel(mm, pud, address))?
79026 + NULL: pmd_offset(pud, address);
79027 +}
79028 #endif /* CONFIG_MMU && !__ARCH_HAS_4LEVEL_HACK */
79029
79030 #if USE_SPLIT_PTE_PTLOCKS
79031 @@ -1694,7 +1707,7 @@ extern int install_special_mapping(struct mm_struct *mm,
79032 unsigned long addr, unsigned long len,
79033 unsigned long flags, struct page **pages);
79034
79035 -extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long);
79036 +extern unsigned long get_unmapped_area(struct file *, unsigned long, unsigned long, unsigned long, unsigned long) __intentional_overflow(-1);
79037
79038 extern unsigned long mmap_region(struct file *file, unsigned long addr,
79039 unsigned long len, vm_flags_t vm_flags, unsigned long pgoff);
79040 @@ -1702,6 +1715,7 @@ extern unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
79041 unsigned long len, unsigned long prot, unsigned long flags,
79042 unsigned long pgoff, unsigned long *populate);
79043 extern int do_munmap(struct mm_struct *, unsigned long, size_t);
79044 +extern int __do_munmap(struct mm_struct *, unsigned long, size_t);
79045
79046 #ifdef CONFIG_MMU
79047 extern int __mm_populate(unsigned long addr, unsigned long len,
79048 @@ -1730,10 +1744,11 @@ struct vm_unmapped_area_info {
79049 unsigned long high_limit;
79050 unsigned long align_mask;
79051 unsigned long align_offset;
79052 + unsigned long threadstack_offset;
79053 };
79054
79055 -extern unsigned long unmapped_area(struct vm_unmapped_area_info *info);
79056 -extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
79057 +extern unsigned long unmapped_area(const struct vm_unmapped_area_info *info);
79058 +extern unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info);
79059
79060 /*
79061 * Search for an unmapped address range.
79062 @@ -1745,7 +1760,7 @@ extern unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info);
79063 * - satisfies (begin_addr & align_mask) == (align_offset & align_mask)
79064 */
79065 static inline unsigned long
79066 -vm_unmapped_area(struct vm_unmapped_area_info *info)
79067 +vm_unmapped_area(const struct vm_unmapped_area_info *info)
79068 {
79069 if (!(info->flags & VM_UNMAPPED_AREA_TOPDOWN))
79070 return unmapped_area(info);
79071 @@ -1808,6 +1823,10 @@ extern struct vm_area_struct * find_vma(struct mm_struct * mm, unsigned long add
79072 extern struct vm_area_struct * find_vma_prev(struct mm_struct * mm, unsigned long addr,
79073 struct vm_area_struct **pprev);
79074
79075 +extern struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma);
79076 +extern __must_check long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma);
79077 +extern void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl);
79078 +
79079 /* Look up the first VMA which intersects the interval start_addr..end_addr-1,
79080 NULL if none. Assume start_addr < end_addr. */
79081 static inline struct vm_area_struct * find_vma_intersection(struct mm_struct * mm, unsigned long start_addr, unsigned long end_addr)
79082 @@ -1836,15 +1855,6 @@ static inline struct vm_area_struct *find_exact_vma(struct mm_struct *mm,
79083 return vma;
79084 }
79085
79086 -#ifdef CONFIG_MMU
79087 -pgprot_t vm_get_page_prot(unsigned long vm_flags);
79088 -#else
79089 -static inline pgprot_t vm_get_page_prot(unsigned long vm_flags)
79090 -{
79091 - return __pgprot(0);
79092 -}
79093 -#endif
79094 -
79095 #ifdef CONFIG_ARCH_USES_NUMA_PROT_NONE
79096 unsigned long change_prot_numa(struct vm_area_struct *vma,
79097 unsigned long start, unsigned long end);
79098 @@ -1896,6 +1906,11 @@ void vm_stat_account(struct mm_struct *, unsigned long, struct file *, long);
79099 static inline void vm_stat_account(struct mm_struct *mm,
79100 unsigned long flags, struct file *file, long pages)
79101 {
79102 +
79103 +#ifdef CONFIG_PAX_RANDMMAP
79104 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
79105 +#endif
79106 +
79107 mm->total_vm += pages;
79108 }
79109 #endif /* CONFIG_PROC_FS */
79110 @@ -1977,7 +1992,7 @@ extern int unpoison_memory(unsigned long pfn);
79111 extern int sysctl_memory_failure_early_kill;
79112 extern int sysctl_memory_failure_recovery;
79113 extern void shake_page(struct page *p, int access);
79114 -extern atomic_long_t num_poisoned_pages;
79115 +extern atomic_long_unchecked_t num_poisoned_pages;
79116 extern int soft_offline_page(struct page *page, int flags);
79117
79118 extern void dump_page(struct page *page);
79119 @@ -2014,5 +2029,11 @@ void __init setup_nr_node_ids(void);
79120 static inline void setup_nr_node_ids(void) {}
79121 #endif
79122
79123 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
79124 +extern void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot);
79125 +#else
79126 +static inline void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot) {}
79127 +#endif
79128 +
79129 #endif /* __KERNEL__ */
79130 #endif /* _LINUX_MM_H */
79131 diff --git a/include/linux/mm_types.h b/include/linux/mm_types.h
79132 index 290901a..e99b01c 100644
79133 --- a/include/linux/mm_types.h
79134 +++ b/include/linux/mm_types.h
79135 @@ -307,7 +307,9 @@ struct vm_area_struct {
79136 #ifdef CONFIG_NUMA
79137 struct mempolicy *vm_policy; /* NUMA policy for the VMA */
79138 #endif
79139 -};
79140 +
79141 + struct vm_area_struct *vm_mirror;/* PaX: mirror vma or NULL */
79142 +} __randomize_layout;
79143
79144 struct core_thread {
79145 struct task_struct *task;
79146 @@ -453,7 +455,25 @@ struct mm_struct {
79147 bool tlb_flush_pending;
79148 #endif
79149 struct uprobes_state uprobes_state;
79150 -};
79151 +
79152 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
79153 + unsigned long pax_flags;
79154 +#endif
79155 +
79156 +#ifdef CONFIG_PAX_DLRESOLVE
79157 + unsigned long call_dl_resolve;
79158 +#endif
79159 +
79160 +#if defined(CONFIG_PPC32) && defined(CONFIG_PAX_EMUSIGRT)
79161 + unsigned long call_syscall;
79162 +#endif
79163 +
79164 +#ifdef CONFIG_PAX_ASLR
79165 + unsigned long delta_mmap; /* randomized offset */
79166 + unsigned long delta_stack; /* randomized offset */
79167 +#endif
79168 +
79169 +} __randomize_layout;
79170
79171 static inline void mm_init_cpumask(struct mm_struct *mm)
79172 {
79173 diff --git a/include/linux/mmiotrace.h b/include/linux/mmiotrace.h
79174 index c5d5278..f0b68c8 100644
79175 --- a/include/linux/mmiotrace.h
79176 +++ b/include/linux/mmiotrace.h
79177 @@ -46,7 +46,7 @@ extern int kmmio_handler(struct pt_regs *regs, unsigned long addr);
79178 /* Called from ioremap.c */
79179 extern void mmiotrace_ioremap(resource_size_t offset, unsigned long size,
79180 void __iomem *addr);
79181 -extern void mmiotrace_iounmap(volatile void __iomem *addr);
79182 +extern void mmiotrace_iounmap(const volatile void __iomem *addr);
79183
79184 /* For anyone to insert markers. Remember trailing newline. */
79185 extern __printf(1, 2) int mmiotrace_printk(const char *fmt, ...);
79186 @@ -66,7 +66,7 @@ static inline void mmiotrace_ioremap(resource_size_t offset,
79187 {
79188 }
79189
79190 -static inline void mmiotrace_iounmap(volatile void __iomem *addr)
79191 +static inline void mmiotrace_iounmap(const volatile void __iomem *addr)
79192 {
79193 }
79194
79195 diff --git a/include/linux/mmzone.h b/include/linux/mmzone.h
79196 index bd791e4..8617c34f 100644
79197 --- a/include/linux/mmzone.h
79198 +++ b/include/linux/mmzone.h
79199 @@ -396,7 +396,7 @@ struct zone {
79200 unsigned long flags; /* zone flags, see below */
79201
79202 /* Zone statistics */
79203 - atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79204 + atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
79205
79206 /*
79207 * The target ratio of ACTIVE_ANON to INACTIVE_ANON pages on
79208 diff --git a/include/linux/mod_devicetable.h b/include/linux/mod_devicetable.h
79209 index 45e9214..a7227d6 100644
79210 --- a/include/linux/mod_devicetable.h
79211 +++ b/include/linux/mod_devicetable.h
79212 @@ -13,7 +13,7 @@
79213 typedef unsigned long kernel_ulong_t;
79214 #endif
79215
79216 -#define PCI_ANY_ID (~0)
79217 +#define PCI_ANY_ID ((__u16)~0)
79218
79219 struct pci_device_id {
79220 __u32 vendor, device; /* Vendor and device ID or PCI_ANY_ID*/
79221 @@ -139,7 +139,7 @@ struct usb_device_id {
79222 #define USB_DEVICE_ID_MATCH_INT_PROTOCOL 0x0200
79223 #define USB_DEVICE_ID_MATCH_INT_NUMBER 0x0400
79224
79225 -#define HID_ANY_ID (~0)
79226 +#define HID_ANY_ID (~0U)
79227 #define HID_BUS_ANY 0xffff
79228 #define HID_GROUP_ANY 0x0000
79229
79230 @@ -467,7 +467,7 @@ struct dmi_system_id {
79231 const char *ident;
79232 struct dmi_strmatch matches[4];
79233 void *driver_data;
79234 -};
79235 +} __do_const;
79236 /*
79237 * struct dmi_device_id appears during expansion of
79238 * "MODULE_DEVICE_TABLE(dmi, x)". Compiler doesn't look inside it
79239 diff --git a/include/linux/module.h b/include/linux/module.h
79240 index 15cd6b1..f6e2e6a 100644
79241 --- a/include/linux/module.h
79242 +++ b/include/linux/module.h
79243 @@ -17,9 +17,11 @@
79244 #include <linux/moduleparam.h>
79245 #include <linux/tracepoint.h>
79246 #include <linux/export.h>
79247 +#include <linux/fs.h>
79248
79249 #include <linux/percpu.h>
79250 #include <asm/module.h>
79251 +#include <asm/pgtable.h>
79252
79253 /* In stripped ARM and x86-64 modules, ~ is surprisingly rare. */
79254 #define MODULE_SIG_STRING "~Module signature appended~\n"
79255 @@ -43,7 +45,7 @@ struct module_kobject {
79256 struct kobject *drivers_dir;
79257 struct module_param_attrs *mp;
79258 struct completion *kobj_completion;
79259 -};
79260 +} __randomize_layout;
79261
79262 struct module_attribute {
79263 struct attribute attr;
79264 @@ -55,12 +57,13 @@ struct module_attribute {
79265 int (*test)(struct module *);
79266 void (*free)(struct module *);
79267 };
79268 +typedef struct module_attribute __no_const module_attribute_no_const;
79269
79270 struct module_version_attribute {
79271 struct module_attribute mattr;
79272 const char *module_name;
79273 const char *version;
79274 -} __attribute__ ((__aligned__(sizeof(void *))));
79275 +} __do_const __attribute__ ((__aligned__(sizeof(void *))));
79276
79277 extern ssize_t __modver_version_show(struct module_attribute *,
79278 struct module_kobject *, char *);
79279 @@ -238,7 +241,7 @@ struct module
79280
79281 /* Sysfs stuff. */
79282 struct module_kobject mkobj;
79283 - struct module_attribute *modinfo_attrs;
79284 + module_attribute_no_const *modinfo_attrs;
79285 const char *version;
79286 const char *srcversion;
79287 struct kobject *holders_dir;
79288 @@ -287,19 +290,16 @@ struct module
79289 int (*init)(void);
79290
79291 /* If this is non-NULL, vfree after init() returns */
79292 - void *module_init;
79293 + void *module_init_rx, *module_init_rw;
79294
79295 /* Here is the actual code + data, vfree'd on unload. */
79296 - void *module_core;
79297 + void *module_core_rx, *module_core_rw;
79298
79299 /* Here are the sizes of the init and core sections */
79300 - unsigned int init_size, core_size;
79301 + unsigned int init_size_rw, core_size_rw;
79302
79303 /* The size of the executable code in each section. */
79304 - unsigned int init_text_size, core_text_size;
79305 -
79306 - /* Size of RO sections of the module (text+rodata) */
79307 - unsigned int init_ro_size, core_ro_size;
79308 + unsigned int init_size_rx, core_size_rx;
79309
79310 /* Arch-specific module values */
79311 struct mod_arch_specific arch;
79312 @@ -355,6 +355,10 @@ struct module
79313 #ifdef CONFIG_EVENT_TRACING
79314 struct ftrace_event_call **trace_events;
79315 unsigned int num_trace_events;
79316 + struct file_operations trace_id;
79317 + struct file_operations trace_enable;
79318 + struct file_operations trace_format;
79319 + struct file_operations trace_filter;
79320 #endif
79321 #ifdef CONFIG_FTRACE_MCOUNT_RECORD
79322 unsigned int num_ftrace_callsites;
79323 @@ -378,7 +382,7 @@ struct module
79324 ctor_fn_t *ctors;
79325 unsigned int num_ctors;
79326 #endif
79327 -};
79328 +} __randomize_layout;
79329 #ifndef MODULE_ARCH_INIT
79330 #define MODULE_ARCH_INIT {}
79331 #endif
79332 @@ -399,16 +403,46 @@ bool is_module_address(unsigned long addr);
79333 bool is_module_percpu_address(unsigned long addr);
79334 bool is_module_text_address(unsigned long addr);
79335
79336 +static inline int within_module_range(unsigned long addr, void *start, unsigned long size)
79337 +{
79338 +
79339 +#ifdef CONFIG_PAX_KERNEXEC
79340 + if (ktla_ktva(addr) >= (unsigned long)start &&
79341 + ktla_ktva(addr) < (unsigned long)start + size)
79342 + return 1;
79343 +#endif
79344 +
79345 + return ((void *)addr >= start && (void *)addr < start + size);
79346 +}
79347 +
79348 +static inline int within_module_core_rx(unsigned long addr, const struct module *mod)
79349 +{
79350 + return within_module_range(addr, mod->module_core_rx, mod->core_size_rx);
79351 +}
79352 +
79353 +static inline int within_module_core_rw(unsigned long addr, const struct module *mod)
79354 +{
79355 + return within_module_range(addr, mod->module_core_rw, mod->core_size_rw);
79356 +}
79357 +
79358 +static inline int within_module_init_rx(unsigned long addr, const struct module *mod)
79359 +{
79360 + return within_module_range(addr, mod->module_init_rx, mod->init_size_rx);
79361 +}
79362 +
79363 +static inline int within_module_init_rw(unsigned long addr, const struct module *mod)
79364 +{
79365 + return within_module_range(addr, mod->module_init_rw, mod->init_size_rw);
79366 +}
79367 +
79368 static inline int within_module_core(unsigned long addr, const struct module *mod)
79369 {
79370 - return (unsigned long)mod->module_core <= addr &&
79371 - addr < (unsigned long)mod->module_core + mod->core_size;
79372 + return within_module_core_rx(addr, mod) || within_module_core_rw(addr, mod);
79373 }
79374
79375 static inline int within_module_init(unsigned long addr, const struct module *mod)
79376 {
79377 - return (unsigned long)mod->module_init <= addr &&
79378 - addr < (unsigned long)mod->module_init + mod->init_size;
79379 + return within_module_init_rx(addr, mod) || within_module_init_rw(addr, mod);
79380 }
79381
79382 /* Search for module by name: must hold module_mutex. */
79383 diff --git a/include/linux/moduleloader.h b/include/linux/moduleloader.h
79384 index 560ca53..ef621ef 100644
79385 --- a/include/linux/moduleloader.h
79386 +++ b/include/linux/moduleloader.h
79387 @@ -25,9 +25,21 @@ unsigned int arch_mod_section_prepend(struct module *mod, unsigned int section);
79388 sections. Returns NULL on failure. */
79389 void *module_alloc(unsigned long size);
79390
79391 +#ifdef CONFIG_PAX_KERNEXEC
79392 +void *module_alloc_exec(unsigned long size);
79393 +#else
79394 +#define module_alloc_exec(x) module_alloc(x)
79395 +#endif
79396 +
79397 /* Free memory returned from module_alloc. */
79398 void module_free(struct module *mod, void *module_region);
79399
79400 +#ifdef CONFIG_PAX_KERNEXEC
79401 +void module_free_exec(struct module *mod, void *module_region);
79402 +#else
79403 +#define module_free_exec(x, y) module_free((x), (y))
79404 +#endif
79405 +
79406 /*
79407 * Apply the given relocation to the (simplified) ELF. Return -error
79408 * or 0.
79409 @@ -45,7 +57,9 @@ static inline int apply_relocate(Elf_Shdr *sechdrs,
79410 unsigned int relsec,
79411 struct module *me)
79412 {
79413 +#ifdef CONFIG_MODULES
79414 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
79415 +#endif
79416 return -ENOEXEC;
79417 }
79418 #endif
79419 @@ -67,7 +81,9 @@ static inline int apply_relocate_add(Elf_Shdr *sechdrs,
79420 unsigned int relsec,
79421 struct module *me)
79422 {
79423 +#ifdef CONFIG_MODULES
79424 printk(KERN_ERR "module %s: REL relocation unsupported\n", me->name);
79425 +#endif
79426 return -ENOEXEC;
79427 }
79428 #endif
79429 diff --git a/include/linux/moduleparam.h b/include/linux/moduleparam.h
79430 index c3eb102..073c4a6 100644
79431 --- a/include/linux/moduleparam.h
79432 +++ b/include/linux/moduleparam.h
79433 @@ -295,7 +295,7 @@ static inline void __kernel_param_unlock(void)
79434 * @len is usually just sizeof(string).
79435 */
79436 #define module_param_string(name, string, len, perm) \
79437 - static const struct kparam_string __param_string_##name \
79438 + static const struct kparam_string __param_string_##name __used \
79439 = { len, string }; \
79440 __module_param_call(MODULE_PARAM_PREFIX, name, \
79441 &param_ops_string, \
79442 @@ -434,7 +434,7 @@ extern int param_set_bint(const char *val, const struct kernel_param *kp);
79443 */
79444 #define module_param_array_named(name, array, type, nump, perm) \
79445 param_check_##type(name, &(array)[0]); \
79446 - static const struct kparam_array __param_arr_##name \
79447 + static const struct kparam_array __param_arr_##name __used \
79448 = { .max = ARRAY_SIZE(array), .num = nump, \
79449 .ops = &param_ops_##type, \
79450 .elemsize = sizeof(array[0]), .elem = array }; \
79451 diff --git a/include/linux/mount.h b/include/linux/mount.h
79452 index 371d346..fba2819 100644
79453 --- a/include/linux/mount.h
79454 +++ b/include/linux/mount.h
79455 @@ -56,7 +56,7 @@ struct vfsmount {
79456 struct dentry *mnt_root; /* root of the mounted tree */
79457 struct super_block *mnt_sb; /* pointer to superblock */
79458 int mnt_flags;
79459 -};
79460 +} __randomize_layout;
79461
79462 struct file; /* forward dec */
79463
79464 diff --git a/include/linux/namei.h b/include/linux/namei.h
79465 index 492de72..1bddcd4 100644
79466 --- a/include/linux/namei.h
79467 +++ b/include/linux/namei.h
79468 @@ -19,7 +19,7 @@ struct nameidata {
79469 unsigned seq, m_seq;
79470 int last_type;
79471 unsigned depth;
79472 - char *saved_names[MAX_NESTED_LINKS + 1];
79473 + const char *saved_names[MAX_NESTED_LINKS + 1];
79474 };
79475
79476 /*
79477 @@ -83,12 +83,12 @@ extern void unlock_rename(struct dentry *, struct dentry *);
79478
79479 extern void nd_jump_link(struct nameidata *nd, struct path *path);
79480
79481 -static inline void nd_set_link(struct nameidata *nd, char *path)
79482 +static inline void nd_set_link(struct nameidata *nd, const char *path)
79483 {
79484 nd->saved_names[nd->depth] = path;
79485 }
79486
79487 -static inline char *nd_get_link(struct nameidata *nd)
79488 +static inline const char *nd_get_link(const struct nameidata *nd)
79489 {
79490 return nd->saved_names[nd->depth];
79491 }
79492 diff --git a/include/linux/net.h b/include/linux/net.h
79493 index 69be3e6..0fb422d 100644
79494 --- a/include/linux/net.h
79495 +++ b/include/linux/net.h
79496 @@ -192,7 +192,7 @@ struct net_proto_family {
79497 int (*create)(struct net *net, struct socket *sock,
79498 int protocol, int kern);
79499 struct module *owner;
79500 -};
79501 +} __do_const;
79502
79503 struct iovec;
79504 struct kvec;
79505 diff --git a/include/linux/netdevice.h b/include/linux/netdevice.h
79506 index ce2a1f5..cb9bc8c 100644
79507 --- a/include/linux/netdevice.h
79508 +++ b/include/linux/netdevice.h
79509 @@ -1129,6 +1129,7 @@ struct net_device_ops {
79510 struct net_device *dev,
79511 void *priv);
79512 };
79513 +typedef struct net_device_ops __no_const net_device_ops_no_const;
79514
79515 /*
79516 * The DEVICE structure.
79517 @@ -1211,7 +1212,7 @@ struct net_device {
79518 int iflink;
79519
79520 struct net_device_stats stats;
79521 - atomic_long_t rx_dropped; /* dropped packets by core network
79522 + atomic_long_unchecked_t rx_dropped; /* dropped packets by core network
79523 * Do not use this in drivers.
79524 */
79525
79526 diff --git a/include/linux/netfilter.h b/include/linux/netfilter.h
79527 index 2077489..a15e561 100644
79528 --- a/include/linux/netfilter.h
79529 +++ b/include/linux/netfilter.h
79530 @@ -84,7 +84,7 @@ struct nf_sockopt_ops {
79531 #endif
79532 /* Use the module struct to lock set/get code in place */
79533 struct module *owner;
79534 -};
79535 +} __do_const;
79536
79537 /* Function to register/unregister hook points. */
79538 int nf_register_hook(struct nf_hook_ops *reg);
79539 diff --git a/include/linux/netfilter/nfnetlink.h b/include/linux/netfilter/nfnetlink.h
79540 index 28c7436..2d6156a 100644
79541 --- a/include/linux/netfilter/nfnetlink.h
79542 +++ b/include/linux/netfilter/nfnetlink.h
79543 @@ -19,7 +19,7 @@ struct nfnl_callback {
79544 const struct nlattr * const cda[]);
79545 const struct nla_policy *policy; /* netlink attribute policy */
79546 const u_int16_t attr_count; /* number of nlattr's */
79547 -};
79548 +} __do_const;
79549
79550 struct nfnetlink_subsystem {
79551 const char *name;
79552 diff --git a/include/linux/netfilter/xt_gradm.h b/include/linux/netfilter/xt_gradm.h
79553 new file mode 100644
79554 index 0000000..33f4af8
79555 --- /dev/null
79556 +++ b/include/linux/netfilter/xt_gradm.h
79557 @@ -0,0 +1,9 @@
79558 +#ifndef _LINUX_NETFILTER_XT_GRADM_H
79559 +#define _LINUX_NETFILTER_XT_GRADM_H 1
79560 +
79561 +struct xt_gradm_mtinfo {
79562 + __u16 flags;
79563 + __u16 invflags;
79564 +};
79565 +
79566 +#endif
79567 diff --git a/include/linux/nls.h b/include/linux/nls.h
79568 index 5dc635f..35f5e11 100644
79569 --- a/include/linux/nls.h
79570 +++ b/include/linux/nls.h
79571 @@ -31,7 +31,7 @@ struct nls_table {
79572 const unsigned char *charset2upper;
79573 struct module *owner;
79574 struct nls_table *next;
79575 -};
79576 +} __do_const;
79577
79578 /* this value hold the maximum octet of charset */
79579 #define NLS_MAX_CHARSET_SIZE 6 /* for UTF-8 */
79580 diff --git a/include/linux/notifier.h b/include/linux/notifier.h
79581 index d14a4c3..a078786 100644
79582 --- a/include/linux/notifier.h
79583 +++ b/include/linux/notifier.h
79584 @@ -54,7 +54,8 @@ struct notifier_block {
79585 notifier_fn_t notifier_call;
79586 struct notifier_block __rcu *next;
79587 int priority;
79588 -};
79589 +} __do_const;
79590 +typedef struct notifier_block __no_const notifier_block_no_const;
79591
79592 struct atomic_notifier_head {
79593 spinlock_t lock;
79594 diff --git a/include/linux/oprofile.h b/include/linux/oprofile.h
79595 index b2a0f15..4d7da32 100644
79596 --- a/include/linux/oprofile.h
79597 +++ b/include/linux/oprofile.h
79598 @@ -138,9 +138,9 @@ int oprofilefs_create_ulong(struct dentry * root,
79599 int oprofilefs_create_ro_ulong(struct dentry * root,
79600 char const * name, ulong * val);
79601
79602 -/** Create a file for read-only access to an atomic_t. */
79603 +/** Create a file for read-only access to an atomic_unchecked_t. */
79604 int oprofilefs_create_ro_atomic(struct dentry * root,
79605 - char const * name, atomic_t * val);
79606 + char const * name, atomic_unchecked_t * val);
79607
79608 /** create a directory */
79609 struct dentry *oprofilefs_mkdir(struct dentry *parent, char const *name);
79610 diff --git a/include/linux/padata.h b/include/linux/padata.h
79611 index 4386946..f50c615 100644
79612 --- a/include/linux/padata.h
79613 +++ b/include/linux/padata.h
79614 @@ -129,7 +129,7 @@ struct parallel_data {
79615 struct padata_serial_queue __percpu *squeue;
79616 atomic_t reorder_objects;
79617 atomic_t refcnt;
79618 - atomic_t seq_nr;
79619 + atomic_unchecked_t seq_nr;
79620 struct padata_cpumask cpumask;
79621 spinlock_t lock ____cacheline_aligned;
79622 unsigned int processed;
79623 diff --git a/include/linux/pci_hotplug.h b/include/linux/pci_hotplug.h
79624 index a2e2f1d..8a391d2 100644
79625 --- a/include/linux/pci_hotplug.h
79626 +++ b/include/linux/pci_hotplug.h
79627 @@ -71,7 +71,8 @@ struct hotplug_slot_ops {
79628 int (*get_latch_status) (struct hotplug_slot *slot, u8 *value);
79629 int (*get_adapter_status) (struct hotplug_slot *slot, u8 *value);
79630 int (*reset_slot) (struct hotplug_slot *slot, int probe);
79631 -};
79632 +} __do_const;
79633 +typedef struct hotplug_slot_ops __no_const hotplug_slot_ops_no_const;
79634
79635 /**
79636 * struct hotplug_slot_info - used to notify the hotplug pci core of the state of the slot
79637 diff --git a/include/linux/perf_event.h b/include/linux/perf_event.h
79638 index 2e069d1..27054b8 100644
79639 --- a/include/linux/perf_event.h
79640 +++ b/include/linux/perf_event.h
79641 @@ -327,8 +327,8 @@ struct perf_event {
79642
79643 enum perf_event_active_state state;
79644 unsigned int attach_state;
79645 - local64_t count;
79646 - atomic64_t child_count;
79647 + local64_t count; /* PaX: fix it one day */
79648 + atomic64_unchecked_t child_count;
79649
79650 /*
79651 * These are the total time in nanoseconds that the event
79652 @@ -379,8 +379,8 @@ struct perf_event {
79653 * These accumulate total time (in nanoseconds) that children
79654 * events have been enabled and running, respectively.
79655 */
79656 - atomic64_t child_total_time_enabled;
79657 - atomic64_t child_total_time_running;
79658 + atomic64_unchecked_t child_total_time_enabled;
79659 + atomic64_unchecked_t child_total_time_running;
79660
79661 /*
79662 * Protect attach/detach and child_list:
79663 @@ -707,7 +707,7 @@ static inline void perf_callchain_store(struct perf_callchain_entry *entry, u64
79664 entry->ip[entry->nr++] = ip;
79665 }
79666
79667 -extern int sysctl_perf_event_paranoid;
79668 +extern int sysctl_perf_event_legitimately_concerned;
79669 extern int sysctl_perf_event_mlock;
79670 extern int sysctl_perf_event_sample_rate;
79671 extern int sysctl_perf_cpu_time_max_percent;
79672 @@ -722,19 +722,24 @@ extern int perf_cpu_time_max_percent_handler(struct ctl_table *table, int write,
79673 loff_t *ppos);
79674
79675
79676 +static inline bool perf_paranoid_any(void)
79677 +{
79678 + return sysctl_perf_event_legitimately_concerned > 2;
79679 +}
79680 +
79681 static inline bool perf_paranoid_tracepoint_raw(void)
79682 {
79683 - return sysctl_perf_event_paranoid > -1;
79684 + return sysctl_perf_event_legitimately_concerned > -1;
79685 }
79686
79687 static inline bool perf_paranoid_cpu(void)
79688 {
79689 - return sysctl_perf_event_paranoid > 0;
79690 + return sysctl_perf_event_legitimately_concerned > 0;
79691 }
79692
79693 static inline bool perf_paranoid_kernel(void)
79694 {
79695 - return sysctl_perf_event_paranoid > 1;
79696 + return sysctl_perf_event_legitimately_concerned > 1;
79697 }
79698
79699 extern void perf_event_init(void);
79700 @@ -850,7 +855,7 @@ struct perf_pmu_events_attr {
79701 struct device_attribute attr;
79702 u64 id;
79703 const char *event_str;
79704 -};
79705 +} __do_const;
79706
79707 #define PMU_EVENT_ATTR(_name, _var, _id, _show) \
79708 static struct perf_pmu_events_attr _var = { \
79709 diff --git a/include/linux/pid_namespace.h b/include/linux/pid_namespace.h
79710 index 7246ef3..1539ea4 100644
79711 --- a/include/linux/pid_namespace.h
79712 +++ b/include/linux/pid_namespace.h
79713 @@ -43,7 +43,7 @@ struct pid_namespace {
79714 int hide_pid;
79715 int reboot; /* group exit code if this pidns was rebooted */
79716 unsigned int proc_inum;
79717 -};
79718 +} __randomize_layout;
79719
79720 extern struct pid_namespace init_pid_ns;
79721
79722 diff --git a/include/linux/pipe_fs_i.h b/include/linux/pipe_fs_i.h
79723 index ab57526..94598804 100644
79724 --- a/include/linux/pipe_fs_i.h
79725 +++ b/include/linux/pipe_fs_i.h
79726 @@ -47,10 +47,10 @@ struct pipe_inode_info {
79727 struct mutex mutex;
79728 wait_queue_head_t wait;
79729 unsigned int nrbufs, curbuf, buffers;
79730 - unsigned int readers;
79731 - unsigned int writers;
79732 - unsigned int files;
79733 - unsigned int waiting_writers;
79734 + atomic_t readers;
79735 + atomic_t writers;
79736 + atomic_t files;
79737 + atomic_t waiting_writers;
79738 unsigned int r_counter;
79739 unsigned int w_counter;
79740 struct page *tmp_page;
79741 diff --git a/include/linux/pm.h b/include/linux/pm.h
79742 index a224c7f..92d8a97 100644
79743 --- a/include/linux/pm.h
79744 +++ b/include/linux/pm.h
79745 @@ -576,6 +576,7 @@ extern int dev_pm_put_subsys_data(struct device *dev);
79746 struct dev_pm_domain {
79747 struct dev_pm_ops ops;
79748 };
79749 +typedef struct dev_pm_domain __no_const dev_pm_domain_no_const;
79750
79751 /*
79752 * The PM_EVENT_ messages are also used by drivers implementing the legacy
79753 diff --git a/include/linux/pm_domain.h b/include/linux/pm_domain.h
79754 index 7c1d252..c5c773e 100644
79755 --- a/include/linux/pm_domain.h
79756 +++ b/include/linux/pm_domain.h
79757 @@ -48,7 +48,7 @@ struct gpd_dev_ops {
79758
79759 struct gpd_cpu_data {
79760 unsigned int saved_exit_latency;
79761 - struct cpuidle_state *idle_state;
79762 + cpuidle_state_no_const *idle_state;
79763 };
79764
79765 struct generic_pm_domain {
79766 diff --git a/include/linux/pm_runtime.h b/include/linux/pm_runtime.h
79767 index 6fa7cea..7bf6415 100644
79768 --- a/include/linux/pm_runtime.h
79769 +++ b/include/linux/pm_runtime.h
79770 @@ -103,7 +103,7 @@ static inline bool pm_runtime_callbacks_present(struct device *dev)
79771
79772 static inline void pm_runtime_mark_last_busy(struct device *dev)
79773 {
79774 - ACCESS_ONCE(dev->power.last_busy) = jiffies;
79775 + ACCESS_ONCE_RW(dev->power.last_busy) = jiffies;
79776 }
79777
79778 #else /* !CONFIG_PM_RUNTIME */
79779 diff --git a/include/linux/pnp.h b/include/linux/pnp.h
79780 index 195aafc..49a7bc2 100644
79781 --- a/include/linux/pnp.h
79782 +++ b/include/linux/pnp.h
79783 @@ -297,7 +297,7 @@ static inline void pnp_set_drvdata(struct pnp_dev *pdev, void *data)
79784 struct pnp_fixup {
79785 char id[7];
79786 void (*quirk_function) (struct pnp_dev * dev); /* fixup function */
79787 -};
79788 +} __do_const;
79789
79790 /* config parameters */
79791 #define PNP_CONFIG_NORMAL 0x0001
79792 diff --git a/include/linux/poison.h b/include/linux/poison.h
79793 index 2110a81..13a11bb 100644
79794 --- a/include/linux/poison.h
79795 +++ b/include/linux/poison.h
79796 @@ -19,8 +19,8 @@
79797 * under normal circumstances, used to verify that nobody uses
79798 * non-initialized list entries.
79799 */
79800 -#define LIST_POISON1 ((void *) 0x00100100 + POISON_POINTER_DELTA)
79801 -#define LIST_POISON2 ((void *) 0x00200200 + POISON_POINTER_DELTA)
79802 +#define LIST_POISON1 ((void *) (long)0xFFFFFF01)
79803 +#define LIST_POISON2 ((void *) (long)0xFFFFFF02)
79804
79805 /********** include/linux/timer.h **********/
79806 /*
79807 diff --git a/include/linux/power/smartreflex.h b/include/linux/power/smartreflex.h
79808 index d8b187c3..9a9257a 100644
79809 --- a/include/linux/power/smartreflex.h
79810 +++ b/include/linux/power/smartreflex.h
79811 @@ -238,7 +238,7 @@ struct omap_sr_class_data {
79812 int (*notify)(struct omap_sr *sr, u32 status);
79813 u8 notify_flags;
79814 u8 class_type;
79815 -};
79816 +} __do_const;
79817
79818 /**
79819 * struct omap_sr_nvalue_table - Smartreflex n-target value info
79820 diff --git a/include/linux/ppp-comp.h b/include/linux/ppp-comp.h
79821 index 4ea1d37..80f4b33 100644
79822 --- a/include/linux/ppp-comp.h
79823 +++ b/include/linux/ppp-comp.h
79824 @@ -84,7 +84,7 @@ struct compressor {
79825 struct module *owner;
79826 /* Extra skb space needed by the compressor algorithm */
79827 unsigned int comp_extra;
79828 -};
79829 +} __do_const;
79830
79831 /*
79832 * The return value from decompress routine is the length of the
79833 diff --git a/include/linux/preempt.h b/include/linux/preempt.h
79834 index a3d9dc8..8af9922 100644
79835 --- a/include/linux/preempt.h
79836 +++ b/include/linux/preempt.h
79837 @@ -27,11 +27,16 @@ extern void preempt_count_sub(int val);
79838 #define preempt_count_dec_and_test() __preempt_count_dec_and_test()
79839 #endif
79840
79841 +#define raw_preempt_count_add(val) __preempt_count_add(val)
79842 +#define raw_preempt_count_sub(val) __preempt_count_sub(val)
79843 +
79844 #define __preempt_count_inc() __preempt_count_add(1)
79845 #define __preempt_count_dec() __preempt_count_sub(1)
79846
79847 #define preempt_count_inc() preempt_count_add(1)
79848 +#define raw_preempt_count_inc() raw_preempt_count_add(1)
79849 #define preempt_count_dec() preempt_count_sub(1)
79850 +#define raw_preempt_count_dec() raw_preempt_count_sub(1)
79851
79852 #ifdef CONFIG_PREEMPT_COUNT
79853
79854 @@ -41,6 +46,12 @@ do { \
79855 barrier(); \
79856 } while (0)
79857
79858 +#define raw_preempt_disable() \
79859 +do { \
79860 + raw_preempt_count_inc(); \
79861 + barrier(); \
79862 +} while (0)
79863 +
79864 #define sched_preempt_enable_no_resched() \
79865 do { \
79866 barrier(); \
79867 @@ -49,6 +60,12 @@ do { \
79868
79869 #define preempt_enable_no_resched() sched_preempt_enable_no_resched()
79870
79871 +#define raw_preempt_enable_no_resched() \
79872 +do { \
79873 + barrier(); \
79874 + raw_preempt_count_dec(); \
79875 +} while (0)
79876 +
79877 #ifdef CONFIG_PREEMPT
79878 #define preempt_enable() \
79879 do { \
79880 @@ -105,8 +122,10 @@ do { \
79881 * region.
79882 */
79883 #define preempt_disable() barrier()
79884 +#define raw_preempt_disable() barrier()
79885 #define sched_preempt_enable_no_resched() barrier()
79886 #define preempt_enable_no_resched() barrier()
79887 +#define raw_preempt_enable_no_resched() barrier()
79888 #define preempt_enable() barrier()
79889 #define preempt_check_resched() do { } while (0)
79890
79891 diff --git a/include/linux/printk.h b/include/linux/printk.h
79892 index 6949258..7c4730e 100644
79893 --- a/include/linux/printk.h
79894 +++ b/include/linux/printk.h
79895 @@ -106,6 +106,8 @@ static inline __printf(1, 2) __cold
79896 void early_printk(const char *s, ...) { }
79897 #endif
79898
79899 +extern int kptr_restrict;
79900 +
79901 #ifdef CONFIG_PRINTK
79902 asmlinkage __printf(5, 0)
79903 int vprintk_emit(int facility, int level,
79904 @@ -140,7 +142,6 @@ extern bool printk_timed_ratelimit(unsigned long *caller_jiffies,
79905
79906 extern int printk_delay_msec;
79907 extern int dmesg_restrict;
79908 -extern int kptr_restrict;
79909
79910 extern void wake_up_klogd(void);
79911
79912 diff --git a/include/linux/proc_fs.h b/include/linux/proc_fs.h
79913 index 608e60a..c26f864 100644
79914 --- a/include/linux/proc_fs.h
79915 +++ b/include/linux/proc_fs.h
79916 @@ -34,6 +34,19 @@ static inline struct proc_dir_entry *proc_create(
79917 return proc_create_data(name, mode, parent, proc_fops, NULL);
79918 }
79919
79920 +static inline struct proc_dir_entry *proc_create_grsec(const char *name, umode_t mode,
79921 + struct proc_dir_entry *parent, const struct file_operations *proc_fops)
79922 +{
79923 +#ifdef CONFIG_GRKERNSEC_PROC_USER
79924 + return proc_create_data(name, S_IRUSR, parent, proc_fops, NULL);
79925 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
79926 + return proc_create_data(name, S_IRUSR | S_IRGRP, parent, proc_fops, NULL);
79927 +#else
79928 + return proc_create_data(name, mode, parent, proc_fops, NULL);
79929 +#endif
79930 +}
79931 +
79932 +
79933 extern void proc_set_size(struct proc_dir_entry *, loff_t);
79934 extern void proc_set_user(struct proc_dir_entry *, kuid_t, kgid_t);
79935 extern void *PDE_DATA(const struct inode *);
79936 diff --git a/include/linux/proc_ns.h b/include/linux/proc_ns.h
79937 index 34a1e10..70f6bde 100644
79938 --- a/include/linux/proc_ns.h
79939 +++ b/include/linux/proc_ns.h
79940 @@ -14,7 +14,7 @@ struct proc_ns_operations {
79941 void (*put)(void *ns);
79942 int (*install)(struct nsproxy *nsproxy, void *ns);
79943 unsigned int (*inum)(void *ns);
79944 -};
79945 +} __do_const __randomize_layout;
79946
79947 struct proc_ns {
79948 void *ns;
79949 diff --git a/include/linux/quota.h b/include/linux/quota.h
79950 index cc7494a..1e27036 100644
79951 --- a/include/linux/quota.h
79952 +++ b/include/linux/quota.h
79953 @@ -70,7 +70,7 @@ struct kqid { /* Type in which we store the quota identifier */
79954
79955 extern bool qid_eq(struct kqid left, struct kqid right);
79956 extern bool qid_lt(struct kqid left, struct kqid right);
79957 -extern qid_t from_kqid(struct user_namespace *to, struct kqid qid);
79958 +extern qid_t from_kqid(struct user_namespace *to, struct kqid qid) __intentional_overflow(-1);
79959 extern qid_t from_kqid_munged(struct user_namespace *to, struct kqid qid);
79960 extern bool qid_valid(struct kqid qid);
79961
79962 diff --git a/include/linux/random.h b/include/linux/random.h
79963 index 4002b3d..d5ad855 100644
79964 --- a/include/linux/random.h
79965 +++ b/include/linux/random.h
79966 @@ -10,9 +10,19 @@
79967
79968
79969 extern void add_device_randomness(const void *, unsigned int);
79970 +
79971 +static inline void add_latent_entropy(void)
79972 +{
79973 +
79974 +#ifdef LATENT_ENTROPY_PLUGIN
79975 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
79976 +#endif
79977 +
79978 +}
79979 +
79980 extern void add_input_randomness(unsigned int type, unsigned int code,
79981 - unsigned int value);
79982 -extern void add_interrupt_randomness(int irq, int irq_flags);
79983 + unsigned int value) __latent_entropy;
79984 +extern void add_interrupt_randomness(int irq, int irq_flags) __latent_entropy;
79985
79986 extern void get_random_bytes(void *buf, int nbytes);
79987 extern void get_random_bytes_arch(void *buf, int nbytes);
79988 @@ -23,10 +33,10 @@ extern int random_int_secret_init(void);
79989 extern const struct file_operations random_fops, urandom_fops;
79990 #endif
79991
79992 -unsigned int get_random_int(void);
79993 +unsigned int __intentional_overflow(-1) get_random_int(void);
79994 unsigned long randomize_range(unsigned long start, unsigned long end, unsigned long len);
79995
79996 -u32 prandom_u32(void);
79997 +u32 prandom_u32(void) __intentional_overflow(-1);
79998 void prandom_bytes(void *buf, int nbytes);
79999 void prandom_seed(u32 seed);
80000 void prandom_reseed_late(void);
80001 @@ -38,6 +48,11 @@ struct rnd_state {
80002 u32 prandom_u32_state(struct rnd_state *state);
80003 void prandom_bytes_state(struct rnd_state *state, void *buf, int nbytes);
80004
80005 +static inline unsigned long __intentional_overflow(-1) pax_get_random_long(void)
80006 +{
80007 + return prandom_u32() + (sizeof(long) > 4 ? (unsigned long)prandom_u32() << 32 : 0);
80008 +}
80009 +
80010 /*
80011 * Handle minimum values for seeds
80012 */
80013 diff --git a/include/linux/rbtree_augmented.h b/include/linux/rbtree_augmented.h
80014 index fea49b5..2ac22bb 100644
80015 --- a/include/linux/rbtree_augmented.h
80016 +++ b/include/linux/rbtree_augmented.h
80017 @@ -80,7 +80,9 @@ rbname ## _rotate(struct rb_node *rb_old, struct rb_node *rb_new) \
80018 old->rbaugmented = rbcompute(old); \
80019 } \
80020 rbstatic const struct rb_augment_callbacks rbname = { \
80021 - rbname ## _propagate, rbname ## _copy, rbname ## _rotate \
80022 + .propagate = rbname ## _propagate, \
80023 + .copy = rbname ## _copy, \
80024 + .rotate = rbname ## _rotate \
80025 };
80026
80027
80028 diff --git a/include/linux/rculist.h b/include/linux/rculist.h
80029 index 45a0a9e..e83788e 100644
80030 --- a/include/linux/rculist.h
80031 +++ b/include/linux/rculist.h
80032 @@ -29,8 +29,8 @@
80033 */
80034 static inline void INIT_LIST_HEAD_RCU(struct list_head *list)
80035 {
80036 - ACCESS_ONCE(list->next) = list;
80037 - ACCESS_ONCE(list->prev) = list;
80038 + ACCESS_ONCE_RW(list->next) = list;
80039 + ACCESS_ONCE_RW(list->prev) = list;
80040 }
80041
80042 /*
80043 @@ -59,6 +59,9 @@ extern void __list_add_rcu(struct list_head *new,
80044 struct list_head *prev, struct list_head *next);
80045 #endif
80046
80047 +extern void __pax_list_add_rcu(struct list_head *new,
80048 + struct list_head *prev, struct list_head *next);
80049 +
80050 /**
80051 * list_add_rcu - add a new entry to rcu-protected list
80052 * @new: new entry to be added
80053 @@ -80,6 +83,11 @@ static inline void list_add_rcu(struct list_head *new, struct list_head *head)
80054 __list_add_rcu(new, head, head->next);
80055 }
80056
80057 +static inline void pax_list_add_rcu(struct list_head *new, struct list_head *head)
80058 +{
80059 + __pax_list_add_rcu(new, head, head->next);
80060 +}
80061 +
80062 /**
80063 * list_add_tail_rcu - add a new entry to rcu-protected list
80064 * @new: new entry to be added
80065 @@ -102,6 +110,12 @@ static inline void list_add_tail_rcu(struct list_head *new,
80066 __list_add_rcu(new, head->prev, head);
80067 }
80068
80069 +static inline void pax_list_add_tail_rcu(struct list_head *new,
80070 + struct list_head *head)
80071 +{
80072 + __pax_list_add_rcu(new, head->prev, head);
80073 +}
80074 +
80075 /**
80076 * list_del_rcu - deletes entry from list without re-initialization
80077 * @entry: the element to delete from the list.
80078 @@ -132,6 +146,8 @@ static inline void list_del_rcu(struct list_head *entry)
80079 entry->prev = LIST_POISON2;
80080 }
80081
80082 +extern void pax_list_del_rcu(struct list_head *entry);
80083 +
80084 /**
80085 * hlist_del_init_rcu - deletes entry from hash list with re-initialization
80086 * @n: the element to delete from the hash list.
80087 diff --git a/include/linux/reboot.h b/include/linux/reboot.h
80088 index 9e7db9e..7d4fd72 100644
80089 --- a/include/linux/reboot.h
80090 +++ b/include/linux/reboot.h
80091 @@ -44,9 +44,9 @@ extern int unregister_reboot_notifier(struct notifier_block *);
80092 */
80093
80094 extern void migrate_to_reboot_cpu(void);
80095 -extern void machine_restart(char *cmd);
80096 -extern void machine_halt(void);
80097 -extern void machine_power_off(void);
80098 +extern void machine_restart(char *cmd) __noreturn;
80099 +extern void machine_halt(void) __noreturn;
80100 +extern void machine_power_off(void) __noreturn;
80101
80102 extern void machine_shutdown(void);
80103 struct pt_regs;
80104 @@ -57,9 +57,9 @@ extern void machine_crash_shutdown(struct pt_regs *);
80105 */
80106
80107 extern void kernel_restart_prepare(char *cmd);
80108 -extern void kernel_restart(char *cmd);
80109 -extern void kernel_halt(void);
80110 -extern void kernel_power_off(void);
80111 +extern void kernel_restart(char *cmd) __noreturn;
80112 +extern void kernel_halt(void) __noreturn;
80113 +extern void kernel_power_off(void) __noreturn;
80114
80115 extern int C_A_D; /* for sysctl */
80116 void ctrl_alt_del(void);
80117 @@ -73,7 +73,7 @@ extern int orderly_poweroff(bool force);
80118 * Emergency restart, callable from an interrupt handler.
80119 */
80120
80121 -extern void emergency_restart(void);
80122 +extern void emergency_restart(void) __noreturn;
80123 #include <asm/emergency-restart.h>
80124
80125 #endif /* _LINUX_REBOOT_H */
80126 diff --git a/include/linux/regset.h b/include/linux/regset.h
80127 index 8e0c9fe..ac4d221 100644
80128 --- a/include/linux/regset.h
80129 +++ b/include/linux/regset.h
80130 @@ -161,7 +161,8 @@ struct user_regset {
80131 unsigned int align;
80132 unsigned int bias;
80133 unsigned int core_note_type;
80134 -};
80135 +} __do_const;
80136 +typedef struct user_regset __no_const user_regset_no_const;
80137
80138 /**
80139 * struct user_regset_view - available regsets
80140 diff --git a/include/linux/relay.h b/include/linux/relay.h
80141 index d7c8359..818daf5 100644
80142 --- a/include/linux/relay.h
80143 +++ b/include/linux/relay.h
80144 @@ -157,7 +157,7 @@ struct rchan_callbacks
80145 * The callback should return 0 if successful, negative if not.
80146 */
80147 int (*remove_buf_file)(struct dentry *dentry);
80148 -};
80149 +} __no_const;
80150
80151 /*
80152 * CONFIG_RELAY kernel API, kernel/relay.c
80153 diff --git a/include/linux/rio.h b/include/linux/rio.h
80154 index b71d573..2f940bd 100644
80155 --- a/include/linux/rio.h
80156 +++ b/include/linux/rio.h
80157 @@ -355,7 +355,7 @@ struct rio_ops {
80158 int (*map_inb)(struct rio_mport *mport, dma_addr_t lstart,
80159 u64 rstart, u32 size, u32 flags);
80160 void (*unmap_inb)(struct rio_mport *mport, dma_addr_t lstart);
80161 -};
80162 +} __no_const;
80163
80164 #define RIO_RESOURCE_MEM 0x00000100
80165 #define RIO_RESOURCE_DOORBELL 0x00000200
80166 diff --git a/include/linux/rmap.h b/include/linux/rmap.h
80167 index 6dacb93..6174423 100644
80168 --- a/include/linux/rmap.h
80169 +++ b/include/linux/rmap.h
80170 @@ -145,8 +145,8 @@ static inline void anon_vma_unlock_read(struct anon_vma *anon_vma)
80171 void anon_vma_init(void); /* create anon_vma_cachep */
80172 int anon_vma_prepare(struct vm_area_struct *);
80173 void unlink_anon_vmas(struct vm_area_struct *);
80174 -int anon_vma_clone(struct vm_area_struct *, struct vm_area_struct *);
80175 -int anon_vma_fork(struct vm_area_struct *, struct vm_area_struct *);
80176 +int anon_vma_clone(struct vm_area_struct *, const struct vm_area_struct *);
80177 +int anon_vma_fork(struct vm_area_struct *, const struct vm_area_struct *);
80178
80179 static inline void anon_vma_merge(struct vm_area_struct *vma,
80180 struct vm_area_struct *next)
80181 diff --git a/include/linux/sched.h b/include/linux/sched.h
80182 index 53f97eb..1d90705 100644
80183 --- a/include/linux/sched.h
80184 +++ b/include/linux/sched.h
80185 @@ -63,6 +63,7 @@ struct bio_list;
80186 struct fs_struct;
80187 struct perf_event_context;
80188 struct blk_plug;
80189 +struct linux_binprm;
80190
80191 /*
80192 * List of flags we want to share for kernel threads,
80193 @@ -304,7 +305,7 @@ extern char __sched_text_start[], __sched_text_end[];
80194 extern int in_sched_functions(unsigned long addr);
80195
80196 #define MAX_SCHEDULE_TIMEOUT LONG_MAX
80197 -extern signed long schedule_timeout(signed long timeout);
80198 +extern signed long schedule_timeout(signed long timeout) __intentional_overflow(-1);
80199 extern signed long schedule_timeout_interruptible(signed long timeout);
80200 extern signed long schedule_timeout_killable(signed long timeout);
80201 extern signed long schedule_timeout_uninterruptible(signed long timeout);
80202 @@ -315,6 +316,19 @@ struct nsproxy;
80203 struct user_namespace;
80204
80205 #ifdef CONFIG_MMU
80206 +
80207 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
80208 +extern unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags);
80209 +#else
80210 +static inline unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
80211 +{
80212 + return 0;
80213 +}
80214 +#endif
80215 +
80216 +extern bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset);
80217 +extern unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset);
80218 +
80219 extern void arch_pick_mmap_layout(struct mm_struct *mm);
80220 extern unsigned long
80221 arch_get_unmapped_area(struct file *, unsigned long, unsigned long,
80222 @@ -600,6 +614,17 @@ struct signal_struct {
80223 #ifdef CONFIG_TASKSTATS
80224 struct taskstats *stats;
80225 #endif
80226 +
80227 +#ifdef CONFIG_GRKERNSEC
80228 + u32 curr_ip;
80229 + u32 saved_ip;
80230 + u32 gr_saddr;
80231 + u32 gr_daddr;
80232 + u16 gr_sport;
80233 + u16 gr_dport;
80234 + u8 used_accept:1;
80235 +#endif
80236 +
80237 #ifdef CONFIG_AUDIT
80238 unsigned audit_tty;
80239 unsigned audit_tty_log_passwd;
80240 @@ -626,7 +651,7 @@ struct signal_struct {
80241 struct mutex cred_guard_mutex; /* guard against foreign influences on
80242 * credential calculations
80243 * (notably. ptrace) */
80244 -};
80245 +} __randomize_layout;
80246
80247 /*
80248 * Bits in flags field of signal_struct.
80249 @@ -680,6 +705,14 @@ struct user_struct {
80250 struct key *session_keyring; /* UID's default session keyring */
80251 #endif
80252
80253 +#ifdef CONFIG_GRKERNSEC_KERN_LOCKOUT
80254 + unsigned char kernel_banned;
80255 +#endif
80256 +#ifdef CONFIG_GRKERNSEC_BRUTE
80257 + unsigned char suid_banned;
80258 + unsigned long suid_ban_expires;
80259 +#endif
80260 +
80261 /* Hash table maintenance information */
80262 struct hlist_node uidhash_node;
80263 kuid_t uid;
80264 @@ -687,7 +720,7 @@ struct user_struct {
80265 #ifdef CONFIG_PERF_EVENTS
80266 atomic_long_t locked_vm;
80267 #endif
80268 -};
80269 +} __randomize_layout;
80270
80271 extern int uids_sysfs_init(void);
80272
80273 @@ -1162,8 +1195,8 @@ struct task_struct {
80274 struct list_head thread_group;
80275
80276 struct completion *vfork_done; /* for vfork() */
80277 - int __user *set_child_tid; /* CLONE_CHILD_SETTID */
80278 - int __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
80279 + pid_t __user *set_child_tid; /* CLONE_CHILD_SETTID */
80280 + pid_t __user *clear_child_tid; /* CLONE_CHILD_CLEARTID */
80281
80282 cputime_t utime, stime, utimescaled, stimescaled;
80283 cputime_t gtime;
80284 @@ -1188,11 +1221,6 @@ struct task_struct {
80285 struct task_cputime cputime_expires;
80286 struct list_head cpu_timers[3];
80287
80288 -/* process credentials */
80289 - const struct cred __rcu *real_cred; /* objective and real subjective task
80290 - * credentials (COW) */
80291 - const struct cred __rcu *cred; /* effective (overridable) subjective task
80292 - * credentials (COW) */
80293 char comm[TASK_COMM_LEN]; /* executable name excluding path
80294 - access with [gs]et_task_comm (which lock
80295 it with task_lock())
80296 @@ -1209,6 +1237,10 @@ struct task_struct {
80297 #endif
80298 /* CPU-specific state of this task */
80299 struct thread_struct thread;
80300 +/* thread_info moved to task_struct */
80301 +#ifdef CONFIG_X86
80302 + struct thread_info tinfo;
80303 +#endif
80304 /* filesystem information */
80305 struct fs_struct *fs;
80306 /* open file information */
80307 @@ -1282,6 +1314,10 @@ struct task_struct {
80308 gfp_t lockdep_reclaim_gfp;
80309 #endif
80310
80311 +/* process credentials */
80312 + const struct cred __rcu *real_cred; /* objective and real subjective task
80313 + * credentials (COW) */
80314 +
80315 /* journalling filesystem info */
80316 void *journal_info;
80317
80318 @@ -1320,6 +1356,10 @@ struct task_struct {
80319 /* cg_list protected by css_set_lock and tsk->alloc_lock */
80320 struct list_head cg_list;
80321 #endif
80322 +
80323 + const struct cred __rcu *cred; /* effective (overridable) subjective task
80324 + * credentials (COW) */
80325 +
80326 #ifdef CONFIG_FUTEX
80327 struct robust_list_head __user *robust_list;
80328 #ifdef CONFIG_COMPAT
80329 @@ -1454,7 +1494,78 @@ struct task_struct {
80330 unsigned int sequential_io;
80331 unsigned int sequential_io_avg;
80332 #endif
80333 -};
80334 +
80335 +#ifdef CONFIG_GRKERNSEC
80336 + /* grsecurity */
80337 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
80338 + u64 exec_id;
80339 +#endif
80340 +#ifdef CONFIG_GRKERNSEC_SETXID
80341 + const struct cred *delayed_cred;
80342 +#endif
80343 + struct dentry *gr_chroot_dentry;
80344 + struct acl_subject_label *acl;
80345 + struct acl_subject_label *tmpacl;
80346 + struct acl_role_label *role;
80347 + struct file *exec_file;
80348 + unsigned long brute_expires;
80349 + u16 acl_role_id;
80350 + u8 inherited;
80351 + /* is this the task that authenticated to the special role */
80352 + u8 acl_sp_role;
80353 + u8 is_writable;
80354 + u8 brute;
80355 + u8 gr_is_chrooted;
80356 +#endif
80357 +
80358 +} __randomize_layout;
80359 +
80360 +#define MF_PAX_PAGEEXEC 0x01000000 /* Paging based non-executable pages */
80361 +#define MF_PAX_EMUTRAMP 0x02000000 /* Emulate trampolines */
80362 +#define MF_PAX_MPROTECT 0x04000000 /* Restrict mprotect() */
80363 +#define MF_PAX_RANDMMAP 0x08000000 /* Randomize mmap() base */
80364 +/*#define MF_PAX_RANDEXEC 0x10000000*/ /* Randomize ET_EXEC base */
80365 +#define MF_PAX_SEGMEXEC 0x20000000 /* Segmentation based non-executable pages */
80366 +
80367 +#ifdef CONFIG_PAX_SOFTMODE
80368 +extern int pax_softmode;
80369 +#endif
80370 +
80371 +extern int pax_check_flags(unsigned long *);
80372 +#define PAX_PARSE_FLAGS_FALLBACK (~0UL)
80373 +
80374 +/* if tsk != current then task_lock must be held on it */
80375 +#if defined(CONFIG_PAX_NOEXEC) || defined(CONFIG_PAX_ASLR)
80376 +static inline unsigned long pax_get_flags(struct task_struct *tsk)
80377 +{
80378 + if (likely(tsk->mm))
80379 + return tsk->mm->pax_flags;
80380 + else
80381 + return 0UL;
80382 +}
80383 +
80384 +/* if tsk != current then task_lock must be held on it */
80385 +static inline long pax_set_flags(struct task_struct *tsk, unsigned long flags)
80386 +{
80387 + if (likely(tsk->mm)) {
80388 + tsk->mm->pax_flags = flags;
80389 + return 0;
80390 + }
80391 + return -EINVAL;
80392 +}
80393 +#endif
80394 +
80395 +#ifdef CONFIG_PAX_HAVE_ACL_FLAGS
80396 +extern void pax_set_initial_flags(struct linux_binprm *bprm);
80397 +#elif defined(CONFIG_PAX_HOOK_ACL_FLAGS)
80398 +extern void (*pax_set_initial_flags_func)(struct linux_binprm *bprm);
80399 +#endif
80400 +
80401 +struct path;
80402 +extern char *pax_get_path(const struct path *path, char *buf, int buflen);
80403 +extern void pax_report_fault(struct pt_regs *regs, void *pc, void *sp);
80404 +extern void pax_report_insns(struct pt_regs *regs, void *pc, void *sp);
80405 +extern void pax_report_refcount_overflow(struct pt_regs *regs);
80406
80407 /* Future-safe accessor for struct task_struct's cpus_allowed. */
80408 #define tsk_cpus_allowed(tsk) (&(tsk)->cpus_allowed)
80409 @@ -1531,7 +1642,7 @@ struct pid_namespace;
80410 pid_t __task_pid_nr_ns(struct task_struct *task, enum pid_type type,
80411 struct pid_namespace *ns);
80412
80413 -static inline pid_t task_pid_nr(struct task_struct *tsk)
80414 +static inline pid_t task_pid_nr(const struct task_struct *tsk)
80415 {
80416 return tsk->pid;
80417 }
80418 @@ -1981,7 +2092,9 @@ void yield(void);
80419 extern struct exec_domain default_exec_domain;
80420
80421 union thread_union {
80422 +#ifndef CONFIG_X86
80423 struct thread_info thread_info;
80424 +#endif
80425 unsigned long stack[THREAD_SIZE/sizeof(long)];
80426 };
80427
80428 @@ -2014,6 +2127,7 @@ extern struct pid_namespace init_pid_ns;
80429 */
80430
80431 extern struct task_struct *find_task_by_vpid(pid_t nr);
80432 +extern struct task_struct *find_task_by_vpid_unrestricted(pid_t nr);
80433 extern struct task_struct *find_task_by_pid_ns(pid_t nr,
80434 struct pid_namespace *ns);
80435
80436 @@ -2178,7 +2292,7 @@ extern void __cleanup_sighand(struct sighand_struct *);
80437 extern void exit_itimers(struct signal_struct *);
80438 extern void flush_itimer_signals(void);
80439
80440 -extern void do_group_exit(int);
80441 +extern __noreturn void do_group_exit(int);
80442
80443 extern int allow_signal(int);
80444 extern int disallow_signal(int);
80445 @@ -2369,9 +2483,9 @@ static inline unsigned long *end_of_stack(struct task_struct *p)
80446
80447 #endif
80448
80449 -static inline int object_is_on_stack(void *obj)
80450 +static inline int object_starts_on_stack(void *obj)
80451 {
80452 - void *stack = task_stack_page(current);
80453 + const void *stack = task_stack_page(current);
80454
80455 return (obj >= stack) && (obj < (stack + THREAD_SIZE));
80456 }
80457 diff --git a/include/linux/sched/sysctl.h b/include/linux/sched/sysctl.h
80458 index e3347c5..f682891 100644
80459 --- a/include/linux/sched/sysctl.h
80460 +++ b/include/linux/sched/sysctl.h
80461 @@ -30,6 +30,7 @@ enum { sysctl_hung_task_timeout_secs = 0 };
80462 #define DEFAULT_MAX_MAP_COUNT (USHRT_MAX - MAPCOUNT_ELF_CORE_MARGIN)
80463
80464 extern int sysctl_max_map_count;
80465 +extern unsigned long sysctl_heap_stack_gap;
80466
80467 extern unsigned int sysctl_sched_latency;
80468 extern unsigned int sysctl_sched_min_granularity;
80469 diff --git a/include/linux/security.h b/include/linux/security.h
80470 index 5623a7f..b352409 100644
80471 --- a/include/linux/security.h
80472 +++ b/include/linux/security.h
80473 @@ -27,6 +27,7 @@
80474 #include <linux/slab.h>
80475 #include <linux/err.h>
80476 #include <linux/string.h>
80477 +#include <linux/grsecurity.h>
80478
80479 struct linux_binprm;
80480 struct cred;
80481 @@ -116,8 +117,6 @@ struct seq_file;
80482
80483 extern int cap_netlink_send(struct sock *sk, struct sk_buff *skb);
80484
80485 -void reset_security_ops(void);
80486 -
80487 #ifdef CONFIG_MMU
80488 extern unsigned long mmap_min_addr;
80489 extern unsigned long dac_mmap_min_addr;
80490 diff --git a/include/linux/semaphore.h b/include/linux/semaphore.h
80491 index dc368b8..e895209 100644
80492 --- a/include/linux/semaphore.h
80493 +++ b/include/linux/semaphore.h
80494 @@ -37,7 +37,7 @@ static inline void sema_init(struct semaphore *sem, int val)
80495 }
80496
80497 extern void down(struct semaphore *sem);
80498 -extern int __must_check down_interruptible(struct semaphore *sem);
80499 +extern int __must_check down_interruptible(struct semaphore *sem) __intentional_overflow(-1);
80500 extern int __must_check down_killable(struct semaphore *sem);
80501 extern int __must_check down_trylock(struct semaphore *sem);
80502 extern int __must_check down_timeout(struct semaphore *sem, long jiffies);
80503 diff --git a/include/linux/seq_file.h b/include/linux/seq_file.h
80504 index 52e0097..09625ef 100644
80505 --- a/include/linux/seq_file.h
80506 +++ b/include/linux/seq_file.h
80507 @@ -27,6 +27,9 @@ struct seq_file {
80508 struct mutex lock;
80509 const struct seq_operations *op;
80510 int poll_event;
80511 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
80512 + u64 exec_id;
80513 +#endif
80514 #ifdef CONFIG_USER_NS
80515 struct user_namespace *user_ns;
80516 #endif
80517 @@ -39,6 +42,7 @@ struct seq_operations {
80518 void * (*next) (struct seq_file *m, void *v, loff_t *pos);
80519 int (*show) (struct seq_file *m, void *v);
80520 };
80521 +typedef struct seq_operations __no_const seq_operations_no_const;
80522
80523 #define SEQ_SKIP 1
80524
80525 diff --git a/include/linux/shm.h b/include/linux/shm.h
80526 index 429c199..4d42e38 100644
80527 --- a/include/linux/shm.h
80528 +++ b/include/linux/shm.h
80529 @@ -21,6 +21,10 @@ struct shmid_kernel /* private to the kernel */
80530
80531 /* The task created the shm object. NULL if the task is dead. */
80532 struct task_struct *shm_creator;
80533 +#ifdef CONFIG_GRKERNSEC
80534 + time_t shm_createtime;
80535 + pid_t shm_lapid;
80536 +#endif
80537 };
80538
80539 /* shm_mode upper byte flags */
80540 diff --git a/include/linux/skbuff.h b/include/linux/skbuff.h
80541 index 6f69b3f..71ac613 100644
80542 --- a/include/linux/skbuff.h
80543 +++ b/include/linux/skbuff.h
80544 @@ -643,7 +643,7 @@ bool skb_try_coalesce(struct sk_buff *to, struct sk_buff *from,
80545 struct sk_buff *__alloc_skb(unsigned int size, gfp_t priority, int flags,
80546 int node);
80547 struct sk_buff *build_skb(void *data, unsigned int frag_size);
80548 -static inline struct sk_buff *alloc_skb(unsigned int size,
80549 +static inline struct sk_buff * __intentional_overflow(0) alloc_skb(unsigned int size,
80550 gfp_t priority)
80551 {
80552 return __alloc_skb(size, priority, 0, NUMA_NO_NODE);
80553 @@ -750,7 +750,7 @@ static inline struct skb_shared_hwtstamps *skb_hwtstamps(struct sk_buff *skb)
80554 */
80555 static inline int skb_queue_empty(const struct sk_buff_head *list)
80556 {
80557 - return list->next == (struct sk_buff *)list;
80558 + return list->next == (const struct sk_buff *)list;
80559 }
80560
80561 /**
80562 @@ -763,7 +763,7 @@ static inline int skb_queue_empty(const struct sk_buff_head *list)
80563 static inline bool skb_queue_is_last(const struct sk_buff_head *list,
80564 const struct sk_buff *skb)
80565 {
80566 - return skb->next == (struct sk_buff *)list;
80567 + return skb->next == (const struct sk_buff *)list;
80568 }
80569
80570 /**
80571 @@ -776,7 +776,7 @@ static inline bool skb_queue_is_last(const struct sk_buff_head *list,
80572 static inline bool skb_queue_is_first(const struct sk_buff_head *list,
80573 const struct sk_buff *skb)
80574 {
80575 - return skb->prev == (struct sk_buff *)list;
80576 + return skb->prev == (const struct sk_buff *)list;
80577 }
80578
80579 /**
80580 @@ -1686,7 +1686,7 @@ static inline u32 skb_inner_network_header_len(const struct sk_buff *skb)
80581 return skb->inner_transport_header - skb->inner_network_header;
80582 }
80583
80584 -static inline int skb_network_offset(const struct sk_buff *skb)
80585 +static inline int __intentional_overflow(0) skb_network_offset(const struct sk_buff *skb)
80586 {
80587 return skb_network_header(skb) - skb->data;
80588 }
80589 @@ -1746,7 +1746,7 @@ static inline int pskb_network_may_pull(struct sk_buff *skb, unsigned int len)
80590 * NET_IP_ALIGN(2) + ethernet_header(14) + IP_header(20/40) + ports(8)
80591 */
80592 #ifndef NET_SKB_PAD
80593 -#define NET_SKB_PAD max(32, L1_CACHE_BYTES)
80594 +#define NET_SKB_PAD max(_AC(32,UL), L1_CACHE_BYTES)
80595 #endif
80596
80597 int ___pskb_trim(struct sk_buff *skb, unsigned int len);
80598 @@ -2345,7 +2345,7 @@ struct sk_buff *skb_recv_datagram(struct sock *sk, unsigned flags, int noblock,
80599 int *err);
80600 unsigned int datagram_poll(struct file *file, struct socket *sock,
80601 struct poll_table_struct *wait);
80602 -int skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
80603 +int __intentional_overflow(0) skb_copy_datagram_iovec(const struct sk_buff *from, int offset,
80604 struct iovec *to, int size);
80605 int skb_copy_and_csum_datagram_iovec(struct sk_buff *skb, int hlen,
80606 struct iovec *iov);
80607 @@ -2617,6 +2617,9 @@ static inline void nf_reset(struct sk_buff *skb)
80608 nf_bridge_put(skb->nf_bridge);
80609 skb->nf_bridge = NULL;
80610 #endif
80611 +#if IS_ENABLED(CONFIG_NETFILTER_XT_TARGET_TRACE)
80612 + skb->nf_trace = 0;
80613 +#endif
80614 }
80615
80616 static inline void nf_reset_trace(struct sk_buff *skb)
80617 diff --git a/include/linux/slab.h b/include/linux/slab.h
80618 index 1e2f4fe..df49ca6 100644
80619 --- a/include/linux/slab.h
80620 +++ b/include/linux/slab.h
80621 @@ -14,15 +14,29 @@
80622 #include <linux/gfp.h>
80623 #include <linux/types.h>
80624 #include <linux/workqueue.h>
80625 -
80626 +#include <linux/err.h>
80627
80628 /*
80629 * Flags to pass to kmem_cache_create().
80630 * The ones marked DEBUG are only valid if CONFIG_SLAB_DEBUG is set.
80631 */
80632 #define SLAB_DEBUG_FREE 0x00000100UL /* DEBUG: Perform (expensive) checks on free */
80633 +
80634 +#ifdef CONFIG_PAX_USERCOPY_SLABS
80635 +#define SLAB_USERCOPY 0x00000200UL /* PaX: Allow copying objs to/from userland */
80636 +#else
80637 +#define SLAB_USERCOPY 0x00000000UL
80638 +#endif
80639 +
80640 #define SLAB_RED_ZONE 0x00000400UL /* DEBUG: Red zone objs in a cache */
80641 #define SLAB_POISON 0x00000800UL /* DEBUG: Poison objects */
80642 +
80643 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
80644 +#define SLAB_NO_SANITIZE 0x00001000UL /* PaX: Do not sanitize objs on free */
80645 +#else
80646 +#define SLAB_NO_SANITIZE 0x00000000UL
80647 +#endif
80648 +
80649 #define SLAB_HWCACHE_ALIGN 0x00002000UL /* Align objs on cache lines */
80650 #define SLAB_CACHE_DMA 0x00004000UL /* Use GFP_DMA memory */
80651 #define SLAB_STORE_USER 0x00010000UL /* DEBUG: Store the last owner for bug hunting */
80652 @@ -98,10 +112,13 @@
80653 * ZERO_SIZE_PTR can be passed to kfree though in the same way that NULL can.
80654 * Both make kfree a no-op.
80655 */
80656 -#define ZERO_SIZE_PTR ((void *)16)
80657 +#define ZERO_SIZE_PTR \
80658 +({ \
80659 + BUILD_BUG_ON(!(MAX_ERRNO & ~PAGE_MASK));\
80660 + (void *)(-MAX_ERRNO-1L); \
80661 +})
80662
80663 -#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) <= \
80664 - (unsigned long)ZERO_SIZE_PTR)
80665 +#define ZERO_OR_NULL_PTR(x) ((unsigned long)(x) - 1 >= (unsigned long)ZERO_SIZE_PTR - 1)
80666
80667 #include <linux/kmemleak.h>
80668
80669 @@ -142,6 +159,8 @@ void * __must_check krealloc(const void *, size_t, gfp_t);
80670 void kfree(const void *);
80671 void kzfree(const void *);
80672 size_t ksize(const void *);
80673 +const char *check_heap_object(const void *ptr, unsigned long n);
80674 +bool is_usercopy_object(const void *ptr);
80675
80676 /*
80677 * Some archs want to perform DMA into kmalloc caches and need a guaranteed
80678 @@ -174,7 +193,7 @@ struct kmem_cache {
80679 unsigned int align; /* Alignment as calculated */
80680 unsigned long flags; /* Active flags on the slab */
80681 const char *name; /* Slab name for sysfs */
80682 - int refcount; /* Use counter */
80683 + atomic_t refcount; /* Use counter */
80684 void (*ctor)(void *); /* Called on object slot creation */
80685 struct list_head list; /* List of all slab caches on the system */
80686 };
80687 @@ -248,6 +267,10 @@ extern struct kmem_cache *kmalloc_caches[KMALLOC_SHIFT_HIGH + 1];
80688 extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
80689 #endif
80690
80691 +#ifdef CONFIG_PAX_USERCOPY_SLABS
80692 +extern struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
80693 +#endif
80694 +
80695 /*
80696 * Figure out which kmalloc slab an allocation of a certain size
80697 * belongs to.
80698 @@ -256,7 +279,7 @@ extern struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
80699 * 2 = 120 .. 192 bytes
80700 * n = 2^(n-1) .. 2^n -1
80701 */
80702 -static __always_inline int kmalloc_index(size_t size)
80703 +static __always_inline __size_overflow(1) int kmalloc_index(size_t size)
80704 {
80705 if (!size)
80706 return 0;
80707 @@ -299,11 +322,11 @@ static __always_inline int kmalloc_index(size_t size)
80708 }
80709 #endif /* !CONFIG_SLOB */
80710
80711 -void *__kmalloc(size_t size, gfp_t flags);
80712 +void *__kmalloc(size_t size, gfp_t flags) __alloc_size(1);
80713 void *kmem_cache_alloc(struct kmem_cache *, gfp_t flags);
80714
80715 #ifdef CONFIG_NUMA
80716 -void *__kmalloc_node(size_t size, gfp_t flags, int node);
80717 +void *__kmalloc_node(size_t size, gfp_t flags, int node) __alloc_size(1);
80718 void *kmem_cache_alloc_node(struct kmem_cache *, gfp_t flags, int node);
80719 #else
80720 static __always_inline void *__kmalloc_node(size_t size, gfp_t flags, int node)
80721 diff --git a/include/linux/slab_def.h b/include/linux/slab_def.h
80722 index 09bfffb..4fc80fb 100644
80723 --- a/include/linux/slab_def.h
80724 +++ b/include/linux/slab_def.h
80725 @@ -36,7 +36,7 @@ struct kmem_cache {
80726 /* 4) cache creation/removal */
80727 const char *name;
80728 struct list_head list;
80729 - int refcount;
80730 + atomic_t refcount;
80731 int object_size;
80732 int align;
80733
80734 @@ -52,10 +52,14 @@ struct kmem_cache {
80735 unsigned long node_allocs;
80736 unsigned long node_frees;
80737 unsigned long node_overflow;
80738 - atomic_t allochit;
80739 - atomic_t allocmiss;
80740 - atomic_t freehit;
80741 - atomic_t freemiss;
80742 + atomic_unchecked_t allochit;
80743 + atomic_unchecked_t allocmiss;
80744 + atomic_unchecked_t freehit;
80745 + atomic_unchecked_t freemiss;
80746 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
80747 + atomic_unchecked_t sanitized;
80748 + atomic_unchecked_t not_sanitized;
80749 +#endif
80750
80751 /*
80752 * If debugging is enabled, then the allocator can add additional
80753 diff --git a/include/linux/slub_def.h b/include/linux/slub_def.h
80754 index f56bfa9..8378a26 100644
80755 --- a/include/linux/slub_def.h
80756 +++ b/include/linux/slub_def.h
80757 @@ -74,7 +74,7 @@ struct kmem_cache {
80758 struct kmem_cache_order_objects max;
80759 struct kmem_cache_order_objects min;
80760 gfp_t allocflags; /* gfp flags to use on each alloc */
80761 - int refcount; /* Refcount for slab cache destroy */
80762 + atomic_t refcount; /* Refcount for slab cache destroy */
80763 void (*ctor)(void *);
80764 int inuse; /* Offset to metadata */
80765 int align; /* Alignment */
80766 diff --git a/include/linux/smp.h b/include/linux/smp.h
80767 index 5da22ee..71d8a28 100644
80768 --- a/include/linux/smp.h
80769 +++ b/include/linux/smp.h
80770 @@ -176,7 +176,9 @@ static inline void kick_all_cpus_sync(void) { }
80771 #endif
80772
80773 #define get_cpu() ({ preempt_disable(); smp_processor_id(); })
80774 +#define raw_get_cpu() ({ raw_preempt_disable(); raw_smp_processor_id(); })
80775 #define put_cpu() preempt_enable()
80776 +#define raw_put_cpu_no_resched() raw_preempt_enable_no_resched()
80777
80778 /*
80779 * Callback to arch code if there's nosmp or maxcpus=0 on the
80780 diff --git a/include/linux/sock_diag.h b/include/linux/sock_diag.h
80781 index 54f91d3..be2c379 100644
80782 --- a/include/linux/sock_diag.h
80783 +++ b/include/linux/sock_diag.h
80784 @@ -11,7 +11,7 @@ struct sock;
80785 struct sock_diag_handler {
80786 __u8 family;
80787 int (*dump)(struct sk_buff *skb, struct nlmsghdr *nlh);
80788 -};
80789 +} __do_const;
80790
80791 int sock_diag_register(const struct sock_diag_handler *h);
80792 void sock_diag_unregister(const struct sock_diag_handler *h);
80793 diff --git a/include/linux/sonet.h b/include/linux/sonet.h
80794 index 680f9a3..f13aeb0 100644
80795 --- a/include/linux/sonet.h
80796 +++ b/include/linux/sonet.h
80797 @@ -7,7 +7,7 @@
80798 #include <uapi/linux/sonet.h>
80799
80800 struct k_sonet_stats {
80801 -#define __HANDLE_ITEM(i) atomic_t i
80802 +#define __HANDLE_ITEM(i) atomic_unchecked_t i
80803 __SONET_ITEMS
80804 #undef __HANDLE_ITEM
80805 };
80806 diff --git a/include/linux/sunrpc/addr.h b/include/linux/sunrpc/addr.h
80807 index 07d8e53..dc934c9 100644
80808 --- a/include/linux/sunrpc/addr.h
80809 +++ b/include/linux/sunrpc/addr.h
80810 @@ -23,9 +23,9 @@ static inline unsigned short rpc_get_port(const struct sockaddr *sap)
80811 {
80812 switch (sap->sa_family) {
80813 case AF_INET:
80814 - return ntohs(((struct sockaddr_in *)sap)->sin_port);
80815 + return ntohs(((const struct sockaddr_in *)sap)->sin_port);
80816 case AF_INET6:
80817 - return ntohs(((struct sockaddr_in6 *)sap)->sin6_port);
80818 + return ntohs(((const struct sockaddr_in6 *)sap)->sin6_port);
80819 }
80820 return 0;
80821 }
80822 @@ -58,7 +58,7 @@ static inline bool __rpc_cmp_addr4(const struct sockaddr *sap1,
80823 static inline bool __rpc_copy_addr4(struct sockaddr *dst,
80824 const struct sockaddr *src)
80825 {
80826 - const struct sockaddr_in *ssin = (struct sockaddr_in *) src;
80827 + const struct sockaddr_in *ssin = (const struct sockaddr_in *) src;
80828 struct sockaddr_in *dsin = (struct sockaddr_in *) dst;
80829
80830 dsin->sin_family = ssin->sin_family;
80831 @@ -164,7 +164,7 @@ static inline u32 rpc_get_scope_id(const struct sockaddr *sa)
80832 if (sa->sa_family != AF_INET6)
80833 return 0;
80834
80835 - return ((struct sockaddr_in6 *) sa)->sin6_scope_id;
80836 + return ((const struct sockaddr_in6 *) sa)->sin6_scope_id;
80837 }
80838
80839 #endif /* _LINUX_SUNRPC_ADDR_H */
80840 diff --git a/include/linux/sunrpc/clnt.h b/include/linux/sunrpc/clnt.h
80841 index 8af2804..c7414ef 100644
80842 --- a/include/linux/sunrpc/clnt.h
80843 +++ b/include/linux/sunrpc/clnt.h
80844 @@ -97,7 +97,7 @@ struct rpc_procinfo {
80845 unsigned int p_timer; /* Which RTT timer to use */
80846 u32 p_statidx; /* Which procedure to account */
80847 const char * p_name; /* name of procedure */
80848 -};
80849 +} __do_const;
80850
80851 #ifdef __KERNEL__
80852
80853 diff --git a/include/linux/sunrpc/svc.h b/include/linux/sunrpc/svc.h
80854 index 6eecfc2..7ada79d 100644
80855 --- a/include/linux/sunrpc/svc.h
80856 +++ b/include/linux/sunrpc/svc.h
80857 @@ -410,7 +410,7 @@ struct svc_procedure {
80858 unsigned int pc_count; /* call count */
80859 unsigned int pc_cachetype; /* cache info (NFS) */
80860 unsigned int pc_xdrressize; /* maximum size of XDR reply */
80861 -};
80862 +} __do_const;
80863
80864 /*
80865 * Function prototypes.
80866 diff --git a/include/linux/sunrpc/svc_rdma.h b/include/linux/sunrpc/svc_rdma.h
80867 index 0b8e3e6..33e0a01 100644
80868 --- a/include/linux/sunrpc/svc_rdma.h
80869 +++ b/include/linux/sunrpc/svc_rdma.h
80870 @@ -53,15 +53,15 @@ extern unsigned int svcrdma_ord;
80871 extern unsigned int svcrdma_max_requests;
80872 extern unsigned int svcrdma_max_req_size;
80873
80874 -extern atomic_t rdma_stat_recv;
80875 -extern atomic_t rdma_stat_read;
80876 -extern atomic_t rdma_stat_write;
80877 -extern atomic_t rdma_stat_sq_starve;
80878 -extern atomic_t rdma_stat_rq_starve;
80879 -extern atomic_t rdma_stat_rq_poll;
80880 -extern atomic_t rdma_stat_rq_prod;
80881 -extern atomic_t rdma_stat_sq_poll;
80882 -extern atomic_t rdma_stat_sq_prod;
80883 +extern atomic_unchecked_t rdma_stat_recv;
80884 +extern atomic_unchecked_t rdma_stat_read;
80885 +extern atomic_unchecked_t rdma_stat_write;
80886 +extern atomic_unchecked_t rdma_stat_sq_starve;
80887 +extern atomic_unchecked_t rdma_stat_rq_starve;
80888 +extern atomic_unchecked_t rdma_stat_rq_poll;
80889 +extern atomic_unchecked_t rdma_stat_rq_prod;
80890 +extern atomic_unchecked_t rdma_stat_sq_poll;
80891 +extern atomic_unchecked_t rdma_stat_sq_prod;
80892
80893 #define RPCRDMA_VERSION 1
80894
80895 diff --git a/include/linux/sunrpc/svcauth.h b/include/linux/sunrpc/svcauth.h
80896 index 8d71d65..f79586e 100644
80897 --- a/include/linux/sunrpc/svcauth.h
80898 +++ b/include/linux/sunrpc/svcauth.h
80899 @@ -120,7 +120,7 @@ struct auth_ops {
80900 int (*release)(struct svc_rqst *rq);
80901 void (*domain_release)(struct auth_domain *);
80902 int (*set_client)(struct svc_rqst *rq);
80903 -};
80904 +} __do_const;
80905
80906 #define SVC_GARBAGE 1
80907 #define SVC_SYSERR 2
80908 diff --git a/include/linux/swiotlb.h b/include/linux/swiotlb.h
80909 index a5ffd32..0935dea 100644
80910 --- a/include/linux/swiotlb.h
80911 +++ b/include/linux/swiotlb.h
80912 @@ -60,7 +60,8 @@ extern void
80913
80914 extern void
80915 swiotlb_free_coherent(struct device *hwdev, size_t size,
80916 - void *vaddr, dma_addr_t dma_handle);
80917 + void *vaddr, dma_addr_t dma_handle,
80918 + struct dma_attrs *attrs);
80919
80920 extern dma_addr_t swiotlb_map_page(struct device *dev, struct page *page,
80921 unsigned long offset, size_t size,
80922 diff --git a/include/linux/syscalls.h b/include/linux/syscalls.h
80923 index 94273bb..c2e05fc 100644
80924 --- a/include/linux/syscalls.h
80925 +++ b/include/linux/syscalls.h
80926 @@ -97,8 +97,14 @@ struct sigaltstack;
80927 #define __MAP(n,...) __MAP##n(__VA_ARGS__)
80928
80929 #define __SC_DECL(t, a) t a
80930 +#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))
80931 #define __TYPE_IS_LL(t) (__same_type((t)0, 0LL) || __same_type((t)0, 0ULL))
80932 -#define __SC_LONG(t, a) __typeof(__builtin_choose_expr(__TYPE_IS_LL(t), 0LL, 0L)) a
80933 +#define __SC_LONG(t, a) __typeof( \
80934 + __builtin_choose_expr( \
80935 + sizeof(t) > sizeof(int), \
80936 + (t) 0, \
80937 + __builtin_choose_expr(__TYPE_IS_U(t), 0UL, 0L) \
80938 + )) a
80939 #define __SC_CAST(t, a) (t) a
80940 #define __SC_ARGS(t, a) a
80941 #define __SC_TEST(t, a) (void)BUILD_BUG_ON_ZERO(!__TYPE_IS_LL(t) && sizeof(t) > sizeof(long))
80942 @@ -363,11 +369,11 @@ asmlinkage long sys_sync(void);
80943 asmlinkage long sys_fsync(unsigned int fd);
80944 asmlinkage long sys_fdatasync(unsigned int fd);
80945 asmlinkage long sys_bdflush(int func, long data);
80946 -asmlinkage long sys_mount(char __user *dev_name, char __user *dir_name,
80947 - char __user *type, unsigned long flags,
80948 +asmlinkage long sys_mount(const char __user *dev_name, const char __user *dir_name,
80949 + const char __user *type, unsigned long flags,
80950 void __user *data);
80951 -asmlinkage long sys_umount(char __user *name, int flags);
80952 -asmlinkage long sys_oldumount(char __user *name);
80953 +asmlinkage long sys_umount(const char __user *name, int flags);
80954 +asmlinkage long sys_oldumount(const char __user *name);
80955 asmlinkage long sys_truncate(const char __user *path, long length);
80956 asmlinkage long sys_ftruncate(unsigned int fd, unsigned long length);
80957 asmlinkage long sys_stat(const char __user *filename,
80958 @@ -579,7 +585,7 @@ asmlinkage long sys_getsockname(int, struct sockaddr __user *, int __user *);
80959 asmlinkage long sys_getpeername(int, struct sockaddr __user *, int __user *);
80960 asmlinkage long sys_send(int, void __user *, size_t, unsigned);
80961 asmlinkage long sys_sendto(int, void __user *, size_t, unsigned,
80962 - struct sockaddr __user *, int);
80963 + struct sockaddr __user *, int) __intentional_overflow(0);
80964 asmlinkage long sys_sendmsg(int fd, struct msghdr __user *msg, unsigned flags);
80965 asmlinkage long sys_sendmmsg(int fd, struct mmsghdr __user *msg,
80966 unsigned int vlen, unsigned flags);
80967 diff --git a/include/linux/syscore_ops.h b/include/linux/syscore_ops.h
80968 index 27b3b0b..e093dd9 100644
80969 --- a/include/linux/syscore_ops.h
80970 +++ b/include/linux/syscore_ops.h
80971 @@ -16,7 +16,7 @@ struct syscore_ops {
80972 int (*suspend)(void);
80973 void (*resume)(void);
80974 void (*shutdown)(void);
80975 -};
80976 +} __do_const;
80977
80978 extern void register_syscore_ops(struct syscore_ops *ops);
80979 extern void unregister_syscore_ops(struct syscore_ops *ops);
80980 diff --git a/include/linux/sysctl.h b/include/linux/sysctl.h
80981 index 14a8ff2..fa95f3a 100644
80982 --- a/include/linux/sysctl.h
80983 +++ b/include/linux/sysctl.h
80984 @@ -34,13 +34,13 @@ struct ctl_table_root;
80985 struct ctl_table_header;
80986 struct ctl_dir;
80987
80988 -typedef struct ctl_table ctl_table;
80989 -
80990 typedef int proc_handler (struct ctl_table *ctl, int write,
80991 void __user *buffer, size_t *lenp, loff_t *ppos);
80992
80993 extern int proc_dostring(struct ctl_table *, int,
80994 void __user *, size_t *, loff_t *);
80995 +extern int proc_dostring_modpriv(struct ctl_table *, int,
80996 + void __user *, size_t *, loff_t *);
80997 extern int proc_dointvec(struct ctl_table *, int,
80998 void __user *, size_t *, loff_t *);
80999 extern int proc_dointvec_minmax(struct ctl_table *, int,
81000 @@ -115,7 +115,9 @@ struct ctl_table
81001 struct ctl_table_poll *poll;
81002 void *extra1;
81003 void *extra2;
81004 -};
81005 +} __do_const __randomize_layout;
81006 +typedef struct ctl_table __no_const ctl_table_no_const;
81007 +typedef struct ctl_table ctl_table;
81008
81009 struct ctl_node {
81010 struct rb_node node;
81011 diff --git a/include/linux/sysfs.h b/include/linux/sysfs.h
81012 index 6695040..3d4192d 100644
81013 --- a/include/linux/sysfs.h
81014 +++ b/include/linux/sysfs.h
81015 @@ -33,7 +33,8 @@ struct attribute {
81016 struct lock_class_key *key;
81017 struct lock_class_key skey;
81018 #endif
81019 -};
81020 +} __do_const;
81021 +typedef struct attribute __no_const attribute_no_const;
81022
81023 /**
81024 * sysfs_attr_init - initialize a dynamically allocated sysfs attribute
81025 @@ -62,7 +63,8 @@ struct attribute_group {
81026 struct attribute *, int);
81027 struct attribute **attrs;
81028 struct bin_attribute **bin_attrs;
81029 -};
81030 +} __do_const;
81031 +typedef struct attribute_group __no_const attribute_group_no_const;
81032
81033 /**
81034 * Use these macros to make defining attributes easier. See include/linux/device.h
81035 @@ -126,7 +128,8 @@ struct bin_attribute {
81036 char *, loff_t, size_t);
81037 int (*mmap)(struct file *, struct kobject *, struct bin_attribute *attr,
81038 struct vm_area_struct *vma);
81039 -};
81040 +} __do_const;
81041 +typedef struct bin_attribute __no_const bin_attribute_no_const;
81042
81043 /**
81044 * sysfs_bin_attr_init - initialize a dynamically allocated bin_attribute
81045 diff --git a/include/linux/sysrq.h b/include/linux/sysrq.h
81046 index 387fa7d..3fcde6b 100644
81047 --- a/include/linux/sysrq.h
81048 +++ b/include/linux/sysrq.h
81049 @@ -16,6 +16,7 @@
81050
81051 #include <linux/errno.h>
81052 #include <linux/types.h>
81053 +#include <linux/compiler.h>
81054
81055 /* Possible values of bitmask for enabling sysrq functions */
81056 /* 0x0001 is reserved for enable everything */
81057 @@ -33,7 +34,7 @@ struct sysrq_key_op {
81058 char *help_msg;
81059 char *action_msg;
81060 int enable_mask;
81061 -};
81062 +} __do_const;
81063
81064 #ifdef CONFIG_MAGIC_SYSRQ
81065
81066 diff --git a/include/linux/thread_info.h b/include/linux/thread_info.h
81067 index fddbe20..0312de8 100644
81068 --- a/include/linux/thread_info.h
81069 +++ b/include/linux/thread_info.h
81070 @@ -161,6 +161,15 @@ static inline bool test_and_clear_restore_sigmask(void)
81071 #error "no set_restore_sigmask() provided and default one won't work"
81072 #endif
81073
81074 +extern void __check_object_size(const void *ptr, unsigned long n, bool to_user);
81075 +static inline void check_object_size(const void *ptr, unsigned long n, bool to_user)
81076 +{
81077 +#ifndef CONFIG_PAX_USERCOPY_DEBUG
81078 + if (!__builtin_constant_p(n))
81079 +#endif
81080 + __check_object_size(ptr, n, to_user);
81081 +}
81082 +
81083 #endif /* __KERNEL__ */
81084
81085 #endif /* _LINUX_THREAD_INFO_H */
81086 diff --git a/include/linux/tty.h b/include/linux/tty.h
81087 index 97d660e..6356755 100644
81088 --- a/include/linux/tty.h
81089 +++ b/include/linux/tty.h
81090 @@ -196,7 +196,7 @@ struct tty_port {
81091 const struct tty_port_operations *ops; /* Port operations */
81092 spinlock_t lock; /* Lock protecting tty field */
81093 int blocked_open; /* Waiting to open */
81094 - int count; /* Usage count */
81095 + atomic_t count; /* Usage count */
81096 wait_queue_head_t open_wait; /* Open waiters */
81097 wait_queue_head_t close_wait; /* Close waiters */
81098 wait_queue_head_t delta_msr_wait; /* Modem status change */
81099 @@ -278,7 +278,7 @@ struct tty_struct {
81100 /* If the tty has a pending do_SAK, queue it here - akpm */
81101 struct work_struct SAK_work;
81102 struct tty_port *port;
81103 -};
81104 +} __randomize_layout;
81105
81106 /* Each of a tty's open files has private_data pointing to tty_file_private */
81107 struct tty_file_private {
81108 @@ -545,7 +545,7 @@ extern int tty_port_open(struct tty_port *port,
81109 struct tty_struct *tty, struct file *filp);
81110 static inline int tty_port_users(struct tty_port *port)
81111 {
81112 - return port->count + port->blocked_open;
81113 + return atomic_read(&port->count) + port->blocked_open;
81114 }
81115
81116 extern int tty_register_ldisc(int disc, struct tty_ldisc_ops *new_ldisc);
81117 diff --git a/include/linux/tty_driver.h b/include/linux/tty_driver.h
81118 index 756a609..f61242d 100644
81119 --- a/include/linux/tty_driver.h
81120 +++ b/include/linux/tty_driver.h
81121 @@ -285,7 +285,7 @@ struct tty_operations {
81122 void (*poll_put_char)(struct tty_driver *driver, int line, char ch);
81123 #endif
81124 const struct file_operations *proc_fops;
81125 -};
81126 +} __do_const;
81127
81128 struct tty_driver {
81129 int magic; /* magic number for this structure */
81130 @@ -319,7 +319,7 @@ struct tty_driver {
81131
81132 const struct tty_operations *ops;
81133 struct list_head tty_drivers;
81134 -};
81135 +} __randomize_layout;
81136
81137 extern struct list_head tty_drivers;
81138
81139 diff --git a/include/linux/tty_ldisc.h b/include/linux/tty_ldisc.h
81140 index f15c898..207b7d1 100644
81141 --- a/include/linux/tty_ldisc.h
81142 +++ b/include/linux/tty_ldisc.h
81143 @@ -211,7 +211,7 @@ struct tty_ldisc_ops {
81144
81145 struct module *owner;
81146
81147 - int refcount;
81148 + atomic_t refcount;
81149 };
81150
81151 struct tty_ldisc {
81152 diff --git a/include/linux/types.h b/include/linux/types.h
81153 index 4d118ba..c3ee9bf 100644
81154 --- a/include/linux/types.h
81155 +++ b/include/linux/types.h
81156 @@ -176,10 +176,26 @@ typedef struct {
81157 int counter;
81158 } atomic_t;
81159
81160 +#ifdef CONFIG_PAX_REFCOUNT
81161 +typedef struct {
81162 + int counter;
81163 +} atomic_unchecked_t;
81164 +#else
81165 +typedef atomic_t atomic_unchecked_t;
81166 +#endif
81167 +
81168 #ifdef CONFIG_64BIT
81169 typedef struct {
81170 long counter;
81171 } atomic64_t;
81172 +
81173 +#ifdef CONFIG_PAX_REFCOUNT
81174 +typedef struct {
81175 + long counter;
81176 +} atomic64_unchecked_t;
81177 +#else
81178 +typedef atomic64_t atomic64_unchecked_t;
81179 +#endif
81180 #endif
81181
81182 struct list_head {
81183 diff --git a/include/linux/uaccess.h b/include/linux/uaccess.h
81184 index 9d8cf05..0ed74dd 100644
81185 --- a/include/linux/uaccess.h
81186 +++ b/include/linux/uaccess.h
81187 @@ -72,11 +72,11 @@ static inline unsigned long __copy_from_user_nocache(void *to,
81188 long ret; \
81189 mm_segment_t old_fs = get_fs(); \
81190 \
81191 - set_fs(KERNEL_DS); \
81192 pagefault_disable(); \
81193 - ret = __copy_from_user_inatomic(&(retval), (__force typeof(retval) __user *)(addr), sizeof(retval)); \
81194 - pagefault_enable(); \
81195 + set_fs(KERNEL_DS); \
81196 + ret = __copy_from_user_inatomic(&(retval), (typeof(retval) __force_user *)(addr), sizeof(retval)); \
81197 set_fs(old_fs); \
81198 + pagefault_enable(); \
81199 ret; \
81200 })
81201
81202 diff --git a/include/linux/uidgid.h b/include/linux/uidgid.h
81203 index 8e522cbc..aa8572d 100644
81204 --- a/include/linux/uidgid.h
81205 +++ b/include/linux/uidgid.h
81206 @@ -197,4 +197,9 @@ static inline bool kgid_has_mapping(struct user_namespace *ns, kgid_t gid)
81207
81208 #endif /* CONFIG_USER_NS */
81209
81210 +#define GR_GLOBAL_UID(x) from_kuid_munged(&init_user_ns, (x))
81211 +#define GR_GLOBAL_GID(x) from_kgid_munged(&init_user_ns, (x))
81212 +#define gr_is_global_root(x) uid_eq((x), GLOBAL_ROOT_UID)
81213 +#define gr_is_global_nonroot(x) (!uid_eq((x), GLOBAL_ROOT_UID))
81214 +
81215 #endif /* _LINUX_UIDGID_H */
81216 diff --git a/include/linux/unaligned/access_ok.h b/include/linux/unaligned/access_ok.h
81217 index 99c1b4d..562e6f3 100644
81218 --- a/include/linux/unaligned/access_ok.h
81219 +++ b/include/linux/unaligned/access_ok.h
81220 @@ -4,34 +4,34 @@
81221 #include <linux/kernel.h>
81222 #include <asm/byteorder.h>
81223
81224 -static inline u16 get_unaligned_le16(const void *p)
81225 +static inline u16 __intentional_overflow(-1) get_unaligned_le16(const void *p)
81226 {
81227 - return le16_to_cpup((__le16 *)p);
81228 + return le16_to_cpup((const __le16 *)p);
81229 }
81230
81231 -static inline u32 get_unaligned_le32(const void *p)
81232 +static inline u32 __intentional_overflow(-1) get_unaligned_le32(const void *p)
81233 {
81234 - return le32_to_cpup((__le32 *)p);
81235 + return le32_to_cpup((const __le32 *)p);
81236 }
81237
81238 -static inline u64 get_unaligned_le64(const void *p)
81239 +static inline u64 __intentional_overflow(-1) get_unaligned_le64(const void *p)
81240 {
81241 - return le64_to_cpup((__le64 *)p);
81242 + return le64_to_cpup((const __le64 *)p);
81243 }
81244
81245 -static inline u16 get_unaligned_be16(const void *p)
81246 +static inline u16 __intentional_overflow(-1) get_unaligned_be16(const void *p)
81247 {
81248 - return be16_to_cpup((__be16 *)p);
81249 + return be16_to_cpup((const __be16 *)p);
81250 }
81251
81252 -static inline u32 get_unaligned_be32(const void *p)
81253 +static inline u32 __intentional_overflow(-1) get_unaligned_be32(const void *p)
81254 {
81255 - return be32_to_cpup((__be32 *)p);
81256 + return be32_to_cpup((const __be32 *)p);
81257 }
81258
81259 -static inline u64 get_unaligned_be64(const void *p)
81260 +static inline u64 __intentional_overflow(-1) get_unaligned_be64(const void *p)
81261 {
81262 - return be64_to_cpup((__be64 *)p);
81263 + return be64_to_cpup((const __be64 *)p);
81264 }
81265
81266 static inline void put_unaligned_le16(u16 val, void *p)
81267 diff --git a/include/linux/usb.h b/include/linux/usb.h
81268 index 512ab16..f53e1bf 100644
81269 --- a/include/linux/usb.h
81270 +++ b/include/linux/usb.h
81271 @@ -563,7 +563,7 @@ struct usb_device {
81272 int maxchild;
81273
81274 u32 quirks;
81275 - atomic_t urbnum;
81276 + atomic_unchecked_t urbnum;
81277
81278 unsigned long active_duration;
81279
81280 @@ -1643,7 +1643,7 @@ void usb_buffer_unmap_sg(const struct usb_device *dev, int is_in,
81281
81282 extern int usb_control_msg(struct usb_device *dev, unsigned int pipe,
81283 __u8 request, __u8 requesttype, __u16 value, __u16 index,
81284 - void *data, __u16 size, int timeout);
81285 + void *data, __u16 size, int timeout) __intentional_overflow(-1);
81286 extern int usb_interrupt_msg(struct usb_device *usb_dev, unsigned int pipe,
81287 void *data, int len, int *actual_length, int timeout);
81288 extern int usb_bulk_msg(struct usb_device *usb_dev, unsigned int pipe,
81289 diff --git a/include/linux/usb/renesas_usbhs.h b/include/linux/usb/renesas_usbhs.h
81290 index e452ba6..78f8e80 100644
81291 --- a/include/linux/usb/renesas_usbhs.h
81292 +++ b/include/linux/usb/renesas_usbhs.h
81293 @@ -39,7 +39,7 @@ enum {
81294 */
81295 struct renesas_usbhs_driver_callback {
81296 int (*notify_hotplug)(struct platform_device *pdev);
81297 -};
81298 +} __no_const;
81299
81300 /*
81301 * callback functions for platform
81302 diff --git a/include/linux/user_namespace.h b/include/linux/user_namespace.h
81303 index 4836ba3..603f6ee 100644
81304 --- a/include/linux/user_namespace.h
81305 +++ b/include/linux/user_namespace.h
81306 @@ -33,7 +33,7 @@ struct user_namespace {
81307 struct key *persistent_keyring_register;
81308 struct rw_semaphore persistent_keyring_register_sem;
81309 #endif
81310 -};
81311 +} __randomize_layout;
81312
81313 extern struct user_namespace init_user_ns;
81314
81315 diff --git a/include/linux/utsname.h b/include/linux/utsname.h
81316 index 239e277..22a5cf5 100644
81317 --- a/include/linux/utsname.h
81318 +++ b/include/linux/utsname.h
81319 @@ -24,7 +24,7 @@ struct uts_namespace {
81320 struct new_utsname name;
81321 struct user_namespace *user_ns;
81322 unsigned int proc_inum;
81323 -};
81324 +} __randomize_layout;
81325 extern struct uts_namespace init_uts_ns;
81326
81327 #ifdef CONFIG_UTS_NS
81328 diff --git a/include/linux/vermagic.h b/include/linux/vermagic.h
81329 index 6f8fbcf..4efc177 100644
81330 --- a/include/linux/vermagic.h
81331 +++ b/include/linux/vermagic.h
81332 @@ -25,9 +25,42 @@
81333 #define MODULE_ARCH_VERMAGIC ""
81334 #endif
81335
81336 +#ifdef CONFIG_PAX_REFCOUNT
81337 +#define MODULE_PAX_REFCOUNT "REFCOUNT "
81338 +#else
81339 +#define MODULE_PAX_REFCOUNT ""
81340 +#endif
81341 +
81342 +#ifdef CONSTIFY_PLUGIN
81343 +#define MODULE_CONSTIFY_PLUGIN "CONSTIFY_PLUGIN "
81344 +#else
81345 +#define MODULE_CONSTIFY_PLUGIN ""
81346 +#endif
81347 +
81348 +#ifdef STACKLEAK_PLUGIN
81349 +#define MODULE_STACKLEAK_PLUGIN "STACKLEAK_PLUGIN "
81350 +#else
81351 +#define MODULE_STACKLEAK_PLUGIN ""
81352 +#endif
81353 +
81354 +#ifdef RANDSTRUCT_PLUGIN
81355 +#include <generated/randomize_layout_hash.h>
81356 +#define MODULE_RANDSTRUCT_PLUGIN "RANDSTRUCT_PLUGIN_" RANDSTRUCT_HASHED_SEED
81357 +#else
81358 +#define MODULE_RANDSTRUCT_PLUGIN
81359 +#endif
81360 +
81361 +#ifdef CONFIG_GRKERNSEC
81362 +#define MODULE_GRSEC "GRSEC "
81363 +#else
81364 +#define MODULE_GRSEC ""
81365 +#endif
81366 +
81367 #define VERMAGIC_STRING \
81368 UTS_RELEASE " " \
81369 MODULE_VERMAGIC_SMP MODULE_VERMAGIC_PREEMPT \
81370 MODULE_VERMAGIC_MODULE_UNLOAD MODULE_VERMAGIC_MODVERSIONS \
81371 - MODULE_ARCH_VERMAGIC
81372 + MODULE_ARCH_VERMAGIC \
81373 + MODULE_PAX_REFCOUNT MODULE_CONSTIFY_PLUGIN MODULE_STACKLEAK_PLUGIN \
81374 + MODULE_GRSEC MODULE_RANDSTRUCT_PLUGIN
81375
81376 diff --git a/include/linux/vga_switcheroo.h b/include/linux/vga_switcheroo.h
81377 index 502073a..a7de024 100644
81378 --- a/include/linux/vga_switcheroo.h
81379 +++ b/include/linux/vga_switcheroo.h
81380 @@ -63,8 +63,8 @@ int vga_switcheroo_get_client_state(struct pci_dev *dev);
81381
81382 void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic);
81383
81384 -int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain);
81385 -int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain);
81386 +int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain);
81387 +int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain);
81388 #else
81389
81390 static inline void vga_switcheroo_unregister_client(struct pci_dev *dev) {}
81391 @@ -81,8 +81,8 @@ static inline int vga_switcheroo_get_client_state(struct pci_dev *dev) { return
81392
81393 static inline void vga_switcheroo_set_dynamic_switch(struct pci_dev *pdev, enum vga_switcheroo_state dynamic) {}
81394
81395 -static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
81396 -static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, struct dev_pm_domain *domain) { return -EINVAL; }
81397 +static inline int vga_switcheroo_init_domain_pm_ops(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
81398 +static inline int vga_switcheroo_init_domain_pm_optimus_hdmi_audio(struct device *dev, dev_pm_domain_no_const *domain) { return -EINVAL; }
81399
81400 #endif
81401 #endif /* _LINUX_VGA_SWITCHEROO_H_ */
81402 diff --git a/include/linux/vmalloc.h b/include/linux/vmalloc.h
81403 index 4b8a891..cb8df6e 100644
81404 --- a/include/linux/vmalloc.h
81405 +++ b/include/linux/vmalloc.h
81406 @@ -16,6 +16,11 @@ struct vm_area_struct; /* vma defining user mapping in mm_types.h */
81407 #define VM_USERMAP 0x00000008 /* suitable for remap_vmalloc_range */
81408 #define VM_VPAGES 0x00000010 /* buffer for pages was vmalloc'ed */
81409 #define VM_UNINITIALIZED 0x00000020 /* vm_struct is not fully initialized */
81410 +
81411 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
81412 +#define VM_KERNEXEC 0x00000040 /* allocate from executable kernel memory range */
81413 +#endif
81414 +
81415 /* bits [20..32] reserved for arch specific ioremap internals */
81416
81417 /*
81418 @@ -142,7 +147,7 @@ extern void free_vm_area(struct vm_struct *area);
81419
81420 /* for /dev/kmem */
81421 extern long vread(char *buf, char *addr, unsigned long count);
81422 -extern long vwrite(char *buf, char *addr, unsigned long count);
81423 +extern long vwrite(char *buf, char *addr, unsigned long count) __size_overflow(3);
81424
81425 /*
81426 * Internals. Dont't use..
81427 diff --git a/include/linux/vmstat.h b/include/linux/vmstat.h
81428 index a67b384..f52a537 100644
81429 --- a/include/linux/vmstat.h
81430 +++ b/include/linux/vmstat.h
81431 @@ -90,18 +90,18 @@ static inline void vm_events_fold_cpu(int cpu)
81432 /*
81433 * Zone based page accounting with per cpu differentials.
81434 */
81435 -extern atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81436 +extern atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS];
81437
81438 static inline void zone_page_state_add(long x, struct zone *zone,
81439 enum zone_stat_item item)
81440 {
81441 - atomic_long_add(x, &zone->vm_stat[item]);
81442 - atomic_long_add(x, &vm_stat[item]);
81443 + atomic_long_add_unchecked(x, &zone->vm_stat[item]);
81444 + atomic_long_add_unchecked(x, &vm_stat[item]);
81445 }
81446
81447 -static inline unsigned long global_page_state(enum zone_stat_item item)
81448 +static inline unsigned long __intentional_overflow(-1) global_page_state(enum zone_stat_item item)
81449 {
81450 - long x = atomic_long_read(&vm_stat[item]);
81451 + long x = atomic_long_read_unchecked(&vm_stat[item]);
81452 #ifdef CONFIG_SMP
81453 if (x < 0)
81454 x = 0;
81455 @@ -109,10 +109,10 @@ static inline unsigned long global_page_state(enum zone_stat_item item)
81456 return x;
81457 }
81458
81459 -static inline unsigned long zone_page_state(struct zone *zone,
81460 +static inline unsigned long __intentional_overflow(-1) zone_page_state(struct zone *zone,
81461 enum zone_stat_item item)
81462 {
81463 - long x = atomic_long_read(&zone->vm_stat[item]);
81464 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
81465 #ifdef CONFIG_SMP
81466 if (x < 0)
81467 x = 0;
81468 @@ -129,7 +129,7 @@ static inline unsigned long zone_page_state(struct zone *zone,
81469 static inline unsigned long zone_page_state_snapshot(struct zone *zone,
81470 enum zone_stat_item item)
81471 {
81472 - long x = atomic_long_read(&zone->vm_stat[item]);
81473 + long x = atomic_long_read_unchecked(&zone->vm_stat[item]);
81474
81475 #ifdef CONFIG_SMP
81476 int cpu;
81477 @@ -218,8 +218,8 @@ static inline void __mod_zone_page_state(struct zone *zone,
81478
81479 static inline void __inc_zone_state(struct zone *zone, enum zone_stat_item item)
81480 {
81481 - atomic_long_inc(&zone->vm_stat[item]);
81482 - atomic_long_inc(&vm_stat[item]);
81483 + atomic_long_inc_unchecked(&zone->vm_stat[item]);
81484 + atomic_long_inc_unchecked(&vm_stat[item]);
81485 }
81486
81487 static inline void __inc_zone_page_state(struct page *page,
81488 @@ -230,8 +230,8 @@ static inline void __inc_zone_page_state(struct page *page,
81489
81490 static inline void __dec_zone_state(struct zone *zone, enum zone_stat_item item)
81491 {
81492 - atomic_long_dec(&zone->vm_stat[item]);
81493 - atomic_long_dec(&vm_stat[item]);
81494 + atomic_long_dec_unchecked(&zone->vm_stat[item]);
81495 + atomic_long_dec_unchecked(&vm_stat[item]);
81496 }
81497
81498 static inline void __dec_zone_page_state(struct page *page,
81499 diff --git a/include/linux/xattr.h b/include/linux/xattr.h
81500 index 91b0a68..0e9adf6 100644
81501 --- a/include/linux/xattr.h
81502 +++ b/include/linux/xattr.h
81503 @@ -28,7 +28,7 @@ struct xattr_handler {
81504 size_t size, int handler_flags);
81505 int (*set)(struct dentry *dentry, const char *name, const void *buffer,
81506 size_t size, int flags, int handler_flags);
81507 -};
81508 +} __do_const;
81509
81510 struct xattr {
81511 const char *name;
81512 @@ -37,6 +37,9 @@ struct xattr {
81513 };
81514
81515 ssize_t xattr_getsecurity(struct inode *, const char *, void *, size_t);
81516 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
81517 +ssize_t pax_getxattr(struct dentry *, void *, size_t);
81518 +#endif
81519 ssize_t vfs_getxattr(struct dentry *, const char *, void *, size_t);
81520 ssize_t vfs_listxattr(struct dentry *d, char *list, size_t size);
81521 int __vfs_setxattr_noperm(struct dentry *, const char *, const void *, size_t, int);
81522 diff --git a/include/linux/zlib.h b/include/linux/zlib.h
81523 index 9c5a6b4..09c9438 100644
81524 --- a/include/linux/zlib.h
81525 +++ b/include/linux/zlib.h
81526 @@ -31,6 +31,7 @@
81527 #define _ZLIB_H
81528
81529 #include <linux/zconf.h>
81530 +#include <linux/compiler.h>
81531
81532 /* zlib deflate based on ZLIB_VERSION "1.1.3" */
81533 /* zlib inflate based on ZLIB_VERSION "1.2.3" */
81534 @@ -179,7 +180,7 @@ typedef z_stream *z_streamp;
81535
81536 /* basic functions */
81537
81538 -extern int zlib_deflate_workspacesize (int windowBits, int memLevel);
81539 +extern int zlib_deflate_workspacesize (int windowBits, int memLevel) __intentional_overflow(0);
81540 /*
81541 Returns the number of bytes that needs to be allocated for a per-
81542 stream workspace with the specified parameters. A pointer to this
81543 diff --git a/include/media/v4l2-dev.h b/include/media/v4l2-dev.h
81544 index c768c9f..bdcaa5a 100644
81545 --- a/include/media/v4l2-dev.h
81546 +++ b/include/media/v4l2-dev.h
81547 @@ -76,7 +76,7 @@ struct v4l2_file_operations {
81548 int (*mmap) (struct file *, struct vm_area_struct *);
81549 int (*open) (struct file *);
81550 int (*release) (struct file *);
81551 -};
81552 +} __do_const;
81553
81554 /*
81555 * Newer version of video_device, handled by videodev2.c
81556 diff --git a/include/media/v4l2-device.h b/include/media/v4l2-device.h
81557 index c9b1593..a572459 100644
81558 --- a/include/media/v4l2-device.h
81559 +++ b/include/media/v4l2-device.h
81560 @@ -95,7 +95,7 @@ int __must_check v4l2_device_register(struct device *dev, struct v4l2_device *v4
81561 this function returns 0. If the name ends with a digit (e.g. cx18),
81562 then the name will be set to cx18-0 since cx180 looks really odd. */
81563 int v4l2_device_set_name(struct v4l2_device *v4l2_dev, const char *basename,
81564 - atomic_t *instance);
81565 + atomic_unchecked_t *instance);
81566
81567 /* Set v4l2_dev->dev to NULL. Call when the USB parent disconnects.
81568 Since the parent disappears this ensures that v4l2_dev doesn't have an
81569 diff --git a/include/net/9p/transport.h b/include/net/9p/transport.h
81570 index 9a36d92..0aafe2a 100644
81571 --- a/include/net/9p/transport.h
81572 +++ b/include/net/9p/transport.h
81573 @@ -60,7 +60,7 @@ struct p9_trans_module {
81574 int (*cancel) (struct p9_client *, struct p9_req_t *req);
81575 int (*zc_request)(struct p9_client *, struct p9_req_t *,
81576 char *, char *, int , int, int, int);
81577 -};
81578 +} __do_const;
81579
81580 void v9fs_register_trans(struct p9_trans_module *m);
81581 void v9fs_unregister_trans(struct p9_trans_module *m);
81582 diff --git a/include/net/bluetooth/l2cap.h b/include/net/bluetooth/l2cap.h
81583 index c853b16d..37fccb7 100644
81584 --- a/include/net/bluetooth/l2cap.h
81585 +++ b/include/net/bluetooth/l2cap.h
81586 @@ -557,7 +557,7 @@ struct l2cap_ops {
81587 long (*get_sndtimeo) (struct l2cap_chan *chan);
81588 struct sk_buff *(*alloc_skb) (struct l2cap_chan *chan,
81589 unsigned long len, int nb);
81590 -};
81591 +} __do_const;
81592
81593 struct l2cap_conn {
81594 struct hci_conn *hcon;
81595 diff --git a/include/net/caif/cfctrl.h b/include/net/caif/cfctrl.h
81596 index f2ae33d..c457cf0 100644
81597 --- a/include/net/caif/cfctrl.h
81598 +++ b/include/net/caif/cfctrl.h
81599 @@ -52,7 +52,7 @@ struct cfctrl_rsp {
81600 void (*radioset_rsp)(void);
81601 void (*reject_rsp)(struct cflayer *layer, u8 linkid,
81602 struct cflayer *client_layer);
81603 -};
81604 +} __no_const;
81605
81606 /* Link Setup Parameters for CAIF-Links. */
81607 struct cfctrl_link_param {
81608 @@ -101,8 +101,8 @@ struct cfctrl_request_info {
81609 struct cfctrl {
81610 struct cfsrvl serv;
81611 struct cfctrl_rsp res;
81612 - atomic_t req_seq_no;
81613 - atomic_t rsp_seq_no;
81614 + atomic_unchecked_t req_seq_no;
81615 + atomic_unchecked_t rsp_seq_no;
81616 struct list_head list;
81617 /* Protects from simultaneous access to first_req list */
81618 spinlock_t info_list_lock;
81619 diff --git a/include/net/flow.h b/include/net/flow.h
81620 index 65ce471..b7bbe9b 100644
81621 --- a/include/net/flow.h
81622 +++ b/include/net/flow.h
81623 @@ -222,6 +222,6 @@ struct flow_cache_object *flow_cache_lookup(struct net *net,
81624
81625 void flow_cache_flush(void);
81626 void flow_cache_flush_deferred(void);
81627 -extern atomic_t flow_cache_genid;
81628 +extern atomic_unchecked_t flow_cache_genid;
81629
81630 #endif
81631 diff --git a/include/net/genetlink.h b/include/net/genetlink.h
81632 index 1b177ed..a24a138 100644
81633 --- a/include/net/genetlink.h
81634 +++ b/include/net/genetlink.h
81635 @@ -118,7 +118,7 @@ struct genl_ops {
81636 u8 cmd;
81637 u8 internal_flags;
81638 u8 flags;
81639 -};
81640 +} __do_const;
81641
81642 int __genl_register_family(struct genl_family *family);
81643
81644 diff --git a/include/net/gro_cells.h b/include/net/gro_cells.h
81645 index 734d9b5..48a9a4b 100644
81646 --- a/include/net/gro_cells.h
81647 +++ b/include/net/gro_cells.h
81648 @@ -29,7 +29,7 @@ static inline void gro_cells_receive(struct gro_cells *gcells, struct sk_buff *s
81649 cell += skb_get_rx_queue(skb) & gcells->gro_cells_mask;
81650
81651 if (skb_queue_len(&cell->napi_skbs) > netdev_max_backlog) {
81652 - atomic_long_inc(&dev->rx_dropped);
81653 + atomic_long_inc_unchecked(&dev->rx_dropped);
81654 kfree_skb(skb);
81655 return;
81656 }
81657 diff --git a/include/net/inet_connection_sock.h b/include/net/inet_connection_sock.h
81658 index c55aeed..b3393f4 100644
81659 --- a/include/net/inet_connection_sock.h
81660 +++ b/include/net/inet_connection_sock.h
81661 @@ -62,7 +62,7 @@ struct inet_connection_sock_af_ops {
81662 void (*addr2sockaddr)(struct sock *sk, struct sockaddr *);
81663 int (*bind_conflict)(const struct sock *sk,
81664 const struct inet_bind_bucket *tb, bool relax);
81665 -};
81666 +} __do_const;
81667
81668 /** inet_connection_sock - INET connection oriented sock
81669 *
81670 diff --git a/include/net/inetpeer.h b/include/net/inetpeer.h
81671 index f4e127a..c3d5e9c 100644
81672 --- a/include/net/inetpeer.h
81673 +++ b/include/net/inetpeer.h
81674 @@ -47,8 +47,8 @@ struct inet_peer {
81675 */
81676 union {
81677 struct {
81678 - atomic_t rid; /* Frag reception counter */
81679 - atomic_t ip_id_count; /* IP ID for the next packet */
81680 + atomic_unchecked_t rid; /* Frag reception counter */
81681 + atomic_unchecked_t ip_id_count; /* IP ID for the next packet */
81682 };
81683 struct rcu_head rcu;
81684 struct inet_peer *gc_next;
81685 @@ -178,16 +178,13 @@ static inline void inet_peer_refcheck(const struct inet_peer *p)
81686 /* can be called with or without local BH being disabled */
81687 static inline int inet_getid(struct inet_peer *p, int more)
81688 {
81689 - int old, new;
81690 + int id;
81691 more++;
81692 inet_peer_refcheck(p);
81693 - do {
81694 - old = atomic_read(&p->ip_id_count);
81695 - new = old + more;
81696 - if (!new)
81697 - new = 1;
81698 - } while (atomic_cmpxchg(&p->ip_id_count, old, new) != old);
81699 - return new;
81700 + id = atomic_add_return_unchecked(more, &p->ip_id_count);
81701 + if (!id)
81702 + id = atomic_inc_return_unchecked(&p->ip_id_count);
81703 + return id;
81704 }
81705
81706 #endif /* _NET_INETPEER_H */
81707 diff --git a/include/net/ip.h b/include/net/ip.h
81708 index 5a25f36..2e73203 100644
81709 --- a/include/net/ip.h
81710 +++ b/include/net/ip.h
81711 @@ -219,7 +219,7 @@ static inline void snmp_mib_free(void __percpu *ptr[SNMP_ARRAY_SZ])
81712
81713 void inet_get_local_port_range(struct net *net, int *low, int *high);
81714
81715 -extern unsigned long *sysctl_local_reserved_ports;
81716 +extern unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
81717 static inline int inet_is_reserved_local_port(int port)
81718 {
81719 return test_bit(port, sysctl_local_reserved_ports);
81720 diff --git a/include/net/ip_fib.h b/include/net/ip_fib.h
81721 index 9922093..a1755d6 100644
81722 --- a/include/net/ip_fib.h
81723 +++ b/include/net/ip_fib.h
81724 @@ -169,7 +169,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh);
81725
81726 #define FIB_RES_SADDR(net, res) \
81727 ((FIB_RES_NH(res).nh_saddr_genid == \
81728 - atomic_read(&(net)->ipv4.dev_addr_genid)) ? \
81729 + atomic_read_unchecked(&(net)->ipv4.dev_addr_genid)) ? \
81730 FIB_RES_NH(res).nh_saddr : \
81731 fib_info_update_nh_saddr((net), &FIB_RES_NH(res)))
81732 #define FIB_RES_GW(res) (FIB_RES_NH(res).nh_gw)
81733 diff --git a/include/net/ip_vs.h b/include/net/ip_vs.h
81734 index 5679d92..2e7a690 100644
81735 --- a/include/net/ip_vs.h
81736 +++ b/include/net/ip_vs.h
81737 @@ -558,7 +558,7 @@ struct ip_vs_conn {
81738 struct ip_vs_conn *control; /* Master control connection */
81739 atomic_t n_control; /* Number of controlled ones */
81740 struct ip_vs_dest *dest; /* real server */
81741 - atomic_t in_pkts; /* incoming packet counter */
81742 + atomic_unchecked_t in_pkts; /* incoming packet counter */
81743
81744 /* packet transmitter for different forwarding methods. If it
81745 mangles the packet, it must return NF_DROP or better NF_STOLEN,
81746 @@ -705,7 +705,7 @@ struct ip_vs_dest {
81747 __be16 port; /* port number of the server */
81748 union nf_inet_addr addr; /* IP address of the server */
81749 volatile unsigned int flags; /* dest status flags */
81750 - atomic_t conn_flags; /* flags to copy to conn */
81751 + atomic_unchecked_t conn_flags; /* flags to copy to conn */
81752 atomic_t weight; /* server weight */
81753
81754 atomic_t refcnt; /* reference counter */
81755 @@ -960,11 +960,11 @@ struct netns_ipvs {
81756 /* ip_vs_lblc */
81757 int sysctl_lblc_expiration;
81758 struct ctl_table_header *lblc_ctl_header;
81759 - struct ctl_table *lblc_ctl_table;
81760 + ctl_table_no_const *lblc_ctl_table;
81761 /* ip_vs_lblcr */
81762 int sysctl_lblcr_expiration;
81763 struct ctl_table_header *lblcr_ctl_header;
81764 - struct ctl_table *lblcr_ctl_table;
81765 + ctl_table_no_const *lblcr_ctl_table;
81766 /* ip_vs_est */
81767 struct list_head est_list; /* estimator list */
81768 spinlock_t est_lock;
81769 diff --git a/include/net/irda/ircomm_tty.h b/include/net/irda/ircomm_tty.h
81770 index 0224402..dafaf94a 100644
81771 --- a/include/net/irda/ircomm_tty.h
81772 +++ b/include/net/irda/ircomm_tty.h
81773 @@ -35,6 +35,7 @@
81774 #include <linux/termios.h>
81775 #include <linux/timer.h>
81776 #include <linux/tty.h> /* struct tty_struct */
81777 +#include <asm/local.h>
81778
81779 #include <net/irda/irias_object.h>
81780 #include <net/irda/ircomm_core.h>
81781 diff --git a/include/net/iucv/af_iucv.h b/include/net/iucv/af_iucv.h
81782 index 714cc9a..ea05f3e 100644
81783 --- a/include/net/iucv/af_iucv.h
81784 +++ b/include/net/iucv/af_iucv.h
81785 @@ -149,7 +149,7 @@ struct iucv_skb_cb {
81786 struct iucv_sock_list {
81787 struct hlist_head head;
81788 rwlock_t lock;
81789 - atomic_t autobind_name;
81790 + atomic_unchecked_t autobind_name;
81791 };
81792
81793 unsigned int iucv_sock_poll(struct file *file, struct socket *sock,
81794 diff --git a/include/net/llc_c_ac.h b/include/net/llc_c_ac.h
81795 index f3be818..bf46196 100644
81796 --- a/include/net/llc_c_ac.h
81797 +++ b/include/net/llc_c_ac.h
81798 @@ -87,7 +87,7 @@
81799 #define LLC_CONN_AC_STOP_SENDACK_TMR 70
81800 #define LLC_CONN_AC_START_SENDACK_TMR_IF_NOT_RUNNING 71
81801
81802 -typedef int (*llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
81803 +typedef int (* const llc_conn_action_t)(struct sock *sk, struct sk_buff *skb);
81804
81805 int llc_conn_ac_clear_remote_busy(struct sock *sk, struct sk_buff *skb);
81806 int llc_conn_ac_conn_ind(struct sock *sk, struct sk_buff *skb);
81807 diff --git a/include/net/llc_c_ev.h b/include/net/llc_c_ev.h
81808 index 3948cf1..83b28c4 100644
81809 --- a/include/net/llc_c_ev.h
81810 +++ b/include/net/llc_c_ev.h
81811 @@ -125,8 +125,8 @@ static __inline__ struct llc_conn_state_ev *llc_conn_ev(struct sk_buff *skb)
81812 return (struct llc_conn_state_ev *)skb->cb;
81813 }
81814
81815 -typedef int (*llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
81816 -typedef int (*llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
81817 +typedef int (* const llc_conn_ev_t)(struct sock *sk, struct sk_buff *skb);
81818 +typedef int (* const llc_conn_ev_qfyr_t)(struct sock *sk, struct sk_buff *skb);
81819
81820 int llc_conn_ev_conn_req(struct sock *sk, struct sk_buff *skb);
81821 int llc_conn_ev_data_req(struct sock *sk, struct sk_buff *skb);
81822 diff --git a/include/net/llc_c_st.h b/include/net/llc_c_st.h
81823 index 0e79cfb..f46db31 100644
81824 --- a/include/net/llc_c_st.h
81825 +++ b/include/net/llc_c_st.h
81826 @@ -37,7 +37,7 @@ struct llc_conn_state_trans {
81827 u8 next_state;
81828 llc_conn_ev_qfyr_t *ev_qualifiers;
81829 llc_conn_action_t *ev_actions;
81830 -};
81831 +} __do_const;
81832
81833 struct llc_conn_state {
81834 u8 current_state;
81835 diff --git a/include/net/llc_s_ac.h b/include/net/llc_s_ac.h
81836 index a61b98c..aade1eb 100644
81837 --- a/include/net/llc_s_ac.h
81838 +++ b/include/net/llc_s_ac.h
81839 @@ -23,7 +23,7 @@
81840 #define SAP_ACT_TEST_IND 9
81841
81842 /* All action functions must look like this */
81843 -typedef int (*llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
81844 +typedef int (* const llc_sap_action_t)(struct llc_sap *sap, struct sk_buff *skb);
81845
81846 int llc_sap_action_unitdata_ind(struct llc_sap *sap, struct sk_buff *skb);
81847 int llc_sap_action_send_ui(struct llc_sap *sap, struct sk_buff *skb);
81848 diff --git a/include/net/llc_s_st.h b/include/net/llc_s_st.h
81849 index 567c681..cd73ac0 100644
81850 --- a/include/net/llc_s_st.h
81851 +++ b/include/net/llc_s_st.h
81852 @@ -20,7 +20,7 @@ struct llc_sap_state_trans {
81853 llc_sap_ev_t ev;
81854 u8 next_state;
81855 llc_sap_action_t *ev_actions;
81856 -};
81857 +} __do_const;
81858
81859 struct llc_sap_state {
81860 u8 curr_state;
81861 diff --git a/include/net/mac80211.h b/include/net/mac80211.h
81862 index 7ceed99..d3ffaa2 100644
81863 --- a/include/net/mac80211.h
81864 +++ b/include/net/mac80211.h
81865 @@ -4407,7 +4407,7 @@ struct rate_control_ops {
81866 void (*add_sta_debugfs)(void *priv, void *priv_sta,
81867 struct dentry *dir);
81868 void (*remove_sta_debugfs)(void *priv, void *priv_sta);
81869 -};
81870 +} __do_const;
81871
81872 static inline int rate_supported(struct ieee80211_sta *sta,
81873 enum ieee80211_band band,
81874 diff --git a/include/net/neighbour.h b/include/net/neighbour.h
81875 index 536501a..74ad02bc 100644
81876 --- a/include/net/neighbour.h
81877 +++ b/include/net/neighbour.h
81878 @@ -123,7 +123,7 @@ struct neigh_ops {
81879 void (*error_report)(struct neighbour *, struct sk_buff *);
81880 int (*output)(struct neighbour *, struct sk_buff *);
81881 int (*connected_output)(struct neighbour *, struct sk_buff *);
81882 -};
81883 +} __do_const;
81884
81885 struct pneigh_entry {
81886 struct pneigh_entry *next;
81887 @@ -178,7 +178,7 @@ struct neigh_table {
81888 struct neigh_statistics __percpu *stats;
81889 struct neigh_hash_table __rcu *nht;
81890 struct pneigh_entry **phash_buckets;
81891 -};
81892 +} __randomize_layout;
81893
81894 #define NEIGH_PRIV_ALIGN sizeof(long long)
81895 #define NEIGH_ENTRY_SIZE(size) ALIGN((size), NEIGH_PRIV_ALIGN)
81896 diff --git a/include/net/net_namespace.h b/include/net/net_namespace.h
81897 index da68c9a..c4a0720 100644
81898 --- a/include/net/net_namespace.h
81899 +++ b/include/net/net_namespace.h
81900 @@ -124,8 +124,8 @@ struct net {
81901 struct netns_ipvs *ipvs;
81902 #endif
81903 struct sock *diag_nlsk;
81904 - atomic_t fnhe_genid;
81905 -};
81906 + atomic_unchecked_t fnhe_genid;
81907 +} __randomize_layout;
81908
81909 /*
81910 * ifindex generation is per-net namespace, and loopback is
81911 @@ -281,7 +281,11 @@ static inline struct net *read_pnet(struct net * const *pnet)
81912 #define __net_init __init
81913 #define __net_exit __exit_refok
81914 #define __net_initdata __initdata
81915 +#ifdef CONSTIFY_PLUGIN
81916 #define __net_initconst __initconst
81917 +#else
81918 +#define __net_initconst __initdata
81919 +#endif
81920 #endif
81921
81922 struct pernet_operations {
81923 @@ -291,7 +295,7 @@ struct pernet_operations {
81924 void (*exit_batch)(struct list_head *net_exit_list);
81925 int *id;
81926 size_t size;
81927 -};
81928 +} __do_const;
81929
81930 /*
81931 * Use these carefully. If you implement a network device and it
81932 @@ -339,23 +343,23 @@ static inline void unregister_net_sysctl_table(struct ctl_table_header *header)
81933
81934 static inline int rt_genid_ipv4(struct net *net)
81935 {
81936 - return atomic_read(&net->ipv4.rt_genid);
81937 + return atomic_read_unchecked(&net->ipv4.rt_genid);
81938 }
81939
81940 static inline void rt_genid_bump_ipv4(struct net *net)
81941 {
81942 - atomic_inc(&net->ipv4.rt_genid);
81943 + atomic_inc_unchecked(&net->ipv4.rt_genid);
81944 }
81945
81946 #if IS_ENABLED(CONFIG_IPV6)
81947 static inline int rt_genid_ipv6(struct net *net)
81948 {
81949 - return atomic_read(&net->ipv6.rt_genid);
81950 + return atomic_read_unchecked(&net->ipv6.rt_genid);
81951 }
81952
81953 static inline void rt_genid_bump_ipv6(struct net *net)
81954 {
81955 - atomic_inc(&net->ipv6.rt_genid);
81956 + atomic_inc_unchecked(&net->ipv6.rt_genid);
81957 }
81958 #else
81959 static inline int rt_genid_ipv6(struct net *net)
81960 @@ -377,12 +381,12 @@ static inline void rt_genid_bump_all(struct net *net)
81961
81962 static inline int fnhe_genid(struct net *net)
81963 {
81964 - return atomic_read(&net->fnhe_genid);
81965 + return atomic_read_unchecked(&net->fnhe_genid);
81966 }
81967
81968 static inline void fnhe_genid_bump(struct net *net)
81969 {
81970 - atomic_inc(&net->fnhe_genid);
81971 + atomic_inc_unchecked(&net->fnhe_genid);
81972 }
81973
81974 #endif /* __NET_NET_NAMESPACE_H */
81975 diff --git a/include/net/netdma.h b/include/net/netdma.h
81976 index 8ba8ce2..99b7fff 100644
81977 --- a/include/net/netdma.h
81978 +++ b/include/net/netdma.h
81979 @@ -24,7 +24,7 @@
81980 #include <linux/dmaengine.h>
81981 #include <linux/skbuff.h>
81982
81983 -int dma_skb_copy_datagram_iovec(struct dma_chan* chan,
81984 +int __intentional_overflow(3,5) dma_skb_copy_datagram_iovec(struct dma_chan* chan,
81985 struct sk_buff *skb, int offset, struct iovec *to,
81986 size_t len, struct dma_pinned_list *pinned_list);
81987
81988 diff --git a/include/net/netlink.h b/include/net/netlink.h
81989 index 2b47eaa..6d5bcc2 100644
81990 --- a/include/net/netlink.h
81991 +++ b/include/net/netlink.h
81992 @@ -521,7 +521,7 @@ static inline void *nlmsg_get_pos(struct sk_buff *skb)
81993 static inline void nlmsg_trim(struct sk_buff *skb, const void *mark)
81994 {
81995 if (mark)
81996 - skb_trim(skb, (unsigned char *) mark - skb->data);
81997 + skb_trim(skb, (const unsigned char *) mark - skb->data);
81998 }
81999
82000 /**
82001 diff --git a/include/net/netns/conntrack.h b/include/net/netns/conntrack.h
82002 index c9c0c53..53f24c3 100644
82003 --- a/include/net/netns/conntrack.h
82004 +++ b/include/net/netns/conntrack.h
82005 @@ -12,10 +12,10 @@ struct nf_conntrack_ecache;
82006 struct nf_proto_net {
82007 #ifdef CONFIG_SYSCTL
82008 struct ctl_table_header *ctl_table_header;
82009 - struct ctl_table *ctl_table;
82010 + ctl_table_no_const *ctl_table;
82011 #ifdef CONFIG_NF_CONNTRACK_PROC_COMPAT
82012 struct ctl_table_header *ctl_compat_header;
82013 - struct ctl_table *ctl_compat_table;
82014 + ctl_table_no_const *ctl_compat_table;
82015 #endif
82016 #endif
82017 unsigned int users;
82018 @@ -58,7 +58,7 @@ struct nf_ip_net {
82019 struct nf_icmp_net icmpv6;
82020 #if defined(CONFIG_SYSCTL) && defined(CONFIG_NF_CONNTRACK_PROC_COMPAT)
82021 struct ctl_table_header *ctl_table_header;
82022 - struct ctl_table *ctl_table;
82023 + ctl_table_no_const *ctl_table;
82024 #endif
82025 };
82026
82027 diff --git a/include/net/netns/ipv4.h b/include/net/netns/ipv4.h
82028 index ee520cb..9a0fd88 100644
82029 --- a/include/net/netns/ipv4.h
82030 +++ b/include/net/netns/ipv4.h
82031 @@ -72,7 +72,7 @@ struct netns_ipv4 {
82032
82033 kgid_t sysctl_ping_group_range[2];
82034
82035 - atomic_t dev_addr_genid;
82036 + atomic_unchecked_t dev_addr_genid;
82037
82038 #ifdef CONFIG_IP_MROUTE
82039 #ifndef CONFIG_IP_MROUTE_MULTIPLE_TABLES
82040 @@ -82,6 +82,6 @@ struct netns_ipv4 {
82041 struct fib_rules_ops *mr_rules_ops;
82042 #endif
82043 #endif
82044 - atomic_t rt_genid;
82045 + atomic_unchecked_t rt_genid;
82046 };
82047 #endif
82048 diff --git a/include/net/netns/ipv6.h b/include/net/netns/ipv6.h
82049 index 0fb2401..477d81c 100644
82050 --- a/include/net/netns/ipv6.h
82051 +++ b/include/net/netns/ipv6.h
82052 @@ -71,8 +71,8 @@ struct netns_ipv6 {
82053 struct fib_rules_ops *mr6_rules_ops;
82054 #endif
82055 #endif
82056 - atomic_t dev_addr_genid;
82057 - atomic_t rt_genid;
82058 + atomic_unchecked_t dev_addr_genid;
82059 + atomic_unchecked_t rt_genid;
82060 };
82061
82062 #if IS_ENABLED(CONFIG_NF_DEFRAG_IPV6)
82063 diff --git a/include/net/ping.h b/include/net/ping.h
82064 index 90f4841..74446a8 100644
82065 --- a/include/net/ping.h
82066 +++ b/include/net/ping.h
82067 @@ -56,7 +56,7 @@ struct ping_iter_state {
82068 extern struct proto ping_prot;
82069 extern struct ping_table ping_table;
82070 #if IS_ENABLED(CONFIG_IPV6)
82071 -extern struct pingv6_ops pingv6_ops;
82072 +extern struct pingv6_ops *pingv6_ops;
82073 #endif
82074
82075 struct pingfakehdr {
82076 diff --git a/include/net/protocol.h b/include/net/protocol.h
82077 index fbf7676..a5e21c3 100644
82078 --- a/include/net/protocol.h
82079 +++ b/include/net/protocol.h
82080 @@ -44,7 +44,7 @@ struct net_protocol {
82081 void (*err_handler)(struct sk_buff *skb, u32 info);
82082 unsigned int no_policy:1,
82083 netns_ok:1;
82084 -};
82085 +} __do_const;
82086
82087 #if IS_ENABLED(CONFIG_IPV6)
82088 struct inet6_protocol {
82089 @@ -57,7 +57,7 @@ struct inet6_protocol {
82090 u8 type, u8 code, int offset,
82091 __be32 info);
82092 unsigned int flags; /* INET6_PROTO_xxx */
82093 -};
82094 +} __do_const;
82095
82096 #define INET6_PROTO_NOPOLICY 0x1
82097 #define INET6_PROTO_FINAL 0x2
82098 diff --git a/include/net/rtnetlink.h b/include/net/rtnetlink.h
82099 index bb13a18..e734116 100644
82100 --- a/include/net/rtnetlink.h
82101 +++ b/include/net/rtnetlink.h
82102 @@ -79,7 +79,7 @@ struct rtnl_link_ops {
82103 const struct net_device *dev);
82104 unsigned int (*get_num_tx_queues)(void);
82105 unsigned int (*get_num_rx_queues)(void);
82106 -};
82107 +} __do_const;
82108
82109 int __rtnl_link_register(struct rtnl_link_ops *ops);
82110 void __rtnl_link_unregister(struct rtnl_link_ops *ops);
82111 diff --git a/include/net/sctp/checksum.h b/include/net/sctp/checksum.h
82112 index 6bd44fe..96f364e 100644
82113 --- a/include/net/sctp/checksum.h
82114 +++ b/include/net/sctp/checksum.h
82115 @@ -62,8 +62,8 @@ static inline __le32 sctp_compute_cksum(const struct sk_buff *skb,
82116 unsigned int offset)
82117 {
82118 struct sctphdr *sh = sctp_hdr(skb);
82119 - __le32 ret, old = sh->checksum;
82120 - const struct skb_checksum_ops ops = {
82121 + __le32 ret, old = sh->checksum;
82122 + static const struct skb_checksum_ops ops = {
82123 .update = sctp_csum_update,
82124 .combine = sctp_csum_combine,
82125 };
82126 diff --git a/include/net/sctp/sm.h b/include/net/sctp/sm.h
82127 index 4ef75af..5aa073a 100644
82128 --- a/include/net/sctp/sm.h
82129 +++ b/include/net/sctp/sm.h
82130 @@ -81,7 +81,7 @@ typedef void (sctp_timer_event_t) (unsigned long);
82131 typedef struct {
82132 sctp_state_fn_t *fn;
82133 const char *name;
82134 -} sctp_sm_table_entry_t;
82135 +} __do_const sctp_sm_table_entry_t;
82136
82137 /* A naming convention of "sctp_sf_xxx" applies to all the state functions
82138 * currently in use.
82139 @@ -293,7 +293,7 @@ __u32 sctp_generate_tag(const struct sctp_endpoint *);
82140 __u32 sctp_generate_tsn(const struct sctp_endpoint *);
82141
82142 /* Extern declarations for major data structures. */
82143 -extern sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
82144 +extern sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES];
82145
82146
82147 /* Get the size of a DATA chunk payload. */
82148 diff --git a/include/net/sctp/structs.h b/include/net/sctp/structs.h
82149 index 0a248b3..4dcbe5c 100644
82150 --- a/include/net/sctp/structs.h
82151 +++ b/include/net/sctp/structs.h
82152 @@ -508,7 +508,7 @@ struct sctp_pf {
82153 struct sctp_association *asoc);
82154 void (*addr_v4map) (struct sctp_sock *, union sctp_addr *);
82155 struct sctp_af *af;
82156 -};
82157 +} __do_const;
82158
82159
82160 /* Structure to track chunk fragments that have been acked, but peer
82161 diff --git a/include/net/sock.h b/include/net/sock.h
82162 index 2ef3c3e..e02013e 100644
82163 --- a/include/net/sock.h
82164 +++ b/include/net/sock.h
82165 @@ -348,7 +348,7 @@ struct sock {
82166 unsigned int sk_napi_id;
82167 unsigned int sk_ll_usec;
82168 #endif
82169 - atomic_t sk_drops;
82170 + atomic_unchecked_t sk_drops;
82171 int sk_rcvbuf;
82172
82173 struct sk_filter __rcu *sk_filter;
82174 @@ -1209,7 +1209,7 @@ static inline u64 memcg_memory_allocated_read(struct cg_proto *prot)
82175 return ret >> PAGE_SHIFT;
82176 }
82177
82178 -static inline long
82179 +static inline long __intentional_overflow(-1)
82180 sk_memory_allocated(const struct sock *sk)
82181 {
82182 struct proto *prot = sk->sk_prot;
82183 @@ -1813,7 +1813,7 @@ static inline void sk_nocaps_add(struct sock *sk, netdev_features_t flags)
82184 }
82185
82186 static inline int skb_do_copy_data_nocache(struct sock *sk, struct sk_buff *skb,
82187 - char __user *from, char *to,
82188 + char __user *from, unsigned char *to,
82189 int copy, int offset)
82190 {
82191 if (skb->ip_summed == CHECKSUM_NONE) {
82192 @@ -2075,7 +2075,7 @@ static inline void sk_stream_moderate_sndbuf(struct sock *sk)
82193 }
82194 }
82195
82196 -struct sk_buff *sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
82197 +struct sk_buff * __intentional_overflow(0) sk_stream_alloc_skb(struct sock *sk, int size, gfp_t gfp);
82198
82199 /**
82200 * sk_page_frag - return an appropriate page_frag
82201 diff --git a/include/net/tcp.h b/include/net/tcp.h
82202 index 70e55d2..c5d8d53 100644
82203 --- a/include/net/tcp.h
82204 +++ b/include/net/tcp.h
82205 @@ -540,7 +540,7 @@ void tcp_retransmit_timer(struct sock *sk);
82206 void tcp_xmit_retransmit_queue(struct sock *);
82207 void tcp_simple_retransmit(struct sock *);
82208 int tcp_trim_head(struct sock *, struct sk_buff *, u32);
82209 -int tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
82210 +int __intentional_overflow(3) tcp_fragment(struct sock *, struct sk_buff *, u32, unsigned int);
82211
82212 void tcp_send_probe0(struct sock *);
82213 void tcp_send_partial(struct sock *);
82214 @@ -711,8 +711,8 @@ struct tcp_skb_cb {
82215 struct inet6_skb_parm h6;
82216 #endif
82217 } header; /* For incoming frames */
82218 - __u32 seq; /* Starting sequence number */
82219 - __u32 end_seq; /* SEQ + FIN + SYN + datalen */
82220 + __u32 seq __intentional_overflow(0); /* Starting sequence number */
82221 + __u32 end_seq __intentional_overflow(0); /* SEQ + FIN + SYN + datalen */
82222 __u32 when; /* used to compute rtt's */
82223 __u8 tcp_flags; /* TCP header flags. (tcp[13]) */
82224
82225 @@ -726,7 +726,7 @@ struct tcp_skb_cb {
82226
82227 __u8 ip_dsfield; /* IPv4 tos or IPv6 dsfield */
82228 /* 1 byte hole */
82229 - __u32 ack_seq; /* Sequence number ACK'd */
82230 + __u32 ack_seq __intentional_overflow(0); /* Sequence number ACK'd */
82231 };
82232
82233 #define TCP_SKB_CB(__skb) ((struct tcp_skb_cb *)&((__skb)->cb[0]))
82234 diff --git a/include/net/xfrm.h b/include/net/xfrm.h
82235 index 6b82fdf..14d74d2 100644
82236 --- a/include/net/xfrm.h
82237 +++ b/include/net/xfrm.h
82238 @@ -287,7 +287,6 @@ struct xfrm_dst;
82239 struct xfrm_policy_afinfo {
82240 unsigned short family;
82241 struct dst_ops *dst_ops;
82242 - void (*garbage_collect)(struct net *net);
82243 struct dst_entry *(*dst_lookup)(struct net *net, int tos,
82244 const xfrm_address_t *saddr,
82245 const xfrm_address_t *daddr);
82246 @@ -305,7 +304,7 @@ struct xfrm_policy_afinfo {
82247 struct net_device *dev,
82248 const struct flowi *fl);
82249 struct dst_entry *(*blackhole_route)(struct net *net, struct dst_entry *orig);
82250 -};
82251 +} __do_const;
82252
82253 int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo);
82254 int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo);
82255 @@ -344,7 +343,7 @@ struct xfrm_state_afinfo {
82256 int (*transport_finish)(struct sk_buff *skb,
82257 int async);
82258 void (*local_error)(struct sk_buff *skb, u32 mtu);
82259 -};
82260 +} __do_const;
82261
82262 int xfrm_state_register_afinfo(struct xfrm_state_afinfo *afinfo);
82263 int xfrm_state_unregister_afinfo(struct xfrm_state_afinfo *afinfo);
82264 @@ -429,7 +428,7 @@ struct xfrm_mode {
82265 struct module *owner;
82266 unsigned int encap;
82267 int flags;
82268 -};
82269 +} __do_const;
82270
82271 /* Flags for xfrm_mode. */
82272 enum {
82273 @@ -526,7 +525,7 @@ struct xfrm_policy {
82274 struct timer_list timer;
82275
82276 struct flow_cache_object flo;
82277 - atomic_t genid;
82278 + atomic_unchecked_t genid;
82279 u32 priority;
82280 u32 index;
82281 struct xfrm_mark mark;
82282 @@ -1166,6 +1165,7 @@ static inline void xfrm_sk_free_policy(struct sock *sk)
82283 }
82284
82285 void xfrm_garbage_collect(struct net *net);
82286 +void xfrm_garbage_collect_deferred(struct net *net);
82287
82288 #else
82289
82290 @@ -1204,6 +1204,9 @@ static inline int xfrm6_policy_check_reverse(struct sock *sk, int dir,
82291 static inline void xfrm_garbage_collect(struct net *net)
82292 {
82293 }
82294 +static inline void xfrm_garbage_collect_deferred(struct net *net)
82295 +{
82296 +}
82297 #endif
82298
82299 static __inline__
82300 diff --git a/include/rdma/iw_cm.h b/include/rdma/iw_cm.h
82301 index 1017e0b..227aa4d 100644
82302 --- a/include/rdma/iw_cm.h
82303 +++ b/include/rdma/iw_cm.h
82304 @@ -122,7 +122,7 @@ struct iw_cm_verbs {
82305 int backlog);
82306
82307 int (*destroy_listen)(struct iw_cm_id *cm_id);
82308 -};
82309 +} __no_const;
82310
82311 /**
82312 * iw_create_cm_id - Create an IW CM identifier.
82313 diff --git a/include/scsi/libfc.h b/include/scsi/libfc.h
82314 index 52beadf..598734c 100644
82315 --- a/include/scsi/libfc.h
82316 +++ b/include/scsi/libfc.h
82317 @@ -771,6 +771,7 @@ struct libfc_function_template {
82318 */
82319 void (*disc_stop_final) (struct fc_lport *);
82320 };
82321 +typedef struct libfc_function_template __no_const libfc_function_template_no_const;
82322
82323 /**
82324 * struct fc_disc - Discovery context
82325 @@ -875,7 +876,7 @@ struct fc_lport {
82326 struct fc_vport *vport;
82327
82328 /* Operational Information */
82329 - struct libfc_function_template tt;
82330 + libfc_function_template_no_const tt;
82331 u8 link_up;
82332 u8 qfull;
82333 enum fc_lport_state state;
82334 diff --git a/include/scsi/scsi_device.h b/include/scsi/scsi_device.h
82335 index d65fbec..f80fef2 100644
82336 --- a/include/scsi/scsi_device.h
82337 +++ b/include/scsi/scsi_device.h
82338 @@ -180,9 +180,9 @@ struct scsi_device {
82339 unsigned int max_device_blocked; /* what device_blocked counts down from */
82340 #define SCSI_DEFAULT_DEVICE_BLOCKED 3
82341
82342 - atomic_t iorequest_cnt;
82343 - atomic_t iodone_cnt;
82344 - atomic_t ioerr_cnt;
82345 + atomic_unchecked_t iorequest_cnt;
82346 + atomic_unchecked_t iodone_cnt;
82347 + atomic_unchecked_t ioerr_cnt;
82348
82349 struct device sdev_gendev,
82350 sdev_dev;
82351 diff --git a/include/scsi/scsi_transport_fc.h b/include/scsi/scsi_transport_fc.h
82352 index b797e8f..8e2c3aa 100644
82353 --- a/include/scsi/scsi_transport_fc.h
82354 +++ b/include/scsi/scsi_transport_fc.h
82355 @@ -751,7 +751,8 @@ struct fc_function_template {
82356 unsigned long show_host_system_hostname:1;
82357
82358 unsigned long disable_target_scan:1;
82359 -};
82360 +} __do_const;
82361 +typedef struct fc_function_template __no_const fc_function_template_no_const;
82362
82363
82364 /**
82365 diff --git a/include/sound/compress_driver.h b/include/sound/compress_driver.h
82366 index ae6c3b8..fd748ac 100644
82367 --- a/include/sound/compress_driver.h
82368 +++ b/include/sound/compress_driver.h
82369 @@ -128,7 +128,7 @@ struct snd_compr_ops {
82370 struct snd_compr_caps *caps);
82371 int (*get_codec_caps) (struct snd_compr_stream *stream,
82372 struct snd_compr_codec_caps *codec);
82373 -};
82374 +} __no_const;
82375
82376 /**
82377 * struct snd_compr: Compressed device
82378 diff --git a/include/sound/soc.h b/include/sound/soc.h
82379 index 1f741cb..8cefc08 100644
82380 --- a/include/sound/soc.h
82381 +++ b/include/sound/soc.h
82382 @@ -763,7 +763,7 @@ struct snd_soc_codec_driver {
82383 /* probe ordering - for components with runtime dependencies */
82384 int probe_order;
82385 int remove_order;
82386 -};
82387 +} __do_const;
82388
82389 /* SoC platform interface */
82390 struct snd_soc_platform_driver {
82391 @@ -809,7 +809,7 @@ struct snd_soc_platform_driver {
82392 unsigned int (*read)(struct snd_soc_platform *, unsigned int);
82393 int (*write)(struct snd_soc_platform *, unsigned int, unsigned int);
82394 int (*bespoke_trigger)(struct snd_pcm_substream *, int);
82395 -};
82396 +} __do_const;
82397
82398 struct snd_soc_platform {
82399 const char *name;
82400 diff --git a/include/target/target_core_base.h b/include/target/target_core_base.h
82401 index e3569f8..6544ffd 100644
82402 --- a/include/target/target_core_base.h
82403 +++ b/include/target/target_core_base.h
82404 @@ -687,7 +687,7 @@ struct se_device {
82405 atomic_long_t write_bytes;
82406 /* Active commands on this virtual SE device */
82407 atomic_t simple_cmds;
82408 - atomic_t dev_ordered_id;
82409 + atomic_unchecked_t dev_ordered_id;
82410 atomic_t dev_ordered_sync;
82411 atomic_t dev_qf_count;
82412 int export_count;
82413 diff --git a/include/trace/events/fs.h b/include/trace/events/fs.h
82414 new file mode 100644
82415 index 0000000..fb634b7
82416 --- /dev/null
82417 +++ b/include/trace/events/fs.h
82418 @@ -0,0 +1,53 @@
82419 +#undef TRACE_SYSTEM
82420 +#define TRACE_SYSTEM fs
82421 +
82422 +#if !defined(_TRACE_FS_H) || defined(TRACE_HEADER_MULTI_READ)
82423 +#define _TRACE_FS_H
82424 +
82425 +#include <linux/fs.h>
82426 +#include <linux/tracepoint.h>
82427 +
82428 +TRACE_EVENT(do_sys_open,
82429 +
82430 + TP_PROTO(const char *filename, int flags, int mode),
82431 +
82432 + TP_ARGS(filename, flags, mode),
82433 +
82434 + TP_STRUCT__entry(
82435 + __string( filename, filename )
82436 + __field( int, flags )
82437 + __field( int, mode )
82438 + ),
82439 +
82440 + TP_fast_assign(
82441 + __assign_str(filename, filename);
82442 + __entry->flags = flags;
82443 + __entry->mode = mode;
82444 + ),
82445 +
82446 + TP_printk("\"%s\" %x %o",
82447 + __get_str(filename), __entry->flags, __entry->mode)
82448 +);
82449 +
82450 +TRACE_EVENT(open_exec,
82451 +
82452 + TP_PROTO(const char *filename),
82453 +
82454 + TP_ARGS(filename),
82455 +
82456 + TP_STRUCT__entry(
82457 + __string( filename, filename )
82458 + ),
82459 +
82460 + TP_fast_assign(
82461 + __assign_str(filename, filename);
82462 + ),
82463 +
82464 + TP_printk("\"%s\"",
82465 + __get_str(filename))
82466 +);
82467 +
82468 +#endif /* _TRACE_FS_H */
82469 +
82470 +/* This part must be outside protection */
82471 +#include <trace/define_trace.h>
82472 diff --git a/include/trace/events/irq.h b/include/trace/events/irq.h
82473 index 1c09820..7f5ec79 100644
82474 --- a/include/trace/events/irq.h
82475 +++ b/include/trace/events/irq.h
82476 @@ -36,7 +36,7 @@ struct softirq_action;
82477 */
82478 TRACE_EVENT(irq_handler_entry,
82479
82480 - TP_PROTO(int irq, struct irqaction *action),
82481 + TP_PROTO(int irq, const struct irqaction *action),
82482
82483 TP_ARGS(irq, action),
82484
82485 @@ -66,7 +66,7 @@ TRACE_EVENT(irq_handler_entry,
82486 */
82487 TRACE_EVENT(irq_handler_exit,
82488
82489 - TP_PROTO(int irq, struct irqaction *action, int ret),
82490 + TP_PROTO(int irq, const struct irqaction *action, int ret),
82491
82492 TP_ARGS(irq, action, ret),
82493
82494 diff --git a/include/uapi/linux/a.out.h b/include/uapi/linux/a.out.h
82495 index 7caf44c..23c6f27 100644
82496 --- a/include/uapi/linux/a.out.h
82497 +++ b/include/uapi/linux/a.out.h
82498 @@ -39,6 +39,14 @@ enum machine_type {
82499 M_MIPS2 = 152 /* MIPS R6000/R4000 binary */
82500 };
82501
82502 +/* Constants for the N_FLAGS field */
82503 +#define F_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
82504 +#define F_PAX_EMUTRAMP 2 /* Emulate trampolines */
82505 +#define F_PAX_MPROTECT 4 /* Restrict mprotect() */
82506 +#define F_PAX_RANDMMAP 8 /* Randomize mmap() base */
82507 +/*#define F_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
82508 +#define F_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
82509 +
82510 #if !defined (N_MAGIC)
82511 #define N_MAGIC(exec) ((exec).a_info & 0xffff)
82512 #endif
82513 diff --git a/include/uapi/linux/byteorder/little_endian.h b/include/uapi/linux/byteorder/little_endian.h
82514 index d876736..ccce5c0 100644
82515 --- a/include/uapi/linux/byteorder/little_endian.h
82516 +++ b/include/uapi/linux/byteorder/little_endian.h
82517 @@ -42,51 +42,51 @@
82518
82519 static inline __le64 __cpu_to_le64p(const __u64 *p)
82520 {
82521 - return (__force __le64)*p;
82522 + return (__force const __le64)*p;
82523 }
82524 -static inline __u64 __le64_to_cpup(const __le64 *p)
82525 +static inline __u64 __intentional_overflow(-1) __le64_to_cpup(const __le64 *p)
82526 {
82527 - return (__force __u64)*p;
82528 + return (__force const __u64)*p;
82529 }
82530 static inline __le32 __cpu_to_le32p(const __u32 *p)
82531 {
82532 - return (__force __le32)*p;
82533 + return (__force const __le32)*p;
82534 }
82535 static inline __u32 __le32_to_cpup(const __le32 *p)
82536 {
82537 - return (__force __u32)*p;
82538 + return (__force const __u32)*p;
82539 }
82540 static inline __le16 __cpu_to_le16p(const __u16 *p)
82541 {
82542 - return (__force __le16)*p;
82543 + return (__force const __le16)*p;
82544 }
82545 static inline __u16 __le16_to_cpup(const __le16 *p)
82546 {
82547 - return (__force __u16)*p;
82548 + return (__force const __u16)*p;
82549 }
82550 static inline __be64 __cpu_to_be64p(const __u64 *p)
82551 {
82552 - return (__force __be64)__swab64p(p);
82553 + return (__force const __be64)__swab64p(p);
82554 }
82555 static inline __u64 __be64_to_cpup(const __be64 *p)
82556 {
82557 - return __swab64p((__u64 *)p);
82558 + return __swab64p((const __u64 *)p);
82559 }
82560 static inline __be32 __cpu_to_be32p(const __u32 *p)
82561 {
82562 - return (__force __be32)__swab32p(p);
82563 + return (__force const __be32)__swab32p(p);
82564 }
82565 -static inline __u32 __be32_to_cpup(const __be32 *p)
82566 +static inline __u32 __intentional_overflow(-1) __be32_to_cpup(const __be32 *p)
82567 {
82568 - return __swab32p((__u32 *)p);
82569 + return __swab32p((const __u32 *)p);
82570 }
82571 static inline __be16 __cpu_to_be16p(const __u16 *p)
82572 {
82573 - return (__force __be16)__swab16p(p);
82574 + return (__force const __be16)__swab16p(p);
82575 }
82576 static inline __u16 __be16_to_cpup(const __be16 *p)
82577 {
82578 - return __swab16p((__u16 *)p);
82579 + return __swab16p((const __u16 *)p);
82580 }
82581 #define __cpu_to_le64s(x) do { (void)(x); } while (0)
82582 #define __le64_to_cpus(x) do { (void)(x); } while (0)
82583 diff --git a/include/uapi/linux/elf.h b/include/uapi/linux/elf.h
82584 index ef6103b..d4e65dd 100644
82585 --- a/include/uapi/linux/elf.h
82586 +++ b/include/uapi/linux/elf.h
82587 @@ -37,6 +37,17 @@ typedef __s64 Elf64_Sxword;
82588 #define PT_GNU_EH_FRAME 0x6474e550
82589
82590 #define PT_GNU_STACK (PT_LOOS + 0x474e551)
82591 +#define PT_GNU_RELRO (PT_LOOS + 0x474e552)
82592 +
82593 +#define PT_PAX_FLAGS (PT_LOOS + 0x5041580)
82594 +
82595 +/* Constants for the e_flags field */
82596 +#define EF_PAX_PAGEEXEC 1 /* Paging based non-executable pages */
82597 +#define EF_PAX_EMUTRAMP 2 /* Emulate trampolines */
82598 +#define EF_PAX_MPROTECT 4 /* Restrict mprotect() */
82599 +#define EF_PAX_RANDMMAP 8 /* Randomize mmap() base */
82600 +/*#define EF_PAX_RANDEXEC 16*/ /* Randomize ET_EXEC base */
82601 +#define EF_PAX_SEGMEXEC 32 /* Segmentation based non-executable pages */
82602
82603 /*
82604 * Extended Numbering
82605 @@ -94,6 +105,8 @@ typedef __s64 Elf64_Sxword;
82606 #define DT_DEBUG 21
82607 #define DT_TEXTREL 22
82608 #define DT_JMPREL 23
82609 +#define DT_FLAGS 30
82610 + #define DF_TEXTREL 0x00000004
82611 #define DT_ENCODING 32
82612 #define OLD_DT_LOOS 0x60000000
82613 #define DT_LOOS 0x6000000d
82614 @@ -240,6 +253,19 @@ typedef struct elf64_hdr {
82615 #define PF_W 0x2
82616 #define PF_X 0x1
82617
82618 +#define PF_PAGEEXEC (1U << 4) /* Enable PAGEEXEC */
82619 +#define PF_NOPAGEEXEC (1U << 5) /* Disable PAGEEXEC */
82620 +#define PF_SEGMEXEC (1U << 6) /* Enable SEGMEXEC */
82621 +#define PF_NOSEGMEXEC (1U << 7) /* Disable SEGMEXEC */
82622 +#define PF_MPROTECT (1U << 8) /* Enable MPROTECT */
82623 +#define PF_NOMPROTECT (1U << 9) /* Disable MPROTECT */
82624 +/*#define PF_RANDEXEC (1U << 10)*/ /* Enable RANDEXEC */
82625 +/*#define PF_NORANDEXEC (1U << 11)*/ /* Disable RANDEXEC */
82626 +#define PF_EMUTRAMP (1U << 12) /* Enable EMUTRAMP */
82627 +#define PF_NOEMUTRAMP (1U << 13) /* Disable EMUTRAMP */
82628 +#define PF_RANDMMAP (1U << 14) /* Enable RANDMMAP */
82629 +#define PF_NORANDMMAP (1U << 15) /* Disable RANDMMAP */
82630 +
82631 typedef struct elf32_phdr{
82632 Elf32_Word p_type;
82633 Elf32_Off p_offset;
82634 @@ -332,6 +358,8 @@ typedef struct elf64_shdr {
82635 #define EI_OSABI 7
82636 #define EI_PAD 8
82637
82638 +#define EI_PAX 14
82639 +
82640 #define ELFMAG0 0x7f /* EI_MAG */
82641 #define ELFMAG1 'E'
82642 #define ELFMAG2 'L'
82643 diff --git a/include/uapi/linux/personality.h b/include/uapi/linux/personality.h
82644 index aa169c4..6a2771d 100644
82645 --- a/include/uapi/linux/personality.h
82646 +++ b/include/uapi/linux/personality.h
82647 @@ -30,6 +30,7 @@ enum {
82648 #define PER_CLEAR_ON_SETID (READ_IMPLIES_EXEC | \
82649 ADDR_NO_RANDOMIZE | \
82650 ADDR_COMPAT_LAYOUT | \
82651 + ADDR_LIMIT_3GB | \
82652 MMAP_PAGE_ZERO)
82653
82654 /*
82655 diff --git a/include/uapi/linux/screen_info.h b/include/uapi/linux/screen_info.h
82656 index 7530e74..e714828 100644
82657 --- a/include/uapi/linux/screen_info.h
82658 +++ b/include/uapi/linux/screen_info.h
82659 @@ -43,7 +43,8 @@ struct screen_info {
82660 __u16 pages; /* 0x32 */
82661 __u16 vesa_attributes; /* 0x34 */
82662 __u32 capabilities; /* 0x36 */
82663 - __u8 _reserved[6]; /* 0x3a */
82664 + __u16 vesapm_size; /* 0x3a */
82665 + __u8 _reserved[4]; /* 0x3c */
82666 } __attribute__((packed));
82667
82668 #define VIDEO_TYPE_MDA 0x10 /* Monochrome Text Display */
82669 diff --git a/include/uapi/linux/swab.h b/include/uapi/linux/swab.h
82670 index 0e011eb..82681b1 100644
82671 --- a/include/uapi/linux/swab.h
82672 +++ b/include/uapi/linux/swab.h
82673 @@ -43,7 +43,7 @@
82674 * ___swab16, ___swab32, ___swab64, ___swahw32, ___swahb32
82675 */
82676
82677 -static inline __attribute_const__ __u16 __fswab16(__u16 val)
82678 +static inline __intentional_overflow(-1) __attribute_const__ __u16 __fswab16(__u16 val)
82679 {
82680 #ifdef __HAVE_BUILTIN_BSWAP16__
82681 return __builtin_bswap16(val);
82682 @@ -54,7 +54,7 @@ static inline __attribute_const__ __u16 __fswab16(__u16 val)
82683 #endif
82684 }
82685
82686 -static inline __attribute_const__ __u32 __fswab32(__u32 val)
82687 +static inline __intentional_overflow(-1) __attribute_const__ __u32 __fswab32(__u32 val)
82688 {
82689 #ifdef __HAVE_BUILTIN_BSWAP32__
82690 return __builtin_bswap32(val);
82691 @@ -65,7 +65,7 @@ static inline __attribute_const__ __u32 __fswab32(__u32 val)
82692 #endif
82693 }
82694
82695 -static inline __attribute_const__ __u64 __fswab64(__u64 val)
82696 +static inline __intentional_overflow(-1) __attribute_const__ __u64 __fswab64(__u64 val)
82697 {
82698 #ifdef __HAVE_BUILTIN_BSWAP64__
82699 return __builtin_bswap64(val);
82700 diff --git a/include/uapi/linux/sysctl.h b/include/uapi/linux/sysctl.h
82701 index 6d67213..552fdd9 100644
82702 --- a/include/uapi/linux/sysctl.h
82703 +++ b/include/uapi/linux/sysctl.h
82704 @@ -155,8 +155,6 @@ enum
82705 KERN_PANIC_ON_NMI=76, /* int: whether we will panic on an unrecovered */
82706 };
82707
82708 -
82709 -
82710 /* CTL_VM names: */
82711 enum
82712 {
82713 diff --git a/include/uapi/linux/videodev2.h b/include/uapi/linux/videodev2.h
82714 index 437f1b0..0eeb38d 100644
82715 --- a/include/uapi/linux/videodev2.h
82716 +++ b/include/uapi/linux/videodev2.h
82717 @@ -1227,7 +1227,7 @@ struct v4l2_ext_control {
82718 union {
82719 __s32 value;
82720 __s64 value64;
82721 - char *string;
82722 + char __user *string;
82723 };
82724 } __attribute__ ((packed));
82725
82726 diff --git a/include/uapi/linux/xattr.h b/include/uapi/linux/xattr.h
82727 index e4629b9..6958086 100644
82728 --- a/include/uapi/linux/xattr.h
82729 +++ b/include/uapi/linux/xattr.h
82730 @@ -63,5 +63,9 @@
82731 #define XATTR_POSIX_ACL_DEFAULT "posix_acl_default"
82732 #define XATTR_NAME_POSIX_ACL_DEFAULT XATTR_SYSTEM_PREFIX XATTR_POSIX_ACL_DEFAULT
82733
82734 +/* User namespace */
82735 +#define XATTR_PAX_PREFIX XATTR_USER_PREFIX "pax."
82736 +#define XATTR_PAX_FLAGS_SUFFIX "flags"
82737 +#define XATTR_NAME_PAX_FLAGS XATTR_PAX_PREFIX XATTR_PAX_FLAGS_SUFFIX
82738
82739 #endif /* _UAPI_LINUX_XATTR_H */
82740 diff --git a/include/video/udlfb.h b/include/video/udlfb.h
82741 index f9466fa..f4e2b81 100644
82742 --- a/include/video/udlfb.h
82743 +++ b/include/video/udlfb.h
82744 @@ -53,10 +53,10 @@ struct dlfb_data {
82745 u32 pseudo_palette[256];
82746 int blank_mode; /*one of FB_BLANK_ */
82747 /* blit-only rendering path metrics, exposed through sysfs */
82748 - atomic_t bytes_rendered; /* raw pixel-bytes driver asked to render */
82749 - atomic_t bytes_identical; /* saved effort with backbuffer comparison */
82750 - atomic_t bytes_sent; /* to usb, after compression including overhead */
82751 - atomic_t cpu_kcycles_used; /* transpired during pixel processing */
82752 + atomic_unchecked_t bytes_rendered; /* raw pixel-bytes driver asked to render */
82753 + atomic_unchecked_t bytes_identical; /* saved effort with backbuffer comparison */
82754 + atomic_unchecked_t bytes_sent; /* to usb, after compression including overhead */
82755 + atomic_unchecked_t cpu_kcycles_used; /* transpired during pixel processing */
82756 };
82757
82758 #define NR_USB_REQUEST_I2C_SUB_IO 0x02
82759 diff --git a/include/video/uvesafb.h b/include/video/uvesafb.h
82760 index 30f5362..8ed8ac9 100644
82761 --- a/include/video/uvesafb.h
82762 +++ b/include/video/uvesafb.h
82763 @@ -122,6 +122,7 @@ struct uvesafb_par {
82764 u8 ypan; /* 0 - nothing, 1 - ypan, 2 - ywrap */
82765 u8 pmi_setpal; /* PMI for palette changes */
82766 u16 *pmi_base; /* protected mode interface location */
82767 + u8 *pmi_code; /* protected mode code location */
82768 void *pmi_start;
82769 void *pmi_pal;
82770 u8 *vbe_state_orig; /*
82771 diff --git a/init/Kconfig b/init/Kconfig
82772 index 4e5d96a..93cd8a1 100644
82773 --- a/init/Kconfig
82774 +++ b/init/Kconfig
82775 @@ -1079,6 +1079,7 @@ endif # CGROUPS
82776
82777 config CHECKPOINT_RESTORE
82778 bool "Checkpoint/restore support" if EXPERT
82779 + depends on !GRKERNSEC
82780 default n
82781 help
82782 Enables additional kernel features in a sake of checkpoint/restore.
82783 @@ -1550,7 +1551,7 @@ config SLUB_DEBUG
82784
82785 config COMPAT_BRK
82786 bool "Disable heap randomization"
82787 - default y
82788 + default n
82789 help
82790 Randomizing heap placement makes heap exploits harder, but it
82791 also breaks ancient binaries (including anything libc5 based).
82792 @@ -1838,7 +1839,7 @@ config INIT_ALL_POSSIBLE
82793 config STOP_MACHINE
82794 bool
82795 default y
82796 - depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU
82797 + depends on (SMP && MODULE_UNLOAD) || HOTPLUG_CPU || GRKERNSEC
82798 help
82799 Need stop_machine() primitive.
82800
82801 diff --git a/init/Makefile b/init/Makefile
82802 index 7bc47ee..6da2dc7 100644
82803 --- a/init/Makefile
82804 +++ b/init/Makefile
82805 @@ -2,6 +2,9 @@
82806 # Makefile for the linux kernel.
82807 #
82808
82809 +ccflags-y := $(GCC_PLUGINS_CFLAGS)
82810 +asflags-y := $(GCC_PLUGINS_AFLAGS)
82811 +
82812 obj-y := main.o version.o mounts.o
82813 ifneq ($(CONFIG_BLK_DEV_INITRD),y)
82814 obj-y += noinitramfs.o
82815 diff --git a/init/do_mounts.c b/init/do_mounts.c
82816 index 8e5addc..c96ea61 100644
82817 --- a/init/do_mounts.c
82818 +++ b/init/do_mounts.c
82819 @@ -359,11 +359,11 @@ static void __init get_fs_names(char *page)
82820 static int __init do_mount_root(char *name, char *fs, int flags, void *data)
82821 {
82822 struct super_block *s;
82823 - int err = sys_mount(name, "/root", fs, flags, data);
82824 + int err = sys_mount((char __force_user *)name, (char __force_user *)"/root", (char __force_user *)fs, flags, (void __force_user *)data);
82825 if (err)
82826 return err;
82827
82828 - sys_chdir("/root");
82829 + sys_chdir((const char __force_user *)"/root");
82830 s = current->fs->pwd.dentry->d_sb;
82831 ROOT_DEV = s->s_dev;
82832 printk(KERN_INFO
82833 @@ -484,18 +484,18 @@ void __init change_floppy(char *fmt, ...)
82834 va_start(args, fmt);
82835 vsprintf(buf, fmt, args);
82836 va_end(args);
82837 - fd = sys_open("/dev/root", O_RDWR | O_NDELAY, 0);
82838 + fd = sys_open((char __user *)"/dev/root", O_RDWR | O_NDELAY, 0);
82839 if (fd >= 0) {
82840 sys_ioctl(fd, FDEJECT, 0);
82841 sys_close(fd);
82842 }
82843 printk(KERN_NOTICE "VFS: Insert %s and press ENTER\n", buf);
82844 - fd = sys_open("/dev/console", O_RDWR, 0);
82845 + fd = sys_open((__force const char __user *)"/dev/console", O_RDWR, 0);
82846 if (fd >= 0) {
82847 sys_ioctl(fd, TCGETS, (long)&termios);
82848 termios.c_lflag &= ~ICANON;
82849 sys_ioctl(fd, TCSETSF, (long)&termios);
82850 - sys_read(fd, &c, 1);
82851 + sys_read(fd, (char __user *)&c, 1);
82852 termios.c_lflag |= ICANON;
82853 sys_ioctl(fd, TCSETSF, (long)&termios);
82854 sys_close(fd);
82855 @@ -589,8 +589,8 @@ void __init prepare_namespace(void)
82856 mount_root();
82857 out:
82858 devtmpfs_mount("dev");
82859 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
82860 - sys_chroot(".");
82861 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
82862 + sys_chroot((const char __force_user *)".");
82863 }
82864
82865 static bool is_tmpfs;
82866 diff --git a/init/do_mounts.h b/init/do_mounts.h
82867 index f5b978a..69dbfe8 100644
82868 --- a/init/do_mounts.h
82869 +++ b/init/do_mounts.h
82870 @@ -15,15 +15,15 @@ extern int root_mountflags;
82871
82872 static inline int create_dev(char *name, dev_t dev)
82873 {
82874 - sys_unlink(name);
82875 - return sys_mknod(name, S_IFBLK|0600, new_encode_dev(dev));
82876 + sys_unlink((char __force_user *)name);
82877 + return sys_mknod((char __force_user *)name, S_IFBLK|0600, new_encode_dev(dev));
82878 }
82879
82880 #if BITS_PER_LONG == 32
82881 static inline u32 bstat(char *name)
82882 {
82883 struct stat64 stat;
82884 - if (sys_stat64(name, &stat) != 0)
82885 + if (sys_stat64((char __force_user *)name, (struct stat64 __force_user *)&stat) != 0)
82886 return 0;
82887 if (!S_ISBLK(stat.st_mode))
82888 return 0;
82889 @@ -35,7 +35,7 @@ static inline u32 bstat(char *name)
82890 static inline u32 bstat(char *name)
82891 {
82892 struct stat stat;
82893 - if (sys_newstat(name, &stat) != 0)
82894 + if (sys_newstat((const char __force_user *)name, (struct stat __force_user *)&stat) != 0)
82895 return 0;
82896 if (!S_ISBLK(stat.st_mode))
82897 return 0;
82898 diff --git a/init/do_mounts_initrd.c b/init/do_mounts_initrd.c
82899 index 3e0878e..8a9d7a0 100644
82900 --- a/init/do_mounts_initrd.c
82901 +++ b/init/do_mounts_initrd.c
82902 @@ -37,13 +37,13 @@ static int init_linuxrc(struct subprocess_info *info, struct cred *new)
82903 {
82904 sys_unshare(CLONE_FS | CLONE_FILES);
82905 /* stdin/stdout/stderr for /linuxrc */
82906 - sys_open("/dev/console", O_RDWR, 0);
82907 + sys_open((const char __force_user *)"/dev/console", O_RDWR, 0);
82908 sys_dup(0);
82909 sys_dup(0);
82910 /* move initrd over / and chdir/chroot in initrd root */
82911 - sys_chdir("/root");
82912 - sys_mount(".", "/", NULL, MS_MOVE, NULL);
82913 - sys_chroot(".");
82914 + sys_chdir((const char __force_user *)"/root");
82915 + sys_mount((char __force_user *)".", (char __force_user *)"/", NULL, MS_MOVE, NULL);
82916 + sys_chroot((const char __force_user *)".");
82917 sys_setsid();
82918 return 0;
82919 }
82920 @@ -59,8 +59,8 @@ static void __init handle_initrd(void)
82921 create_dev("/dev/root.old", Root_RAM0);
82922 /* mount initrd on rootfs' /root */
82923 mount_block_root("/dev/root.old", root_mountflags & ~MS_RDONLY);
82924 - sys_mkdir("/old", 0700);
82925 - sys_chdir("/old");
82926 + sys_mkdir((const char __force_user *)"/old", 0700);
82927 + sys_chdir((const char __force_user *)"/old");
82928
82929 /* try loading default modules from initrd */
82930 load_default_modules();
82931 @@ -80,31 +80,31 @@ static void __init handle_initrd(void)
82932 current->flags &= ~PF_FREEZER_SKIP;
82933
82934 /* move initrd to rootfs' /old */
82935 - sys_mount("..", ".", NULL, MS_MOVE, NULL);
82936 + sys_mount((char __force_user *)"..", (char __force_user *)".", NULL, MS_MOVE, NULL);
82937 /* switch root and cwd back to / of rootfs */
82938 - sys_chroot("..");
82939 + sys_chroot((const char __force_user *)"..");
82940
82941 if (new_decode_dev(real_root_dev) == Root_RAM0) {
82942 - sys_chdir("/old");
82943 + sys_chdir((const char __force_user *)"/old");
82944 return;
82945 }
82946
82947 - sys_chdir("/");
82948 + sys_chdir((const char __force_user *)"/");
82949 ROOT_DEV = new_decode_dev(real_root_dev);
82950 mount_root();
82951
82952 printk(KERN_NOTICE "Trying to move old root to /initrd ... ");
82953 - error = sys_mount("/old", "/root/initrd", NULL, MS_MOVE, NULL);
82954 + error = sys_mount((char __force_user *)"/old", (char __force_user *)"/root/initrd", NULL, MS_MOVE, NULL);
82955 if (!error)
82956 printk("okay\n");
82957 else {
82958 - int fd = sys_open("/dev/root.old", O_RDWR, 0);
82959 + int fd = sys_open((const char __force_user *)"/dev/root.old", O_RDWR, 0);
82960 if (error == -ENOENT)
82961 printk("/initrd does not exist. Ignored.\n");
82962 else
82963 printk("failed\n");
82964 printk(KERN_NOTICE "Unmounting old root\n");
82965 - sys_umount("/old", MNT_DETACH);
82966 + sys_umount((char __force_user *)"/old", MNT_DETACH);
82967 printk(KERN_NOTICE "Trying to free ramdisk memory ... ");
82968 if (fd < 0) {
82969 error = fd;
82970 @@ -127,11 +127,11 @@ int __init initrd_load(void)
82971 * mounted in the normal path.
82972 */
82973 if (rd_load_image("/initrd.image") && ROOT_DEV != Root_RAM0) {
82974 - sys_unlink("/initrd.image");
82975 + sys_unlink((const char __force_user *)"/initrd.image");
82976 handle_initrd();
82977 return 1;
82978 }
82979 }
82980 - sys_unlink("/initrd.image");
82981 + sys_unlink((const char __force_user *)"/initrd.image");
82982 return 0;
82983 }
82984 diff --git a/init/do_mounts_md.c b/init/do_mounts_md.c
82985 index 8cb6db5..d729f50 100644
82986 --- a/init/do_mounts_md.c
82987 +++ b/init/do_mounts_md.c
82988 @@ -180,7 +180,7 @@ static void __init md_setup_drive(void)
82989 partitioned ? "_d" : "", minor,
82990 md_setup_args[ent].device_names);
82991
82992 - fd = sys_open(name, 0, 0);
82993 + fd = sys_open((char __force_user *)name, 0, 0);
82994 if (fd < 0) {
82995 printk(KERN_ERR "md: open failed - cannot start "
82996 "array %s\n", name);
82997 @@ -243,7 +243,7 @@ static void __init md_setup_drive(void)
82998 * array without it
82999 */
83000 sys_close(fd);
83001 - fd = sys_open(name, 0, 0);
83002 + fd = sys_open((char __force_user *)name, 0, 0);
83003 sys_ioctl(fd, BLKRRPART, 0);
83004 }
83005 sys_close(fd);
83006 @@ -293,7 +293,7 @@ static void __init autodetect_raid(void)
83007
83008 wait_for_device_probe();
83009
83010 - fd = sys_open("/dev/md0", 0, 0);
83011 + fd = sys_open((const char __force_user *) "/dev/md0", 0, 0);
83012 if (fd >= 0) {
83013 sys_ioctl(fd, RAID_AUTORUN, raid_autopart);
83014 sys_close(fd);
83015 diff --git a/init/init_task.c b/init/init_task.c
83016 index ba0a7f36..2bcf1d5 100644
83017 --- a/init/init_task.c
83018 +++ b/init/init_task.c
83019 @@ -22,5 +22,9 @@ EXPORT_SYMBOL(init_task);
83020 * Initial thread structure. Alignment of this is handled by a special
83021 * linker map entry.
83022 */
83023 +#ifdef CONFIG_X86
83024 +union thread_union init_thread_union __init_task_data;
83025 +#else
83026 union thread_union init_thread_union __init_task_data =
83027 { INIT_THREAD_INFO(init_task) };
83028 +#endif
83029 diff --git a/init/initramfs.c b/init/initramfs.c
83030 index a67ef9d..2d17ed9 100644
83031 --- a/init/initramfs.c
83032 +++ b/init/initramfs.c
83033 @@ -84,7 +84,7 @@ static void __init free_hash(void)
83034 }
83035 }
83036
83037 -static long __init do_utime(char *filename, time_t mtime)
83038 +static long __init do_utime(char __force_user *filename, time_t mtime)
83039 {
83040 struct timespec t[2];
83041
83042 @@ -119,7 +119,7 @@ static void __init dir_utime(void)
83043 struct dir_entry *de, *tmp;
83044 list_for_each_entry_safe(de, tmp, &dir_list, list) {
83045 list_del(&de->list);
83046 - do_utime(de->name, de->mtime);
83047 + do_utime((char __force_user *)de->name, de->mtime);
83048 kfree(de->name);
83049 kfree(de);
83050 }
83051 @@ -281,7 +281,7 @@ static int __init maybe_link(void)
83052 if (nlink >= 2) {
83053 char *old = find_link(major, minor, ino, mode, collected);
83054 if (old)
83055 - return (sys_link(old, collected) < 0) ? -1 : 1;
83056 + return (sys_link((char __force_user *)old, (char __force_user *)collected) < 0) ? -1 : 1;
83057 }
83058 return 0;
83059 }
83060 @@ -290,11 +290,11 @@ static void __init clean_path(char *path, umode_t mode)
83061 {
83062 struct stat st;
83063
83064 - if (!sys_newlstat(path, &st) && (st.st_mode^mode) & S_IFMT) {
83065 + if (!sys_newlstat((char __force_user *)path, (struct stat __force_user *)&st) && (st.st_mode^mode) & S_IFMT) {
83066 if (S_ISDIR(st.st_mode))
83067 - sys_rmdir(path);
83068 + sys_rmdir((char __force_user *)path);
83069 else
83070 - sys_unlink(path);
83071 + sys_unlink((char __force_user *)path);
83072 }
83073 }
83074
83075 @@ -315,7 +315,7 @@ static int __init do_name(void)
83076 int openflags = O_WRONLY|O_CREAT;
83077 if (ml != 1)
83078 openflags |= O_TRUNC;
83079 - wfd = sys_open(collected, openflags, mode);
83080 + wfd = sys_open((char __force_user *)collected, openflags, mode);
83081
83082 if (wfd >= 0) {
83083 sys_fchown(wfd, uid, gid);
83084 @@ -327,17 +327,17 @@ static int __init do_name(void)
83085 }
83086 }
83087 } else if (S_ISDIR(mode)) {
83088 - sys_mkdir(collected, mode);
83089 - sys_chown(collected, uid, gid);
83090 - sys_chmod(collected, mode);
83091 + sys_mkdir((char __force_user *)collected, mode);
83092 + sys_chown((char __force_user *)collected, uid, gid);
83093 + sys_chmod((char __force_user *)collected, mode);
83094 dir_add(collected, mtime);
83095 } else if (S_ISBLK(mode) || S_ISCHR(mode) ||
83096 S_ISFIFO(mode) || S_ISSOCK(mode)) {
83097 if (maybe_link() == 0) {
83098 - sys_mknod(collected, mode, rdev);
83099 - sys_chown(collected, uid, gid);
83100 - sys_chmod(collected, mode);
83101 - do_utime(collected, mtime);
83102 + sys_mknod((char __force_user *)collected, mode, rdev);
83103 + sys_chown((char __force_user *)collected, uid, gid);
83104 + sys_chmod((char __force_user *)collected, mode);
83105 + do_utime((char __force_user *)collected, mtime);
83106 }
83107 }
83108 return 0;
83109 @@ -346,15 +346,15 @@ static int __init do_name(void)
83110 static int __init do_copy(void)
83111 {
83112 if (count >= body_len) {
83113 - sys_write(wfd, victim, body_len);
83114 + sys_write(wfd, (char __force_user *)victim, body_len);
83115 sys_close(wfd);
83116 - do_utime(vcollected, mtime);
83117 + do_utime((char __force_user *)vcollected, mtime);
83118 kfree(vcollected);
83119 eat(body_len);
83120 state = SkipIt;
83121 return 0;
83122 } else {
83123 - sys_write(wfd, victim, count);
83124 + sys_write(wfd, (char __force_user *)victim, count);
83125 body_len -= count;
83126 eat(count);
83127 return 1;
83128 @@ -365,9 +365,9 @@ static int __init do_symlink(void)
83129 {
83130 collected[N_ALIGN(name_len) + body_len] = '\0';
83131 clean_path(collected, 0);
83132 - sys_symlink(collected + N_ALIGN(name_len), collected);
83133 - sys_lchown(collected, uid, gid);
83134 - do_utime(collected, mtime);
83135 + sys_symlink((char __force_user *)collected + N_ALIGN(name_len), (char __force_user *)collected);
83136 + sys_lchown((char __force_user *)collected, uid, gid);
83137 + do_utime((char __force_user *)collected, mtime);
83138 state = SkipIt;
83139 next_state = Reset;
83140 return 0;
83141 @@ -583,7 +583,7 @@ static int __init populate_rootfs(void)
83142 {
83143 char *err = unpack_to_rootfs(__initramfs_start, __initramfs_size);
83144 if (err)
83145 - panic(err); /* Failed to decompress INTERNAL initramfs */
83146 + panic("%s", err); /* Failed to decompress INTERNAL initramfs */
83147 if (initrd_start) {
83148 #ifdef CONFIG_BLK_DEV_RAM
83149 int fd;
83150 diff --git a/init/main.c b/init/main.c
83151 index febc511..f0851763 100644
83152 --- a/init/main.c
83153 +++ b/init/main.c
83154 @@ -103,6 +103,8 @@ static inline void mark_rodata_ro(void) { }
83155 extern void tc_init(void);
83156 #endif
83157
83158 +extern void grsecurity_init(void);
83159 +
83160 /*
83161 * Debug helper: via this flag we know that we are in 'early bootup code'
83162 * where only the boot processor is running with IRQ disabled. This means
83163 @@ -164,6 +166,75 @@ static int __init set_reset_devices(char *str)
83164
83165 __setup("reset_devices", set_reset_devices);
83166
83167 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
83168 +kgid_t grsec_proc_gid = KGIDT_INIT(CONFIG_GRKERNSEC_PROC_GID);
83169 +static int __init setup_grsec_proc_gid(char *str)
83170 +{
83171 + grsec_proc_gid = KGIDT_INIT(simple_strtol(str, NULL, 0));
83172 + return 1;
83173 +}
83174 +__setup("grsec_proc_gid=", setup_grsec_proc_gid);
83175 +#endif
83176 +
83177 +#if defined(CONFIG_X86_64) && defined(CONFIG_PAX_MEMORY_UDEREF)
83178 +unsigned long pax_user_shadow_base __read_only;
83179 +EXPORT_SYMBOL(pax_user_shadow_base);
83180 +extern char pax_enter_kernel_user[];
83181 +extern char pax_exit_kernel_user[];
83182 +#endif
83183 +
83184 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_MEMORY_UDEREF)
83185 +static int __init setup_pax_nouderef(char *str)
83186 +{
83187 +#ifdef CONFIG_X86_32
83188 + unsigned int cpu;
83189 + struct desc_struct *gdt;
83190 +
83191 + for (cpu = 0; cpu < nr_cpu_ids; cpu++) {
83192 + gdt = get_cpu_gdt_table(cpu);
83193 + gdt[GDT_ENTRY_KERNEL_DS].type = 3;
83194 + gdt[GDT_ENTRY_KERNEL_DS].limit = 0xf;
83195 + gdt[GDT_ENTRY_DEFAULT_USER_CS].limit = 0xf;
83196 + gdt[GDT_ENTRY_DEFAULT_USER_DS].limit = 0xf;
83197 + }
83198 + loadsegment(ds, __KERNEL_DS);
83199 + loadsegment(es, __KERNEL_DS);
83200 + loadsegment(ss, __KERNEL_DS);
83201 +#else
83202 + memcpy(pax_enter_kernel_user, (unsigned char []){0xc3}, 1);
83203 + memcpy(pax_exit_kernel_user, (unsigned char []){0xc3}, 1);
83204 + clone_pgd_mask = ~(pgdval_t)0UL;
83205 + pax_user_shadow_base = 0UL;
83206 + setup_clear_cpu_cap(X86_FEATURE_PCID);
83207 + setup_clear_cpu_cap(X86_FEATURE_INVPCID);
83208 +#endif
83209 +
83210 + return 0;
83211 +}
83212 +early_param("pax_nouderef", setup_pax_nouderef);
83213 +
83214 +#ifdef CONFIG_X86_64
83215 +static int __init setup_pax_weakuderef(char *str)
83216 +{
83217 + if (clone_pgd_mask != ~(pgdval_t)0UL)
83218 + pax_user_shadow_base = 1UL << TASK_SIZE_MAX_SHIFT;
83219 + return 1;
83220 +}
83221 +__setup("pax_weakuderef", setup_pax_weakuderef);
83222 +#endif
83223 +#endif
83224 +
83225 +#ifdef CONFIG_PAX_SOFTMODE
83226 +int pax_softmode;
83227 +
83228 +static int __init setup_pax_softmode(char *str)
83229 +{
83230 + get_option(&str, &pax_softmode);
83231 + return 1;
83232 +}
83233 +__setup("pax_softmode=", setup_pax_softmode);
83234 +#endif
83235 +
83236 static const char * argv_init[MAX_INIT_ARGS+2] = { "init", NULL, };
83237 const char * envp_init[MAX_INIT_ENVS+2] = { "HOME=/", "TERM=linux", NULL, };
83238 static const char *panic_later, *panic_param;
83239 @@ -691,25 +762,24 @@ int __init_or_module do_one_initcall(initcall_t fn)
83240 {
83241 int count = preempt_count();
83242 int ret;
83243 - char msgbuf[64];
83244 + const char *msg1 = "", *msg2 = "";
83245
83246 if (initcall_debug)
83247 ret = do_one_initcall_debug(fn);
83248 else
83249 ret = fn();
83250
83251 - msgbuf[0] = 0;
83252 -
83253 if (preempt_count() != count) {
83254 - sprintf(msgbuf, "preemption imbalance ");
83255 + msg1 = " preemption imbalance";
83256 preempt_count_set(count);
83257 }
83258 if (irqs_disabled()) {
83259 - strlcat(msgbuf, "disabled interrupts ", sizeof(msgbuf));
83260 + msg2 = " disabled interrupts";
83261 local_irq_enable();
83262 }
83263 - WARN(msgbuf[0], "initcall %pF returned with %s\n", fn, msgbuf);
83264 + WARN(*msg1 || *msg2, "initcall %pF returned with%s%s\n", fn, msg1, msg2);
83265
83266 + add_latent_entropy();
83267 return ret;
83268 }
83269
83270 @@ -816,8 +886,8 @@ static int run_init_process(const char *init_filename)
83271 {
83272 argv_init[0] = init_filename;
83273 return do_execve(init_filename,
83274 - (const char __user *const __user *)argv_init,
83275 - (const char __user *const __user *)envp_init);
83276 + (const char __user *const __force_user *)argv_init,
83277 + (const char __user *const __force_user *)envp_init);
83278 }
83279
83280 static int try_to_run_init_process(const char *init_filename)
83281 @@ -834,6 +904,10 @@ static int try_to_run_init_process(const char *init_filename)
83282 return ret;
83283 }
83284
83285 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
83286 +extern int gr_init_ran;
83287 +#endif
83288 +
83289 static noinline void __init kernel_init_freeable(void);
83290
83291 static int __ref kernel_init(void *unused)
83292 @@ -858,6 +932,11 @@ static int __ref kernel_init(void *unused)
83293 ramdisk_execute_command, ret);
83294 }
83295
83296 +#ifdef CONFIG_GRKERNSEC_CHROOT_INITRD
83297 + /* if no initrd was used, be extra sure we enforce chroot restrictions */
83298 + gr_init_ran = 1;
83299 +#endif
83300 +
83301 /*
83302 * We try each of these until one succeeds.
83303 *
83304 @@ -913,7 +992,7 @@ static noinline void __init kernel_init_freeable(void)
83305 do_basic_setup();
83306
83307 /* Open the /dev/console on the rootfs, this should never fail */
83308 - if (sys_open((const char __user *) "/dev/console", O_RDWR, 0) < 0)
83309 + if (sys_open((const char __force_user *) "/dev/console", O_RDWR, 0) < 0)
83310 pr_err("Warning: unable to open an initial console.\n");
83311
83312 (void) sys_dup(0);
83313 @@ -926,11 +1005,13 @@ static noinline void __init kernel_init_freeable(void)
83314 if (!ramdisk_execute_command)
83315 ramdisk_execute_command = "/init";
83316
83317 - if (sys_access((const char __user *) ramdisk_execute_command, 0) != 0) {
83318 + if (sys_access((const char __force_user *) ramdisk_execute_command, 0) != 0) {
83319 ramdisk_execute_command = NULL;
83320 prepare_namespace();
83321 }
83322
83323 + grsecurity_init();
83324 +
83325 /*
83326 * Ok, we have completed the initial bootup, and
83327 * we're essentially up and running. Get rid of the
83328 diff --git a/ipc/compat.c b/ipc/compat.c
83329 index 892f658..e7c6320 100644
83330 --- a/ipc/compat.c
83331 +++ b/ipc/compat.c
83332 @@ -399,7 +399,7 @@ COMPAT_SYSCALL_DEFINE6(ipc, u32, call, int, first, int, second,
83333 COMPAT_SHMLBA);
83334 if (err < 0)
83335 return err;
83336 - return put_user(raddr, (compat_ulong_t *)compat_ptr(third));
83337 + return put_user(raddr, (compat_ulong_t __user *)compat_ptr(third));
83338 }
83339 case SHMDT:
83340 return sys_shmdt(compat_ptr(ptr));
83341 diff --git a/ipc/ipc_sysctl.c b/ipc/ipc_sysctl.c
83342 index b0e99de..09f385c 100644
83343 --- a/ipc/ipc_sysctl.c
83344 +++ b/ipc/ipc_sysctl.c
83345 @@ -30,7 +30,7 @@ static void *get_ipc(ctl_table *table)
83346 static int proc_ipc_dointvec(ctl_table *table, int write,
83347 void __user *buffer, size_t *lenp, loff_t *ppos)
83348 {
83349 - struct ctl_table ipc_table;
83350 + ctl_table_no_const ipc_table;
83351
83352 memcpy(&ipc_table, table, sizeof(ipc_table));
83353 ipc_table.data = get_ipc(table);
83354 @@ -41,7 +41,7 @@ static int proc_ipc_dointvec(ctl_table *table, int write,
83355 static int proc_ipc_dointvec_minmax(ctl_table *table, int write,
83356 void __user *buffer, size_t *lenp, loff_t *ppos)
83357 {
83358 - struct ctl_table ipc_table;
83359 + ctl_table_no_const ipc_table;
83360
83361 memcpy(&ipc_table, table, sizeof(ipc_table));
83362 ipc_table.data = get_ipc(table);
83363 @@ -65,7 +65,7 @@ static int proc_ipc_dointvec_minmax_orphans(ctl_table *table, int write,
83364 static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
83365 void __user *buffer, size_t *lenp, loff_t *ppos)
83366 {
83367 - struct ctl_table ipc_table;
83368 + ctl_table_no_const ipc_table;
83369 size_t lenp_bef = *lenp;
83370 int rc;
83371
83372 @@ -88,7 +88,7 @@ static int proc_ipc_callback_dointvec_minmax(ctl_table *table, int write,
83373 static int proc_ipc_doulongvec_minmax(ctl_table *table, int write,
83374 void __user *buffer, size_t *lenp, loff_t *ppos)
83375 {
83376 - struct ctl_table ipc_table;
83377 + ctl_table_no_const ipc_table;
83378 memcpy(&ipc_table, table, sizeof(ipc_table));
83379 ipc_table.data = get_ipc(table);
83380
83381 @@ -122,7 +122,7 @@ static void ipc_auto_callback(int val)
83382 static int proc_ipcauto_dointvec_minmax(ctl_table *table, int write,
83383 void __user *buffer, size_t *lenp, loff_t *ppos)
83384 {
83385 - struct ctl_table ipc_table;
83386 + ctl_table_no_const ipc_table;
83387 size_t lenp_bef = *lenp;
83388 int oldval;
83389 int rc;
83390 diff --git a/ipc/mq_sysctl.c b/ipc/mq_sysctl.c
83391 index 383d638..943fdbb 100644
83392 --- a/ipc/mq_sysctl.c
83393 +++ b/ipc/mq_sysctl.c
83394 @@ -25,7 +25,7 @@ static void *get_mq(ctl_table *table)
83395 static int proc_mq_dointvec_minmax(ctl_table *table, int write,
83396 void __user *buffer, size_t *lenp, loff_t *ppos)
83397 {
83398 - struct ctl_table mq_table;
83399 + ctl_table_no_const mq_table;
83400 memcpy(&mq_table, table, sizeof(mq_table));
83401 mq_table.data = get_mq(table);
83402
83403 diff --git a/ipc/mqueue.c b/ipc/mqueue.c
83404 index 95827ce..09e6d38 100644
83405 --- a/ipc/mqueue.c
83406 +++ b/ipc/mqueue.c
83407 @@ -278,6 +278,7 @@ static struct inode *mqueue_get_inode(struct super_block *sb,
83408 mq_bytes = mq_treesize + (info->attr.mq_maxmsg *
83409 info->attr.mq_msgsize);
83410
83411 + gr_learn_resource(current, RLIMIT_MSGQUEUE, u->mq_bytes + mq_bytes, 1);
83412 spin_lock(&mq_lock);
83413 if (u->mq_bytes + mq_bytes < u->mq_bytes ||
83414 u->mq_bytes + mq_bytes > rlimit(RLIMIT_MSGQUEUE)) {
83415 diff --git a/ipc/msg.c b/ipc/msg.c
83416 index 558aa91..359e718 100644
83417 --- a/ipc/msg.c
83418 +++ b/ipc/msg.c
83419 @@ -297,18 +297,19 @@ static inline int msg_security(struct kern_ipc_perm *ipcp, int msgflg)
83420 return security_msg_queue_associate(msq, msgflg);
83421 }
83422
83423 +static struct ipc_ops msg_ops = {
83424 + .getnew = newque,
83425 + .associate = msg_security,
83426 + .more_checks = NULL
83427 +};
83428 +
83429 SYSCALL_DEFINE2(msgget, key_t, key, int, msgflg)
83430 {
83431 struct ipc_namespace *ns;
83432 - struct ipc_ops msg_ops;
83433 struct ipc_params msg_params;
83434
83435 ns = current->nsproxy->ipc_ns;
83436
83437 - msg_ops.getnew = newque;
83438 - msg_ops.associate = msg_security;
83439 - msg_ops.more_checks = NULL;
83440 -
83441 msg_params.key = key;
83442 msg_params.flg = msgflg;
83443
83444 diff --git a/ipc/sem.c b/ipc/sem.c
83445 index db9d241..bc8427c 100644
83446 --- a/ipc/sem.c
83447 +++ b/ipc/sem.c
83448 @@ -562,10 +562,15 @@ static inline int sem_more_checks(struct kern_ipc_perm *ipcp,
83449 return 0;
83450 }
83451
83452 +static struct ipc_ops sem_ops = {
83453 + .getnew = newary,
83454 + .associate = sem_security,
83455 + .more_checks = sem_more_checks
83456 +};
83457 +
83458 SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
83459 {
83460 struct ipc_namespace *ns;
83461 - struct ipc_ops sem_ops;
83462 struct ipc_params sem_params;
83463
83464 ns = current->nsproxy->ipc_ns;
83465 @@ -573,10 +578,6 @@ SYSCALL_DEFINE3(semget, key_t, key, int, nsems, int, semflg)
83466 if (nsems < 0 || nsems > ns->sc_semmsl)
83467 return -EINVAL;
83468
83469 - sem_ops.getnew = newary;
83470 - sem_ops.associate = sem_security;
83471 - sem_ops.more_checks = sem_more_checks;
83472 -
83473 sem_params.key = key;
83474 sem_params.flg = semflg;
83475 sem_params.u.nsems = nsems;
83476 diff --git a/ipc/shm.c b/ipc/shm.c
83477 index 7a51443..3a257d8 100644
83478 --- a/ipc/shm.c
83479 +++ b/ipc/shm.c
83480 @@ -72,6 +72,14 @@ static void shm_destroy (struct ipc_namespace *ns, struct shmid_kernel *shp);
83481 static int sysvipc_shm_proc_show(struct seq_file *s, void *it);
83482 #endif
83483
83484 +#ifdef CONFIG_GRKERNSEC
83485 +extern int gr_handle_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
83486 + const time_t shm_createtime, const kuid_t cuid,
83487 + const int shmid);
83488 +extern int gr_chroot_shmat(const pid_t shm_cprid, const pid_t shm_lapid,
83489 + const time_t shm_createtime);
83490 +#endif
83491 +
83492 void shm_init_ns(struct ipc_namespace *ns)
83493 {
83494 ns->shm_ctlmax = SHMMAX;
83495 @@ -554,6 +562,14 @@ static int newseg(struct ipc_namespace *ns, struct ipc_params *params)
83496 shp->shm_lprid = 0;
83497 shp->shm_atim = shp->shm_dtim = 0;
83498 shp->shm_ctim = get_seconds();
83499 +#ifdef CONFIG_GRKERNSEC
83500 + {
83501 + struct timespec timeval;
83502 + do_posix_clock_monotonic_gettime(&timeval);
83503 +
83504 + shp->shm_createtime = timeval.tv_sec;
83505 + }
83506 +#endif
83507 shp->shm_segsz = size;
83508 shp->shm_nattch = 0;
83509 shp->shm_file = file;
83510 @@ -607,18 +623,19 @@ static inline int shm_more_checks(struct kern_ipc_perm *ipcp,
83511 return 0;
83512 }
83513
83514 +static struct ipc_ops shm_ops = {
83515 + .getnew = newseg,
83516 + .associate = shm_security,
83517 + .more_checks = shm_more_checks
83518 +};
83519 +
83520 SYSCALL_DEFINE3(shmget, key_t, key, size_t, size, int, shmflg)
83521 {
83522 struct ipc_namespace *ns;
83523 - struct ipc_ops shm_ops;
83524 struct ipc_params shm_params;
83525
83526 ns = current->nsproxy->ipc_ns;
83527
83528 - shm_ops.getnew = newseg;
83529 - shm_ops.associate = shm_security;
83530 - shm_ops.more_checks = shm_more_checks;
83531 -
83532 shm_params.key = key;
83533 shm_params.flg = shmflg;
83534 shm_params.u.size = size;
83535 @@ -1089,6 +1106,12 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
83536 f_mode = FMODE_READ | FMODE_WRITE;
83537 }
83538 if (shmflg & SHM_EXEC) {
83539 +
83540 +#ifdef CONFIG_PAX_MPROTECT
83541 + if (current->mm->pax_flags & MF_PAX_MPROTECT)
83542 + goto out;
83543 +#endif
83544 +
83545 prot |= PROT_EXEC;
83546 acc_mode |= S_IXUGO;
83547 }
83548 @@ -1113,6 +1136,15 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
83549 if (err)
83550 goto out_unlock;
83551
83552 +#ifdef CONFIG_GRKERNSEC
83553 + if (!gr_handle_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime,
83554 + shp->shm_perm.cuid, shmid) ||
83555 + !gr_chroot_shmat(shp->shm_cprid, shp->shm_lapid, shp->shm_createtime)) {
83556 + err = -EACCES;
83557 + goto out_unlock;
83558 + }
83559 +#endif
83560 +
83561 ipc_lock_object(&shp->shm_perm);
83562
83563 /* check if shm_destroy() is tearing down shp */
83564 @@ -1125,6 +1157,9 @@ long do_shmat(int shmid, char __user *shmaddr, int shmflg, ulong *raddr,
83565 path = shp->shm_file->f_path;
83566 path_get(&path);
83567 shp->shm_nattch++;
83568 +#ifdef CONFIG_GRKERNSEC
83569 + shp->shm_lapid = current->pid;
83570 +#endif
83571 size = i_size_read(path.dentry->d_inode);
83572 ipc_unlock_object(&shp->shm_perm);
83573 rcu_read_unlock();
83574 diff --git a/ipc/util.c b/ipc/util.c
83575 index 3ae17a4..d67c32f 100644
83576 --- a/ipc/util.c
83577 +++ b/ipc/util.c
83578 @@ -71,6 +71,8 @@ struct ipc_proc_iface {
83579 int (*show)(struct seq_file *, void *);
83580 };
83581
83582 +extern int gr_ipc_permitted(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, int requested_mode, int granted_mode);
83583 +
83584 static void ipc_memory_notifier(struct work_struct *work)
83585 {
83586 ipcns_notify(IPCNS_MEMCHANGED);
83587 @@ -558,6 +560,10 @@ int ipcperms(struct ipc_namespace *ns, struct kern_ipc_perm *ipcp, short flag)
83588 granted_mode >>= 6;
83589 else if (in_group_p(ipcp->cgid) || in_group_p(ipcp->gid))
83590 granted_mode >>= 3;
83591 +
83592 + if (!gr_ipc_permitted(ns, ipcp, requested_mode, granted_mode))
83593 + return -1;
83594 +
83595 /* is there some bit set in requested_mode but not in granted_mode? */
83596 if ((requested_mode & ~granted_mode & 0007) &&
83597 !ns_capable(ns->user_ns, CAP_IPC_OWNER))
83598 diff --git a/kernel/acct.c b/kernel/acct.c
83599 index 8d6e145..33e0b1e 100644
83600 --- a/kernel/acct.c
83601 +++ b/kernel/acct.c
83602 @@ -556,7 +556,7 @@ static void do_acct_process(struct bsd_acct_struct *acct,
83603 */
83604 flim = current->signal->rlim[RLIMIT_FSIZE].rlim_cur;
83605 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = RLIM_INFINITY;
83606 - file->f_op->write(file, (char *)&ac,
83607 + file->f_op->write(file, (char __force_user *)&ac,
83608 sizeof(acct_t), &file->f_pos);
83609 current->signal->rlim[RLIMIT_FSIZE].rlim_cur = flim;
83610 set_fs(fs);
83611 diff --git a/kernel/audit.c b/kernel/audit.c
83612 index 15ec13a..986322e 100644
83613 --- a/kernel/audit.c
83614 +++ b/kernel/audit.c
83615 @@ -118,7 +118,7 @@ u32 audit_sig_sid = 0;
83616 3) suppressed due to audit_rate_limit
83617 4) suppressed due to audit_backlog_limit
83618 */
83619 -static atomic_t audit_lost = ATOMIC_INIT(0);
83620 +static atomic_unchecked_t audit_lost = ATOMIC_INIT(0);
83621
83622 /* The netlink socket. */
83623 static struct sock *audit_sock;
83624 @@ -251,7 +251,7 @@ void audit_log_lost(const char *message)
83625 unsigned long now;
83626 int print;
83627
83628 - atomic_inc(&audit_lost);
83629 + atomic_inc_unchecked(&audit_lost);
83630
83631 print = (audit_failure == AUDIT_FAIL_PANIC || !audit_rate_limit);
83632
83633 @@ -270,7 +270,7 @@ void audit_log_lost(const char *message)
83634 printk(KERN_WARNING
83635 "audit: audit_lost=%d audit_rate_limit=%d "
83636 "audit_backlog_limit=%d\n",
83637 - atomic_read(&audit_lost),
83638 + atomic_read_unchecked(&audit_lost),
83639 audit_rate_limit,
83640 audit_backlog_limit);
83641 audit_panic(message);
83642 @@ -766,7 +766,7 @@ static int audit_receive_msg(struct sk_buff *skb, struct nlmsghdr *nlh)
83643 status_set.pid = audit_pid;
83644 status_set.rate_limit = audit_rate_limit;
83645 status_set.backlog_limit = audit_backlog_limit;
83646 - status_set.lost = atomic_read(&audit_lost);
83647 + status_set.lost = atomic_read_unchecked(&audit_lost);
83648 status_set.backlog = skb_queue_len(&audit_skb_queue);
83649 audit_send_reply(NETLINK_CB(skb).portid, seq, AUDIT_GET, 0, 0,
83650 &status_set, sizeof(status_set));
83651 @@ -1359,7 +1359,7 @@ void audit_log_n_hex(struct audit_buffer *ab, const unsigned char *buf,
83652 int i, avail, new_len;
83653 unsigned char *ptr;
83654 struct sk_buff *skb;
83655 - static const unsigned char *hex = "0123456789ABCDEF";
83656 + static const unsigned char hex[] = "0123456789ABCDEF";
83657
83658 if (!ab)
83659 return;
83660 diff --git a/kernel/auditsc.c b/kernel/auditsc.c
83661 index 90594c9..abbeed7 100644
83662 --- a/kernel/auditsc.c
83663 +++ b/kernel/auditsc.c
83664 @@ -1945,7 +1945,7 @@ int auditsc_get_stamp(struct audit_context *ctx,
83665 }
83666
83667 /* global counter which is incremented every time something logs in */
83668 -static atomic_t session_id = ATOMIC_INIT(0);
83669 +static atomic_unchecked_t session_id = ATOMIC_INIT(0);
83670
83671 static int audit_set_loginuid_perm(kuid_t loginuid)
83672 {
83673 @@ -2008,7 +2008,7 @@ int audit_set_loginuid(kuid_t loginuid)
83674
83675 /* are we setting or clearing? */
83676 if (uid_valid(loginuid))
83677 - sessionid = atomic_inc_return(&session_id);
83678 + sessionid = atomic_inc_return_unchecked(&session_id);
83679
83680 task->sessionid = sessionid;
83681 task->loginuid = loginuid;
83682 diff --git a/kernel/capability.c b/kernel/capability.c
83683 index 4e66bf9..cdccecf 100644
83684 --- a/kernel/capability.c
83685 +++ b/kernel/capability.c
83686 @@ -202,6 +202,9 @@ SYSCALL_DEFINE2(capget, cap_user_header_t, header, cap_user_data_t, dataptr)
83687 * before modification is attempted and the application
83688 * fails.
83689 */
83690 + if (tocopy > ARRAY_SIZE(kdata))
83691 + return -EFAULT;
83692 +
83693 if (copy_to_user(dataptr, kdata, tocopy
83694 * sizeof(struct __user_cap_data_struct))) {
83695 return -EFAULT;
83696 @@ -303,10 +306,11 @@ bool has_ns_capability(struct task_struct *t,
83697 int ret;
83698
83699 rcu_read_lock();
83700 - ret = security_capable(__task_cred(t), ns, cap);
83701 + ret = security_capable(__task_cred(t), ns, cap) == 0 &&
83702 + gr_task_is_capable(t, __task_cred(t), cap);
83703 rcu_read_unlock();
83704
83705 - return (ret == 0);
83706 + return ret;
83707 }
83708
83709 /**
83710 @@ -343,10 +347,10 @@ bool has_ns_capability_noaudit(struct task_struct *t,
83711 int ret;
83712
83713 rcu_read_lock();
83714 - ret = security_capable_noaudit(__task_cred(t), ns, cap);
83715 + ret = security_capable_noaudit(__task_cred(t), ns, cap) == 0 && gr_task_is_capable_nolog(t, cap);
83716 rcu_read_unlock();
83717
83718 - return (ret == 0);
83719 + return ret;
83720 }
83721
83722 /**
83723 @@ -384,7 +388,7 @@ bool ns_capable(struct user_namespace *ns, int cap)
83724 BUG();
83725 }
83726
83727 - if (security_capable(current_cred(), ns, cap) == 0) {
83728 + if (security_capable(current_cred(), ns, cap) == 0 && gr_is_capable(cap)) {
83729 current->flags |= PF_SUPERPRIV;
83730 return true;
83731 }
83732 @@ -392,6 +396,21 @@ bool ns_capable(struct user_namespace *ns, int cap)
83733 }
83734 EXPORT_SYMBOL(ns_capable);
83735
83736 +bool ns_capable_nolog(struct user_namespace *ns, int cap)
83737 +{
83738 + if (unlikely(!cap_valid(cap))) {
83739 + printk(KERN_CRIT "capable_nolog() called with invalid cap=%u\n", cap);
83740 + BUG();
83741 + }
83742 +
83743 + if (security_capable_noaudit(current_cred(), ns, cap) == 0 && gr_is_capable_nolog(cap)) {
83744 + current->flags |= PF_SUPERPRIV;
83745 + return true;
83746 + }
83747 + return false;
83748 +}
83749 +EXPORT_SYMBOL(ns_capable_nolog);
83750 +
83751 /**
83752 * file_ns_capable - Determine if the file's opener had a capability in effect
83753 * @file: The file we want to check
83754 @@ -432,6 +451,12 @@ bool capable(int cap)
83755 }
83756 EXPORT_SYMBOL(capable);
83757
83758 +bool capable_nolog(int cap)
83759 +{
83760 + return ns_capable_nolog(&init_user_ns, cap);
83761 +}
83762 +EXPORT_SYMBOL(capable_nolog);
83763 +
83764 /**
83765 * inode_capable - Check superior capability over inode
83766 * @inode: The inode in question
83767 @@ -453,3 +478,11 @@ bool inode_capable(const struct inode *inode, int cap)
83768 return ns_capable(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
83769 }
83770 EXPORT_SYMBOL(inode_capable);
83771 +
83772 +bool inode_capable_nolog(const struct inode *inode, int cap)
83773 +{
83774 + struct user_namespace *ns = current_user_ns();
83775 +
83776 + return ns_capable_nolog(ns, cap) && kuid_has_mapping(ns, inode->i_uid);
83777 +}
83778 +EXPORT_SYMBOL(inode_capable_nolog);
83779 diff --git a/kernel/cgroup.c b/kernel/cgroup.c
83780 index bc1dcab..f3a6b42 100644
83781 --- a/kernel/cgroup.c
83782 +++ b/kernel/cgroup.c
83783 @@ -5607,7 +5607,7 @@ static int cgroup_css_links_read(struct cgroup_subsys_state *css,
83784 struct css_set *cset = link->cset;
83785 struct task_struct *task;
83786 int count = 0;
83787 - seq_printf(seq, "css_set %p\n", cset);
83788 + seq_printf(seq, "css_set %pK\n", cset);
83789 list_for_each_entry(task, &cset->tasks, cg_list) {
83790 if (count++ > MAX_TASKS_SHOWN_PER_CSS) {
83791 seq_puts(seq, " ...\n");
83792 diff --git a/kernel/compat.c b/kernel/compat.c
83793 index 0a09e48..b46b3d78 100644
83794 --- a/kernel/compat.c
83795 +++ b/kernel/compat.c
83796 @@ -13,6 +13,7 @@
83797
83798 #include <linux/linkage.h>
83799 #include <linux/compat.h>
83800 +#include <linux/module.h>
83801 #include <linux/errno.h>
83802 #include <linux/time.h>
83803 #include <linux/signal.h>
83804 @@ -220,7 +221,7 @@ static long compat_nanosleep_restart(struct restart_block *restart)
83805 mm_segment_t oldfs;
83806 long ret;
83807
83808 - restart->nanosleep.rmtp = (struct timespec __user *) &rmt;
83809 + restart->nanosleep.rmtp = (struct timespec __force_user *) &rmt;
83810 oldfs = get_fs();
83811 set_fs(KERNEL_DS);
83812 ret = hrtimer_nanosleep_restart(restart);
83813 @@ -252,7 +253,7 @@ asmlinkage long compat_sys_nanosleep(struct compat_timespec __user *rqtp,
83814 oldfs = get_fs();
83815 set_fs(KERNEL_DS);
83816 ret = hrtimer_nanosleep(&tu,
83817 - rmtp ? (struct timespec __user *)&rmt : NULL,
83818 + rmtp ? (struct timespec __force_user *)&rmt : NULL,
83819 HRTIMER_MODE_REL, CLOCK_MONOTONIC);
83820 set_fs(oldfs);
83821
83822 @@ -361,7 +362,7 @@ asmlinkage long compat_sys_sigpending(compat_old_sigset_t __user *set)
83823 mm_segment_t old_fs = get_fs();
83824
83825 set_fs(KERNEL_DS);
83826 - ret = sys_sigpending((old_sigset_t __user *) &s);
83827 + ret = sys_sigpending((old_sigset_t __force_user *) &s);
83828 set_fs(old_fs);
83829 if (ret == 0)
83830 ret = put_user(s, set);
83831 @@ -451,7 +452,7 @@ asmlinkage long compat_sys_old_getrlimit(unsigned int resource,
83832 mm_segment_t old_fs = get_fs();
83833
83834 set_fs(KERNEL_DS);
83835 - ret = sys_old_getrlimit(resource, &r);
83836 + ret = sys_old_getrlimit(resource, (struct rlimit __force_user *)&r);
83837 set_fs(old_fs);
83838
83839 if (!ret) {
83840 @@ -533,8 +534,8 @@ COMPAT_SYSCALL_DEFINE4(wait4,
83841 set_fs (KERNEL_DS);
83842 ret = sys_wait4(pid,
83843 (stat_addr ?
83844 - (unsigned int __user *) &status : NULL),
83845 - options, (struct rusage __user *) &r);
83846 + (unsigned int __force_user *) &status : NULL),
83847 + options, (struct rusage __force_user *) &r);
83848 set_fs (old_fs);
83849
83850 if (ret > 0) {
83851 @@ -560,8 +561,8 @@ COMPAT_SYSCALL_DEFINE5(waitid,
83852 memset(&info, 0, sizeof(info));
83853
83854 set_fs(KERNEL_DS);
83855 - ret = sys_waitid(which, pid, (siginfo_t __user *)&info, options,
83856 - uru ? (struct rusage __user *)&ru : NULL);
83857 + ret = sys_waitid(which, pid, (siginfo_t __force_user *)&info, options,
83858 + uru ? (struct rusage __force_user *)&ru : NULL);
83859 set_fs(old_fs);
83860
83861 if ((ret < 0) || (info.si_signo == 0))
83862 @@ -695,8 +696,8 @@ long compat_sys_timer_settime(timer_t timer_id, int flags,
83863 oldfs = get_fs();
83864 set_fs(KERNEL_DS);
83865 err = sys_timer_settime(timer_id, flags,
83866 - (struct itimerspec __user *) &newts,
83867 - (struct itimerspec __user *) &oldts);
83868 + (struct itimerspec __force_user *) &newts,
83869 + (struct itimerspec __force_user *) &oldts);
83870 set_fs(oldfs);
83871 if (!err && old && put_compat_itimerspec(old, &oldts))
83872 return -EFAULT;
83873 @@ -713,7 +714,7 @@ long compat_sys_timer_gettime(timer_t timer_id,
83874 oldfs = get_fs();
83875 set_fs(KERNEL_DS);
83876 err = sys_timer_gettime(timer_id,
83877 - (struct itimerspec __user *) &ts);
83878 + (struct itimerspec __force_user *) &ts);
83879 set_fs(oldfs);
83880 if (!err && put_compat_itimerspec(setting, &ts))
83881 return -EFAULT;
83882 @@ -732,7 +733,7 @@ long compat_sys_clock_settime(clockid_t which_clock,
83883 oldfs = get_fs();
83884 set_fs(KERNEL_DS);
83885 err = sys_clock_settime(which_clock,
83886 - (struct timespec __user *) &ts);
83887 + (struct timespec __force_user *) &ts);
83888 set_fs(oldfs);
83889 return err;
83890 }
83891 @@ -747,7 +748,7 @@ long compat_sys_clock_gettime(clockid_t which_clock,
83892 oldfs = get_fs();
83893 set_fs(KERNEL_DS);
83894 err = sys_clock_gettime(which_clock,
83895 - (struct timespec __user *) &ts);
83896 + (struct timespec __force_user *) &ts);
83897 set_fs(oldfs);
83898 if (!err && put_compat_timespec(&ts, tp))
83899 return -EFAULT;
83900 @@ -767,7 +768,7 @@ long compat_sys_clock_adjtime(clockid_t which_clock,
83901
83902 oldfs = get_fs();
83903 set_fs(KERNEL_DS);
83904 - ret = sys_clock_adjtime(which_clock, (struct timex __user *) &txc);
83905 + ret = sys_clock_adjtime(which_clock, (struct timex __force_user *) &txc);
83906 set_fs(oldfs);
83907
83908 err = compat_put_timex(utp, &txc);
83909 @@ -787,7 +788,7 @@ long compat_sys_clock_getres(clockid_t which_clock,
83910 oldfs = get_fs();
83911 set_fs(KERNEL_DS);
83912 err = sys_clock_getres(which_clock,
83913 - (struct timespec __user *) &ts);
83914 + (struct timespec __force_user *) &ts);
83915 set_fs(oldfs);
83916 if (!err && tp && put_compat_timespec(&ts, tp))
83917 return -EFAULT;
83918 @@ -799,9 +800,9 @@ static long compat_clock_nanosleep_restart(struct restart_block *restart)
83919 long err;
83920 mm_segment_t oldfs;
83921 struct timespec tu;
83922 - struct compat_timespec *rmtp = restart->nanosleep.compat_rmtp;
83923 + struct compat_timespec __user *rmtp = restart->nanosleep.compat_rmtp;
83924
83925 - restart->nanosleep.rmtp = (struct timespec __user *) &tu;
83926 + restart->nanosleep.rmtp = (struct timespec __force_user *) &tu;
83927 oldfs = get_fs();
83928 set_fs(KERNEL_DS);
83929 err = clock_nanosleep_restart(restart);
83930 @@ -833,8 +834,8 @@ long compat_sys_clock_nanosleep(clockid_t which_clock, int flags,
83931 oldfs = get_fs();
83932 set_fs(KERNEL_DS);
83933 err = sys_clock_nanosleep(which_clock, flags,
83934 - (struct timespec __user *) &in,
83935 - (struct timespec __user *) &out);
83936 + (struct timespec __force_user *) &in,
83937 + (struct timespec __force_user *) &out);
83938 set_fs(oldfs);
83939
83940 if ((err == -ERESTART_RESTARTBLOCK) && rmtp &&
83941 @@ -1128,7 +1129,7 @@ COMPAT_SYSCALL_DEFINE2(sched_rr_get_interval,
83942 mm_segment_t old_fs = get_fs();
83943
83944 set_fs(KERNEL_DS);
83945 - ret = sys_sched_rr_get_interval(pid, (struct timespec __user *)&t);
83946 + ret = sys_sched_rr_get_interval(pid, (struct timespec __force_user *)&t);
83947 set_fs(old_fs);
83948 if (put_compat_timespec(&t, interval))
83949 return -EFAULT;
83950 diff --git a/kernel/configs.c b/kernel/configs.c
83951 index c18b1f1..b9a0132 100644
83952 --- a/kernel/configs.c
83953 +++ b/kernel/configs.c
83954 @@ -74,8 +74,19 @@ static int __init ikconfig_init(void)
83955 struct proc_dir_entry *entry;
83956
83957 /* create the current config file */
83958 +#if defined(CONFIG_GRKERNSEC_PROC_ADD) || defined(CONFIG_GRKERNSEC_HIDESYM)
83959 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_HIDESYM)
83960 + entry = proc_create("config.gz", S_IFREG | S_IRUSR, NULL,
83961 + &ikconfig_file_ops);
83962 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
83963 + entry = proc_create("config.gz", S_IFREG | S_IRUSR | S_IRGRP, NULL,
83964 + &ikconfig_file_ops);
83965 +#endif
83966 +#else
83967 entry = proc_create("config.gz", S_IFREG | S_IRUGO, NULL,
83968 &ikconfig_file_ops);
83969 +#endif
83970 +
83971 if (!entry)
83972 return -ENOMEM;
83973
83974 diff --git a/kernel/cred.c b/kernel/cred.c
83975 index e0573a4..3874e41 100644
83976 --- a/kernel/cred.c
83977 +++ b/kernel/cred.c
83978 @@ -164,6 +164,16 @@ void exit_creds(struct task_struct *tsk)
83979 validate_creds(cred);
83980 alter_cred_subscribers(cred, -1);
83981 put_cred(cred);
83982 +
83983 +#ifdef CONFIG_GRKERNSEC_SETXID
83984 + cred = (struct cred *) tsk->delayed_cred;
83985 + if (cred != NULL) {
83986 + tsk->delayed_cred = NULL;
83987 + validate_creds(cred);
83988 + alter_cred_subscribers(cred, -1);
83989 + put_cred(cred);
83990 + }
83991 +#endif
83992 }
83993
83994 /**
83995 @@ -411,7 +421,7 @@ static bool cred_cap_issubset(const struct cred *set, const struct cred *subset)
83996 * Always returns 0 thus allowing this function to be tail-called at the end
83997 * of, say, sys_setgid().
83998 */
83999 -int commit_creds(struct cred *new)
84000 +static int __commit_creds(struct cred *new)
84001 {
84002 struct task_struct *task = current;
84003 const struct cred *old = task->real_cred;
84004 @@ -430,6 +440,8 @@ int commit_creds(struct cred *new)
84005
84006 get_cred(new); /* we will require a ref for the subj creds too */
84007
84008 + gr_set_role_label(task, new->uid, new->gid);
84009 +
84010 /* dumpability changes */
84011 if (!uid_eq(old->euid, new->euid) ||
84012 !gid_eq(old->egid, new->egid) ||
84013 @@ -479,6 +491,102 @@ int commit_creds(struct cred *new)
84014 put_cred(old);
84015 return 0;
84016 }
84017 +#ifdef CONFIG_GRKERNSEC_SETXID
84018 +extern int set_user(struct cred *new);
84019 +
84020 +void gr_delayed_cred_worker(void)
84021 +{
84022 + const struct cred *new = current->delayed_cred;
84023 + struct cred *ncred;
84024 +
84025 + current->delayed_cred = NULL;
84026 +
84027 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID) && new != NULL) {
84028 + // from doing get_cred on it when queueing this
84029 + put_cred(new);
84030 + return;
84031 + } else if (new == NULL)
84032 + return;
84033 +
84034 + ncred = prepare_creds();
84035 + if (!ncred)
84036 + goto die;
84037 + // uids
84038 + ncred->uid = new->uid;
84039 + ncred->euid = new->euid;
84040 + ncred->suid = new->suid;
84041 + ncred->fsuid = new->fsuid;
84042 + // gids
84043 + ncred->gid = new->gid;
84044 + ncred->egid = new->egid;
84045 + ncred->sgid = new->sgid;
84046 + ncred->fsgid = new->fsgid;
84047 + // groups
84048 + if (set_groups(ncred, new->group_info) < 0) {
84049 + abort_creds(ncred);
84050 + goto die;
84051 + }
84052 + // caps
84053 + ncred->securebits = new->securebits;
84054 + ncred->cap_inheritable = new->cap_inheritable;
84055 + ncred->cap_permitted = new->cap_permitted;
84056 + ncred->cap_effective = new->cap_effective;
84057 + ncred->cap_bset = new->cap_bset;
84058 +
84059 + if (set_user(ncred)) {
84060 + abort_creds(ncred);
84061 + goto die;
84062 + }
84063 +
84064 + // from doing get_cred on it when queueing this
84065 + put_cred(new);
84066 +
84067 + __commit_creds(ncred);
84068 + return;
84069 +die:
84070 + // from doing get_cred on it when queueing this
84071 + put_cred(new);
84072 + do_group_exit(SIGKILL);
84073 +}
84074 +#endif
84075 +
84076 +int commit_creds(struct cred *new)
84077 +{
84078 +#ifdef CONFIG_GRKERNSEC_SETXID
84079 + int ret;
84080 + int schedule_it = 0;
84081 + struct task_struct *t;
84082 +
84083 + /* we won't get called with tasklist_lock held for writing
84084 + and interrupts disabled as the cred struct in that case is
84085 + init_cred
84086 + */
84087 + if (grsec_enable_setxid && !current_is_single_threaded() &&
84088 + uid_eq(current_uid(), GLOBAL_ROOT_UID) &&
84089 + !uid_eq(new->uid, GLOBAL_ROOT_UID)) {
84090 + schedule_it = 1;
84091 + }
84092 + ret = __commit_creds(new);
84093 + if (schedule_it) {
84094 + rcu_read_lock();
84095 + read_lock(&tasklist_lock);
84096 + for (t = next_thread(current); t != current;
84097 + t = next_thread(t)) {
84098 + if (t->delayed_cred == NULL) {
84099 + t->delayed_cred = get_cred(new);
84100 + set_tsk_thread_flag(t, TIF_GRSEC_SETXID);
84101 + set_tsk_need_resched(t);
84102 + }
84103 + }
84104 + read_unlock(&tasklist_lock);
84105 + rcu_read_unlock();
84106 + }
84107 + return ret;
84108 +#else
84109 + return __commit_creds(new);
84110 +#endif
84111 +}
84112 +
84113 EXPORT_SYMBOL(commit_creds);
84114
84115 /**
84116 diff --git a/kernel/debug/debug_core.c b/kernel/debug/debug_core.c
84117 index 7d2f35e..1bafcd0 100644
84118 --- a/kernel/debug/debug_core.c
84119 +++ b/kernel/debug/debug_core.c
84120 @@ -123,7 +123,7 @@ static DEFINE_RAW_SPINLOCK(dbg_slave_lock);
84121 */
84122 static atomic_t masters_in_kgdb;
84123 static atomic_t slaves_in_kgdb;
84124 -static atomic_t kgdb_break_tasklet_var;
84125 +static atomic_unchecked_t kgdb_break_tasklet_var;
84126 atomic_t kgdb_setting_breakpoint;
84127
84128 struct task_struct *kgdb_usethread;
84129 @@ -133,7 +133,7 @@ int kgdb_single_step;
84130 static pid_t kgdb_sstep_pid;
84131
84132 /* to keep track of the CPU which is doing the single stepping*/
84133 -atomic_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
84134 +atomic_unchecked_t kgdb_cpu_doing_single_step = ATOMIC_INIT(-1);
84135
84136 /*
84137 * If you are debugging a problem where roundup (the collection of
84138 @@ -541,7 +541,7 @@ return_normal:
84139 * kernel will only try for the value of sstep_tries before
84140 * giving up and continuing on.
84141 */
84142 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1 &&
84143 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1 &&
84144 (kgdb_info[cpu].task &&
84145 kgdb_info[cpu].task->pid != kgdb_sstep_pid) && --sstep_tries) {
84146 atomic_set(&kgdb_active, -1);
84147 @@ -639,8 +639,8 @@ cpu_master_loop:
84148 }
84149
84150 kgdb_restore:
84151 - if (atomic_read(&kgdb_cpu_doing_single_step) != -1) {
84152 - int sstep_cpu = atomic_read(&kgdb_cpu_doing_single_step);
84153 + if (atomic_read_unchecked(&kgdb_cpu_doing_single_step) != -1) {
84154 + int sstep_cpu = atomic_read_unchecked(&kgdb_cpu_doing_single_step);
84155 if (kgdb_info[sstep_cpu].task)
84156 kgdb_sstep_pid = kgdb_info[sstep_cpu].task->pid;
84157 else
84158 @@ -916,18 +916,18 @@ static void kgdb_unregister_callbacks(void)
84159 static void kgdb_tasklet_bpt(unsigned long ing)
84160 {
84161 kgdb_breakpoint();
84162 - atomic_set(&kgdb_break_tasklet_var, 0);
84163 + atomic_set_unchecked(&kgdb_break_tasklet_var, 0);
84164 }
84165
84166 static DECLARE_TASKLET(kgdb_tasklet_breakpoint, kgdb_tasklet_bpt, 0);
84167
84168 void kgdb_schedule_breakpoint(void)
84169 {
84170 - if (atomic_read(&kgdb_break_tasklet_var) ||
84171 + if (atomic_read_unchecked(&kgdb_break_tasklet_var) ||
84172 atomic_read(&kgdb_active) != -1 ||
84173 atomic_read(&kgdb_setting_breakpoint))
84174 return;
84175 - atomic_inc(&kgdb_break_tasklet_var);
84176 + atomic_inc_unchecked(&kgdb_break_tasklet_var);
84177 tasklet_schedule(&kgdb_tasklet_breakpoint);
84178 }
84179 EXPORT_SYMBOL_GPL(kgdb_schedule_breakpoint);
84180 diff --git a/kernel/debug/kdb/kdb_main.c b/kernel/debug/kdb/kdb_main.c
84181 index 0b097c8..11dd5c5 100644
84182 --- a/kernel/debug/kdb/kdb_main.c
84183 +++ b/kernel/debug/kdb/kdb_main.c
84184 @@ -1977,7 +1977,7 @@ static int kdb_lsmod(int argc, const char **argv)
84185 continue;
84186
84187 kdb_printf("%-20s%8u 0x%p ", mod->name,
84188 - mod->core_size, (void *)mod);
84189 + mod->core_size_rx + mod->core_size_rw, (void *)mod);
84190 #ifdef CONFIG_MODULE_UNLOAD
84191 kdb_printf("%4ld ", module_refcount(mod));
84192 #endif
84193 @@ -1987,7 +1987,7 @@ static int kdb_lsmod(int argc, const char **argv)
84194 kdb_printf(" (Loading)");
84195 else
84196 kdb_printf(" (Live)");
84197 - kdb_printf(" 0x%p", mod->module_core);
84198 + kdb_printf(" 0x%p 0x%p", mod->module_core_rx, mod->module_core_rw);
84199
84200 #ifdef CONFIG_MODULE_UNLOAD
84201 {
84202 diff --git a/kernel/events/core.c b/kernel/events/core.c
84203 index f574401..11b21f0 100644
84204 --- a/kernel/events/core.c
84205 +++ b/kernel/events/core.c
84206 @@ -157,8 +157,15 @@ static struct srcu_struct pmus_srcu;
84207 * 0 - disallow raw tracepoint access for unpriv
84208 * 1 - disallow cpu events for unpriv
84209 * 2 - disallow kernel profiling for unpriv
84210 + * 3 - disallow all unpriv perf event use
84211 */
84212 -int sysctl_perf_event_paranoid __read_mostly = 1;
84213 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
84214 +int sysctl_perf_event_legitimately_concerned __read_mostly = 3;
84215 +#elif defined(CONFIG_GRKERNSEC_HIDESYM)
84216 +int sysctl_perf_event_legitimately_concerned __read_mostly = 2;
84217 +#else
84218 +int sysctl_perf_event_legitimately_concerned __read_mostly = 1;
84219 +#endif
84220
84221 /* Minimum for 512 kiB + 1 user control page */
84222 int sysctl_perf_event_mlock __read_mostly = 512 + (PAGE_SIZE / 1024); /* 'free' kiB per user */
84223 @@ -184,7 +191,7 @@ void update_perf_cpu_limits(void)
84224
84225 tmp *= sysctl_perf_cpu_time_max_percent;
84226 do_div(tmp, 100);
84227 - ACCESS_ONCE(perf_sample_allowed_ns) = tmp;
84228 + ACCESS_ONCE_RW(perf_sample_allowed_ns) = tmp;
84229 }
84230
84231 static int perf_rotate_context(struct perf_cpu_context *cpuctx);
84232 @@ -271,7 +278,7 @@ void perf_sample_event_took(u64 sample_len_ns)
84233 update_perf_cpu_limits();
84234 }
84235
84236 -static atomic64_t perf_event_id;
84237 +static atomic64_unchecked_t perf_event_id;
84238
84239 static void cpu_ctx_sched_out(struct perf_cpu_context *cpuctx,
84240 enum event_type_t event_type);
84241 @@ -2985,7 +2992,7 @@ static void __perf_event_read(void *info)
84242
84243 static inline u64 perf_event_count(struct perf_event *event)
84244 {
84245 - return local64_read(&event->count) + atomic64_read(&event->child_count);
84246 + return local64_read(&event->count) + atomic64_read_unchecked(&event->child_count);
84247 }
84248
84249 static u64 perf_event_read(struct perf_event *event)
84250 @@ -3353,9 +3360,9 @@ u64 perf_event_read_value(struct perf_event *event, u64 *enabled, u64 *running)
84251 mutex_lock(&event->child_mutex);
84252 total += perf_event_read(event);
84253 *enabled += event->total_time_enabled +
84254 - atomic64_read(&event->child_total_time_enabled);
84255 + atomic64_read_unchecked(&event->child_total_time_enabled);
84256 *running += event->total_time_running +
84257 - atomic64_read(&event->child_total_time_running);
84258 + atomic64_read_unchecked(&event->child_total_time_running);
84259
84260 list_for_each_entry(child, &event->child_list, child_list) {
84261 total += perf_event_read(child);
84262 @@ -3770,10 +3777,10 @@ void perf_event_update_userpage(struct perf_event *event)
84263 userpg->offset -= local64_read(&event->hw.prev_count);
84264
84265 userpg->time_enabled = enabled +
84266 - atomic64_read(&event->child_total_time_enabled);
84267 + atomic64_read_unchecked(&event->child_total_time_enabled);
84268
84269 userpg->time_running = running +
84270 - atomic64_read(&event->child_total_time_running);
84271 + atomic64_read_unchecked(&event->child_total_time_running);
84272
84273 arch_perf_update_userpage(userpg, now);
84274
84275 @@ -4324,7 +4331,7 @@ perf_output_sample_ustack(struct perf_output_handle *handle, u64 dump_size,
84276
84277 /* Data. */
84278 sp = perf_user_stack_pointer(regs);
84279 - rem = __output_copy_user(handle, (void *) sp, dump_size);
84280 + rem = __output_copy_user(handle, (void __user *) sp, dump_size);
84281 dyn_size = dump_size - rem;
84282
84283 perf_output_skip(handle, rem);
84284 @@ -4415,11 +4422,11 @@ static void perf_output_read_one(struct perf_output_handle *handle,
84285 values[n++] = perf_event_count(event);
84286 if (read_format & PERF_FORMAT_TOTAL_TIME_ENABLED) {
84287 values[n++] = enabled +
84288 - atomic64_read(&event->child_total_time_enabled);
84289 + atomic64_read_unchecked(&event->child_total_time_enabled);
84290 }
84291 if (read_format & PERF_FORMAT_TOTAL_TIME_RUNNING) {
84292 values[n++] = running +
84293 - atomic64_read(&event->child_total_time_running);
84294 + atomic64_read_unchecked(&event->child_total_time_running);
84295 }
84296 if (read_format & PERF_FORMAT_ID)
84297 values[n++] = primary_event_id(event);
84298 @@ -6686,7 +6693,7 @@ perf_event_alloc(struct perf_event_attr *attr, int cpu,
84299 event->parent = parent_event;
84300
84301 event->ns = get_pid_ns(task_active_pid_ns(current));
84302 - event->id = atomic64_inc_return(&perf_event_id);
84303 + event->id = atomic64_inc_return_unchecked(&perf_event_id);
84304
84305 event->state = PERF_EVENT_STATE_INACTIVE;
84306
84307 @@ -6985,6 +6992,11 @@ SYSCALL_DEFINE5(perf_event_open,
84308 if (flags & ~PERF_FLAG_ALL)
84309 return -EINVAL;
84310
84311 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
84312 + if (perf_paranoid_any() && !capable(CAP_SYS_ADMIN))
84313 + return -EACCES;
84314 +#endif
84315 +
84316 err = perf_copy_attr(attr_uptr, &attr);
84317 if (err)
84318 return err;
84319 @@ -7316,10 +7328,10 @@ static void sync_child_event(struct perf_event *child_event,
84320 /*
84321 * Add back the child's count to the parent's count:
84322 */
84323 - atomic64_add(child_val, &parent_event->child_count);
84324 - atomic64_add(child_event->total_time_enabled,
84325 + atomic64_add_unchecked(child_val, &parent_event->child_count);
84326 + atomic64_add_unchecked(child_event->total_time_enabled,
84327 &parent_event->child_total_time_enabled);
84328 - atomic64_add(child_event->total_time_running,
84329 + atomic64_add_unchecked(child_event->total_time_running,
84330 &parent_event->child_total_time_running);
84331
84332 /*
84333 diff --git a/kernel/events/internal.h b/kernel/events/internal.h
84334 index 569b2187..19940d9 100644
84335 --- a/kernel/events/internal.h
84336 +++ b/kernel/events/internal.h
84337 @@ -81,10 +81,10 @@ static inline unsigned long perf_data_size(struct ring_buffer *rb)
84338 return rb->nr_pages << (PAGE_SHIFT + page_order(rb));
84339 }
84340
84341 -#define DEFINE_OUTPUT_COPY(func_name, memcpy_func) \
84342 +#define DEFINE_OUTPUT_COPY(func_name, memcpy_func, user) \
84343 static inline unsigned long \
84344 func_name(struct perf_output_handle *handle, \
84345 - const void *buf, unsigned long len) \
84346 + const void user *buf, unsigned long len) \
84347 { \
84348 unsigned long size, written; \
84349 \
84350 @@ -117,7 +117,7 @@ memcpy_common(void *dst, const void *src, unsigned long n)
84351 return 0;
84352 }
84353
84354 -DEFINE_OUTPUT_COPY(__output_copy, memcpy_common)
84355 +DEFINE_OUTPUT_COPY(__output_copy, memcpy_common, )
84356
84357 static inline unsigned long
84358 memcpy_skip(void *dst, const void *src, unsigned long n)
84359 @@ -125,7 +125,7 @@ memcpy_skip(void *dst, const void *src, unsigned long n)
84360 return 0;
84361 }
84362
84363 -DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip)
84364 +DEFINE_OUTPUT_COPY(__output_skip, memcpy_skip, )
84365
84366 #ifndef arch_perf_out_copy_user
84367 #define arch_perf_out_copy_user arch_perf_out_copy_user
84368 @@ -143,7 +143,7 @@ arch_perf_out_copy_user(void *dst, const void *src, unsigned long n)
84369 }
84370 #endif
84371
84372 -DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user)
84373 +DEFINE_OUTPUT_COPY(__output_copy_user, arch_perf_out_copy_user, __user)
84374
84375 /* Callchain handling */
84376 extern struct perf_callchain_entry *
84377 diff --git a/kernel/events/uprobes.c b/kernel/events/uprobes.c
84378 index 24b7d6c..40cf797 100644
84379 --- a/kernel/events/uprobes.c
84380 +++ b/kernel/events/uprobes.c
84381 @@ -1640,7 +1640,7 @@ static int is_trap_at_addr(struct mm_struct *mm, unsigned long vaddr)
84382 {
84383 struct page *page;
84384 uprobe_opcode_t opcode;
84385 - int result;
84386 + long result;
84387
84388 pagefault_disable();
84389 result = __copy_from_user_inatomic(&opcode, (void __user*)vaddr,
84390 diff --git a/kernel/exit.c b/kernel/exit.c
84391 index a949819..a5f127d 100644
84392 --- a/kernel/exit.c
84393 +++ b/kernel/exit.c
84394 @@ -172,6 +172,10 @@ void release_task(struct task_struct * p)
84395 struct task_struct *leader;
84396 int zap_leader;
84397 repeat:
84398 +#ifdef CONFIG_NET
84399 + gr_del_task_from_ip_table(p);
84400 +#endif
84401 +
84402 /* don't need to get the RCU readlock here - the process is dead and
84403 * can't be modifying its own credentials. But shut RCU-lockdep up */
84404 rcu_read_lock();
84405 @@ -329,7 +333,7 @@ int allow_signal(int sig)
84406 * know it'll be handled, so that they don't get converted to
84407 * SIGKILL or just silently dropped.
84408 */
84409 - current->sighand->action[(sig)-1].sa.sa_handler = (void __user *)2;
84410 + current->sighand->action[(sig)-1].sa.sa_handler = (__force void __user *)2;
84411 recalc_sigpending();
84412 spin_unlock_irq(&current->sighand->siglock);
84413 return 0;
84414 @@ -698,6 +702,8 @@ void do_exit(long code)
84415 struct task_struct *tsk = current;
84416 int group_dead;
84417
84418 + set_fs(USER_DS);
84419 +
84420 profile_task_exit(tsk);
84421
84422 WARN_ON(blk_needs_flush_plug(tsk));
84423 @@ -714,7 +720,6 @@ void do_exit(long code)
84424 * mm_release()->clear_child_tid() from writing to a user-controlled
84425 * kernel address.
84426 */
84427 - set_fs(USER_DS);
84428
84429 ptrace_event(PTRACE_EVENT_EXIT, code);
84430
84431 @@ -773,6 +778,9 @@ void do_exit(long code)
84432 tsk->exit_code = code;
84433 taskstats_exit(tsk, group_dead);
84434
84435 + gr_acl_handle_psacct(tsk, code);
84436 + gr_acl_handle_exit();
84437 +
84438 exit_mm(tsk);
84439
84440 if (group_dead)
84441 @@ -894,7 +902,7 @@ SYSCALL_DEFINE1(exit, int, error_code)
84442 * Take down every thread in the group. This is called by fatal signals
84443 * as well as by sys_exit_group (below).
84444 */
84445 -void
84446 +__noreturn void
84447 do_group_exit(int exit_code)
84448 {
84449 struct signal_struct *sig = current->signal;
84450 diff --git a/kernel/fork.c b/kernel/fork.c
84451 index dfa736c..d170f9b 100644
84452 --- a/kernel/fork.c
84453 +++ b/kernel/fork.c
84454 @@ -319,7 +319,7 @@ static struct task_struct *dup_task_struct(struct task_struct *orig)
84455 *stackend = STACK_END_MAGIC; /* for overflow detection */
84456
84457 #ifdef CONFIG_CC_STACKPROTECTOR
84458 - tsk->stack_canary = get_random_int();
84459 + tsk->stack_canary = pax_get_random_long();
84460 #endif
84461
84462 /*
84463 @@ -345,12 +345,80 @@ free_tsk:
84464 }
84465
84466 #ifdef CONFIG_MMU
84467 -static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84468 +static struct vm_area_struct *dup_vma(struct mm_struct *mm, struct mm_struct *oldmm, struct vm_area_struct *mpnt)
84469 +{
84470 + struct vm_area_struct *tmp;
84471 + unsigned long charge;
84472 + struct file *file;
84473 + int retval;
84474 +
84475 + charge = 0;
84476 + if (mpnt->vm_flags & VM_ACCOUNT) {
84477 + unsigned long len = vma_pages(mpnt);
84478 +
84479 + if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
84480 + goto fail_nomem;
84481 + charge = len;
84482 + }
84483 + tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
84484 + if (!tmp)
84485 + goto fail_nomem;
84486 + *tmp = *mpnt;
84487 + tmp->vm_mm = mm;
84488 + INIT_LIST_HEAD(&tmp->anon_vma_chain);
84489 + retval = vma_dup_policy(mpnt, tmp);
84490 + if (retval)
84491 + goto fail_nomem_policy;
84492 + if (anon_vma_fork(tmp, mpnt))
84493 + goto fail_nomem_anon_vma_fork;
84494 + tmp->vm_flags &= ~VM_LOCKED;
84495 + tmp->vm_next = tmp->vm_prev = NULL;
84496 + tmp->vm_mirror = NULL;
84497 + file = tmp->vm_file;
84498 + if (file) {
84499 + struct inode *inode = file_inode(file);
84500 + struct address_space *mapping = file->f_mapping;
84501 +
84502 + get_file(file);
84503 + if (tmp->vm_flags & VM_DENYWRITE)
84504 + atomic_dec(&inode->i_writecount);
84505 + mutex_lock(&mapping->i_mmap_mutex);
84506 + if (tmp->vm_flags & VM_SHARED)
84507 + mapping->i_mmap_writable++;
84508 + flush_dcache_mmap_lock(mapping);
84509 + /* insert tmp into the share list, just after mpnt */
84510 + if (unlikely(tmp->vm_flags & VM_NONLINEAR))
84511 + vma_nonlinear_insert(tmp, &mapping->i_mmap_nonlinear);
84512 + else
84513 + vma_interval_tree_insert_after(tmp, mpnt, &mapping->i_mmap);
84514 + flush_dcache_mmap_unlock(mapping);
84515 + mutex_unlock(&mapping->i_mmap_mutex);
84516 + }
84517 +
84518 + /*
84519 + * Clear hugetlb-related page reserves for children. This only
84520 + * affects MAP_PRIVATE mappings. Faults generated by the child
84521 + * are not guaranteed to succeed, even if read-only
84522 + */
84523 + if (is_vm_hugetlb_page(tmp))
84524 + reset_vma_resv_huge_pages(tmp);
84525 +
84526 + return tmp;
84527 +
84528 +fail_nomem_anon_vma_fork:
84529 + mpol_put(vma_policy(tmp));
84530 +fail_nomem_policy:
84531 + kmem_cache_free(vm_area_cachep, tmp);
84532 +fail_nomem:
84533 + vm_unacct_memory(charge);
84534 + return NULL;
84535 +}
84536 +
84537 +static __latent_entropy int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84538 {
84539 struct vm_area_struct *mpnt, *tmp, *prev, **pprev;
84540 struct rb_node **rb_link, *rb_parent;
84541 int retval;
84542 - unsigned long charge;
84543
84544 uprobe_start_dup_mmap();
84545 down_write(&oldmm->mmap_sem);
84546 @@ -379,55 +447,15 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84547
84548 prev = NULL;
84549 for (mpnt = oldmm->mmap; mpnt; mpnt = mpnt->vm_next) {
84550 - struct file *file;
84551 -
84552 if (mpnt->vm_flags & VM_DONTCOPY) {
84553 vm_stat_account(mm, mpnt->vm_flags, mpnt->vm_file,
84554 -vma_pages(mpnt));
84555 continue;
84556 }
84557 - charge = 0;
84558 - if (mpnt->vm_flags & VM_ACCOUNT) {
84559 - unsigned long len = vma_pages(mpnt);
84560 -
84561 - if (security_vm_enough_memory_mm(oldmm, len)) /* sic */
84562 - goto fail_nomem;
84563 - charge = len;
84564 - }
84565 - tmp = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
84566 - if (!tmp)
84567 - goto fail_nomem;
84568 - *tmp = *mpnt;
84569 - INIT_LIST_HEAD(&tmp->anon_vma_chain);
84570 - retval = vma_dup_policy(mpnt, tmp);
84571 - if (retval)
84572 - goto fail_nomem_policy;
84573 - tmp->vm_mm = mm;
84574 - if (anon_vma_fork(tmp, mpnt))
84575 - goto fail_nomem_anon_vma_fork;
84576 - tmp->vm_flags &= ~VM_LOCKED;
84577 - tmp->vm_next = tmp->vm_prev = NULL;
84578 - file = tmp->vm_file;
84579 - if (file) {
84580 - struct inode *inode = file_inode(file);
84581 - struct address_space *mapping = file->f_mapping;
84582 -
84583 - get_file(file);
84584 - if (tmp->vm_flags & VM_DENYWRITE)
84585 - atomic_dec(&inode->i_writecount);
84586 - mutex_lock(&mapping->i_mmap_mutex);
84587 - if (tmp->vm_flags & VM_SHARED)
84588 - mapping->i_mmap_writable++;
84589 - flush_dcache_mmap_lock(mapping);
84590 - /* insert tmp into the share list, just after mpnt */
84591 - if (unlikely(tmp->vm_flags & VM_NONLINEAR))
84592 - vma_nonlinear_insert(tmp,
84593 - &mapping->i_mmap_nonlinear);
84594 - else
84595 - vma_interval_tree_insert_after(tmp, mpnt,
84596 - &mapping->i_mmap);
84597 - flush_dcache_mmap_unlock(mapping);
84598 - mutex_unlock(&mapping->i_mmap_mutex);
84599 + tmp = dup_vma(mm, oldmm, mpnt);
84600 + if (!tmp) {
84601 + retval = -ENOMEM;
84602 + goto out;
84603 }
84604
84605 /*
84606 @@ -459,6 +487,31 @@ static int dup_mmap(struct mm_struct *mm, struct mm_struct *oldmm)
84607 if (retval)
84608 goto out;
84609 }
84610 +
84611 +#ifdef CONFIG_PAX_SEGMEXEC
84612 + if (oldmm->pax_flags & MF_PAX_SEGMEXEC) {
84613 + struct vm_area_struct *mpnt_m;
84614 +
84615 + for (mpnt = oldmm->mmap, mpnt_m = mm->mmap; mpnt; mpnt = mpnt->vm_next, mpnt_m = mpnt_m->vm_next) {
84616 + BUG_ON(!mpnt_m || mpnt_m->vm_mirror || mpnt->vm_mm != oldmm || mpnt_m->vm_mm != mm);
84617 +
84618 + if (!mpnt->vm_mirror)
84619 + continue;
84620 +
84621 + if (mpnt->vm_end <= SEGMEXEC_TASK_SIZE) {
84622 + BUG_ON(mpnt->vm_mirror->vm_mirror != mpnt);
84623 + mpnt->vm_mirror = mpnt_m;
84624 + } else {
84625 + BUG_ON(mpnt->vm_mirror->vm_mirror == mpnt || mpnt->vm_mirror->vm_mirror->vm_mm != mm);
84626 + mpnt_m->vm_mirror = mpnt->vm_mirror->vm_mirror;
84627 + mpnt_m->vm_mirror->vm_mirror = mpnt_m;
84628 + mpnt->vm_mirror->vm_mirror = mpnt;
84629 + }
84630 + }
84631 + BUG_ON(mpnt_m);
84632 + }
84633 +#endif
84634 +
84635 /* a new mm has just been created */
84636 arch_dup_mmap(oldmm, mm);
84637 retval = 0;
84638 @@ -468,14 +521,6 @@ out:
84639 up_write(&oldmm->mmap_sem);
84640 uprobe_end_dup_mmap();
84641 return retval;
84642 -fail_nomem_anon_vma_fork:
84643 - mpol_put(vma_policy(tmp));
84644 -fail_nomem_policy:
84645 - kmem_cache_free(vm_area_cachep, tmp);
84646 -fail_nomem:
84647 - retval = -ENOMEM;
84648 - vm_unacct_memory(charge);
84649 - goto out;
84650 }
84651
84652 static inline int mm_alloc_pgd(struct mm_struct *mm)
84653 @@ -689,8 +734,8 @@ struct mm_struct *mm_access(struct task_struct *task, unsigned int mode)
84654 return ERR_PTR(err);
84655
84656 mm = get_task_mm(task);
84657 - if (mm && mm != current->mm &&
84658 - !ptrace_may_access(task, mode)) {
84659 + if (mm && ((mm != current->mm && !ptrace_may_access(task, mode)) ||
84660 + (mode == PTRACE_MODE_ATTACH && (gr_handle_proc_ptrace(task) || gr_acl_handle_procpidmem(task))))) {
84661 mmput(mm);
84662 mm = ERR_PTR(-EACCES);
84663 }
84664 @@ -909,13 +954,20 @@ static int copy_fs(unsigned long clone_flags, struct task_struct *tsk)
84665 spin_unlock(&fs->lock);
84666 return -EAGAIN;
84667 }
84668 - fs->users++;
84669 + atomic_inc(&fs->users);
84670 spin_unlock(&fs->lock);
84671 return 0;
84672 }
84673 tsk->fs = copy_fs_struct(fs);
84674 if (!tsk->fs)
84675 return -ENOMEM;
84676 + /* Carry through gr_chroot_dentry and is_chrooted instead
84677 + of recomputing it here. Already copied when the task struct
84678 + is duplicated. This allows pivot_root to not be treated as
84679 + a chroot
84680 + */
84681 + //gr_set_chroot_entries(tsk, &tsk->fs->root);
84682 +
84683 return 0;
84684 }
84685
84686 @@ -1126,7 +1178,7 @@ init_task_pid(struct task_struct *task, enum pid_type type, struct pid *pid)
84687 * parts of the process environment (as per the clone
84688 * flags). The actual kick-off is left to the caller.
84689 */
84690 -static struct task_struct *copy_process(unsigned long clone_flags,
84691 +static __latent_entropy struct task_struct *copy_process(unsigned long clone_flags,
84692 unsigned long stack_start,
84693 unsigned long stack_size,
84694 int __user *child_tidptr,
84695 @@ -1198,6 +1250,9 @@ static struct task_struct *copy_process(unsigned long clone_flags,
84696 DEBUG_LOCKS_WARN_ON(!p->softirqs_enabled);
84697 #endif
84698 retval = -EAGAIN;
84699 +
84700 + gr_learn_resource(p, RLIMIT_NPROC, atomic_read(&p->real_cred->user->processes), 0);
84701 +
84702 if (atomic_read(&p->real_cred->user->processes) >=
84703 task_rlimit(p, RLIMIT_NPROC)) {
84704 if (p->real_cred->user != INIT_USER &&
84705 @@ -1446,6 +1501,11 @@ static struct task_struct *copy_process(unsigned long clone_flags,
84706 goto bad_fork_free_pid;
84707 }
84708
84709 + /* synchronizes with gr_set_acls()
84710 + we need to call this past the point of no return for fork()
84711 + */
84712 + gr_copy_label(p);
84713 +
84714 if (likely(p->pid)) {
84715 ptrace_init_task(p, (clone_flags & CLONE_PTRACE) || trace);
84716
84717 @@ -1532,6 +1592,8 @@ bad_fork_cleanup_count:
84718 bad_fork_free:
84719 free_task(p);
84720 fork_out:
84721 + gr_log_forkfail(retval);
84722 +
84723 return ERR_PTR(retval);
84724 }
84725
84726 @@ -1593,6 +1655,7 @@ long do_fork(unsigned long clone_flags,
84727
84728 p = copy_process(clone_flags, stack_start, stack_size,
84729 child_tidptr, NULL, trace);
84730 + add_latent_entropy();
84731 /*
84732 * Do this prior waking up the new thread - the thread pointer
84733 * might get invalid after that point, if the thread exits quickly.
84734 @@ -1607,6 +1670,8 @@ long do_fork(unsigned long clone_flags,
84735 if (clone_flags & CLONE_PARENT_SETTID)
84736 put_user(nr, parent_tidptr);
84737
84738 + gr_handle_brute_check();
84739 +
84740 if (clone_flags & CLONE_VFORK) {
84741 p->vfork_done = &vfork;
84742 init_completion(&vfork);
84743 @@ -1723,7 +1788,7 @@ void __init proc_caches_init(void)
84744 mm_cachep = kmem_cache_create("mm_struct",
84745 sizeof(struct mm_struct), ARCH_MIN_MMSTRUCT_ALIGN,
84746 SLAB_HWCACHE_ALIGN|SLAB_PANIC|SLAB_NOTRACK, NULL);
84747 - vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC);
84748 + vm_area_cachep = KMEM_CACHE(vm_area_struct, SLAB_PANIC | SLAB_NO_SANITIZE);
84749 mmap_init();
84750 nsproxy_cache_init();
84751 }
84752 @@ -1763,7 +1828,7 @@ static int unshare_fs(unsigned long unshare_flags, struct fs_struct **new_fsp)
84753 return 0;
84754
84755 /* don't need lock here; in the worst case we'll do useless copy */
84756 - if (fs->users == 1)
84757 + if (atomic_read(&fs->users) == 1)
84758 return 0;
84759
84760 *new_fsp = copy_fs_struct(fs);
84761 @@ -1870,7 +1935,8 @@ SYSCALL_DEFINE1(unshare, unsigned long, unshare_flags)
84762 fs = current->fs;
84763 spin_lock(&fs->lock);
84764 current->fs = new_fs;
84765 - if (--fs->users)
84766 + gr_set_chroot_entries(current, &current->fs->root);
84767 + if (atomic_dec_return(&fs->users))
84768 new_fs = NULL;
84769 else
84770 new_fs = fs;
84771 diff --git a/kernel/futex.c b/kernel/futex.c
84772 index f6ff019..ac53307 100644
84773 --- a/kernel/futex.c
84774 +++ b/kernel/futex.c
84775 @@ -54,6 +54,7 @@
84776 #include <linux/mount.h>
84777 #include <linux/pagemap.h>
84778 #include <linux/syscalls.h>
84779 +#include <linux/ptrace.h>
84780 #include <linux/signal.h>
84781 #include <linux/export.h>
84782 #include <linux/magic.h>
84783 @@ -243,6 +244,11 @@ get_futex_key(u32 __user *uaddr, int fshared, union futex_key *key, int rw)
84784 struct page *page, *page_head;
84785 int err, ro = 0;
84786
84787 +#ifdef CONFIG_PAX_SEGMEXEC
84788 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && address >= SEGMEXEC_TASK_SIZE)
84789 + return -EFAULT;
84790 +#endif
84791 +
84792 /*
84793 * The futex address must be "naturally" aligned.
84794 */
84795 @@ -442,7 +448,7 @@ static int cmpxchg_futex_value_locked(u32 *curval, u32 __user *uaddr,
84796
84797 static int get_futex_value_locked(u32 *dest, u32 __user *from)
84798 {
84799 - int ret;
84800 + unsigned long ret;
84801
84802 pagefault_disable();
84803 ret = __copy_from_user_inatomic(dest, from, sizeof(u32));
84804 @@ -2735,6 +2741,7 @@ static int __init futex_init(void)
84805 {
84806 u32 curval;
84807 int i;
84808 + mm_segment_t oldfs;
84809
84810 /*
84811 * This will fail and we want it. Some arch implementations do
84812 @@ -2746,8 +2753,11 @@ static int __init futex_init(void)
84813 * implementation, the non-functional ones will return
84814 * -ENOSYS.
84815 */
84816 + oldfs = get_fs();
84817 + set_fs(USER_DS);
84818 if (cmpxchg_futex_value_locked(&curval, NULL, 0, 0) == -EFAULT)
84819 futex_cmpxchg_enabled = 1;
84820 + set_fs(oldfs);
84821
84822 for (i = 0; i < ARRAY_SIZE(futex_queues); i++) {
84823 plist_head_init(&futex_queues[i].chain);
84824 diff --git a/kernel/futex_compat.c b/kernel/futex_compat.c
84825 index f9f44fd..29885e4 100644
84826 --- a/kernel/futex_compat.c
84827 +++ b/kernel/futex_compat.c
84828 @@ -32,7 +32,7 @@ fetch_robust_entry(compat_uptr_t *uentry, struct robust_list __user **entry,
84829 return 0;
84830 }
84831
84832 -static void __user *futex_uaddr(struct robust_list __user *entry,
84833 +static void __user __intentional_overflow(-1) *futex_uaddr(struct robust_list __user *entry,
84834 compat_long_t futex_offset)
84835 {
84836 compat_uptr_t base = ptr_to_compat(entry);
84837 diff --git a/kernel/gcov/base.c b/kernel/gcov/base.c
84838 index f45b75b..bfac6d5 100644
84839 --- a/kernel/gcov/base.c
84840 +++ b/kernel/gcov/base.c
84841 @@ -108,11 +108,6 @@ void gcov_enable_events(void)
84842 }
84843
84844 #ifdef CONFIG_MODULES
84845 -static inline int within(void *addr, void *start, unsigned long size)
84846 -{
84847 - return ((addr >= start) && (addr < start + size));
84848 -}
84849 -
84850 /* Update list and generate events when modules are unloaded. */
84851 static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
84852 void *data)
84853 @@ -127,7 +122,7 @@ static int gcov_module_notifier(struct notifier_block *nb, unsigned long event,
84854
84855 /* Remove entries located in module from linked list. */
84856 while ((info = gcov_info_next(info))) {
84857 - if (within(info, mod->module_core, mod->core_size)) {
84858 + if (within_module_core_rw((unsigned long)info, mod)) {
84859 gcov_info_unlink(prev, info);
84860 if (gcov_events_enabled)
84861 gcov_event(GCOV_REMOVE, info);
84862 diff --git a/kernel/hrtimer.c b/kernel/hrtimer.c
84863 index 383319b..56ebb13 100644
84864 --- a/kernel/hrtimer.c
84865 +++ b/kernel/hrtimer.c
84866 @@ -1438,7 +1438,7 @@ void hrtimer_peek_ahead_timers(void)
84867 local_irq_restore(flags);
84868 }
84869
84870 -static void run_hrtimer_softirq(struct softirq_action *h)
84871 +static __latent_entropy void run_hrtimer_softirq(void)
84872 {
84873 hrtimer_peek_ahead_timers();
84874 }
84875 diff --git a/kernel/irq_work.c b/kernel/irq_work.c
84876 index 55fcce6..0e4cf34 100644
84877 --- a/kernel/irq_work.c
84878 +++ b/kernel/irq_work.c
84879 @@ -189,12 +189,13 @@ static int irq_work_cpu_notify(struct notifier_block *self,
84880 return NOTIFY_OK;
84881 }
84882
84883 -static struct notifier_block cpu_notify;
84884 +static struct notifier_block cpu_notify = {
84885 + .notifier_call = irq_work_cpu_notify,
84886 + .priority = 0,
84887 +};
84888
84889 static __init int irq_work_init_cpu_notifier(void)
84890 {
84891 - cpu_notify.notifier_call = irq_work_cpu_notify;
84892 - cpu_notify.priority = 0;
84893 register_cpu_notifier(&cpu_notify);
84894 return 0;
84895 }
84896 diff --git a/kernel/jump_label.c b/kernel/jump_label.c
84897 index 9019f15..9a3c42e 100644
84898 --- a/kernel/jump_label.c
84899 +++ b/kernel/jump_label.c
84900 @@ -14,6 +14,7 @@
84901 #include <linux/err.h>
84902 #include <linux/static_key.h>
84903 #include <linux/jump_label_ratelimit.h>
84904 +#include <linux/mm.h>
84905
84906 #ifdef HAVE_JUMP_LABEL
84907
84908 @@ -51,7 +52,9 @@ jump_label_sort_entries(struct jump_entry *start, struct jump_entry *stop)
84909
84910 size = (((unsigned long)stop - (unsigned long)start)
84911 / sizeof(struct jump_entry));
84912 + pax_open_kernel();
84913 sort(start, size, sizeof(struct jump_entry), jump_label_cmp, NULL);
84914 + pax_close_kernel();
84915 }
84916
84917 static void jump_label_update(struct static_key *key, int enable);
84918 @@ -363,10 +366,12 @@ static void jump_label_invalidate_module_init(struct module *mod)
84919 struct jump_entry *iter_stop = iter_start + mod->num_jump_entries;
84920 struct jump_entry *iter;
84921
84922 + pax_open_kernel();
84923 for (iter = iter_start; iter < iter_stop; iter++) {
84924 if (within_module_init(iter->code, mod))
84925 iter->code = 0;
84926 }
84927 + pax_close_kernel();
84928 }
84929
84930 static int
84931 diff --git a/kernel/kallsyms.c b/kernel/kallsyms.c
84932 index 3127ad5..159d880 100644
84933 --- a/kernel/kallsyms.c
84934 +++ b/kernel/kallsyms.c
84935 @@ -11,6 +11,9 @@
84936 * Changed the compression method from stem compression to "table lookup"
84937 * compression (see scripts/kallsyms.c for a more complete description)
84938 */
84939 +#ifdef CONFIG_GRKERNSEC_HIDESYM
84940 +#define __INCLUDED_BY_HIDESYM 1
84941 +#endif
84942 #include <linux/kallsyms.h>
84943 #include <linux/module.h>
84944 #include <linux/init.h>
84945 @@ -53,12 +56,33 @@ extern const unsigned long kallsyms_markers[] __attribute__((weak));
84946
84947 static inline int is_kernel_inittext(unsigned long addr)
84948 {
84949 + if (system_state != SYSTEM_BOOTING)
84950 + return 0;
84951 +
84952 if (addr >= (unsigned long)_sinittext
84953 && addr <= (unsigned long)_einittext)
84954 return 1;
84955 return 0;
84956 }
84957
84958 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84959 +#ifdef CONFIG_MODULES
84960 +static inline int is_module_text(unsigned long addr)
84961 +{
84962 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END)
84963 + return 1;
84964 +
84965 + addr = ktla_ktva(addr);
84966 + return (unsigned long)MODULES_EXEC_VADDR <= addr && addr <= (unsigned long)MODULES_EXEC_END;
84967 +}
84968 +#else
84969 +static inline int is_module_text(unsigned long addr)
84970 +{
84971 + return 0;
84972 +}
84973 +#endif
84974 +#endif
84975 +
84976 static inline int is_kernel_text(unsigned long addr)
84977 {
84978 if ((addr >= (unsigned long)_stext && addr <= (unsigned long)_etext) ||
84979 @@ -69,13 +93,28 @@ static inline int is_kernel_text(unsigned long addr)
84980
84981 static inline int is_kernel(unsigned long addr)
84982 {
84983 +
84984 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
84985 + if (is_kernel_text(addr) || is_kernel_inittext(addr))
84986 + return 1;
84987 +
84988 + if (ktla_ktva((unsigned long)_text) <= addr && addr < (unsigned long)_end)
84989 +#else
84990 if (addr >= (unsigned long)_stext && addr <= (unsigned long)_end)
84991 +#endif
84992 +
84993 return 1;
84994 return in_gate_area_no_mm(addr);
84995 }
84996
84997 static int is_ksym_addr(unsigned long addr)
84998 {
84999 +
85000 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
85001 + if (is_module_text(addr))
85002 + return 0;
85003 +#endif
85004 +
85005 if (all_var)
85006 return is_kernel(addr);
85007
85008 @@ -480,7 +519,6 @@ static unsigned long get_ksymbol_core(struct kallsym_iter *iter)
85009
85010 static void reset_iter(struct kallsym_iter *iter, loff_t new_pos)
85011 {
85012 - iter->name[0] = '\0';
85013 iter->nameoff = get_symbol_offset(new_pos);
85014 iter->pos = new_pos;
85015 }
85016 @@ -528,6 +566,11 @@ static int s_show(struct seq_file *m, void *p)
85017 {
85018 struct kallsym_iter *iter = m->private;
85019
85020 +#ifdef CONFIG_GRKERNSEC_HIDESYM
85021 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID))
85022 + return 0;
85023 +#endif
85024 +
85025 /* Some debugging symbols have no name. Ignore them. */
85026 if (!iter->name[0])
85027 return 0;
85028 @@ -541,6 +584,7 @@ static int s_show(struct seq_file *m, void *p)
85029 */
85030 type = iter->exported ? toupper(iter->type) :
85031 tolower(iter->type);
85032 +
85033 seq_printf(m, "%pK %c %s\t[%s]\n", (void *)iter->value,
85034 type, iter->name, iter->module_name);
85035 } else
85036 @@ -566,7 +610,7 @@ static int kallsyms_open(struct inode *inode, struct file *file)
85037 struct kallsym_iter *iter;
85038 int ret;
85039
85040 - iter = kmalloc(sizeof(*iter), GFP_KERNEL);
85041 + iter = kzalloc(sizeof(*iter), GFP_KERNEL);
85042 if (!iter)
85043 return -ENOMEM;
85044 reset_iter(iter, 0);
85045 diff --git a/kernel/kcmp.c b/kernel/kcmp.c
85046 index e30ac0f..3528cac 100644
85047 --- a/kernel/kcmp.c
85048 +++ b/kernel/kcmp.c
85049 @@ -99,6 +99,10 @@ SYSCALL_DEFINE5(kcmp, pid_t, pid1, pid_t, pid2, int, type,
85050 struct task_struct *task1, *task2;
85051 int ret;
85052
85053 +#ifdef CONFIG_GRKERNSEC
85054 + return -ENOSYS;
85055 +#endif
85056 +
85057 rcu_read_lock();
85058
85059 /*
85060 diff --git a/kernel/kexec.c b/kernel/kexec.c
85061 index 9c97016..df438f8 100644
85062 --- a/kernel/kexec.c
85063 +++ b/kernel/kexec.c
85064 @@ -1044,7 +1044,8 @@ asmlinkage long compat_sys_kexec_load(unsigned long entry,
85065 unsigned long flags)
85066 {
85067 struct compat_kexec_segment in;
85068 - struct kexec_segment out, __user *ksegments;
85069 + struct kexec_segment out;
85070 + struct kexec_segment __user *ksegments;
85071 unsigned long i, result;
85072
85073 /* Don't allow clients that don't understand the native
85074 diff --git a/kernel/kmod.c b/kernel/kmod.c
85075 index b086006..655e2aa 100644
85076 --- a/kernel/kmod.c
85077 +++ b/kernel/kmod.c
85078 @@ -75,7 +75,7 @@ static void free_modprobe_argv(struct subprocess_info *info)
85079 kfree(info->argv);
85080 }
85081
85082 -static int call_modprobe(char *module_name, int wait)
85083 +static int call_modprobe(char *module_name, char *module_param, int wait)
85084 {
85085 struct subprocess_info *info;
85086 static char *envp[] = {
85087 @@ -85,7 +85,7 @@ static int call_modprobe(char *module_name, int wait)
85088 NULL
85089 };
85090
85091 - char **argv = kmalloc(sizeof(char *[5]), GFP_KERNEL);
85092 + char **argv = kmalloc(sizeof(char *[6]), GFP_KERNEL);
85093 if (!argv)
85094 goto out;
85095
85096 @@ -97,7 +97,8 @@ static int call_modprobe(char *module_name, int wait)
85097 argv[1] = "-q";
85098 argv[2] = "--";
85099 argv[3] = module_name; /* check free_modprobe_argv() */
85100 - argv[4] = NULL;
85101 + argv[4] = module_param;
85102 + argv[5] = NULL;
85103
85104 info = call_usermodehelper_setup(modprobe_path, argv, envp, GFP_KERNEL,
85105 NULL, free_modprobe_argv, NULL);
85106 @@ -129,9 +130,8 @@ out:
85107 * If module auto-loading support is disabled then this function
85108 * becomes a no-operation.
85109 */
85110 -int __request_module(bool wait, const char *fmt, ...)
85111 +static int ____request_module(bool wait, char *module_param, const char *fmt, va_list ap)
85112 {
85113 - va_list args;
85114 char module_name[MODULE_NAME_LEN];
85115 unsigned int max_modprobes;
85116 int ret;
85117 @@ -150,9 +150,7 @@ int __request_module(bool wait, const char *fmt, ...)
85118 if (!modprobe_path[0])
85119 return 0;
85120
85121 - va_start(args, fmt);
85122 - ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, args);
85123 - va_end(args);
85124 + ret = vsnprintf(module_name, MODULE_NAME_LEN, fmt, ap);
85125 if (ret >= MODULE_NAME_LEN)
85126 return -ENAMETOOLONG;
85127
85128 @@ -160,6 +158,20 @@ int __request_module(bool wait, const char *fmt, ...)
85129 if (ret)
85130 return ret;
85131
85132 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
85133 + if (uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
85134 + /* hack to workaround consolekit/udisks stupidity */
85135 + read_lock(&tasklist_lock);
85136 + if (!strcmp(current->comm, "mount") &&
85137 + current->real_parent && !strncmp(current->real_parent->comm, "udisk", 5)) {
85138 + read_unlock(&tasklist_lock);
85139 + printk(KERN_ALERT "grsec: denied attempt to auto-load fs module %.64s by udisks\n", module_name);
85140 + return -EPERM;
85141 + }
85142 + read_unlock(&tasklist_lock);
85143 + }
85144 +#endif
85145 +
85146 /* If modprobe needs a service that is in a module, we get a recursive
85147 * loop. Limit the number of running kmod threads to max_threads/2 or
85148 * MAX_KMOD_CONCURRENT, whichever is the smaller. A cleaner method
85149 @@ -188,11 +200,52 @@ int __request_module(bool wait, const char *fmt, ...)
85150
85151 trace_module_request(module_name, wait, _RET_IP_);
85152
85153 - ret = call_modprobe(module_name, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
85154 + ret = call_modprobe(module_name, module_param, wait ? UMH_WAIT_PROC : UMH_WAIT_EXEC);
85155
85156 atomic_dec(&kmod_concurrent);
85157 return ret;
85158 }
85159 +
85160 +int ___request_module(bool wait, char *module_param, const char *fmt, ...)
85161 +{
85162 + va_list args;
85163 + int ret;
85164 +
85165 + va_start(args, fmt);
85166 + ret = ____request_module(wait, module_param, fmt, args);
85167 + va_end(args);
85168 +
85169 + return ret;
85170 +}
85171 +
85172 +int __request_module(bool wait, const char *fmt, ...)
85173 +{
85174 + va_list args;
85175 + int ret;
85176 +
85177 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
85178 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)) {
85179 + char module_param[MODULE_NAME_LEN];
85180 +
85181 + memset(module_param, 0, sizeof(module_param));
85182 +
85183 + snprintf(module_param, sizeof(module_param) - 1, "grsec_modharden_normal%u_", GR_GLOBAL_UID(current_uid()));
85184 +
85185 + va_start(args, fmt);
85186 + ret = ____request_module(wait, module_param, fmt, args);
85187 + va_end(args);
85188 +
85189 + return ret;
85190 + }
85191 +#endif
85192 +
85193 + va_start(args, fmt);
85194 + ret = ____request_module(wait, NULL, fmt, args);
85195 + va_end(args);
85196 +
85197 + return ret;
85198 +}
85199 +
85200 EXPORT_SYMBOL(__request_module);
85201 #endif /* CONFIG_MODULES */
85202
85203 @@ -218,6 +271,19 @@ static int ____call_usermodehelper(void *data)
85204 */
85205 set_user_nice(current, 0);
85206
85207 +#ifdef CONFIG_GRKERNSEC
85208 + /* this is race-free as far as userland is concerned as we copied
85209 + out the path to be used prior to this point and are now operating
85210 + on that copy
85211 + */
85212 + if ((strncmp(sub_info->path, "/sbin/", 6) && strncmp(sub_info->path, "/usr/lib/", 9) &&
85213 + strncmp(sub_info->path, "/lib/", 5) && strncmp(sub_info->path, "/lib64/", 7)) || strstr(sub_info->path, "..")) {
85214 + printk(KERN_ALERT "grsec: denied exec of usermode helper binary %.950s located outside of /sbin and system library paths\n", sub_info->path);
85215 + retval = -EPERM;
85216 + goto fail;
85217 + }
85218 +#endif
85219 +
85220 retval = -ENOMEM;
85221 new = prepare_kernel_cred(current);
85222 if (!new)
85223 @@ -240,8 +306,8 @@ static int ____call_usermodehelper(void *data)
85224 commit_creds(new);
85225
85226 retval = do_execve(sub_info->path,
85227 - (const char __user *const __user *)sub_info->argv,
85228 - (const char __user *const __user *)sub_info->envp);
85229 + (const char __user *const __force_user *)sub_info->argv,
85230 + (const char __user *const __force_user *)sub_info->envp);
85231 if (!retval)
85232 return 0;
85233
85234 @@ -260,6 +326,10 @@ static int call_helper(void *data)
85235
85236 static void call_usermodehelper_freeinfo(struct subprocess_info *info)
85237 {
85238 +#ifdef CONFIG_GRKERNSEC
85239 + kfree(info->path);
85240 + info->path = info->origpath;
85241 +#endif
85242 if (info->cleanup)
85243 (*info->cleanup)(info);
85244 kfree(info);
85245 @@ -303,7 +373,7 @@ static int wait_for_helper(void *data)
85246 *
85247 * Thus the __user pointer cast is valid here.
85248 */
85249 - sys_wait4(pid, (int __user *)&ret, 0, NULL);
85250 + sys_wait4(pid, (int __force_user *)&ret, 0, NULL);
85251
85252 /*
85253 * If ret is 0, either ____call_usermodehelper failed and the
85254 @@ -542,7 +612,12 @@ struct subprocess_info *call_usermodehelper_setup(char *path, char **argv,
85255 goto out;
85256
85257 INIT_WORK(&sub_info->work, __call_usermodehelper);
85258 +#ifdef CONFIG_GRKERNSEC
85259 + sub_info->origpath = path;
85260 + sub_info->path = kstrdup(path, gfp_mask);
85261 +#else
85262 sub_info->path = path;
85263 +#endif
85264 sub_info->argv = argv;
85265 sub_info->envp = envp;
85266
85267 @@ -650,7 +725,7 @@ EXPORT_SYMBOL(call_usermodehelper);
85268 static int proc_cap_handler(struct ctl_table *table, int write,
85269 void __user *buffer, size_t *lenp, loff_t *ppos)
85270 {
85271 - struct ctl_table t;
85272 + ctl_table_no_const t;
85273 unsigned long cap_array[_KERNEL_CAPABILITY_U32S];
85274 kernel_cap_t new_cap;
85275 int err, i;
85276 diff --git a/kernel/kprobes.c b/kernel/kprobes.c
85277 index ceeadfc..11c18b6 100644
85278 --- a/kernel/kprobes.c
85279 +++ b/kernel/kprobes.c
85280 @@ -31,6 +31,9 @@
85281 * <jkenisto@us.ibm.com> and Prasanna S Panchamukhi
85282 * <prasanna@in.ibm.com> added function-return probes.
85283 */
85284 +#ifdef CONFIG_GRKERNSEC_HIDESYM
85285 +#define __INCLUDED_BY_HIDESYM 1
85286 +#endif
85287 #include <linux/kprobes.h>
85288 #include <linux/hash.h>
85289 #include <linux/init.h>
85290 @@ -135,12 +138,12 @@ enum kprobe_slot_state {
85291
85292 static void *alloc_insn_page(void)
85293 {
85294 - return module_alloc(PAGE_SIZE);
85295 + return module_alloc_exec(PAGE_SIZE);
85296 }
85297
85298 static void free_insn_page(void *page)
85299 {
85300 - module_free(NULL, page);
85301 + module_free_exec(NULL, page);
85302 }
85303
85304 struct kprobe_insn_cache kprobe_insn_slots = {
85305 @@ -2151,11 +2154,11 @@ static void __kprobes report_probe(struct seq_file *pi, struct kprobe *p,
85306 kprobe_type = "k";
85307
85308 if (sym)
85309 - seq_printf(pi, "%p %s %s+0x%x %s ",
85310 + seq_printf(pi, "%pK %s %s+0x%x %s ",
85311 p->addr, kprobe_type, sym, offset,
85312 (modname ? modname : " "));
85313 else
85314 - seq_printf(pi, "%p %s %p ",
85315 + seq_printf(pi, "%pK %s %pK ",
85316 p->addr, kprobe_type, p->addr);
85317
85318 if (!pp)
85319 diff --git a/kernel/ksysfs.c b/kernel/ksysfs.c
85320 index 9659d38..bffd520 100644
85321 --- a/kernel/ksysfs.c
85322 +++ b/kernel/ksysfs.c
85323 @@ -46,6 +46,8 @@ static ssize_t uevent_helper_store(struct kobject *kobj,
85324 {
85325 if (count+1 > UEVENT_HELPER_PATH_LEN)
85326 return -ENOENT;
85327 + if (!capable(CAP_SYS_ADMIN))
85328 + return -EPERM;
85329 memcpy(uevent_helper, buf, count);
85330 uevent_helper[count] = '\0';
85331 if (count && uevent_helper[count-1] == '\n')
85332 @@ -172,7 +174,7 @@ static ssize_t notes_read(struct file *filp, struct kobject *kobj,
85333 return count;
85334 }
85335
85336 -static struct bin_attribute notes_attr = {
85337 +static bin_attribute_no_const notes_attr __read_only = {
85338 .attr = {
85339 .name = "notes",
85340 .mode = S_IRUGO,
85341 diff --git a/kernel/locking/lockdep.c b/kernel/locking/lockdep.c
85342 index 576ba75..7c256e4 100644
85343 --- a/kernel/locking/lockdep.c
85344 +++ b/kernel/locking/lockdep.c
85345 @@ -596,6 +596,10 @@ static int static_obj(void *obj)
85346 end = (unsigned long) &_end,
85347 addr = (unsigned long) obj;
85348
85349 +#ifdef CONFIG_PAX_KERNEXEC
85350 + start = ktla_ktva(start);
85351 +#endif
85352 +
85353 /*
85354 * static variable?
85355 */
85356 @@ -736,6 +740,7 @@ register_lock_class(struct lockdep_map *lock, unsigned int subclass, int force)
85357 if (!static_obj(lock->key)) {
85358 debug_locks_off();
85359 printk("INFO: trying to register non-static key.\n");
85360 + printk("lock:%pS key:%pS.\n", lock, lock->key);
85361 printk("the code is fine but needs lockdep annotation.\n");
85362 printk("turning off the locking correctness validator.\n");
85363 dump_stack();
85364 @@ -3080,7 +3085,7 @@ static int __lock_acquire(struct lockdep_map *lock, unsigned int subclass,
85365 if (!class)
85366 return 0;
85367 }
85368 - atomic_inc((atomic_t *)&class->ops);
85369 + atomic_long_inc_unchecked((atomic_long_unchecked_t *)&class->ops);
85370 if (very_verbose(class)) {
85371 printk("\nacquire class [%p] %s", class->key, class->name);
85372 if (class->name_version > 1)
85373 diff --git a/kernel/locking/lockdep_proc.c b/kernel/locking/lockdep_proc.c
85374 index ef43ac4..2720dfa 100644
85375 --- a/kernel/locking/lockdep_proc.c
85376 +++ b/kernel/locking/lockdep_proc.c
85377 @@ -65,7 +65,7 @@ static int l_show(struct seq_file *m, void *v)
85378 return 0;
85379 }
85380
85381 - seq_printf(m, "%p", class->key);
85382 + seq_printf(m, "%pK", class->key);
85383 #ifdef CONFIG_DEBUG_LOCKDEP
85384 seq_printf(m, " OPS:%8ld", class->ops);
85385 #endif
85386 @@ -83,7 +83,7 @@ static int l_show(struct seq_file *m, void *v)
85387
85388 list_for_each_entry(entry, &class->locks_after, entry) {
85389 if (entry->distance == 1) {
85390 - seq_printf(m, " -> [%p] ", entry->class->key);
85391 + seq_printf(m, " -> [%pK] ", entry->class->key);
85392 print_name(m, entry->class);
85393 seq_puts(m, "\n");
85394 }
85395 @@ -152,7 +152,7 @@ static int lc_show(struct seq_file *m, void *v)
85396 if (!class->key)
85397 continue;
85398
85399 - seq_printf(m, "[%p] ", class->key);
85400 + seq_printf(m, "[%pK] ", class->key);
85401 print_name(m, class);
85402 seq_puts(m, "\n");
85403 }
85404 @@ -496,7 +496,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
85405 if (!i)
85406 seq_line(m, '-', 40-namelen, namelen);
85407
85408 - snprintf(ip, sizeof(ip), "[<%p>]",
85409 + snprintf(ip, sizeof(ip), "[<%pK>]",
85410 (void *)class->contention_point[i]);
85411 seq_printf(m, "%40s %14lu %29s %pS\n",
85412 name, stats->contention_point[i],
85413 @@ -511,7 +511,7 @@ static void seq_stats(struct seq_file *m, struct lock_stat_data *data)
85414 if (!i)
85415 seq_line(m, '-', 40-namelen, namelen);
85416
85417 - snprintf(ip, sizeof(ip), "[<%p>]",
85418 + snprintf(ip, sizeof(ip), "[<%pK>]",
85419 (void *)class->contending_point[i]);
85420 seq_printf(m, "%40s %14lu %29s %pS\n",
85421 name, stats->contending_point[i],
85422 diff --git a/kernel/locking/mutex-debug.c b/kernel/locking/mutex-debug.c
85423 index 7e3443f..b2a1e6b 100644
85424 --- a/kernel/locking/mutex-debug.c
85425 +++ b/kernel/locking/mutex-debug.c
85426 @@ -49,21 +49,21 @@ void debug_mutex_free_waiter(struct mutex_waiter *waiter)
85427 }
85428
85429 void debug_mutex_add_waiter(struct mutex *lock, struct mutex_waiter *waiter,
85430 - struct thread_info *ti)
85431 + struct task_struct *task)
85432 {
85433 SMP_DEBUG_LOCKS_WARN_ON(!spin_is_locked(&lock->wait_lock));
85434
85435 /* Mark the current thread as blocked on the lock: */
85436 - ti->task->blocked_on = waiter;
85437 + task->blocked_on = waiter;
85438 }
85439
85440 void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
85441 - struct thread_info *ti)
85442 + struct task_struct *task)
85443 {
85444 DEBUG_LOCKS_WARN_ON(list_empty(&waiter->list));
85445 - DEBUG_LOCKS_WARN_ON(waiter->task != ti->task);
85446 - DEBUG_LOCKS_WARN_ON(ti->task->blocked_on != waiter);
85447 - ti->task->blocked_on = NULL;
85448 + DEBUG_LOCKS_WARN_ON(waiter->task != task);
85449 + DEBUG_LOCKS_WARN_ON(task->blocked_on != waiter);
85450 + task->blocked_on = NULL;
85451
85452 list_del_init(&waiter->list);
85453 waiter->task = NULL;
85454 diff --git a/kernel/locking/mutex-debug.h b/kernel/locking/mutex-debug.h
85455 index 0799fd3..d06ae3b 100644
85456 --- a/kernel/locking/mutex-debug.h
85457 +++ b/kernel/locking/mutex-debug.h
85458 @@ -20,9 +20,9 @@ extern void debug_mutex_wake_waiter(struct mutex *lock,
85459 extern void debug_mutex_free_waiter(struct mutex_waiter *waiter);
85460 extern void debug_mutex_add_waiter(struct mutex *lock,
85461 struct mutex_waiter *waiter,
85462 - struct thread_info *ti);
85463 + struct task_struct *task);
85464 extern void mutex_remove_waiter(struct mutex *lock, struct mutex_waiter *waiter,
85465 - struct thread_info *ti);
85466 + struct task_struct *task);
85467 extern void debug_mutex_unlock(struct mutex *lock);
85468 extern void debug_mutex_init(struct mutex *lock, const char *name,
85469 struct lock_class_key *key);
85470 diff --git a/kernel/locking/mutex.c b/kernel/locking/mutex.c
85471 index 4dd6e4c..df52693 100644
85472 --- a/kernel/locking/mutex.c
85473 +++ b/kernel/locking/mutex.c
85474 @@ -135,7 +135,7 @@ void mspin_lock(struct mspin_node **lock, struct mspin_node *node)
85475 node->locked = 1;
85476 return;
85477 }
85478 - ACCESS_ONCE(prev->next) = node;
85479 + ACCESS_ONCE_RW(prev->next) = node;
85480 smp_wmb();
85481 /* Wait until the lock holder passes the lock down */
85482 while (!ACCESS_ONCE(node->locked))
85483 @@ -156,7 +156,7 @@ static void mspin_unlock(struct mspin_node **lock, struct mspin_node *node)
85484 while (!(next = ACCESS_ONCE(node->next)))
85485 arch_mutex_cpu_relax();
85486 }
85487 - ACCESS_ONCE(next->locked) = 1;
85488 + ACCESS_ONCE_RW(next->locked) = 1;
85489 smp_wmb();
85490 }
85491
85492 @@ -520,7 +520,7 @@ slowpath:
85493 goto skip_wait;
85494
85495 debug_mutex_lock_common(lock, &waiter);
85496 - debug_mutex_add_waiter(lock, &waiter, task_thread_info(task));
85497 + debug_mutex_add_waiter(lock, &waiter, task);
85498
85499 /* add waiting tasks to the end of the waitqueue (FIFO): */
85500 list_add_tail(&waiter.list, &lock->wait_list);
85501 @@ -564,7 +564,7 @@ slowpath:
85502 schedule_preempt_disabled();
85503 spin_lock_mutex(&lock->wait_lock, flags);
85504 }
85505 - mutex_remove_waiter(lock, &waiter, current_thread_info());
85506 + mutex_remove_waiter(lock, &waiter, task);
85507 /* set it to 0 if there are no waiters left: */
85508 if (likely(list_empty(&lock->wait_list)))
85509 atomic_set(&lock->count, 0);
85510 @@ -601,7 +601,7 @@ skip_wait:
85511 return 0;
85512
85513 err:
85514 - mutex_remove_waiter(lock, &waiter, task_thread_info(task));
85515 + mutex_remove_waiter(lock, &waiter, task);
85516 spin_unlock_mutex(&lock->wait_lock, flags);
85517 debug_mutex_free_waiter(&waiter);
85518 mutex_release(&lock->dep_map, 1, ip);
85519 diff --git a/kernel/locking/rtmutex-tester.c b/kernel/locking/rtmutex-tester.c
85520 index 1d96dd0..994ff19 100644
85521 --- a/kernel/locking/rtmutex-tester.c
85522 +++ b/kernel/locking/rtmutex-tester.c
85523 @@ -22,7 +22,7 @@
85524 #define MAX_RT_TEST_MUTEXES 8
85525
85526 static spinlock_t rttest_lock;
85527 -static atomic_t rttest_event;
85528 +static atomic_unchecked_t rttest_event;
85529
85530 struct test_thread_data {
85531 int opcode;
85532 @@ -63,7 +63,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85533
85534 case RTTEST_LOCKCONT:
85535 td->mutexes[td->opdata] = 1;
85536 - td->event = atomic_add_return(1, &rttest_event);
85537 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85538 return 0;
85539
85540 case RTTEST_RESET:
85541 @@ -76,7 +76,7 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85542 return 0;
85543
85544 case RTTEST_RESETEVENT:
85545 - atomic_set(&rttest_event, 0);
85546 + atomic_set_unchecked(&rttest_event, 0);
85547 return 0;
85548
85549 default:
85550 @@ -93,9 +93,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85551 return ret;
85552
85553 td->mutexes[id] = 1;
85554 - td->event = atomic_add_return(1, &rttest_event);
85555 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85556 rt_mutex_lock(&mutexes[id]);
85557 - td->event = atomic_add_return(1, &rttest_event);
85558 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85559 td->mutexes[id] = 4;
85560 return 0;
85561
85562 @@ -106,9 +106,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85563 return ret;
85564
85565 td->mutexes[id] = 1;
85566 - td->event = atomic_add_return(1, &rttest_event);
85567 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85568 ret = rt_mutex_lock_interruptible(&mutexes[id], 0);
85569 - td->event = atomic_add_return(1, &rttest_event);
85570 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85571 td->mutexes[id] = ret ? 0 : 4;
85572 return ret ? -EINTR : 0;
85573
85574 @@ -117,9 +117,9 @@ static int handle_op(struct test_thread_data *td, int lockwakeup)
85575 if (id < 0 || id >= MAX_RT_TEST_MUTEXES || td->mutexes[id] != 4)
85576 return ret;
85577
85578 - td->event = atomic_add_return(1, &rttest_event);
85579 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85580 rt_mutex_unlock(&mutexes[id]);
85581 - td->event = atomic_add_return(1, &rttest_event);
85582 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85583 td->mutexes[id] = 0;
85584 return 0;
85585
85586 @@ -166,7 +166,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
85587 break;
85588
85589 td->mutexes[dat] = 2;
85590 - td->event = atomic_add_return(1, &rttest_event);
85591 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85592 break;
85593
85594 default:
85595 @@ -186,7 +186,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
85596 return;
85597
85598 td->mutexes[dat] = 3;
85599 - td->event = atomic_add_return(1, &rttest_event);
85600 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85601 break;
85602
85603 case RTTEST_LOCKNOWAIT:
85604 @@ -198,7 +198,7 @@ void schedule_rt_mutex_test(struct rt_mutex *mutex)
85605 return;
85606
85607 td->mutexes[dat] = 1;
85608 - td->event = atomic_add_return(1, &rttest_event);
85609 + td->event = atomic_add_return_unchecked(1, &rttest_event);
85610 return;
85611
85612 default:
85613 diff --git a/kernel/module.c b/kernel/module.c
85614 index f5a3b1e..97ebb15 100644
85615 --- a/kernel/module.c
85616 +++ b/kernel/module.c
85617 @@ -61,6 +61,7 @@
85618 #include <linux/pfn.h>
85619 #include <linux/bsearch.h>
85620 #include <linux/fips.h>
85621 +#include <linux/grsecurity.h>
85622 #include <uapi/linux/module.h>
85623 #include "module-internal.h"
85624
85625 @@ -157,7 +158,8 @@ static BLOCKING_NOTIFIER_HEAD(module_notify_list);
85626
85627 /* Bounds of module allocation, for speeding __module_address.
85628 * Protected by module_mutex. */
85629 -static unsigned long module_addr_min = -1UL, module_addr_max = 0;
85630 +static unsigned long module_addr_min_rw = -1UL, module_addr_max_rw = 0;
85631 +static unsigned long module_addr_min_rx = -1UL, module_addr_max_rx = 0;
85632
85633 int register_module_notifier(struct notifier_block * nb)
85634 {
85635 @@ -324,7 +326,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
85636 return true;
85637
85638 list_for_each_entry_rcu(mod, &modules, list) {
85639 - struct symsearch arr[] = {
85640 + struct symsearch modarr[] = {
85641 { mod->syms, mod->syms + mod->num_syms, mod->crcs,
85642 NOT_GPL_ONLY, false },
85643 { mod->gpl_syms, mod->gpl_syms + mod->num_gpl_syms,
85644 @@ -349,7 +351,7 @@ bool each_symbol_section(bool (*fn)(const struct symsearch *arr,
85645 if (mod->state == MODULE_STATE_UNFORMED)
85646 continue;
85647
85648 - if (each_symbol_in_section(arr, ARRAY_SIZE(arr), mod, fn, data))
85649 + if (each_symbol_in_section(modarr, ARRAY_SIZE(modarr), mod, fn, data))
85650 return true;
85651 }
85652 return false;
85653 @@ -489,7 +491,7 @@ static int percpu_modalloc(struct module *mod, struct load_info *info)
85654 if (!pcpusec->sh_size)
85655 return 0;
85656
85657 - if (align > PAGE_SIZE) {
85658 + if (align-1 >= PAGE_SIZE) {
85659 pr_warn("%s: per-cpu alignment %li > %li\n",
85660 mod->name, align, PAGE_SIZE);
85661 align = PAGE_SIZE;
85662 @@ -1064,7 +1066,7 @@ struct module_attribute module_uevent =
85663 static ssize_t show_coresize(struct module_attribute *mattr,
85664 struct module_kobject *mk, char *buffer)
85665 {
85666 - return sprintf(buffer, "%u\n", mk->mod->core_size);
85667 + return sprintf(buffer, "%u\n", mk->mod->core_size_rx + mk->mod->core_size_rw);
85668 }
85669
85670 static struct module_attribute modinfo_coresize =
85671 @@ -1073,7 +1075,7 @@ static struct module_attribute modinfo_coresize =
85672 static ssize_t show_initsize(struct module_attribute *mattr,
85673 struct module_kobject *mk, char *buffer)
85674 {
85675 - return sprintf(buffer, "%u\n", mk->mod->init_size);
85676 + return sprintf(buffer, "%u\n", mk->mod->init_size_rx + mk->mod->init_size_rw);
85677 }
85678
85679 static struct module_attribute modinfo_initsize =
85680 @@ -1165,12 +1167,29 @@ static int check_version(Elf_Shdr *sechdrs,
85681 goto bad_version;
85682 }
85683
85684 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
85685 + /*
85686 + * avoid potentially printing jibberish on attempted load
85687 + * of a module randomized with a different seed
85688 + */
85689 + pr_warn("no symbol version for %s\n", symname);
85690 +#else
85691 pr_warn("%s: no symbol version for %s\n", mod->name, symname);
85692 +#endif
85693 return 0;
85694
85695 bad_version:
85696 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
85697 + /*
85698 + * avoid potentially printing jibberish on attempted load
85699 + * of a module randomized with a different seed
85700 + */
85701 + printk("attempted module disagrees about version of symbol %s\n",
85702 + symname);
85703 +#else
85704 printk("%s: disagrees about version of symbol %s\n",
85705 mod->name, symname);
85706 +#endif
85707 return 0;
85708 }
85709
85710 @@ -1286,7 +1305,7 @@ resolve_symbol_wait(struct module *mod,
85711 */
85712 #ifdef CONFIG_SYSFS
85713
85714 -#ifdef CONFIG_KALLSYMS
85715 +#if defined(CONFIG_KALLSYMS) && !defined(CONFIG_GRKERNSEC_HIDESYM)
85716 static inline bool sect_empty(const Elf_Shdr *sect)
85717 {
85718 return !(sect->sh_flags & SHF_ALLOC) || sect->sh_size == 0;
85719 @@ -1426,7 +1445,7 @@ static void add_notes_attrs(struct module *mod, const struct load_info *info)
85720 {
85721 unsigned int notes, loaded, i;
85722 struct module_notes_attrs *notes_attrs;
85723 - struct bin_attribute *nattr;
85724 + bin_attribute_no_const *nattr;
85725
85726 /* failed to create section attributes, so can't create notes */
85727 if (!mod->sect_attrs)
85728 @@ -1538,7 +1557,7 @@ static void del_usage_links(struct module *mod)
85729 static int module_add_modinfo_attrs(struct module *mod)
85730 {
85731 struct module_attribute *attr;
85732 - struct module_attribute *temp_attr;
85733 + module_attribute_no_const *temp_attr;
85734 int error = 0;
85735 int i;
85736
85737 @@ -1759,21 +1778,21 @@ static void set_section_ro_nx(void *base,
85738
85739 static void unset_module_core_ro_nx(struct module *mod)
85740 {
85741 - set_page_attributes(mod->module_core + mod->core_text_size,
85742 - mod->module_core + mod->core_size,
85743 + set_page_attributes(mod->module_core_rw,
85744 + mod->module_core_rw + mod->core_size_rw,
85745 set_memory_x);
85746 - set_page_attributes(mod->module_core,
85747 - mod->module_core + mod->core_ro_size,
85748 + set_page_attributes(mod->module_core_rx,
85749 + mod->module_core_rx + mod->core_size_rx,
85750 set_memory_rw);
85751 }
85752
85753 static void unset_module_init_ro_nx(struct module *mod)
85754 {
85755 - set_page_attributes(mod->module_init + mod->init_text_size,
85756 - mod->module_init + mod->init_size,
85757 + set_page_attributes(mod->module_init_rw,
85758 + mod->module_init_rw + mod->init_size_rw,
85759 set_memory_x);
85760 - set_page_attributes(mod->module_init,
85761 - mod->module_init + mod->init_ro_size,
85762 + set_page_attributes(mod->module_init_rx,
85763 + mod->module_init_rx + mod->init_size_rx,
85764 set_memory_rw);
85765 }
85766
85767 @@ -1786,14 +1805,14 @@ void set_all_modules_text_rw(void)
85768 list_for_each_entry_rcu(mod, &modules, list) {
85769 if (mod->state == MODULE_STATE_UNFORMED)
85770 continue;
85771 - if ((mod->module_core) && (mod->core_text_size)) {
85772 - set_page_attributes(mod->module_core,
85773 - mod->module_core + mod->core_text_size,
85774 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
85775 + set_page_attributes(mod->module_core_rx,
85776 + mod->module_core_rx + mod->core_size_rx,
85777 set_memory_rw);
85778 }
85779 - if ((mod->module_init) && (mod->init_text_size)) {
85780 - set_page_attributes(mod->module_init,
85781 - mod->module_init + mod->init_text_size,
85782 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
85783 + set_page_attributes(mod->module_init_rx,
85784 + mod->module_init_rx + mod->init_size_rx,
85785 set_memory_rw);
85786 }
85787 }
85788 @@ -1809,14 +1828,14 @@ void set_all_modules_text_ro(void)
85789 list_for_each_entry_rcu(mod, &modules, list) {
85790 if (mod->state == MODULE_STATE_UNFORMED)
85791 continue;
85792 - if ((mod->module_core) && (mod->core_text_size)) {
85793 - set_page_attributes(mod->module_core,
85794 - mod->module_core + mod->core_text_size,
85795 + if ((mod->module_core_rx) && (mod->core_size_rx)) {
85796 + set_page_attributes(mod->module_core_rx,
85797 + mod->module_core_rx + mod->core_size_rx,
85798 set_memory_ro);
85799 }
85800 - if ((mod->module_init) && (mod->init_text_size)) {
85801 - set_page_attributes(mod->module_init,
85802 - mod->module_init + mod->init_text_size,
85803 + if ((mod->module_init_rx) && (mod->init_size_rx)) {
85804 + set_page_attributes(mod->module_init_rx,
85805 + mod->module_init_rx + mod->init_size_rx,
85806 set_memory_ro);
85807 }
85808 }
85809 @@ -1867,16 +1886,19 @@ static void free_module(struct module *mod)
85810
85811 /* This may be NULL, but that's OK */
85812 unset_module_init_ro_nx(mod);
85813 - module_free(mod, mod->module_init);
85814 + module_free(mod, mod->module_init_rw);
85815 + module_free_exec(mod, mod->module_init_rx);
85816 kfree(mod->args);
85817 percpu_modfree(mod);
85818
85819 /* Free lock-classes: */
85820 - lockdep_free_key_range(mod->module_core, mod->core_size);
85821 + lockdep_free_key_range(mod->module_core_rx, mod->core_size_rx);
85822 + lockdep_free_key_range(mod->module_core_rw, mod->core_size_rw);
85823
85824 /* Finally, free the core (containing the module structure) */
85825 unset_module_core_ro_nx(mod);
85826 - module_free(mod, mod->module_core);
85827 + module_free_exec(mod, mod->module_core_rx);
85828 + module_free(mod, mod->module_core_rw);
85829
85830 #ifdef CONFIG_MPU
85831 update_protections(current->mm);
85832 @@ -1945,9 +1967,31 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
85833 int ret = 0;
85834 const struct kernel_symbol *ksym;
85835
85836 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
85837 + int is_fs_load = 0;
85838 + int register_filesystem_found = 0;
85839 + char *p;
85840 +
85841 + p = strstr(mod->args, "grsec_modharden_fs");
85842 + if (p) {
85843 + char *endptr = p + sizeof("grsec_modharden_fs") - 1;
85844 + /* copy \0 as well */
85845 + memmove(p, endptr, strlen(mod->args) - (unsigned int)(endptr - mod->args) + 1);
85846 + is_fs_load = 1;
85847 + }
85848 +#endif
85849 +
85850 for (i = 1; i < symsec->sh_size / sizeof(Elf_Sym); i++) {
85851 const char *name = info->strtab + sym[i].st_name;
85852
85853 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
85854 + /* it's a real shame this will never get ripped and copied
85855 + upstream! ;(
85856 + */
85857 + if (is_fs_load && !strcmp(name, "register_filesystem"))
85858 + register_filesystem_found = 1;
85859 +#endif
85860 +
85861 switch (sym[i].st_shndx) {
85862 case SHN_COMMON:
85863 /* We compiled with -fno-common. These are not
85864 @@ -1968,7 +2012,9 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
85865 ksym = resolve_symbol_wait(mod, info, name);
85866 /* Ok if resolved. */
85867 if (ksym && !IS_ERR(ksym)) {
85868 + pax_open_kernel();
85869 sym[i].st_value = ksym->value;
85870 + pax_close_kernel();
85871 break;
85872 }
85873
85874 @@ -1987,11 +2033,20 @@ static int simplify_symbols(struct module *mod, const struct load_info *info)
85875 secbase = (unsigned long)mod_percpu(mod);
85876 else
85877 secbase = info->sechdrs[sym[i].st_shndx].sh_addr;
85878 + pax_open_kernel();
85879 sym[i].st_value += secbase;
85880 + pax_close_kernel();
85881 break;
85882 }
85883 }
85884
85885 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
85886 + if (is_fs_load && !register_filesystem_found) {
85887 + printk(KERN_ALERT "grsec: Denied attempt to load non-fs module %.64s through mount\n", mod->name);
85888 + ret = -EPERM;
85889 + }
85890 +#endif
85891 +
85892 return ret;
85893 }
85894
85895 @@ -2075,22 +2130,12 @@ static void layout_sections(struct module *mod, struct load_info *info)
85896 || s->sh_entsize != ~0UL
85897 || strstarts(sname, ".init"))
85898 continue;
85899 - s->sh_entsize = get_offset(mod, &mod->core_size, s, i);
85900 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
85901 + s->sh_entsize = get_offset(mod, &mod->core_size_rw, s, i);
85902 + else
85903 + s->sh_entsize = get_offset(mod, &mod->core_size_rx, s, i);
85904 pr_debug("\t%s\n", sname);
85905 }
85906 - switch (m) {
85907 - case 0: /* executable */
85908 - mod->core_size = debug_align(mod->core_size);
85909 - mod->core_text_size = mod->core_size;
85910 - break;
85911 - case 1: /* RO: text and ro-data */
85912 - mod->core_size = debug_align(mod->core_size);
85913 - mod->core_ro_size = mod->core_size;
85914 - break;
85915 - case 3: /* whole core */
85916 - mod->core_size = debug_align(mod->core_size);
85917 - break;
85918 - }
85919 }
85920
85921 pr_debug("Init section allocation order:\n");
85922 @@ -2104,23 +2149,13 @@ static void layout_sections(struct module *mod, struct load_info *info)
85923 || s->sh_entsize != ~0UL
85924 || !strstarts(sname, ".init"))
85925 continue;
85926 - s->sh_entsize = (get_offset(mod, &mod->init_size, s, i)
85927 - | INIT_OFFSET_MASK);
85928 + if ((s->sh_flags & SHF_WRITE) || !(s->sh_flags & SHF_ALLOC))
85929 + s->sh_entsize = get_offset(mod, &mod->init_size_rw, s, i);
85930 + else
85931 + s->sh_entsize = get_offset(mod, &mod->init_size_rx, s, i);
85932 + s->sh_entsize |= INIT_OFFSET_MASK;
85933 pr_debug("\t%s\n", sname);
85934 }
85935 - switch (m) {
85936 - case 0: /* executable */
85937 - mod->init_size = debug_align(mod->init_size);
85938 - mod->init_text_size = mod->init_size;
85939 - break;
85940 - case 1: /* RO: text and ro-data */
85941 - mod->init_size = debug_align(mod->init_size);
85942 - mod->init_ro_size = mod->init_size;
85943 - break;
85944 - case 3: /* whole init */
85945 - mod->init_size = debug_align(mod->init_size);
85946 - break;
85947 - }
85948 }
85949 }
85950
85951 @@ -2293,7 +2328,7 @@ static void layout_symtab(struct module *mod, struct load_info *info)
85952
85953 /* Put symbol section at end of init part of module. */
85954 symsect->sh_flags |= SHF_ALLOC;
85955 - symsect->sh_entsize = get_offset(mod, &mod->init_size, symsect,
85956 + symsect->sh_entsize = get_offset(mod, &mod->init_size_rx, symsect,
85957 info->index.sym) | INIT_OFFSET_MASK;
85958 pr_debug("\t%s\n", info->secstrings + symsect->sh_name);
85959
85960 @@ -2310,13 +2345,13 @@ static void layout_symtab(struct module *mod, struct load_info *info)
85961 }
85962
85963 /* Append room for core symbols at end of core part. */
85964 - info->symoffs = ALIGN(mod->core_size, symsect->sh_addralign ?: 1);
85965 - info->stroffs = mod->core_size = info->symoffs + ndst * sizeof(Elf_Sym);
85966 - mod->core_size += strtab_size;
85967 + info->symoffs = ALIGN(mod->core_size_rx, symsect->sh_addralign ?: 1);
85968 + info->stroffs = mod->core_size_rx = info->symoffs + ndst * sizeof(Elf_Sym);
85969 + mod->core_size_rx += strtab_size;
85970
85971 /* Put string table section at end of init part of module. */
85972 strsect->sh_flags |= SHF_ALLOC;
85973 - strsect->sh_entsize = get_offset(mod, &mod->init_size, strsect,
85974 + strsect->sh_entsize = get_offset(mod, &mod->init_size_rx, strsect,
85975 info->index.str) | INIT_OFFSET_MASK;
85976 pr_debug("\t%s\n", info->secstrings + strsect->sh_name);
85977 }
85978 @@ -2334,12 +2369,14 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
85979 /* Make sure we get permanent strtab: don't use info->strtab. */
85980 mod->strtab = (void *)info->sechdrs[info->index.str].sh_addr;
85981
85982 + pax_open_kernel();
85983 +
85984 /* Set types up while we still have access to sections. */
85985 for (i = 0; i < mod->num_symtab; i++)
85986 mod->symtab[i].st_info = elf_type(&mod->symtab[i], info);
85987
85988 - mod->core_symtab = dst = mod->module_core + info->symoffs;
85989 - mod->core_strtab = s = mod->module_core + info->stroffs;
85990 + mod->core_symtab = dst = mod->module_core_rx + info->symoffs;
85991 + mod->core_strtab = s = mod->module_core_rx + info->stroffs;
85992 src = mod->symtab;
85993 for (ndst = i = 0; i < mod->num_symtab; i++) {
85994 if (i == 0 ||
85995 @@ -2351,6 +2388,8 @@ static void add_kallsyms(struct module *mod, const struct load_info *info)
85996 }
85997 }
85998 mod->core_num_syms = ndst;
85999 +
86000 + pax_close_kernel();
86001 }
86002 #else
86003 static inline void layout_symtab(struct module *mod, struct load_info *info)
86004 @@ -2384,17 +2423,33 @@ void * __weak module_alloc(unsigned long size)
86005 return vmalloc_exec(size);
86006 }
86007
86008 -static void *module_alloc_update_bounds(unsigned long size)
86009 +static void *module_alloc_update_bounds_rw(unsigned long size)
86010 {
86011 void *ret = module_alloc(size);
86012
86013 if (ret) {
86014 mutex_lock(&module_mutex);
86015 /* Update module bounds. */
86016 - if ((unsigned long)ret < module_addr_min)
86017 - module_addr_min = (unsigned long)ret;
86018 - if ((unsigned long)ret + size > module_addr_max)
86019 - module_addr_max = (unsigned long)ret + size;
86020 + if ((unsigned long)ret < module_addr_min_rw)
86021 + module_addr_min_rw = (unsigned long)ret;
86022 + if ((unsigned long)ret + size > module_addr_max_rw)
86023 + module_addr_max_rw = (unsigned long)ret + size;
86024 + mutex_unlock(&module_mutex);
86025 + }
86026 + return ret;
86027 +}
86028 +
86029 +static void *module_alloc_update_bounds_rx(unsigned long size)
86030 +{
86031 + void *ret = module_alloc_exec(size);
86032 +
86033 + if (ret) {
86034 + mutex_lock(&module_mutex);
86035 + /* Update module bounds. */
86036 + if ((unsigned long)ret < module_addr_min_rx)
86037 + module_addr_min_rx = (unsigned long)ret;
86038 + if ((unsigned long)ret + size > module_addr_max_rx)
86039 + module_addr_max_rx = (unsigned long)ret + size;
86040 mutex_unlock(&module_mutex);
86041 }
86042 return ret;
86043 @@ -2651,7 +2706,15 @@ static struct module *setup_load_info(struct load_info *info, int flags)
86044 mod = (void *)info->sechdrs[info->index.mod].sh_addr;
86045
86046 if (info->index.sym == 0) {
86047 +#ifdef CONFIG_GRKERNSEC_RANDSTRUCT
86048 + /*
86049 + * avoid potentially printing jibberish on attempted load
86050 + * of a module randomized with a different seed
86051 + */
86052 + pr_warn("module has no symbols (stripped?)\n");
86053 +#else
86054 pr_warn("%s: module has no symbols (stripped?)\n", mod->name);
86055 +#endif
86056 return ERR_PTR(-ENOEXEC);
86057 }
86058
86059 @@ -2667,8 +2730,14 @@ static struct module *setup_load_info(struct load_info *info, int flags)
86060 static int check_modinfo(struct module *mod, struct load_info *info, int flags)
86061 {
86062 const char *modmagic = get_modinfo(info, "vermagic");
86063 + const char *license = get_modinfo(info, "license");
86064 int err;
86065
86066 +#ifdef CONFIG_PAX_KERNEXEC_PLUGIN_METHOD_OR
86067 + if (!license || !license_is_gpl_compatible(license))
86068 + return -ENOEXEC;
86069 +#endif
86070 +
86071 if (flags & MODULE_INIT_IGNORE_VERMAGIC)
86072 modmagic = NULL;
86073
86074 @@ -2693,7 +2762,7 @@ static int check_modinfo(struct module *mod, struct load_info *info, int flags)
86075 }
86076
86077 /* Set up license info based on the info section */
86078 - set_license(mod, get_modinfo(info, "license"));
86079 + set_license(mod, license);
86080
86081 return 0;
86082 }
86083 @@ -2787,7 +2856,7 @@ static int move_module(struct module *mod, struct load_info *info)
86084 void *ptr;
86085
86086 /* Do the allocs. */
86087 - ptr = module_alloc_update_bounds(mod->core_size);
86088 + ptr = module_alloc_update_bounds_rw(mod->core_size_rw);
86089 /*
86090 * The pointer to this block is stored in the module structure
86091 * which is inside the block. Just mark it as not being a
86092 @@ -2797,11 +2866,11 @@ static int move_module(struct module *mod, struct load_info *info)
86093 if (!ptr)
86094 return -ENOMEM;
86095
86096 - memset(ptr, 0, mod->core_size);
86097 - mod->module_core = ptr;
86098 + memset(ptr, 0, mod->core_size_rw);
86099 + mod->module_core_rw = ptr;
86100
86101 - if (mod->init_size) {
86102 - ptr = module_alloc_update_bounds(mod->init_size);
86103 + if (mod->init_size_rw) {
86104 + ptr = module_alloc_update_bounds_rw(mod->init_size_rw);
86105 /*
86106 * The pointer to this block is stored in the module structure
86107 * which is inside the block. This block doesn't need to be
86108 @@ -2810,13 +2879,45 @@ static int move_module(struct module *mod, struct load_info *info)
86109 */
86110 kmemleak_ignore(ptr);
86111 if (!ptr) {
86112 - module_free(mod, mod->module_core);
86113 + module_free(mod, mod->module_core_rw);
86114 return -ENOMEM;
86115 }
86116 - memset(ptr, 0, mod->init_size);
86117 - mod->module_init = ptr;
86118 + memset(ptr, 0, mod->init_size_rw);
86119 + mod->module_init_rw = ptr;
86120 } else
86121 - mod->module_init = NULL;
86122 + mod->module_init_rw = NULL;
86123 +
86124 + ptr = module_alloc_update_bounds_rx(mod->core_size_rx);
86125 + kmemleak_not_leak(ptr);
86126 + if (!ptr) {
86127 + if (mod->module_init_rw)
86128 + module_free(mod, mod->module_init_rw);
86129 + module_free(mod, mod->module_core_rw);
86130 + return -ENOMEM;
86131 + }
86132 +
86133 + pax_open_kernel();
86134 + memset(ptr, 0, mod->core_size_rx);
86135 + pax_close_kernel();
86136 + mod->module_core_rx = ptr;
86137 +
86138 + if (mod->init_size_rx) {
86139 + ptr = module_alloc_update_bounds_rx(mod->init_size_rx);
86140 + kmemleak_ignore(ptr);
86141 + if (!ptr && mod->init_size_rx) {
86142 + module_free_exec(mod, mod->module_core_rx);
86143 + if (mod->module_init_rw)
86144 + module_free(mod, mod->module_init_rw);
86145 + module_free(mod, mod->module_core_rw);
86146 + return -ENOMEM;
86147 + }
86148 +
86149 + pax_open_kernel();
86150 + memset(ptr, 0, mod->init_size_rx);
86151 + pax_close_kernel();
86152 + mod->module_init_rx = ptr;
86153 + } else
86154 + mod->module_init_rx = NULL;
86155
86156 /* Transfer each section which specifies SHF_ALLOC */
86157 pr_debug("final section addresses:\n");
86158 @@ -2827,16 +2928,45 @@ static int move_module(struct module *mod, struct load_info *info)
86159 if (!(shdr->sh_flags & SHF_ALLOC))
86160 continue;
86161
86162 - if (shdr->sh_entsize & INIT_OFFSET_MASK)
86163 - dest = mod->module_init
86164 - + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
86165 - else
86166 - dest = mod->module_core + shdr->sh_entsize;
86167 + if (shdr->sh_entsize & INIT_OFFSET_MASK) {
86168 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
86169 + dest = mod->module_init_rw
86170 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
86171 + else
86172 + dest = mod->module_init_rx
86173 + + (shdr->sh_entsize & ~INIT_OFFSET_MASK);
86174 + } else {
86175 + if ((shdr->sh_flags & SHF_WRITE) || !(shdr->sh_flags & SHF_ALLOC))
86176 + dest = mod->module_core_rw + shdr->sh_entsize;
86177 + else
86178 + dest = mod->module_core_rx + shdr->sh_entsize;
86179 + }
86180 +
86181 + if (shdr->sh_type != SHT_NOBITS) {
86182 +
86183 +#ifdef CONFIG_PAX_KERNEXEC
86184 +#ifdef CONFIG_X86_64
86185 + if ((shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_EXECINSTR))
86186 + set_memory_x((unsigned long)dest, (shdr->sh_size + PAGE_SIZE) >> PAGE_SHIFT);
86187 +#endif
86188 + if (!(shdr->sh_flags & SHF_WRITE) && (shdr->sh_flags & SHF_ALLOC)) {
86189 + pax_open_kernel();
86190 + memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
86191 + pax_close_kernel();
86192 + } else
86193 +#endif
86194
86195 - if (shdr->sh_type != SHT_NOBITS)
86196 memcpy(dest, (void *)shdr->sh_addr, shdr->sh_size);
86197 + }
86198 /* Update sh_addr to point to copy in image. */
86199 - shdr->sh_addr = (unsigned long)dest;
86200 +
86201 +#ifdef CONFIG_PAX_KERNEXEC
86202 + if (shdr->sh_flags & SHF_EXECINSTR)
86203 + shdr->sh_addr = ktva_ktla((unsigned long)dest);
86204 + else
86205 +#endif
86206 +
86207 + shdr->sh_addr = (unsigned long)dest;
86208 pr_debug("\t0x%lx %s\n",
86209 (long)shdr->sh_addr, info->secstrings + shdr->sh_name);
86210 }
86211 @@ -2893,12 +3023,12 @@ static void flush_module_icache(const struct module *mod)
86212 * Do it before processing of module parameters, so the module
86213 * can provide parameter accessor functions of its own.
86214 */
86215 - if (mod->module_init)
86216 - flush_icache_range((unsigned long)mod->module_init,
86217 - (unsigned long)mod->module_init
86218 - + mod->init_size);
86219 - flush_icache_range((unsigned long)mod->module_core,
86220 - (unsigned long)mod->module_core + mod->core_size);
86221 + if (mod->module_init_rx)
86222 + flush_icache_range((unsigned long)mod->module_init_rx,
86223 + (unsigned long)mod->module_init_rx
86224 + + mod->init_size_rx);
86225 + flush_icache_range((unsigned long)mod->module_core_rx,
86226 + (unsigned long)mod->module_core_rx + mod->core_size_rx);
86227
86228 set_fs(old_fs);
86229 }
86230 @@ -2955,8 +3085,10 @@ static struct module *layout_and_allocate(struct load_info *info, int flags)
86231 static void module_deallocate(struct module *mod, struct load_info *info)
86232 {
86233 percpu_modfree(mod);
86234 - module_free(mod, mod->module_init);
86235 - module_free(mod, mod->module_core);
86236 + module_free_exec(mod, mod->module_init_rx);
86237 + module_free_exec(mod, mod->module_core_rx);
86238 + module_free(mod, mod->module_init_rw);
86239 + module_free(mod, mod->module_core_rw);
86240 }
86241
86242 int __weak module_finalize(const Elf_Ehdr *hdr,
86243 @@ -2969,7 +3101,9 @@ int __weak module_finalize(const Elf_Ehdr *hdr,
86244 static int post_relocation(struct module *mod, const struct load_info *info)
86245 {
86246 /* Sort exception table now relocations are done. */
86247 + pax_open_kernel();
86248 sort_extable(mod->extable, mod->extable + mod->num_exentries);
86249 + pax_close_kernel();
86250
86251 /* Copy relocated percpu area over. */
86252 percpu_modcopy(mod, (void *)info->sechdrs[info->index.pcpu].sh_addr,
86253 @@ -3023,16 +3157,16 @@ static int do_init_module(struct module *mod)
86254 MODULE_STATE_COMING, mod);
86255
86256 /* Set RO and NX regions for core */
86257 - set_section_ro_nx(mod->module_core,
86258 - mod->core_text_size,
86259 - mod->core_ro_size,
86260 - mod->core_size);
86261 + set_section_ro_nx(mod->module_core_rx,
86262 + mod->core_size_rx,
86263 + mod->core_size_rx,
86264 + mod->core_size_rx);
86265
86266 /* Set RO and NX regions for init */
86267 - set_section_ro_nx(mod->module_init,
86268 - mod->init_text_size,
86269 - mod->init_ro_size,
86270 - mod->init_size);
86271 + set_section_ro_nx(mod->module_init_rx,
86272 + mod->init_size_rx,
86273 + mod->init_size_rx,
86274 + mod->init_size_rx);
86275
86276 do_mod_ctors(mod);
86277 /* Start the module */
86278 @@ -3093,11 +3227,12 @@ static int do_init_module(struct module *mod)
86279 mod->strtab = mod->core_strtab;
86280 #endif
86281 unset_module_init_ro_nx(mod);
86282 - module_free(mod, mod->module_init);
86283 - mod->module_init = NULL;
86284 - mod->init_size = 0;
86285 - mod->init_ro_size = 0;
86286 - mod->init_text_size = 0;
86287 + module_free(mod, mod->module_init_rw);
86288 + module_free_exec(mod, mod->module_init_rx);
86289 + mod->module_init_rw = NULL;
86290 + mod->module_init_rx = NULL;
86291 + mod->init_size_rw = 0;
86292 + mod->init_size_rx = 0;
86293 mutex_unlock(&module_mutex);
86294 wake_up_all(&module_wq);
86295
86296 @@ -3240,9 +3375,38 @@ static int load_module(struct load_info *info, const char __user *uargs,
86297 if (err)
86298 goto free_unload;
86299
86300 + /* Now copy in args */
86301 + mod->args = strndup_user(uargs, ~0UL >> 1);
86302 + if (IS_ERR(mod->args)) {
86303 + err = PTR_ERR(mod->args);
86304 + goto free_unload;
86305 + }
86306 +
86307 /* Set up MODINFO_ATTR fields */
86308 setup_modinfo(mod, info);
86309
86310 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
86311 + {
86312 + char *p, *p2;
86313 +
86314 + if (strstr(mod->args, "grsec_modharden_netdev")) {
86315 + 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);
86316 + err = -EPERM;
86317 + goto free_modinfo;
86318 + } else if ((p = strstr(mod->args, "grsec_modharden_normal"))) {
86319 + p += sizeof("grsec_modharden_normal") - 1;
86320 + p2 = strstr(p, "_");
86321 + if (p2) {
86322 + *p2 = '\0';
86323 + printk(KERN_ALERT "grsec: denied kernel module auto-load of %.64s by uid %.9s\n", mod->name, p);
86324 + *p2 = '_';
86325 + }
86326 + err = -EPERM;
86327 + goto free_modinfo;
86328 + }
86329 + }
86330 +#endif
86331 +
86332 /* Fix up syms, so that st_value is a pointer to location. */
86333 err = simplify_symbols(mod, info);
86334 if (err < 0)
86335 @@ -3258,13 +3422,6 @@ static int load_module(struct load_info *info, const char __user *uargs,
86336
86337 flush_module_icache(mod);
86338
86339 - /* Now copy in args */
86340 - mod->args = strndup_user(uargs, ~0UL >> 1);
86341 - if (IS_ERR(mod->args)) {
86342 - err = PTR_ERR(mod->args);
86343 - goto free_arch_cleanup;
86344 - }
86345 -
86346 dynamic_debug_setup(info->debug, info->num_debug);
86347
86348 /* Finally it's fully formed, ready to start executing. */
86349 @@ -3299,11 +3456,10 @@ static int load_module(struct load_info *info, const char __user *uargs,
86350 ddebug_cleanup:
86351 dynamic_debug_remove(info->debug);
86352 synchronize_sched();
86353 - kfree(mod->args);
86354 - free_arch_cleanup:
86355 module_arch_cleanup(mod);
86356 free_modinfo:
86357 free_modinfo(mod);
86358 + kfree(mod->args);
86359 free_unload:
86360 module_unload_free(mod);
86361 unlink_mod:
86362 @@ -3386,10 +3542,16 @@ static const char *get_ksymbol(struct module *mod,
86363 unsigned long nextval;
86364
86365 /* At worse, next value is at end of module */
86366 - if (within_module_init(addr, mod))
86367 - nextval = (unsigned long)mod->module_init+mod->init_text_size;
86368 + if (within_module_init_rx(addr, mod))
86369 + nextval = (unsigned long)mod->module_init_rx+mod->init_size_rx;
86370 + else if (within_module_init_rw(addr, mod))
86371 + nextval = (unsigned long)mod->module_init_rw+mod->init_size_rw;
86372 + else if (within_module_core_rx(addr, mod))
86373 + nextval = (unsigned long)mod->module_core_rx+mod->core_size_rx;
86374 + else if (within_module_core_rw(addr, mod))
86375 + nextval = (unsigned long)mod->module_core_rw+mod->core_size_rw;
86376 else
86377 - nextval = (unsigned long)mod->module_core+mod->core_text_size;
86378 + return NULL;
86379
86380 /* Scan for closest preceding symbol, and next symbol. (ELF
86381 starts real symbols at 1). */
86382 @@ -3640,7 +3802,7 @@ static int m_show(struct seq_file *m, void *p)
86383 return 0;
86384
86385 seq_printf(m, "%s %u",
86386 - mod->name, mod->init_size + mod->core_size);
86387 + mod->name, mod->init_size_rx + mod->init_size_rw + mod->core_size_rx + mod->core_size_rw);
86388 print_unload_info(m, mod);
86389
86390 /* Informative for users. */
86391 @@ -3649,7 +3811,7 @@ static int m_show(struct seq_file *m, void *p)
86392 mod->state == MODULE_STATE_COMING ? "Loading":
86393 "Live");
86394 /* Used by oprofile and other similar tools. */
86395 - seq_printf(m, " 0x%pK", mod->module_core);
86396 + seq_printf(m, " 0x%pK 0x%pK", mod->module_core_rx, mod->module_core_rw);
86397
86398 /* Taints info */
86399 if (mod->taints)
86400 @@ -3685,7 +3847,17 @@ static const struct file_operations proc_modules_operations = {
86401
86402 static int __init proc_modules_init(void)
86403 {
86404 +#ifndef CONFIG_GRKERNSEC_HIDESYM
86405 +#ifdef CONFIG_GRKERNSEC_PROC_USER
86406 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
86407 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
86408 + proc_create("modules", S_IRUSR | S_IRGRP, NULL, &proc_modules_operations);
86409 +#else
86410 proc_create("modules", 0, NULL, &proc_modules_operations);
86411 +#endif
86412 +#else
86413 + proc_create("modules", S_IRUSR, NULL, &proc_modules_operations);
86414 +#endif
86415 return 0;
86416 }
86417 module_init(proc_modules_init);
86418 @@ -3746,14 +3918,14 @@ struct module *__module_address(unsigned long addr)
86419 {
86420 struct module *mod;
86421
86422 - if (addr < module_addr_min || addr > module_addr_max)
86423 + if ((addr < module_addr_min_rx || addr > module_addr_max_rx) &&
86424 + (addr < module_addr_min_rw || addr > module_addr_max_rw))
86425 return NULL;
86426
86427 list_for_each_entry_rcu(mod, &modules, list) {
86428 if (mod->state == MODULE_STATE_UNFORMED)
86429 continue;
86430 - if (within_module_core(addr, mod)
86431 - || within_module_init(addr, mod))
86432 + if (within_module_init(addr, mod) || within_module_core(addr, mod))
86433 return mod;
86434 }
86435 return NULL;
86436 @@ -3788,11 +3960,20 @@ bool is_module_text_address(unsigned long addr)
86437 */
86438 struct module *__module_text_address(unsigned long addr)
86439 {
86440 - struct module *mod = __module_address(addr);
86441 + struct module *mod;
86442 +
86443 +#ifdef CONFIG_X86_32
86444 + addr = ktla_ktva(addr);
86445 +#endif
86446 +
86447 + if (addr < module_addr_min_rx || addr > module_addr_max_rx)
86448 + return NULL;
86449 +
86450 + mod = __module_address(addr);
86451 +
86452 if (mod) {
86453 /* Make sure it's within the text section. */
86454 - if (!within(addr, mod->module_init, mod->init_text_size)
86455 - && !within(addr, mod->module_core, mod->core_text_size))
86456 + if (!within_module_init_rx(addr, mod) && !within_module_core_rx(addr, mod))
86457 mod = NULL;
86458 }
86459 return mod;
86460 diff --git a/kernel/notifier.c b/kernel/notifier.c
86461 index 2d5cc4c..d9ea600 100644
86462 --- a/kernel/notifier.c
86463 +++ b/kernel/notifier.c
86464 @@ -5,6 +5,7 @@
86465 #include <linux/rcupdate.h>
86466 #include <linux/vmalloc.h>
86467 #include <linux/reboot.h>
86468 +#include <linux/mm.h>
86469
86470 /*
86471 * Notifier list for kernel code which wants to be called
86472 @@ -24,10 +25,12 @@ static int notifier_chain_register(struct notifier_block **nl,
86473 while ((*nl) != NULL) {
86474 if (n->priority > (*nl)->priority)
86475 break;
86476 - nl = &((*nl)->next);
86477 + nl = (struct notifier_block **)&((*nl)->next);
86478 }
86479 - n->next = *nl;
86480 + pax_open_kernel();
86481 + *(const void **)&n->next = *nl;
86482 rcu_assign_pointer(*nl, n);
86483 + pax_close_kernel();
86484 return 0;
86485 }
86486
86487 @@ -39,10 +42,12 @@ static int notifier_chain_cond_register(struct notifier_block **nl,
86488 return 0;
86489 if (n->priority > (*nl)->priority)
86490 break;
86491 - nl = &((*nl)->next);
86492 + nl = (struct notifier_block **)&((*nl)->next);
86493 }
86494 - n->next = *nl;
86495 + pax_open_kernel();
86496 + *(const void **)&n->next = *nl;
86497 rcu_assign_pointer(*nl, n);
86498 + pax_close_kernel();
86499 return 0;
86500 }
86501
86502 @@ -51,10 +56,12 @@ static int notifier_chain_unregister(struct notifier_block **nl,
86503 {
86504 while ((*nl) != NULL) {
86505 if ((*nl) == n) {
86506 + pax_open_kernel();
86507 rcu_assign_pointer(*nl, n->next);
86508 + pax_close_kernel();
86509 return 0;
86510 }
86511 - nl = &((*nl)->next);
86512 + nl = (struct notifier_block **)&((*nl)->next);
86513 }
86514 return -ENOENT;
86515 }
86516 diff --git a/kernel/padata.c b/kernel/padata.c
86517 index 2abd25d..02c4faa 100644
86518 --- a/kernel/padata.c
86519 +++ b/kernel/padata.c
86520 @@ -54,7 +54,7 @@ static int padata_cpu_hash(struct parallel_data *pd)
86521 * seq_nr mod. number of cpus in use.
86522 */
86523
86524 - seq_nr = atomic_inc_return(&pd->seq_nr);
86525 + seq_nr = atomic_inc_return_unchecked(&pd->seq_nr);
86526 cpu_index = seq_nr % cpumask_weight(pd->cpumask.pcpu);
86527
86528 return padata_index_to_cpu(pd, cpu_index);
86529 @@ -428,7 +428,7 @@ static struct parallel_data *padata_alloc_pd(struct padata_instance *pinst,
86530 padata_init_pqueues(pd);
86531 padata_init_squeues(pd);
86532 setup_timer(&pd->timer, padata_reorder_timer, (unsigned long)pd);
86533 - atomic_set(&pd->seq_nr, -1);
86534 + atomic_set_unchecked(&pd->seq_nr, -1);
86535 atomic_set(&pd->reorder_objects, 0);
86536 atomic_set(&pd->refcnt, 0);
86537 pd->pinst = pinst;
86538 diff --git a/kernel/panic.c b/kernel/panic.c
86539 index c00b4ce..a846117 100644
86540 --- a/kernel/panic.c
86541 +++ b/kernel/panic.c
86542 @@ -407,7 +407,7 @@ static void warn_slowpath_common(const char *file, int line, void *caller,
86543 disable_trace_on_warning();
86544
86545 pr_warn("------------[ cut here ]------------\n");
86546 - pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pS()\n",
86547 + pr_warn("WARNING: CPU: %d PID: %d at %s:%d %pA()\n",
86548 raw_smp_processor_id(), current->pid, file, line, caller);
86549
86550 if (args)
86551 @@ -461,7 +461,8 @@ EXPORT_SYMBOL(warn_slowpath_null);
86552 */
86553 void __stack_chk_fail(void)
86554 {
86555 - panic("stack-protector: Kernel stack is corrupted in: %p\n",
86556 + dump_stack();
86557 + panic("stack-protector: Kernel stack is corrupted in: %pA\n",
86558 __builtin_return_address(0));
86559 }
86560 EXPORT_SYMBOL(__stack_chk_fail);
86561 diff --git a/kernel/pid.c b/kernel/pid.c
86562 index 9b9a266..c20ef80 100644
86563 --- a/kernel/pid.c
86564 +++ b/kernel/pid.c
86565 @@ -33,6 +33,7 @@
86566 #include <linux/rculist.h>
86567 #include <linux/bootmem.h>
86568 #include <linux/hash.h>
86569 +#include <linux/security.h>
86570 #include <linux/pid_namespace.h>
86571 #include <linux/init_task.h>
86572 #include <linux/syscalls.h>
86573 @@ -47,7 +48,7 @@ struct pid init_struct_pid = INIT_STRUCT_PID;
86574
86575 int pid_max = PID_MAX_DEFAULT;
86576
86577 -#define RESERVED_PIDS 300
86578 +#define RESERVED_PIDS 500
86579
86580 int pid_max_min = RESERVED_PIDS + 1;
86581 int pid_max_max = PID_MAX_LIMIT;
86582 @@ -445,10 +446,18 @@ EXPORT_SYMBOL(pid_task);
86583 */
86584 struct task_struct *find_task_by_pid_ns(pid_t nr, struct pid_namespace *ns)
86585 {
86586 + struct task_struct *task;
86587 +
86588 rcu_lockdep_assert(rcu_read_lock_held(),
86589 "find_task_by_pid_ns() needs rcu_read_lock()"
86590 " protection");
86591 - return pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
86592 +
86593 + task = pid_task(find_pid_ns(nr, ns), PIDTYPE_PID);
86594 +
86595 + if (gr_pid_is_chrooted(task))
86596 + return NULL;
86597 +
86598 + return task;
86599 }
86600
86601 struct task_struct *find_task_by_vpid(pid_t vnr)
86602 @@ -456,6 +465,14 @@ struct task_struct *find_task_by_vpid(pid_t vnr)
86603 return find_task_by_pid_ns(vnr, task_active_pid_ns(current));
86604 }
86605
86606 +struct task_struct *find_task_by_vpid_unrestricted(pid_t vnr)
86607 +{
86608 + rcu_lockdep_assert(rcu_read_lock_held(),
86609 + "find_task_by_pid_ns() needs rcu_read_lock()"
86610 + " protection");
86611 + return pid_task(find_pid_ns(vnr, task_active_pid_ns(current)), PIDTYPE_PID);
86612 +}
86613 +
86614 struct pid *get_task_pid(struct task_struct *task, enum pid_type type)
86615 {
86616 struct pid *pid;
86617 diff --git a/kernel/pid_namespace.c b/kernel/pid_namespace.c
86618 index 06c62de..b08cc6c 100644
86619 --- a/kernel/pid_namespace.c
86620 +++ b/kernel/pid_namespace.c
86621 @@ -253,7 +253,7 @@ static int pid_ns_ctl_handler(struct ctl_table *table, int write,
86622 void __user *buffer, size_t *lenp, loff_t *ppos)
86623 {
86624 struct pid_namespace *pid_ns = task_active_pid_ns(current);
86625 - struct ctl_table tmp = *table;
86626 + ctl_table_no_const tmp = *table;
86627
86628 if (write && !ns_capable(pid_ns->user_ns, CAP_SYS_ADMIN))
86629 return -EPERM;
86630 diff --git a/kernel/posix-cpu-timers.c b/kernel/posix-cpu-timers.c
86631 index c7f31aa..2b44977 100644
86632 --- a/kernel/posix-cpu-timers.c
86633 +++ b/kernel/posix-cpu-timers.c
86634 @@ -1521,14 +1521,14 @@ struct k_clock clock_posix_cpu = {
86635
86636 static __init int init_posix_cpu_timers(void)
86637 {
86638 - struct k_clock process = {
86639 + static struct k_clock process = {
86640 .clock_getres = process_cpu_clock_getres,
86641 .clock_get = process_cpu_clock_get,
86642 .timer_create = process_cpu_timer_create,
86643 .nsleep = process_cpu_nsleep,
86644 .nsleep_restart = process_cpu_nsleep_restart,
86645 };
86646 - struct k_clock thread = {
86647 + static struct k_clock thread = {
86648 .clock_getres = thread_cpu_clock_getres,
86649 .clock_get = thread_cpu_clock_get,
86650 .timer_create = thread_cpu_timer_create,
86651 diff --git a/kernel/posix-timers.c b/kernel/posix-timers.c
86652 index 424c2d4..679242f 100644
86653 --- a/kernel/posix-timers.c
86654 +++ b/kernel/posix-timers.c
86655 @@ -43,6 +43,7 @@
86656 #include <linux/hash.h>
86657 #include <linux/posix-clock.h>
86658 #include <linux/posix-timers.h>
86659 +#include <linux/grsecurity.h>
86660 #include <linux/syscalls.h>
86661 #include <linux/wait.h>
86662 #include <linux/workqueue.h>
86663 @@ -122,7 +123,7 @@ static DEFINE_SPINLOCK(hash_lock);
86664 * which we beg off on and pass to do_sys_settimeofday().
86665 */
86666
86667 -static struct k_clock posix_clocks[MAX_CLOCKS];
86668 +static struct k_clock *posix_clocks[MAX_CLOCKS];
86669
86670 /*
86671 * These ones are defined below.
86672 @@ -275,7 +276,7 @@ static int posix_get_tai(clockid_t which_clock, struct timespec *tp)
86673 */
86674 static __init int init_posix_timers(void)
86675 {
86676 - struct k_clock clock_realtime = {
86677 + static struct k_clock clock_realtime = {
86678 .clock_getres = hrtimer_get_res,
86679 .clock_get = posix_clock_realtime_get,
86680 .clock_set = posix_clock_realtime_set,
86681 @@ -287,7 +288,7 @@ static __init int init_posix_timers(void)
86682 .timer_get = common_timer_get,
86683 .timer_del = common_timer_del,
86684 };
86685 - struct k_clock clock_monotonic = {
86686 + static struct k_clock clock_monotonic = {
86687 .clock_getres = hrtimer_get_res,
86688 .clock_get = posix_ktime_get_ts,
86689 .nsleep = common_nsleep,
86690 @@ -297,19 +298,19 @@ static __init int init_posix_timers(void)
86691 .timer_get = common_timer_get,
86692 .timer_del = common_timer_del,
86693 };
86694 - struct k_clock clock_monotonic_raw = {
86695 + static struct k_clock clock_monotonic_raw = {
86696 .clock_getres = hrtimer_get_res,
86697 .clock_get = posix_get_monotonic_raw,
86698 };
86699 - struct k_clock clock_realtime_coarse = {
86700 + static struct k_clock clock_realtime_coarse = {
86701 .clock_getres = posix_get_coarse_res,
86702 .clock_get = posix_get_realtime_coarse,
86703 };
86704 - struct k_clock clock_monotonic_coarse = {
86705 + static struct k_clock clock_monotonic_coarse = {
86706 .clock_getres = posix_get_coarse_res,
86707 .clock_get = posix_get_monotonic_coarse,
86708 };
86709 - struct k_clock clock_tai = {
86710 + static struct k_clock clock_tai = {
86711 .clock_getres = hrtimer_get_res,
86712 .clock_get = posix_get_tai,
86713 .nsleep = common_nsleep,
86714 @@ -319,7 +320,7 @@ static __init int init_posix_timers(void)
86715 .timer_get = common_timer_get,
86716 .timer_del = common_timer_del,
86717 };
86718 - struct k_clock clock_boottime = {
86719 + static struct k_clock clock_boottime = {
86720 .clock_getres = hrtimer_get_res,
86721 .clock_get = posix_get_boottime,
86722 .nsleep = common_nsleep,
86723 @@ -531,7 +532,7 @@ void posix_timers_register_clock(const clockid_t clock_id,
86724 return;
86725 }
86726
86727 - posix_clocks[clock_id] = *new_clock;
86728 + posix_clocks[clock_id] = new_clock;
86729 }
86730 EXPORT_SYMBOL_GPL(posix_timers_register_clock);
86731
86732 @@ -577,9 +578,9 @@ static struct k_clock *clockid_to_kclock(const clockid_t id)
86733 return (id & CLOCKFD_MASK) == CLOCKFD ?
86734 &clock_posix_dynamic : &clock_posix_cpu;
86735
86736 - if (id >= MAX_CLOCKS || !posix_clocks[id].clock_getres)
86737 + if (id >= MAX_CLOCKS || !posix_clocks[id] || !posix_clocks[id]->clock_getres)
86738 return NULL;
86739 - return &posix_clocks[id];
86740 + return posix_clocks[id];
86741 }
86742
86743 static int common_timer_create(struct k_itimer *new_timer)
86744 @@ -597,7 +598,7 @@ SYSCALL_DEFINE3(timer_create, const clockid_t, which_clock,
86745 struct k_clock *kc = clockid_to_kclock(which_clock);
86746 struct k_itimer *new_timer;
86747 int error, new_timer_id;
86748 - sigevent_t event;
86749 + sigevent_t event = { };
86750 int it_id_set = IT_ID_NOT_SET;
86751
86752 if (!kc)
86753 @@ -1011,6 +1012,13 @@ SYSCALL_DEFINE2(clock_settime, const clockid_t, which_clock,
86754 if (copy_from_user(&new_tp, tp, sizeof (*tp)))
86755 return -EFAULT;
86756
86757 + /* only the CLOCK_REALTIME clock can be set, all other clocks
86758 + have their clock_set fptr set to a nosettime dummy function
86759 + CLOCK_REALTIME has a NULL clock_set fptr which causes it to
86760 + call common_clock_set, which calls do_sys_settimeofday, which
86761 + we hook
86762 + */
86763 +
86764 return kc->clock_set(which_clock, &new_tp);
86765 }
86766
86767 diff --git a/kernel/power/Kconfig b/kernel/power/Kconfig
86768 index 2fac9cc..56fef29 100644
86769 --- a/kernel/power/Kconfig
86770 +++ b/kernel/power/Kconfig
86771 @@ -24,6 +24,8 @@ config HIBERNATE_CALLBACKS
86772 config HIBERNATION
86773 bool "Hibernation (aka 'suspend to disk')"
86774 depends on SWAP && ARCH_HIBERNATION_POSSIBLE
86775 + depends on !GRKERNSEC_KMEM
86776 + depends on !PAX_MEMORY_SANITIZE
86777 select HIBERNATE_CALLBACKS
86778 select LZO_COMPRESS
86779 select LZO_DECOMPRESS
86780 diff --git a/kernel/power/process.c b/kernel/power/process.c
86781 index 06ec886..9dba35e 100644
86782 --- a/kernel/power/process.c
86783 +++ b/kernel/power/process.c
86784 @@ -34,6 +34,7 @@ static int try_to_freeze_tasks(bool user_only)
86785 unsigned int elapsed_msecs;
86786 bool wakeup = false;
86787 int sleep_usecs = USEC_PER_MSEC;
86788 + bool timedout = false;
86789
86790 do_gettimeofday(&start);
86791
86792 @@ -44,13 +45,20 @@ static int try_to_freeze_tasks(bool user_only)
86793
86794 while (true) {
86795 todo = 0;
86796 + if (time_after(jiffies, end_time))
86797 + timedout = true;
86798 read_lock(&tasklist_lock);
86799 do_each_thread(g, p) {
86800 if (p == current || !freeze_task(p))
86801 continue;
86802
86803 - if (!freezer_should_skip(p))
86804 + if (!freezer_should_skip(p)) {
86805 todo++;
86806 + if (timedout) {
86807 + printk(KERN_ERR "Task refusing to freeze:\n");
86808 + sched_show_task(p);
86809 + }
86810 + }
86811 } while_each_thread(g, p);
86812 read_unlock(&tasklist_lock);
86813
86814 @@ -59,7 +67,7 @@ static int try_to_freeze_tasks(bool user_only)
86815 todo += wq_busy;
86816 }
86817
86818 - if (!todo || time_after(jiffies, end_time))
86819 + if (!todo || timedout)
86820 break;
86821
86822 if (pm_wakeup_pending()) {
86823 diff --git a/kernel/printk/printk.c b/kernel/printk/printk.c
86824 index be7c86b..c741464 100644
86825 --- a/kernel/printk/printk.c
86826 +++ b/kernel/printk/printk.c
86827 @@ -385,6 +385,11 @@ static int check_syslog_permissions(int type, bool from_file)
86828 if (from_file && type != SYSLOG_ACTION_OPEN)
86829 return 0;
86830
86831 +#ifdef CONFIG_GRKERNSEC_DMESG
86832 + if (grsec_enable_dmesg && !capable(CAP_SYSLOG) && !capable_nolog(CAP_SYS_ADMIN))
86833 + return -EPERM;
86834 +#endif
86835 +
86836 if (syslog_action_restricted(type)) {
86837 if (capable(CAP_SYSLOG))
86838 return 0;
86839 diff --git a/kernel/profile.c b/kernel/profile.c
86840 index 6631e1e..310c266 100644
86841 --- a/kernel/profile.c
86842 +++ b/kernel/profile.c
86843 @@ -37,7 +37,7 @@ struct profile_hit {
86844 #define NR_PROFILE_HIT (PAGE_SIZE/sizeof(struct profile_hit))
86845 #define NR_PROFILE_GRP (NR_PROFILE_HIT/PROFILE_GRPSZ)
86846
86847 -static atomic_t *prof_buffer;
86848 +static atomic_unchecked_t *prof_buffer;
86849 static unsigned long prof_len, prof_shift;
86850
86851 int prof_on __read_mostly;
86852 @@ -260,7 +260,7 @@ static void profile_flip_buffers(void)
86853 hits[i].pc = 0;
86854 continue;
86855 }
86856 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
86857 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
86858 hits[i].hits = hits[i].pc = 0;
86859 }
86860 }
86861 @@ -321,9 +321,9 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
86862 * Add the current hit(s) and flush the write-queue out
86863 * to the global buffer:
86864 */
86865 - atomic_add(nr_hits, &prof_buffer[pc]);
86866 + atomic_add_unchecked(nr_hits, &prof_buffer[pc]);
86867 for (i = 0; i < NR_PROFILE_HIT; ++i) {
86868 - atomic_add(hits[i].hits, &prof_buffer[hits[i].pc]);
86869 + atomic_add_unchecked(hits[i].hits, &prof_buffer[hits[i].pc]);
86870 hits[i].pc = hits[i].hits = 0;
86871 }
86872 out:
86873 @@ -398,7 +398,7 @@ static void do_profile_hits(int type, void *__pc, unsigned int nr_hits)
86874 {
86875 unsigned long pc;
86876 pc = ((unsigned long)__pc - (unsigned long)_stext) >> prof_shift;
86877 - atomic_add(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
86878 + atomic_add_unchecked(nr_hits, &prof_buffer[min(pc, prof_len - 1)]);
86879 }
86880 #endif /* !CONFIG_SMP */
86881
86882 @@ -494,7 +494,7 @@ read_profile(struct file *file, char __user *buf, size_t count, loff_t *ppos)
86883 return -EFAULT;
86884 buf++; p++; count--; read++;
86885 }
86886 - pnt = (char *)prof_buffer + p - sizeof(atomic_t);
86887 + pnt = (char *)prof_buffer + p - sizeof(atomic_unchecked_t);
86888 if (copy_to_user(buf, (void *)pnt, count))
86889 return -EFAULT;
86890 read += count;
86891 @@ -525,7 +525,7 @@ static ssize_t write_profile(struct file *file, const char __user *buf,
86892 }
86893 #endif
86894 profile_discard_flip_buffers();
86895 - memset(prof_buffer, 0, prof_len * sizeof(atomic_t));
86896 + memset(prof_buffer, 0, prof_len * sizeof(atomic_unchecked_t));
86897 return count;
86898 }
86899
86900 diff --git a/kernel/ptrace.c b/kernel/ptrace.c
86901 index 1f4bcb3..99cf7ab 100644
86902 --- a/kernel/ptrace.c
86903 +++ b/kernel/ptrace.c
86904 @@ -327,7 +327,7 @@ static int ptrace_attach(struct task_struct *task, long request,
86905 if (seize)
86906 flags |= PT_SEIZED;
86907 rcu_read_lock();
86908 - if (ns_capable(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
86909 + if (ns_capable_nolog(__task_cred(task)->user_ns, CAP_SYS_PTRACE))
86910 flags |= PT_PTRACE_CAP;
86911 rcu_read_unlock();
86912 task->ptrace = flags;
86913 @@ -538,7 +538,7 @@ int ptrace_readdata(struct task_struct *tsk, unsigned long src, char __user *dst
86914 break;
86915 return -EIO;
86916 }
86917 - if (copy_to_user(dst, buf, retval))
86918 + if (retval > sizeof(buf) || copy_to_user(dst, buf, retval))
86919 return -EFAULT;
86920 copied += retval;
86921 src += retval;
86922 @@ -806,7 +806,7 @@ int ptrace_request(struct task_struct *child, long request,
86923 bool seized = child->ptrace & PT_SEIZED;
86924 int ret = -EIO;
86925 siginfo_t siginfo, *si;
86926 - void __user *datavp = (void __user *) data;
86927 + void __user *datavp = (__force void __user *) data;
86928 unsigned long __user *datalp = datavp;
86929 unsigned long flags;
86930
86931 @@ -1052,14 +1052,21 @@ SYSCALL_DEFINE4(ptrace, long, request, long, pid, unsigned long, addr,
86932 goto out;
86933 }
86934
86935 + if (gr_handle_ptrace(child, request)) {
86936 + ret = -EPERM;
86937 + goto out_put_task_struct;
86938 + }
86939 +
86940 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
86941 ret = ptrace_attach(child, request, addr, data);
86942 /*
86943 * Some architectures need to do book-keeping after
86944 * a ptrace attach.
86945 */
86946 - if (!ret)
86947 + if (!ret) {
86948 arch_ptrace_attach(child);
86949 + gr_audit_ptrace(child);
86950 + }
86951 goto out_put_task_struct;
86952 }
86953
86954 @@ -1087,7 +1094,7 @@ int generic_ptrace_peekdata(struct task_struct *tsk, unsigned long addr,
86955 copied = access_process_vm(tsk, addr, &tmp, sizeof(tmp), 0);
86956 if (copied != sizeof(tmp))
86957 return -EIO;
86958 - return put_user(tmp, (unsigned long __user *)data);
86959 + return put_user(tmp, (__force unsigned long __user *)data);
86960 }
86961
86962 int generic_ptrace_pokedata(struct task_struct *tsk, unsigned long addr,
86963 @@ -1181,7 +1188,7 @@ int compat_ptrace_request(struct task_struct *child, compat_long_t request,
86964 }
86965
86966 asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
86967 - compat_long_t addr, compat_long_t data)
86968 + compat_ulong_t addr, compat_ulong_t data)
86969 {
86970 struct task_struct *child;
86971 long ret;
86972 @@ -1197,14 +1204,21 @@ asmlinkage long compat_sys_ptrace(compat_long_t request, compat_long_t pid,
86973 goto out;
86974 }
86975
86976 + if (gr_handle_ptrace(child, request)) {
86977 + ret = -EPERM;
86978 + goto out_put_task_struct;
86979 + }
86980 +
86981 if (request == PTRACE_ATTACH || request == PTRACE_SEIZE) {
86982 ret = ptrace_attach(child, request, addr, data);
86983 /*
86984 * Some architectures need to do book-keeping after
86985 * a ptrace attach.
86986 */
86987 - if (!ret)
86988 + if (!ret) {
86989 arch_ptrace_attach(child);
86990 + gr_audit_ptrace(child);
86991 + }
86992 goto out_put_task_struct;
86993 }
86994
86995 diff --git a/kernel/rcu/srcu.c b/kernel/rcu/srcu.c
86996 index 01d5ccb..cdcbee6 100644
86997 --- a/kernel/rcu/srcu.c
86998 +++ b/kernel/rcu/srcu.c
86999 @@ -300,9 +300,9 @@ int __srcu_read_lock(struct srcu_struct *sp)
87000
87001 idx = ACCESS_ONCE(sp->completed) & 0x1;
87002 preempt_disable();
87003 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
87004 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->c[idx]) += 1;
87005 smp_mb(); /* B */ /* Avoid leaking the critical section. */
87006 - ACCESS_ONCE(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
87007 + ACCESS_ONCE_RW(this_cpu_ptr(sp->per_cpu_ref)->seq[idx]) += 1;
87008 preempt_enable();
87009 return idx;
87010 }
87011 diff --git a/kernel/rcu/tiny.c b/kernel/rcu/tiny.c
87012 index 1254f31..16258dc 100644
87013 --- a/kernel/rcu/tiny.c
87014 +++ b/kernel/rcu/tiny.c
87015 @@ -46,7 +46,7 @@
87016 /* Forward declarations for tiny_plugin.h. */
87017 struct rcu_ctrlblk;
87018 static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp);
87019 -static void rcu_process_callbacks(struct softirq_action *unused);
87020 +static void rcu_process_callbacks(void);
87021 static void __call_rcu(struct rcu_head *head,
87022 void (*func)(struct rcu_head *rcu),
87023 struct rcu_ctrlblk *rcp);
87024 @@ -312,7 +312,7 @@ static void __rcu_process_callbacks(struct rcu_ctrlblk *rcp)
87025 false));
87026 }
87027
87028 -static void rcu_process_callbacks(struct softirq_action *unused)
87029 +static __latent_entropy void rcu_process_callbacks(void)
87030 {
87031 __rcu_process_callbacks(&rcu_sched_ctrlblk);
87032 __rcu_process_callbacks(&rcu_bh_ctrlblk);
87033 diff --git a/kernel/rcu/torture.c b/kernel/rcu/torture.c
87034 index 3929cd4..421624d 100644
87035 --- a/kernel/rcu/torture.c
87036 +++ b/kernel/rcu/torture.c
87037 @@ -176,12 +176,12 @@ static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_count) =
87038 { 0 };
87039 static DEFINE_PER_CPU(long [RCU_TORTURE_PIPE_LEN + 1], rcu_torture_batch) =
87040 { 0 };
87041 -static atomic_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
87042 -static atomic_t n_rcu_torture_alloc;
87043 -static atomic_t n_rcu_torture_alloc_fail;
87044 -static atomic_t n_rcu_torture_free;
87045 -static atomic_t n_rcu_torture_mberror;
87046 -static atomic_t n_rcu_torture_error;
87047 +static atomic_unchecked_t rcu_torture_wcount[RCU_TORTURE_PIPE_LEN + 1];
87048 +static atomic_unchecked_t n_rcu_torture_alloc;
87049 +static atomic_unchecked_t n_rcu_torture_alloc_fail;
87050 +static atomic_unchecked_t n_rcu_torture_free;
87051 +static atomic_unchecked_t n_rcu_torture_mberror;
87052 +static atomic_unchecked_t n_rcu_torture_error;
87053 static long n_rcu_torture_barrier_error;
87054 static long n_rcu_torture_boost_ktrerror;
87055 static long n_rcu_torture_boost_rterror;
87056 @@ -299,11 +299,11 @@ rcu_torture_alloc(void)
87057
87058 spin_lock_bh(&rcu_torture_lock);
87059 if (list_empty(&rcu_torture_freelist)) {
87060 - atomic_inc(&n_rcu_torture_alloc_fail);
87061 + atomic_inc_unchecked(&n_rcu_torture_alloc_fail);
87062 spin_unlock_bh(&rcu_torture_lock);
87063 return NULL;
87064 }
87065 - atomic_inc(&n_rcu_torture_alloc);
87066 + atomic_inc_unchecked(&n_rcu_torture_alloc);
87067 p = rcu_torture_freelist.next;
87068 list_del_init(p);
87069 spin_unlock_bh(&rcu_torture_lock);
87070 @@ -316,7 +316,7 @@ rcu_torture_alloc(void)
87071 static void
87072 rcu_torture_free(struct rcu_torture *p)
87073 {
87074 - atomic_inc(&n_rcu_torture_free);
87075 + atomic_inc_unchecked(&n_rcu_torture_free);
87076 spin_lock_bh(&rcu_torture_lock);
87077 list_add_tail(&p->rtort_free, &rcu_torture_freelist);
87078 spin_unlock_bh(&rcu_torture_lock);
87079 @@ -437,7 +437,7 @@ rcu_torture_cb(struct rcu_head *p)
87080 i = rp->rtort_pipe_count;
87081 if (i > RCU_TORTURE_PIPE_LEN)
87082 i = RCU_TORTURE_PIPE_LEN;
87083 - atomic_inc(&rcu_torture_wcount[i]);
87084 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
87085 if (++rp->rtort_pipe_count >= RCU_TORTURE_PIPE_LEN) {
87086 rp->rtort_mbtest = 0;
87087 rcu_torture_free(rp);
87088 @@ -827,7 +827,7 @@ rcu_torture_writer(void *arg)
87089 i = old_rp->rtort_pipe_count;
87090 if (i > RCU_TORTURE_PIPE_LEN)
87091 i = RCU_TORTURE_PIPE_LEN;
87092 - atomic_inc(&rcu_torture_wcount[i]);
87093 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
87094 old_rp->rtort_pipe_count++;
87095 if (gp_normal == gp_exp)
87096 exp = !!(rcu_random(&rand) & 0x80);
87097 @@ -845,7 +845,7 @@ rcu_torture_writer(void *arg)
87098 i = rp->rtort_pipe_count;
87099 if (i > RCU_TORTURE_PIPE_LEN)
87100 i = RCU_TORTURE_PIPE_LEN;
87101 - atomic_inc(&rcu_torture_wcount[i]);
87102 + atomic_inc_unchecked(&rcu_torture_wcount[i]);
87103 if (++rp->rtort_pipe_count >=
87104 RCU_TORTURE_PIPE_LEN) {
87105 rp->rtort_mbtest = 0;
87106 @@ -944,7 +944,7 @@ static void rcu_torture_timer(unsigned long unused)
87107 return;
87108 }
87109 if (p->rtort_mbtest == 0)
87110 - atomic_inc(&n_rcu_torture_mberror);
87111 + atomic_inc_unchecked(&n_rcu_torture_mberror);
87112 spin_lock(&rand_lock);
87113 cur_ops->read_delay(&rand);
87114 n_rcu_torture_timers++;
87115 @@ -1014,7 +1014,7 @@ rcu_torture_reader(void *arg)
87116 continue;
87117 }
87118 if (p->rtort_mbtest == 0)
87119 - atomic_inc(&n_rcu_torture_mberror);
87120 + atomic_inc_unchecked(&n_rcu_torture_mberror);
87121 cur_ops->read_delay(&rand);
87122 preempt_disable();
87123 pipe_count = p->rtort_pipe_count;
87124 @@ -1077,11 +1077,11 @@ rcu_torture_printk(char *page)
87125 rcu_torture_current,
87126 rcu_torture_current_version,
87127 list_empty(&rcu_torture_freelist),
87128 - atomic_read(&n_rcu_torture_alloc),
87129 - atomic_read(&n_rcu_torture_alloc_fail),
87130 - atomic_read(&n_rcu_torture_free));
87131 + atomic_read_unchecked(&n_rcu_torture_alloc),
87132 + atomic_read_unchecked(&n_rcu_torture_alloc_fail),
87133 + atomic_read_unchecked(&n_rcu_torture_free));
87134 cnt += sprintf(&page[cnt], "rtmbe: %d rtbke: %ld rtbre: %ld ",
87135 - atomic_read(&n_rcu_torture_mberror),
87136 + atomic_read_unchecked(&n_rcu_torture_mberror),
87137 n_rcu_torture_boost_ktrerror,
87138 n_rcu_torture_boost_rterror);
87139 cnt += sprintf(&page[cnt], "rtbf: %ld rtb: %ld nt: %ld ",
87140 @@ -1100,14 +1100,14 @@ rcu_torture_printk(char *page)
87141 n_barrier_attempts,
87142 n_rcu_torture_barrier_error);
87143 cnt += sprintf(&page[cnt], "\n%s%s ", torture_type, TORTURE_FLAG);
87144 - if (atomic_read(&n_rcu_torture_mberror) != 0 ||
87145 + if (atomic_read_unchecked(&n_rcu_torture_mberror) != 0 ||
87146 n_rcu_torture_barrier_error != 0 ||
87147 n_rcu_torture_boost_ktrerror != 0 ||
87148 n_rcu_torture_boost_rterror != 0 ||
87149 n_rcu_torture_boost_failure != 0 ||
87150 i > 1) {
87151 cnt += sprintf(&page[cnt], "!!! ");
87152 - atomic_inc(&n_rcu_torture_error);
87153 + atomic_inc_unchecked(&n_rcu_torture_error);
87154 WARN_ON_ONCE(1);
87155 }
87156 cnt += sprintf(&page[cnt], "Reader Pipe: ");
87157 @@ -1121,7 +1121,7 @@ rcu_torture_printk(char *page)
87158 cnt += sprintf(&page[cnt], "Free-Block Circulation: ");
87159 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
87160 cnt += sprintf(&page[cnt], " %d",
87161 - atomic_read(&rcu_torture_wcount[i]));
87162 + atomic_read_unchecked(&rcu_torture_wcount[i]));
87163 }
87164 cnt += sprintf(&page[cnt], "\n");
87165 if (cur_ops->stats)
87166 @@ -1836,7 +1836,7 @@ rcu_torture_cleanup(void)
87167
87168 rcu_torture_stats_print(); /* -After- the stats thread is stopped! */
87169
87170 - if (atomic_read(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
87171 + if (atomic_read_unchecked(&n_rcu_torture_error) || n_rcu_torture_barrier_error)
87172 rcu_torture_print_module_parms(cur_ops, "End of test: FAILURE");
87173 else if (n_online_successes != n_online_attempts ||
87174 n_offline_successes != n_offline_attempts)
87175 @@ -1958,18 +1958,18 @@ rcu_torture_init(void)
87176
87177 rcu_torture_current = NULL;
87178 rcu_torture_current_version = 0;
87179 - atomic_set(&n_rcu_torture_alloc, 0);
87180 - atomic_set(&n_rcu_torture_alloc_fail, 0);
87181 - atomic_set(&n_rcu_torture_free, 0);
87182 - atomic_set(&n_rcu_torture_mberror, 0);
87183 - atomic_set(&n_rcu_torture_error, 0);
87184 + atomic_set_unchecked(&n_rcu_torture_alloc, 0);
87185 + atomic_set_unchecked(&n_rcu_torture_alloc_fail, 0);
87186 + atomic_set_unchecked(&n_rcu_torture_free, 0);
87187 + atomic_set_unchecked(&n_rcu_torture_mberror, 0);
87188 + atomic_set_unchecked(&n_rcu_torture_error, 0);
87189 n_rcu_torture_barrier_error = 0;
87190 n_rcu_torture_boost_ktrerror = 0;
87191 n_rcu_torture_boost_rterror = 0;
87192 n_rcu_torture_boost_failure = 0;
87193 n_rcu_torture_boosts = 0;
87194 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++)
87195 - atomic_set(&rcu_torture_wcount[i], 0);
87196 + atomic_set_unchecked(&rcu_torture_wcount[i], 0);
87197 for_each_possible_cpu(cpu) {
87198 for (i = 0; i < RCU_TORTURE_PIPE_LEN + 1; i++) {
87199 per_cpu(rcu_torture_count, cpu)[i] = 0;
87200 diff --git a/kernel/rcu/tree.c b/kernel/rcu/tree.c
87201 index dd08198..5ccccbe 100644
87202 --- a/kernel/rcu/tree.c
87203 +++ b/kernel/rcu/tree.c
87204 @@ -383,9 +383,9 @@ static void rcu_eqs_enter_common(struct rcu_dynticks *rdtp, long long oldval,
87205 rcu_prepare_for_idle(smp_processor_id());
87206 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
87207 smp_mb__before_atomic_inc(); /* See above. */
87208 - atomic_inc(&rdtp->dynticks);
87209 + atomic_inc_unchecked(&rdtp->dynticks);
87210 smp_mb__after_atomic_inc(); /* Force ordering with next sojourn. */
87211 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
87212 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
87213
87214 /*
87215 * It is illegal to enter an extended quiescent state while
87216 @@ -502,10 +502,10 @@ static void rcu_eqs_exit_common(struct rcu_dynticks *rdtp, long long oldval,
87217 int user)
87218 {
87219 smp_mb__before_atomic_inc(); /* Force ordering w/previous sojourn. */
87220 - atomic_inc(&rdtp->dynticks);
87221 + atomic_inc_unchecked(&rdtp->dynticks);
87222 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
87223 smp_mb__after_atomic_inc(); /* See above. */
87224 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
87225 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
87226 rcu_cleanup_after_idle(smp_processor_id());
87227 trace_rcu_dyntick(TPS("End"), oldval, rdtp->dynticks_nesting);
87228 if (!user && !is_idle_task(current)) {
87229 @@ -625,14 +625,14 @@ void rcu_nmi_enter(void)
87230 struct rcu_dynticks *rdtp = this_cpu_ptr(&rcu_dynticks);
87231
87232 if (rdtp->dynticks_nmi_nesting == 0 &&
87233 - (atomic_read(&rdtp->dynticks) & 0x1))
87234 + (atomic_read_unchecked(&rdtp->dynticks) & 0x1))
87235 return;
87236 rdtp->dynticks_nmi_nesting++;
87237 smp_mb__before_atomic_inc(); /* Force delay from prior write. */
87238 - atomic_inc(&rdtp->dynticks);
87239 + atomic_inc_unchecked(&rdtp->dynticks);
87240 /* CPUs seeing atomic_inc() must see later RCU read-side crit sects */
87241 smp_mb__after_atomic_inc(); /* See above. */
87242 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks) & 0x1));
87243 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks) & 0x1));
87244 }
87245
87246 /**
87247 @@ -651,9 +651,9 @@ void rcu_nmi_exit(void)
87248 return;
87249 /* CPUs seeing atomic_inc() must see prior RCU read-side crit sects */
87250 smp_mb__before_atomic_inc(); /* See above. */
87251 - atomic_inc(&rdtp->dynticks);
87252 + atomic_inc_unchecked(&rdtp->dynticks);
87253 smp_mb__after_atomic_inc(); /* Force delay to next write. */
87254 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks) & 0x1);
87255 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks) & 0x1);
87256 }
87257
87258 /**
87259 @@ -666,7 +666,7 @@ void rcu_nmi_exit(void)
87260 */
87261 bool notrace __rcu_is_watching(void)
87262 {
87263 - return atomic_read(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
87264 + return atomic_read_unchecked(this_cpu_ptr(&rcu_dynticks.dynticks)) & 0x1;
87265 }
87266
87267 /**
87268 @@ -749,7 +749,7 @@ static int rcu_is_cpu_rrupt_from_idle(void)
87269 static int dyntick_save_progress_counter(struct rcu_data *rdp,
87270 bool *isidle, unsigned long *maxj)
87271 {
87272 - rdp->dynticks_snap = atomic_add_return(0, &rdp->dynticks->dynticks);
87273 + rdp->dynticks_snap = atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
87274 rcu_sysidle_check_cpu(rdp, isidle, maxj);
87275 return (rdp->dynticks_snap & 0x1) == 0;
87276 }
87277 @@ -766,7 +766,7 @@ static int rcu_implicit_dynticks_qs(struct rcu_data *rdp,
87278 unsigned int curr;
87279 unsigned int snap;
87280
87281 - curr = (unsigned int)atomic_add_return(0, &rdp->dynticks->dynticks);
87282 + curr = (unsigned int)atomic_add_return_unchecked(0, &rdp->dynticks->dynticks);
87283 snap = (unsigned int)rdp->dynticks_snap;
87284
87285 /*
87286 @@ -1412,9 +1412,9 @@ static int rcu_gp_init(struct rcu_state *rsp)
87287 rdp = this_cpu_ptr(rsp->rda);
87288 rcu_preempt_check_blocked_tasks(rnp);
87289 rnp->qsmask = rnp->qsmaskinit;
87290 - ACCESS_ONCE(rnp->gpnum) = rsp->gpnum;
87291 + ACCESS_ONCE_RW(rnp->gpnum) = rsp->gpnum;
87292 WARN_ON_ONCE(rnp->completed != rsp->completed);
87293 - ACCESS_ONCE(rnp->completed) = rsp->completed;
87294 + ACCESS_ONCE_RW(rnp->completed) = rsp->completed;
87295 if (rnp == rdp->mynode)
87296 __note_gp_changes(rsp, rnp, rdp);
87297 rcu_preempt_boost_start_gp(rnp);
87298 @@ -1505,7 +1505,7 @@ static void rcu_gp_cleanup(struct rcu_state *rsp)
87299 */
87300 rcu_for_each_node_breadth_first(rsp, rnp) {
87301 raw_spin_lock_irq(&rnp->lock);
87302 - ACCESS_ONCE(rnp->completed) = rsp->gpnum;
87303 + ACCESS_ONCE_RW(rnp->completed) = rsp->gpnum;
87304 rdp = this_cpu_ptr(rsp->rda);
87305 if (rnp == rdp->mynode)
87306 __note_gp_changes(rsp, rnp, rdp);
87307 @@ -1865,7 +1865,7 @@ rcu_send_cbs_to_orphanage(int cpu, struct rcu_state *rsp,
87308 rsp->qlen += rdp->qlen;
87309 rdp->n_cbs_orphaned += rdp->qlen;
87310 rdp->qlen_lazy = 0;
87311 - ACCESS_ONCE(rdp->qlen) = 0;
87312 + ACCESS_ONCE_RW(rdp->qlen) = 0;
87313 }
87314
87315 /*
87316 @@ -2111,7 +2111,7 @@ static void rcu_do_batch(struct rcu_state *rsp, struct rcu_data *rdp)
87317 }
87318 smp_mb(); /* List handling before counting for rcu_barrier(). */
87319 rdp->qlen_lazy -= count_lazy;
87320 - ACCESS_ONCE(rdp->qlen) -= count;
87321 + ACCESS_ONCE_RW(rdp->qlen) -= count;
87322 rdp->n_cbs_invoked += count;
87323
87324 /* Reinstate batch limit if we have worked down the excess. */
87325 @@ -2308,7 +2308,7 @@ __rcu_process_callbacks(struct rcu_state *rsp)
87326 /*
87327 * Do RCU core processing for the current CPU.
87328 */
87329 -static void rcu_process_callbacks(struct softirq_action *unused)
87330 +static void rcu_process_callbacks(void)
87331 {
87332 struct rcu_state *rsp;
87333
87334 @@ -2415,7 +2415,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
87335 WARN_ON_ONCE((unsigned long)head & 0x3); /* Misaligned rcu_head! */
87336 if (debug_rcu_head_queue(head)) {
87337 /* Probable double call_rcu(), so leak the callback. */
87338 - ACCESS_ONCE(head->func) = rcu_leak_callback;
87339 + ACCESS_ONCE_RW(head->func) = rcu_leak_callback;
87340 WARN_ONCE(1, "__call_rcu(): Leaked duplicate callback\n");
87341 return;
87342 }
87343 @@ -2443,7 +2443,7 @@ __call_rcu(struct rcu_head *head, void (*func)(struct rcu_head *rcu),
87344 local_irq_restore(flags);
87345 return;
87346 }
87347 - ACCESS_ONCE(rdp->qlen)++;
87348 + ACCESS_ONCE_RW(rdp->qlen)++;
87349 if (lazy)
87350 rdp->qlen_lazy++;
87351 else
87352 @@ -2652,11 +2652,11 @@ void synchronize_sched_expedited(void)
87353 * counter wrap on a 32-bit system. Quite a few more CPUs would of
87354 * course be required on a 64-bit system.
87355 */
87356 - if (ULONG_CMP_GE((ulong)atomic_long_read(&rsp->expedited_start),
87357 + if (ULONG_CMP_GE((ulong)atomic_long_read_unchecked(&rsp->expedited_start),
87358 (ulong)atomic_long_read(&rsp->expedited_done) +
87359 ULONG_MAX / 8)) {
87360 synchronize_sched();
87361 - atomic_long_inc(&rsp->expedited_wrap);
87362 + atomic_long_inc_unchecked(&rsp->expedited_wrap);
87363 return;
87364 }
87365
87366 @@ -2664,7 +2664,7 @@ void synchronize_sched_expedited(void)
87367 * Take a ticket. Note that atomic_inc_return() implies a
87368 * full memory barrier.
87369 */
87370 - snap = atomic_long_inc_return(&rsp->expedited_start);
87371 + snap = atomic_long_inc_return_unchecked(&rsp->expedited_start);
87372 firstsnap = snap;
87373 get_online_cpus();
87374 WARN_ON_ONCE(cpu_is_offline(raw_smp_processor_id()));
87375 @@ -2677,14 +2677,14 @@ void synchronize_sched_expedited(void)
87376 synchronize_sched_expedited_cpu_stop,
87377 NULL) == -EAGAIN) {
87378 put_online_cpus();
87379 - atomic_long_inc(&rsp->expedited_tryfail);
87380 + atomic_long_inc_unchecked(&rsp->expedited_tryfail);
87381
87382 /* Check to see if someone else did our work for us. */
87383 s = atomic_long_read(&rsp->expedited_done);
87384 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
87385 /* ensure test happens before caller kfree */
87386 smp_mb__before_atomic_inc(); /* ^^^ */
87387 - atomic_long_inc(&rsp->expedited_workdone1);
87388 + atomic_long_inc_unchecked(&rsp->expedited_workdone1);
87389 return;
87390 }
87391
87392 @@ -2693,7 +2693,7 @@ void synchronize_sched_expedited(void)
87393 udelay(trycount * num_online_cpus());
87394 } else {
87395 wait_rcu_gp(call_rcu_sched);
87396 - atomic_long_inc(&rsp->expedited_normal);
87397 + atomic_long_inc_unchecked(&rsp->expedited_normal);
87398 return;
87399 }
87400
87401 @@ -2702,7 +2702,7 @@ void synchronize_sched_expedited(void)
87402 if (ULONG_CMP_GE((ulong)s, (ulong)firstsnap)) {
87403 /* ensure test happens before caller kfree */
87404 smp_mb__before_atomic_inc(); /* ^^^ */
87405 - atomic_long_inc(&rsp->expedited_workdone2);
87406 + atomic_long_inc_unchecked(&rsp->expedited_workdone2);
87407 return;
87408 }
87409
87410 @@ -2714,10 +2714,10 @@ void synchronize_sched_expedited(void)
87411 * period works for us.
87412 */
87413 get_online_cpus();
87414 - snap = atomic_long_read(&rsp->expedited_start);
87415 + snap = atomic_long_read_unchecked(&rsp->expedited_start);
87416 smp_mb(); /* ensure read is before try_stop_cpus(). */
87417 }
87418 - atomic_long_inc(&rsp->expedited_stoppedcpus);
87419 + atomic_long_inc_unchecked(&rsp->expedited_stoppedcpus);
87420
87421 /*
87422 * Everyone up to our most recent fetch is covered by our grace
87423 @@ -2726,16 +2726,16 @@ void synchronize_sched_expedited(void)
87424 * than we did already did their update.
87425 */
87426 do {
87427 - atomic_long_inc(&rsp->expedited_done_tries);
87428 + atomic_long_inc_unchecked(&rsp->expedited_done_tries);
87429 s = atomic_long_read(&rsp->expedited_done);
87430 if (ULONG_CMP_GE((ulong)s, (ulong)snap)) {
87431 /* ensure test happens before caller kfree */
87432 smp_mb__before_atomic_inc(); /* ^^^ */
87433 - atomic_long_inc(&rsp->expedited_done_lost);
87434 + atomic_long_inc_unchecked(&rsp->expedited_done_lost);
87435 break;
87436 }
87437 } while (atomic_long_cmpxchg(&rsp->expedited_done, s, snap) != s);
87438 - atomic_long_inc(&rsp->expedited_done_exit);
87439 + atomic_long_inc_unchecked(&rsp->expedited_done_exit);
87440
87441 put_online_cpus();
87442 }
87443 @@ -2931,7 +2931,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
87444 * ACCESS_ONCE() to prevent the compiler from speculating
87445 * the increment to precede the early-exit check.
87446 */
87447 - ACCESS_ONCE(rsp->n_barrier_done)++;
87448 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
87449 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 1);
87450 _rcu_barrier_trace(rsp, "Inc1", -1, rsp->n_barrier_done);
87451 smp_mb(); /* Order ->n_barrier_done increment with below mechanism. */
87452 @@ -2981,7 +2981,7 @@ static void _rcu_barrier(struct rcu_state *rsp)
87453
87454 /* Increment ->n_barrier_done to prevent duplicate work. */
87455 smp_mb(); /* Keep increment after above mechanism. */
87456 - ACCESS_ONCE(rsp->n_barrier_done)++;
87457 + ACCESS_ONCE_RW(rsp->n_barrier_done)++;
87458 WARN_ON_ONCE((rsp->n_barrier_done & 0x1) != 0);
87459 _rcu_barrier_trace(rsp, "Inc2", -1, rsp->n_barrier_done);
87460 smp_mb(); /* Keep increment before caller's subsequent code. */
87461 @@ -3026,10 +3026,10 @@ rcu_boot_init_percpu_data(int cpu, struct rcu_state *rsp)
87462 rdp->grpmask = 1UL << (cpu - rdp->mynode->grplo);
87463 init_callback_list(rdp);
87464 rdp->qlen_lazy = 0;
87465 - ACCESS_ONCE(rdp->qlen) = 0;
87466 + ACCESS_ONCE_RW(rdp->qlen) = 0;
87467 rdp->dynticks = &per_cpu(rcu_dynticks, cpu);
87468 WARN_ON_ONCE(rdp->dynticks->dynticks_nesting != DYNTICK_TASK_EXIT_IDLE);
87469 - WARN_ON_ONCE(atomic_read(&rdp->dynticks->dynticks) != 1);
87470 + WARN_ON_ONCE(atomic_read_unchecked(&rdp->dynticks->dynticks) != 1);
87471 rdp->cpu = cpu;
87472 rdp->rsp = rsp;
87473 rcu_boot_init_nocb_percpu_data(rdp);
87474 @@ -3063,8 +3063,8 @@ rcu_init_percpu_data(int cpu, struct rcu_state *rsp, int preemptible)
87475 init_callback_list(rdp); /* Re-enable callbacks on this CPU. */
87476 rdp->dynticks->dynticks_nesting = DYNTICK_TASK_EXIT_IDLE;
87477 rcu_sysidle_init_percpu_data(rdp->dynticks);
87478 - atomic_set(&rdp->dynticks->dynticks,
87479 - (atomic_read(&rdp->dynticks->dynticks) & ~0x1) + 1);
87480 + atomic_set_unchecked(&rdp->dynticks->dynticks,
87481 + (atomic_read_unchecked(&rdp->dynticks->dynticks) & ~0x1) + 1);
87482 raw_spin_unlock(&rnp->lock); /* irqs remain disabled. */
87483
87484 /* Add CPU to rcu_node bitmasks. */
87485 diff --git a/kernel/rcu/tree.h b/kernel/rcu/tree.h
87486 index 52be957..365ded3 100644
87487 --- a/kernel/rcu/tree.h
87488 +++ b/kernel/rcu/tree.h
87489 @@ -87,11 +87,11 @@ struct rcu_dynticks {
87490 long long dynticks_nesting; /* Track irq/process nesting level. */
87491 /* Process level is worth LLONG_MAX/2. */
87492 int dynticks_nmi_nesting; /* Track NMI nesting level. */
87493 - atomic_t dynticks; /* Even value for idle, else odd. */
87494 + atomic_unchecked_t dynticks;/* Even value for idle, else odd. */
87495 #ifdef CONFIG_NO_HZ_FULL_SYSIDLE
87496 long long dynticks_idle_nesting;
87497 /* irq/process nesting level from idle. */
87498 - atomic_t dynticks_idle; /* Even value for idle, else odd. */
87499 + atomic_unchecked_t dynticks_idle;/* Even value for idle, else odd. */
87500 /* "Idle" excludes userspace execution. */
87501 unsigned long dynticks_idle_jiffies;
87502 /* End of last non-NMI non-idle period. */
87503 @@ -429,17 +429,17 @@ struct rcu_state {
87504 /* _rcu_barrier(). */
87505 /* End of fields guarded by barrier_mutex. */
87506
87507 - atomic_long_t expedited_start; /* Starting ticket. */
87508 - atomic_long_t expedited_done; /* Done ticket. */
87509 - atomic_long_t expedited_wrap; /* # near-wrap incidents. */
87510 - atomic_long_t expedited_tryfail; /* # acquisition failures. */
87511 - atomic_long_t expedited_workdone1; /* # done by others #1. */
87512 - atomic_long_t expedited_workdone2; /* # done by others #2. */
87513 - atomic_long_t expedited_normal; /* # fallbacks to normal. */
87514 - atomic_long_t expedited_stoppedcpus; /* # successful stop_cpus. */
87515 - atomic_long_t expedited_done_tries; /* # tries to update _done. */
87516 - atomic_long_t expedited_done_lost; /* # times beaten to _done. */
87517 - atomic_long_t expedited_done_exit; /* # times exited _done loop. */
87518 + atomic_long_unchecked_t expedited_start; /* Starting ticket. */
87519 + atomic_long_t expedited_done; /* Done ticket. */
87520 + atomic_long_unchecked_t expedited_wrap; /* # near-wrap incidents. */
87521 + atomic_long_unchecked_t expedited_tryfail; /* # acquisition failures. */
87522 + atomic_long_unchecked_t expedited_workdone1; /* # done by others #1. */
87523 + atomic_long_unchecked_t expedited_workdone2; /* # done by others #2. */
87524 + atomic_long_unchecked_t expedited_normal; /* # fallbacks to normal. */
87525 + atomic_long_unchecked_t expedited_stoppedcpus; /* # successful stop_cpus. */
87526 + atomic_long_unchecked_t expedited_done_tries; /* # tries to update _done. */
87527 + atomic_long_unchecked_t expedited_done_lost; /* # times beaten to _done. */
87528 + atomic_long_unchecked_t expedited_done_exit; /* # times exited _done loop. */
87529
87530 unsigned long jiffies_force_qs; /* Time at which to invoke */
87531 /* force_quiescent_state(). */
87532 diff --git a/kernel/rcu/tree_plugin.h b/kernel/rcu/tree_plugin.h
87533 index 08a7652..3598c7e 100644
87534 --- a/kernel/rcu/tree_plugin.h
87535 +++ b/kernel/rcu/tree_plugin.h
87536 @@ -749,7 +749,7 @@ static int rcu_preempted_readers_exp(struct rcu_node *rnp)
87537 static int sync_rcu_preempt_exp_done(struct rcu_node *rnp)
87538 {
87539 return !rcu_preempted_readers_exp(rnp) &&
87540 - ACCESS_ONCE(rnp->expmask) == 0;
87541 + ACCESS_ONCE_RW(rnp->expmask) == 0;
87542 }
87543
87544 /*
87545 @@ -905,7 +905,7 @@ void synchronize_rcu_expedited(void)
87546
87547 /* Clean up and exit. */
87548 smp_mb(); /* ensure expedited GP seen before counter increment. */
87549 - ACCESS_ONCE(sync_rcu_preempt_exp_count)++;
87550 + ACCESS_ONCE_RW(sync_rcu_preempt_exp_count)++;
87551 unlock_mb_ret:
87552 mutex_unlock(&sync_rcu_preempt_exp_mutex);
87553 mb_ret:
87554 @@ -1479,7 +1479,7 @@ static void rcu_boost_kthread_setaffinity(struct rcu_node *rnp, int outgoingcpu)
87555 free_cpumask_var(cm);
87556 }
87557
87558 -static struct smp_hotplug_thread rcu_cpu_thread_spec = {
87559 +static struct smp_hotplug_thread rcu_cpu_thread_spec __read_only = {
87560 .store = &rcu_cpu_kthread_task,
87561 .thread_should_run = rcu_cpu_kthread_should_run,
87562 .thread_fn = rcu_cpu_kthread,
87563 @@ -1946,7 +1946,7 @@ static void print_cpu_stall_info(struct rcu_state *rsp, int cpu)
87564 print_cpu_stall_fast_no_hz(fast_no_hz, cpu);
87565 pr_err("\t%d: (%lu %s) idle=%03x/%llx/%d softirq=%u/%u %s\n",
87566 cpu, ticks_value, ticks_title,
87567 - atomic_read(&rdtp->dynticks) & 0xfff,
87568 + atomic_read_unchecked(&rdtp->dynticks) & 0xfff,
87569 rdtp->dynticks_nesting, rdtp->dynticks_nmi_nesting,
87570 rdp->softirq_snap, kstat_softirqs_cpu(RCU_SOFTIRQ, cpu),
87571 fast_no_hz);
87572 @@ -2109,7 +2109,7 @@ static void __call_rcu_nocb_enqueue(struct rcu_data *rdp,
87573
87574 /* Enqueue the callback on the nocb list and update counts. */
87575 old_rhpp = xchg(&rdp->nocb_tail, rhtp);
87576 - ACCESS_ONCE(*old_rhpp) = rhp;
87577 + ACCESS_ONCE_RW(*old_rhpp) = rhp;
87578 atomic_long_add(rhcount, &rdp->nocb_q_count);
87579 atomic_long_add(rhcount_lazy, &rdp->nocb_q_count_lazy);
87580
87581 @@ -2272,12 +2272,12 @@ static int rcu_nocb_kthread(void *arg)
87582 * Extract queued callbacks, update counts, and wait
87583 * for a grace period to elapse.
87584 */
87585 - ACCESS_ONCE(rdp->nocb_head) = NULL;
87586 + ACCESS_ONCE_RW(rdp->nocb_head) = NULL;
87587 tail = xchg(&rdp->nocb_tail, &rdp->nocb_head);
87588 c = atomic_long_xchg(&rdp->nocb_q_count, 0);
87589 cl = atomic_long_xchg(&rdp->nocb_q_count_lazy, 0);
87590 - ACCESS_ONCE(rdp->nocb_p_count) += c;
87591 - ACCESS_ONCE(rdp->nocb_p_count_lazy) += cl;
87592 + ACCESS_ONCE_RW(rdp->nocb_p_count) += c;
87593 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) += cl;
87594 rcu_nocb_wait_gp(rdp);
87595
87596 /* Each pass through the following loop invokes a callback. */
87597 @@ -2303,8 +2303,8 @@ static int rcu_nocb_kthread(void *arg)
87598 list = next;
87599 }
87600 trace_rcu_batch_end(rdp->rsp->name, c, !!list, 0, 0, 1);
87601 - ACCESS_ONCE(rdp->nocb_p_count) -= c;
87602 - ACCESS_ONCE(rdp->nocb_p_count_lazy) -= cl;
87603 + ACCESS_ONCE_RW(rdp->nocb_p_count) -= c;
87604 + ACCESS_ONCE_RW(rdp->nocb_p_count_lazy) -= cl;
87605 rdp->n_nocbs_invoked += c;
87606 }
87607 return 0;
87608 @@ -2331,7 +2331,7 @@ static void __init rcu_spawn_nocb_kthreads(struct rcu_state *rsp)
87609 t = kthread_run(rcu_nocb_kthread, rdp,
87610 "rcuo%c/%d", rsp->abbr, cpu);
87611 BUG_ON(IS_ERR(t));
87612 - ACCESS_ONCE(rdp->nocb_kthread) = t;
87613 + ACCESS_ONCE_RW(rdp->nocb_kthread) = t;
87614 }
87615 }
87616
87617 @@ -2457,11 +2457,11 @@ static void rcu_sysidle_enter(struct rcu_dynticks *rdtp, int irq)
87618
87619 /* Record start of fully idle period. */
87620 j = jiffies;
87621 - ACCESS_ONCE(rdtp->dynticks_idle_jiffies) = j;
87622 + ACCESS_ONCE_RW(rdtp->dynticks_idle_jiffies) = j;
87623 smp_mb__before_atomic_inc();
87624 - atomic_inc(&rdtp->dynticks_idle);
87625 + atomic_inc_unchecked(&rdtp->dynticks_idle);
87626 smp_mb__after_atomic_inc();
87627 - WARN_ON_ONCE(atomic_read(&rdtp->dynticks_idle) & 0x1);
87628 + WARN_ON_ONCE(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1);
87629 }
87630
87631 /*
87632 @@ -2526,9 +2526,9 @@ static void rcu_sysidle_exit(struct rcu_dynticks *rdtp, int irq)
87633
87634 /* Record end of idle period. */
87635 smp_mb__before_atomic_inc();
87636 - atomic_inc(&rdtp->dynticks_idle);
87637 + atomic_inc_unchecked(&rdtp->dynticks_idle);
87638 smp_mb__after_atomic_inc();
87639 - WARN_ON_ONCE(!(atomic_read(&rdtp->dynticks_idle) & 0x1));
87640 + WARN_ON_ONCE(!(atomic_read_unchecked(&rdtp->dynticks_idle) & 0x1));
87641
87642 /*
87643 * If we are the timekeeping CPU, we are permitted to be non-idle
87644 @@ -2569,7 +2569,7 @@ static void rcu_sysidle_check_cpu(struct rcu_data *rdp, bool *isidle,
87645 WARN_ON_ONCE(smp_processor_id() != tick_do_timer_cpu);
87646
87647 /* Pick up current idle and NMI-nesting counter and check. */
87648 - cur = atomic_read(&rdtp->dynticks_idle);
87649 + cur = atomic_read_unchecked(&rdtp->dynticks_idle);
87650 if (cur & 0x1) {
87651 *isidle = false; /* We are not idle! */
87652 return;
87653 @@ -2632,7 +2632,7 @@ static void rcu_sysidle(unsigned long j)
87654 case RCU_SYSIDLE_NOT:
87655
87656 /* First time all are idle, so note a short idle period. */
87657 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_SHORT;
87658 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_SHORT;
87659 break;
87660
87661 case RCU_SYSIDLE_SHORT:
87662 @@ -2669,7 +2669,7 @@ static void rcu_sysidle(unsigned long j)
87663 static void rcu_sysidle_cancel(void)
87664 {
87665 smp_mb();
87666 - ACCESS_ONCE(full_sysidle_state) = RCU_SYSIDLE_NOT;
87667 + ACCESS_ONCE_RW(full_sysidle_state) = RCU_SYSIDLE_NOT;
87668 }
87669
87670 /*
87671 @@ -2717,7 +2717,7 @@ static void rcu_sysidle_cb(struct rcu_head *rhp)
87672 smp_mb(); /* grace period precedes setting inuse. */
87673
87674 rshp = container_of(rhp, struct rcu_sysidle_head, rh);
87675 - ACCESS_ONCE(rshp->inuse) = 0;
87676 + ACCESS_ONCE_RW(rshp->inuse) = 0;
87677 }
87678
87679 /*
87680 diff --git a/kernel/rcu/tree_trace.c b/kernel/rcu/tree_trace.c
87681 index 3596797..f78391c 100644
87682 --- a/kernel/rcu/tree_trace.c
87683 +++ b/kernel/rcu/tree_trace.c
87684 @@ -121,7 +121,7 @@ static void print_one_rcu_data(struct seq_file *m, struct rcu_data *rdp)
87685 ulong2long(rdp->completed), ulong2long(rdp->gpnum),
87686 rdp->passed_quiesce, rdp->qs_pending);
87687 seq_printf(m, " dt=%d/%llx/%d df=%lu",
87688 - atomic_read(&rdp->dynticks->dynticks),
87689 + atomic_read_unchecked(&rdp->dynticks->dynticks),
87690 rdp->dynticks->dynticks_nesting,
87691 rdp->dynticks->dynticks_nmi_nesting,
87692 rdp->dynticks_fqs);
87693 @@ -182,17 +182,17 @@ static int show_rcuexp(struct seq_file *m, void *v)
87694 struct rcu_state *rsp = (struct rcu_state *)m->private;
87695
87696 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",
87697 - atomic_long_read(&rsp->expedited_start),
87698 + atomic_long_read_unchecked(&rsp->expedited_start),
87699 atomic_long_read(&rsp->expedited_done),
87700 - atomic_long_read(&rsp->expedited_wrap),
87701 - atomic_long_read(&rsp->expedited_tryfail),
87702 - atomic_long_read(&rsp->expedited_workdone1),
87703 - atomic_long_read(&rsp->expedited_workdone2),
87704 - atomic_long_read(&rsp->expedited_normal),
87705 - atomic_long_read(&rsp->expedited_stoppedcpus),
87706 - atomic_long_read(&rsp->expedited_done_tries),
87707 - atomic_long_read(&rsp->expedited_done_lost),
87708 - atomic_long_read(&rsp->expedited_done_exit));
87709 + atomic_long_read_unchecked(&rsp->expedited_wrap),
87710 + atomic_long_read_unchecked(&rsp->expedited_tryfail),
87711 + atomic_long_read_unchecked(&rsp->expedited_workdone1),
87712 + atomic_long_read_unchecked(&rsp->expedited_workdone2),
87713 + atomic_long_read_unchecked(&rsp->expedited_normal),
87714 + atomic_long_read_unchecked(&rsp->expedited_stoppedcpus),
87715 + atomic_long_read_unchecked(&rsp->expedited_done_tries),
87716 + atomic_long_read_unchecked(&rsp->expedited_done_lost),
87717 + atomic_long_read_unchecked(&rsp->expedited_done_exit));
87718 return 0;
87719 }
87720
87721 diff --git a/kernel/rcu/update.c b/kernel/rcu/update.c
87722 index 6cb3dff..dc5710f 100644
87723 --- a/kernel/rcu/update.c
87724 +++ b/kernel/rcu/update.c
87725 @@ -318,10 +318,10 @@ int rcu_jiffies_till_stall_check(void)
87726 * for CONFIG_RCU_CPU_STALL_TIMEOUT.
87727 */
87728 if (till_stall_check < 3) {
87729 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 3;
87730 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 3;
87731 till_stall_check = 3;
87732 } else if (till_stall_check > 300) {
87733 - ACCESS_ONCE(rcu_cpu_stall_timeout) = 300;
87734 + ACCESS_ONCE_RW(rcu_cpu_stall_timeout) = 300;
87735 till_stall_check = 300;
87736 }
87737 return till_stall_check * HZ + RCU_STALL_DELAY_DELTA;
87738 diff --git a/kernel/resource.c b/kernel/resource.c
87739 index 3f285dc..5755f62 100644
87740 --- a/kernel/resource.c
87741 +++ b/kernel/resource.c
87742 @@ -152,8 +152,18 @@ static const struct file_operations proc_iomem_operations = {
87743
87744 static int __init ioresources_init(void)
87745 {
87746 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
87747 +#ifdef CONFIG_GRKERNSEC_PROC_USER
87748 + proc_create("ioports", S_IRUSR, NULL, &proc_ioports_operations);
87749 + proc_create("iomem", S_IRUSR, NULL, &proc_iomem_operations);
87750 +#elif defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
87751 + proc_create("ioports", S_IRUSR | S_IRGRP, NULL, &proc_ioports_operations);
87752 + proc_create("iomem", S_IRUSR | S_IRGRP, NULL, &proc_iomem_operations);
87753 +#endif
87754 +#else
87755 proc_create("ioports", 0, NULL, &proc_ioports_operations);
87756 proc_create("iomem", 0, NULL, &proc_iomem_operations);
87757 +#endif
87758 return 0;
87759 }
87760 __initcall(ioresources_init);
87761 diff --git a/kernel/sched/auto_group.c b/kernel/sched/auto_group.c
87762 index 4a07353..66b5291 100644
87763 --- a/kernel/sched/auto_group.c
87764 +++ b/kernel/sched/auto_group.c
87765 @@ -11,7 +11,7 @@
87766
87767 unsigned int __read_mostly sysctl_sched_autogroup_enabled = 1;
87768 static struct autogroup autogroup_default;
87769 -static atomic_t autogroup_seq_nr;
87770 +static atomic_unchecked_t autogroup_seq_nr;
87771
87772 void __init autogroup_init(struct task_struct *init_task)
87773 {
87774 @@ -79,7 +79,7 @@ static inline struct autogroup *autogroup_create(void)
87775
87776 kref_init(&ag->kref);
87777 init_rwsem(&ag->lock);
87778 - ag->id = atomic_inc_return(&autogroup_seq_nr);
87779 + ag->id = atomic_inc_return_unchecked(&autogroup_seq_nr);
87780 ag->tg = tg;
87781 #ifdef CONFIG_RT_GROUP_SCHED
87782 /*
87783 diff --git a/kernel/sched/completion.c b/kernel/sched/completion.c
87784 index a63f4dc..349bbb0 100644
87785 --- a/kernel/sched/completion.c
87786 +++ b/kernel/sched/completion.c
87787 @@ -204,7 +204,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible);
87788 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
87789 * or number of jiffies left till timeout) if completed.
87790 */
87791 -long __sched
87792 +long __sched __intentional_overflow(-1)
87793 wait_for_completion_interruptible_timeout(struct completion *x,
87794 unsigned long timeout)
87795 {
87796 @@ -221,7 +221,7 @@ EXPORT_SYMBOL(wait_for_completion_interruptible_timeout);
87797 *
87798 * Return: -ERESTARTSYS if interrupted, 0 if completed.
87799 */
87800 -int __sched wait_for_completion_killable(struct completion *x)
87801 +int __sched __intentional_overflow(-1) wait_for_completion_killable(struct completion *x)
87802 {
87803 long t = wait_for_common(x, MAX_SCHEDULE_TIMEOUT, TASK_KILLABLE);
87804 if (t == -ERESTARTSYS)
87805 @@ -242,7 +242,7 @@ EXPORT_SYMBOL(wait_for_completion_killable);
87806 * Return: -ERESTARTSYS if interrupted, 0 if timed out, positive (at least 1,
87807 * or number of jiffies left till timeout) if completed.
87808 */
87809 -long __sched
87810 +long __sched __intentional_overflow(-1)
87811 wait_for_completion_killable_timeout(struct completion *x,
87812 unsigned long timeout)
87813 {
87814 diff --git a/kernel/sched/core.c b/kernel/sched/core.c
87815 index c677510..132bb14 100644
87816 --- a/kernel/sched/core.c
87817 +++ b/kernel/sched/core.c
87818 @@ -1768,7 +1768,7 @@ void set_numabalancing_state(bool enabled)
87819 int sysctl_numa_balancing(struct ctl_table *table, int write,
87820 void __user *buffer, size_t *lenp, loff_t *ppos)
87821 {
87822 - struct ctl_table t;
87823 + ctl_table_no_const t;
87824 int err;
87825 int state = numabalancing_enabled;
87826
87827 @@ -2893,6 +2893,8 @@ int can_nice(const struct task_struct *p, const int nice)
87828 /* convert nice value [19,-20] to rlimit style value [1,40] */
87829 int nice_rlim = 20 - nice;
87830
87831 + gr_learn_resource(p, RLIMIT_NICE, nice_rlim, 1);
87832 +
87833 return (nice_rlim <= task_rlimit(p, RLIMIT_NICE) ||
87834 capable(CAP_SYS_NICE));
87835 }
87836 @@ -2926,7 +2928,8 @@ SYSCALL_DEFINE1(nice, int, increment)
87837 if (nice > 19)
87838 nice = 19;
87839
87840 - if (increment < 0 && !can_nice(current, nice))
87841 + if (increment < 0 && (!can_nice(current, nice) ||
87842 + gr_handle_chroot_nice()))
87843 return -EPERM;
87844
87845 retval = security_task_setnice(current, nice);
87846 @@ -3088,6 +3091,7 @@ recheck:
87847 unsigned long rlim_rtprio =
87848 task_rlimit(p, RLIMIT_RTPRIO);
87849
87850 + gr_learn_resource(p, RLIMIT_RTPRIO, param->sched_priority, 1);
87851 /* can't set/change the rt policy */
87852 if (policy != p->policy && !rlim_rtprio)
87853 return -EPERM;
87854 @@ -4254,7 +4258,7 @@ static void migrate_tasks(unsigned int dead_cpu)
87855
87856 #if defined(CONFIG_SCHED_DEBUG) && defined(CONFIG_SYSCTL)
87857
87858 -static struct ctl_table sd_ctl_dir[] = {
87859 +static ctl_table_no_const sd_ctl_dir[] __read_only = {
87860 {
87861 .procname = "sched_domain",
87862 .mode = 0555,
87863 @@ -4271,17 +4275,17 @@ static struct ctl_table sd_ctl_root[] = {
87864 {}
87865 };
87866
87867 -static struct ctl_table *sd_alloc_ctl_entry(int n)
87868 +static ctl_table_no_const *sd_alloc_ctl_entry(int n)
87869 {
87870 - struct ctl_table *entry =
87871 + ctl_table_no_const *entry =
87872 kcalloc(n, sizeof(struct ctl_table), GFP_KERNEL);
87873
87874 return entry;
87875 }
87876
87877 -static void sd_free_ctl_entry(struct ctl_table **tablep)
87878 +static void sd_free_ctl_entry(ctl_table_no_const *tablep)
87879 {
87880 - struct ctl_table *entry;
87881 + ctl_table_no_const *entry;
87882
87883 /*
87884 * In the intermediate directories, both the child directory and
87885 @@ -4289,22 +4293,25 @@ static void sd_free_ctl_entry(struct ctl_table **tablep)
87886 * will always be set. In the lowest directory the names are
87887 * static strings and all have proc handlers.
87888 */
87889 - for (entry = *tablep; entry->mode; entry++) {
87890 - if (entry->child)
87891 - sd_free_ctl_entry(&entry->child);
87892 + for (entry = tablep; entry->mode; entry++) {
87893 + if (entry->child) {
87894 + sd_free_ctl_entry(entry->child);
87895 + pax_open_kernel();
87896 + entry->child = NULL;
87897 + pax_close_kernel();
87898 + }
87899 if (entry->proc_handler == NULL)
87900 kfree(entry->procname);
87901 }
87902
87903 - kfree(*tablep);
87904 - *tablep = NULL;
87905 + kfree(tablep);
87906 }
87907
87908 static int min_load_idx = 0;
87909 static int max_load_idx = CPU_LOAD_IDX_MAX-1;
87910
87911 static void
87912 -set_table_entry(struct ctl_table *entry,
87913 +set_table_entry(ctl_table_no_const *entry,
87914 const char *procname, void *data, int maxlen,
87915 umode_t mode, proc_handler *proc_handler,
87916 bool load_idx)
87917 @@ -4324,7 +4331,7 @@ set_table_entry(struct ctl_table *entry,
87918 static struct ctl_table *
87919 sd_alloc_ctl_domain_table(struct sched_domain *sd)
87920 {
87921 - struct ctl_table *table = sd_alloc_ctl_entry(13);
87922 + ctl_table_no_const *table = sd_alloc_ctl_entry(13);
87923
87924 if (table == NULL)
87925 return NULL;
87926 @@ -4359,9 +4366,9 @@ sd_alloc_ctl_domain_table(struct sched_domain *sd)
87927 return table;
87928 }
87929
87930 -static struct ctl_table *sd_alloc_ctl_cpu_table(int cpu)
87931 +static ctl_table_no_const *sd_alloc_ctl_cpu_table(int cpu)
87932 {
87933 - struct ctl_table *entry, *table;
87934 + ctl_table_no_const *entry, *table;
87935 struct sched_domain *sd;
87936 int domain_num = 0, i;
87937 char buf[32];
87938 @@ -4388,11 +4395,13 @@ static struct ctl_table_header *sd_sysctl_header;
87939 static void register_sched_domain_sysctl(void)
87940 {
87941 int i, cpu_num = num_possible_cpus();
87942 - struct ctl_table *entry = sd_alloc_ctl_entry(cpu_num + 1);
87943 + ctl_table_no_const *entry = sd_alloc_ctl_entry(cpu_num + 1);
87944 char buf[32];
87945
87946 WARN_ON(sd_ctl_dir[0].child);
87947 + pax_open_kernel();
87948 sd_ctl_dir[0].child = entry;
87949 + pax_close_kernel();
87950
87951 if (entry == NULL)
87952 return;
87953 @@ -4415,8 +4424,12 @@ static void unregister_sched_domain_sysctl(void)
87954 if (sd_sysctl_header)
87955 unregister_sysctl_table(sd_sysctl_header);
87956 sd_sysctl_header = NULL;
87957 - if (sd_ctl_dir[0].child)
87958 - sd_free_ctl_entry(&sd_ctl_dir[0].child);
87959 + if (sd_ctl_dir[0].child) {
87960 + sd_free_ctl_entry(sd_ctl_dir[0].child);
87961 + pax_open_kernel();
87962 + sd_ctl_dir[0].child = NULL;
87963 + pax_close_kernel();
87964 + }
87965 }
87966 #else
87967 static void register_sched_domain_sysctl(void)
87968 diff --git a/kernel/sched/fair.c b/kernel/sched/fair.c
87969 index e64b079..a46bd34 100644
87970 --- a/kernel/sched/fair.c
87971 +++ b/kernel/sched/fair.c
87972 @@ -1652,7 +1652,7 @@ void task_numa_fault(int last_cpupid, int node, int pages, int flags)
87973
87974 static void reset_ptenuma_scan(struct task_struct *p)
87975 {
87976 - ACCESS_ONCE(p->mm->numa_scan_seq)++;
87977 + ACCESS_ONCE_RW(p->mm->numa_scan_seq)++;
87978 p->mm->numa_scan_offset = 0;
87979 }
87980
87981 @@ -6863,7 +6863,7 @@ static void nohz_idle_balance(int this_cpu, enum cpu_idle_type idle) { }
87982 * run_rebalance_domains is triggered when needed from the scheduler tick.
87983 * Also triggered for nohz idle balancing (with nohz_balancing_kick set).
87984 */
87985 -static void run_rebalance_domains(struct softirq_action *h)
87986 +static __latent_entropy void run_rebalance_domains(void)
87987 {
87988 int this_cpu = smp_processor_id();
87989 struct rq *this_rq = cpu_rq(this_cpu);
87990 diff --git a/kernel/sched/sched.h b/kernel/sched/sched.h
87991 index 88c85b2..a1dec86 100644
87992 --- a/kernel/sched/sched.h
87993 +++ b/kernel/sched/sched.h
87994 @@ -1035,7 +1035,7 @@ struct sched_class {
87995 #ifdef CONFIG_FAIR_GROUP_SCHED
87996 void (*task_move_group) (struct task_struct *p, int on_rq);
87997 #endif
87998 -};
87999 +} __do_const;
88000
88001 #define sched_class_highest (&stop_sched_class)
88002 #define for_each_class(class) \
88003 diff --git a/kernel/signal.c b/kernel/signal.c
88004 index 940b30e..7fd6041 100644
88005 --- a/kernel/signal.c
88006 +++ b/kernel/signal.c
88007 @@ -51,12 +51,12 @@ static struct kmem_cache *sigqueue_cachep;
88008
88009 int print_fatal_signals __read_mostly;
88010
88011 -static void __user *sig_handler(struct task_struct *t, int sig)
88012 +static __sighandler_t sig_handler(struct task_struct *t, int sig)
88013 {
88014 return t->sighand->action[sig - 1].sa.sa_handler;
88015 }
88016
88017 -static int sig_handler_ignored(void __user *handler, int sig)
88018 +static int sig_handler_ignored(__sighandler_t handler, int sig)
88019 {
88020 /* Is it explicitly or implicitly ignored? */
88021 return handler == SIG_IGN ||
88022 @@ -65,7 +65,7 @@ static int sig_handler_ignored(void __user *handler, int sig)
88023
88024 static int sig_task_ignored(struct task_struct *t, int sig, bool force)
88025 {
88026 - void __user *handler;
88027 + __sighandler_t handler;
88028
88029 handler = sig_handler(t, sig);
88030
88031 @@ -369,6 +369,9 @@ __sigqueue_alloc(int sig, struct task_struct *t, gfp_t flags, int override_rlimi
88032 atomic_inc(&user->sigpending);
88033 rcu_read_unlock();
88034
88035 + if (!override_rlimit)
88036 + gr_learn_resource(t, RLIMIT_SIGPENDING, atomic_read(&user->sigpending), 1);
88037 +
88038 if (override_rlimit ||
88039 atomic_read(&user->sigpending) <=
88040 task_rlimit(t, RLIMIT_SIGPENDING)) {
88041 @@ -496,7 +499,7 @@ flush_signal_handlers(struct task_struct *t, int force_default)
88042
88043 int unhandled_signal(struct task_struct *tsk, int sig)
88044 {
88045 - void __user *handler = tsk->sighand->action[sig-1].sa.sa_handler;
88046 + __sighandler_t handler = tsk->sighand->action[sig-1].sa.sa_handler;
88047 if (is_global_init(tsk))
88048 return 1;
88049 if (handler != SIG_IGN && handler != SIG_DFL)
88050 @@ -816,6 +819,13 @@ static int check_kill_permission(int sig, struct siginfo *info,
88051 }
88052 }
88053
88054 + /* allow glibc communication via tgkill to other threads in our
88055 + thread group */
88056 + if ((info == SEND_SIG_NOINFO || info->si_code != SI_TKILL ||
88057 + sig != (SIGRTMIN+1) || task_tgid_vnr(t) != info->si_pid)
88058 + && gr_handle_signal(t, sig))
88059 + return -EPERM;
88060 +
88061 return security_task_kill(t, info, sig, 0);
88062 }
88063
88064 @@ -1199,7 +1209,7 @@ __group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
88065 return send_signal(sig, info, p, 1);
88066 }
88067
88068 -static int
88069 +int
88070 specific_send_sig_info(int sig, struct siginfo *info, struct task_struct *t)
88071 {
88072 return send_signal(sig, info, t, 0);
88073 @@ -1236,6 +1246,7 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
88074 unsigned long int flags;
88075 int ret, blocked, ignored;
88076 struct k_sigaction *action;
88077 + int is_unhandled = 0;
88078
88079 spin_lock_irqsave(&t->sighand->siglock, flags);
88080 action = &t->sighand->action[sig-1];
88081 @@ -1250,9 +1261,18 @@ force_sig_info(int sig, struct siginfo *info, struct task_struct *t)
88082 }
88083 if (action->sa.sa_handler == SIG_DFL)
88084 t->signal->flags &= ~SIGNAL_UNKILLABLE;
88085 + if (action->sa.sa_handler == SIG_IGN || action->sa.sa_handler == SIG_DFL)
88086 + is_unhandled = 1;
88087 ret = specific_send_sig_info(sig, info, t);
88088 spin_unlock_irqrestore(&t->sighand->siglock, flags);
88089
88090 + /* only deal with unhandled signals, java etc trigger SIGSEGV during
88091 + normal operation */
88092 + if (is_unhandled) {
88093 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, t);
88094 + gr_handle_crash(t, sig);
88095 + }
88096 +
88097 return ret;
88098 }
88099
88100 @@ -1319,8 +1339,11 @@ int group_send_sig_info(int sig, struct siginfo *info, struct task_struct *p)
88101 ret = check_kill_permission(sig, info, p);
88102 rcu_read_unlock();
88103
88104 - if (!ret && sig)
88105 + if (!ret && sig) {
88106 ret = do_send_sig_info(sig, info, p, true);
88107 + if (!ret)
88108 + gr_log_signal(sig, !is_si_special(info) ? info->si_addr : NULL, p);
88109 + }
88110
88111 return ret;
88112 }
88113 @@ -2926,7 +2949,15 @@ do_send_specific(pid_t tgid, pid_t pid, int sig, struct siginfo *info)
88114 int error = -ESRCH;
88115
88116 rcu_read_lock();
88117 - p = find_task_by_vpid(pid);
88118 +#ifdef CONFIG_GRKERNSEC_CHROOT_FINDTASK
88119 + /* allow glibc communication via tgkill to other threads in our
88120 + thread group */
88121 + if (grsec_enable_chroot_findtask && info->si_code == SI_TKILL &&
88122 + sig == (SIGRTMIN+1) && tgid == info->si_pid)
88123 + p = find_task_by_vpid_unrestricted(pid);
88124 + else
88125 +#endif
88126 + p = find_task_by_vpid(pid);
88127 if (p && (tgid <= 0 || task_tgid_vnr(p) == tgid)) {
88128 error = check_kill_permission(sig, info, p);
88129 /*
88130 @@ -3240,8 +3271,8 @@ COMPAT_SYSCALL_DEFINE2(sigaltstack,
88131 }
88132 seg = get_fs();
88133 set_fs(KERNEL_DS);
88134 - ret = do_sigaltstack((stack_t __force __user *) (uss_ptr ? &uss : NULL),
88135 - (stack_t __force __user *) &uoss,
88136 + ret = do_sigaltstack((stack_t __force_user *) (uss_ptr ? &uss : NULL),
88137 + (stack_t __force_user *) &uoss,
88138 compat_user_stack_pointer());
88139 set_fs(seg);
88140 if (ret >= 0 && uoss_ptr) {
88141 diff --git a/kernel/smpboot.c b/kernel/smpboot.c
88142 index eb89e18..a4e6792 100644
88143 --- a/kernel/smpboot.c
88144 +++ b/kernel/smpboot.c
88145 @@ -288,7 +288,7 @@ int smpboot_register_percpu_thread(struct smp_hotplug_thread *plug_thread)
88146 }
88147 smpboot_unpark_thread(plug_thread, cpu);
88148 }
88149 - list_add(&plug_thread->list, &hotplug_threads);
88150 + pax_list_add(&plug_thread->list, &hotplug_threads);
88151 out:
88152 mutex_unlock(&smpboot_threads_lock);
88153 return ret;
88154 @@ -305,7 +305,7 @@ void smpboot_unregister_percpu_thread(struct smp_hotplug_thread *plug_thread)
88155 {
88156 get_online_cpus();
88157 mutex_lock(&smpboot_threads_lock);
88158 - list_del(&plug_thread->list);
88159 + pax_list_del(&plug_thread->list);
88160 smpboot_destroy_threads(plug_thread);
88161 mutex_unlock(&smpboot_threads_lock);
88162 put_online_cpus();
88163 diff --git a/kernel/softirq.c b/kernel/softirq.c
88164 index 11025cc..bc0e4dc 100644
88165 --- a/kernel/softirq.c
88166 +++ b/kernel/softirq.c
88167 @@ -50,11 +50,11 @@ irq_cpustat_t irq_stat[NR_CPUS] ____cacheline_aligned;
88168 EXPORT_SYMBOL(irq_stat);
88169 #endif
88170
88171 -static struct softirq_action softirq_vec[NR_SOFTIRQS] __cacheline_aligned_in_smp;
88172 +static struct softirq_action softirq_vec[NR_SOFTIRQS] __read_only __aligned(PAGE_SIZE);
88173
88174 DEFINE_PER_CPU(struct task_struct *, ksoftirqd);
88175
88176 -char *softirq_to_name[NR_SOFTIRQS] = {
88177 +const char * const softirq_to_name[NR_SOFTIRQS] = {
88178 "HI", "TIMER", "NET_TX", "NET_RX", "BLOCK", "BLOCK_IOPOLL",
88179 "TASKLET", "SCHED", "HRTIMER", "RCU"
88180 };
88181 @@ -250,7 +250,7 @@ restart:
88182 kstat_incr_softirqs_this_cpu(vec_nr);
88183
88184 trace_softirq_entry(vec_nr);
88185 - h->action(h);
88186 + h->action();
88187 trace_softirq_exit(vec_nr);
88188 if (unlikely(prev_count != preempt_count())) {
88189 printk(KERN_ERR "huh, entered softirq %u %s %p"
88190 @@ -419,7 +419,7 @@ void __raise_softirq_irqoff(unsigned int nr)
88191 or_softirq_pending(1UL << nr);
88192 }
88193
88194 -void open_softirq(int nr, void (*action)(struct softirq_action *))
88195 +void __init open_softirq(int nr, void (*action)(void))
88196 {
88197 softirq_vec[nr].action = action;
88198 }
88199 @@ -475,7 +475,7 @@ void __tasklet_hi_schedule_first(struct tasklet_struct *t)
88200
88201 EXPORT_SYMBOL(__tasklet_hi_schedule_first);
88202
88203 -static void tasklet_action(struct softirq_action *a)
88204 +static __latent_entropy void tasklet_action(void)
88205 {
88206 struct tasklet_struct *list;
88207
88208 @@ -510,7 +510,7 @@ static void tasklet_action(struct softirq_action *a)
88209 }
88210 }
88211
88212 -static void tasklet_hi_action(struct softirq_action *a)
88213 +static __latent_entropy void tasklet_hi_action(void)
88214 {
88215 struct tasklet_struct *list;
88216
88217 @@ -740,7 +740,7 @@ static struct notifier_block cpu_nfb = {
88218 .notifier_call = cpu_callback
88219 };
88220
88221 -static struct smp_hotplug_thread softirq_threads = {
88222 +static struct smp_hotplug_thread softirq_threads __read_only = {
88223 .store = &ksoftirqd,
88224 .thread_should_run = ksoftirqd_should_run,
88225 .thread_fn = run_ksoftirqd,
88226 diff --git a/kernel/sys.c b/kernel/sys.c
88227 index c723113..46bf922 100644
88228 --- a/kernel/sys.c
88229 +++ b/kernel/sys.c
88230 @@ -148,6 +148,12 @@ static int set_one_prio(struct task_struct *p, int niceval, int error)
88231 error = -EACCES;
88232 goto out;
88233 }
88234 +
88235 + if (gr_handle_chroot_setpriority(p, niceval)) {
88236 + error = -EACCES;
88237 + goto out;
88238 + }
88239 +
88240 no_nice = security_task_setnice(p, niceval);
88241 if (no_nice) {
88242 error = no_nice;
88243 @@ -351,6 +357,9 @@ SYSCALL_DEFINE2(setregid, gid_t, rgid, gid_t, egid)
88244 goto error;
88245 }
88246
88247 + if (gr_check_group_change(new->gid, new->egid, INVALID_GID))
88248 + goto error;
88249 +
88250 if (rgid != (gid_t) -1 ||
88251 (egid != (gid_t) -1 && !gid_eq(kegid, old->gid)))
88252 new->sgid = new->egid;
88253 @@ -386,6 +395,10 @@ SYSCALL_DEFINE1(setgid, gid_t, gid)
88254 old = current_cred();
88255
88256 retval = -EPERM;
88257 +
88258 + if (gr_check_group_change(kgid, kgid, kgid))
88259 + goto error;
88260 +
88261 if (ns_capable(old->user_ns, CAP_SETGID))
88262 new->gid = new->egid = new->sgid = new->fsgid = kgid;
88263 else if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->sgid))
88264 @@ -403,7 +416,7 @@ error:
88265 /*
88266 * change the user struct in a credentials set to match the new UID
88267 */
88268 -static int set_user(struct cred *new)
88269 +int set_user(struct cred *new)
88270 {
88271 struct user_struct *new_user;
88272
88273 @@ -483,6 +496,9 @@ SYSCALL_DEFINE2(setreuid, uid_t, ruid, uid_t, euid)
88274 goto error;
88275 }
88276
88277 + if (gr_check_user_change(new->uid, new->euid, INVALID_UID))
88278 + goto error;
88279 +
88280 if (!uid_eq(new->uid, old->uid)) {
88281 retval = set_user(new);
88282 if (retval < 0)
88283 @@ -533,6 +549,12 @@ SYSCALL_DEFINE1(setuid, uid_t, uid)
88284 old = current_cred();
88285
88286 retval = -EPERM;
88287 +
88288 + if (gr_check_crash_uid(kuid))
88289 + goto error;
88290 + if (gr_check_user_change(kuid, kuid, kuid))
88291 + goto error;
88292 +
88293 if (ns_capable(old->user_ns, CAP_SETUID)) {
88294 new->suid = new->uid = kuid;
88295 if (!uid_eq(kuid, old->uid)) {
88296 @@ -602,6 +624,9 @@ SYSCALL_DEFINE3(setresuid, uid_t, ruid, uid_t, euid, uid_t, suid)
88297 goto error;
88298 }
88299
88300 + if (gr_check_user_change(kruid, keuid, INVALID_UID))
88301 + goto error;
88302 +
88303 if (ruid != (uid_t) -1) {
88304 new->uid = kruid;
88305 if (!uid_eq(kruid, old->uid)) {
88306 @@ -684,6 +709,9 @@ SYSCALL_DEFINE3(setresgid, gid_t, rgid, gid_t, egid, gid_t, sgid)
88307 goto error;
88308 }
88309
88310 + if (gr_check_group_change(krgid, kegid, INVALID_GID))
88311 + goto error;
88312 +
88313 if (rgid != (gid_t) -1)
88314 new->gid = krgid;
88315 if (egid != (gid_t) -1)
88316 @@ -745,12 +773,16 @@ SYSCALL_DEFINE1(setfsuid, uid_t, uid)
88317 uid_eq(kuid, old->suid) || uid_eq(kuid, old->fsuid) ||
88318 ns_capable(old->user_ns, CAP_SETUID)) {
88319 if (!uid_eq(kuid, old->fsuid)) {
88320 + if (gr_check_user_change(INVALID_UID, INVALID_UID, kuid))
88321 + goto error;
88322 +
88323 new->fsuid = kuid;
88324 if (security_task_fix_setuid(new, old, LSM_SETID_FS) == 0)
88325 goto change_okay;
88326 }
88327 }
88328
88329 +error:
88330 abort_creds(new);
88331 return old_fsuid;
88332
88333 @@ -783,12 +815,16 @@ SYSCALL_DEFINE1(setfsgid, gid_t, gid)
88334 if (gid_eq(kgid, old->gid) || gid_eq(kgid, old->egid) ||
88335 gid_eq(kgid, old->sgid) || gid_eq(kgid, old->fsgid) ||
88336 ns_capable(old->user_ns, CAP_SETGID)) {
88337 + if (gr_check_group_change(INVALID_GID, INVALID_GID, kgid))
88338 + goto error;
88339 +
88340 if (!gid_eq(kgid, old->fsgid)) {
88341 new->fsgid = kgid;
88342 goto change_okay;
88343 }
88344 }
88345
88346 +error:
88347 abort_creds(new);
88348 return old_fsgid;
88349
88350 @@ -1168,19 +1204,19 @@ SYSCALL_DEFINE1(olduname, struct oldold_utsname __user *, name)
88351 return -EFAULT;
88352
88353 down_read(&uts_sem);
88354 - error = __copy_to_user(&name->sysname, &utsname()->sysname,
88355 + error = __copy_to_user(name->sysname, &utsname()->sysname,
88356 __OLD_UTS_LEN);
88357 error |= __put_user(0, name->sysname + __OLD_UTS_LEN);
88358 - error |= __copy_to_user(&name->nodename, &utsname()->nodename,
88359 + error |= __copy_to_user(name->nodename, &utsname()->nodename,
88360 __OLD_UTS_LEN);
88361 error |= __put_user(0, name->nodename + __OLD_UTS_LEN);
88362 - error |= __copy_to_user(&name->release, &utsname()->release,
88363 + error |= __copy_to_user(name->release, &utsname()->release,
88364 __OLD_UTS_LEN);
88365 error |= __put_user(0, name->release + __OLD_UTS_LEN);
88366 - error |= __copy_to_user(&name->version, &utsname()->version,
88367 + error |= __copy_to_user(name->version, &utsname()->version,
88368 __OLD_UTS_LEN);
88369 error |= __put_user(0, name->version + __OLD_UTS_LEN);
88370 - error |= __copy_to_user(&name->machine, &utsname()->machine,
88371 + error |= __copy_to_user(name->machine, &utsname()->machine,
88372 __OLD_UTS_LEN);
88373 error |= __put_user(0, name->machine + __OLD_UTS_LEN);
88374 up_read(&uts_sem);
88375 @@ -1382,6 +1418,13 @@ int do_prlimit(struct task_struct *tsk, unsigned int resource,
88376 */
88377 new_rlim->rlim_cur = 1;
88378 }
88379 + /* Handle the case where a fork and setuid occur and then RLIMIT_NPROC
88380 + is changed to a lower value. Since tasks can be created by the same
88381 + user in between this limit change and an execve by this task, force
88382 + a recheck only for this task by setting PF_NPROC_EXCEEDED
88383 + */
88384 + if (resource == RLIMIT_NPROC && tsk->real_cred->user != INIT_USER)
88385 + tsk->flags |= PF_NPROC_EXCEEDED;
88386 }
88387 if (!retval) {
88388 if (old_rlim)
88389 diff --git a/kernel/sysctl.c b/kernel/sysctl.c
88390 index 06962ba..a54d45e 100644
88391 --- a/kernel/sysctl.c
88392 +++ b/kernel/sysctl.c
88393 @@ -93,7 +93,6 @@
88394
88395
88396 #if defined(CONFIG_SYSCTL)
88397 -
88398 /* External variables not in a header file. */
88399 extern int sysctl_overcommit_memory;
88400 extern int sysctl_overcommit_ratio;
88401 @@ -119,17 +118,18 @@ extern int blk_iopoll_enabled;
88402
88403 /* Constants used for minimum and maximum */
88404 #ifdef CONFIG_LOCKUP_DETECTOR
88405 -static int sixty = 60;
88406 +static int sixty __read_only = 60;
88407 #endif
88408
88409 -static int zero;
88410 -static int __maybe_unused one = 1;
88411 -static int __maybe_unused two = 2;
88412 -static int __maybe_unused three = 3;
88413 -static unsigned long one_ul = 1;
88414 -static int one_hundred = 100;
88415 +static int neg_one __read_only = -1;
88416 +static int zero __read_only = 0;
88417 +static int __maybe_unused one __read_only = 1;
88418 +static int __maybe_unused two __read_only = 2;
88419 +static int __maybe_unused three __read_only = 3;
88420 +static unsigned long one_ul __read_only = 1;
88421 +static int one_hundred __read_only = 100;
88422 #ifdef CONFIG_PRINTK
88423 -static int ten_thousand = 10000;
88424 +static int ten_thousand __read_only = 10000;
88425 #endif
88426
88427 /* this is needed for the proc_doulongvec_minmax of vm_dirty_bytes */
88428 @@ -176,10 +176,8 @@ static int proc_taint(struct ctl_table *table, int write,
88429 void __user *buffer, size_t *lenp, loff_t *ppos);
88430 #endif
88431
88432 -#ifdef CONFIG_PRINTK
88433 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
88434 void __user *buffer, size_t *lenp, loff_t *ppos);
88435 -#endif
88436
88437 static int proc_dointvec_minmax_coredump(struct ctl_table *table, int write,
88438 void __user *buffer, size_t *lenp, loff_t *ppos);
88439 @@ -210,6 +208,8 @@ static int sysrq_sysctl_handler(ctl_table *table, int write,
88440
88441 #endif
88442
88443 +extern struct ctl_table grsecurity_table[];
88444 +
88445 static struct ctl_table kern_table[];
88446 static struct ctl_table vm_table[];
88447 static struct ctl_table fs_table[];
88448 @@ -224,6 +224,20 @@ extern struct ctl_table epoll_table[];
88449 int sysctl_legacy_va_layout;
88450 #endif
88451
88452 +#ifdef CONFIG_PAX_SOFTMODE
88453 +static ctl_table pax_table[] = {
88454 + {
88455 + .procname = "softmode",
88456 + .data = &pax_softmode,
88457 + .maxlen = sizeof(unsigned int),
88458 + .mode = 0600,
88459 + .proc_handler = &proc_dointvec,
88460 + },
88461 +
88462 + { }
88463 +};
88464 +#endif
88465 +
88466 /* The default sysctl tables: */
88467
88468 static struct ctl_table sysctl_base_table[] = {
88469 @@ -272,6 +286,22 @@ static int max_extfrag_threshold = 1000;
88470 #endif
88471
88472 static struct ctl_table kern_table[] = {
88473 +#if defined(CONFIG_GRKERNSEC_SYSCTL) || defined(CONFIG_GRKERNSEC_ROFS)
88474 + {
88475 + .procname = "grsecurity",
88476 + .mode = 0500,
88477 + .child = grsecurity_table,
88478 + },
88479 +#endif
88480 +
88481 +#ifdef CONFIG_PAX_SOFTMODE
88482 + {
88483 + .procname = "pax",
88484 + .mode = 0500,
88485 + .child = pax_table,
88486 + },
88487 +#endif
88488 +
88489 {
88490 .procname = "sched_child_runs_first",
88491 .data = &sysctl_sched_child_runs_first,
88492 @@ -629,7 +659,7 @@ static struct ctl_table kern_table[] = {
88493 .data = &modprobe_path,
88494 .maxlen = KMOD_PATH_LEN,
88495 .mode = 0644,
88496 - .proc_handler = proc_dostring,
88497 + .proc_handler = proc_dostring_modpriv,
88498 },
88499 {
88500 .procname = "modules_disabled",
88501 @@ -796,16 +826,20 @@ static struct ctl_table kern_table[] = {
88502 .extra1 = &zero,
88503 .extra2 = &one,
88504 },
88505 +#endif
88506 {
88507 .procname = "kptr_restrict",
88508 .data = &kptr_restrict,
88509 .maxlen = sizeof(int),
88510 .mode = 0644,
88511 .proc_handler = proc_dointvec_minmax_sysadmin,
88512 +#ifdef CONFIG_GRKERNSEC_HIDESYM
88513 + .extra1 = &two,
88514 +#else
88515 .extra1 = &zero,
88516 +#endif
88517 .extra2 = &two,
88518 },
88519 -#endif
88520 {
88521 .procname = "ngroups_max",
88522 .data = &ngroups_max,
88523 @@ -1048,10 +1082,17 @@ static struct ctl_table kern_table[] = {
88524 */
88525 {
88526 .procname = "perf_event_paranoid",
88527 - .data = &sysctl_perf_event_paranoid,
88528 - .maxlen = sizeof(sysctl_perf_event_paranoid),
88529 + .data = &sysctl_perf_event_legitimately_concerned,
88530 + .maxlen = sizeof(sysctl_perf_event_legitimately_concerned),
88531 .mode = 0644,
88532 - .proc_handler = proc_dointvec,
88533 + /* go ahead, be a hero */
88534 + .proc_handler = proc_dointvec_minmax_sysadmin,
88535 + .extra1 = &neg_one,
88536 +#ifdef CONFIG_GRKERNSEC_PERF_HARDEN
88537 + .extra2 = &three,
88538 +#else
88539 + .extra2 = &two,
88540 +#endif
88541 },
88542 {
88543 .procname = "perf_event_mlock_kb",
88544 @@ -1315,6 +1356,13 @@ static struct ctl_table vm_table[] = {
88545 .proc_handler = proc_dointvec_minmax,
88546 .extra1 = &zero,
88547 },
88548 + {
88549 + .procname = "heap_stack_gap",
88550 + .data = &sysctl_heap_stack_gap,
88551 + .maxlen = sizeof(sysctl_heap_stack_gap),
88552 + .mode = 0644,
88553 + .proc_handler = proc_doulongvec_minmax,
88554 + },
88555 #else
88556 {
88557 .procname = "nr_trim_pages",
88558 @@ -1779,6 +1827,16 @@ int proc_dostring(struct ctl_table *table, int write,
88559 buffer, lenp, ppos);
88560 }
88561
88562 +int proc_dostring_modpriv(struct ctl_table *table, int write,
88563 + void __user *buffer, size_t *lenp, loff_t *ppos)
88564 +{
88565 + if (write && !capable(CAP_SYS_MODULE))
88566 + return -EPERM;
88567 +
88568 + return _proc_do_string(table->data, table->maxlen, write,
88569 + buffer, lenp, ppos);
88570 +}
88571 +
88572 static size_t proc_skip_spaces(char **buf)
88573 {
88574 size_t ret;
88575 @@ -1884,6 +1942,8 @@ static int proc_put_long(void __user **buf, size_t *size, unsigned long val,
88576 len = strlen(tmp);
88577 if (len > *size)
88578 len = *size;
88579 + if (len > sizeof(tmp))
88580 + len = sizeof(tmp);
88581 if (copy_to_user(*buf, tmp, len))
88582 return -EFAULT;
88583 *size -= len;
88584 @@ -2048,7 +2108,7 @@ int proc_dointvec(struct ctl_table *table, int write,
88585 static int proc_taint(struct ctl_table *table, int write,
88586 void __user *buffer, size_t *lenp, loff_t *ppos)
88587 {
88588 - struct ctl_table t;
88589 + ctl_table_no_const t;
88590 unsigned long tmptaint = get_taint();
88591 int err;
88592
88593 @@ -2076,7 +2136,6 @@ static int proc_taint(struct ctl_table *table, int write,
88594 return err;
88595 }
88596
88597 -#ifdef CONFIG_PRINTK
88598 static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
88599 void __user *buffer, size_t *lenp, loff_t *ppos)
88600 {
88601 @@ -2085,7 +2144,6 @@ static int proc_dointvec_minmax_sysadmin(struct ctl_table *table, int write,
88602
88603 return proc_dointvec_minmax(table, write, buffer, lenp, ppos);
88604 }
88605 -#endif
88606
88607 struct do_proc_dointvec_minmax_conv_param {
88608 int *min;
88609 @@ -2632,6 +2690,12 @@ int proc_dostring(struct ctl_table *table, int write,
88610 return -ENOSYS;
88611 }
88612
88613 +int proc_dostring_modpriv(struct ctl_table *table, int write,
88614 + void __user *buffer, size_t *lenp, loff_t *ppos)
88615 +{
88616 + return -ENOSYS;
88617 +}
88618 +
88619 int proc_dointvec(struct ctl_table *table, int write,
88620 void __user *buffer, size_t *lenp, loff_t *ppos)
88621 {
88622 @@ -2688,5 +2752,6 @@ EXPORT_SYMBOL(proc_dointvec_minmax);
88623 EXPORT_SYMBOL(proc_dointvec_userhz_jiffies);
88624 EXPORT_SYMBOL(proc_dointvec_ms_jiffies);
88625 EXPORT_SYMBOL(proc_dostring);
88626 +EXPORT_SYMBOL(proc_dostring_modpriv);
88627 EXPORT_SYMBOL(proc_doulongvec_minmax);
88628 EXPORT_SYMBOL(proc_doulongvec_ms_jiffies_minmax);
88629 diff --git a/kernel/taskstats.c b/kernel/taskstats.c
88630 index 13d2f7c..c93d0b0 100644
88631 --- a/kernel/taskstats.c
88632 +++ b/kernel/taskstats.c
88633 @@ -28,9 +28,12 @@
88634 #include <linux/fs.h>
88635 #include <linux/file.h>
88636 #include <linux/pid_namespace.h>
88637 +#include <linux/grsecurity.h>
88638 #include <net/genetlink.h>
88639 #include <linux/atomic.h>
88640
88641 +extern int gr_is_taskstats_denied(int pid);
88642 +
88643 /*
88644 * Maximum length of a cpumask that can be specified in
88645 * the TASKSTATS_CMD_ATTR_REGISTER/DEREGISTER_CPUMASK attribute
88646 @@ -576,6 +579,9 @@ err:
88647
88648 static int taskstats_user_cmd(struct sk_buff *skb, struct genl_info *info)
88649 {
88650 + if (gr_is_taskstats_denied(current->pid))
88651 + return -EACCES;
88652 +
88653 if (info->attrs[TASKSTATS_CMD_ATTR_REGISTER_CPUMASK])
88654 return cmd_attr_register_cpumask(info);
88655 else if (info->attrs[TASKSTATS_CMD_ATTR_DEREGISTER_CPUMASK])
88656 diff --git a/kernel/time.c b/kernel/time.c
88657 index 7c7964c..2a0d412 100644
88658 --- a/kernel/time.c
88659 +++ b/kernel/time.c
88660 @@ -172,6 +172,11 @@ int do_sys_settimeofday(const struct timespec *tv, const struct timezone *tz)
88661 return error;
88662
88663 if (tz) {
88664 + /* we log in do_settimeofday called below, so don't log twice
88665 + */
88666 + if (!tv)
88667 + gr_log_timechange();
88668 +
88669 sys_tz = *tz;
88670 update_vsyscall_tz();
88671 if (firsttime) {
88672 diff --git a/kernel/time/alarmtimer.c b/kernel/time/alarmtimer.c
88673 index 88c9c65..7497ebc 100644
88674 --- a/kernel/time/alarmtimer.c
88675 +++ b/kernel/time/alarmtimer.c
88676 @@ -795,7 +795,7 @@ static int __init alarmtimer_init(void)
88677 struct platform_device *pdev;
88678 int error = 0;
88679 int i;
88680 - struct k_clock alarm_clock = {
88681 + static struct k_clock alarm_clock = {
88682 .clock_getres = alarm_clock_getres,
88683 .clock_get = alarm_clock_get,
88684 .timer_create = alarm_timer_create,
88685 diff --git a/kernel/time/timekeeping.c b/kernel/time/timekeeping.c
88686 index b415457..c26876d 100644
88687 --- a/kernel/time/timekeeping.c
88688 +++ b/kernel/time/timekeeping.c
88689 @@ -15,6 +15,7 @@
88690 #include <linux/init.h>
88691 #include <linux/mm.h>
88692 #include <linux/sched.h>
88693 +#include <linux/grsecurity.h>
88694 #include <linux/syscore_ops.h>
88695 #include <linux/clocksource.h>
88696 #include <linux/jiffies.h>
88697 @@ -500,6 +501,8 @@ int do_settimeofday(const struct timespec *tv)
88698 if (!timespec_valid_strict(tv))
88699 return -EINVAL;
88700
88701 + gr_log_timechange();
88702 +
88703 raw_spin_lock_irqsave(&timekeeper_lock, flags);
88704 write_seqcount_begin(&timekeeper_seq);
88705
88706 diff --git a/kernel/time/timer_list.c b/kernel/time/timer_list.c
88707 index 61ed862..3b52c65 100644
88708 --- a/kernel/time/timer_list.c
88709 +++ b/kernel/time/timer_list.c
88710 @@ -45,12 +45,16 @@ DECLARE_PER_CPU(struct hrtimer_cpu_base, hrtimer_bases);
88711
88712 static void print_name_offset(struct seq_file *m, void *sym)
88713 {
88714 +#ifdef CONFIG_GRKERNSEC_HIDESYM
88715 + SEQ_printf(m, "<%p>", NULL);
88716 +#else
88717 char symname[KSYM_NAME_LEN];
88718
88719 if (lookup_symbol_name((unsigned long)sym, symname) < 0)
88720 SEQ_printf(m, "<%pK>", sym);
88721 else
88722 SEQ_printf(m, "%s", symname);
88723 +#endif
88724 }
88725
88726 static void
88727 @@ -119,7 +123,11 @@ next_one:
88728 static void
88729 print_base(struct seq_file *m, struct hrtimer_clock_base *base, u64 now)
88730 {
88731 +#ifdef CONFIG_GRKERNSEC_HIDESYM
88732 + SEQ_printf(m, " .base: %p\n", NULL);
88733 +#else
88734 SEQ_printf(m, " .base: %pK\n", base);
88735 +#endif
88736 SEQ_printf(m, " .index: %d\n",
88737 base->index);
88738 SEQ_printf(m, " .resolution: %Lu nsecs\n",
88739 @@ -362,7 +370,11 @@ static int __init init_timer_list_procfs(void)
88740 {
88741 struct proc_dir_entry *pe;
88742
88743 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
88744 + pe = proc_create("timer_list", 0400, NULL, &timer_list_fops);
88745 +#else
88746 pe = proc_create("timer_list", 0444, NULL, &timer_list_fops);
88747 +#endif
88748 if (!pe)
88749 return -ENOMEM;
88750 return 0;
88751 diff --git a/kernel/time/timer_stats.c b/kernel/time/timer_stats.c
88752 index 1fb08f2..ca4bb1e 100644
88753 --- a/kernel/time/timer_stats.c
88754 +++ b/kernel/time/timer_stats.c
88755 @@ -116,7 +116,7 @@ static ktime_t time_start, time_stop;
88756 static unsigned long nr_entries;
88757 static struct entry entries[MAX_ENTRIES];
88758
88759 -static atomic_t overflow_count;
88760 +static atomic_unchecked_t overflow_count;
88761
88762 /*
88763 * The entries are in a hash-table, for fast lookup:
88764 @@ -140,7 +140,7 @@ static void reset_entries(void)
88765 nr_entries = 0;
88766 memset(entries, 0, sizeof(entries));
88767 memset(tstat_hash_table, 0, sizeof(tstat_hash_table));
88768 - atomic_set(&overflow_count, 0);
88769 + atomic_set_unchecked(&overflow_count, 0);
88770 }
88771
88772 static struct entry *alloc_entry(void)
88773 @@ -261,7 +261,7 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
88774 if (likely(entry))
88775 entry->count++;
88776 else
88777 - atomic_inc(&overflow_count);
88778 + atomic_inc_unchecked(&overflow_count);
88779
88780 out_unlock:
88781 raw_spin_unlock_irqrestore(lock, flags);
88782 @@ -269,12 +269,16 @@ void timer_stats_update_stats(void *timer, pid_t pid, void *startf,
88783
88784 static void print_name_offset(struct seq_file *m, unsigned long addr)
88785 {
88786 +#ifdef CONFIG_GRKERNSEC_HIDESYM
88787 + seq_printf(m, "<%p>", NULL);
88788 +#else
88789 char symname[KSYM_NAME_LEN];
88790
88791 if (lookup_symbol_name(addr, symname) < 0)
88792 - seq_printf(m, "<%p>", (void *)addr);
88793 + seq_printf(m, "<%pK>", (void *)addr);
88794 else
88795 seq_printf(m, "%s", symname);
88796 +#endif
88797 }
88798
88799 static int tstats_show(struct seq_file *m, void *v)
88800 @@ -300,8 +304,8 @@ static int tstats_show(struct seq_file *m, void *v)
88801
88802 seq_puts(m, "Timer Stats Version: v0.3\n");
88803 seq_printf(m, "Sample period: %ld.%03ld s\n", period.tv_sec, ms);
88804 - if (atomic_read(&overflow_count))
88805 - seq_printf(m, "Overflow: %d entries\n", atomic_read(&overflow_count));
88806 + if (atomic_read_unchecked(&overflow_count))
88807 + seq_printf(m, "Overflow: %d entries\n", atomic_read_unchecked(&overflow_count));
88808 seq_printf(m, "Collection: %s\n", timer_stats_active ? "active" : "inactive");
88809
88810 for (i = 0; i < nr_entries; i++) {
88811 @@ -417,7 +421,11 @@ static int __init init_tstats_procfs(void)
88812 {
88813 struct proc_dir_entry *pe;
88814
88815 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
88816 + pe = proc_create("timer_stats", 0600, NULL, &tstats_fops);
88817 +#else
88818 pe = proc_create("timer_stats", 0644, NULL, &tstats_fops);
88819 +#endif
88820 if (!pe)
88821 return -ENOMEM;
88822 return 0;
88823 diff --git a/kernel/timer.c b/kernel/timer.c
88824 index accfd24..e00f0c0 100644
88825 --- a/kernel/timer.c
88826 +++ b/kernel/timer.c
88827 @@ -1366,7 +1366,7 @@ void update_process_times(int user_tick)
88828 /*
88829 * This function runs timers and the timer-tq in bottom half context.
88830 */
88831 -static void run_timer_softirq(struct softirq_action *h)
88832 +static __latent_entropy void run_timer_softirq(void)
88833 {
88834 struct tvec_base *base = __this_cpu_read(tvec_bases);
88835
88836 @@ -1429,7 +1429,7 @@ static void process_timeout(unsigned long __data)
88837 *
88838 * In all cases the return value is guaranteed to be non-negative.
88839 */
88840 -signed long __sched schedule_timeout(signed long timeout)
88841 +signed long __sched __intentional_overflow(-1) schedule_timeout(signed long timeout)
88842 {
88843 struct timer_list timer;
88844 unsigned long expire;
88845 diff --git a/kernel/trace/blktrace.c b/kernel/trace/blktrace.c
88846 index f785aef..59f1b18 100644
88847 --- a/kernel/trace/blktrace.c
88848 +++ b/kernel/trace/blktrace.c
88849 @@ -328,7 +328,7 @@ static ssize_t blk_dropped_read(struct file *filp, char __user *buffer,
88850 struct blk_trace *bt = filp->private_data;
88851 char buf[16];
88852
88853 - snprintf(buf, sizeof(buf), "%u\n", atomic_read(&bt->dropped));
88854 + snprintf(buf, sizeof(buf), "%u\n", atomic_read_unchecked(&bt->dropped));
88855
88856 return simple_read_from_buffer(buffer, count, ppos, buf, strlen(buf));
88857 }
88858 @@ -386,7 +386,7 @@ static int blk_subbuf_start_callback(struct rchan_buf *buf, void *subbuf,
88859 return 1;
88860
88861 bt = buf->chan->private_data;
88862 - atomic_inc(&bt->dropped);
88863 + atomic_inc_unchecked(&bt->dropped);
88864 return 0;
88865 }
88866
88867 @@ -487,7 +487,7 @@ int do_blk_trace_setup(struct request_queue *q, char *name, dev_t dev,
88868
88869 bt->dir = dir;
88870 bt->dev = dev;
88871 - atomic_set(&bt->dropped, 0);
88872 + atomic_set_unchecked(&bt->dropped, 0);
88873 INIT_LIST_HEAD(&bt->running_list);
88874
88875 ret = -EIO;
88876 diff --git a/kernel/trace/ftrace.c b/kernel/trace/ftrace.c
88877 index 38463d2..68abe92 100644
88878 --- a/kernel/trace/ftrace.c
88879 +++ b/kernel/trace/ftrace.c
88880 @@ -1978,12 +1978,17 @@ ftrace_code_disable(struct module *mod, struct dyn_ftrace *rec)
88881 if (unlikely(ftrace_disabled))
88882 return 0;
88883
88884 + ret = ftrace_arch_code_modify_prepare();
88885 + FTRACE_WARN_ON(ret);
88886 + if (ret)
88887 + return 0;
88888 +
88889 ret = ftrace_make_nop(mod, rec, MCOUNT_ADDR);
88890 + FTRACE_WARN_ON(ftrace_arch_code_modify_post_process());
88891 if (ret) {
88892 ftrace_bug(ret, ip);
88893 - return 0;
88894 }
88895 - return 1;
88896 + return ret ? 0 : 1;
88897 }
88898
88899 /*
88900 @@ -4190,8 +4195,10 @@ static int ftrace_process_locs(struct module *mod,
88901 if (!count)
88902 return 0;
88903
88904 + pax_open_kernel();
88905 sort(start, count, sizeof(*start),
88906 ftrace_cmp_ips, ftrace_swap_ips);
88907 + pax_close_kernel();
88908
88909 start_pg = ftrace_allocate_pages(count);
88910 if (!start_pg)
88911 @@ -4922,8 +4929,6 @@ ftrace_enable_sysctl(struct ctl_table *table, int write,
88912 #ifdef CONFIG_FUNCTION_GRAPH_TRACER
88913
88914 static int ftrace_graph_active;
88915 -static struct notifier_block ftrace_suspend_notifier;
88916 -
88917 int ftrace_graph_entry_stub(struct ftrace_graph_ent *trace)
88918 {
88919 return 0;
88920 @@ -5099,6 +5104,10 @@ static void update_function_graph_func(void)
88921 ftrace_graph_entry = ftrace_graph_entry_test;
88922 }
88923
88924 +static struct notifier_block ftrace_suspend_notifier = {
88925 + .notifier_call = ftrace_suspend_notifier_call
88926 +};
88927 +
88928 int register_ftrace_graph(trace_func_graph_ret_t retfunc,
88929 trace_func_graph_ent_t entryfunc)
88930 {
88931 @@ -5112,7 +5121,6 @@ int register_ftrace_graph(trace_func_graph_ret_t retfunc,
88932 goto out;
88933 }
88934
88935 - ftrace_suspend_notifier.notifier_call = ftrace_suspend_notifier_call;
88936 register_pm_notifier(&ftrace_suspend_notifier);
88937
88938 ftrace_graph_active++;
88939 diff --git a/kernel/trace/ring_buffer.c b/kernel/trace/ring_buffer.c
88940 index cc2f66f..05edd54 100644
88941 --- a/kernel/trace/ring_buffer.c
88942 +++ b/kernel/trace/ring_buffer.c
88943 @@ -352,9 +352,9 @@ struct buffer_data_page {
88944 */
88945 struct buffer_page {
88946 struct list_head list; /* list of buffer pages */
88947 - local_t write; /* index for next write */
88948 + local_unchecked_t write; /* index for next write */
88949 unsigned read; /* index for next read */
88950 - local_t entries; /* entries on this page */
88951 + local_unchecked_t entries; /* entries on this page */
88952 unsigned long real_end; /* real end of data */
88953 struct buffer_data_page *page; /* Actual data page */
88954 };
88955 @@ -473,8 +473,8 @@ struct ring_buffer_per_cpu {
88956 unsigned long last_overrun;
88957 local_t entries_bytes;
88958 local_t entries;
88959 - local_t overrun;
88960 - local_t commit_overrun;
88961 + local_unchecked_t overrun;
88962 + local_unchecked_t commit_overrun;
88963 local_t dropped_events;
88964 local_t committing;
88965 local_t commits;
88966 @@ -992,8 +992,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
88967 *
88968 * We add a counter to the write field to denote this.
88969 */
88970 - old_write = local_add_return(RB_WRITE_INTCNT, &next_page->write);
88971 - old_entries = local_add_return(RB_WRITE_INTCNT, &next_page->entries);
88972 + old_write = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->write);
88973 + old_entries = local_add_return_unchecked(RB_WRITE_INTCNT, &next_page->entries);
88974
88975 /*
88976 * Just make sure we have seen our old_write and synchronize
88977 @@ -1021,8 +1021,8 @@ static int rb_tail_page_update(struct ring_buffer_per_cpu *cpu_buffer,
88978 * cmpxchg to only update if an interrupt did not already
88979 * do it for us. If the cmpxchg fails, we don't care.
88980 */
88981 - (void)local_cmpxchg(&next_page->write, old_write, val);
88982 - (void)local_cmpxchg(&next_page->entries, old_entries, eval);
88983 + (void)local_cmpxchg_unchecked(&next_page->write, old_write, val);
88984 + (void)local_cmpxchg_unchecked(&next_page->entries, old_entries, eval);
88985
88986 /*
88987 * No need to worry about races with clearing out the commit.
88988 @@ -1386,12 +1386,12 @@ static void rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer);
88989
88990 static inline unsigned long rb_page_entries(struct buffer_page *bpage)
88991 {
88992 - return local_read(&bpage->entries) & RB_WRITE_MASK;
88993 + return local_read_unchecked(&bpage->entries) & RB_WRITE_MASK;
88994 }
88995
88996 static inline unsigned long rb_page_write(struct buffer_page *bpage)
88997 {
88998 - return local_read(&bpage->write) & RB_WRITE_MASK;
88999 + return local_read_unchecked(&bpage->write) & RB_WRITE_MASK;
89000 }
89001
89002 static int
89003 @@ -1486,7 +1486,7 @@ rb_remove_pages(struct ring_buffer_per_cpu *cpu_buffer, unsigned int nr_pages)
89004 * bytes consumed in ring buffer from here.
89005 * Increment overrun to account for the lost events.
89006 */
89007 - local_add(page_entries, &cpu_buffer->overrun);
89008 + local_add_unchecked(page_entries, &cpu_buffer->overrun);
89009 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
89010 }
89011
89012 @@ -2064,7 +2064,7 @@ rb_handle_head_page(struct ring_buffer_per_cpu *cpu_buffer,
89013 * it is our responsibility to update
89014 * the counters.
89015 */
89016 - local_add(entries, &cpu_buffer->overrun);
89017 + local_add_unchecked(entries, &cpu_buffer->overrun);
89018 local_sub(BUF_PAGE_SIZE, &cpu_buffer->entries_bytes);
89019
89020 /*
89021 @@ -2214,7 +2214,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
89022 if (tail == BUF_PAGE_SIZE)
89023 tail_page->real_end = 0;
89024
89025 - local_sub(length, &tail_page->write);
89026 + local_sub_unchecked(length, &tail_page->write);
89027 return;
89028 }
89029
89030 @@ -2249,7 +2249,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
89031 rb_event_set_padding(event);
89032
89033 /* Set the write back to the previous setting */
89034 - local_sub(length, &tail_page->write);
89035 + local_sub_unchecked(length, &tail_page->write);
89036 return;
89037 }
89038
89039 @@ -2261,7 +2261,7 @@ rb_reset_tail(struct ring_buffer_per_cpu *cpu_buffer,
89040
89041 /* Set write to end of buffer */
89042 length = (tail + length) - BUF_PAGE_SIZE;
89043 - local_sub(length, &tail_page->write);
89044 + local_sub_unchecked(length, &tail_page->write);
89045 }
89046
89047 /*
89048 @@ -2287,7 +2287,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
89049 * about it.
89050 */
89051 if (unlikely(next_page == commit_page)) {
89052 - local_inc(&cpu_buffer->commit_overrun);
89053 + local_inc_unchecked(&cpu_buffer->commit_overrun);
89054 goto out_reset;
89055 }
89056
89057 @@ -2343,7 +2343,7 @@ rb_move_tail(struct ring_buffer_per_cpu *cpu_buffer,
89058 cpu_buffer->tail_page) &&
89059 (cpu_buffer->commit_page ==
89060 cpu_buffer->reader_page))) {
89061 - local_inc(&cpu_buffer->commit_overrun);
89062 + local_inc_unchecked(&cpu_buffer->commit_overrun);
89063 goto out_reset;
89064 }
89065 }
89066 @@ -2391,7 +2391,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
89067 length += RB_LEN_TIME_EXTEND;
89068
89069 tail_page = cpu_buffer->tail_page;
89070 - write = local_add_return(length, &tail_page->write);
89071 + write = local_add_return_unchecked(length, &tail_page->write);
89072
89073 /* set write to only the index of the write */
89074 write &= RB_WRITE_MASK;
89075 @@ -2408,7 +2408,7 @@ __rb_reserve_next(struct ring_buffer_per_cpu *cpu_buffer,
89076 kmemcheck_annotate_bitfield(event, bitfield);
89077 rb_update_event(cpu_buffer, event, length, add_timestamp, delta);
89078
89079 - local_inc(&tail_page->entries);
89080 + local_inc_unchecked(&tail_page->entries);
89081
89082 /*
89083 * If this is the first commit on the page, then update
89084 @@ -2441,7 +2441,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
89085
89086 if (bpage->page == (void *)addr && rb_page_write(bpage) == old_index) {
89087 unsigned long write_mask =
89088 - local_read(&bpage->write) & ~RB_WRITE_MASK;
89089 + local_read_unchecked(&bpage->write) & ~RB_WRITE_MASK;
89090 unsigned long event_length = rb_event_length(event);
89091 /*
89092 * This is on the tail page. It is possible that
89093 @@ -2451,7 +2451,7 @@ rb_try_to_discard(struct ring_buffer_per_cpu *cpu_buffer,
89094 */
89095 old_index += write_mask;
89096 new_index += write_mask;
89097 - index = local_cmpxchg(&bpage->write, old_index, new_index);
89098 + index = local_cmpxchg_unchecked(&bpage->write, old_index, new_index);
89099 if (index == old_index) {
89100 /* update counters */
89101 local_sub(event_length, &cpu_buffer->entries_bytes);
89102 @@ -2843,7 +2843,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
89103
89104 /* Do the likely case first */
89105 if (likely(bpage->page == (void *)addr)) {
89106 - local_dec(&bpage->entries);
89107 + local_dec_unchecked(&bpage->entries);
89108 return;
89109 }
89110
89111 @@ -2855,7 +2855,7 @@ rb_decrement_entry(struct ring_buffer_per_cpu *cpu_buffer,
89112 start = bpage;
89113 do {
89114 if (bpage->page == (void *)addr) {
89115 - local_dec(&bpage->entries);
89116 + local_dec_unchecked(&bpage->entries);
89117 return;
89118 }
89119 rb_inc_page(cpu_buffer, &bpage);
89120 @@ -3139,7 +3139,7 @@ static inline unsigned long
89121 rb_num_of_entries(struct ring_buffer_per_cpu *cpu_buffer)
89122 {
89123 return local_read(&cpu_buffer->entries) -
89124 - (local_read(&cpu_buffer->overrun) + cpu_buffer->read);
89125 + (local_read_unchecked(&cpu_buffer->overrun) + cpu_buffer->read);
89126 }
89127
89128 /**
89129 @@ -3228,7 +3228,7 @@ unsigned long ring_buffer_overrun_cpu(struct ring_buffer *buffer, int cpu)
89130 return 0;
89131
89132 cpu_buffer = buffer->buffers[cpu];
89133 - ret = local_read(&cpu_buffer->overrun);
89134 + ret = local_read_unchecked(&cpu_buffer->overrun);
89135
89136 return ret;
89137 }
89138 @@ -3251,7 +3251,7 @@ ring_buffer_commit_overrun_cpu(struct ring_buffer *buffer, int cpu)
89139 return 0;
89140
89141 cpu_buffer = buffer->buffers[cpu];
89142 - ret = local_read(&cpu_buffer->commit_overrun);
89143 + ret = local_read_unchecked(&cpu_buffer->commit_overrun);
89144
89145 return ret;
89146 }
89147 @@ -3336,7 +3336,7 @@ unsigned long ring_buffer_overruns(struct ring_buffer *buffer)
89148 /* if you care about this being correct, lock the buffer */
89149 for_each_buffer_cpu(buffer, cpu) {
89150 cpu_buffer = buffer->buffers[cpu];
89151 - overruns += local_read(&cpu_buffer->overrun);
89152 + overruns += local_read_unchecked(&cpu_buffer->overrun);
89153 }
89154
89155 return overruns;
89156 @@ -3512,8 +3512,8 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
89157 /*
89158 * Reset the reader page to size zero.
89159 */
89160 - local_set(&cpu_buffer->reader_page->write, 0);
89161 - local_set(&cpu_buffer->reader_page->entries, 0);
89162 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
89163 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
89164 local_set(&cpu_buffer->reader_page->page->commit, 0);
89165 cpu_buffer->reader_page->real_end = 0;
89166
89167 @@ -3547,7 +3547,7 @@ rb_get_reader_page(struct ring_buffer_per_cpu *cpu_buffer)
89168 * want to compare with the last_overrun.
89169 */
89170 smp_mb();
89171 - overwrite = local_read(&(cpu_buffer->overrun));
89172 + overwrite = local_read_unchecked(&(cpu_buffer->overrun));
89173
89174 /*
89175 * Here's the tricky part.
89176 @@ -4117,8 +4117,8 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
89177
89178 cpu_buffer->head_page
89179 = list_entry(cpu_buffer->pages, struct buffer_page, list);
89180 - local_set(&cpu_buffer->head_page->write, 0);
89181 - local_set(&cpu_buffer->head_page->entries, 0);
89182 + local_set_unchecked(&cpu_buffer->head_page->write, 0);
89183 + local_set_unchecked(&cpu_buffer->head_page->entries, 0);
89184 local_set(&cpu_buffer->head_page->page->commit, 0);
89185
89186 cpu_buffer->head_page->read = 0;
89187 @@ -4128,14 +4128,14 @@ rb_reset_cpu(struct ring_buffer_per_cpu *cpu_buffer)
89188
89189 INIT_LIST_HEAD(&cpu_buffer->reader_page->list);
89190 INIT_LIST_HEAD(&cpu_buffer->new_pages);
89191 - local_set(&cpu_buffer->reader_page->write, 0);
89192 - local_set(&cpu_buffer->reader_page->entries, 0);
89193 + local_set_unchecked(&cpu_buffer->reader_page->write, 0);
89194 + local_set_unchecked(&cpu_buffer->reader_page->entries, 0);
89195 local_set(&cpu_buffer->reader_page->page->commit, 0);
89196 cpu_buffer->reader_page->read = 0;
89197
89198 local_set(&cpu_buffer->entries_bytes, 0);
89199 - local_set(&cpu_buffer->overrun, 0);
89200 - local_set(&cpu_buffer->commit_overrun, 0);
89201 + local_set_unchecked(&cpu_buffer->overrun, 0);
89202 + local_set_unchecked(&cpu_buffer->commit_overrun, 0);
89203 local_set(&cpu_buffer->dropped_events, 0);
89204 local_set(&cpu_buffer->entries, 0);
89205 local_set(&cpu_buffer->committing, 0);
89206 @@ -4540,8 +4540,8 @@ int ring_buffer_read_page(struct ring_buffer *buffer,
89207 rb_init_page(bpage);
89208 bpage = reader->page;
89209 reader->page = *data_page;
89210 - local_set(&reader->write, 0);
89211 - local_set(&reader->entries, 0);
89212 + local_set_unchecked(&reader->write, 0);
89213 + local_set_unchecked(&reader->entries, 0);
89214 reader->read = 0;
89215 *data_page = bpage;
89216
89217 diff --git a/kernel/trace/trace.c b/kernel/trace/trace.c
89218 index 0a360ce..7bd800e 100644
89219 --- a/kernel/trace/trace.c
89220 +++ b/kernel/trace/trace.c
89221 @@ -3352,7 +3352,7 @@ int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set)
89222 return 0;
89223 }
89224
89225 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled)
89226 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled)
89227 {
89228 /* do nothing if flag is already set */
89229 if (!!(trace_flags & mask) == !!enabled)
89230 diff --git a/kernel/trace/trace.h b/kernel/trace/trace.h
89231 index ea189e0..a5b48c4 100644
89232 --- a/kernel/trace/trace.h
89233 +++ b/kernel/trace/trace.h
89234 @@ -1040,7 +1040,7 @@ extern const char *__stop___tracepoint_str[];
89235 void trace_printk_init_buffers(void);
89236 void trace_printk_start_comm(void);
89237 int trace_keep_overwrite(struct tracer *tracer, u32 mask, int set);
89238 -int set_tracer_flag(struct trace_array *tr, unsigned int mask, int enabled);
89239 +int set_tracer_flag(struct trace_array *tr, unsigned long mask, int enabled);
89240
89241 /*
89242 * Normal trace_printk() and friends allocates special buffers
89243 diff --git a/kernel/trace/trace_clock.c b/kernel/trace/trace_clock.c
89244 index 26dc348..8708ca7 100644
89245 --- a/kernel/trace/trace_clock.c
89246 +++ b/kernel/trace/trace_clock.c
89247 @@ -123,7 +123,7 @@ u64 notrace trace_clock_global(void)
89248 return now;
89249 }
89250
89251 -static atomic64_t trace_counter;
89252 +static atomic64_unchecked_t trace_counter;
89253
89254 /*
89255 * trace_clock_counter(): simply an atomic counter.
89256 @@ -132,5 +132,5 @@ static atomic64_t trace_counter;
89257 */
89258 u64 notrace trace_clock_counter(void)
89259 {
89260 - return atomic64_add_return(1, &trace_counter);
89261 + return atomic64_inc_return_unchecked(&trace_counter);
89262 }
89263 diff --git a/kernel/trace/trace_events.c b/kernel/trace/trace_events.c
89264 index a11800a..3dafde5 100644
89265 --- a/kernel/trace/trace_events.c
89266 +++ b/kernel/trace/trace_events.c
89267 @@ -1681,7 +1681,6 @@ __trace_early_add_new_event(struct ftrace_event_call *call,
89268 return 0;
89269 }
89270
89271 -struct ftrace_module_file_ops;
89272 static void __add_event_to_tracers(struct ftrace_event_call *call);
89273
89274 /* Add an additional event_call dynamically */
89275 diff --git a/kernel/trace/trace_mmiotrace.c b/kernel/trace/trace_mmiotrace.c
89276 index 0abd9b8..6a663a2 100644
89277 --- a/kernel/trace/trace_mmiotrace.c
89278 +++ b/kernel/trace/trace_mmiotrace.c
89279 @@ -24,7 +24,7 @@ struct header_iter {
89280 static struct trace_array *mmio_trace_array;
89281 static bool overrun_detected;
89282 static unsigned long prev_overruns;
89283 -static atomic_t dropped_count;
89284 +static atomic_unchecked_t dropped_count;
89285
89286 static void mmio_reset_data(struct trace_array *tr)
89287 {
89288 @@ -127,7 +127,7 @@ static void mmio_close(struct trace_iterator *iter)
89289
89290 static unsigned long count_overruns(struct trace_iterator *iter)
89291 {
89292 - unsigned long cnt = atomic_xchg(&dropped_count, 0);
89293 + unsigned long cnt = atomic_xchg_unchecked(&dropped_count, 0);
89294 unsigned long over = ring_buffer_overruns(iter->trace_buffer->buffer);
89295
89296 if (over > prev_overruns)
89297 @@ -317,7 +317,7 @@ static void __trace_mmiotrace_rw(struct trace_array *tr,
89298 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_RW,
89299 sizeof(*entry), 0, pc);
89300 if (!event) {
89301 - atomic_inc(&dropped_count);
89302 + atomic_inc_unchecked(&dropped_count);
89303 return;
89304 }
89305 entry = ring_buffer_event_data(event);
89306 @@ -347,7 +347,7 @@ static void __trace_mmiotrace_map(struct trace_array *tr,
89307 event = trace_buffer_lock_reserve(buffer, TRACE_MMIO_MAP,
89308 sizeof(*entry), 0, pc);
89309 if (!event) {
89310 - atomic_inc(&dropped_count);
89311 + atomic_inc_unchecked(&dropped_count);
89312 return;
89313 }
89314 entry = ring_buffer_event_data(event);
89315 diff --git a/kernel/trace/trace_output.c b/kernel/trace/trace_output.c
89316 index ed32284..884d6c3 100644
89317 --- a/kernel/trace/trace_output.c
89318 +++ b/kernel/trace/trace_output.c
89319 @@ -294,7 +294,7 @@ int trace_seq_path(struct trace_seq *s, const struct path *path)
89320
89321 p = d_path(path, s->buffer + s->len, PAGE_SIZE - s->len);
89322 if (!IS_ERR(p)) {
89323 - p = mangle_path(s->buffer + s->len, p, "\n");
89324 + p = mangle_path(s->buffer + s->len, p, "\n\\");
89325 if (p) {
89326 s->len = p - s->buffer;
89327 return 1;
89328 @@ -908,14 +908,16 @@ int register_ftrace_event(struct trace_event *event)
89329 goto out;
89330 }
89331
89332 + pax_open_kernel();
89333 if (event->funcs->trace == NULL)
89334 - event->funcs->trace = trace_nop_print;
89335 + *(void **)&event->funcs->trace = trace_nop_print;
89336 if (event->funcs->raw == NULL)
89337 - event->funcs->raw = trace_nop_print;
89338 + *(void **)&event->funcs->raw = trace_nop_print;
89339 if (event->funcs->hex == NULL)
89340 - event->funcs->hex = trace_nop_print;
89341 + *(void **)&event->funcs->hex = trace_nop_print;
89342 if (event->funcs->binary == NULL)
89343 - event->funcs->binary = trace_nop_print;
89344 + *(void **)&event->funcs->binary = trace_nop_print;
89345 + pax_close_kernel();
89346
89347 key = event->type & (EVENT_HASHSIZE - 1);
89348
89349 diff --git a/kernel/trace/trace_stack.c b/kernel/trace/trace_stack.c
89350 index b20428c..4845a10 100644
89351 --- a/kernel/trace/trace_stack.c
89352 +++ b/kernel/trace/trace_stack.c
89353 @@ -68,7 +68,7 @@ check_stack(unsigned long ip, unsigned long *stack)
89354 return;
89355
89356 /* we do not handle interrupt stacks yet */
89357 - if (!object_is_on_stack(stack))
89358 + if (!object_starts_on_stack(stack))
89359 return;
89360
89361 local_irq_save(flags);
89362 diff --git a/kernel/user_namespace.c b/kernel/user_namespace.c
89363 index 240fb62..583473e 100644
89364 --- a/kernel/user_namespace.c
89365 +++ b/kernel/user_namespace.c
89366 @@ -82,6 +82,21 @@ int create_user_ns(struct cred *new)
89367 !kgid_has_mapping(parent_ns, group))
89368 return -EPERM;
89369
89370 +#ifdef CONFIG_GRKERNSEC
89371 + /*
89372 + * This doesn't really inspire confidence:
89373 + * http://marc.info/?l=linux-kernel&m=135543612731939&w=2
89374 + * http://marc.info/?l=linux-kernel&m=135545831607095&w=2
89375 + * Increases kernel attack surface in areas developers
89376 + * previously cared little about ("low importance due
89377 + * to requiring "root" capability")
89378 + * To be removed when this code receives *proper* review
89379 + */
89380 + if (!capable(CAP_SYS_ADMIN) || !capable(CAP_SETUID) ||
89381 + !capable(CAP_SETGID))
89382 + return -EPERM;
89383 +#endif
89384 +
89385 ns = kmem_cache_zalloc(user_ns_cachep, GFP_KERNEL);
89386 if (!ns)
89387 return -ENOMEM;
89388 @@ -866,7 +881,7 @@ static int userns_install(struct nsproxy *nsproxy, void *ns)
89389 if (atomic_read(&current->mm->mm_users) > 1)
89390 return -EINVAL;
89391
89392 - if (current->fs->users != 1)
89393 + if (atomic_read(&current->fs->users) != 1)
89394 return -EINVAL;
89395
89396 if (!ns_capable(user_ns, CAP_SYS_ADMIN))
89397 diff --git a/kernel/utsname_sysctl.c b/kernel/utsname_sysctl.c
89398 index 4f69f9a..7c6f8f8 100644
89399 --- a/kernel/utsname_sysctl.c
89400 +++ b/kernel/utsname_sysctl.c
89401 @@ -47,7 +47,7 @@ static void put_uts(ctl_table *table, int write, void *which)
89402 static int proc_do_uts_string(ctl_table *table, int write,
89403 void __user *buffer, size_t *lenp, loff_t *ppos)
89404 {
89405 - struct ctl_table uts_table;
89406 + ctl_table_no_const uts_table;
89407 int r;
89408 memcpy(&uts_table, table, sizeof(uts_table));
89409 uts_table.data = get_uts(table, write);
89410 diff --git a/kernel/watchdog.c b/kernel/watchdog.c
89411 index 4431610..4265616 100644
89412 --- a/kernel/watchdog.c
89413 +++ b/kernel/watchdog.c
89414 @@ -475,7 +475,7 @@ static int watchdog_nmi_enable(unsigned int cpu) { return 0; }
89415 static void watchdog_nmi_disable(unsigned int cpu) { return; }
89416 #endif /* CONFIG_HARDLOCKUP_DETECTOR */
89417
89418 -static struct smp_hotplug_thread watchdog_threads = {
89419 +static struct smp_hotplug_thread watchdog_threads __read_only = {
89420 .store = &softlockup_watchdog,
89421 .thread_should_run = watchdog_should_run,
89422 .thread_fn = watchdog,
89423 diff --git a/kernel/workqueue.c b/kernel/workqueue.c
89424 index b010eac..e4bda78 100644
89425 --- a/kernel/workqueue.c
89426 +++ b/kernel/workqueue.c
89427 @@ -4671,7 +4671,7 @@ static void rebind_workers(struct worker_pool *pool)
89428 WARN_ON_ONCE(!(worker_flags & WORKER_UNBOUND));
89429 worker_flags |= WORKER_REBOUND;
89430 worker_flags &= ~WORKER_UNBOUND;
89431 - ACCESS_ONCE(worker->flags) = worker_flags;
89432 + ACCESS_ONCE_RW(worker->flags) = worker_flags;
89433 }
89434
89435 spin_unlock_irq(&pool->lock);
89436 diff --git a/lib/Kconfig.debug b/lib/Kconfig.debug
89437 index db25707..8b16430 100644
89438 --- a/lib/Kconfig.debug
89439 +++ b/lib/Kconfig.debug
89440 @@ -845,7 +845,7 @@ config DEBUG_MUTEXES
89441
89442 config DEBUG_WW_MUTEX_SLOWPATH
89443 bool "Wait/wound mutex debugging: Slowpath testing"
89444 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
89445 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
89446 select DEBUG_LOCK_ALLOC
89447 select DEBUG_SPINLOCK
89448 select DEBUG_MUTEXES
89449 @@ -858,7 +858,7 @@ config DEBUG_WW_MUTEX_SLOWPATH
89450
89451 config DEBUG_LOCK_ALLOC
89452 bool "Lock debugging: detect incorrect freeing of live locks"
89453 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
89454 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
89455 select DEBUG_SPINLOCK
89456 select DEBUG_MUTEXES
89457 select LOCKDEP
89458 @@ -872,7 +872,7 @@ config DEBUG_LOCK_ALLOC
89459
89460 config PROVE_LOCKING
89461 bool "Lock debugging: prove locking correctness"
89462 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
89463 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
89464 select LOCKDEP
89465 select DEBUG_SPINLOCK
89466 select DEBUG_MUTEXES
89467 @@ -923,7 +923,7 @@ config LOCKDEP
89468
89469 config LOCK_STAT
89470 bool "Lock usage statistics"
89471 - depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT
89472 + depends on DEBUG_KERNEL && TRACE_IRQFLAGS_SUPPORT && STACKTRACE_SUPPORT && LOCKDEP_SUPPORT && !PAX_CONSTIFY_PLUGIN
89473 select LOCKDEP
89474 select DEBUG_SPINLOCK
89475 select DEBUG_MUTEXES
89476 @@ -1385,6 +1385,7 @@ config LATENCYTOP
89477 depends on DEBUG_KERNEL
89478 depends on STACKTRACE_SUPPORT
89479 depends on PROC_FS
89480 + depends on !GRKERNSEC_HIDESYM
89481 select FRAME_POINTER if !MIPS && !PPC && !S390 && !MICROBLAZE && !ARM_UNWIND && !ARC
89482 select KALLSYMS
89483 select KALLSYMS_ALL
89484 @@ -1401,7 +1402,7 @@ config ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
89485 config DEBUG_STRICT_USER_COPY_CHECKS
89486 bool "Strict user copy size checks"
89487 depends on ARCH_HAS_DEBUG_STRICT_USER_COPY_CHECKS
89488 - depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING
89489 + depends on DEBUG_KERNEL && !TRACE_BRANCH_PROFILING && !PAX_SIZE_OVERFLOW
89490 help
89491 Enabling this option turns a certain set of sanity checks for user
89492 copy operations into compile time failures.
89493 @@ -1520,7 +1521,7 @@ endmenu # runtime tests
89494
89495 config PROVIDE_OHCI1394_DMA_INIT
89496 bool "Remote debugging over FireWire early on boot"
89497 - depends on PCI && X86
89498 + depends on PCI && X86 && !GRKERNSEC
89499 help
89500 If you want to debug problems which hang or crash the kernel early
89501 on boot and the crashing machine has a FireWire port, you can use
89502 @@ -1549,7 +1550,7 @@ config PROVIDE_OHCI1394_DMA_INIT
89503
89504 config FIREWIRE_OHCI_REMOTE_DMA
89505 bool "Remote debugging over FireWire with firewire-ohci"
89506 - depends on FIREWIRE_OHCI
89507 + depends on FIREWIRE_OHCI && !GRKERNSEC
89508 help
89509 This option lets you use the FireWire bus for remote debugging
89510 with help of the firewire-ohci driver. It enables unfiltered
89511 diff --git a/lib/Makefile b/lib/Makefile
89512 index a459c31..3320e82 100644
89513 --- a/lib/Makefile
89514 +++ b/lib/Makefile
89515 @@ -49,7 +49,7 @@ obj-$(CONFIG_GENERIC_HWEIGHT) += hweight.o
89516 obj-$(CONFIG_BTREE) += btree.o
89517 obj-$(CONFIG_ASSOCIATIVE_ARRAY) += assoc_array.o
89518 obj-$(CONFIG_DEBUG_PREEMPT) += smp_processor_id.o
89519 -obj-$(CONFIG_DEBUG_LIST) += list_debug.o
89520 +obj-y += list_debug.o
89521 obj-$(CONFIG_DEBUG_OBJECTS) += debugobjects.o
89522
89523 ifneq ($(CONFIG_HAVE_DEC_LOCK),y)
89524 diff --git a/lib/bitmap.c b/lib/bitmap.c
89525 index 06f7e4f..f3cf2b0 100644
89526 --- a/lib/bitmap.c
89527 +++ b/lib/bitmap.c
89528 @@ -422,7 +422,7 @@ int __bitmap_parse(const char *buf, unsigned int buflen,
89529 {
89530 int c, old_c, totaldigits, ndigits, nchunks, nbits;
89531 u32 chunk;
89532 - const char __user __force *ubuf = (const char __user __force *)buf;
89533 + const char __user *ubuf = (const char __force_user *)buf;
89534
89535 bitmap_zero(maskp, nmaskbits);
89536
89537 @@ -507,7 +507,7 @@ int bitmap_parse_user(const char __user *ubuf,
89538 {
89539 if (!access_ok(VERIFY_READ, ubuf, ulen))
89540 return -EFAULT;
89541 - return __bitmap_parse((const char __force *)ubuf,
89542 + return __bitmap_parse((const char __force_kernel *)ubuf,
89543 ulen, 1, maskp, nmaskbits);
89544
89545 }
89546 @@ -598,7 +598,7 @@ static int __bitmap_parselist(const char *buf, unsigned int buflen,
89547 {
89548 unsigned a, b;
89549 int c, old_c, totaldigits;
89550 - const char __user __force *ubuf = (const char __user __force *)buf;
89551 + const char __user *ubuf = (const char __force_user *)buf;
89552 int exp_digit, in_range;
89553
89554 totaldigits = c = 0;
89555 @@ -698,7 +698,7 @@ int bitmap_parselist_user(const char __user *ubuf,
89556 {
89557 if (!access_ok(VERIFY_READ, ubuf, ulen))
89558 return -EFAULT;
89559 - return __bitmap_parselist((const char __force *)ubuf,
89560 + return __bitmap_parselist((const char __force_kernel *)ubuf,
89561 ulen, 1, maskp, nmaskbits);
89562 }
89563 EXPORT_SYMBOL(bitmap_parselist_user);
89564 diff --git a/lib/bug.c b/lib/bug.c
89565 index 1686034..a9c00c8 100644
89566 --- a/lib/bug.c
89567 +++ b/lib/bug.c
89568 @@ -134,6 +134,8 @@ enum bug_trap_type report_bug(unsigned long bugaddr, struct pt_regs *regs)
89569 return BUG_TRAP_TYPE_NONE;
89570
89571 bug = find_bug(bugaddr);
89572 + if (!bug)
89573 + return BUG_TRAP_TYPE_NONE;
89574
89575 file = NULL;
89576 line = 0;
89577 diff --git a/lib/debugobjects.c b/lib/debugobjects.c
89578 index e0731c3..ad66444 100644
89579 --- a/lib/debugobjects.c
89580 +++ b/lib/debugobjects.c
89581 @@ -286,7 +286,7 @@ static void debug_object_is_on_stack(void *addr, int onstack)
89582 if (limit > 4)
89583 return;
89584
89585 - is_on_stack = object_is_on_stack(addr);
89586 + is_on_stack = object_starts_on_stack(addr);
89587 if (is_on_stack == onstack)
89588 return;
89589
89590 diff --git a/lib/devres.c b/lib/devres.c
89591 index 8235331..5881053 100644
89592 --- a/lib/devres.c
89593 +++ b/lib/devres.c
89594 @@ -81,7 +81,7 @@ EXPORT_SYMBOL(devm_ioremap_nocache);
89595 void devm_iounmap(struct device *dev, void __iomem *addr)
89596 {
89597 WARN_ON(devres_destroy(dev, devm_ioremap_release, devm_ioremap_match,
89598 - (void *)addr));
89599 + (void __force *)addr));
89600 iounmap(addr);
89601 }
89602 EXPORT_SYMBOL(devm_iounmap);
89603 @@ -224,7 +224,7 @@ void devm_ioport_unmap(struct device *dev, void __iomem *addr)
89604 {
89605 ioport_unmap(addr);
89606 WARN_ON(devres_destroy(dev, devm_ioport_map_release,
89607 - devm_ioport_map_match, (void *)addr));
89608 + devm_ioport_map_match, (void __force *)addr));
89609 }
89610 EXPORT_SYMBOL(devm_ioport_unmap);
89611 #endif /* CONFIG_HAS_IOPORT */
89612 diff --git a/lib/div64.c b/lib/div64.c
89613 index 4382ad7..08aa558 100644
89614 --- a/lib/div64.c
89615 +++ b/lib/div64.c
89616 @@ -59,7 +59,7 @@ uint32_t __attribute__((weak)) __div64_32(uint64_t *n, uint32_t base)
89617 EXPORT_SYMBOL(__div64_32);
89618
89619 #ifndef div_s64_rem
89620 -s64 div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
89621 +s64 __intentional_overflow(-1) div_s64_rem(s64 dividend, s32 divisor, s32 *remainder)
89622 {
89623 u64 quotient;
89624
89625 @@ -130,7 +130,7 @@ EXPORT_SYMBOL(div64_u64_rem);
89626 * 'http://www.hackersdelight.org/HDcode/newCode/divDouble.c.txt'
89627 */
89628 #ifndef div64_u64
89629 -u64 div64_u64(u64 dividend, u64 divisor)
89630 +u64 __intentional_overflow(-1) div64_u64(u64 dividend, u64 divisor)
89631 {
89632 u32 high = divisor >> 32;
89633 u64 quot;
89634 diff --git a/lib/dma-debug.c b/lib/dma-debug.c
89635 index d87a17a..ac0d79a 100644
89636 --- a/lib/dma-debug.c
89637 +++ b/lib/dma-debug.c
89638 @@ -768,7 +768,7 @@ static int dma_debug_device_change(struct notifier_block *nb, unsigned long acti
89639
89640 void dma_debug_add_bus(struct bus_type *bus)
89641 {
89642 - struct notifier_block *nb;
89643 + notifier_block_no_const *nb;
89644
89645 if (global_disable)
89646 return;
89647 @@ -945,7 +945,7 @@ static void check_unmap(struct dma_debug_entry *ref)
89648
89649 static void check_for_stack(struct device *dev, void *addr)
89650 {
89651 - if (object_is_on_stack(addr))
89652 + if (object_starts_on_stack(addr))
89653 err_printk(dev, NULL, "DMA-API: device driver maps memory from"
89654 "stack [addr=%p]\n", addr);
89655 }
89656 diff --git a/lib/inflate.c b/lib/inflate.c
89657 index 013a761..c28f3fc 100644
89658 --- a/lib/inflate.c
89659 +++ b/lib/inflate.c
89660 @@ -269,7 +269,7 @@ static void free(void *where)
89661 malloc_ptr = free_mem_ptr;
89662 }
89663 #else
89664 -#define malloc(a) kmalloc(a, GFP_KERNEL)
89665 +#define malloc(a) kmalloc((a), GFP_KERNEL)
89666 #define free(a) kfree(a)
89667 #endif
89668
89669 diff --git a/lib/ioremap.c b/lib/ioremap.c
89670 index 0c9216c..863bd89 100644
89671 --- a/lib/ioremap.c
89672 +++ b/lib/ioremap.c
89673 @@ -38,7 +38,7 @@ static inline int ioremap_pmd_range(pud_t *pud, unsigned long addr,
89674 unsigned long next;
89675
89676 phys_addr -= addr;
89677 - pmd = pmd_alloc(&init_mm, pud, addr);
89678 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
89679 if (!pmd)
89680 return -ENOMEM;
89681 do {
89682 @@ -56,7 +56,7 @@ static inline int ioremap_pud_range(pgd_t *pgd, unsigned long addr,
89683 unsigned long next;
89684
89685 phys_addr -= addr;
89686 - pud = pud_alloc(&init_mm, pgd, addr);
89687 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
89688 if (!pud)
89689 return -ENOMEM;
89690 do {
89691 diff --git a/lib/is_single_threaded.c b/lib/is_single_threaded.c
89692 index bd2bea9..6b3c95e 100644
89693 --- a/lib/is_single_threaded.c
89694 +++ b/lib/is_single_threaded.c
89695 @@ -22,6 +22,9 @@ bool current_is_single_threaded(void)
89696 struct task_struct *p, *t;
89697 bool ret;
89698
89699 + if (!mm)
89700 + return true;
89701 +
89702 if (atomic_read(&task->signal->live) != 1)
89703 return false;
89704
89705 diff --git a/lib/kobject.c b/lib/kobject.c
89706 index 5b4b888..c2950f7 100644
89707 --- a/lib/kobject.c
89708 +++ b/lib/kobject.c
89709 @@ -957,9 +957,9 @@ EXPORT_SYMBOL_GPL(kset_create_and_add);
89710
89711
89712 static DEFINE_SPINLOCK(kobj_ns_type_lock);
89713 -static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES];
89714 +static const struct kobj_ns_type_operations *kobj_ns_ops_tbl[KOBJ_NS_TYPES] __read_only;
89715
89716 -int kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
89717 +int __init kobj_ns_type_register(const struct kobj_ns_type_operations *ops)
89718 {
89719 enum kobj_ns_type type = ops->type;
89720 int error;
89721 diff --git a/lib/list_debug.c b/lib/list_debug.c
89722 index c24c2f7..f0296f4 100644
89723 --- a/lib/list_debug.c
89724 +++ b/lib/list_debug.c
89725 @@ -11,7 +11,9 @@
89726 #include <linux/bug.h>
89727 #include <linux/kernel.h>
89728 #include <linux/rculist.h>
89729 +#include <linux/mm.h>
89730
89731 +#ifdef CONFIG_DEBUG_LIST
89732 /*
89733 * Insert a new entry between two known consecutive entries.
89734 *
89735 @@ -19,21 +21,40 @@
89736 * the prev/next entries already!
89737 */
89738
89739 +static bool __list_add_debug(struct list_head *new,
89740 + struct list_head *prev,
89741 + struct list_head *next)
89742 +{
89743 + if (unlikely(next->prev != prev)) {
89744 + printk(KERN_ERR "list_add corruption. next->prev should be "
89745 + "prev (%p), but was %p. (next=%p).\n",
89746 + prev, next->prev, next);
89747 + BUG();
89748 + return false;
89749 + }
89750 + if (unlikely(prev->next != next)) {
89751 + printk(KERN_ERR "list_add corruption. prev->next should be "
89752 + "next (%p), but was %p. (prev=%p).\n",
89753 + next, prev->next, prev);
89754 + BUG();
89755 + return false;
89756 + }
89757 + if (unlikely(new == prev || new == next)) {
89758 + printk(KERN_ERR "list_add double add: new=%p, prev=%p, next=%p.\n",
89759 + new, prev, next);
89760 + BUG();
89761 + return false;
89762 + }
89763 + return true;
89764 +}
89765 +
89766 void __list_add(struct list_head *new,
89767 - struct list_head *prev,
89768 - struct list_head *next)
89769 + struct list_head *prev,
89770 + struct list_head *next)
89771 {
89772 - WARN(next->prev != prev,
89773 - "list_add corruption. next->prev should be "
89774 - "prev (%p), but was %p. (next=%p).\n",
89775 - prev, next->prev, next);
89776 - WARN(prev->next != next,
89777 - "list_add corruption. prev->next should be "
89778 - "next (%p), but was %p. (prev=%p).\n",
89779 - next, prev->next, prev);
89780 - WARN(new == prev || new == next,
89781 - "list_add double add: new=%p, prev=%p, next=%p.\n",
89782 - new, prev, next);
89783 + if (!__list_add_debug(new, prev, next))
89784 + return;
89785 +
89786 next->prev = new;
89787 new->next = next;
89788 new->prev = prev;
89789 @@ -41,28 +62,46 @@ void __list_add(struct list_head *new,
89790 }
89791 EXPORT_SYMBOL(__list_add);
89792
89793 -void __list_del_entry(struct list_head *entry)
89794 +static bool __list_del_entry_debug(struct list_head *entry)
89795 {
89796 struct list_head *prev, *next;
89797
89798 prev = entry->prev;
89799 next = entry->next;
89800
89801 - if (WARN(next == LIST_POISON1,
89802 - "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
89803 - entry, LIST_POISON1) ||
89804 - WARN(prev == LIST_POISON2,
89805 - "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
89806 - entry, LIST_POISON2) ||
89807 - WARN(prev->next != entry,
89808 - "list_del corruption. prev->next should be %p, "
89809 - "but was %p\n", entry, prev->next) ||
89810 - WARN(next->prev != entry,
89811 - "list_del corruption. next->prev should be %p, "
89812 - "but was %p\n", entry, next->prev))
89813 + if (unlikely(next == LIST_POISON1)) {
89814 + printk(KERN_ERR "list_del corruption, %p->next is LIST_POISON1 (%p)\n",
89815 + entry, LIST_POISON1);
89816 + BUG();
89817 + return false;
89818 + }
89819 + if (unlikely(prev == LIST_POISON2)) {
89820 + printk(KERN_ERR "list_del corruption, %p->prev is LIST_POISON2 (%p)\n",
89821 + entry, LIST_POISON2);
89822 + BUG();
89823 + return false;
89824 + }
89825 + if (unlikely(entry->prev->next != entry)) {
89826 + printk(KERN_ERR "list_del corruption. prev->next should be %p, "
89827 + "but was %p\n", entry, prev->next);
89828 + BUG();
89829 + return false;
89830 + }
89831 + if (unlikely(entry->next->prev != entry)) {
89832 + printk(KERN_ERR "list_del corruption. next->prev should be %p, "
89833 + "but was %p\n", entry, next->prev);
89834 + BUG();
89835 + return false;
89836 + }
89837 + return true;
89838 +}
89839 +
89840 +void __list_del_entry(struct list_head *entry)
89841 +{
89842 + if (!__list_del_entry_debug(entry))
89843 return;
89844
89845 - __list_del(prev, next);
89846 + __list_del(entry->prev, entry->next);
89847 }
89848 EXPORT_SYMBOL(__list_del_entry);
89849
89850 @@ -86,15 +125,85 @@ EXPORT_SYMBOL(list_del);
89851 void __list_add_rcu(struct list_head *new,
89852 struct list_head *prev, struct list_head *next)
89853 {
89854 - WARN(next->prev != prev,
89855 - "list_add_rcu corruption. next->prev should be prev (%p), but was %p. (next=%p).\n",
89856 - prev, next->prev, next);
89857 - WARN(prev->next != next,
89858 - "list_add_rcu corruption. prev->next should be next (%p), but was %p. (prev=%p).\n",
89859 - next, prev->next, prev);
89860 + if (!__list_add_debug(new, prev, next))
89861 + return;
89862 +
89863 new->next = next;
89864 new->prev = prev;
89865 rcu_assign_pointer(list_next_rcu(prev), new);
89866 next->prev = new;
89867 }
89868 EXPORT_SYMBOL(__list_add_rcu);
89869 +#endif
89870 +
89871 +void __pax_list_add(struct list_head *new, struct list_head *prev, struct list_head *next)
89872 +{
89873 +#ifdef CONFIG_DEBUG_LIST
89874 + if (!__list_add_debug(new, prev, next))
89875 + return;
89876 +#endif
89877 +
89878 + pax_open_kernel();
89879 + next->prev = new;
89880 + new->next = next;
89881 + new->prev = prev;
89882 + prev->next = new;
89883 + pax_close_kernel();
89884 +}
89885 +EXPORT_SYMBOL(__pax_list_add);
89886 +
89887 +void pax_list_del(struct list_head *entry)
89888 +{
89889 +#ifdef CONFIG_DEBUG_LIST
89890 + if (!__list_del_entry_debug(entry))
89891 + return;
89892 +#endif
89893 +
89894 + pax_open_kernel();
89895 + __list_del(entry->prev, entry->next);
89896 + entry->next = LIST_POISON1;
89897 + entry->prev = LIST_POISON2;
89898 + pax_close_kernel();
89899 +}
89900 +EXPORT_SYMBOL(pax_list_del);
89901 +
89902 +void pax_list_del_init(struct list_head *entry)
89903 +{
89904 + pax_open_kernel();
89905 + __list_del(entry->prev, entry->next);
89906 + INIT_LIST_HEAD(entry);
89907 + pax_close_kernel();
89908 +}
89909 +EXPORT_SYMBOL(pax_list_del_init);
89910 +
89911 +void __pax_list_add_rcu(struct list_head *new,
89912 + struct list_head *prev, struct list_head *next)
89913 +{
89914 +#ifdef CONFIG_DEBUG_LIST
89915 + if (!__list_add_debug(new, prev, next))
89916 + return;
89917 +#endif
89918 +
89919 + pax_open_kernel();
89920 + new->next = next;
89921 + new->prev = prev;
89922 + rcu_assign_pointer(list_next_rcu(prev), new);
89923 + next->prev = new;
89924 + pax_close_kernel();
89925 +}
89926 +EXPORT_SYMBOL(__pax_list_add_rcu);
89927 +
89928 +void pax_list_del_rcu(struct list_head *entry)
89929 +{
89930 +#ifdef CONFIG_DEBUG_LIST
89931 + if (!__list_del_entry_debug(entry))
89932 + return;
89933 +#endif
89934 +
89935 + pax_open_kernel();
89936 + __list_del(entry->prev, entry->next);
89937 + entry->next = LIST_POISON1;
89938 + entry->prev = LIST_POISON2;
89939 + pax_close_kernel();
89940 +}
89941 +EXPORT_SYMBOL(pax_list_del_rcu);
89942 diff --git a/lib/percpu-refcount.c b/lib/percpu-refcount.c
89943 index 1a53d49..ace934c 100644
89944 --- a/lib/percpu-refcount.c
89945 +++ b/lib/percpu-refcount.c
89946 @@ -29,7 +29,7 @@
89947 * can't hit 0 before we've added up all the percpu refs.
89948 */
89949
89950 -#define PCPU_COUNT_BIAS (1U << 31)
89951 +#define PCPU_COUNT_BIAS (1U << 30)
89952
89953 /**
89954 * percpu_ref_init - initialize a percpu refcount
89955 diff --git a/lib/radix-tree.c b/lib/radix-tree.c
89956 index 7811ed3..f80ca19 100644
89957 --- a/lib/radix-tree.c
89958 +++ b/lib/radix-tree.c
89959 @@ -93,7 +93,7 @@ struct radix_tree_preload {
89960 int nr;
89961 struct radix_tree_node *nodes[RADIX_TREE_PRELOAD_SIZE];
89962 };
89963 -static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads) = { 0, };
89964 +static DEFINE_PER_CPU(struct radix_tree_preload, radix_tree_preloads);
89965
89966 static inline void *ptr_to_indirect(void *ptr)
89967 {
89968 diff --git a/lib/rbtree.c b/lib/rbtree.c
89969 index 65f4eff..2cfa167 100644
89970 --- a/lib/rbtree.c
89971 +++ b/lib/rbtree.c
89972 @@ -380,7 +380,9 @@ static inline void dummy_copy(struct rb_node *old, struct rb_node *new) {}
89973 static inline void dummy_rotate(struct rb_node *old, struct rb_node *new) {}
89974
89975 static const struct rb_augment_callbacks dummy_callbacks = {
89976 - dummy_propagate, dummy_copy, dummy_rotate
89977 + .propagate = dummy_propagate,
89978 + .copy = dummy_copy,
89979 + .rotate = dummy_rotate
89980 };
89981
89982 void rb_insert_color(struct rb_node *node, struct rb_root *root)
89983 diff --git a/lib/strncpy_from_user.c b/lib/strncpy_from_user.c
89984 index bb2b201..46abaf9 100644
89985 --- a/lib/strncpy_from_user.c
89986 +++ b/lib/strncpy_from_user.c
89987 @@ -21,7 +21,7 @@
89988 */
89989 static inline long do_strncpy_from_user(char *dst, const char __user *src, long count, unsigned long max)
89990 {
89991 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
89992 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
89993 long res = 0;
89994
89995 /*
89996 diff --git a/lib/strnlen_user.c b/lib/strnlen_user.c
89997 index a28df52..3d55877 100644
89998 --- a/lib/strnlen_user.c
89999 +++ b/lib/strnlen_user.c
90000 @@ -26,7 +26,7 @@
90001 */
90002 static inline long do_strnlen_user(const char __user *src, unsigned long count, unsigned long max)
90003 {
90004 - const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
90005 + static const struct word_at_a_time constants = WORD_AT_A_TIME_CONSTANTS;
90006 long align, res = 0;
90007 unsigned long c;
90008
90009 diff --git a/lib/swiotlb.c b/lib/swiotlb.c
90010 index e4399fa..5e8b214 100644
90011 --- a/lib/swiotlb.c
90012 +++ b/lib/swiotlb.c
90013 @@ -668,7 +668,7 @@ EXPORT_SYMBOL(swiotlb_alloc_coherent);
90014
90015 void
90016 swiotlb_free_coherent(struct device *hwdev, size_t size, void *vaddr,
90017 - dma_addr_t dev_addr)
90018 + dma_addr_t dev_addr, struct dma_attrs *attrs)
90019 {
90020 phys_addr_t paddr = dma_to_phys(hwdev, dev_addr);
90021
90022 diff --git a/lib/usercopy.c b/lib/usercopy.c
90023 index 4f5b1dd..7cab418 100644
90024 --- a/lib/usercopy.c
90025 +++ b/lib/usercopy.c
90026 @@ -7,3 +7,9 @@ void copy_from_user_overflow(void)
90027 WARN(1, "Buffer overflow detected!\n");
90028 }
90029 EXPORT_SYMBOL(copy_from_user_overflow);
90030 +
90031 +void copy_to_user_overflow(void)
90032 +{
90033 + WARN(1, "Buffer overflow detected!\n");
90034 +}
90035 +EXPORT_SYMBOL(copy_to_user_overflow);
90036 diff --git a/lib/vsprintf.c b/lib/vsprintf.c
90037 index 10909c5..653e1b8 100644
90038 --- a/lib/vsprintf.c
90039 +++ b/lib/vsprintf.c
90040 @@ -16,6 +16,9 @@
90041 * - scnprintf and vscnprintf
90042 */
90043
90044 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90045 +#define __INCLUDED_BY_HIDESYM 1
90046 +#endif
90047 #include <stdarg.h>
90048 #include <linux/module.h> /* for KSYM_SYMBOL_LEN */
90049 #include <linux/types.h>
90050 @@ -1155,7 +1158,11 @@ char *netdev_feature_string(char *buf, char *end, const u8 *addr,
90051 return number(buf, end, *(const netdev_features_t *)addr, spec);
90052 }
90053
90054 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90055 +int kptr_restrict __read_mostly = 2;
90056 +#else
90057 int kptr_restrict __read_mostly;
90058 +#endif
90059
90060 /*
90061 * Show a '%p' thing. A kernel extension is that the '%p' is followed
90062 @@ -1168,6 +1175,7 @@ int kptr_restrict __read_mostly;
90063 * - 'f' For simple symbolic function names without offset
90064 * - 'S' For symbolic direct pointers with offset
90065 * - 's' For symbolic direct pointers without offset
90066 + * - 'A' For symbolic direct pointers with offset approved for use with GRKERNSEC_HIDESYM
90067 * - '[FfSs]R' as above with __builtin_extract_return_addr() translation
90068 * - 'B' For backtraced symbolic direct pointers with offset
90069 * - 'R' For decoded struct resource, e.g., [mem 0x0-0x1f 64bit pref]
90070 @@ -1234,12 +1242,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
90071
90072 if (!ptr && *fmt != 'K') {
90073 /*
90074 - * Print (null) with the same width as a pointer so it makes
90075 + * Print (nil) with the same width as a pointer so it makes
90076 * tabular output look nice.
90077 */
90078 if (spec.field_width == -1)
90079 spec.field_width = default_width;
90080 - return string(buf, end, "(null)", spec);
90081 + return string(buf, end, "(nil)", spec);
90082 }
90083
90084 switch (*fmt) {
90085 @@ -1249,6 +1257,12 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
90086 /* Fallthrough */
90087 case 'S':
90088 case 's':
90089 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90090 + break;
90091 +#else
90092 + return symbol_string(buf, end, ptr, spec, fmt);
90093 +#endif
90094 + case 'A':
90095 case 'B':
90096 return symbol_string(buf, end, ptr, spec, fmt);
90097 case 'R':
90098 @@ -1304,6 +1318,8 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
90099 va_end(va);
90100 return buf;
90101 }
90102 + case 'P':
90103 + break;
90104 case 'K':
90105 /*
90106 * %pK cannot be used in IRQ context because its test
90107 @@ -1365,6 +1381,21 @@ char *pointer(const char *fmt, char *buf, char *end, void *ptr,
90108 ((const struct file *)ptr)->f_path.dentry,
90109 spec, fmt);
90110 }
90111 +
90112 +#ifdef CONFIG_GRKERNSEC_HIDESYM
90113 + /* 'P' = approved pointers to copy to userland,
90114 + as in the /proc/kallsyms case, as we make it display nothing
90115 + for non-root users, and the real contents for root users
90116 + Also ignore 'K' pointers, since we force their NULLing for non-root users
90117 + above
90118 + */
90119 + if ((unsigned long)ptr > TASK_SIZE && *fmt != 'P' && *fmt != 'K' && is_usercopy_object(buf)) {
90120 + printk(KERN_ALERT "grsec: kernel infoleak detected! Please report this log to spender@grsecurity.net.\n");
90121 + dump_stack();
90122 + ptr = NULL;
90123 + }
90124 +#endif
90125 +
90126 spec.flags |= SMALL;
90127 if (spec.field_width == -1) {
90128 spec.field_width = default_width;
90129 @@ -2086,11 +2117,11 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
90130 typeof(type) value; \
90131 if (sizeof(type) == 8) { \
90132 args = PTR_ALIGN(args, sizeof(u32)); \
90133 - *(u32 *)&value = *(u32 *)args; \
90134 - *((u32 *)&value + 1) = *(u32 *)(args + 4); \
90135 + *(u32 *)&value = *(const u32 *)args; \
90136 + *((u32 *)&value + 1) = *(const u32 *)(args + 4); \
90137 } else { \
90138 args = PTR_ALIGN(args, sizeof(type)); \
90139 - value = *(typeof(type) *)args; \
90140 + value = *(const typeof(type) *)args; \
90141 } \
90142 args += sizeof(type); \
90143 value; \
90144 @@ -2153,7 +2184,7 @@ int bstr_printf(char *buf, size_t size, const char *fmt, const u32 *bin_buf)
90145 case FORMAT_TYPE_STR: {
90146 const char *str_arg = args;
90147 args += strlen(str_arg) + 1;
90148 - str = string(str, end, (char *)str_arg, spec);
90149 + str = string(str, end, str_arg, spec);
90150 break;
90151 }
90152
90153 diff --git a/localversion-grsec b/localversion-grsec
90154 new file mode 100644
90155 index 0000000..7cd6065
90156 --- /dev/null
90157 +++ b/localversion-grsec
90158 @@ -0,0 +1 @@
90159 +-grsec
90160 diff --git a/mm/Kconfig b/mm/Kconfig
90161 index 723bbe0..ea624b1 100644
90162 --- a/mm/Kconfig
90163 +++ b/mm/Kconfig
90164 @@ -326,10 +326,11 @@ config KSM
90165 root has set /sys/kernel/mm/ksm/run to 1 (if CONFIG_SYSFS is set).
90166
90167 config DEFAULT_MMAP_MIN_ADDR
90168 - int "Low address space to protect from user allocation"
90169 + int "Low address space to protect from user allocation"
90170 depends on MMU
90171 - default 4096
90172 - help
90173 + default 32768 if ALPHA || ARM || PARISC || SPARC32
90174 + default 65536
90175 + help
90176 This is the portion of low virtual memory which should be protected
90177 from userspace allocation. Keeping a user from writing to low pages
90178 can help reduce the impact of kernel NULL pointer bugs.
90179 @@ -360,7 +361,7 @@ config MEMORY_FAILURE
90180
90181 config HWPOISON_INJECT
90182 tristate "HWPoison pages injector"
90183 - depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS
90184 + depends on MEMORY_FAILURE && DEBUG_KERNEL && PROC_FS && !GRKERNSEC
90185 select PROC_PAGE_MONITOR
90186
90187 config NOMMU_INITIAL_TRIM_EXCESS
90188 diff --git a/mm/backing-dev.c b/mm/backing-dev.c
90189 index ce682f7..1fb54f9 100644
90190 --- a/mm/backing-dev.c
90191 +++ b/mm/backing-dev.c
90192 @@ -12,7 +12,7 @@
90193 #include <linux/device.h>
90194 #include <trace/events/writeback.h>
90195
90196 -static atomic_long_t bdi_seq = ATOMIC_LONG_INIT(0);
90197 +static atomic_long_unchecked_t bdi_seq = ATOMIC_LONG_INIT(0);
90198
90199 struct backing_dev_info default_backing_dev_info = {
90200 .name = "default",
90201 @@ -525,7 +525,7 @@ int bdi_setup_and_register(struct backing_dev_info *bdi, char *name,
90202 return err;
90203
90204 err = bdi_register(bdi, NULL, "%.28s-%ld", name,
90205 - atomic_long_inc_return(&bdi_seq));
90206 + atomic_long_inc_return_unchecked(&bdi_seq));
90207 if (err) {
90208 bdi_destroy(bdi);
90209 return err;
90210 diff --git a/mm/filemap.c b/mm/filemap.c
90211 index b7749a9..50d1123 100644
90212 --- a/mm/filemap.c
90213 +++ b/mm/filemap.c
90214 @@ -1768,7 +1768,7 @@ int generic_file_mmap(struct file * file, struct vm_area_struct * vma)
90215 struct address_space *mapping = file->f_mapping;
90216
90217 if (!mapping->a_ops->readpage)
90218 - return -ENOEXEC;
90219 + return -ENODEV;
90220 file_accessed(file);
90221 vma->vm_ops = &generic_file_vm_ops;
90222 return 0;
90223 @@ -1950,7 +1950,7 @@ static size_t __iovec_copy_from_user_inatomic(char *vaddr,
90224
90225 while (bytes) {
90226 char __user *buf = iov->iov_base + base;
90227 - int copy = min(bytes, iov->iov_len - base);
90228 + size_t copy = min(bytes, iov->iov_len - base);
90229
90230 base = 0;
90231 left = __copy_from_user_inatomic(vaddr, buf, copy);
90232 @@ -1979,7 +1979,7 @@ size_t iov_iter_copy_from_user_atomic(struct page *page,
90233 BUG_ON(!in_atomic());
90234 kaddr = kmap_atomic(page);
90235 if (likely(i->nr_segs == 1)) {
90236 - int left;
90237 + size_t left;
90238 char __user *buf = i->iov->iov_base + i->iov_offset;
90239 left = __copy_from_user_inatomic(kaddr + offset, buf, bytes);
90240 copied = bytes - left;
90241 @@ -2007,7 +2007,7 @@ size_t iov_iter_copy_from_user(struct page *page,
90242
90243 kaddr = kmap(page);
90244 if (likely(i->nr_segs == 1)) {
90245 - int left;
90246 + size_t left;
90247 char __user *buf = i->iov->iov_base + i->iov_offset;
90248 left = __copy_from_user(kaddr + offset, buf, bytes);
90249 copied = bytes - left;
90250 @@ -2037,7 +2037,7 @@ void iov_iter_advance(struct iov_iter *i, size_t bytes)
90251 * zero-length segments (without overruning the iovec).
90252 */
90253 while (bytes || unlikely(i->count && !iov->iov_len)) {
90254 - int copy;
90255 + size_t copy;
90256
90257 copy = min(bytes, iov->iov_len - base);
90258 BUG_ON(!i->count || i->count < copy);
90259 @@ -2108,6 +2108,7 @@ inline int generic_write_checks(struct file *file, loff_t *pos, size_t *count, i
90260 *pos = i_size_read(inode);
90261
90262 if (limit != RLIM_INFINITY) {
90263 + gr_learn_resource(current, RLIMIT_FSIZE,*pos, 0);
90264 if (*pos >= limit) {
90265 send_sig(SIGXFSZ, current, 0);
90266 return -EFBIG;
90267 diff --git a/mm/fremap.c b/mm/fremap.c
90268 index bbc4d66..117b798 100644
90269 --- a/mm/fremap.c
90270 +++ b/mm/fremap.c
90271 @@ -163,6 +163,11 @@ SYSCALL_DEFINE5(remap_file_pages, unsigned long, start, unsigned long, size,
90272 retry:
90273 vma = find_vma(mm, start);
90274
90275 +#ifdef CONFIG_PAX_SEGMEXEC
90276 + if (vma && (mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_MAYEXEC))
90277 + goto out;
90278 +#endif
90279 +
90280 /*
90281 * Make sure the vma is shared, that it supports prefaulting,
90282 * and that the remapped range is valid and fully within
90283 diff --git a/mm/highmem.c b/mm/highmem.c
90284 index b32b70c..e512eb0 100644
90285 --- a/mm/highmem.c
90286 +++ b/mm/highmem.c
90287 @@ -138,8 +138,9 @@ static void flush_all_zero_pkmaps(void)
90288 * So no dangers, even with speculative execution.
90289 */
90290 page = pte_page(pkmap_page_table[i]);
90291 + pax_open_kernel();
90292 pte_clear(&init_mm, PKMAP_ADDR(i), &pkmap_page_table[i]);
90293 -
90294 + pax_close_kernel();
90295 set_page_address(page, NULL);
90296 need_flush = 1;
90297 }
90298 @@ -198,9 +199,11 @@ start:
90299 }
90300 }
90301 vaddr = PKMAP_ADDR(last_pkmap_nr);
90302 +
90303 + pax_open_kernel();
90304 set_pte_at(&init_mm, vaddr,
90305 &(pkmap_page_table[last_pkmap_nr]), mk_pte(page, kmap_prot));
90306 -
90307 + pax_close_kernel();
90308 pkmap_count[last_pkmap_nr] = 1;
90309 set_page_address(page, (void *)vaddr);
90310
90311 diff --git a/mm/hugetlb.c b/mm/hugetlb.c
90312 index dee6cf4..52b94f7 100644
90313 --- a/mm/hugetlb.c
90314 +++ b/mm/hugetlb.c
90315 @@ -2077,15 +2077,17 @@ static int hugetlb_sysctl_handler_common(bool obey_mempolicy,
90316 struct hstate *h = &default_hstate;
90317 unsigned long tmp;
90318 int ret;
90319 + ctl_table_no_const hugetlb_table;
90320
90321 tmp = h->max_huge_pages;
90322
90323 if (write && h->order >= MAX_ORDER)
90324 return -EINVAL;
90325
90326 - table->data = &tmp;
90327 - table->maxlen = sizeof(unsigned long);
90328 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
90329 + hugetlb_table = *table;
90330 + hugetlb_table.data = &tmp;
90331 + hugetlb_table.maxlen = sizeof(unsigned long);
90332 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
90333 if (ret)
90334 goto out;
90335
90336 @@ -2130,15 +2132,17 @@ int hugetlb_overcommit_handler(struct ctl_table *table, int write,
90337 struct hstate *h = &default_hstate;
90338 unsigned long tmp;
90339 int ret;
90340 + ctl_table_no_const hugetlb_table;
90341
90342 tmp = h->nr_overcommit_huge_pages;
90343
90344 if (write && h->order >= MAX_ORDER)
90345 return -EINVAL;
90346
90347 - table->data = &tmp;
90348 - table->maxlen = sizeof(unsigned long);
90349 - ret = proc_doulongvec_minmax(table, write, buffer, length, ppos);
90350 + hugetlb_table = *table;
90351 + hugetlb_table.data = &tmp;
90352 + hugetlb_table.maxlen = sizeof(unsigned long);
90353 + ret = proc_doulongvec_minmax(&hugetlb_table, write, buffer, length, ppos);
90354 if (ret)
90355 goto out;
90356
90357 @@ -2596,6 +2600,27 @@ static int unmap_ref_private(struct mm_struct *mm, struct vm_area_struct *vma,
90358 return 1;
90359 }
90360
90361 +#ifdef CONFIG_PAX_SEGMEXEC
90362 +static void pax_mirror_huge_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m)
90363 +{
90364 + struct mm_struct *mm = vma->vm_mm;
90365 + struct vm_area_struct *vma_m;
90366 + unsigned long address_m;
90367 + pte_t *ptep_m;
90368 +
90369 + vma_m = pax_find_mirror_vma(vma);
90370 + if (!vma_m)
90371 + return;
90372 +
90373 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90374 + address_m = address + SEGMEXEC_TASK_SIZE;
90375 + ptep_m = huge_pte_offset(mm, address_m & HPAGE_MASK);
90376 + get_page(page_m);
90377 + hugepage_add_anon_rmap(page_m, vma_m, address_m);
90378 + set_huge_pte_at(mm, address_m, ptep_m, make_huge_pte(vma_m, page_m, 0));
90379 +}
90380 +#endif
90381 +
90382 /*
90383 * Hugetlb_cow() should be called with page lock of the original hugepage held.
90384 * Called with hugetlb_instantiation_mutex held and pte_page locked so we
90385 @@ -2712,6 +2737,11 @@ retry_avoidcopy:
90386 make_huge_pte(vma, new_page, 1));
90387 page_remove_rmap(old_page);
90388 hugepage_add_new_anon_rmap(new_page, vma, address);
90389 +
90390 +#ifdef CONFIG_PAX_SEGMEXEC
90391 + pax_mirror_huge_pte(vma, address, new_page);
90392 +#endif
90393 +
90394 /* Make the old page be freed below */
90395 new_page = old_page;
90396 }
90397 @@ -2876,6 +2906,10 @@ retry:
90398 && (vma->vm_flags & VM_SHARED)));
90399 set_huge_pte_at(mm, address, ptep, new_pte);
90400
90401 +#ifdef CONFIG_PAX_SEGMEXEC
90402 + pax_mirror_huge_pte(vma, address, page);
90403 +#endif
90404 +
90405 if ((flags & FAULT_FLAG_WRITE) && !(vma->vm_flags & VM_SHARED)) {
90406 /* Optimization, do the COW without a second fault */
90407 ret = hugetlb_cow(mm, vma, address, ptep, new_pte, page, ptl);
90408 @@ -2906,6 +2940,10 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
90409 static DEFINE_MUTEX(hugetlb_instantiation_mutex);
90410 struct hstate *h = hstate_vma(vma);
90411
90412 +#ifdef CONFIG_PAX_SEGMEXEC
90413 + struct vm_area_struct *vma_m;
90414 +#endif
90415 +
90416 address &= huge_page_mask(h);
90417
90418 ptep = huge_pte_offset(mm, address);
90419 @@ -2919,6 +2957,26 @@ int hugetlb_fault(struct mm_struct *mm, struct vm_area_struct *vma,
90420 VM_FAULT_SET_HINDEX(hstate_index(h));
90421 }
90422
90423 +#ifdef CONFIG_PAX_SEGMEXEC
90424 + vma_m = pax_find_mirror_vma(vma);
90425 + if (vma_m) {
90426 + unsigned long address_m;
90427 +
90428 + if (vma->vm_start > vma_m->vm_start) {
90429 + address_m = address;
90430 + address -= SEGMEXEC_TASK_SIZE;
90431 + vma = vma_m;
90432 + h = hstate_vma(vma);
90433 + } else
90434 + address_m = address + SEGMEXEC_TASK_SIZE;
90435 +
90436 + if (!huge_pte_alloc(mm, address_m, huge_page_size(h)))
90437 + return VM_FAULT_OOM;
90438 + address_m &= HPAGE_MASK;
90439 + unmap_hugepage_range(vma, address_m, address_m + HPAGE_SIZE, NULL);
90440 + }
90441 +#endif
90442 +
90443 ptep = huge_pte_alloc(mm, address, huge_page_size(h));
90444 if (!ptep)
90445 return VM_FAULT_OOM;
90446 diff --git a/mm/internal.h b/mm/internal.h
90447 index 8b6cfd6..ec809a6 100644
90448 --- a/mm/internal.h
90449 +++ b/mm/internal.h
90450 @@ -96,6 +96,7 @@ extern pmd_t *mm_find_pmd(struct mm_struct *mm, unsigned long address);
90451 * in mm/page_alloc.c
90452 */
90453 extern void __free_pages_bootmem(struct page *page, unsigned int order);
90454 +extern void free_compound_page(struct page *page);
90455 extern void prep_compound_page(struct page *page, unsigned long order);
90456 #ifdef CONFIG_MEMORY_FAILURE
90457 extern bool is_free_buddy_page(struct page *page);
90458 @@ -351,7 +352,7 @@ extern u32 hwpoison_filter_enable;
90459
90460 extern unsigned long vm_mmap_pgoff(struct file *, unsigned long,
90461 unsigned long, unsigned long,
90462 - unsigned long, unsigned long);
90463 + unsigned long, unsigned long) __intentional_overflow(-1);
90464
90465 extern void set_pageblock_order(void);
90466 unsigned long reclaim_clean_pages_from_list(struct zone *zone,
90467 diff --git a/mm/kmemleak.c b/mm/kmemleak.c
90468 index 31f01c5..7015178 100644
90469 --- a/mm/kmemleak.c
90470 +++ b/mm/kmemleak.c
90471 @@ -363,7 +363,7 @@ static void print_unreferenced(struct seq_file *seq,
90472
90473 for (i = 0; i < object->trace_len; i++) {
90474 void *ptr = (void *)object->trace[i];
90475 - seq_printf(seq, " [<%p>] %pS\n", ptr, ptr);
90476 + seq_printf(seq, " [<%pP>] %pA\n", ptr, ptr);
90477 }
90478 }
90479
90480 @@ -1853,7 +1853,7 @@ static int __init kmemleak_late_init(void)
90481 return -ENOMEM;
90482 }
90483
90484 - dentry = debugfs_create_file("kmemleak", S_IRUGO, NULL, NULL,
90485 + dentry = debugfs_create_file("kmemleak", S_IRUSR, NULL, NULL,
90486 &kmemleak_fops);
90487 if (!dentry)
90488 pr_warning("Failed to create the debugfs kmemleak file\n");
90489 diff --git a/mm/maccess.c b/mm/maccess.c
90490 index d53adf9..03a24bf 100644
90491 --- a/mm/maccess.c
90492 +++ b/mm/maccess.c
90493 @@ -26,7 +26,7 @@ long __probe_kernel_read(void *dst, const void *src, size_t size)
90494 set_fs(KERNEL_DS);
90495 pagefault_disable();
90496 ret = __copy_from_user_inatomic(dst,
90497 - (__force const void __user *)src, size);
90498 + (const void __force_user *)src, size);
90499 pagefault_enable();
90500 set_fs(old_fs);
90501
90502 @@ -53,7 +53,7 @@ long __probe_kernel_write(void *dst, const void *src, size_t size)
90503
90504 set_fs(KERNEL_DS);
90505 pagefault_disable();
90506 - ret = __copy_to_user_inatomic((__force void __user *)dst, src, size);
90507 + ret = __copy_to_user_inatomic((void __force_user *)dst, src, size);
90508 pagefault_enable();
90509 set_fs(old_fs);
90510
90511 diff --git a/mm/madvise.c b/mm/madvise.c
90512 index 539eeb9..e24a987 100644
90513 --- a/mm/madvise.c
90514 +++ b/mm/madvise.c
90515 @@ -51,6 +51,10 @@ static long madvise_behavior(struct vm_area_struct *vma,
90516 pgoff_t pgoff;
90517 unsigned long new_flags = vma->vm_flags;
90518
90519 +#ifdef CONFIG_PAX_SEGMEXEC
90520 + struct vm_area_struct *vma_m;
90521 +#endif
90522 +
90523 switch (behavior) {
90524 case MADV_NORMAL:
90525 new_flags = new_flags & ~VM_RAND_READ & ~VM_SEQ_READ;
90526 @@ -126,6 +130,13 @@ success:
90527 /*
90528 * vm_flags is protected by the mmap_sem held in write mode.
90529 */
90530 +
90531 +#ifdef CONFIG_PAX_SEGMEXEC
90532 + vma_m = pax_find_mirror_vma(vma);
90533 + if (vma_m)
90534 + vma_m->vm_flags = new_flags & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT);
90535 +#endif
90536 +
90537 vma->vm_flags = new_flags;
90538
90539 out:
90540 @@ -274,6 +285,11 @@ static long madvise_dontneed(struct vm_area_struct *vma,
90541 struct vm_area_struct **prev,
90542 unsigned long start, unsigned long end)
90543 {
90544 +
90545 +#ifdef CONFIG_PAX_SEGMEXEC
90546 + struct vm_area_struct *vma_m;
90547 +#endif
90548 +
90549 *prev = vma;
90550 if (vma->vm_flags & (VM_LOCKED|VM_HUGETLB|VM_PFNMAP))
90551 return -EINVAL;
90552 @@ -286,6 +302,21 @@ static long madvise_dontneed(struct vm_area_struct *vma,
90553 zap_page_range(vma, start, end - start, &details);
90554 } else
90555 zap_page_range(vma, start, end - start, NULL);
90556 +
90557 +#ifdef CONFIG_PAX_SEGMEXEC
90558 + vma_m = pax_find_mirror_vma(vma);
90559 + if (vma_m) {
90560 + if (unlikely(vma->vm_flags & VM_NONLINEAR)) {
90561 + struct zap_details details = {
90562 + .nonlinear_vma = vma_m,
90563 + .last_index = ULONG_MAX,
90564 + };
90565 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, &details);
90566 + } else
90567 + zap_page_range(vma, start + SEGMEXEC_TASK_SIZE, end - start, NULL);
90568 + }
90569 +#endif
90570 +
90571 return 0;
90572 }
90573
90574 @@ -491,6 +522,16 @@ SYSCALL_DEFINE3(madvise, unsigned long, start, size_t, len_in, int, behavior)
90575 if (end < start)
90576 return error;
90577
90578 +#ifdef CONFIG_PAX_SEGMEXEC
90579 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
90580 + if (end > SEGMEXEC_TASK_SIZE)
90581 + return error;
90582 + } else
90583 +#endif
90584 +
90585 + if (end > TASK_SIZE)
90586 + return error;
90587 +
90588 error = 0;
90589 if (end == start)
90590 return error;
90591 diff --git a/mm/memory-failure.c b/mm/memory-failure.c
90592 index 6420be5..b7b7c8f 100644
90593 --- a/mm/memory-failure.c
90594 +++ b/mm/memory-failure.c
90595 @@ -61,7 +61,7 @@ int sysctl_memory_failure_early_kill __read_mostly = 0;
90596
90597 int sysctl_memory_failure_recovery __read_mostly = 1;
90598
90599 -atomic_long_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
90600 +atomic_long_unchecked_t num_poisoned_pages __read_mostly = ATOMIC_LONG_INIT(0);
90601
90602 #if defined(CONFIG_HWPOISON_INJECT) || defined(CONFIG_HWPOISON_INJECT_MODULE)
90603
90604 @@ -202,7 +202,7 @@ static int kill_proc(struct task_struct *t, unsigned long addr, int trapno,
90605 pfn, t->comm, t->pid);
90606 si.si_signo = SIGBUS;
90607 si.si_errno = 0;
90608 - si.si_addr = (void *)addr;
90609 + si.si_addr = (void __user *)addr;
90610 #ifdef __ARCH_SI_TRAPNO
90611 si.si_trapno = trapno;
90612 #endif
90613 @@ -762,7 +762,7 @@ static struct page_state {
90614 unsigned long res;
90615 char *msg;
90616 int (*action)(struct page *p, unsigned long pfn);
90617 -} error_states[] = {
90618 +} __do_const error_states[] = {
90619 { reserved, reserved, "reserved kernel", me_kernel },
90620 /*
90621 * free pages are specially detected outside this table:
90622 @@ -1060,7 +1060,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
90623 nr_pages = 1 << compound_order(hpage);
90624 else /* normal page or thp */
90625 nr_pages = 1;
90626 - atomic_long_add(nr_pages, &num_poisoned_pages);
90627 + atomic_long_add_unchecked(nr_pages, &num_poisoned_pages);
90628
90629 /*
90630 * We need/can do nothing about count=0 pages.
90631 @@ -1090,7 +1090,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
90632 if (!PageHWPoison(hpage)
90633 || (hwpoison_filter(p) && TestClearPageHWPoison(p))
90634 || (p != hpage && TestSetPageHWPoison(hpage))) {
90635 - atomic_long_sub(nr_pages, &num_poisoned_pages);
90636 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
90637 return 0;
90638 }
90639 set_page_hwpoison_huge_page(hpage);
90640 @@ -1159,7 +1159,7 @@ int memory_failure(unsigned long pfn, int trapno, int flags)
90641 }
90642 if (hwpoison_filter(p)) {
90643 if (TestClearPageHWPoison(p))
90644 - atomic_long_sub(nr_pages, &num_poisoned_pages);
90645 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
90646 unlock_page(hpage);
90647 put_page(hpage);
90648 return 0;
90649 @@ -1381,7 +1381,7 @@ int unpoison_memory(unsigned long pfn)
90650 return 0;
90651 }
90652 if (TestClearPageHWPoison(p))
90653 - atomic_long_dec(&num_poisoned_pages);
90654 + atomic_long_dec_unchecked(&num_poisoned_pages);
90655 pr_info("MCE: Software-unpoisoned free page %#lx\n", pfn);
90656 return 0;
90657 }
90658 @@ -1395,7 +1395,7 @@ int unpoison_memory(unsigned long pfn)
90659 */
90660 if (TestClearPageHWPoison(page)) {
90661 pr_info("MCE: Software-unpoisoned page %#lx\n", pfn);
90662 - atomic_long_sub(nr_pages, &num_poisoned_pages);
90663 + atomic_long_sub_unchecked(nr_pages, &num_poisoned_pages);
90664 freeit = 1;
90665 if (PageHuge(page))
90666 clear_page_hwpoison_huge_page(page);
90667 @@ -1520,11 +1520,11 @@ static int soft_offline_huge_page(struct page *page, int flags)
90668 if (PageHuge(page)) {
90669 set_page_hwpoison_huge_page(hpage);
90670 dequeue_hwpoisoned_huge_page(hpage);
90671 - atomic_long_add(1 << compound_order(hpage),
90672 + atomic_long_add_unchecked(1 << compound_order(hpage),
90673 &num_poisoned_pages);
90674 } else {
90675 SetPageHWPoison(page);
90676 - atomic_long_inc(&num_poisoned_pages);
90677 + atomic_long_inc_unchecked(&num_poisoned_pages);
90678 }
90679 }
90680 return ret;
90681 @@ -1563,7 +1563,7 @@ static int __soft_offline_page(struct page *page, int flags)
90682 put_page(page);
90683 pr_info("soft_offline: %#lx: invalidated\n", pfn);
90684 SetPageHWPoison(page);
90685 - atomic_long_inc(&num_poisoned_pages);
90686 + atomic_long_inc_unchecked(&num_poisoned_pages);
90687 return 0;
90688 }
90689
90690 @@ -1608,7 +1608,7 @@ static int __soft_offline_page(struct page *page, int flags)
90691 if (!is_free_buddy_page(page))
90692 pr_info("soft offline: %#lx: page leaked\n",
90693 pfn);
90694 - atomic_long_inc(&num_poisoned_pages);
90695 + atomic_long_inc_unchecked(&num_poisoned_pages);
90696 }
90697 } else {
90698 pr_info("soft offline: %#lx: isolation failed: %d, page count %d, type %lx\n",
90699 @@ -1682,11 +1682,11 @@ int soft_offline_page(struct page *page, int flags)
90700 if (PageHuge(page)) {
90701 set_page_hwpoison_huge_page(hpage);
90702 dequeue_hwpoisoned_huge_page(hpage);
90703 - atomic_long_add(1 << compound_order(hpage),
90704 + atomic_long_add_unchecked(1 << compound_order(hpage),
90705 &num_poisoned_pages);
90706 } else {
90707 SetPageHWPoison(page);
90708 - atomic_long_inc(&num_poisoned_pages);
90709 + atomic_long_inc_unchecked(&num_poisoned_pages);
90710 }
90711 }
90712 unset_migratetype_isolate(page, MIGRATE_MOVABLE);
90713 diff --git a/mm/memory.c b/mm/memory.c
90714 index 6768ce9..4c41d69 100644
90715 --- a/mm/memory.c
90716 +++ b/mm/memory.c
90717 @@ -402,6 +402,7 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
90718 free_pte_range(tlb, pmd, addr);
90719 } while (pmd++, addr = next, addr != end);
90720
90721 +#if !defined(CONFIG_X86_32) || !defined(CONFIG_PAX_PER_CPU_PGD)
90722 start &= PUD_MASK;
90723 if (start < floor)
90724 return;
90725 @@ -416,6 +417,8 @@ static inline void free_pmd_range(struct mmu_gather *tlb, pud_t *pud,
90726 pmd = pmd_offset(pud, start);
90727 pud_clear(pud);
90728 pmd_free_tlb(tlb, pmd, start);
90729 +#endif
90730 +
90731 }
90732
90733 static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
90734 @@ -435,6 +438,7 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
90735 free_pmd_range(tlb, pud, addr, next, floor, ceiling);
90736 } while (pud++, addr = next, addr != end);
90737
90738 +#if !defined(CONFIG_X86_64) || !defined(CONFIG_PAX_PER_CPU_PGD)
90739 start &= PGDIR_MASK;
90740 if (start < floor)
90741 return;
90742 @@ -449,6 +453,8 @@ static inline void free_pud_range(struct mmu_gather *tlb, pgd_t *pgd,
90743 pud = pud_offset(pgd, start);
90744 pgd_clear(pgd);
90745 pud_free_tlb(tlb, pud, start);
90746 +#endif
90747 +
90748 }
90749
90750 /*
90751 @@ -1635,12 +1641,6 @@ no_page_table:
90752 return page;
90753 }
90754
90755 -static inline int stack_guard_page(struct vm_area_struct *vma, unsigned long addr)
90756 -{
90757 - return stack_guard_page_start(vma, addr) ||
90758 - stack_guard_page_end(vma, addr+PAGE_SIZE);
90759 -}
90760 -
90761 /**
90762 * __get_user_pages() - pin user pages in memory
90763 * @tsk: task_struct of target task
90764 @@ -1727,10 +1727,10 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
90765
90766 i = 0;
90767
90768 - do {
90769 + while (nr_pages) {
90770 struct vm_area_struct *vma;
90771
90772 - vma = find_extend_vma(mm, start);
90773 + vma = find_vma(mm, start);
90774 if (!vma && in_gate_area(mm, start)) {
90775 unsigned long pg = start & PAGE_MASK;
90776 pgd_t *pgd;
90777 @@ -1779,7 +1779,7 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
90778 goto next_page;
90779 }
90780
90781 - if (!vma ||
90782 + if (!vma || start < vma->vm_start ||
90783 (vma->vm_flags & (VM_IO | VM_PFNMAP)) ||
90784 !(vm_flags & vma->vm_flags))
90785 return i ? : -EFAULT;
90786 @@ -1808,11 +1808,6 @@ long __get_user_pages(struct task_struct *tsk, struct mm_struct *mm,
90787 int ret;
90788 unsigned int fault_flags = 0;
90789
90790 - /* For mlock, just skip the stack guard page. */
90791 - if (foll_flags & FOLL_MLOCK) {
90792 - if (stack_guard_page(vma, start))
90793 - goto next_page;
90794 - }
90795 if (foll_flags & FOLL_WRITE)
90796 fault_flags |= FAULT_FLAG_WRITE;
90797 if (nonblocking)
90798 @@ -1892,7 +1887,7 @@ next_page:
90799 start += page_increm * PAGE_SIZE;
90800 nr_pages -= page_increm;
90801 } while (nr_pages && start < vma->vm_end);
90802 - } while (nr_pages);
90803 + }
90804 return i;
90805 }
90806 EXPORT_SYMBOL(__get_user_pages);
90807 @@ -2099,6 +2094,10 @@ static int insert_page(struct vm_area_struct *vma, unsigned long addr,
90808 page_add_file_rmap(page);
90809 set_pte_at(mm, addr, pte, mk_pte(page, prot));
90810
90811 +#ifdef CONFIG_PAX_SEGMEXEC
90812 + pax_mirror_file_pte(vma, addr, page, ptl);
90813 +#endif
90814 +
90815 retval = 0;
90816 pte_unmap_unlock(pte, ptl);
90817 return retval;
90818 @@ -2143,9 +2142,21 @@ int vm_insert_page(struct vm_area_struct *vma, unsigned long addr,
90819 if (!page_count(page))
90820 return -EINVAL;
90821 if (!(vma->vm_flags & VM_MIXEDMAP)) {
90822 +
90823 +#ifdef CONFIG_PAX_SEGMEXEC
90824 + struct vm_area_struct *vma_m;
90825 +#endif
90826 +
90827 BUG_ON(down_read_trylock(&vma->vm_mm->mmap_sem));
90828 BUG_ON(vma->vm_flags & VM_PFNMAP);
90829 vma->vm_flags |= VM_MIXEDMAP;
90830 +
90831 +#ifdef CONFIG_PAX_SEGMEXEC
90832 + vma_m = pax_find_mirror_vma(vma);
90833 + if (vma_m)
90834 + vma_m->vm_flags |= VM_MIXEDMAP;
90835 +#endif
90836 +
90837 }
90838 return insert_page(vma, addr, page, vma->vm_page_prot);
90839 }
90840 @@ -2228,6 +2239,7 @@ int vm_insert_mixed(struct vm_area_struct *vma, unsigned long addr,
90841 unsigned long pfn)
90842 {
90843 BUG_ON(!(vma->vm_flags & VM_MIXEDMAP));
90844 + BUG_ON(vma->vm_mirror);
90845
90846 if (addr < vma->vm_start || addr >= vma->vm_end)
90847 return -EFAULT;
90848 @@ -2475,7 +2487,9 @@ static int apply_to_pmd_range(struct mm_struct *mm, pud_t *pud,
90849
90850 BUG_ON(pud_huge(*pud));
90851
90852 - pmd = pmd_alloc(mm, pud, addr);
90853 + pmd = (mm == &init_mm) ?
90854 + pmd_alloc_kernel(mm, pud, addr) :
90855 + pmd_alloc(mm, pud, addr);
90856 if (!pmd)
90857 return -ENOMEM;
90858 do {
90859 @@ -2495,7 +2509,9 @@ static int apply_to_pud_range(struct mm_struct *mm, pgd_t *pgd,
90860 unsigned long next;
90861 int err;
90862
90863 - pud = pud_alloc(mm, pgd, addr);
90864 + pud = (mm == &init_mm) ?
90865 + pud_alloc_kernel(mm, pgd, addr) :
90866 + pud_alloc(mm, pgd, addr);
90867 if (!pud)
90868 return -ENOMEM;
90869 do {
90870 @@ -2583,6 +2599,186 @@ static inline void cow_user_page(struct page *dst, struct page *src, unsigned lo
90871 copy_user_highpage(dst, src, va, vma);
90872 }
90873
90874 +#ifdef CONFIG_PAX_SEGMEXEC
90875 +static void pax_unmap_mirror_pte(struct vm_area_struct *vma, unsigned long address, pmd_t *pmd)
90876 +{
90877 + struct mm_struct *mm = vma->vm_mm;
90878 + spinlock_t *ptl;
90879 + pte_t *pte, entry;
90880 +
90881 + pte = pte_offset_map_lock(mm, pmd, address, &ptl);
90882 + entry = *pte;
90883 + if (!pte_present(entry)) {
90884 + if (!pte_none(entry)) {
90885 + BUG_ON(pte_file(entry));
90886 + free_swap_and_cache(pte_to_swp_entry(entry));
90887 + pte_clear_not_present_full(mm, address, pte, 0);
90888 + }
90889 + } else {
90890 + struct page *page;
90891 +
90892 + flush_cache_page(vma, address, pte_pfn(entry));
90893 + entry = ptep_clear_flush(vma, address, pte);
90894 + BUG_ON(pte_dirty(entry));
90895 + page = vm_normal_page(vma, address, entry);
90896 + if (page) {
90897 + update_hiwater_rss(mm);
90898 + if (PageAnon(page))
90899 + dec_mm_counter_fast(mm, MM_ANONPAGES);
90900 + else
90901 + dec_mm_counter_fast(mm, MM_FILEPAGES);
90902 + page_remove_rmap(page);
90903 + page_cache_release(page);
90904 + }
90905 + }
90906 + pte_unmap_unlock(pte, ptl);
90907 +}
90908 +
90909 +/* PaX: if vma is mirrored, synchronize the mirror's PTE
90910 + *
90911 + * the ptl of the lower mapped page is held on entry and is not released on exit
90912 + * or inside to ensure atomic changes to the PTE states (swapout, mremap, munmap, etc)
90913 + */
90914 +static void pax_mirror_anon_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
90915 +{
90916 + struct mm_struct *mm = vma->vm_mm;
90917 + unsigned long address_m;
90918 + spinlock_t *ptl_m;
90919 + struct vm_area_struct *vma_m;
90920 + pmd_t *pmd_m;
90921 + pte_t *pte_m, entry_m;
90922 +
90923 + BUG_ON(!page_m || !PageAnon(page_m));
90924 +
90925 + vma_m = pax_find_mirror_vma(vma);
90926 + if (!vma_m)
90927 + return;
90928 +
90929 + BUG_ON(!PageLocked(page_m));
90930 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90931 + address_m = address + SEGMEXEC_TASK_SIZE;
90932 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
90933 + pte_m = pte_offset_map(pmd_m, address_m);
90934 + ptl_m = pte_lockptr(mm, pmd_m);
90935 + if (ptl != ptl_m) {
90936 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
90937 + if (!pte_none(*pte_m))
90938 + goto out;
90939 + }
90940 +
90941 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
90942 + page_cache_get(page_m);
90943 + page_add_anon_rmap(page_m, vma_m, address_m);
90944 + inc_mm_counter_fast(mm, MM_ANONPAGES);
90945 + set_pte_at(mm, address_m, pte_m, entry_m);
90946 + update_mmu_cache(vma_m, address_m, pte_m);
90947 +out:
90948 + if (ptl != ptl_m)
90949 + spin_unlock(ptl_m);
90950 + pte_unmap(pte_m);
90951 + unlock_page(page_m);
90952 +}
90953 +
90954 +void pax_mirror_file_pte(struct vm_area_struct *vma, unsigned long address, struct page *page_m, spinlock_t *ptl)
90955 +{
90956 + struct mm_struct *mm = vma->vm_mm;
90957 + unsigned long address_m;
90958 + spinlock_t *ptl_m;
90959 + struct vm_area_struct *vma_m;
90960 + pmd_t *pmd_m;
90961 + pte_t *pte_m, entry_m;
90962 +
90963 + BUG_ON(!page_m || PageAnon(page_m));
90964 +
90965 + vma_m = pax_find_mirror_vma(vma);
90966 + if (!vma_m)
90967 + return;
90968 +
90969 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
90970 + address_m = address + SEGMEXEC_TASK_SIZE;
90971 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
90972 + pte_m = pte_offset_map(pmd_m, address_m);
90973 + ptl_m = pte_lockptr(mm, pmd_m);
90974 + if (ptl != ptl_m) {
90975 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
90976 + if (!pte_none(*pte_m))
90977 + goto out;
90978 + }
90979 +
90980 + entry_m = pfn_pte(page_to_pfn(page_m), vma_m->vm_page_prot);
90981 + page_cache_get(page_m);
90982 + page_add_file_rmap(page_m);
90983 + inc_mm_counter_fast(mm, MM_FILEPAGES);
90984 + set_pte_at(mm, address_m, pte_m, entry_m);
90985 + update_mmu_cache(vma_m, address_m, pte_m);
90986 +out:
90987 + if (ptl != ptl_m)
90988 + spin_unlock(ptl_m);
90989 + pte_unmap(pte_m);
90990 +}
90991 +
90992 +static void pax_mirror_pfn_pte(struct vm_area_struct *vma, unsigned long address, unsigned long pfn_m, spinlock_t *ptl)
90993 +{
90994 + struct mm_struct *mm = vma->vm_mm;
90995 + unsigned long address_m;
90996 + spinlock_t *ptl_m;
90997 + struct vm_area_struct *vma_m;
90998 + pmd_t *pmd_m;
90999 + pte_t *pte_m, entry_m;
91000 +
91001 + vma_m = pax_find_mirror_vma(vma);
91002 + if (!vma_m)
91003 + return;
91004 +
91005 + BUG_ON(address >= SEGMEXEC_TASK_SIZE);
91006 + address_m = address + SEGMEXEC_TASK_SIZE;
91007 + pmd_m = pmd_offset(pud_offset(pgd_offset(mm, address_m), address_m), address_m);
91008 + pte_m = pte_offset_map(pmd_m, address_m);
91009 + ptl_m = pte_lockptr(mm, pmd_m);
91010 + if (ptl != ptl_m) {
91011 + spin_lock_nested(ptl_m, SINGLE_DEPTH_NESTING);
91012 + if (!pte_none(*pte_m))
91013 + goto out;
91014 + }
91015 +
91016 + entry_m = pfn_pte(pfn_m, vma_m->vm_page_prot);
91017 + set_pte_at(mm, address_m, pte_m, entry_m);
91018 +out:
91019 + if (ptl != ptl_m)
91020 + spin_unlock(ptl_m);
91021 + pte_unmap(pte_m);
91022 +}
91023 +
91024 +static void pax_mirror_pte(struct vm_area_struct *vma, unsigned long address, pte_t *pte, pmd_t *pmd, spinlock_t *ptl)
91025 +{
91026 + struct page *page_m;
91027 + pte_t entry;
91028 +
91029 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC))
91030 + goto out;
91031 +
91032 + entry = *pte;
91033 + page_m = vm_normal_page(vma, address, entry);
91034 + if (!page_m)
91035 + pax_mirror_pfn_pte(vma, address, pte_pfn(entry), ptl);
91036 + else if (PageAnon(page_m)) {
91037 + if (pax_find_mirror_vma(vma)) {
91038 + pte_unmap_unlock(pte, ptl);
91039 + lock_page(page_m);
91040 + pte = pte_offset_map_lock(vma->vm_mm, pmd, address, &ptl);
91041 + if (pte_same(entry, *pte))
91042 + pax_mirror_anon_pte(vma, address, page_m, ptl);
91043 + else
91044 + unlock_page(page_m);
91045 + }
91046 + } else
91047 + pax_mirror_file_pte(vma, address, page_m, ptl);
91048 +
91049 +out:
91050 + pte_unmap_unlock(pte, ptl);
91051 +}
91052 +#endif
91053 +
91054 /*
91055 * This routine handles present pages, when users try to write
91056 * to a shared page. It is done by copying the page to a new address
91057 @@ -2807,6 +3003,12 @@ gotten:
91058 */
91059 page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
91060 if (likely(pte_same(*page_table, orig_pte))) {
91061 +
91062 +#ifdef CONFIG_PAX_SEGMEXEC
91063 + if (pax_find_mirror_vma(vma))
91064 + BUG_ON(!trylock_page(new_page));
91065 +#endif
91066 +
91067 if (old_page) {
91068 if (!PageAnon(old_page)) {
91069 dec_mm_counter_fast(mm, MM_FILEPAGES);
91070 @@ -2858,6 +3060,10 @@ gotten:
91071 page_remove_rmap(old_page);
91072 }
91073
91074 +#ifdef CONFIG_PAX_SEGMEXEC
91075 + pax_mirror_anon_pte(vma, address, new_page, ptl);
91076 +#endif
91077 +
91078 /* Free the old page.. */
91079 new_page = old_page;
91080 ret |= VM_FAULT_WRITE;
91081 @@ -3135,6 +3341,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
91082 swap_free(entry);
91083 if (vm_swap_full() || (vma->vm_flags & VM_LOCKED) || PageMlocked(page))
91084 try_to_free_swap(page);
91085 +
91086 +#ifdef CONFIG_PAX_SEGMEXEC
91087 + if ((flags & FAULT_FLAG_WRITE) || !pax_find_mirror_vma(vma))
91088 +#endif
91089 +
91090 unlock_page(page);
91091 if (page != swapcache) {
91092 /*
91093 @@ -3158,6 +3369,11 @@ static int do_swap_page(struct mm_struct *mm, struct vm_area_struct *vma,
91094
91095 /* No need to invalidate - it was non-present before */
91096 update_mmu_cache(vma, address, page_table);
91097 +
91098 +#ifdef CONFIG_PAX_SEGMEXEC
91099 + pax_mirror_anon_pte(vma, address, page, ptl);
91100 +#endif
91101 +
91102 unlock:
91103 pte_unmap_unlock(page_table, ptl);
91104 out:
91105 @@ -3177,40 +3393,6 @@ out_release:
91106 }
91107
91108 /*
91109 - * This is like a special single-page "expand_{down|up}wards()",
91110 - * except we must first make sure that 'address{-|+}PAGE_SIZE'
91111 - * doesn't hit another vma.
91112 - */
91113 -static inline int check_stack_guard_page(struct vm_area_struct *vma, unsigned long address)
91114 -{
91115 - address &= PAGE_MASK;
91116 - if ((vma->vm_flags & VM_GROWSDOWN) && address == vma->vm_start) {
91117 - struct vm_area_struct *prev = vma->vm_prev;
91118 -
91119 - /*
91120 - * Is there a mapping abutting this one below?
91121 - *
91122 - * That's only ok if it's the same stack mapping
91123 - * that has gotten split..
91124 - */
91125 - if (prev && prev->vm_end == address)
91126 - return prev->vm_flags & VM_GROWSDOWN ? 0 : -ENOMEM;
91127 -
91128 - expand_downwards(vma, address - PAGE_SIZE);
91129 - }
91130 - if ((vma->vm_flags & VM_GROWSUP) && address + PAGE_SIZE == vma->vm_end) {
91131 - struct vm_area_struct *next = vma->vm_next;
91132 -
91133 - /* As VM_GROWSDOWN but s/below/above/ */
91134 - if (next && next->vm_start == address + PAGE_SIZE)
91135 - return next->vm_flags & VM_GROWSUP ? 0 : -ENOMEM;
91136 -
91137 - expand_upwards(vma, address + PAGE_SIZE);
91138 - }
91139 - return 0;
91140 -}
91141 -
91142 -/*
91143 * We enter with non-exclusive mmap_sem (to exclude vma changes,
91144 * but allow concurrent faults), and pte mapped but not yet locked.
91145 * We return with mmap_sem still held, but pte unmapped and unlocked.
91146 @@ -3219,27 +3401,23 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
91147 unsigned long address, pte_t *page_table, pmd_t *pmd,
91148 unsigned int flags)
91149 {
91150 - struct page *page;
91151 + struct page *page = NULL;
91152 spinlock_t *ptl;
91153 pte_t entry;
91154
91155 - pte_unmap(page_table);
91156 -
91157 - /* Check if we need to add a guard page to the stack */
91158 - if (check_stack_guard_page(vma, address) < 0)
91159 - return VM_FAULT_SIGBUS;
91160 -
91161 - /* Use the zero-page for reads */
91162 if (!(flags & FAULT_FLAG_WRITE)) {
91163 entry = pte_mkspecial(pfn_pte(my_zero_pfn(address),
91164 vma->vm_page_prot));
91165 - page_table = pte_offset_map_lock(mm, pmd, address, &ptl);
91166 + ptl = pte_lockptr(mm, pmd);
91167 + spin_lock(ptl);
91168 if (!pte_none(*page_table))
91169 goto unlock;
91170 goto setpte;
91171 }
91172
91173 /* Allocate our own private page. */
91174 + pte_unmap(page_table);
91175 +
91176 if (unlikely(anon_vma_prepare(vma)))
91177 goto oom;
91178 page = alloc_zeroed_user_highpage_movable(vma, address);
91179 @@ -3263,6 +3441,11 @@ static int do_anonymous_page(struct mm_struct *mm, struct vm_area_struct *vma,
91180 if (!pte_none(*page_table))
91181 goto release;
91182
91183 +#ifdef CONFIG_PAX_SEGMEXEC
91184 + if (pax_find_mirror_vma(vma))
91185 + BUG_ON(!trylock_page(page));
91186 +#endif
91187 +
91188 inc_mm_counter_fast(mm, MM_ANONPAGES);
91189 page_add_new_anon_rmap(page, vma, address);
91190 setpte:
91191 @@ -3270,6 +3453,12 @@ setpte:
91192
91193 /* No need to invalidate - it was non-present before */
91194 update_mmu_cache(vma, address, page_table);
91195 +
91196 +#ifdef CONFIG_PAX_SEGMEXEC
91197 + if (page)
91198 + pax_mirror_anon_pte(vma, address, page, ptl);
91199 +#endif
91200 +
91201 unlock:
91202 pte_unmap_unlock(page_table, ptl);
91203 return 0;
91204 @@ -3413,6 +3602,12 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91205 */
91206 /* Only go through if we didn't race with anybody else... */
91207 if (likely(pte_same(*page_table, orig_pte))) {
91208 +
91209 +#ifdef CONFIG_PAX_SEGMEXEC
91210 + if (anon && pax_find_mirror_vma(vma))
91211 + BUG_ON(!trylock_page(page));
91212 +#endif
91213 +
91214 flush_icache_page(vma, page);
91215 entry = mk_pte(page, vma->vm_page_prot);
91216 if (flags & FAULT_FLAG_WRITE)
91217 @@ -3434,6 +3629,14 @@ static int __do_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91218
91219 /* no need to invalidate: a not-present page won't be cached */
91220 update_mmu_cache(vma, address, page_table);
91221 +
91222 +#ifdef CONFIG_PAX_SEGMEXEC
91223 + if (anon)
91224 + pax_mirror_anon_pte(vma, address, page, ptl);
91225 + else
91226 + pax_mirror_file_pte(vma, address, page, ptl);
91227 +#endif
91228 +
91229 } else {
91230 if (cow_page)
91231 mem_cgroup_uncharge_page(cow_page);
91232 @@ -3681,6 +3884,12 @@ static int handle_pte_fault(struct mm_struct *mm,
91233 if (flags & FAULT_FLAG_WRITE)
91234 flush_tlb_fix_spurious_fault(vma, address);
91235 }
91236 +
91237 +#ifdef CONFIG_PAX_SEGMEXEC
91238 + pax_mirror_pte(vma, address, pte, pmd, ptl);
91239 + return 0;
91240 +#endif
91241 +
91242 unlock:
91243 pte_unmap_unlock(pte, ptl);
91244 return 0;
91245 @@ -3697,9 +3906,41 @@ static int __handle_mm_fault(struct mm_struct *mm, struct vm_area_struct *vma,
91246 pmd_t *pmd;
91247 pte_t *pte;
91248
91249 +#ifdef CONFIG_PAX_SEGMEXEC
91250 + struct vm_area_struct *vma_m;
91251 +#endif
91252 +
91253 if (unlikely(is_vm_hugetlb_page(vma)))
91254 return hugetlb_fault(mm, vma, address, flags);
91255
91256 +#ifdef CONFIG_PAX_SEGMEXEC
91257 + vma_m = pax_find_mirror_vma(vma);
91258 + if (vma_m) {
91259 + unsigned long address_m;
91260 + pgd_t *pgd_m;
91261 + pud_t *pud_m;
91262 + pmd_t *pmd_m;
91263 +
91264 + if (vma->vm_start > vma_m->vm_start) {
91265 + address_m = address;
91266 + address -= SEGMEXEC_TASK_SIZE;
91267 + vma = vma_m;
91268 + } else
91269 + address_m = address + SEGMEXEC_TASK_SIZE;
91270 +
91271 + pgd_m = pgd_offset(mm, address_m);
91272 + pud_m = pud_alloc(mm, pgd_m, address_m);
91273 + if (!pud_m)
91274 + return VM_FAULT_OOM;
91275 + pmd_m = pmd_alloc(mm, pud_m, address_m);
91276 + if (!pmd_m)
91277 + return VM_FAULT_OOM;
91278 + if (!pmd_present(*pmd_m) && __pte_alloc(mm, vma_m, pmd_m, address_m))
91279 + return VM_FAULT_OOM;
91280 + pax_unmap_mirror_pte(vma_m, address_m, pmd_m);
91281 + }
91282 +#endif
91283 +
91284 retry:
91285 pgd = pgd_offset(mm, address);
91286 pud = pud_alloc(mm, pgd, address);
91287 @@ -3838,6 +4079,23 @@ int __pud_alloc(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
91288 spin_unlock(&mm->page_table_lock);
91289 return 0;
91290 }
91291 +
91292 +int __pud_alloc_kernel(struct mm_struct *mm, pgd_t *pgd, unsigned long address)
91293 +{
91294 + pud_t *new = pud_alloc_one(mm, address);
91295 + if (!new)
91296 + return -ENOMEM;
91297 +
91298 + smp_wmb(); /* See comment in __pte_alloc */
91299 +
91300 + spin_lock(&mm->page_table_lock);
91301 + if (pgd_present(*pgd)) /* Another has populated it */
91302 + pud_free(mm, new);
91303 + else
91304 + pgd_populate_kernel(mm, pgd, new);
91305 + spin_unlock(&mm->page_table_lock);
91306 + return 0;
91307 +}
91308 #endif /* __PAGETABLE_PUD_FOLDED */
91309
91310 #ifndef __PAGETABLE_PMD_FOLDED
91311 @@ -3868,6 +4126,30 @@ int __pmd_alloc(struct mm_struct *mm, pud_t *pud, unsigned long address)
91312 spin_unlock(&mm->page_table_lock);
91313 return 0;
91314 }
91315 +
91316 +int __pmd_alloc_kernel(struct mm_struct *mm, pud_t *pud, unsigned long address)
91317 +{
91318 + pmd_t *new = pmd_alloc_one(mm, address);
91319 + if (!new)
91320 + return -ENOMEM;
91321 +
91322 + smp_wmb(); /* See comment in __pte_alloc */
91323 +
91324 + spin_lock(&mm->page_table_lock);
91325 +#ifndef __ARCH_HAS_4LEVEL_HACK
91326 + if (pud_present(*pud)) /* Another has populated it */
91327 + pmd_free(mm, new);
91328 + else
91329 + pud_populate_kernel(mm, pud, new);
91330 +#else
91331 + if (pgd_present(*pud)) /* Another has populated it */
91332 + pmd_free(mm, new);
91333 + else
91334 + pgd_populate_kernel(mm, pud, new);
91335 +#endif /* __ARCH_HAS_4LEVEL_HACK */
91336 + spin_unlock(&mm->page_table_lock);
91337 + return 0;
91338 +}
91339 #endif /* __PAGETABLE_PMD_FOLDED */
91340
91341 #if !defined(__HAVE_ARCH_GATE_AREA)
91342 @@ -3881,7 +4163,7 @@ static int __init gate_vma_init(void)
91343 gate_vma.vm_start = FIXADDR_USER_START;
91344 gate_vma.vm_end = FIXADDR_USER_END;
91345 gate_vma.vm_flags = VM_READ | VM_MAYREAD | VM_EXEC | VM_MAYEXEC;
91346 - gate_vma.vm_page_prot = __P101;
91347 + gate_vma.vm_page_prot = vm_get_page_prot(gate_vma.vm_flags);
91348
91349 return 0;
91350 }
91351 @@ -4015,8 +4297,8 @@ out:
91352 return ret;
91353 }
91354
91355 -int generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
91356 - void *buf, int len, int write)
91357 +ssize_t generic_access_phys(struct vm_area_struct *vma, unsigned long addr,
91358 + void *buf, size_t len, int write)
91359 {
91360 resource_size_t phys_addr;
91361 unsigned long prot = 0;
91362 @@ -4042,8 +4324,8 @@ EXPORT_SYMBOL_GPL(generic_access_phys);
91363 * Access another process' address space as given in mm. If non-NULL, use the
91364 * given task for page fault accounting.
91365 */
91366 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91367 - unsigned long addr, void *buf, int len, int write)
91368 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91369 + unsigned long addr, void *buf, size_t len, int write)
91370 {
91371 struct vm_area_struct *vma;
91372 void *old_buf = buf;
91373 @@ -4051,7 +4333,7 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91374 down_read(&mm->mmap_sem);
91375 /* ignore errors, just check how much was successfully transferred */
91376 while (len) {
91377 - int bytes, ret, offset;
91378 + ssize_t bytes, ret, offset;
91379 void *maddr;
91380 struct page *page = NULL;
91381
91382 @@ -4110,8 +4392,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
91383 *
91384 * The caller must hold a reference on @mm.
91385 */
91386 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
91387 - void *buf, int len, int write)
91388 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
91389 + void *buf, size_t len, int write)
91390 {
91391 return __access_remote_vm(NULL, mm, addr, buf, len, write);
91392 }
91393 @@ -4121,11 +4403,11 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
91394 * Source/target buffer must be kernel space,
91395 * Do not walk the page table directly, use get_user_pages
91396 */
91397 -int access_process_vm(struct task_struct *tsk, unsigned long addr,
91398 - void *buf, int len, int write)
91399 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr,
91400 + void *buf, size_t len, int write)
91401 {
91402 struct mm_struct *mm;
91403 - int ret;
91404 + ssize_t ret;
91405
91406 mm = get_task_mm(tsk);
91407 if (!mm)
91408 diff --git a/mm/mempolicy.c b/mm/mempolicy.c
91409 index cb2f3dd..fb80468 100644
91410 --- a/mm/mempolicy.c
91411 +++ b/mm/mempolicy.c
91412 @@ -747,6 +747,10 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
91413 unsigned long vmstart;
91414 unsigned long vmend;
91415
91416 +#ifdef CONFIG_PAX_SEGMEXEC
91417 + struct vm_area_struct *vma_m;
91418 +#endif
91419 +
91420 vma = find_vma(mm, start);
91421 if (!vma || vma->vm_start > start)
91422 return -EFAULT;
91423 @@ -790,6 +794,16 @@ static int mbind_range(struct mm_struct *mm, unsigned long start,
91424 err = vma_replace_policy(vma, new_pol);
91425 if (err)
91426 goto out;
91427 +
91428 +#ifdef CONFIG_PAX_SEGMEXEC
91429 + vma_m = pax_find_mirror_vma(vma);
91430 + if (vma_m) {
91431 + err = vma_replace_policy(vma_m, new_pol);
91432 + if (err)
91433 + goto out;
91434 + }
91435 +#endif
91436 +
91437 }
91438
91439 out:
91440 @@ -1255,6 +1269,17 @@ static long do_mbind(unsigned long start, unsigned long len,
91441
91442 if (end < start)
91443 return -EINVAL;
91444 +
91445 +#ifdef CONFIG_PAX_SEGMEXEC
91446 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
91447 + if (end > SEGMEXEC_TASK_SIZE)
91448 + return -EINVAL;
91449 + } else
91450 +#endif
91451 +
91452 + if (end > TASK_SIZE)
91453 + return -EINVAL;
91454 +
91455 if (end == start)
91456 return 0;
91457
91458 @@ -1483,8 +1508,7 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
91459 */
91460 tcred = __task_cred(task);
91461 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
91462 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
91463 - !capable(CAP_SYS_NICE)) {
91464 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
91465 rcu_read_unlock();
91466 err = -EPERM;
91467 goto out_put;
91468 @@ -1515,6 +1539,15 @@ SYSCALL_DEFINE4(migrate_pages, pid_t, pid, unsigned long, maxnode,
91469 goto out;
91470 }
91471
91472 +#ifdef CONFIG_GRKERNSEC_PROC_MEMMAP
91473 + if (mm != current->mm &&
91474 + (mm->pax_flags & MF_PAX_RANDMMAP || mm->pax_flags & MF_PAX_SEGMEXEC)) {
91475 + mmput(mm);
91476 + err = -EPERM;
91477 + goto out;
91478 + }
91479 +#endif
91480 +
91481 err = do_migrate_pages(mm, old, new,
91482 capable(CAP_SYS_NICE) ? MPOL_MF_MOVE_ALL : MPOL_MF_MOVE);
91483
91484 diff --git a/mm/migrate.c b/mm/migrate.c
91485 index 9194375..75c81e2 100644
91486 --- a/mm/migrate.c
91487 +++ b/mm/migrate.c
91488 @@ -1464,8 +1464,7 @@ SYSCALL_DEFINE6(move_pages, pid_t, pid, unsigned long, nr_pages,
91489 */
91490 tcred = __task_cred(task);
91491 if (!uid_eq(cred->euid, tcred->suid) && !uid_eq(cred->euid, tcred->uid) &&
91492 - !uid_eq(cred->uid, tcred->suid) && !uid_eq(cred->uid, tcred->uid) &&
91493 - !capable(CAP_SYS_NICE)) {
91494 + !uid_eq(cred->uid, tcred->suid) && !capable(CAP_SYS_NICE)) {
91495 rcu_read_unlock();
91496 err = -EPERM;
91497 goto out;
91498 diff --git a/mm/mlock.c b/mm/mlock.c
91499 index 192e6ee..b044449 100644
91500 --- a/mm/mlock.c
91501 +++ b/mm/mlock.c
91502 @@ -14,6 +14,7 @@
91503 #include <linux/pagevec.h>
91504 #include <linux/mempolicy.h>
91505 #include <linux/syscalls.h>
91506 +#include <linux/security.h>
91507 #include <linux/sched.h>
91508 #include <linux/export.h>
91509 #include <linux/rmap.h>
91510 @@ -588,7 +589,7 @@ static int do_mlock(unsigned long start, size_t len, int on)
91511 {
91512 unsigned long nstart, end, tmp;
91513 struct vm_area_struct * vma, * prev;
91514 - int error;
91515 + int error = 0;
91516
91517 VM_BUG_ON(start & ~PAGE_MASK);
91518 VM_BUG_ON(len != PAGE_ALIGN(len));
91519 @@ -597,6 +598,9 @@ static int do_mlock(unsigned long start, size_t len, int on)
91520 return -EINVAL;
91521 if (end == start)
91522 return 0;
91523 + if (end > TASK_SIZE)
91524 + return -EINVAL;
91525 +
91526 vma = find_vma(current->mm, start);
91527 if (!vma || vma->vm_start > start)
91528 return -ENOMEM;
91529 @@ -608,6 +612,11 @@ static int do_mlock(unsigned long start, size_t len, int on)
91530 for (nstart = start ; ; ) {
91531 vm_flags_t newflags;
91532
91533 +#ifdef CONFIG_PAX_SEGMEXEC
91534 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
91535 + break;
91536 +#endif
91537 +
91538 /* Here we know that vma->vm_start <= nstart < vma->vm_end. */
91539
91540 newflags = vma->vm_flags & ~VM_LOCKED;
91541 @@ -720,6 +729,7 @@ SYSCALL_DEFINE2(mlock, unsigned long, start, size_t, len)
91542 lock_limit >>= PAGE_SHIFT;
91543
91544 /* check against resource limits */
91545 + gr_learn_resource(current, RLIMIT_MEMLOCK, (current->mm->locked_vm << PAGE_SHIFT) + len, 1);
91546 if ((locked <= lock_limit) || capable(CAP_IPC_LOCK))
91547 error = do_mlock(start, len, 1);
91548 up_write(&current->mm->mmap_sem);
91549 @@ -754,6 +764,11 @@ static int do_mlockall(int flags)
91550 for (vma = current->mm->mmap; vma ; vma = prev->vm_next) {
91551 vm_flags_t newflags;
91552
91553 +#ifdef CONFIG_PAX_SEGMEXEC
91554 + if ((current->mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE))
91555 + break;
91556 +#endif
91557 +
91558 newflags = vma->vm_flags & ~VM_LOCKED;
91559 if (flags & MCL_CURRENT)
91560 newflags |= VM_LOCKED;
91561 @@ -787,6 +802,7 @@ SYSCALL_DEFINE1(mlockall, int, flags)
91562 lock_limit >>= PAGE_SHIFT;
91563
91564 ret = -ENOMEM;
91565 + gr_learn_resource(current, RLIMIT_MEMLOCK, current->mm->total_vm << PAGE_SHIFT, 1);
91566 if (!(flags & MCL_CURRENT) || (current->mm->total_vm <= lock_limit) ||
91567 capable(CAP_IPC_LOCK))
91568 ret = do_mlockall(flags);
91569 diff --git a/mm/mmap.c b/mm/mmap.c
91570 index 546db74..650d1b9 100644
91571 --- a/mm/mmap.c
91572 +++ b/mm/mmap.c
91573 @@ -36,6 +36,7 @@
91574 #include <linux/sched/sysctl.h>
91575 #include <linux/notifier.h>
91576 #include <linux/memory.h>
91577 +#include <linux/random.h>
91578
91579 #include <asm/uaccess.h>
91580 #include <asm/cacheflush.h>
91581 @@ -52,6 +53,16 @@
91582 #define arch_rebalance_pgtables(addr, len) (addr)
91583 #endif
91584
91585 +static inline void verify_mm_writelocked(struct mm_struct *mm)
91586 +{
91587 +#if defined(CONFIG_DEBUG_VM) || defined(CONFIG_PAX)
91588 + if (unlikely(down_read_trylock(&mm->mmap_sem))) {
91589 + up_read(&mm->mmap_sem);
91590 + BUG();
91591 + }
91592 +#endif
91593 +}
91594 +
91595 static void unmap_region(struct mm_struct *mm,
91596 struct vm_area_struct *vma, struct vm_area_struct *prev,
91597 unsigned long start, unsigned long end);
91598 @@ -71,16 +82,25 @@ static void unmap_region(struct mm_struct *mm,
91599 * x: (no) no x: (no) yes x: (no) yes x: (yes) yes
91600 *
91601 */
91602 -pgprot_t protection_map[16] = {
91603 +pgprot_t protection_map[16] __read_only = {
91604 __P000, __P001, __P010, __P011, __P100, __P101, __P110, __P111,
91605 __S000, __S001, __S010, __S011, __S100, __S101, __S110, __S111
91606 };
91607
91608 -pgprot_t vm_get_page_prot(unsigned long vm_flags)
91609 +pgprot_t vm_get_page_prot(vm_flags_t vm_flags)
91610 {
91611 - return __pgprot(pgprot_val(protection_map[vm_flags &
91612 + pgprot_t prot = __pgprot(pgprot_val(protection_map[vm_flags &
91613 (VM_READ|VM_WRITE|VM_EXEC|VM_SHARED)]) |
91614 pgprot_val(arch_vm_get_page_prot(vm_flags)));
91615 +
91616 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
91617 + if (!(__supported_pte_mask & _PAGE_NX) &&
91618 + (vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC &&
91619 + (vm_flags & (VM_READ | VM_WRITE)))
91620 + prot = __pgprot(pte_val(pte_exprotect(__pte(pgprot_val(prot)))));
91621 +#endif
91622 +
91623 + return prot;
91624 }
91625 EXPORT_SYMBOL(vm_get_page_prot);
91626
91627 @@ -89,6 +109,7 @@ int sysctl_overcommit_ratio __read_mostly = 50; /* default is 50% */
91628 int sysctl_max_map_count __read_mostly = DEFAULT_MAX_MAP_COUNT;
91629 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
91630 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
91631 +unsigned long sysctl_heap_stack_gap __read_mostly = 64*1024;
91632 /*
91633 * Make sure vm_committed_as in one cacheline and not cacheline shared with
91634 * other variables. It can be updated by several CPUs frequently.
91635 @@ -245,6 +266,7 @@ static struct vm_area_struct *remove_vma(struct vm_area_struct *vma)
91636 struct vm_area_struct *next = vma->vm_next;
91637
91638 might_sleep();
91639 + BUG_ON(vma->vm_mirror);
91640 if (vma->vm_ops && vma->vm_ops->close)
91641 vma->vm_ops->close(vma);
91642 if (vma->vm_file)
91643 @@ -289,6 +311,7 @@ SYSCALL_DEFINE1(brk, unsigned long, brk)
91644 * not page aligned -Ram Gupta
91645 */
91646 rlim = rlimit(RLIMIT_DATA);
91647 + gr_learn_resource(current, RLIMIT_DATA, (brk - mm->start_brk) + (mm->end_data - mm->start_data), 1);
91648 if (rlim < RLIM_INFINITY && (brk - mm->start_brk) +
91649 (mm->end_data - mm->start_data) > rlim)
91650 goto out;
91651 @@ -939,6 +962,12 @@ static int
91652 can_vma_merge_before(struct vm_area_struct *vma, unsigned long vm_flags,
91653 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
91654 {
91655 +
91656 +#ifdef CONFIG_PAX_SEGMEXEC
91657 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_start == SEGMEXEC_TASK_SIZE)
91658 + return 0;
91659 +#endif
91660 +
91661 if (is_mergeable_vma(vma, file, vm_flags) &&
91662 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
91663 if (vma->vm_pgoff == vm_pgoff)
91664 @@ -958,6 +987,12 @@ static int
91665 can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
91666 struct anon_vma *anon_vma, struct file *file, pgoff_t vm_pgoff)
91667 {
91668 +
91669 +#ifdef CONFIG_PAX_SEGMEXEC
91670 + if ((vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) && vma->vm_end == SEGMEXEC_TASK_SIZE)
91671 + return 0;
91672 +#endif
91673 +
91674 if (is_mergeable_vma(vma, file, vm_flags) &&
91675 is_mergeable_anon_vma(anon_vma, vma->anon_vma, vma)) {
91676 pgoff_t vm_pglen;
91677 @@ -1000,13 +1035,20 @@ can_vma_merge_after(struct vm_area_struct *vma, unsigned long vm_flags,
91678 struct vm_area_struct *vma_merge(struct mm_struct *mm,
91679 struct vm_area_struct *prev, unsigned long addr,
91680 unsigned long end, unsigned long vm_flags,
91681 - struct anon_vma *anon_vma, struct file *file,
91682 + struct anon_vma *anon_vma, struct file *file,
91683 pgoff_t pgoff, struct mempolicy *policy)
91684 {
91685 pgoff_t pglen = (end - addr) >> PAGE_SHIFT;
91686 struct vm_area_struct *area, *next;
91687 int err;
91688
91689 +#ifdef CONFIG_PAX_SEGMEXEC
91690 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE, end_m = end + SEGMEXEC_TASK_SIZE;
91691 + struct vm_area_struct *area_m = NULL, *next_m = NULL, *prev_m = NULL;
91692 +
91693 + BUG_ON((mm->pax_flags & MF_PAX_SEGMEXEC) && SEGMEXEC_TASK_SIZE < end);
91694 +#endif
91695 +
91696 /*
91697 * We later require that vma->vm_flags == vm_flags,
91698 * so this tests vma->vm_flags & VM_SPECIAL, too.
91699 @@ -1022,6 +1064,15 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
91700 if (next && next->vm_end == end) /* cases 6, 7, 8 */
91701 next = next->vm_next;
91702
91703 +#ifdef CONFIG_PAX_SEGMEXEC
91704 + if (prev)
91705 + prev_m = pax_find_mirror_vma(prev);
91706 + if (area)
91707 + area_m = pax_find_mirror_vma(area);
91708 + if (next)
91709 + next_m = pax_find_mirror_vma(next);
91710 +#endif
91711 +
91712 /*
91713 * Can it merge with the predecessor?
91714 */
91715 @@ -1041,9 +1092,24 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
91716 /* cases 1, 6 */
91717 err = vma_adjust(prev, prev->vm_start,
91718 next->vm_end, prev->vm_pgoff, NULL);
91719 - } else /* cases 2, 5, 7 */
91720 +
91721 +#ifdef CONFIG_PAX_SEGMEXEC
91722 + if (!err && prev_m)
91723 + err = vma_adjust(prev_m, prev_m->vm_start,
91724 + next_m->vm_end, prev_m->vm_pgoff, NULL);
91725 +#endif
91726 +
91727 + } else { /* cases 2, 5, 7 */
91728 err = vma_adjust(prev, prev->vm_start,
91729 end, prev->vm_pgoff, NULL);
91730 +
91731 +#ifdef CONFIG_PAX_SEGMEXEC
91732 + if (!err && prev_m)
91733 + err = vma_adjust(prev_m, prev_m->vm_start,
91734 + end_m, prev_m->vm_pgoff, NULL);
91735 +#endif
91736 +
91737 + }
91738 if (err)
91739 return NULL;
91740 khugepaged_enter_vma_merge(prev);
91741 @@ -1057,12 +1123,27 @@ struct vm_area_struct *vma_merge(struct mm_struct *mm,
91742 mpol_equal(policy, vma_policy(next)) &&
91743 can_vma_merge_before(next, vm_flags,
91744 anon_vma, file, pgoff+pglen)) {
91745 - if (prev && addr < prev->vm_end) /* case 4 */
91746 + if (prev && addr < prev->vm_end) { /* case 4 */
91747 err = vma_adjust(prev, prev->vm_start,
91748 addr, prev->vm_pgoff, NULL);
91749 - else /* cases 3, 8 */
91750 +
91751 +#ifdef CONFIG_PAX_SEGMEXEC
91752 + if (!err && prev_m)
91753 + err = vma_adjust(prev_m, prev_m->vm_start,
91754 + addr_m, prev_m->vm_pgoff, NULL);
91755 +#endif
91756 +
91757 + } else { /* cases 3, 8 */
91758 err = vma_adjust(area, addr, next->vm_end,
91759 next->vm_pgoff - pglen, NULL);
91760 +
91761 +#ifdef CONFIG_PAX_SEGMEXEC
91762 + if (!err && area_m)
91763 + err = vma_adjust(area_m, addr_m, next_m->vm_end,
91764 + next_m->vm_pgoff - pglen, NULL);
91765 +#endif
91766 +
91767 + }
91768 if (err)
91769 return NULL;
91770 khugepaged_enter_vma_merge(area);
91771 @@ -1171,8 +1252,10 @@ none:
91772 void vm_stat_account(struct mm_struct *mm, unsigned long flags,
91773 struct file *file, long pages)
91774 {
91775 - const unsigned long stack_flags
91776 - = VM_STACK_FLAGS & (VM_GROWSUP|VM_GROWSDOWN);
91777 +
91778 +#ifdef CONFIG_PAX_RANDMMAP
91779 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
91780 +#endif
91781
91782 mm->total_vm += pages;
91783
91784 @@ -1180,7 +1263,7 @@ void vm_stat_account(struct mm_struct *mm, unsigned long flags,
91785 mm->shared_vm += pages;
91786 if ((flags & (VM_EXEC|VM_WRITE)) == VM_EXEC)
91787 mm->exec_vm += pages;
91788 - } else if (flags & stack_flags)
91789 + } else if (flags & (VM_GROWSUP|VM_GROWSDOWN))
91790 mm->stack_vm += pages;
91791 }
91792 #endif /* CONFIG_PROC_FS */
91793 @@ -1218,7 +1301,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91794 * (the exception is when the underlying filesystem is noexec
91795 * mounted, in which case we dont add PROT_EXEC.)
91796 */
91797 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
91798 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
91799 if (!(file && (file->f_path.mnt->mnt_flags & MNT_NOEXEC)))
91800 prot |= PROT_EXEC;
91801
91802 @@ -1244,7 +1327,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91803 /* Obtain the address to map to. we verify (or select) it and ensure
91804 * that it represents a valid section of the address space.
91805 */
91806 - addr = get_unmapped_area(file, addr, len, pgoff, flags);
91807 + addr = get_unmapped_area(file, addr, len, pgoff, flags | ((prot & PROT_EXEC) ? MAP_EXECUTABLE : 0));
91808 if (addr & ~PAGE_MASK)
91809 return addr;
91810
91811 @@ -1255,6 +1338,43 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91812 vm_flags = calc_vm_prot_bits(prot) | calc_vm_flag_bits(flags) |
91813 mm->def_flags | VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC;
91814
91815 +#ifdef CONFIG_PAX_MPROTECT
91816 + if (mm->pax_flags & MF_PAX_MPROTECT) {
91817 +
91818 +#ifdef CONFIG_GRKERNSEC_RWXMAP_LOG
91819 + if (file && !pgoff && (vm_flags & VM_EXEC) && mm->binfmt &&
91820 + mm->binfmt->handle_mmap)
91821 + mm->binfmt->handle_mmap(file);
91822 +#endif
91823 +
91824 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
91825 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC)) {
91826 + gr_log_rwxmmap(file);
91827 +
91828 +#ifdef CONFIG_PAX_EMUPLT
91829 + vm_flags &= ~VM_EXEC;
91830 +#else
91831 + return -EPERM;
91832 +#endif
91833 +
91834 + }
91835 +
91836 + if (!(vm_flags & VM_EXEC))
91837 + vm_flags &= ~VM_MAYEXEC;
91838 +#else
91839 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
91840 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
91841 +#endif
91842 + else
91843 + vm_flags &= ~VM_MAYWRITE;
91844 + }
91845 +#endif
91846 +
91847 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
91848 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && file)
91849 + vm_flags &= ~VM_PAGEEXEC;
91850 +#endif
91851 +
91852 if (flags & MAP_LOCKED)
91853 if (!can_do_mlock())
91854 return -EPERM;
91855 @@ -1266,6 +1386,7 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91856 locked += mm->locked_vm;
91857 lock_limit = rlimit(RLIMIT_MEMLOCK);
91858 lock_limit >>= PAGE_SHIFT;
91859 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
91860 if (locked > lock_limit && !capable(CAP_IPC_LOCK))
91861 return -EAGAIN;
91862 }
91863 @@ -1350,6 +1471,9 @@ unsigned long do_mmap_pgoff(struct file *file, unsigned long addr,
91864 vm_flags |= VM_NORESERVE;
91865 }
91866
91867 + if (!gr_acl_handle_mmap(file, prot))
91868 + return -EACCES;
91869 +
91870 addr = mmap_region(file, addr, len, vm_flags, pgoff);
91871 if (!IS_ERR_VALUE(addr) &&
91872 ((vm_flags & VM_LOCKED) ||
91873 @@ -1443,7 +1567,7 @@ int vma_wants_writenotify(struct vm_area_struct *vma)
91874 vm_flags_t vm_flags = vma->vm_flags;
91875
91876 /* If it was private or non-writable, the write bit is already clear */
91877 - if ((vm_flags & (VM_WRITE|VM_SHARED)) != ((VM_WRITE|VM_SHARED)))
91878 + if ((vm_flags & (VM_WRITE|VM_SHARED)) != (VM_WRITE|VM_SHARED))
91879 return 0;
91880
91881 /* The backer wishes to know when pages are first written to? */
91882 @@ -1489,7 +1613,22 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
91883 struct rb_node **rb_link, *rb_parent;
91884 unsigned long charged = 0;
91885
91886 +#ifdef CONFIG_PAX_SEGMEXEC
91887 + struct vm_area_struct *vma_m = NULL;
91888 +#endif
91889 +
91890 + /*
91891 + * mm->mmap_sem is required to protect against another thread
91892 + * changing the mappings in case we sleep.
91893 + */
91894 + verify_mm_writelocked(mm);
91895 +
91896 /* Check against address space limit. */
91897 +
91898 +#ifdef CONFIG_PAX_RANDMMAP
91899 + if (!(mm->pax_flags & MF_PAX_RANDMMAP) || (vm_flags & (VM_MAYREAD | VM_MAYWRITE | VM_MAYEXEC)))
91900 +#endif
91901 +
91902 if (!may_expand_vm(mm, len >> PAGE_SHIFT)) {
91903 unsigned long nr_pages;
91904
91905 @@ -1508,11 +1647,10 @@ unsigned long mmap_region(struct file *file, unsigned long addr,
91906
91907 /* Clear old maps */
91908 error = -ENOMEM;
91909 -munmap_back:
91910 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
91911 if (do_munmap(mm, addr, len))
91912 return -ENOMEM;
91913 - goto munmap_back;
91914 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
91915 }
91916
91917 /*
91918 @@ -1543,6 +1681,16 @@ munmap_back:
91919 goto unacct_error;
91920 }
91921
91922 +#ifdef CONFIG_PAX_SEGMEXEC
91923 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vm_flags & VM_EXEC)) {
91924 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
91925 + if (!vma_m) {
91926 + error = -ENOMEM;
91927 + goto free_vma;
91928 + }
91929 + }
91930 +#endif
91931 +
91932 vma->vm_mm = mm;
91933 vma->vm_start = addr;
91934 vma->vm_end = addr + len;
91935 @@ -1562,6 +1710,13 @@ munmap_back:
91936 if (error)
91937 goto unmap_and_free_vma;
91938
91939 +#if defined(CONFIG_PAX_PAGEEXEC) && defined(CONFIG_X86_32)
91940 + if ((mm->pax_flags & MF_PAX_PAGEEXEC) && !(vma->vm_flags & VM_SPECIAL)) {
91941 + vma->vm_flags |= VM_PAGEEXEC;
91942 + vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
91943 + }
91944 +#endif
91945 +
91946 /* Can addr have changed??
91947 *
91948 * Answer: Yes, several device drivers can do it in their
91949 @@ -1595,6 +1750,12 @@ munmap_back:
91950 }
91951
91952 vma_link(mm, vma, prev, rb_link, rb_parent);
91953 +
91954 +#ifdef CONFIG_PAX_SEGMEXEC
91955 + if (vma_m)
91956 + BUG_ON(pax_mirror_vma(vma_m, vma));
91957 +#endif
91958 +
91959 /* Once vma denies write, undo our temporary denial count */
91960 if (vm_flags & VM_DENYWRITE)
91961 allow_write_access(file);
91962 @@ -1603,6 +1764,7 @@ out:
91963 perf_event_mmap(vma);
91964
91965 vm_stat_account(mm, vm_flags, file, len >> PAGE_SHIFT);
91966 + track_exec_limit(mm, addr, addr + len, vm_flags);
91967 if (vm_flags & VM_LOCKED) {
91968 if (!((vm_flags & VM_SPECIAL) || is_vm_hugetlb_page(vma) ||
91969 vma == get_gate_vma(current->mm)))
91970 @@ -1635,6 +1797,12 @@ unmap_and_free_vma:
91971 unmap_region(mm, vma, prev, vma->vm_start, vma->vm_end);
91972 charged = 0;
91973 free_vma:
91974 +
91975 +#ifdef CONFIG_PAX_SEGMEXEC
91976 + if (vma_m)
91977 + kmem_cache_free(vm_area_cachep, vma_m);
91978 +#endif
91979 +
91980 kmem_cache_free(vm_area_cachep, vma);
91981 unacct_error:
91982 if (charged)
91983 @@ -1642,7 +1810,63 @@ unacct_error:
91984 return error;
91985 }
91986
91987 -unsigned long unmapped_area(struct vm_unmapped_area_info *info)
91988 +#ifdef CONFIG_GRKERNSEC_RAND_THREADSTACK
91989 +unsigned long gr_rand_threadstack_offset(const struct mm_struct *mm, const struct file *filp, unsigned long flags)
91990 +{
91991 + if ((mm->pax_flags & MF_PAX_RANDMMAP) && !filp && (flags & MAP_STACK))
91992 + return ((prandom_u32() & 0xFF) + 1) << PAGE_SHIFT;
91993 +
91994 + return 0;
91995 +}
91996 +#endif
91997 +
91998 +bool check_heap_stack_gap(const struct vm_area_struct *vma, unsigned long addr, unsigned long len, unsigned long offset)
91999 +{
92000 + if (!vma) {
92001 +#ifdef CONFIG_STACK_GROWSUP
92002 + if (addr > sysctl_heap_stack_gap)
92003 + vma = find_vma(current->mm, addr - sysctl_heap_stack_gap);
92004 + else
92005 + vma = find_vma(current->mm, 0);
92006 + if (vma && (vma->vm_flags & VM_GROWSUP))
92007 + return false;
92008 +#endif
92009 + return true;
92010 + }
92011 +
92012 + if (addr + len > vma->vm_start)
92013 + return false;
92014 +
92015 + if (vma->vm_flags & VM_GROWSDOWN)
92016 + return sysctl_heap_stack_gap <= vma->vm_start - addr - len;
92017 +#ifdef CONFIG_STACK_GROWSUP
92018 + else if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP))
92019 + return addr - vma->vm_prev->vm_end >= sysctl_heap_stack_gap;
92020 +#endif
92021 + else if (offset)
92022 + return offset <= vma->vm_start - addr - len;
92023 +
92024 + return true;
92025 +}
92026 +
92027 +unsigned long skip_heap_stack_gap(const struct vm_area_struct *vma, unsigned long len, unsigned long offset)
92028 +{
92029 + if (vma->vm_start < len)
92030 + return -ENOMEM;
92031 +
92032 + if (!(vma->vm_flags & VM_GROWSDOWN)) {
92033 + if (offset <= vma->vm_start - len)
92034 + return vma->vm_start - len - offset;
92035 + else
92036 + return -ENOMEM;
92037 + }
92038 +
92039 + if (sysctl_heap_stack_gap <= vma->vm_start - len)
92040 + return vma->vm_start - len - sysctl_heap_stack_gap;
92041 + return -ENOMEM;
92042 +}
92043 +
92044 +unsigned long unmapped_area(const struct vm_unmapped_area_info *info)
92045 {
92046 /*
92047 * We implement the search by looking for an rbtree node that
92048 @@ -1690,11 +1914,29 @@ unsigned long unmapped_area(struct vm_unmapped_area_info *info)
92049 }
92050 }
92051
92052 - gap_start = vma->vm_prev ? vma->vm_prev->vm_end : 0;
92053 + gap_start = vma->vm_prev ? vma->vm_prev->vm_end: 0;
92054 check_current:
92055 /* Check if current node has a suitable gap */
92056 if (gap_start > high_limit)
92057 return -ENOMEM;
92058 +
92059 + if (gap_end - gap_start > info->threadstack_offset)
92060 + gap_start += info->threadstack_offset;
92061 + else
92062 + gap_start = gap_end;
92063 +
92064 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
92065 + if (gap_end - gap_start > sysctl_heap_stack_gap)
92066 + gap_start += sysctl_heap_stack_gap;
92067 + else
92068 + gap_start = gap_end;
92069 + }
92070 + if (vma->vm_flags & VM_GROWSDOWN) {
92071 + if (gap_end - gap_start > sysctl_heap_stack_gap)
92072 + gap_end -= sysctl_heap_stack_gap;
92073 + else
92074 + gap_end = gap_start;
92075 + }
92076 if (gap_end >= low_limit && gap_end - gap_start >= length)
92077 goto found;
92078
92079 @@ -1744,7 +1986,7 @@ found:
92080 return gap_start;
92081 }
92082
92083 -unsigned long unmapped_area_topdown(struct vm_unmapped_area_info *info)
92084 +unsigned long unmapped_area_topdown(const struct vm_unmapped_area_info *info)
92085 {
92086 struct mm_struct *mm = current->mm;
92087 struct vm_area_struct *vma;
92088 @@ -1798,6 +2040,24 @@ check_current:
92089 gap_end = vma->vm_start;
92090 if (gap_end < low_limit)
92091 return -ENOMEM;
92092 +
92093 + if (gap_end - gap_start > info->threadstack_offset)
92094 + gap_end -= info->threadstack_offset;
92095 + else
92096 + gap_end = gap_start;
92097 +
92098 + if (vma->vm_prev && (vma->vm_prev->vm_flags & VM_GROWSUP)) {
92099 + if (gap_end - gap_start > sysctl_heap_stack_gap)
92100 + gap_start += sysctl_heap_stack_gap;
92101 + else
92102 + gap_start = gap_end;
92103 + }
92104 + if (vma->vm_flags & VM_GROWSDOWN) {
92105 + if (gap_end - gap_start > sysctl_heap_stack_gap)
92106 + gap_end -= sysctl_heap_stack_gap;
92107 + else
92108 + gap_end = gap_start;
92109 + }
92110 if (gap_start <= high_limit && gap_end - gap_start >= length)
92111 goto found;
92112
92113 @@ -1861,6 +2121,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
92114 struct mm_struct *mm = current->mm;
92115 struct vm_area_struct *vma;
92116 struct vm_unmapped_area_info info;
92117 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
92118
92119 if (len > TASK_SIZE - mmap_min_addr)
92120 return -ENOMEM;
92121 @@ -1868,11 +2129,15 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
92122 if (flags & MAP_FIXED)
92123 return addr;
92124
92125 +#ifdef CONFIG_PAX_RANDMMAP
92126 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
92127 +#endif
92128 +
92129 if (addr) {
92130 addr = PAGE_ALIGN(addr);
92131 vma = find_vma(mm, addr);
92132 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
92133 - (!vma || addr + len <= vma->vm_start))
92134 + check_heap_stack_gap(vma, addr, len, offset))
92135 return addr;
92136 }
92137
92138 @@ -1881,6 +2146,7 @@ arch_get_unmapped_area(struct file *filp, unsigned long addr,
92139 info.low_limit = mm->mmap_base;
92140 info.high_limit = TASK_SIZE;
92141 info.align_mask = 0;
92142 + info.threadstack_offset = offset;
92143 return vm_unmapped_area(&info);
92144 }
92145 #endif
92146 @@ -1899,6 +2165,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
92147 struct mm_struct *mm = current->mm;
92148 unsigned long addr = addr0;
92149 struct vm_unmapped_area_info info;
92150 + unsigned long offset = gr_rand_threadstack_offset(mm, filp, flags);
92151
92152 /* requested length too big for entire address space */
92153 if (len > TASK_SIZE - mmap_min_addr)
92154 @@ -1907,12 +2174,16 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
92155 if (flags & MAP_FIXED)
92156 return addr;
92157
92158 +#ifdef CONFIG_PAX_RANDMMAP
92159 + if (!(mm->pax_flags & MF_PAX_RANDMMAP))
92160 +#endif
92161 +
92162 /* requesting a specific address */
92163 if (addr) {
92164 addr = PAGE_ALIGN(addr);
92165 vma = find_vma(mm, addr);
92166 if (TASK_SIZE - len >= addr && addr >= mmap_min_addr &&
92167 - (!vma || addr + len <= vma->vm_start))
92168 + check_heap_stack_gap(vma, addr, len, offset))
92169 return addr;
92170 }
92171
92172 @@ -1921,6 +2192,7 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
92173 info.low_limit = max(PAGE_SIZE, mmap_min_addr);
92174 info.high_limit = mm->mmap_base;
92175 info.align_mask = 0;
92176 + info.threadstack_offset = offset;
92177 addr = vm_unmapped_area(&info);
92178
92179 /*
92180 @@ -1933,6 +2205,12 @@ arch_get_unmapped_area_topdown(struct file *filp, const unsigned long addr0,
92181 VM_BUG_ON(addr != -ENOMEM);
92182 info.flags = 0;
92183 info.low_limit = TASK_UNMAPPED_BASE;
92184 +
92185 +#ifdef CONFIG_PAX_RANDMMAP
92186 + if (mm->pax_flags & MF_PAX_RANDMMAP)
92187 + info.low_limit += mm->delta_mmap;
92188 +#endif
92189 +
92190 info.high_limit = TASK_SIZE;
92191 addr = vm_unmapped_area(&info);
92192 }
92193 @@ -2034,6 +2312,28 @@ find_vma_prev(struct mm_struct *mm, unsigned long addr,
92194 return vma;
92195 }
92196
92197 +#ifdef CONFIG_PAX_SEGMEXEC
92198 +struct vm_area_struct *pax_find_mirror_vma(struct vm_area_struct *vma)
92199 +{
92200 + struct vm_area_struct *vma_m;
92201 +
92202 + BUG_ON(!vma || vma->vm_start >= vma->vm_end);
92203 + if (!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC)) {
92204 + BUG_ON(vma->vm_mirror);
92205 + return NULL;
92206 + }
92207 + BUG_ON(vma->vm_start < SEGMEXEC_TASK_SIZE && SEGMEXEC_TASK_SIZE < vma->vm_end);
92208 + vma_m = vma->vm_mirror;
92209 + BUG_ON(!vma_m || vma_m->vm_mirror != vma);
92210 + BUG_ON(vma->vm_file != vma_m->vm_file);
92211 + BUG_ON(vma->vm_end - vma->vm_start != vma_m->vm_end - vma_m->vm_start);
92212 + BUG_ON(vma->vm_pgoff != vma_m->vm_pgoff);
92213 + BUG_ON(vma->anon_vma != vma_m->anon_vma && vma->anon_vma->root != vma_m->anon_vma->root);
92214 + BUG_ON((vma->vm_flags ^ vma_m->vm_flags) & ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED));
92215 + return vma_m;
92216 +}
92217 +#endif
92218 +
92219 /*
92220 * Verify that the stack growth is acceptable and
92221 * update accounting. This is shared with both the
92222 @@ -2050,6 +2350,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
92223 return -ENOMEM;
92224
92225 /* Stack limit test */
92226 + gr_learn_resource(current, RLIMIT_STACK, size, 1);
92227 if (size > ACCESS_ONCE(rlim[RLIMIT_STACK].rlim_cur))
92228 return -ENOMEM;
92229
92230 @@ -2060,6 +2361,7 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
92231 locked = mm->locked_vm + grow;
92232 limit = ACCESS_ONCE(rlim[RLIMIT_MEMLOCK].rlim_cur);
92233 limit >>= PAGE_SHIFT;
92234 + gr_learn_resource(current, RLIMIT_MEMLOCK, locked << PAGE_SHIFT, 1);
92235 if (locked > limit && !capable(CAP_IPC_LOCK))
92236 return -ENOMEM;
92237 }
92238 @@ -2089,37 +2391,48 @@ static int acct_stack_growth(struct vm_area_struct *vma, unsigned long size, uns
92239 * PA-RISC uses this for its stack; IA64 for its Register Backing Store.
92240 * vma is the last one with address > vma->vm_end. Have to extend vma.
92241 */
92242 +#ifndef CONFIG_IA64
92243 +static
92244 +#endif
92245 int expand_upwards(struct vm_area_struct *vma, unsigned long address)
92246 {
92247 int error;
92248 + bool locknext;
92249
92250 if (!(vma->vm_flags & VM_GROWSUP))
92251 return -EFAULT;
92252
92253 + /* Also guard against wrapping around to address 0. */
92254 + if (address < PAGE_ALIGN(address+1))
92255 + address = PAGE_ALIGN(address+1);
92256 + else
92257 + return -ENOMEM;
92258 +
92259 /*
92260 * We must make sure the anon_vma is allocated
92261 * so that the anon_vma locking is not a noop.
92262 */
92263 if (unlikely(anon_vma_prepare(vma)))
92264 return -ENOMEM;
92265 + locknext = vma->vm_next && (vma->vm_next->vm_flags & VM_GROWSDOWN);
92266 + if (locknext && anon_vma_prepare(vma->vm_next))
92267 + return -ENOMEM;
92268 vma_lock_anon_vma(vma);
92269 + if (locknext)
92270 + vma_lock_anon_vma(vma->vm_next);
92271
92272 /*
92273 * vma->vm_start/vm_end cannot change under us because the caller
92274 * is required to hold the mmap_sem in read mode. We need the
92275 - * anon_vma lock to serialize against concurrent expand_stacks.
92276 - * Also guard against wrapping around to address 0.
92277 + * anon_vma locks to serialize against concurrent expand_stacks
92278 + * and expand_upwards.
92279 */
92280 - if (address < PAGE_ALIGN(address+4))
92281 - address = PAGE_ALIGN(address+4);
92282 - else {
92283 - vma_unlock_anon_vma(vma);
92284 - return -ENOMEM;
92285 - }
92286 error = 0;
92287
92288 /* Somebody else might have raced and expanded it already */
92289 - if (address > vma->vm_end) {
92290 + 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)
92291 + error = -ENOMEM;
92292 + else if (address > vma->vm_end && (!locknext || vma->vm_next->vm_start >= address)) {
92293 unsigned long size, grow;
92294
92295 size = address - vma->vm_start;
92296 @@ -2154,6 +2467,8 @@ int expand_upwards(struct vm_area_struct *vma, unsigned long address)
92297 }
92298 }
92299 }
92300 + if (locknext)
92301 + vma_unlock_anon_vma(vma->vm_next);
92302 vma_unlock_anon_vma(vma);
92303 khugepaged_enter_vma_merge(vma);
92304 validate_mm(vma->vm_mm);
92305 @@ -2168,6 +2483,8 @@ int expand_downwards(struct vm_area_struct *vma,
92306 unsigned long address)
92307 {
92308 int error;
92309 + bool lockprev = false;
92310 + struct vm_area_struct *prev;
92311
92312 /*
92313 * We must make sure the anon_vma is allocated
92314 @@ -2181,6 +2498,15 @@ int expand_downwards(struct vm_area_struct *vma,
92315 if (error)
92316 return error;
92317
92318 + prev = vma->vm_prev;
92319 +#if defined(CONFIG_STACK_GROWSUP) || defined(CONFIG_IA64)
92320 + lockprev = prev && (prev->vm_flags & VM_GROWSUP);
92321 +#endif
92322 + if (lockprev && anon_vma_prepare(prev))
92323 + return -ENOMEM;
92324 + if (lockprev)
92325 + vma_lock_anon_vma(prev);
92326 +
92327 vma_lock_anon_vma(vma);
92328
92329 /*
92330 @@ -2190,9 +2516,17 @@ int expand_downwards(struct vm_area_struct *vma,
92331 */
92332
92333 /* Somebody else might have raced and expanded it already */
92334 - if (address < vma->vm_start) {
92335 + if (prev && (prev->vm_flags & (VM_READ | VM_WRITE | VM_EXEC)) && address - prev->vm_end < sysctl_heap_stack_gap)
92336 + error = -ENOMEM;
92337 + else if (address < vma->vm_start && (!lockprev || prev->vm_end <= address)) {
92338 unsigned long size, grow;
92339
92340 +#ifdef CONFIG_PAX_SEGMEXEC
92341 + struct vm_area_struct *vma_m;
92342 +
92343 + vma_m = pax_find_mirror_vma(vma);
92344 +#endif
92345 +
92346 size = vma->vm_end - address;
92347 grow = (vma->vm_start - address) >> PAGE_SHIFT;
92348
92349 @@ -2217,13 +2551,27 @@ int expand_downwards(struct vm_area_struct *vma,
92350 vma->vm_pgoff -= grow;
92351 anon_vma_interval_tree_post_update_vma(vma);
92352 vma_gap_update(vma);
92353 +
92354 +#ifdef CONFIG_PAX_SEGMEXEC
92355 + if (vma_m) {
92356 + anon_vma_interval_tree_pre_update_vma(vma_m);
92357 + vma_m->vm_start -= grow << PAGE_SHIFT;
92358 + vma_m->vm_pgoff -= grow;
92359 + anon_vma_interval_tree_post_update_vma(vma_m);
92360 + vma_gap_update(vma_m);
92361 + }
92362 +#endif
92363 +
92364 spin_unlock(&vma->vm_mm->page_table_lock);
92365
92366 + track_exec_limit(vma->vm_mm, vma->vm_start, vma->vm_end, vma->vm_flags);
92367 perf_event_mmap(vma);
92368 }
92369 }
92370 }
92371 vma_unlock_anon_vma(vma);
92372 + if (lockprev)
92373 + vma_unlock_anon_vma(prev);
92374 khugepaged_enter_vma_merge(vma);
92375 validate_mm(vma->vm_mm);
92376 return error;
92377 @@ -2321,6 +2669,13 @@ static void remove_vma_list(struct mm_struct *mm, struct vm_area_struct *vma)
92378 do {
92379 long nrpages = vma_pages(vma);
92380
92381 +#ifdef CONFIG_PAX_SEGMEXEC
92382 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_start >= SEGMEXEC_TASK_SIZE)) {
92383 + vma = remove_vma(vma);
92384 + continue;
92385 + }
92386 +#endif
92387 +
92388 if (vma->vm_flags & VM_ACCOUNT)
92389 nr_accounted += nrpages;
92390 vm_stat_account(mm, vma->vm_flags, vma->vm_file, -nrpages);
92391 @@ -2365,6 +2720,16 @@ detach_vmas_to_be_unmapped(struct mm_struct *mm, struct vm_area_struct *vma,
92392 insertion_point = (prev ? &prev->vm_next : &mm->mmap);
92393 vma->vm_prev = NULL;
92394 do {
92395 +
92396 +#ifdef CONFIG_PAX_SEGMEXEC
92397 + if (vma->vm_mirror) {
92398 + BUG_ON(!vma->vm_mirror->vm_mirror || vma->vm_mirror->vm_mirror != vma);
92399 + vma->vm_mirror->vm_mirror = NULL;
92400 + vma->vm_mirror->vm_flags &= ~VM_EXEC;
92401 + vma->vm_mirror = NULL;
92402 + }
92403 +#endif
92404 +
92405 vma_rb_erase(vma, &mm->mm_rb);
92406 mm->map_count--;
92407 tail_vma = vma;
92408 @@ -2390,14 +2755,33 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92409 struct vm_area_struct *new;
92410 int err = -ENOMEM;
92411
92412 +#ifdef CONFIG_PAX_SEGMEXEC
92413 + struct vm_area_struct *vma_m, *new_m = NULL;
92414 + unsigned long addr_m = addr + SEGMEXEC_TASK_SIZE;
92415 +#endif
92416 +
92417 if (is_vm_hugetlb_page(vma) && (addr &
92418 ~(huge_page_mask(hstate_vma(vma)))))
92419 return -EINVAL;
92420
92421 +#ifdef CONFIG_PAX_SEGMEXEC
92422 + vma_m = pax_find_mirror_vma(vma);
92423 +#endif
92424 +
92425 new = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
92426 if (!new)
92427 goto out_err;
92428
92429 +#ifdef CONFIG_PAX_SEGMEXEC
92430 + if (vma_m) {
92431 + new_m = kmem_cache_alloc(vm_area_cachep, GFP_KERNEL);
92432 + if (!new_m) {
92433 + kmem_cache_free(vm_area_cachep, new);
92434 + goto out_err;
92435 + }
92436 + }
92437 +#endif
92438 +
92439 /* most fields are the same, copy all, and then fixup */
92440 *new = *vma;
92441
92442 @@ -2410,6 +2794,22 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92443 new->vm_pgoff += ((addr - vma->vm_start) >> PAGE_SHIFT);
92444 }
92445
92446 +#ifdef CONFIG_PAX_SEGMEXEC
92447 + if (vma_m) {
92448 + *new_m = *vma_m;
92449 + INIT_LIST_HEAD(&new_m->anon_vma_chain);
92450 + new_m->vm_mirror = new;
92451 + new->vm_mirror = new_m;
92452 +
92453 + if (new_below)
92454 + new_m->vm_end = addr_m;
92455 + else {
92456 + new_m->vm_start = addr_m;
92457 + new_m->vm_pgoff += ((addr_m - vma_m->vm_start) >> PAGE_SHIFT);
92458 + }
92459 + }
92460 +#endif
92461 +
92462 err = vma_dup_policy(vma, new);
92463 if (err)
92464 goto out_free_vma;
92465 @@ -2429,6 +2829,38 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92466 else
92467 err = vma_adjust(vma, vma->vm_start, addr, vma->vm_pgoff, new);
92468
92469 +#ifdef CONFIG_PAX_SEGMEXEC
92470 + if (!err && vma_m) {
92471 + struct mempolicy *pol = vma_policy(new);
92472 +
92473 + if (anon_vma_clone(new_m, vma_m))
92474 + goto out_free_mpol;
92475 +
92476 + mpol_get(pol);
92477 + set_vma_policy(new_m, pol);
92478 +
92479 + if (new_m->vm_file)
92480 + get_file(new_m->vm_file);
92481 +
92482 + if (new_m->vm_ops && new_m->vm_ops->open)
92483 + new_m->vm_ops->open(new_m);
92484 +
92485 + if (new_below)
92486 + err = vma_adjust(vma_m, addr_m, vma_m->vm_end, vma_m->vm_pgoff +
92487 + ((addr_m - new_m->vm_start) >> PAGE_SHIFT), new_m);
92488 + else
92489 + err = vma_adjust(vma_m, vma_m->vm_start, addr_m, vma_m->vm_pgoff, new_m);
92490 +
92491 + if (err) {
92492 + if (new_m->vm_ops && new_m->vm_ops->close)
92493 + new_m->vm_ops->close(new_m);
92494 + if (new_m->vm_file)
92495 + fput(new_m->vm_file);
92496 + mpol_put(pol);
92497 + }
92498 + }
92499 +#endif
92500 +
92501 /* Success. */
92502 if (!err)
92503 return 0;
92504 @@ -2438,10 +2870,18 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92505 new->vm_ops->close(new);
92506 if (new->vm_file)
92507 fput(new->vm_file);
92508 - unlink_anon_vmas(new);
92509 out_free_mpol:
92510 mpol_put(vma_policy(new));
92511 out_free_vma:
92512 +
92513 +#ifdef CONFIG_PAX_SEGMEXEC
92514 + if (new_m) {
92515 + unlink_anon_vmas(new_m);
92516 + kmem_cache_free(vm_area_cachep, new_m);
92517 + }
92518 +#endif
92519 +
92520 + unlink_anon_vmas(new);
92521 kmem_cache_free(vm_area_cachep, new);
92522 out_err:
92523 return err;
92524 @@ -2454,6 +2894,15 @@ static int __split_vma(struct mm_struct * mm, struct vm_area_struct * vma,
92525 int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
92526 unsigned long addr, int new_below)
92527 {
92528 +
92529 +#ifdef CONFIG_PAX_SEGMEXEC
92530 + if (mm->pax_flags & MF_PAX_SEGMEXEC) {
92531 + BUG_ON(vma->vm_end > SEGMEXEC_TASK_SIZE);
92532 + if (mm->map_count >= sysctl_max_map_count-1)
92533 + return -ENOMEM;
92534 + } else
92535 +#endif
92536 +
92537 if (mm->map_count >= sysctl_max_map_count)
92538 return -ENOMEM;
92539
92540 @@ -2465,11 +2914,30 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
92541 * work. This now handles partial unmappings.
92542 * Jeremy Fitzhardinge <jeremy@goop.org>
92543 */
92544 +#ifdef CONFIG_PAX_SEGMEXEC
92545 int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92546 {
92547 + int ret = __do_munmap(mm, start, len);
92548 + if (ret || !(mm->pax_flags & MF_PAX_SEGMEXEC))
92549 + return ret;
92550 +
92551 + return __do_munmap(mm, start + SEGMEXEC_TASK_SIZE, len);
92552 +}
92553 +
92554 +int __do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92555 +#else
92556 +int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92557 +#endif
92558 +{
92559 unsigned long end;
92560 struct vm_area_struct *vma, *prev, *last;
92561
92562 + /*
92563 + * mm->mmap_sem is required to protect against another thread
92564 + * changing the mappings in case we sleep.
92565 + */
92566 + verify_mm_writelocked(mm);
92567 +
92568 if ((start & ~PAGE_MASK) || start > TASK_SIZE || len > TASK_SIZE-start)
92569 return -EINVAL;
92570
92571 @@ -2544,6 +3012,8 @@ int do_munmap(struct mm_struct *mm, unsigned long start, size_t len)
92572 /* Fix up all other VM information */
92573 remove_vma_list(mm, vma);
92574
92575 + track_exec_limit(mm, start, end, 0UL);
92576 +
92577 return 0;
92578 }
92579
92580 @@ -2552,6 +3022,13 @@ int vm_munmap(unsigned long start, size_t len)
92581 int ret;
92582 struct mm_struct *mm = current->mm;
92583
92584 +
92585 +#ifdef CONFIG_PAX_SEGMEXEC
92586 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) &&
92587 + (len > SEGMEXEC_TASK_SIZE || start > SEGMEXEC_TASK_SIZE-len))
92588 + return -EINVAL;
92589 +#endif
92590 +
92591 down_write(&mm->mmap_sem);
92592 ret = do_munmap(mm, start, len);
92593 up_write(&mm->mmap_sem);
92594 @@ -2565,16 +3042,6 @@ SYSCALL_DEFINE2(munmap, unsigned long, addr, size_t, len)
92595 return vm_munmap(addr, len);
92596 }
92597
92598 -static inline void verify_mm_writelocked(struct mm_struct *mm)
92599 -{
92600 -#ifdef CONFIG_DEBUG_VM
92601 - if (unlikely(down_read_trylock(&mm->mmap_sem))) {
92602 - WARN_ON(1);
92603 - up_read(&mm->mmap_sem);
92604 - }
92605 -#endif
92606 -}
92607 -
92608 /*
92609 * this is really a simplified "do_mmap". it only handles
92610 * anonymous maps. eventually we may be able to do some
92611 @@ -2588,6 +3055,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92612 struct rb_node ** rb_link, * rb_parent;
92613 pgoff_t pgoff = addr >> PAGE_SHIFT;
92614 int error;
92615 + unsigned long charged;
92616
92617 len = PAGE_ALIGN(len);
92618 if (!len)
92619 @@ -2595,16 +3063,30 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92620
92621 flags = VM_DATA_DEFAULT_FLAGS | VM_ACCOUNT | mm->def_flags;
92622
92623 +#if defined(CONFIG_PAX_PAGEEXEC) || defined(CONFIG_PAX_SEGMEXEC)
92624 + if (mm->pax_flags & (MF_PAX_PAGEEXEC | MF_PAX_SEGMEXEC)) {
92625 + flags &= ~VM_EXEC;
92626 +
92627 +#ifdef CONFIG_PAX_MPROTECT
92628 + if (mm->pax_flags & MF_PAX_MPROTECT)
92629 + flags &= ~VM_MAYEXEC;
92630 +#endif
92631 +
92632 + }
92633 +#endif
92634 +
92635 error = get_unmapped_area(NULL, addr, len, 0, MAP_FIXED);
92636 if (error & ~PAGE_MASK)
92637 return error;
92638
92639 + charged = len >> PAGE_SHIFT;
92640 +
92641 /*
92642 * mlock MCL_FUTURE?
92643 */
92644 if (mm->def_flags & VM_LOCKED) {
92645 unsigned long locked, lock_limit;
92646 - locked = len >> PAGE_SHIFT;
92647 + locked = charged;
92648 locked += mm->locked_vm;
92649 lock_limit = rlimit(RLIMIT_MEMLOCK);
92650 lock_limit >>= PAGE_SHIFT;
92651 @@ -2621,21 +3103,20 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92652 /*
92653 * Clear old maps. this also does some error checking for us
92654 */
92655 - munmap_back:
92656 if (find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent)) {
92657 if (do_munmap(mm, addr, len))
92658 return -ENOMEM;
92659 - goto munmap_back;
92660 + BUG_ON(find_vma_links(mm, addr, addr + len, &prev, &rb_link, &rb_parent));
92661 }
92662
92663 /* Check against address space limits *after* clearing old maps... */
92664 - if (!may_expand_vm(mm, len >> PAGE_SHIFT))
92665 + if (!may_expand_vm(mm, charged))
92666 return -ENOMEM;
92667
92668 if (mm->map_count > sysctl_max_map_count)
92669 return -ENOMEM;
92670
92671 - if (security_vm_enough_memory_mm(mm, len >> PAGE_SHIFT))
92672 + if (security_vm_enough_memory_mm(mm, charged))
92673 return -ENOMEM;
92674
92675 /* Can we just expand an old private anonymous mapping? */
92676 @@ -2649,7 +3130,7 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92677 */
92678 vma = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92679 if (!vma) {
92680 - vm_unacct_memory(len >> PAGE_SHIFT);
92681 + vm_unacct_memory(charged);
92682 return -ENOMEM;
92683 }
92684
92685 @@ -2663,10 +3144,11 @@ static unsigned long do_brk(unsigned long addr, unsigned long len)
92686 vma_link(mm, vma, prev, rb_link, rb_parent);
92687 out:
92688 perf_event_mmap(vma);
92689 - mm->total_vm += len >> PAGE_SHIFT;
92690 + mm->total_vm += charged;
92691 if (flags & VM_LOCKED)
92692 - mm->locked_vm += (len >> PAGE_SHIFT);
92693 + mm->locked_vm += charged;
92694 vma->vm_flags |= VM_SOFTDIRTY;
92695 + track_exec_limit(mm, addr, addr + len, flags);
92696 return addr;
92697 }
92698
92699 @@ -2728,6 +3210,7 @@ void exit_mmap(struct mm_struct *mm)
92700 while (vma) {
92701 if (vma->vm_flags & VM_ACCOUNT)
92702 nr_accounted += vma_pages(vma);
92703 + vma->vm_mirror = NULL;
92704 vma = remove_vma(vma);
92705 }
92706 vm_unacct_memory(nr_accounted);
92707 @@ -2745,6 +3228,13 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
92708 struct vm_area_struct *prev;
92709 struct rb_node **rb_link, *rb_parent;
92710
92711 +#ifdef CONFIG_PAX_SEGMEXEC
92712 + struct vm_area_struct *vma_m = NULL;
92713 +#endif
92714 +
92715 + if (security_mmap_addr(vma->vm_start))
92716 + return -EPERM;
92717 +
92718 /*
92719 * The vm_pgoff of a purely anonymous vma should be irrelevant
92720 * until its first write fault, when page's anon_vma and index
92721 @@ -2768,7 +3258,21 @@ int insert_vm_struct(struct mm_struct *mm, struct vm_area_struct *vma)
92722 security_vm_enough_memory_mm(mm, vma_pages(vma)))
92723 return -ENOMEM;
92724
92725 +#ifdef CONFIG_PAX_SEGMEXEC
92726 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (vma->vm_flags & VM_EXEC)) {
92727 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92728 + if (!vma_m)
92729 + return -ENOMEM;
92730 + }
92731 +#endif
92732 +
92733 vma_link(mm, vma, prev, rb_link, rb_parent);
92734 +
92735 +#ifdef CONFIG_PAX_SEGMEXEC
92736 + if (vma_m)
92737 + BUG_ON(pax_mirror_vma(vma_m, vma));
92738 +#endif
92739 +
92740 return 0;
92741 }
92742
92743 @@ -2787,6 +3291,8 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
92744 struct rb_node **rb_link, *rb_parent;
92745 bool faulted_in_anon_vma = true;
92746
92747 + BUG_ON(vma->vm_mirror);
92748 +
92749 /*
92750 * If anonymous vma has not yet been faulted, update new pgoff
92751 * to match new location, to increase its chance of merging.
92752 @@ -2851,6 +3357,39 @@ struct vm_area_struct *copy_vma(struct vm_area_struct **vmap,
92753 return NULL;
92754 }
92755
92756 +#ifdef CONFIG_PAX_SEGMEXEC
92757 +long pax_mirror_vma(struct vm_area_struct *vma_m, struct vm_area_struct *vma)
92758 +{
92759 + struct vm_area_struct *prev_m;
92760 + struct rb_node **rb_link_m, *rb_parent_m;
92761 + struct mempolicy *pol_m;
92762 +
92763 + BUG_ON(!(vma->vm_mm->pax_flags & MF_PAX_SEGMEXEC) || !(vma->vm_flags & VM_EXEC));
92764 + BUG_ON(vma->vm_mirror || vma_m->vm_mirror);
92765 + BUG_ON(!mpol_equal(vma_policy(vma), vma_policy(vma_m)));
92766 + *vma_m = *vma;
92767 + INIT_LIST_HEAD(&vma_m->anon_vma_chain);
92768 + if (anon_vma_clone(vma_m, vma))
92769 + return -ENOMEM;
92770 + pol_m = vma_policy(vma_m);
92771 + mpol_get(pol_m);
92772 + set_vma_policy(vma_m, pol_m);
92773 + vma_m->vm_start += SEGMEXEC_TASK_SIZE;
92774 + vma_m->vm_end += SEGMEXEC_TASK_SIZE;
92775 + vma_m->vm_flags &= ~(VM_WRITE | VM_MAYWRITE | VM_ACCOUNT | VM_LOCKED);
92776 + vma_m->vm_page_prot = vm_get_page_prot(vma_m->vm_flags);
92777 + if (vma_m->vm_file)
92778 + get_file(vma_m->vm_file);
92779 + if (vma_m->vm_ops && vma_m->vm_ops->open)
92780 + vma_m->vm_ops->open(vma_m);
92781 + BUG_ON(find_vma_links(vma->vm_mm, vma_m->vm_start, vma_m->vm_end, &prev_m, &rb_link_m, &rb_parent_m));
92782 + vma_link(vma->vm_mm, vma_m, prev_m, rb_link_m, rb_parent_m);
92783 + vma_m->vm_mirror = vma;
92784 + vma->vm_mirror = vma_m;
92785 + return 0;
92786 +}
92787 +#endif
92788 +
92789 /*
92790 * Return true if the calling process may expand its vm space by the passed
92791 * number of pages
92792 @@ -2862,6 +3401,7 @@ int may_expand_vm(struct mm_struct *mm, unsigned long npages)
92793
92794 lim = rlimit(RLIMIT_AS) >> PAGE_SHIFT;
92795
92796 + gr_learn_resource(current, RLIMIT_AS, (cur + npages) << PAGE_SHIFT, 1);
92797 if (cur + npages > lim)
92798 return 0;
92799 return 1;
92800 @@ -2932,6 +3472,22 @@ int install_special_mapping(struct mm_struct *mm,
92801 vma->vm_start = addr;
92802 vma->vm_end = addr + len;
92803
92804 +#ifdef CONFIG_PAX_MPROTECT
92805 + if (mm->pax_flags & MF_PAX_MPROTECT) {
92806 +#ifndef CONFIG_PAX_MPROTECT_COMPAT
92807 + if ((vm_flags & (VM_WRITE | VM_EXEC)) == (VM_WRITE | VM_EXEC))
92808 + return -EPERM;
92809 + if (!(vm_flags & VM_EXEC))
92810 + vm_flags &= ~VM_MAYEXEC;
92811 +#else
92812 + if ((vm_flags & (VM_WRITE | VM_EXEC)) != VM_EXEC)
92813 + vm_flags &= ~(VM_EXEC | VM_MAYEXEC);
92814 +#endif
92815 + else
92816 + vm_flags &= ~VM_MAYWRITE;
92817 + }
92818 +#endif
92819 +
92820 vma->vm_flags = vm_flags | mm->def_flags | VM_DONTEXPAND | VM_SOFTDIRTY;
92821 vma->vm_page_prot = vm_get_page_prot(vma->vm_flags);
92822
92823 diff --git a/mm/mprotect.c b/mm/mprotect.c
92824 index bb53a65..249c052 100644
92825 --- a/mm/mprotect.c
92826 +++ b/mm/mprotect.c
92827 @@ -23,10 +23,18 @@
92828 #include <linux/mmu_notifier.h>
92829 #include <linux/migrate.h>
92830 #include <linux/perf_event.h>
92831 +#include <linux/sched/sysctl.h>
92832 +
92833 +#ifdef CONFIG_PAX_MPROTECT
92834 +#include <linux/elf.h>
92835 +#include <linux/binfmts.h>
92836 +#endif
92837 +
92838 #include <asm/uaccess.h>
92839 #include <asm/pgtable.h>
92840 #include <asm/cacheflush.h>
92841 #include <asm/tlbflush.h>
92842 +#include <asm/mmu_context.h>
92843
92844 #ifndef pgprot_modify
92845 static inline pgprot_t pgprot_modify(pgprot_t oldprot, pgprot_t newprot)
92846 @@ -222,6 +230,48 @@ unsigned long change_protection(struct vm_area_struct *vma, unsigned long start,
92847 return pages;
92848 }
92849
92850 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
92851 +/* called while holding the mmap semaphor for writing except stack expansion */
92852 +void track_exec_limit(struct mm_struct *mm, unsigned long start, unsigned long end, unsigned long prot)
92853 +{
92854 + unsigned long oldlimit, newlimit = 0UL;
92855 +
92856 + if (!(mm->pax_flags & MF_PAX_PAGEEXEC) || (__supported_pte_mask & _PAGE_NX))
92857 + return;
92858 +
92859 + spin_lock(&mm->page_table_lock);
92860 + oldlimit = mm->context.user_cs_limit;
92861 + if ((prot & VM_EXEC) && oldlimit < end)
92862 + /* USER_CS limit moved up */
92863 + newlimit = end;
92864 + else if (!(prot & VM_EXEC) && start < oldlimit && oldlimit <= end)
92865 + /* USER_CS limit moved down */
92866 + newlimit = start;
92867 +
92868 + if (newlimit) {
92869 + mm->context.user_cs_limit = newlimit;
92870 +
92871 +#ifdef CONFIG_SMP
92872 + wmb();
92873 + cpus_clear(mm->context.cpu_user_cs_mask);
92874 + cpu_set(smp_processor_id(), mm->context.cpu_user_cs_mask);
92875 +#endif
92876 +
92877 + set_user_cs(mm->context.user_cs_base, mm->context.user_cs_limit, smp_processor_id());
92878 + }
92879 + spin_unlock(&mm->page_table_lock);
92880 + if (newlimit == end) {
92881 + struct vm_area_struct *vma = find_vma(mm, oldlimit);
92882 +
92883 + for (; vma && vma->vm_start < end; vma = vma->vm_next)
92884 + if (is_vm_hugetlb_page(vma))
92885 + hugetlb_change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot);
92886 + else
92887 + change_protection(vma, vma->vm_start, vma->vm_end, vma->vm_page_prot, vma_wants_writenotify(vma), 0);
92888 + }
92889 +}
92890 +#endif
92891 +
92892 int
92893 mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
92894 unsigned long start, unsigned long end, unsigned long newflags)
92895 @@ -234,11 +284,29 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
92896 int error;
92897 int dirty_accountable = 0;
92898
92899 +#ifdef CONFIG_PAX_SEGMEXEC
92900 + struct vm_area_struct *vma_m = NULL;
92901 + unsigned long start_m, end_m;
92902 +
92903 + start_m = start + SEGMEXEC_TASK_SIZE;
92904 + end_m = end + SEGMEXEC_TASK_SIZE;
92905 +#endif
92906 +
92907 if (newflags == oldflags) {
92908 *pprev = vma;
92909 return 0;
92910 }
92911
92912 + if (newflags & (VM_READ | VM_WRITE | VM_EXEC)) {
92913 + struct vm_area_struct *prev = vma->vm_prev, *next = vma->vm_next;
92914 +
92915 + if (next && (next->vm_flags & VM_GROWSDOWN) && sysctl_heap_stack_gap > next->vm_start - end)
92916 + return -ENOMEM;
92917 +
92918 + if (prev && (prev->vm_flags & VM_GROWSUP) && sysctl_heap_stack_gap > start - prev->vm_end)
92919 + return -ENOMEM;
92920 + }
92921 +
92922 /*
92923 * If we make a private mapping writable we increase our commit;
92924 * but (without finer accounting) cannot reduce our commit if we
92925 @@ -255,6 +323,42 @@ mprotect_fixup(struct vm_area_struct *vma, struct vm_area_struct **pprev,
92926 }
92927 }
92928
92929 +#ifdef CONFIG_PAX_SEGMEXEC
92930 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && ((oldflags ^ newflags) & VM_EXEC)) {
92931 + if (start != vma->vm_start) {
92932 + error = split_vma(mm, vma, start, 1);
92933 + if (error)
92934 + goto fail;
92935 + BUG_ON(!*pprev || (*pprev)->vm_next == vma);
92936 + *pprev = (*pprev)->vm_next;
92937 + }
92938 +
92939 + if (end != vma->vm_end) {
92940 + error = split_vma(mm, vma, end, 0);
92941 + if (error)
92942 + goto fail;
92943 + }
92944 +
92945 + if (pax_find_mirror_vma(vma)) {
92946 + error = __do_munmap(mm, start_m, end_m - start_m);
92947 + if (error)
92948 + goto fail;
92949 + } else {
92950 + vma_m = kmem_cache_zalloc(vm_area_cachep, GFP_KERNEL);
92951 + if (!vma_m) {
92952 + error = -ENOMEM;
92953 + goto fail;
92954 + }
92955 + vma->vm_flags = newflags;
92956 + error = pax_mirror_vma(vma_m, vma);
92957 + if (error) {
92958 + vma->vm_flags = oldflags;
92959 + goto fail;
92960 + }
92961 + }
92962 + }
92963 +#endif
92964 +
92965 /*
92966 * First try to merge with previous and/or next vma.
92967 */
92968 @@ -285,9 +389,21 @@ success:
92969 * vm_flags and vm_page_prot are protected by the mmap_sem
92970 * held in write mode.
92971 */
92972 +
92973 +#ifdef CONFIG_PAX_SEGMEXEC
92974 + if ((mm->pax_flags & MF_PAX_SEGMEXEC) && (newflags & VM_EXEC) && ((vma->vm_flags ^ newflags) & VM_READ))
92975 + pax_find_mirror_vma(vma)->vm_flags ^= VM_READ;
92976 +#endif
92977 +
92978 vma->vm_flags = newflags;
92979 +
92980 +#ifdef CONFIG_PAX_MPROTECT
92981 + if (mm->binfmt && mm->binfmt->handle_mprotect)
92982 + mm->binfmt->handle_mprotect(vma, newflags);
92983 +#endif
92984 +
92985 vma->vm_page_prot = pgprot_modify(vma->vm_page_prot,
92986 - vm_get_page_prot(newflags));
92987 + vm_get_page_prot(vma->vm_flags));
92988
92989 if (vma_wants_writenotify(vma)) {
92990 vma->vm_page_prot = vm_get_page_prot(newflags & ~VM_SHARED);
92991 @@ -326,6 +442,17 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
92992 end = start + len;
92993 if (end <= start)
92994 return -ENOMEM;
92995 +
92996 +#ifdef CONFIG_PAX_SEGMEXEC
92997 + if (current->mm->pax_flags & MF_PAX_SEGMEXEC) {
92998 + if (end > SEGMEXEC_TASK_SIZE)
92999 + return -EINVAL;
93000 + } else
93001 +#endif
93002 +
93003 + if (end > TASK_SIZE)
93004 + return -EINVAL;
93005 +
93006 if (!arch_validate_prot(prot))
93007 return -EINVAL;
93008
93009 @@ -333,7 +460,7 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
93010 /*
93011 * Does the application expect PROT_READ to imply PROT_EXEC:
93012 */
93013 - if ((prot & PROT_READ) && (current->personality & READ_IMPLIES_EXEC))
93014 + if ((prot & (PROT_READ | PROT_WRITE)) && (current->personality & READ_IMPLIES_EXEC))
93015 prot |= PROT_EXEC;
93016
93017 vm_flags = calc_vm_prot_bits(prot);
93018 @@ -365,6 +492,11 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
93019 if (start > vma->vm_start)
93020 prev = vma;
93021
93022 +#ifdef CONFIG_PAX_MPROTECT
93023 + if (current->mm->binfmt && current->mm->binfmt->handle_mprotect)
93024 + current->mm->binfmt->handle_mprotect(vma, vm_flags);
93025 +#endif
93026 +
93027 for (nstart = start ; ; ) {
93028 unsigned long newflags;
93029
93030 @@ -375,6 +507,14 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
93031
93032 /* newflags >> 4 shift VM_MAY% in place of VM_% */
93033 if ((newflags & ~(newflags >> 4)) & (VM_READ | VM_WRITE | VM_EXEC)) {
93034 + if (prot & (PROT_WRITE | PROT_EXEC))
93035 + gr_log_rwxmprotect(vma);
93036 +
93037 + error = -EACCES;
93038 + goto out;
93039 + }
93040 +
93041 + if (!gr_acl_handle_mprotect(vma->vm_file, prot)) {
93042 error = -EACCES;
93043 goto out;
93044 }
93045 @@ -389,6 +529,9 @@ SYSCALL_DEFINE3(mprotect, unsigned long, start, size_t, len,
93046 error = mprotect_fixup(vma, &prev, nstart, tmp, newflags);
93047 if (error)
93048 goto out;
93049 +
93050 + track_exec_limit(current->mm, nstart, tmp, vm_flags);
93051 +
93052 nstart = tmp;
93053
93054 if (nstart < prev->vm_end)
93055 diff --git a/mm/mremap.c b/mm/mremap.c
93056 index 0843feb..4f5b2e6 100644
93057 --- a/mm/mremap.c
93058 +++ b/mm/mremap.c
93059 @@ -144,6 +144,12 @@ static void move_ptes(struct vm_area_struct *vma, pmd_t *old_pmd,
93060 continue;
93061 pte = ptep_get_and_clear(mm, old_addr, old_pte);
93062 pte = move_pte(pte, new_vma->vm_page_prot, old_addr, new_addr);
93063 +
93064 +#ifdef CONFIG_ARCH_TRACK_EXEC_LIMIT
93065 + if (!(__supported_pte_mask & _PAGE_NX) && pte_present(pte) && (new_vma->vm_flags & (VM_PAGEEXEC | VM_EXEC)) == VM_PAGEEXEC)
93066 + pte = pte_exprotect(pte);
93067 +#endif
93068 +
93069 pte = move_soft_dirty_pte(pte);
93070 set_pte_at(mm, new_addr, new_pte, pte);
93071 }
93072 @@ -337,6 +343,11 @@ static struct vm_area_struct *vma_to_resize(unsigned long addr,
93073 if (is_vm_hugetlb_page(vma))
93074 goto Einval;
93075
93076 +#ifdef CONFIG_PAX_SEGMEXEC
93077 + if (pax_find_mirror_vma(vma))
93078 + goto Einval;
93079 +#endif
93080 +
93081 /* We can't remap across vm area boundaries */
93082 if (old_len > vma->vm_end - addr)
93083 goto Efault;
93084 @@ -392,20 +403,25 @@ static unsigned long mremap_to(unsigned long addr, unsigned long old_len,
93085 unsigned long ret = -EINVAL;
93086 unsigned long charged = 0;
93087 unsigned long map_flags;
93088 + unsigned long pax_task_size = TASK_SIZE;
93089
93090 if (new_addr & ~PAGE_MASK)
93091 goto out;
93092
93093 - if (new_len > TASK_SIZE || new_addr > TASK_SIZE - new_len)
93094 +#ifdef CONFIG_PAX_SEGMEXEC
93095 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
93096 + pax_task_size = SEGMEXEC_TASK_SIZE;
93097 +#endif
93098 +
93099 + pax_task_size -= PAGE_SIZE;
93100 +
93101 + if (new_len > TASK_SIZE || new_addr > pax_task_size - new_len)
93102 goto out;
93103
93104 /* Check if the location we're moving into overlaps the
93105 * old location at all, and fail if it does.
93106 */
93107 - if ((new_addr <= addr) && (new_addr+new_len) > addr)
93108 - goto out;
93109 -
93110 - if ((addr <= new_addr) && (addr+old_len) > new_addr)
93111 + if (addr + old_len > new_addr && new_addr + new_len > addr)
93112 goto out;
93113
93114 ret = do_munmap(mm, new_addr, new_len);
93115 @@ -474,6 +490,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
93116 unsigned long ret = -EINVAL;
93117 unsigned long charged = 0;
93118 bool locked = false;
93119 + unsigned long pax_task_size = TASK_SIZE;
93120
93121 if (flags & ~(MREMAP_FIXED | MREMAP_MAYMOVE))
93122 return ret;
93123 @@ -495,6 +512,17 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
93124 if (!new_len)
93125 return ret;
93126
93127 +#ifdef CONFIG_PAX_SEGMEXEC
93128 + if (mm->pax_flags & MF_PAX_SEGMEXEC)
93129 + pax_task_size = SEGMEXEC_TASK_SIZE;
93130 +#endif
93131 +
93132 + pax_task_size -= PAGE_SIZE;
93133 +
93134 + if (new_len > pax_task_size || addr > pax_task_size-new_len ||
93135 + old_len > pax_task_size || addr > pax_task_size-old_len)
93136 + return ret;
93137 +
93138 down_write(&current->mm->mmap_sem);
93139
93140 if (flags & MREMAP_FIXED) {
93141 @@ -545,6 +573,7 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
93142 new_addr = addr;
93143 }
93144 ret = addr;
93145 + track_exec_limit(vma->vm_mm, vma->vm_start, addr + new_len, vma->vm_flags);
93146 goto out;
93147 }
93148 }
93149 @@ -568,7 +597,12 @@ SYSCALL_DEFINE5(mremap, unsigned long, addr, unsigned long, old_len,
93150 goto out;
93151 }
93152
93153 + map_flags = vma->vm_flags;
93154 ret = move_vma(vma, addr, old_len, new_len, new_addr, &locked);
93155 + if (!(ret & ~PAGE_MASK)) {
93156 + track_exec_limit(current->mm, addr, addr + old_len, 0UL);
93157 + track_exec_limit(current->mm, new_addr, new_addr + new_len, map_flags);
93158 + }
93159 }
93160 out:
93161 if (ret & ~PAGE_MASK)
93162 diff --git a/mm/nommu.c b/mm/nommu.c
93163 index fec093a..8162f74 100644
93164 --- a/mm/nommu.c
93165 +++ b/mm/nommu.c
93166 @@ -64,7 +64,6 @@ int sysctl_max_map_count = DEFAULT_MAX_MAP_COUNT;
93167 int sysctl_nr_trim_pages = CONFIG_NOMMU_INITIAL_TRIM_EXCESS;
93168 unsigned long sysctl_user_reserve_kbytes __read_mostly = 1UL << 17; /* 128MB */
93169 unsigned long sysctl_admin_reserve_kbytes __read_mostly = 1UL << 13; /* 8MB */
93170 -int heap_stack_gap = 0;
93171
93172 atomic_long_t mmap_pages_allocated;
93173
93174 @@ -844,15 +843,6 @@ struct vm_area_struct *find_vma(struct mm_struct *mm, unsigned long addr)
93175 EXPORT_SYMBOL(find_vma);
93176
93177 /*
93178 - * find a VMA
93179 - * - we don't extend stack VMAs under NOMMU conditions
93180 - */
93181 -struct vm_area_struct *find_extend_vma(struct mm_struct *mm, unsigned long addr)
93182 -{
93183 - return find_vma(mm, addr);
93184 -}
93185 -
93186 -/*
93187 * expand a stack to a given address
93188 * - not supported under NOMMU conditions
93189 */
93190 @@ -1563,6 +1553,7 @@ int split_vma(struct mm_struct *mm, struct vm_area_struct *vma,
93191
93192 /* most fields are the same, copy all, and then fixup */
93193 *new = *vma;
93194 + INIT_LIST_HEAD(&new->anon_vma_chain);
93195 *region = *vma->vm_region;
93196 new->vm_region = region;
93197
93198 @@ -1992,8 +1983,8 @@ int generic_file_remap_pages(struct vm_area_struct *vma, unsigned long addr,
93199 }
93200 EXPORT_SYMBOL(generic_file_remap_pages);
93201
93202 -static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93203 - unsigned long addr, void *buf, int len, int write)
93204 +static ssize_t __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93205 + unsigned long addr, void *buf, size_t len, int write)
93206 {
93207 struct vm_area_struct *vma;
93208
93209 @@ -2034,8 +2025,8 @@ static int __access_remote_vm(struct task_struct *tsk, struct mm_struct *mm,
93210 *
93211 * The caller must hold a reference on @mm.
93212 */
93213 -int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93214 - void *buf, int len, int write)
93215 +ssize_t access_remote_vm(struct mm_struct *mm, unsigned long addr,
93216 + void *buf, size_t len, int write)
93217 {
93218 return __access_remote_vm(NULL, mm, addr, buf, len, write);
93219 }
93220 @@ -2044,7 +2035,7 @@ int access_remote_vm(struct mm_struct *mm, unsigned long addr,
93221 * Access another process' address space.
93222 * - source/target buffer must be kernel space
93223 */
93224 -int access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, int len, int write)
93225 +ssize_t access_process_vm(struct task_struct *tsk, unsigned long addr, void *buf, size_t len, int write)
93226 {
93227 struct mm_struct *mm;
93228
93229 diff --git a/mm/page-writeback.c b/mm/page-writeback.c
93230 index 2d30e2c..8b3d14c 100644
93231 --- a/mm/page-writeback.c
93232 +++ b/mm/page-writeback.c
93233 @@ -685,7 +685,7 @@ static inline long long pos_ratio_polynom(unsigned long setpoint,
93234 * card's bdi_dirty may rush to many times higher than bdi_setpoint.
93235 * - the bdi dirty thresh drops quickly due to change of JBOD workload
93236 */
93237 -static unsigned long bdi_position_ratio(struct backing_dev_info *bdi,
93238 +static unsigned long __intentional_overflow(-1) bdi_position_ratio(struct backing_dev_info *bdi,
93239 unsigned long thresh,
93240 unsigned long bg_thresh,
93241 unsigned long dirty,
93242 diff --git a/mm/page_alloc.c b/mm/page_alloc.c
93243 index 5248fe0..0f693aa 100644
93244 --- a/mm/page_alloc.c
93245 +++ b/mm/page_alloc.c
93246 @@ -61,6 +61,7 @@
93247 #include <linux/page-debug-flags.h>
93248 #include <linux/hugetlb.h>
93249 #include <linux/sched/rt.h>
93250 +#include <linux/random.h>
93251
93252 #include <asm/sections.h>
93253 #include <asm/tlbflush.h>
93254 @@ -354,7 +355,7 @@ out:
93255 * This usage means that zero-order pages may not be compound.
93256 */
93257
93258 -static void free_compound_page(struct page *page)
93259 +void free_compound_page(struct page *page)
93260 {
93261 __free_pages_ok(page, compound_order(page));
93262 }
93263 @@ -712,6 +713,10 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
93264 int i;
93265 int bad = 0;
93266
93267 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93268 + unsigned long index = 1UL << order;
93269 +#endif
93270 +
93271 trace_mm_page_free(page, order);
93272 kmemcheck_free_shadow(page, order);
93273
93274 @@ -728,6 +733,12 @@ static bool free_pages_prepare(struct page *page, unsigned int order)
93275 debug_check_no_obj_freed(page_address(page),
93276 PAGE_SIZE << order);
93277 }
93278 +
93279 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93280 + for (; index; --index)
93281 + sanitize_highpage(page + index - 1);
93282 +#endif
93283 +
93284 arch_free_page(page, order);
93285 kernel_map_pages(page, 1 << order, 0);
93286
93287 @@ -750,6 +761,20 @@ static void __free_pages_ok(struct page *page, unsigned int order)
93288 local_irq_restore(flags);
93289 }
93290
93291 +#ifdef CONFIG_PAX_LATENT_ENTROPY
93292 +bool __meminitdata extra_latent_entropy;
93293 +
93294 +static int __init setup_pax_extra_latent_entropy(char *str)
93295 +{
93296 + extra_latent_entropy = true;
93297 + return 0;
93298 +}
93299 +early_param("pax_extra_latent_entropy", setup_pax_extra_latent_entropy);
93300 +
93301 +volatile u64 latent_entropy __latent_entropy;
93302 +EXPORT_SYMBOL(latent_entropy);
93303 +#endif
93304 +
93305 void __init __free_pages_bootmem(struct page *page, unsigned int order)
93306 {
93307 unsigned int nr_pages = 1 << order;
93308 @@ -765,6 +790,19 @@ void __init __free_pages_bootmem(struct page *page, unsigned int order)
93309 __ClearPageReserved(p);
93310 set_page_count(p, 0);
93311
93312 +#ifdef CONFIG_PAX_LATENT_ENTROPY
93313 + if (extra_latent_entropy && !PageHighMem(page) && page_to_pfn(page) < 0x100000) {
93314 + u64 hash = 0;
93315 + size_t index, end = PAGE_SIZE * nr_pages / sizeof hash;
93316 + const u64 *data = lowmem_page_address(page);
93317 +
93318 + for (index = 0; index < end; index++)
93319 + hash ^= hash + data[index];
93320 + latent_entropy ^= hash;
93321 + add_device_randomness((const void *)&latent_entropy, sizeof(latent_entropy));
93322 + }
93323 +#endif
93324 +
93325 page_zone(page)->managed_pages += nr_pages;
93326 set_page_refcounted(page);
93327 __free_pages(page, order);
93328 @@ -870,8 +908,10 @@ static int prep_new_page(struct page *page, int order, gfp_t gfp_flags)
93329 arch_alloc_page(page, order);
93330 kernel_map_pages(page, 1 << order, 1);
93331
93332 +#ifndef CONFIG_PAX_MEMORY_SANITIZE
93333 if (gfp_flags & __GFP_ZERO)
93334 prep_zero_page(page, order, gfp_flags);
93335 +#endif
93336
93337 if (order && (gfp_flags & __GFP_COMP))
93338 prep_compound_page(page, order);
93339 diff --git a/mm/page_io.c b/mm/page_io.c
93340 index 8c79a47..a689e0d 100644
93341 --- a/mm/page_io.c
93342 +++ b/mm/page_io.c
93343 @@ -260,7 +260,7 @@ int __swap_writepage(struct page *page, struct writeback_control *wbc,
93344 struct file *swap_file = sis->swap_file;
93345 struct address_space *mapping = swap_file->f_mapping;
93346 struct iovec iov = {
93347 - .iov_base = kmap(page),
93348 + .iov_base = (void __force_user *)kmap(page),
93349 .iov_len = PAGE_SIZE,
93350 };
93351
93352 diff --git a/mm/percpu.c b/mm/percpu.c
93353 index 0d10def..6dc822d 100644
93354 --- a/mm/percpu.c
93355 +++ b/mm/percpu.c
93356 @@ -122,7 +122,7 @@ static unsigned int pcpu_low_unit_cpu __read_mostly;
93357 static unsigned int pcpu_high_unit_cpu __read_mostly;
93358
93359 /* the address of the first chunk which starts with the kernel static area */
93360 -void *pcpu_base_addr __read_mostly;
93361 +void *pcpu_base_addr __read_only;
93362 EXPORT_SYMBOL_GPL(pcpu_base_addr);
93363
93364 static const int *pcpu_unit_map __read_mostly; /* cpu -> unit */
93365 diff --git a/mm/process_vm_access.c b/mm/process_vm_access.c
93366 index fd26d04..0cea1b0 100644
93367 --- a/mm/process_vm_access.c
93368 +++ b/mm/process_vm_access.c
93369 @@ -13,6 +13,7 @@
93370 #include <linux/uio.h>
93371 #include <linux/sched.h>
93372 #include <linux/highmem.h>
93373 +#include <linux/security.h>
93374 #include <linux/ptrace.h>
93375 #include <linux/slab.h>
93376 #include <linux/syscalls.h>
93377 @@ -258,19 +259,19 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
93378 size_t iov_l_curr_offset = 0;
93379 ssize_t iov_len;
93380
93381 + return -ENOSYS; // PaX: until properly audited
93382 +
93383 /*
93384 * Work out how many pages of struct pages we're going to need
93385 * when eventually calling get_user_pages
93386 */
93387 for (i = 0; i < riovcnt; i++) {
93388 iov_len = rvec[i].iov_len;
93389 - if (iov_len > 0) {
93390 - nr_pages_iov = ((unsigned long)rvec[i].iov_base
93391 - + iov_len)
93392 - / PAGE_SIZE - (unsigned long)rvec[i].iov_base
93393 - / PAGE_SIZE + 1;
93394 - nr_pages = max(nr_pages, nr_pages_iov);
93395 - }
93396 + if (iov_len <= 0)
93397 + continue;
93398 + nr_pages_iov = ((unsigned long)rvec[i].iov_base + iov_len) / PAGE_SIZE -
93399 + (unsigned long)rvec[i].iov_base / PAGE_SIZE + 1;
93400 + nr_pages = max(nr_pages, nr_pages_iov);
93401 }
93402
93403 if (nr_pages == 0)
93404 @@ -298,6 +299,11 @@ static ssize_t process_vm_rw_core(pid_t pid, const struct iovec *lvec,
93405 goto free_proc_pages;
93406 }
93407
93408 + if (gr_handle_ptrace(task, vm_write ? PTRACE_POKETEXT : PTRACE_ATTACH)) {
93409 + rc = -EPERM;
93410 + goto put_task_struct;
93411 + }
93412 +
93413 mm = mm_access(task, PTRACE_MODE_ATTACH);
93414 if (!mm || IS_ERR(mm)) {
93415 rc = IS_ERR(mm) ? PTR_ERR(mm) : -ESRCH;
93416 diff --git a/mm/rmap.c b/mm/rmap.c
93417 index 068522d..f539f21 100644
93418 --- a/mm/rmap.c
93419 +++ b/mm/rmap.c
93420 @@ -163,6 +163,10 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93421 struct anon_vma *anon_vma = vma->anon_vma;
93422 struct anon_vma_chain *avc;
93423
93424 +#ifdef CONFIG_PAX_SEGMEXEC
93425 + struct anon_vma_chain *avc_m = NULL;
93426 +#endif
93427 +
93428 might_sleep();
93429 if (unlikely(!anon_vma)) {
93430 struct mm_struct *mm = vma->vm_mm;
93431 @@ -172,6 +176,12 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93432 if (!avc)
93433 goto out_enomem;
93434
93435 +#ifdef CONFIG_PAX_SEGMEXEC
93436 + avc_m = anon_vma_chain_alloc(GFP_KERNEL);
93437 + if (!avc_m)
93438 + goto out_enomem_free_avc;
93439 +#endif
93440 +
93441 anon_vma = find_mergeable_anon_vma(vma);
93442 allocated = NULL;
93443 if (!anon_vma) {
93444 @@ -185,6 +195,18 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93445 /* page_table_lock to protect against threads */
93446 spin_lock(&mm->page_table_lock);
93447 if (likely(!vma->anon_vma)) {
93448 +
93449 +#ifdef CONFIG_PAX_SEGMEXEC
93450 + struct vm_area_struct *vma_m = pax_find_mirror_vma(vma);
93451 +
93452 + if (vma_m) {
93453 + BUG_ON(vma_m->anon_vma);
93454 + vma_m->anon_vma = anon_vma;
93455 + anon_vma_chain_link(vma_m, avc_m, anon_vma);
93456 + avc_m = NULL;
93457 + }
93458 +#endif
93459 +
93460 vma->anon_vma = anon_vma;
93461 anon_vma_chain_link(vma, avc, anon_vma);
93462 allocated = NULL;
93463 @@ -195,12 +217,24 @@ int anon_vma_prepare(struct vm_area_struct *vma)
93464
93465 if (unlikely(allocated))
93466 put_anon_vma(allocated);
93467 +
93468 +#ifdef CONFIG_PAX_SEGMEXEC
93469 + if (unlikely(avc_m))
93470 + anon_vma_chain_free(avc_m);
93471 +#endif
93472 +
93473 if (unlikely(avc))
93474 anon_vma_chain_free(avc);
93475 }
93476 return 0;
93477
93478 out_enomem_free_avc:
93479 +
93480 +#ifdef CONFIG_PAX_SEGMEXEC
93481 + if (avc_m)
93482 + anon_vma_chain_free(avc_m);
93483 +#endif
93484 +
93485 anon_vma_chain_free(avc);
93486 out_enomem:
93487 return -ENOMEM;
93488 @@ -236,7 +270,7 @@ static inline void unlock_anon_vma_root(struct anon_vma *root)
93489 * Attach the anon_vmas from src to dst.
93490 * Returns 0 on success, -ENOMEM on failure.
93491 */
93492 -int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
93493 +int anon_vma_clone(struct vm_area_struct *dst, const struct vm_area_struct *src)
93494 {
93495 struct anon_vma_chain *avc, *pavc;
93496 struct anon_vma *root = NULL;
93497 @@ -269,7 +303,7 @@ int anon_vma_clone(struct vm_area_struct *dst, struct vm_area_struct *src)
93498 * the corresponding VMA in the parent process is attached to.
93499 * Returns 0 on success, non-zero on failure.
93500 */
93501 -int anon_vma_fork(struct vm_area_struct *vma, struct vm_area_struct *pvma)
93502 +int anon_vma_fork(struct vm_area_struct *vma, const struct vm_area_struct *pvma)
93503 {
93504 struct anon_vma_chain *avc;
93505 struct anon_vma *anon_vma;
93506 @@ -373,8 +407,10 @@ static void anon_vma_ctor(void *data)
93507 void __init anon_vma_init(void)
93508 {
93509 anon_vma_cachep = kmem_cache_create("anon_vma", sizeof(struct anon_vma),
93510 - 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC, anon_vma_ctor);
93511 - anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain, SLAB_PANIC);
93512 + 0, SLAB_DESTROY_BY_RCU|SLAB_PANIC|SLAB_NO_SANITIZE,
93513 + anon_vma_ctor);
93514 + anon_vma_chain_cachep = KMEM_CACHE(anon_vma_chain,
93515 + SLAB_PANIC|SLAB_NO_SANITIZE);
93516 }
93517
93518 /*
93519 diff --git a/mm/shmem.c b/mm/shmem.c
93520 index 902a148..58f9d59 100644
93521 --- a/mm/shmem.c
93522 +++ b/mm/shmem.c
93523 @@ -33,7 +33,7 @@
93524 #include <linux/swap.h>
93525 #include <linux/aio.h>
93526
93527 -static struct vfsmount *shm_mnt;
93528 +struct vfsmount *shm_mnt;
93529
93530 #ifdef CONFIG_SHMEM
93531 /*
93532 @@ -77,7 +77,7 @@ static struct vfsmount *shm_mnt;
93533 #define BOGO_DIRENT_SIZE 20
93534
93535 /* Symlink up to this size is kmalloc'ed instead of using a swappable page */
93536 -#define SHORT_SYMLINK_LEN 128
93537 +#define SHORT_SYMLINK_LEN 64
93538
93539 /*
93540 * shmem_fallocate and shmem_writepage communicate via inode->i_private
93541 @@ -2232,6 +2232,11 @@ static const struct xattr_handler *shmem_xattr_handlers[] = {
93542 static int shmem_xattr_validate(const char *name)
93543 {
93544 struct { const char *prefix; size_t len; } arr[] = {
93545 +
93546 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
93547 + { XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN},
93548 +#endif
93549 +
93550 { XATTR_SECURITY_PREFIX, XATTR_SECURITY_PREFIX_LEN },
93551 { XATTR_TRUSTED_PREFIX, XATTR_TRUSTED_PREFIX_LEN }
93552 };
93553 @@ -2287,6 +2292,15 @@ static int shmem_setxattr(struct dentry *dentry, const char *name,
93554 if (err)
93555 return err;
93556
93557 +#ifdef CONFIG_PAX_XATTR_PAX_FLAGS
93558 + if (!strncmp(name, XATTR_USER_PREFIX, XATTR_USER_PREFIX_LEN)) {
93559 + if (strcmp(name, XATTR_NAME_PAX_FLAGS))
93560 + return -EOPNOTSUPP;
93561 + if (size > 8)
93562 + return -EINVAL;
93563 + }
93564 +#endif
93565 +
93566 return simple_xattr_set(&info->xattrs, name, value, size, flags);
93567 }
93568
93569 @@ -2599,8 +2613,7 @@ int shmem_fill_super(struct super_block *sb, void *data, int silent)
93570 int err = -ENOMEM;
93571
93572 /* Round up to L1_CACHE_BYTES to resist false sharing */
93573 - sbinfo = kzalloc(max((int)sizeof(struct shmem_sb_info),
93574 - L1_CACHE_BYTES), GFP_KERNEL);
93575 + sbinfo = kzalloc(max(sizeof(struct shmem_sb_info), L1_CACHE_BYTES), GFP_KERNEL);
93576 if (!sbinfo)
93577 return -ENOMEM;
93578
93579 diff --git a/mm/slab.c b/mm/slab.c
93580 index eb043bf..d82f5a8 100644
93581 --- a/mm/slab.c
93582 +++ b/mm/slab.c
93583 @@ -300,10 +300,12 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
93584 if ((x)->max_freeable < i) \
93585 (x)->max_freeable = i; \
93586 } while (0)
93587 -#define STATS_INC_ALLOCHIT(x) atomic_inc(&(x)->allochit)
93588 -#define STATS_INC_ALLOCMISS(x) atomic_inc(&(x)->allocmiss)
93589 -#define STATS_INC_FREEHIT(x) atomic_inc(&(x)->freehit)
93590 -#define STATS_INC_FREEMISS(x) atomic_inc(&(x)->freemiss)
93591 +#define STATS_INC_ALLOCHIT(x) atomic_inc_unchecked(&(x)->allochit)
93592 +#define STATS_INC_ALLOCMISS(x) atomic_inc_unchecked(&(x)->allocmiss)
93593 +#define STATS_INC_FREEHIT(x) atomic_inc_unchecked(&(x)->freehit)
93594 +#define STATS_INC_FREEMISS(x) atomic_inc_unchecked(&(x)->freemiss)
93595 +#define STATS_INC_SANITIZED(x) atomic_inc_unchecked(&(x)->sanitized)
93596 +#define STATS_INC_NOT_SANITIZED(x) atomic_inc_unchecked(&(x)->not_sanitized)
93597 #else
93598 #define STATS_INC_ACTIVE(x) do { } while (0)
93599 #define STATS_DEC_ACTIVE(x) do { } while (0)
93600 @@ -320,6 +322,8 @@ static void kmem_cache_node_init(struct kmem_cache_node *parent)
93601 #define STATS_INC_ALLOCMISS(x) do { } while (0)
93602 #define STATS_INC_FREEHIT(x) do { } while (0)
93603 #define STATS_INC_FREEMISS(x) do { } while (0)
93604 +#define STATS_INC_SANITIZED(x) do { } while (0)
93605 +#define STATS_INC_NOT_SANITIZED(x) do { } while (0)
93606 #endif
93607
93608 #if DEBUG
93609 @@ -403,7 +407,7 @@ static inline void *index_to_obj(struct kmem_cache *cache, struct page *page,
93610 * reciprocal_divide(offset, cache->reciprocal_buffer_size)
93611 */
93612 static inline unsigned int obj_to_index(const struct kmem_cache *cache,
93613 - const struct page *page, void *obj)
93614 + const struct page *page, const void *obj)
93615 {
93616 u32 offset = (obj - page->s_mem);
93617 return reciprocal_divide(offset, cache->reciprocal_buffer_size);
93618 @@ -1489,12 +1493,12 @@ void __init kmem_cache_init(void)
93619 */
93620
93621 kmalloc_caches[INDEX_AC] = create_kmalloc_cache("kmalloc-ac",
93622 - kmalloc_size(INDEX_AC), ARCH_KMALLOC_FLAGS);
93623 + kmalloc_size(INDEX_AC), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
93624
93625 if (INDEX_AC != INDEX_NODE)
93626 kmalloc_caches[INDEX_NODE] =
93627 create_kmalloc_cache("kmalloc-node",
93628 - kmalloc_size(INDEX_NODE), ARCH_KMALLOC_FLAGS);
93629 + kmalloc_size(INDEX_NODE), SLAB_USERCOPY | ARCH_KMALLOC_FLAGS);
93630
93631 slab_early_init = 0;
93632
93633 @@ -3428,6 +3432,21 @@ static inline void __cache_free(struct kmem_cache *cachep, void *objp,
93634 struct array_cache *ac = cpu_cache_get(cachep);
93635
93636 check_irq_off();
93637 +
93638 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93639 + if (pax_sanitize_slab) {
93640 + if (!(cachep->flags & (SLAB_POISON | SLAB_NO_SANITIZE))) {
93641 + memset(objp, PAX_MEMORY_SANITIZE_VALUE, cachep->object_size);
93642 +
93643 + if (cachep->ctor)
93644 + cachep->ctor(objp);
93645 +
93646 + STATS_INC_SANITIZED(cachep);
93647 + } else
93648 + STATS_INC_NOT_SANITIZED(cachep);
93649 + }
93650 +#endif
93651 +
93652 kmemleak_free_recursive(objp, cachep->flags);
93653 objp = cache_free_debugcheck(cachep, objp, caller);
93654
93655 @@ -3656,6 +3675,7 @@ void kfree(const void *objp)
93656
93657 if (unlikely(ZERO_OR_NULL_PTR(objp)))
93658 return;
93659 + VM_BUG_ON(!virt_addr_valid(objp));
93660 local_irq_save(flags);
93661 kfree_debugcheck(objp);
93662 c = virt_to_cache(objp);
93663 @@ -4097,14 +4117,22 @@ void slabinfo_show_stats(struct seq_file *m, struct kmem_cache *cachep)
93664 }
93665 /* cpu stats */
93666 {
93667 - unsigned long allochit = atomic_read(&cachep->allochit);
93668 - unsigned long allocmiss = atomic_read(&cachep->allocmiss);
93669 - unsigned long freehit = atomic_read(&cachep->freehit);
93670 - unsigned long freemiss = atomic_read(&cachep->freemiss);
93671 + unsigned long allochit = atomic_read_unchecked(&cachep->allochit);
93672 + unsigned long allocmiss = atomic_read_unchecked(&cachep->allocmiss);
93673 + unsigned long freehit = atomic_read_unchecked(&cachep->freehit);
93674 + unsigned long freemiss = atomic_read_unchecked(&cachep->freemiss);
93675
93676 seq_printf(m, " : cpustat %6lu %6lu %6lu %6lu",
93677 allochit, allocmiss, freehit, freemiss);
93678 }
93679 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93680 + {
93681 + unsigned long sanitized = atomic_read_unchecked(&cachep->sanitized);
93682 + unsigned long not_sanitized = atomic_read_unchecked(&cachep->not_sanitized);
93683 +
93684 + seq_printf(m, " : pax %6lu %6lu", sanitized, not_sanitized);
93685 + }
93686 +#endif
93687 #endif
93688 }
93689
93690 @@ -4334,13 +4362,69 @@ static const struct file_operations proc_slabstats_operations = {
93691 static int __init slab_proc_init(void)
93692 {
93693 #ifdef CONFIG_DEBUG_SLAB_LEAK
93694 - proc_create("slab_allocators", 0, NULL, &proc_slabstats_operations);
93695 + proc_create("slab_allocators", S_IRUSR, NULL, &proc_slabstats_operations);
93696 #endif
93697 return 0;
93698 }
93699 module_init(slab_proc_init);
93700 #endif
93701
93702 +bool is_usercopy_object(const void *ptr)
93703 +{
93704 + struct page *page;
93705 + struct kmem_cache *cachep;
93706 +
93707 + if (ZERO_OR_NULL_PTR(ptr))
93708 + return false;
93709 +
93710 + if (!slab_is_available())
93711 + return false;
93712 +
93713 + if (!virt_addr_valid(ptr))
93714 + return false;
93715 +
93716 + page = virt_to_head_page(ptr);
93717 +
93718 + if (!PageSlab(page))
93719 + return false;
93720 +
93721 + cachep = page->slab_cache;
93722 + return cachep->flags & SLAB_USERCOPY;
93723 +}
93724 +
93725 +#ifdef CONFIG_PAX_USERCOPY
93726 +const char *check_heap_object(const void *ptr, unsigned long n)
93727 +{
93728 + struct page *page;
93729 + struct kmem_cache *cachep;
93730 + unsigned int objnr;
93731 + unsigned long offset;
93732 +
93733 + if (ZERO_OR_NULL_PTR(ptr))
93734 + return "<null>";
93735 +
93736 + if (!virt_addr_valid(ptr))
93737 + return NULL;
93738 +
93739 + page = virt_to_head_page(ptr);
93740 +
93741 + if (!PageSlab(page))
93742 + return NULL;
93743 +
93744 + cachep = page->slab_cache;
93745 + if (!(cachep->flags & SLAB_USERCOPY))
93746 + return cachep->name;
93747 +
93748 + objnr = obj_to_index(cachep, page, ptr);
93749 + BUG_ON(objnr >= cachep->num);
93750 + offset = ptr - index_to_obj(cachep, page, objnr) - obj_offset(cachep);
93751 + if (offset <= cachep->object_size && n <= cachep->object_size - offset)
93752 + return NULL;
93753 +
93754 + return cachep->name;
93755 +}
93756 +#endif
93757 +
93758 /**
93759 * ksize - get the actual amount of memory allocated for a given object
93760 * @objp: Pointer to the object
93761 diff --git a/mm/slab.h b/mm/slab.h
93762 index 0859c42..2f7b737 100644
93763 --- a/mm/slab.h
93764 +++ b/mm/slab.h
93765 @@ -32,6 +32,15 @@ extern struct list_head slab_caches;
93766 /* The slab cache that manages slab cache information */
93767 extern struct kmem_cache *kmem_cache;
93768
93769 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93770 +#ifdef CONFIG_X86_64
93771 +#define PAX_MEMORY_SANITIZE_VALUE '\xfe'
93772 +#else
93773 +#define PAX_MEMORY_SANITIZE_VALUE '\xff'
93774 +#endif
93775 +extern bool pax_sanitize_slab;
93776 +#endif
93777 +
93778 unsigned long calculate_alignment(unsigned long flags,
93779 unsigned long align, unsigned long size);
93780
93781 @@ -67,7 +76,8 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
93782
93783 /* Legal flag mask for kmem_cache_create(), for various configurations */
93784 #define SLAB_CORE_FLAGS (SLAB_HWCACHE_ALIGN | SLAB_CACHE_DMA | SLAB_PANIC | \
93785 - SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS )
93786 + SLAB_DESTROY_BY_RCU | SLAB_DEBUG_OBJECTS | \
93787 + SLAB_USERCOPY | SLAB_NO_SANITIZE)
93788
93789 #if defined(CONFIG_DEBUG_SLAB)
93790 #define SLAB_DEBUG_FLAGS (SLAB_RED_ZONE | SLAB_POISON | SLAB_STORE_USER)
93791 @@ -233,6 +243,9 @@ static inline struct kmem_cache *cache_from_obj(struct kmem_cache *s, void *x)
93792 return s;
93793
93794 page = virt_to_head_page(x);
93795 +
93796 + BUG_ON(!PageSlab(page));
93797 +
93798 cachep = page->slab_cache;
93799 if (slab_equal_or_root(cachep, s))
93800 return cachep;
93801 diff --git a/mm/slab_common.c b/mm/slab_common.c
93802 index 0b7bb39..334c328 100644
93803 --- a/mm/slab_common.c
93804 +++ b/mm/slab_common.c
93805 @@ -23,11 +23,22 @@
93806
93807 #include "slab.h"
93808
93809 -enum slab_state slab_state;
93810 +enum slab_state slab_state __read_only;
93811 LIST_HEAD(slab_caches);
93812 DEFINE_MUTEX(slab_mutex);
93813 struct kmem_cache *kmem_cache;
93814
93815 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93816 +bool pax_sanitize_slab __read_only = true;
93817 +static int __init pax_sanitize_slab_setup(char *str)
93818 +{
93819 + pax_sanitize_slab = !!simple_strtol(str, NULL, 0);
93820 + printk("%sabled PaX slab sanitization\n", pax_sanitize_slab ? "En" : "Dis");
93821 + return 1;
93822 +}
93823 +__setup("pax_sanitize_slab=", pax_sanitize_slab_setup);
93824 +#endif
93825 +
93826 #ifdef CONFIG_DEBUG_VM
93827 static int kmem_cache_sanity_check(struct mem_cgroup *memcg, const char *name,
93828 size_t size)
93829 @@ -212,7 +223,7 @@ kmem_cache_create_memcg(struct mem_cgroup *memcg, const char *name, size_t size,
93830
93831 err = __kmem_cache_create(s, flags);
93832 if (!err) {
93833 - s->refcount = 1;
93834 + atomic_set(&s->refcount, 1);
93835 list_add(&s->list, &slab_caches);
93836 memcg_cache_list_add(memcg, s);
93837 } else {
93838 @@ -258,8 +269,7 @@ void kmem_cache_destroy(struct kmem_cache *s)
93839
93840 get_online_cpus();
93841 mutex_lock(&slab_mutex);
93842 - s->refcount--;
93843 - if (!s->refcount) {
93844 + if (atomic_dec_and_test(&s->refcount)) {
93845 list_del(&s->list);
93846
93847 if (!__kmem_cache_shutdown(s)) {
93848 @@ -305,7 +315,7 @@ void __init create_boot_cache(struct kmem_cache *s, const char *name, size_t siz
93849 panic("Creation of kmalloc slab %s size=%zu failed. Reason %d\n",
93850 name, size, err);
93851
93852 - s->refcount = -1; /* Exempt from merging for now */
93853 + atomic_set(&s->refcount, -1); /* Exempt from merging for now */
93854 }
93855
93856 struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
93857 @@ -318,7 +328,7 @@ struct kmem_cache *__init create_kmalloc_cache(const char *name, size_t size,
93858
93859 create_boot_cache(s, name, size, flags);
93860 list_add(&s->list, &slab_caches);
93861 - s->refcount = 1;
93862 + atomic_set(&s->refcount, 1);
93863 return s;
93864 }
93865
93866 @@ -330,6 +340,11 @@ struct kmem_cache *kmalloc_dma_caches[KMALLOC_SHIFT_HIGH + 1];
93867 EXPORT_SYMBOL(kmalloc_dma_caches);
93868 #endif
93869
93870 +#ifdef CONFIG_PAX_USERCOPY_SLABS
93871 +struct kmem_cache *kmalloc_usercopy_caches[KMALLOC_SHIFT_HIGH + 1];
93872 +EXPORT_SYMBOL(kmalloc_usercopy_caches);
93873 +#endif
93874 +
93875 /*
93876 * Conversion table for small slabs sizes / 8 to the index in the
93877 * kmalloc array. This is necessary for slabs < 192 since we have non power
93878 @@ -394,6 +409,13 @@ struct kmem_cache *kmalloc_slab(size_t size, gfp_t flags)
93879 return kmalloc_dma_caches[index];
93880
93881 #endif
93882 +
93883 +#ifdef CONFIG_PAX_USERCOPY_SLABS
93884 + if (unlikely((flags & GFP_USERCOPY)))
93885 + return kmalloc_usercopy_caches[index];
93886 +
93887 +#endif
93888 +
93889 return kmalloc_caches[index];
93890 }
93891
93892 @@ -450,7 +472,7 @@ void __init create_kmalloc_caches(unsigned long flags)
93893 for (i = KMALLOC_SHIFT_LOW; i <= KMALLOC_SHIFT_HIGH; i++) {
93894 if (!kmalloc_caches[i]) {
93895 kmalloc_caches[i] = create_kmalloc_cache(NULL,
93896 - 1 << i, flags);
93897 + 1 << i, SLAB_USERCOPY | flags);
93898 }
93899
93900 /*
93901 @@ -459,10 +481,10 @@ void __init create_kmalloc_caches(unsigned long flags)
93902 * earlier power of two caches
93903 */
93904 if (KMALLOC_MIN_SIZE <= 32 && !kmalloc_caches[1] && i == 6)
93905 - kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, flags);
93906 + kmalloc_caches[1] = create_kmalloc_cache(NULL, 96, SLAB_USERCOPY | flags);
93907
93908 if (KMALLOC_MIN_SIZE <= 64 && !kmalloc_caches[2] && i == 7)
93909 - kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, flags);
93910 + kmalloc_caches[2] = create_kmalloc_cache(NULL, 192, SLAB_USERCOPY | flags);
93911 }
93912
93913 /* Kmalloc array is now usable */
93914 @@ -495,6 +517,23 @@ void __init create_kmalloc_caches(unsigned long flags)
93915 }
93916 }
93917 #endif
93918 +
93919 +#ifdef CONFIG_PAX_USERCOPY_SLABS
93920 + for (i = 0; i <= KMALLOC_SHIFT_HIGH; i++) {
93921 + struct kmem_cache *s = kmalloc_caches[i];
93922 +
93923 + if (s) {
93924 + int size = kmalloc_size(i);
93925 + char *n = kasprintf(GFP_NOWAIT,
93926 + "usercopy-kmalloc-%d", size);
93927 +
93928 + BUG_ON(!n);
93929 + kmalloc_usercopy_caches[i] = create_kmalloc_cache(n,
93930 + size, SLAB_USERCOPY | flags);
93931 + }
93932 + }
93933 +#endif
93934 +
93935 }
93936 #endif /* !CONFIG_SLOB */
93937
93938 @@ -535,6 +574,9 @@ void print_slabinfo_header(struct seq_file *m)
93939 seq_puts(m, " : globalstat <listallocs> <maxobjs> <grown> <reaped> "
93940 "<error> <maxfreeable> <nodeallocs> <remotefrees> <alienoverflow>");
93941 seq_puts(m, " : cpustat <allochit> <allocmiss> <freehit> <freemiss>");
93942 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
93943 + seq_puts(m, " : pax <sanitized> <not_sanitized>");
93944 +#endif
93945 #endif
93946 seq_putc(m, '\n');
93947 }
93948 diff --git a/mm/slob.c b/mm/slob.c
93949 index 4bf8809..98a6914 100644
93950 --- a/mm/slob.c
93951 +++ b/mm/slob.c
93952 @@ -157,7 +157,7 @@ static void set_slob(slob_t *s, slobidx_t size, slob_t *next)
93953 /*
93954 * Return the size of a slob block.
93955 */
93956 -static slobidx_t slob_units(slob_t *s)
93957 +static slobidx_t slob_units(const slob_t *s)
93958 {
93959 if (s->units > 0)
93960 return s->units;
93961 @@ -167,7 +167,7 @@ static slobidx_t slob_units(slob_t *s)
93962 /*
93963 * Return the next free slob block pointer after this one.
93964 */
93965 -static slob_t *slob_next(slob_t *s)
93966 +static slob_t *slob_next(const slob_t *s)
93967 {
93968 slob_t *base = (slob_t *)((unsigned long)s & PAGE_MASK);
93969 slobidx_t next;
93970 @@ -182,14 +182,14 @@ static slob_t *slob_next(slob_t *s)
93971 /*
93972 * Returns true if s is the last free block in its page.
93973 */
93974 -static int slob_last(slob_t *s)
93975 +static int slob_last(const slob_t *s)
93976 {
93977 return !((unsigned long)slob_next(s) & ~PAGE_MASK);
93978 }
93979
93980 -static void *slob_new_pages(gfp_t gfp, int order, int node)
93981 +static struct page *slob_new_pages(gfp_t gfp, unsigned int order, int node)
93982 {
93983 - void *page;
93984 + struct page *page;
93985
93986 #ifdef CONFIG_NUMA
93987 if (node != NUMA_NO_NODE)
93988 @@ -201,14 +201,18 @@ static void *slob_new_pages(gfp_t gfp, int order, int node)
93989 if (!page)
93990 return NULL;
93991
93992 - return page_address(page);
93993 + __SetPageSlab(page);
93994 + return page;
93995 }
93996
93997 -static void slob_free_pages(void *b, int order)
93998 +static void slob_free_pages(struct page *sp, int order)
93999 {
94000 if (current->reclaim_state)
94001 current->reclaim_state->reclaimed_slab += 1 << order;
94002 - free_pages((unsigned long)b, order);
94003 + __ClearPageSlab(sp);
94004 + page_mapcount_reset(sp);
94005 + sp->private = 0;
94006 + __free_pages(sp, order);
94007 }
94008
94009 /*
94010 @@ -313,15 +317,15 @@ static void *slob_alloc(size_t size, gfp_t gfp, int align, int node)
94011
94012 /* Not enough space: must allocate a new page */
94013 if (!b) {
94014 - b = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
94015 - if (!b)
94016 + sp = slob_new_pages(gfp & ~__GFP_ZERO, 0, node);
94017 + if (!sp)
94018 return NULL;
94019 - sp = virt_to_page(b);
94020 - __SetPageSlab(sp);
94021 + b = page_address(sp);
94022
94023 spin_lock_irqsave(&slob_lock, flags);
94024 sp->units = SLOB_UNITS(PAGE_SIZE);
94025 sp->freelist = b;
94026 + sp->private = 0;
94027 INIT_LIST_HEAD(&sp->list);
94028 set_slob(b, SLOB_UNITS(PAGE_SIZE), b + SLOB_UNITS(PAGE_SIZE));
94029 set_slob_page_free(sp, slob_list);
94030 @@ -359,12 +363,15 @@ static void slob_free(void *block, int size)
94031 if (slob_page_free(sp))
94032 clear_slob_page_free(sp);
94033 spin_unlock_irqrestore(&slob_lock, flags);
94034 - __ClearPageSlab(sp);
94035 - page_mapcount_reset(sp);
94036 - slob_free_pages(b, 0);
94037 + slob_free_pages(sp, 0);
94038 return;
94039 }
94040
94041 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94042 + if (pax_sanitize_slab)
94043 + memset(block, PAX_MEMORY_SANITIZE_VALUE, size);
94044 +#endif
94045 +
94046 if (!slob_page_free(sp)) {
94047 /* This slob page is about to become partially free. Easy! */
94048 sp->units = units;
94049 @@ -424,11 +431,10 @@ out:
94050 */
94051
94052 static __always_inline void *
94053 -__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
94054 +__do_kmalloc_node_align(size_t size, gfp_t gfp, int node, unsigned long caller, int align)
94055 {
94056 - unsigned int *m;
94057 - int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
94058 - void *ret;
94059 + slob_t *m;
94060 + void *ret = NULL;
94061
94062 gfp &= gfp_allowed_mask;
94063
94064 @@ -442,23 +448,41 @@ __do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
94065
94066 if (!m)
94067 return NULL;
94068 - *m = size;
94069 + BUILD_BUG_ON(ARCH_KMALLOC_MINALIGN < 2 * SLOB_UNIT);
94070 + BUILD_BUG_ON(ARCH_SLAB_MINALIGN < 2 * SLOB_UNIT);
94071 + m[0].units = size;
94072 + m[1].units = align;
94073 ret = (void *)m + align;
94074
94075 trace_kmalloc_node(caller, ret,
94076 size, size + align, gfp, node);
94077 } else {
94078 unsigned int order = get_order(size);
94079 + struct page *page;
94080
94081 if (likely(order))
94082 gfp |= __GFP_COMP;
94083 - ret = slob_new_pages(gfp, order, node);
94084 + page = slob_new_pages(gfp, order, node);
94085 + if (page) {
94086 + ret = page_address(page);
94087 + page->private = size;
94088 + }
94089
94090 trace_kmalloc_node(caller, ret,
94091 size, PAGE_SIZE << order, gfp, node);
94092 }
94093
94094 - kmemleak_alloc(ret, size, 1, gfp);
94095 + return ret;
94096 +}
94097 +
94098 +static __always_inline void *
94099 +__do_kmalloc_node(size_t size, gfp_t gfp, int node, unsigned long caller)
94100 +{
94101 + int align = max(ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
94102 + void *ret = __do_kmalloc_node_align(size, gfp, node, caller, align);
94103 +
94104 + if (!ZERO_OR_NULL_PTR(ret))
94105 + kmemleak_alloc(ret, size, 1, gfp);
94106 return ret;
94107 }
94108
94109 @@ -493,34 +517,112 @@ void kfree(const void *block)
94110 return;
94111 kmemleak_free(block);
94112
94113 + VM_BUG_ON(!virt_addr_valid(block));
94114 sp = virt_to_page(block);
94115 - if (PageSlab(sp)) {
94116 + VM_BUG_ON(!PageSlab(sp));
94117 + if (!sp->private) {
94118 int align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
94119 - unsigned int *m = (unsigned int *)(block - align);
94120 - slob_free(m, *m + align);
94121 - } else
94122 + slob_t *m = (slob_t *)(block - align);
94123 + slob_free(m, m[0].units + align);
94124 + } else {
94125 + __ClearPageSlab(sp);
94126 + page_mapcount_reset(sp);
94127 + sp->private = 0;
94128 __free_pages(sp, compound_order(sp));
94129 + }
94130 }
94131 EXPORT_SYMBOL(kfree);
94132
94133 +bool is_usercopy_object(const void *ptr)
94134 +{
94135 + if (!slab_is_available())
94136 + return false;
94137 +
94138 + // PAX: TODO
94139 +
94140 + return false;
94141 +}
94142 +
94143 +#ifdef CONFIG_PAX_USERCOPY
94144 +const char *check_heap_object(const void *ptr, unsigned long n)
94145 +{
94146 + struct page *page;
94147 + const slob_t *free;
94148 + const void *base;
94149 + unsigned long flags;
94150 +
94151 + if (ZERO_OR_NULL_PTR(ptr))
94152 + return "<null>";
94153 +
94154 + if (!virt_addr_valid(ptr))
94155 + return NULL;
94156 +
94157 + page = virt_to_head_page(ptr);
94158 + if (!PageSlab(page))
94159 + return NULL;
94160 +
94161 + if (page->private) {
94162 + base = page;
94163 + if (base <= ptr && n <= page->private - (ptr - base))
94164 + return NULL;
94165 + return "<slob>";
94166 + }
94167 +
94168 + /* some tricky double walking to find the chunk */
94169 + spin_lock_irqsave(&slob_lock, flags);
94170 + base = (void *)((unsigned long)ptr & PAGE_MASK);
94171 + free = page->freelist;
94172 +
94173 + while (!slob_last(free) && (void *)free <= ptr) {
94174 + base = free + slob_units(free);
94175 + free = slob_next(free);
94176 + }
94177 +
94178 + while (base < (void *)free) {
94179 + slobidx_t m = ((slob_t *)base)[0].units, align = ((slob_t *)base)[1].units;
94180 + int size = SLOB_UNIT * SLOB_UNITS(m + align);
94181 + int offset;
94182 +
94183 + if (ptr < base + align)
94184 + break;
94185 +
94186 + offset = ptr - base - align;
94187 + if (offset >= m) {
94188 + base += size;
94189 + continue;
94190 + }
94191 +
94192 + if (n > m - offset)
94193 + break;
94194 +
94195 + spin_unlock_irqrestore(&slob_lock, flags);
94196 + return NULL;
94197 + }
94198 +
94199 + spin_unlock_irqrestore(&slob_lock, flags);
94200 + return "<slob>";
94201 +}
94202 +#endif
94203 +
94204 /* can't use ksize for kmem_cache_alloc memory, only kmalloc */
94205 size_t ksize(const void *block)
94206 {
94207 struct page *sp;
94208 int align;
94209 - unsigned int *m;
94210 + slob_t *m;
94211
94212 BUG_ON(!block);
94213 if (unlikely(block == ZERO_SIZE_PTR))
94214 return 0;
94215
94216 sp = virt_to_page(block);
94217 - if (unlikely(!PageSlab(sp)))
94218 - return PAGE_SIZE << compound_order(sp);
94219 + VM_BUG_ON(!PageSlab(sp));
94220 + if (sp->private)
94221 + return sp->private;
94222
94223 align = max_t(size_t, ARCH_KMALLOC_MINALIGN, ARCH_SLAB_MINALIGN);
94224 - m = (unsigned int *)(block - align);
94225 - return SLOB_UNITS(*m) * SLOB_UNIT;
94226 + m = (slob_t *)(block - align);
94227 + return SLOB_UNITS(m[0].units) * SLOB_UNIT;
94228 }
94229 EXPORT_SYMBOL(ksize);
94230
94231 @@ -536,23 +638,33 @@ int __kmem_cache_create(struct kmem_cache *c, unsigned long flags)
94232
94233 void *slob_alloc_node(struct kmem_cache *c, gfp_t flags, int node)
94234 {
94235 - void *b;
94236 + void *b = NULL;
94237
94238 flags &= gfp_allowed_mask;
94239
94240 lockdep_trace_alloc(flags);
94241
94242 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94243 + b = __do_kmalloc_node_align(c->size, flags, node, _RET_IP_, c->align);
94244 +#else
94245 if (c->size < PAGE_SIZE) {
94246 b = slob_alloc(c->size, flags, c->align, node);
94247 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
94248 SLOB_UNITS(c->size) * SLOB_UNIT,
94249 flags, node);
94250 } else {
94251 - b = slob_new_pages(flags, get_order(c->size), node);
94252 + struct page *sp;
94253 +
94254 + sp = slob_new_pages(flags, get_order(c->size), node);
94255 + if (sp) {
94256 + b = page_address(sp);
94257 + sp->private = c->size;
94258 + }
94259 trace_kmem_cache_alloc_node(_RET_IP_, b, c->object_size,
94260 PAGE_SIZE << get_order(c->size),
94261 flags, node);
94262 }
94263 +#endif
94264
94265 if (b && c->ctor)
94266 c->ctor(b);
94267 @@ -584,10 +696,14 @@ EXPORT_SYMBOL(kmem_cache_alloc_node);
94268
94269 static void __kmem_cache_free(void *b, int size)
94270 {
94271 - if (size < PAGE_SIZE)
94272 + struct page *sp;
94273 +
94274 + sp = virt_to_page(b);
94275 + BUG_ON(!PageSlab(sp));
94276 + if (!sp->private)
94277 slob_free(b, size);
94278 else
94279 - slob_free_pages(b, get_order(size));
94280 + slob_free_pages(sp, get_order(size));
94281 }
94282
94283 static void kmem_rcu_free(struct rcu_head *head)
94284 @@ -600,17 +716,31 @@ static void kmem_rcu_free(struct rcu_head *head)
94285
94286 void kmem_cache_free(struct kmem_cache *c, void *b)
94287 {
94288 + int size = c->size;
94289 +
94290 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94291 + if (size + c->align < PAGE_SIZE) {
94292 + size += c->align;
94293 + b -= c->align;
94294 + }
94295 +#endif
94296 +
94297 kmemleak_free_recursive(b, c->flags);
94298 if (unlikely(c->flags & SLAB_DESTROY_BY_RCU)) {
94299 struct slob_rcu *slob_rcu;
94300 - slob_rcu = b + (c->size - sizeof(struct slob_rcu));
94301 - slob_rcu->size = c->size;
94302 + slob_rcu = b + (size - sizeof(struct slob_rcu));
94303 + slob_rcu->size = size;
94304 call_rcu(&slob_rcu->head, kmem_rcu_free);
94305 } else {
94306 - __kmem_cache_free(b, c->size);
94307 + __kmem_cache_free(b, size);
94308 }
94309
94310 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94311 + trace_kfree(_RET_IP_, b);
94312 +#else
94313 trace_kmem_cache_free(_RET_IP_, b);
94314 +#endif
94315 +
94316 }
94317 EXPORT_SYMBOL(kmem_cache_free);
94318
94319 diff --git a/mm/slub.c b/mm/slub.c
94320 index 89490d9..c7b226a 100644
94321 --- a/mm/slub.c
94322 +++ b/mm/slub.c
94323 @@ -207,7 +207,7 @@ struct track {
94324
94325 enum track_item { TRACK_ALLOC, TRACK_FREE };
94326
94327 -#ifdef CONFIG_SYSFS
94328 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94329 static int sysfs_slab_add(struct kmem_cache *);
94330 static int sysfs_slab_alias(struct kmem_cache *, const char *);
94331 static void sysfs_slab_remove(struct kmem_cache *);
94332 @@ -530,7 +530,7 @@ static void print_track(const char *s, struct track *t)
94333 if (!t->addr)
94334 return;
94335
94336 - printk(KERN_ERR "INFO: %s in %pS age=%lu cpu=%u pid=%d\n",
94337 + printk(KERN_ERR "INFO: %s in %pA age=%lu cpu=%u pid=%d\n",
94338 s, (void *)t->addr, jiffies - t->when, t->cpu, t->pid);
94339 #ifdef CONFIG_STACKTRACE
94340 {
94341 @@ -2643,6 +2643,14 @@ static __always_inline void slab_free(struct kmem_cache *s,
94342
94343 slab_free_hook(s, x);
94344
94345 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94346 + if (pax_sanitize_slab && !(s->flags & SLAB_NO_SANITIZE)) {
94347 + memset(x, PAX_MEMORY_SANITIZE_VALUE, s->object_size);
94348 + if (s->ctor)
94349 + s->ctor(x);
94350 + }
94351 +#endif
94352 +
94353 redo:
94354 /*
94355 * Determine the currently cpus per cpu slab.
94356 @@ -2710,7 +2718,7 @@ static int slub_min_objects;
94357 * Merge control. If this is set then no merging of slab caches will occur.
94358 * (Could be removed. This was introduced to pacify the merge skeptics.)
94359 */
94360 -static int slub_nomerge;
94361 +static int slub_nomerge = 1;
94362
94363 /*
94364 * Calculate the order of allocation given an slab object size.
94365 @@ -2987,6 +2995,9 @@ static int calculate_sizes(struct kmem_cache *s, int forced_order)
94366 s->inuse = size;
94367
94368 if (((flags & (SLAB_DESTROY_BY_RCU | SLAB_POISON)) ||
94369 +#ifdef CONFIG_PAX_MEMORY_SANITIZE
94370 + (pax_sanitize_slab && !(flags & SLAB_NO_SANITIZE)) ||
94371 +#endif
94372 s->ctor)) {
94373 /*
94374 * Relocate free pointer after the object if it is not
94375 @@ -3332,6 +3343,59 @@ void *__kmalloc_node(size_t size, gfp_t flags, int node)
94376 EXPORT_SYMBOL(__kmalloc_node);
94377 #endif
94378
94379 +bool is_usercopy_object(const void *ptr)
94380 +{
94381 + struct page *page;
94382 + struct kmem_cache *s;
94383 +
94384 + if (ZERO_OR_NULL_PTR(ptr))
94385 + return false;
94386 +
94387 + if (!slab_is_available())
94388 + return false;
94389 +
94390 + if (!virt_addr_valid(ptr))
94391 + return false;
94392 +
94393 + page = virt_to_head_page(ptr);
94394 +
94395 + if (!PageSlab(page))
94396 + return false;
94397 +
94398 + s = page->slab_cache;
94399 + return s->flags & SLAB_USERCOPY;
94400 +}
94401 +
94402 +#ifdef CONFIG_PAX_USERCOPY
94403 +const char *check_heap_object(const void *ptr, unsigned long n)
94404 +{
94405 + struct page *page;
94406 + struct kmem_cache *s;
94407 + unsigned long offset;
94408 +
94409 + if (ZERO_OR_NULL_PTR(ptr))
94410 + return "<null>";
94411 +
94412 + if (!virt_addr_valid(ptr))
94413 + return NULL;
94414 +
94415 + page = virt_to_head_page(ptr);
94416 +
94417 + if (!PageSlab(page))
94418 + return NULL;
94419 +
94420 + s = page->slab_cache;
94421 + if (!(s->flags & SLAB_USERCOPY))
94422 + return s->name;
94423 +
94424 + offset = (ptr - page_address(page)) % s->size;
94425 + if (offset <= s->object_size && n <= s->object_size - offset)
94426 + return NULL;
94427 +
94428 + return s->name;
94429 +}
94430 +#endif
94431 +
94432 size_t ksize(const void *object)
94433 {
94434 struct page *page;
94435 @@ -3360,6 +3424,7 @@ void kfree(const void *x)
94436 if (unlikely(ZERO_OR_NULL_PTR(x)))
94437 return;
94438
94439 + VM_BUG_ON(!virt_addr_valid(x));
94440 page = virt_to_head_page(x);
94441 if (unlikely(!PageSlab(page))) {
94442 BUG_ON(!PageCompound(page));
94443 @@ -3665,7 +3730,7 @@ static int slab_unmergeable(struct kmem_cache *s)
94444 /*
94445 * We may have set a slab to be unmergeable during bootstrap.
94446 */
94447 - if (s->refcount < 0)
94448 + if (atomic_read(&s->refcount) < 0)
94449 return 1;
94450
94451 return 0;
94452 @@ -3723,7 +3788,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
94453
94454 s = find_mergeable(memcg, size, align, flags, name, ctor);
94455 if (s) {
94456 - s->refcount++;
94457 + atomic_inc(&s->refcount);
94458 /*
94459 * Adjust the object sizes so that we clear
94460 * the complete object on kzalloc.
94461 @@ -3732,7 +3797,7 @@ __kmem_cache_alias(struct mem_cgroup *memcg, const char *name, size_t size,
94462 s->inuse = max_t(int, s->inuse, ALIGN(size, sizeof(void *)));
94463
94464 if (sysfs_slab_alias(s, name)) {
94465 - s->refcount--;
94466 + atomic_dec(&s->refcount);
94467 s = NULL;
94468 }
94469 }
94470 @@ -3852,7 +3917,7 @@ void *__kmalloc_node_track_caller(size_t size, gfp_t gfpflags,
94471 }
94472 #endif
94473
94474 -#ifdef CONFIG_SYSFS
94475 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94476 static int count_inuse(struct page *page)
94477 {
94478 return page->inuse;
94479 @@ -4241,12 +4306,12 @@ static void resiliency_test(void)
94480 validate_slab_cache(kmalloc_caches[9]);
94481 }
94482 #else
94483 -#ifdef CONFIG_SYSFS
94484 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94485 static void resiliency_test(void) {};
94486 #endif
94487 #endif
94488
94489 -#ifdef CONFIG_SYSFS
94490 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94491 enum slab_stat_type {
94492 SL_ALL, /* All slabs */
94493 SL_PARTIAL, /* Only partially allocated slabs */
94494 @@ -4492,7 +4557,7 @@ SLAB_ATTR_RO(ctor);
94495
94496 static ssize_t aliases_show(struct kmem_cache *s, char *buf)
94497 {
94498 - return sprintf(buf, "%d\n", s->refcount - 1);
94499 + return sprintf(buf, "%d\n", atomic_read(&s->refcount) - 1);
94500 }
94501 SLAB_ATTR_RO(aliases);
94502
94503 @@ -4580,6 +4645,14 @@ static ssize_t cache_dma_show(struct kmem_cache *s, char *buf)
94504 SLAB_ATTR_RO(cache_dma);
94505 #endif
94506
94507 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94508 +static ssize_t usercopy_show(struct kmem_cache *s, char *buf)
94509 +{
94510 + return sprintf(buf, "%d\n", !!(s->flags & SLAB_USERCOPY));
94511 +}
94512 +SLAB_ATTR_RO(usercopy);
94513 +#endif
94514 +
94515 static ssize_t destroy_by_rcu_show(struct kmem_cache *s, char *buf)
94516 {
94517 return sprintf(buf, "%d\n", !!(s->flags & SLAB_DESTROY_BY_RCU));
94518 @@ -4914,6 +4987,9 @@ static struct attribute *slab_attrs[] = {
94519 #ifdef CONFIG_ZONE_DMA
94520 &cache_dma_attr.attr,
94521 #endif
94522 +#ifdef CONFIG_PAX_USERCOPY_SLABS
94523 + &usercopy_attr.attr,
94524 +#endif
94525 #ifdef CONFIG_NUMA
94526 &remote_node_defrag_ratio_attr.attr,
94527 #endif
94528 @@ -5146,6 +5222,7 @@ static char *create_unique_id(struct kmem_cache *s)
94529 return name;
94530 }
94531
94532 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94533 static int sysfs_slab_add(struct kmem_cache *s)
94534 {
94535 int err;
94536 @@ -5169,7 +5246,7 @@ static int sysfs_slab_add(struct kmem_cache *s)
94537 }
94538
94539 s->kobj.kset = slab_kset;
94540 - err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, name);
94541 + err = kobject_init_and_add(&s->kobj, &slab_ktype, NULL, "%s", name);
94542 if (err) {
94543 kobject_put(&s->kobj);
94544 return err;
94545 @@ -5203,6 +5280,7 @@ static void sysfs_slab_remove(struct kmem_cache *s)
94546 kobject_del(&s->kobj);
94547 kobject_put(&s->kobj);
94548 }
94549 +#endif
94550
94551 /*
94552 * Need to buffer aliases during bootup until sysfs becomes
94553 @@ -5216,6 +5294,7 @@ struct saved_alias {
94554
94555 static struct saved_alias *alias_list;
94556
94557 +#if defined(CONFIG_SYSFS) && !defined(CONFIG_GRKERNSEC_PROC_ADD)
94558 static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
94559 {
94560 struct saved_alias *al;
94561 @@ -5238,6 +5317,7 @@ static int sysfs_slab_alias(struct kmem_cache *s, const char *name)
94562 alias_list = al;
94563 return 0;
94564 }
94565 +#endif
94566
94567 static int __init slab_sysfs_init(void)
94568 {
94569 diff --git a/mm/sparse-vmemmap.c b/mm/sparse-vmemmap.c
94570 index 27eeab3..7c3f7f2 100644
94571 --- a/mm/sparse-vmemmap.c
94572 +++ b/mm/sparse-vmemmap.c
94573 @@ -130,7 +130,7 @@ pud_t * __meminit vmemmap_pud_populate(pgd_t *pgd, unsigned long addr, int node)
94574 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
94575 if (!p)
94576 return NULL;
94577 - pud_populate(&init_mm, pud, p);
94578 + pud_populate_kernel(&init_mm, pud, p);
94579 }
94580 return pud;
94581 }
94582 @@ -142,7 +142,7 @@ pgd_t * __meminit vmemmap_pgd_populate(unsigned long addr, int node)
94583 void *p = vmemmap_alloc_block(PAGE_SIZE, node);
94584 if (!p)
94585 return NULL;
94586 - pgd_populate(&init_mm, pgd, p);
94587 + pgd_populate_kernel(&init_mm, pgd, p);
94588 }
94589 return pgd;
94590 }
94591 diff --git a/mm/sparse.c b/mm/sparse.c
94592 index 8cc7be0..d0f7d7a 100644
94593 --- a/mm/sparse.c
94594 +++ b/mm/sparse.c
94595 @@ -745,7 +745,7 @@ static void clear_hwpoisoned_pages(struct page *memmap, int nr_pages)
94596
94597 for (i = 0; i < PAGES_PER_SECTION; i++) {
94598 if (PageHWPoison(&memmap[i])) {
94599 - atomic_long_sub(1, &num_poisoned_pages);
94600 + atomic_long_sub_unchecked(1, &num_poisoned_pages);
94601 ClearPageHWPoison(&memmap[i]);
94602 }
94603 }
94604 diff --git a/mm/swap.c b/mm/swap.c
94605 index 84b26aa..ce39899 100644
94606 --- a/mm/swap.c
94607 +++ b/mm/swap.c
94608 @@ -77,6 +77,8 @@ static void __put_compound_page(struct page *page)
94609
94610 __page_cache_release(page);
94611 dtor = get_compound_page_dtor(page);
94612 + if (!PageHuge(page))
94613 + BUG_ON(dtor != free_compound_page);
94614 (*dtor)(page);
94615 }
94616
94617 diff --git a/mm/swapfile.c b/mm/swapfile.c
94618 index 612a7c9..66b0f5a 100644
94619 --- a/mm/swapfile.c
94620 +++ b/mm/swapfile.c
94621 @@ -66,7 +66,7 @@ static DEFINE_MUTEX(swapon_mutex);
94622
94623 static DECLARE_WAIT_QUEUE_HEAD(proc_poll_wait);
94624 /* Activity counter to indicate that a swapon or swapoff has occurred */
94625 -static atomic_t proc_poll_event = ATOMIC_INIT(0);
94626 +static atomic_unchecked_t proc_poll_event = ATOMIC_INIT(0);
94627
94628 static inline unsigned char swap_count(unsigned char ent)
94629 {
94630 @@ -1949,7 +1949,7 @@ SYSCALL_DEFINE1(swapoff, const char __user *, specialfile)
94631 }
94632 filp_close(swap_file, NULL);
94633 err = 0;
94634 - atomic_inc(&proc_poll_event);
94635 + atomic_inc_unchecked(&proc_poll_event);
94636 wake_up_interruptible(&proc_poll_wait);
94637
94638 out_dput:
94639 @@ -1966,8 +1966,8 @@ static unsigned swaps_poll(struct file *file, poll_table *wait)
94640
94641 poll_wait(file, &proc_poll_wait, wait);
94642
94643 - if (seq->poll_event != atomic_read(&proc_poll_event)) {
94644 - seq->poll_event = atomic_read(&proc_poll_event);
94645 + if (seq->poll_event != atomic_read_unchecked(&proc_poll_event)) {
94646 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
94647 return POLLIN | POLLRDNORM | POLLERR | POLLPRI;
94648 }
94649
94650 @@ -2065,7 +2065,7 @@ static int swaps_open(struct inode *inode, struct file *file)
94651 return ret;
94652
94653 seq = file->private_data;
94654 - seq->poll_event = atomic_read(&proc_poll_event);
94655 + seq->poll_event = atomic_read_unchecked(&proc_poll_event);
94656 return 0;
94657 }
94658
94659 @@ -2524,7 +2524,7 @@ SYSCALL_DEFINE2(swapon, const char __user *, specialfile, int, swap_flags)
94660 (frontswap_map) ? "FS" : "");
94661
94662 mutex_unlock(&swapon_mutex);
94663 - atomic_inc(&proc_poll_event);
94664 + atomic_inc_unchecked(&proc_poll_event);
94665 wake_up_interruptible(&proc_poll_wait);
94666
94667 if (S_ISREG(inode->i_mode))
94668 diff --git a/mm/util.c b/mm/util.c
94669 index 808f375..e4764b5 100644
94670 --- a/mm/util.c
94671 +++ b/mm/util.c
94672 @@ -297,6 +297,12 @@ done:
94673 void arch_pick_mmap_layout(struct mm_struct *mm)
94674 {
94675 mm->mmap_base = TASK_UNMAPPED_BASE;
94676 +
94677 +#ifdef CONFIG_PAX_RANDMMAP
94678 + if (mm->pax_flags & MF_PAX_RANDMMAP)
94679 + mm->mmap_base += mm->delta_mmap;
94680 +#endif
94681 +
94682 mm->get_unmapped_area = arch_get_unmapped_area;
94683 }
94684 #endif
94685 diff --git a/mm/vmalloc.c b/mm/vmalloc.c
94686 index 0fdf968..d6686e8 100644
94687 --- a/mm/vmalloc.c
94688 +++ b/mm/vmalloc.c
94689 @@ -59,8 +59,19 @@ static void vunmap_pte_range(pmd_t *pmd, unsigned long addr, unsigned long end)
94690
94691 pte = pte_offset_kernel(pmd, addr);
94692 do {
94693 - pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
94694 - WARN_ON(!pte_none(ptent) && !pte_present(ptent));
94695 +
94696 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
94697 + if ((unsigned long)MODULES_EXEC_VADDR <= addr && addr < (unsigned long)MODULES_EXEC_END) {
94698 + BUG_ON(!pte_exec(*pte));
94699 + set_pte_at(&init_mm, addr, pte, pfn_pte(__pa(addr) >> PAGE_SHIFT, PAGE_KERNEL_EXEC));
94700 + continue;
94701 + }
94702 +#endif
94703 +
94704 + {
94705 + pte_t ptent = ptep_get_and_clear(&init_mm, addr, pte);
94706 + WARN_ON(!pte_none(ptent) && !pte_present(ptent));
94707 + }
94708 } while (pte++, addr += PAGE_SIZE, addr != end);
94709 }
94710
94711 @@ -120,16 +131,29 @@ static int vmap_pte_range(pmd_t *pmd, unsigned long addr,
94712 pte = pte_alloc_kernel(pmd, addr);
94713 if (!pte)
94714 return -ENOMEM;
94715 +
94716 + pax_open_kernel();
94717 do {
94718 struct page *page = pages[*nr];
94719
94720 - if (WARN_ON(!pte_none(*pte)))
94721 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
94722 + if (pgprot_val(prot) & _PAGE_NX)
94723 +#endif
94724 +
94725 + if (!pte_none(*pte)) {
94726 + pax_close_kernel();
94727 + WARN_ON(1);
94728 return -EBUSY;
94729 - if (WARN_ON(!page))
94730 + }
94731 + if (!page) {
94732 + pax_close_kernel();
94733 + WARN_ON(1);
94734 return -ENOMEM;
94735 + }
94736 set_pte_at(&init_mm, addr, pte, mk_pte(page, prot));
94737 (*nr)++;
94738 } while (pte++, addr += PAGE_SIZE, addr != end);
94739 + pax_close_kernel();
94740 return 0;
94741 }
94742
94743 @@ -139,7 +163,7 @@ static int vmap_pmd_range(pud_t *pud, unsigned long addr,
94744 pmd_t *pmd;
94745 unsigned long next;
94746
94747 - pmd = pmd_alloc(&init_mm, pud, addr);
94748 + pmd = pmd_alloc_kernel(&init_mm, pud, addr);
94749 if (!pmd)
94750 return -ENOMEM;
94751 do {
94752 @@ -156,7 +180,7 @@ static int vmap_pud_range(pgd_t *pgd, unsigned long addr,
94753 pud_t *pud;
94754 unsigned long next;
94755
94756 - pud = pud_alloc(&init_mm, pgd, addr);
94757 + pud = pud_alloc_kernel(&init_mm, pgd, addr);
94758 if (!pud)
94759 return -ENOMEM;
94760 do {
94761 @@ -216,6 +240,12 @@ int is_vmalloc_or_module_addr(const void *x)
94762 if (addr >= MODULES_VADDR && addr < MODULES_END)
94763 return 1;
94764 #endif
94765 +
94766 +#if defined(CONFIG_X86_32) && defined(CONFIG_PAX_KERNEXEC)
94767 + if (x >= (const void *)MODULES_EXEC_VADDR && x < (const void *)MODULES_EXEC_END)
94768 + return 1;
94769 +#endif
94770 +
94771 return is_vmalloc_addr(x);
94772 }
94773
94774 @@ -236,8 +266,14 @@ struct page *vmalloc_to_page(const void *vmalloc_addr)
94775
94776 if (!pgd_none(*pgd)) {
94777 pud_t *pud = pud_offset(pgd, addr);
94778 +#ifdef CONFIG_X86
94779 + if (!pud_large(*pud))
94780 +#endif
94781 if (!pud_none(*pud)) {
94782 pmd_t *pmd = pmd_offset(pud, addr);
94783 +#ifdef CONFIG_X86
94784 + if (!pmd_large(*pmd))
94785 +#endif
94786 if (!pmd_none(*pmd)) {
94787 pte_t *ptep, pte;
94788
94789 @@ -1309,6 +1345,16 @@ static struct vm_struct *__get_vm_area_node(unsigned long size,
94790 struct vm_struct *area;
94791
94792 BUG_ON(in_interrupt());
94793 +
94794 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
94795 + if (flags & VM_KERNEXEC) {
94796 + if (start != VMALLOC_START || end != VMALLOC_END)
94797 + return NULL;
94798 + start = (unsigned long)MODULES_EXEC_VADDR;
94799 + end = (unsigned long)MODULES_EXEC_END;
94800 + }
94801 +#endif
94802 +
94803 if (flags & VM_IOREMAP)
94804 align = 1ul << clamp(fls(size), PAGE_SHIFT, IOREMAP_MAX_ORDER);
94805
94806 @@ -1534,6 +1580,11 @@ void *vmap(struct page **pages, unsigned int count,
94807 if (count > totalram_pages)
94808 return NULL;
94809
94810 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
94811 + if (!(pgprot_val(prot) & _PAGE_NX))
94812 + flags |= VM_KERNEXEC;
94813 +#endif
94814 +
94815 area = get_vm_area_caller((count << PAGE_SHIFT), flags,
94816 __builtin_return_address(0));
94817 if (!area)
94818 @@ -1634,6 +1685,13 @@ void *__vmalloc_node_range(unsigned long size, unsigned long align,
94819 if (!size || (size >> PAGE_SHIFT) > totalram_pages)
94820 goto fail;
94821
94822 +#if defined(CONFIG_X86) && defined(CONFIG_PAX_KERNEXEC)
94823 + if (!(pgprot_val(prot) & _PAGE_NX))
94824 + area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED | VM_KERNEXEC,
94825 + VMALLOC_START, VMALLOC_END, node, gfp_mask, caller);
94826 + else
94827 +#endif
94828 +
94829 area = __get_vm_area_node(size, align, VM_ALLOC | VM_UNINITIALIZED,
94830 start, end, node, gfp_mask, caller);
94831 if (!area)
94832 @@ -1810,10 +1868,9 @@ EXPORT_SYMBOL(vzalloc_node);
94833 * For tight control over page level allocator and protection flags
94834 * use __vmalloc() instead.
94835 */
94836 -
94837 void *vmalloc_exec(unsigned long size)
94838 {
94839 - return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM, PAGE_KERNEL_EXEC,
94840 + return __vmalloc_node(size, 1, GFP_KERNEL | __GFP_HIGHMEM | __GFP_ZERO, PAGE_KERNEL_EXEC,
94841 NUMA_NO_NODE, __builtin_return_address(0));
94842 }
94843
94844 @@ -2120,6 +2177,8 @@ int remap_vmalloc_range_partial(struct vm_area_struct *vma, unsigned long uaddr,
94845 {
94846 struct vm_struct *area;
94847
94848 + BUG_ON(vma->vm_mirror);
94849 +
94850 size = PAGE_ALIGN(size);
94851
94852 if (!PAGE_ALIGNED(uaddr) || !PAGE_ALIGNED(kaddr))
94853 @@ -2602,7 +2661,11 @@ static int s_show(struct seq_file *m, void *p)
94854 v->addr, v->addr + v->size, v->size);
94855
94856 if (v->caller)
94857 +#ifdef CONFIG_GRKERNSEC_HIDESYM
94858 + seq_printf(m, " %pK", v->caller);
94859 +#else
94860 seq_printf(m, " %pS", v->caller);
94861 +#endif
94862
94863 if (v->nr_pages)
94864 seq_printf(m, " pages=%d", v->nr_pages);
94865 diff --git a/mm/vmstat.c b/mm/vmstat.c
94866 index 7249614..2639fc7 100644
94867 --- a/mm/vmstat.c
94868 +++ b/mm/vmstat.c
94869 @@ -20,6 +20,7 @@
94870 #include <linux/writeback.h>
94871 #include <linux/compaction.h>
94872 #include <linux/mm_inline.h>
94873 +#include <linux/grsecurity.h>
94874
94875 #include "internal.h"
94876
94877 @@ -79,7 +80,7 @@ void vm_events_fold_cpu(int cpu)
94878 *
94879 * vm_stat contains the global counters
94880 */
94881 -atomic_long_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
94882 +atomic_long_unchecked_t vm_stat[NR_VM_ZONE_STAT_ITEMS] __cacheline_aligned_in_smp;
94883 EXPORT_SYMBOL(vm_stat);
94884
94885 #ifdef CONFIG_SMP
94886 @@ -423,7 +424,7 @@ static inline void fold_diff(int *diff)
94887
94888 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
94889 if (diff[i])
94890 - atomic_long_add(diff[i], &vm_stat[i]);
94891 + atomic_long_add_unchecked(diff[i], &vm_stat[i]);
94892 }
94893
94894 /*
94895 @@ -455,7 +456,7 @@ static void refresh_cpu_vm_stats(void)
94896 v = this_cpu_xchg(p->vm_stat_diff[i], 0);
94897 if (v) {
94898
94899 - atomic_long_add(v, &zone->vm_stat[i]);
94900 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
94901 global_diff[i] += v;
94902 #ifdef CONFIG_NUMA
94903 /* 3 seconds idle till flush */
94904 @@ -517,7 +518,7 @@ void cpu_vm_stats_fold(int cpu)
94905
94906 v = p->vm_stat_diff[i];
94907 p->vm_stat_diff[i] = 0;
94908 - atomic_long_add(v, &zone->vm_stat[i]);
94909 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
94910 global_diff[i] += v;
94911 }
94912 }
94913 @@ -537,8 +538,8 @@ void drain_zonestat(struct zone *zone, struct per_cpu_pageset *pset)
94914 if (pset->vm_stat_diff[i]) {
94915 int v = pset->vm_stat_diff[i];
94916 pset->vm_stat_diff[i] = 0;
94917 - atomic_long_add(v, &zone->vm_stat[i]);
94918 - atomic_long_add(v, &vm_stat[i]);
94919 + atomic_long_add_unchecked(v, &zone->vm_stat[i]);
94920 + atomic_long_add_unchecked(v, &vm_stat[i]);
94921 }
94922 }
94923 #endif
94924 @@ -1148,10 +1149,22 @@ static void *vmstat_start(struct seq_file *m, loff_t *pos)
94925 stat_items_size += sizeof(struct vm_event_state);
94926 #endif
94927
94928 - v = kmalloc(stat_items_size, GFP_KERNEL);
94929 + v = kzalloc(stat_items_size, GFP_KERNEL);
94930 m->private = v;
94931 if (!v)
94932 return ERR_PTR(-ENOMEM);
94933 +
94934 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
94935 +#if defined(CONFIG_GRKERNSEC_PROC_USER) || defined(CONFIG_GRKERNSEC_PROC_USERGROUP)
94936 + if (!uid_eq(current_uid(), GLOBAL_ROOT_UID)
94937 +#ifdef CONFIG_GRKERNSEC_PROC_USERGROUP
94938 + && !in_group_p(grsec_proc_gid)
94939 +#endif
94940 + )
94941 + return (unsigned long *)m->private + *pos;
94942 +#endif
94943 +#endif
94944 +
94945 for (i = 0; i < NR_VM_ZONE_STAT_ITEMS; i++)
94946 v[i] = global_page_state(i);
94947 v += NR_VM_ZONE_STAT_ITEMS;
94948 @@ -1300,10 +1313,16 @@ static int __init setup_vmstat(void)
94949 put_online_cpus();
94950 #endif
94951 #ifdef CONFIG_PROC_FS
94952 - proc_create("buddyinfo", S_IRUGO, NULL, &fragmentation_file_operations);
94953 - proc_create("pagetypeinfo", S_IRUGO, NULL, &pagetypeinfo_file_ops);
94954 - proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
94955 - proc_create("zoneinfo", S_IRUGO, NULL, &proc_zoneinfo_file_operations);
94956 + {
94957 + mode_t gr_mode = S_IRUGO;
94958 +#ifdef CONFIG_GRKERNSEC_PROC_ADD
94959 + gr_mode = S_IRUSR;
94960 +#endif
94961 + proc_create("buddyinfo", gr_mode, NULL, &fragmentation_file_operations);
94962 + proc_create("pagetypeinfo", gr_mode, NULL, &pagetypeinfo_file_ops);
94963 + proc_create("vmstat", S_IRUGO, NULL, &proc_vmstat_file_operations);
94964 + proc_create("zoneinfo", gr_mode, NULL, &proc_zoneinfo_file_operations);
94965 + }
94966 #endif
94967 return 0;
94968 }
94969 diff --git a/net/8021q/vlan.c b/net/8021q/vlan.c
94970 index b3d17d1..e8e4cdd 100644
94971 --- a/net/8021q/vlan.c
94972 +++ b/net/8021q/vlan.c
94973 @@ -472,7 +472,7 @@ out:
94974 return NOTIFY_DONE;
94975 }
94976
94977 -static struct notifier_block vlan_notifier_block __read_mostly = {
94978 +static struct notifier_block vlan_notifier_block = {
94979 .notifier_call = vlan_device_event,
94980 };
94981
94982 @@ -547,8 +547,7 @@ static int vlan_ioctl_handler(struct net *net, void __user *arg)
94983 err = -EPERM;
94984 if (!ns_capable(net->user_ns, CAP_NET_ADMIN))
94985 break;
94986 - if ((args.u.name_type >= 0) &&
94987 - (args.u.name_type < VLAN_NAME_TYPE_HIGHEST)) {
94988 + if (args.u.name_type < VLAN_NAME_TYPE_HIGHEST) {
94989 struct vlan_net *vn;
94990
94991 vn = net_generic(net, vlan_net_id);
94992 diff --git a/net/9p/client.c b/net/9p/client.c
94993 index ee8fd6b..0469d50 100644
94994 --- a/net/9p/client.c
94995 +++ b/net/9p/client.c
94996 @@ -588,7 +588,7 @@ static int p9_check_zc_errors(struct p9_client *c, struct p9_req_t *req,
94997 len - inline_len);
94998 } else {
94999 err = copy_from_user(ename + inline_len,
95000 - uidata, len - inline_len);
95001 + (char __force_user *)uidata, len - inline_len);
95002 if (err) {
95003 err = -EFAULT;
95004 goto out_err;
95005 @@ -1563,7 +1563,7 @@ p9_client_read(struct p9_fid *fid, char *data, char __user *udata, u64 offset,
95006 kernel_buf = 1;
95007 indata = data;
95008 } else
95009 - indata = (__force char *)udata;
95010 + indata = (__force_kernel char *)udata;
95011 /*
95012 * response header len is 11
95013 * PDU Header(7) + IO Size (4)
95014 @@ -1638,7 +1638,7 @@ p9_client_write(struct p9_fid *fid, char *data, const char __user *udata,
95015 kernel_buf = 1;
95016 odata = data;
95017 } else
95018 - odata = (char *)udata;
95019 + odata = (char __force_kernel *)udata;
95020 req = p9_client_zc_rpc(clnt, P9_TWRITE, NULL, odata, 0, rsize,
95021 P9_ZC_HDR_SZ, kernel_buf, "dqd",
95022 fid->fid, offset, rsize);
95023 diff --git a/net/9p/mod.c b/net/9p/mod.c
95024 index 6ab36ae..6f1841b 100644
95025 --- a/net/9p/mod.c
95026 +++ b/net/9p/mod.c
95027 @@ -84,7 +84,7 @@ static LIST_HEAD(v9fs_trans_list);
95028 void v9fs_register_trans(struct p9_trans_module *m)
95029 {
95030 spin_lock(&v9fs_trans_lock);
95031 - list_add_tail(&m->list, &v9fs_trans_list);
95032 + pax_list_add_tail((struct list_head *)&m->list, &v9fs_trans_list);
95033 spin_unlock(&v9fs_trans_lock);
95034 }
95035 EXPORT_SYMBOL(v9fs_register_trans);
95036 @@ -97,7 +97,7 @@ EXPORT_SYMBOL(v9fs_register_trans);
95037 void v9fs_unregister_trans(struct p9_trans_module *m)
95038 {
95039 spin_lock(&v9fs_trans_lock);
95040 - list_del_init(&m->list);
95041 + pax_list_del_init((struct list_head *)&m->list);
95042 spin_unlock(&v9fs_trans_lock);
95043 }
95044 EXPORT_SYMBOL(v9fs_unregister_trans);
95045 diff --git a/net/9p/trans_fd.c b/net/9p/trans_fd.c
95046 index 9321a77..ed2f256 100644
95047 --- a/net/9p/trans_fd.c
95048 +++ b/net/9p/trans_fd.c
95049 @@ -432,7 +432,7 @@ static int p9_fd_write(struct p9_client *client, void *v, int len)
95050 oldfs = get_fs();
95051 set_fs(get_ds());
95052 /* The cast to a user pointer is valid due to the set_fs() */
95053 - ret = vfs_write(ts->wr, (__force void __user *)v, len, &ts->wr->f_pos);
95054 + ret = vfs_write(ts->wr, (void __force_user *)v, len, &ts->wr->f_pos);
95055 set_fs(oldfs);
95056
95057 if (ret <= 0 && ret != -ERESTARTSYS && ret != -EAGAIN)
95058 diff --git a/net/9p/trans_virtio.c b/net/9p/trans_virtio.c
95059 index 9c5a1aa..3c6c637 100644
95060 --- a/net/9p/trans_virtio.c
95061 +++ b/net/9p/trans_virtio.c
95062 @@ -340,7 +340,10 @@ static int p9_get_mapped_pages(struct virtio_chan *chan,
95063 int count = nr_pages;
95064 while (nr_pages) {
95065 s = rest_of_page(data);
95066 - pages[index++] = kmap_to_page(data);
95067 + if (is_vmalloc_addr(data))
95068 + pages[index++] = vmalloc_to_page(data);
95069 + else
95070 + pages[index++] = kmap_to_page(data);
95071 data += s;
95072 nr_pages--;
95073 }
95074 diff --git a/net/atm/atm_misc.c b/net/atm/atm_misc.c
95075 index 876fbe8..8bbea9f 100644
95076 --- a/net/atm/atm_misc.c
95077 +++ b/net/atm/atm_misc.c
95078 @@ -17,7 +17,7 @@ int atm_charge(struct atm_vcc *vcc, int truesize)
95079 if (atomic_read(&sk_atm(vcc)->sk_rmem_alloc) <= sk_atm(vcc)->sk_rcvbuf)
95080 return 1;
95081 atm_return(vcc, truesize);
95082 - atomic_inc(&vcc->stats->rx_drop);
95083 + atomic_inc_unchecked(&vcc->stats->rx_drop);
95084 return 0;
95085 }
95086 EXPORT_SYMBOL(atm_charge);
95087 @@ -39,7 +39,7 @@ struct sk_buff *atm_alloc_charge(struct atm_vcc *vcc, int pdu_size,
95088 }
95089 }
95090 atm_return(vcc, guess);
95091 - atomic_inc(&vcc->stats->rx_drop);
95092 + atomic_inc_unchecked(&vcc->stats->rx_drop);
95093 return NULL;
95094 }
95095 EXPORT_SYMBOL(atm_alloc_charge);
95096 @@ -86,7 +86,7 @@ EXPORT_SYMBOL(atm_pcr_goal);
95097
95098 void sonet_copy_stats(struct k_sonet_stats *from, struct sonet_stats *to)
95099 {
95100 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
95101 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
95102 __SONET_ITEMS
95103 #undef __HANDLE_ITEM
95104 }
95105 @@ -94,7 +94,7 @@ EXPORT_SYMBOL(sonet_copy_stats);
95106
95107 void sonet_subtract_stats(struct k_sonet_stats *from, struct sonet_stats *to)
95108 {
95109 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
95110 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i,&from->i)
95111 __SONET_ITEMS
95112 #undef __HANDLE_ITEM
95113 }
95114 diff --git a/net/atm/lec.c b/net/atm/lec.c
95115 index f23916b..dd4d26b 100644
95116 --- a/net/atm/lec.c
95117 +++ b/net/atm/lec.c
95118 @@ -111,9 +111,9 @@ static inline void lec_arp_put(struct lec_arp_table *entry)
95119 }
95120
95121 static struct lane2_ops lane2_ops = {
95122 - lane2_resolve, /* resolve, spec 3.1.3 */
95123 - lane2_associate_req, /* associate_req, spec 3.1.4 */
95124 - NULL /* associate indicator, spec 3.1.5 */
95125 + .resolve = lane2_resolve,
95126 + .associate_req = lane2_associate_req,
95127 + .associate_indicator = NULL
95128 };
95129
95130 static unsigned char bus_mac[ETH_ALEN] = { 0xff, 0xff, 0xff, 0xff, 0xff, 0xff };
95131 diff --git a/net/atm/lec.h b/net/atm/lec.h
95132 index 4149db1..f2ab682 100644
95133 --- a/net/atm/lec.h
95134 +++ b/net/atm/lec.h
95135 @@ -48,7 +48,7 @@ struct lane2_ops {
95136 const u8 *tlvs, u32 sizeoftlvs);
95137 void (*associate_indicator) (struct net_device *dev, const u8 *mac_addr,
95138 const u8 *tlvs, u32 sizeoftlvs);
95139 -};
95140 +} __no_const;
95141
95142 /*
95143 * ATM LAN Emulation supports both LLC & Dix Ethernet EtherType
95144 diff --git a/net/atm/mpoa_caches.c b/net/atm/mpoa_caches.c
95145 index d1b2d9a..d549f7f 100644
95146 --- a/net/atm/mpoa_caches.c
95147 +++ b/net/atm/mpoa_caches.c
95148 @@ -535,30 +535,30 @@ static void eg_destroy_cache(struct mpoa_client *mpc)
95149
95150
95151 static struct in_cache_ops ingress_ops = {
95152 - in_cache_add_entry, /* add_entry */
95153 - in_cache_get, /* get */
95154 - in_cache_get_with_mask, /* get_with_mask */
95155 - in_cache_get_by_vcc, /* get_by_vcc */
95156 - in_cache_put, /* put */
95157 - in_cache_remove_entry, /* remove_entry */
95158 - cache_hit, /* cache_hit */
95159 - clear_count_and_expired, /* clear_count */
95160 - check_resolving_entries, /* check_resolving */
95161 - refresh_entries, /* refresh */
95162 - in_destroy_cache /* destroy_cache */
95163 + .add_entry = in_cache_add_entry,
95164 + .get = in_cache_get,
95165 + .get_with_mask = in_cache_get_with_mask,
95166 + .get_by_vcc = in_cache_get_by_vcc,
95167 + .put = in_cache_put,
95168 + .remove_entry = in_cache_remove_entry,
95169 + .cache_hit = cache_hit,
95170 + .clear_count = clear_count_and_expired,
95171 + .check_resolving = check_resolving_entries,
95172 + .refresh = refresh_entries,
95173 + .destroy_cache = in_destroy_cache
95174 };
95175
95176 static struct eg_cache_ops egress_ops = {
95177 - eg_cache_add_entry, /* add_entry */
95178 - eg_cache_get_by_cache_id, /* get_by_cache_id */
95179 - eg_cache_get_by_tag, /* get_by_tag */
95180 - eg_cache_get_by_vcc, /* get_by_vcc */
95181 - eg_cache_get_by_src_ip, /* get_by_src_ip */
95182 - eg_cache_put, /* put */
95183 - eg_cache_remove_entry, /* remove_entry */
95184 - update_eg_cache_entry, /* update */
95185 - clear_expired, /* clear_expired */
95186 - eg_destroy_cache /* destroy_cache */
95187 + .add_entry = eg_cache_add_entry,
95188 + .get_by_cache_id = eg_cache_get_by_cache_id,
95189 + .get_by_tag = eg_cache_get_by_tag,
95190 + .get_by_vcc = eg_cache_get_by_vcc,
95191 + .get_by_src_ip = eg_cache_get_by_src_ip,
95192 + .put = eg_cache_put,
95193 + .remove_entry = eg_cache_remove_entry,
95194 + .update = update_eg_cache_entry,
95195 + .clear_expired = clear_expired,
95196 + .destroy_cache = eg_destroy_cache
95197 };
95198
95199
95200 diff --git a/net/atm/proc.c b/net/atm/proc.c
95201 index bbb6461..cf04016 100644
95202 --- a/net/atm/proc.c
95203 +++ b/net/atm/proc.c
95204 @@ -45,9 +45,9 @@ static void add_stats(struct seq_file *seq, const char *aal,
95205 const struct k_atm_aal_stats *stats)
95206 {
95207 seq_printf(seq, "%s ( %d %d %d %d %d )", aal,
95208 - atomic_read(&stats->tx), atomic_read(&stats->tx_err),
95209 - atomic_read(&stats->rx), atomic_read(&stats->rx_err),
95210 - atomic_read(&stats->rx_drop));
95211 + atomic_read_unchecked(&stats->tx),atomic_read_unchecked(&stats->tx_err),
95212 + atomic_read_unchecked(&stats->rx),atomic_read_unchecked(&stats->rx_err),
95213 + atomic_read_unchecked(&stats->rx_drop));
95214 }
95215
95216 static void atm_dev_info(struct seq_file *seq, const struct atm_dev *dev)
95217 diff --git a/net/atm/resources.c b/net/atm/resources.c
95218 index 0447d5d..3cf4728 100644
95219 --- a/net/atm/resources.c
95220 +++ b/net/atm/resources.c
95221 @@ -160,7 +160,7 @@ EXPORT_SYMBOL(atm_dev_deregister);
95222 static void copy_aal_stats(struct k_atm_aal_stats *from,
95223 struct atm_aal_stats *to)
95224 {
95225 -#define __HANDLE_ITEM(i) to->i = atomic_read(&from->i)
95226 +#define __HANDLE_ITEM(i) to->i = atomic_read_unchecked(&from->i)
95227 __AAL_STAT_ITEMS
95228 #undef __HANDLE_ITEM
95229 }
95230 @@ -168,7 +168,7 @@ static void copy_aal_stats(struct k_atm_aal_stats *from,
95231 static void subtract_aal_stats(struct k_atm_aal_stats *from,
95232 struct atm_aal_stats *to)
95233 {
95234 -#define __HANDLE_ITEM(i) atomic_sub(to->i, &from->i)
95235 +#define __HANDLE_ITEM(i) atomic_sub_unchecked(to->i, &from->i)
95236 __AAL_STAT_ITEMS
95237 #undef __HANDLE_ITEM
95238 }
95239 diff --git a/net/ax25/sysctl_net_ax25.c b/net/ax25/sysctl_net_ax25.c
95240 index 919a5ce..cc6b444 100644
95241 --- a/net/ax25/sysctl_net_ax25.c
95242 +++ b/net/ax25/sysctl_net_ax25.c
95243 @@ -152,7 +152,7 @@ int ax25_register_dev_sysctl(ax25_dev *ax25_dev)
95244 {
95245 char path[sizeof("net/ax25/") + IFNAMSIZ];
95246 int k;
95247 - struct ctl_table *table;
95248 + ctl_table_no_const *table;
95249
95250 table = kmemdup(ax25_param_table, sizeof(ax25_param_table), GFP_KERNEL);
95251 if (!table)
95252 diff --git a/net/batman-adv/bat_iv_ogm.c b/net/batman-adv/bat_iv_ogm.c
95253 index b9c8a6e..ed0f711 100644
95254 --- a/net/batman-adv/bat_iv_ogm.c
95255 +++ b/net/batman-adv/bat_iv_ogm.c
95256 @@ -297,7 +297,7 @@ static int batadv_iv_ogm_iface_enable(struct batadv_hard_iface *hard_iface)
95257
95258 /* randomize initial seqno to avoid collision */
95259 get_random_bytes(&random_seqno, sizeof(random_seqno));
95260 - atomic_set(&hard_iface->bat_iv.ogm_seqno, random_seqno);
95261 + atomic_set_unchecked(&hard_iface->bat_iv.ogm_seqno, random_seqno);
95262
95263 hard_iface->bat_iv.ogm_buff_len = BATADV_OGM_HLEN;
95264 ogm_buff = kmalloc(hard_iface->bat_iv.ogm_buff_len, GFP_ATOMIC);
95265 @@ -884,9 +884,9 @@ static void batadv_iv_ogm_schedule(struct batadv_hard_iface *hard_iface)
95266 batadv_ogm_packet->tvlv_len = htons(tvlv_len);
95267
95268 /* change sequence number to network order */
95269 - seqno = (uint32_t)atomic_read(&hard_iface->bat_iv.ogm_seqno);
95270 + seqno = (uint32_t)atomic_read_unchecked(&hard_iface->bat_iv.ogm_seqno);
95271 batadv_ogm_packet->seqno = htonl(seqno);
95272 - atomic_inc(&hard_iface->bat_iv.ogm_seqno);
95273 + atomic_inc_unchecked(&hard_iface->bat_iv.ogm_seqno);
95274
95275 batadv_iv_ogm_slide_own_bcast_window(hard_iface);
95276 batadv_iv_ogm_queue_add(bat_priv, hard_iface->bat_iv.ogm_buff,
95277 @@ -1251,7 +1251,7 @@ static void batadv_iv_ogm_process(const struct ethhdr *ethhdr,
95278 return;
95279
95280 /* could be changed by schedule_own_packet() */
95281 - if_incoming_seqno = atomic_read(&if_incoming->bat_iv.ogm_seqno);
95282 + if_incoming_seqno = atomic_read_unchecked(&if_incoming->bat_iv.ogm_seqno);
95283
95284 if (batadv_ogm_packet->flags & BATADV_DIRECTLINK)
95285 has_directlink_flag = 1;
95286 diff --git a/net/batman-adv/fragmentation.c b/net/batman-adv/fragmentation.c
95287 index 6ddb614..ca7e886 100644
95288 --- a/net/batman-adv/fragmentation.c
95289 +++ b/net/batman-adv/fragmentation.c
95290 @@ -447,7 +447,7 @@ bool batadv_frag_send_packet(struct sk_buff *skb,
95291 frag_header.packet_type = BATADV_UNICAST_FRAG;
95292 frag_header.version = BATADV_COMPAT_VERSION;
95293 frag_header.ttl = BATADV_TTL;
95294 - frag_header.seqno = htons(atomic_inc_return(&bat_priv->frag_seqno));
95295 + frag_header.seqno = htons(atomic_inc_return_unchecked(&bat_priv->frag_seqno));
95296 frag_header.reserved = 0;
95297 frag_header.no = 0;
95298 frag_header.total_size = htons(skb->len);
95299 diff --git a/net/batman-adv/soft-interface.c b/net/batman-adv/soft-interface.c
95300 index a8f99d1..11797ef 100644
95301 --- a/net/batman-adv/soft-interface.c
95302 +++ b/net/batman-adv/soft-interface.c
95303 @@ -278,7 +278,7 @@ static int batadv_interface_tx(struct sk_buff *skb,
95304 primary_if->net_dev->dev_addr, ETH_ALEN);
95305
95306 /* set broadcast sequence number */
95307 - seqno = atomic_inc_return(&bat_priv->bcast_seqno);
95308 + seqno = atomic_inc_return_unchecked(&bat_priv->bcast_seqno);
95309 bcast_packet->seqno = htonl(seqno);
95310
95311 batadv_add_bcast_packet_to_list(bat_priv, skb, brd_delay);
95312 @@ -688,7 +688,7 @@ static int batadv_softif_init_late(struct net_device *dev)
95313 atomic_set(&bat_priv->batman_queue_left, BATADV_BATMAN_QUEUE_LEN);
95314
95315 atomic_set(&bat_priv->mesh_state, BATADV_MESH_INACTIVE);
95316 - atomic_set(&bat_priv->bcast_seqno, 1);
95317 + atomic_set_unchecked(&bat_priv->bcast_seqno, 1);
95318 atomic_set(&bat_priv->tt.vn, 0);
95319 atomic_set(&bat_priv->tt.local_changes, 0);
95320 atomic_set(&bat_priv->tt.ogm_append_cnt, 0);
95321 @@ -700,7 +700,7 @@ static int batadv_softif_init_late(struct net_device *dev)
95322
95323 /* randomize initial seqno to avoid collision */
95324 get_random_bytes(&random_seqno, sizeof(random_seqno));
95325 - atomic_set(&bat_priv->frag_seqno, random_seqno);
95326 + atomic_set_unchecked(&bat_priv->frag_seqno, random_seqno);
95327
95328 bat_priv->primary_if = NULL;
95329 bat_priv->num_ifaces = 0;
95330 diff --git a/net/batman-adv/types.h b/net/batman-adv/types.h
95331 index 91dd369..9c25750 100644
95332 --- a/net/batman-adv/types.h
95333 +++ b/net/batman-adv/types.h
95334 @@ -56,7 +56,7 @@
95335 struct batadv_hard_iface_bat_iv {
95336 unsigned char *ogm_buff;
95337 int ogm_buff_len;
95338 - atomic_t ogm_seqno;
95339 + atomic_unchecked_t ogm_seqno;
95340 };
95341
95342 /**
95343 @@ -673,7 +673,7 @@ struct batadv_priv {
95344 atomic_t bonding;
95345 atomic_t fragmentation;
95346 atomic_t packet_size_max;
95347 - atomic_t frag_seqno;
95348 + atomic_unchecked_t frag_seqno;
95349 #ifdef CONFIG_BATMAN_ADV_BLA
95350 atomic_t bridge_loop_avoidance;
95351 #endif
95352 @@ -687,7 +687,7 @@ struct batadv_priv {
95353 #ifdef CONFIG_BATMAN_ADV_DEBUG
95354 atomic_t log_level;
95355 #endif
95356 - atomic_t bcast_seqno;
95357 + atomic_unchecked_t bcast_seqno;
95358 atomic_t bcast_queue_left;
95359 atomic_t batman_queue_left;
95360 char num_ifaces;
95361 diff --git a/net/bluetooth/hci_sock.c b/net/bluetooth/hci_sock.c
95362 index 7552f9e..074ce29 100644
95363 --- a/net/bluetooth/hci_sock.c
95364 +++ b/net/bluetooth/hci_sock.c
95365 @@ -1052,7 +1052,7 @@ static int hci_sock_setsockopt(struct socket *sock, int level, int optname,
95366 uf.event_mask[1] = *((u32 *) f->event_mask + 1);
95367 }
95368
95369 - len = min_t(unsigned int, len, sizeof(uf));
95370 + len = min((size_t)len, sizeof(uf));
95371 if (copy_from_user(&uf, optval, len)) {
95372 err = -EFAULT;
95373 break;
95374 diff --git a/net/bluetooth/l2cap_core.c b/net/bluetooth/l2cap_core.c
95375 index 4af3821..f2ba46c 100644
95376 --- a/net/bluetooth/l2cap_core.c
95377 +++ b/net/bluetooth/l2cap_core.c
95378 @@ -3500,8 +3500,10 @@ static int l2cap_parse_conf_rsp(struct l2cap_chan *chan, void *rsp, int len,
95379 break;
95380
95381 case L2CAP_CONF_RFC:
95382 - if (olen == sizeof(rfc))
95383 - memcpy(&rfc, (void *)val, olen);
95384 + if (olen != sizeof(rfc))
95385 + break;
95386 +
95387 + memcpy(&rfc, (void *)val, olen);
95388
95389 if (test_bit(CONF_STATE2_DEVICE, &chan->conf_state) &&
95390 rfc.mode != chan->mode)
95391 diff --git a/net/bluetooth/l2cap_sock.c b/net/bluetooth/l2cap_sock.c
95392 index 7cc24d2..e83f531 100644
95393 --- a/net/bluetooth/l2cap_sock.c
95394 +++ b/net/bluetooth/l2cap_sock.c
95395 @@ -545,7 +545,8 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
95396 struct sock *sk = sock->sk;
95397 struct l2cap_chan *chan = l2cap_pi(sk)->chan;
95398 struct l2cap_options opts;
95399 - int len, err = 0;
95400 + int err = 0;
95401 + size_t len = optlen;
95402 u32 opt;
95403
95404 BT_DBG("sk %p", sk);
95405 @@ -567,7 +568,7 @@ static int l2cap_sock_setsockopt_old(struct socket *sock, int optname,
95406 opts.max_tx = chan->max_tx;
95407 opts.txwin_size = chan->tx_win;
95408
95409 - len = min_t(unsigned int, sizeof(opts), optlen);
95410 + len = min(sizeof(opts), len);
95411 if (copy_from_user((char *) &opts, optval, len)) {
95412 err = -EFAULT;
95413 break;
95414 @@ -647,7 +648,8 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
95415 struct bt_security sec;
95416 struct bt_power pwr;
95417 struct l2cap_conn *conn;
95418 - int len, err = 0;
95419 + int err = 0;
95420 + size_t len = optlen;
95421 u32 opt;
95422
95423 BT_DBG("sk %p", sk);
95424 @@ -670,7 +672,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
95425
95426 sec.level = BT_SECURITY_LOW;
95427
95428 - len = min_t(unsigned int, sizeof(sec), optlen);
95429 + len = min(sizeof(sec), len);
95430 if (copy_from_user((char *) &sec, optval, len)) {
95431 err = -EFAULT;
95432 break;
95433 @@ -770,7 +772,7 @@ static int l2cap_sock_setsockopt(struct socket *sock, int level, int optname,
95434
95435 pwr.force_active = BT_POWER_FORCE_ACTIVE_ON;
95436
95437 - len = min_t(unsigned int, sizeof(pwr), optlen);
95438 + len = min(sizeof(pwr), len);
95439 if (copy_from_user((char *) &pwr, optval, len)) {
95440 err = -EFAULT;
95441 break;
95442 diff --git a/net/bluetooth/rfcomm/sock.c b/net/bluetooth/rfcomm/sock.c
95443 index 3c2d3e4..884855a 100644
95444 --- a/net/bluetooth/rfcomm/sock.c
95445 +++ b/net/bluetooth/rfcomm/sock.c
95446 @@ -672,7 +672,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
95447 struct sock *sk = sock->sk;
95448 struct bt_security sec;
95449 int err = 0;
95450 - size_t len;
95451 + size_t len = optlen;
95452 u32 opt;
95453
95454 BT_DBG("sk %p", sk);
95455 @@ -694,7 +694,7 @@ static int rfcomm_sock_setsockopt(struct socket *sock, int level, int optname, c
95456
95457 sec.level = BT_SECURITY_LOW;
95458
95459 - len = min_t(unsigned int, sizeof(sec), optlen);
95460 + len = min(sizeof(sec), len);
95461 if (copy_from_user((char *) &sec, optval, len)) {
95462 err = -EFAULT;
95463 break;
95464 diff --git a/net/bluetooth/rfcomm/tty.c b/net/bluetooth/rfcomm/tty.c
95465 index 84fcf9f..e389b27 100644
95466 --- a/net/bluetooth/rfcomm/tty.c
95467 +++ b/net/bluetooth/rfcomm/tty.c
95468 @@ -684,7 +684,7 @@ static int rfcomm_tty_open(struct tty_struct *tty, struct file *filp)
95469 BT_DBG("tty %p id %d", tty, tty->index);
95470
95471 BT_DBG("dev %p dst %pMR channel %d opened %d", dev, &dev->dst,
95472 - dev->channel, dev->port.count);
95473 + dev->channel, atomic_read(&dev->port.count));
95474
95475 err = tty_port_open(&dev->port, tty, filp);
95476 if (err)
95477 @@ -707,7 +707,7 @@ static void rfcomm_tty_close(struct tty_struct *tty, struct file *filp)
95478 struct rfcomm_dev *dev = (struct rfcomm_dev *) tty->driver_data;
95479
95480 BT_DBG("tty %p dev %p dlc %p opened %d", tty, dev, dev->dlc,
95481 - dev->port.count);
95482 + atomic_read(&dev->port.count));
95483
95484 tty_port_close(&dev->port, tty, filp);
95485 }
95486 diff --git a/net/bridge/netfilter/ebtables.c b/net/bridge/netfilter/ebtables.c
95487 index ac78024..161a80c 100644
95488 --- a/net/bridge/netfilter/ebtables.c
95489 +++ b/net/bridge/netfilter/ebtables.c
95490 @@ -1525,7 +1525,7 @@ static int do_ebt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
95491 tmp.valid_hooks = t->table->valid_hooks;
95492 }
95493 mutex_unlock(&ebt_mutex);
95494 - if (copy_to_user(user, &tmp, *len) != 0){
95495 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0){
95496 BUGPRINT("c2u Didn't work\n");
95497 ret = -EFAULT;
95498 break;
95499 @@ -2331,7 +2331,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
95500 goto out;
95501 tmp.valid_hooks = t->valid_hooks;
95502
95503 - if (copy_to_user(user, &tmp, *len) != 0) {
95504 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
95505 ret = -EFAULT;
95506 break;
95507 }
95508 @@ -2342,7 +2342,7 @@ static int compat_do_ebt_get_ctl(struct sock *sk, int cmd,
95509 tmp.entries_size = t->table->entries_size;
95510 tmp.valid_hooks = t->table->valid_hooks;
95511
95512 - if (copy_to_user(user, &tmp, *len) != 0) {
95513 + if (*len > sizeof(tmp) || copy_to_user(user, &tmp, *len) != 0) {
95514 ret = -EFAULT;
95515 break;
95516 }
95517 diff --git a/net/caif/cfctrl.c b/net/caif/cfctrl.c
95518 index 0f45522..dab651f 100644
95519 --- a/net/caif/cfctrl.c
95520 +++ b/net/caif/cfctrl.c
95521 @@ -10,6 +10,7 @@
95522 #include <linux/spinlock.h>
95523 #include <linux/slab.h>
95524 #include <linux/pkt_sched.h>
95525 +#include <linux/sched.h>
95526 #include <net/caif/caif_layer.h>
95527 #include <net/caif/cfpkt.h>
95528 #include <net/caif/cfctrl.h>
95529 @@ -43,8 +44,8 @@ struct cflayer *cfctrl_create(void)
95530 memset(&dev_info, 0, sizeof(dev_info));
95531 dev_info.id = 0xff;
95532 cfsrvl_init(&this->serv, 0, &dev_info, false);
95533 - atomic_set(&this->req_seq_no, 1);
95534 - atomic_set(&this->rsp_seq_no, 1);
95535 + atomic_set_unchecked(&this->req_seq_no, 1);
95536 + atomic_set_unchecked(&this->rsp_seq_no, 1);
95537 this->serv.layer.receive = cfctrl_recv;
95538 sprintf(this->serv.layer.name, "ctrl");
95539 this->serv.layer.ctrlcmd = cfctrl_ctrlcmd;
95540 @@ -130,8 +131,8 @@ static void cfctrl_insert_req(struct cfctrl *ctrl,
95541 struct cfctrl_request_info *req)
95542 {
95543 spin_lock_bh(&ctrl->info_list_lock);
95544 - atomic_inc(&ctrl->req_seq_no);
95545 - req->sequence_no = atomic_read(&ctrl->req_seq_no);
95546 + atomic_inc_unchecked(&ctrl->req_seq_no);
95547 + req->sequence_no = atomic_read_unchecked(&ctrl->req_seq_no);
95548 list_add_tail(&req->list, &ctrl->list);
95549 spin_unlock_bh(&ctrl->info_list_lock);
95550 }
95551 @@ -149,7 +150,7 @@ static struct cfctrl_request_info *cfctrl_remove_req(struct cfctrl *ctrl,
95552 if (p != first)
95553 pr_warn("Requests are not received in order\n");
95554
95555 - atomic_set(&ctrl->rsp_seq_no,
95556 + atomic_set_unchecked(&ctrl->rsp_seq_no,
95557 p->sequence_no);
95558 list_del(&p->list);
95559 goto out;
95560 diff --git a/net/can/af_can.c b/net/can/af_can.c
95561 index d249874..99e197b 100644
95562 --- a/net/can/af_can.c
95563 +++ b/net/can/af_can.c
95564 @@ -862,7 +862,7 @@ static const struct net_proto_family can_family_ops = {
95565 };
95566
95567 /* notifier block for netdevice event */
95568 -static struct notifier_block can_netdev_notifier __read_mostly = {
95569 +static struct notifier_block can_netdev_notifier = {
95570 .notifier_call = can_notifier,
95571 };
95572
95573 diff --git a/net/can/gw.c b/net/can/gw.c
95574 index 3f9b0f3..fc6d4fa 100644
95575 --- a/net/can/gw.c
95576 +++ b/net/can/gw.c
95577 @@ -80,7 +80,6 @@ MODULE_PARM_DESC(max_hops,
95578 "default: " __stringify(CGW_DEFAULT_HOPS) ")");
95579
95580 static HLIST_HEAD(cgw_list);
95581 -static struct notifier_block notifier;
95582
95583 static struct kmem_cache *cgw_cache __read_mostly;
95584
95585 @@ -954,6 +953,10 @@ static int cgw_remove_job(struct sk_buff *skb, struct nlmsghdr *nlh)
95586 return err;
95587 }
95588
95589 +static struct notifier_block notifier = {
95590 + .notifier_call = cgw_notifier
95591 +};
95592 +
95593 static __init int cgw_module_init(void)
95594 {
95595 /* sanitize given module parameter */
95596 @@ -969,7 +972,6 @@ static __init int cgw_module_init(void)
95597 return -ENOMEM;
95598
95599 /* set notifier */
95600 - notifier.notifier_call = cgw_notifier;
95601 register_netdevice_notifier(&notifier);
95602
95603 if (__rtnl_register(PF_CAN, RTM_GETROUTE, NULL, cgw_dump_jobs, NULL)) {
95604 diff --git a/net/ceph/messenger.c b/net/ceph/messenger.c
95605 index 4a5df7b..9ad1f1d 100644
95606 --- a/net/ceph/messenger.c
95607 +++ b/net/ceph/messenger.c
95608 @@ -186,7 +186,7 @@ static void con_fault(struct ceph_connection *con);
95609 #define MAX_ADDR_STR_LEN 64 /* 54 is enough */
95610
95611 static char addr_str[ADDR_STR_COUNT][MAX_ADDR_STR_LEN];
95612 -static atomic_t addr_str_seq = ATOMIC_INIT(0);
95613 +static atomic_unchecked_t addr_str_seq = ATOMIC_INIT(0);
95614
95615 static struct page *zero_page; /* used in certain error cases */
95616
95617 @@ -197,7 +197,7 @@ const char *ceph_pr_addr(const struct sockaddr_storage *ss)
95618 struct sockaddr_in *in4 = (struct sockaddr_in *) ss;
95619 struct sockaddr_in6 *in6 = (struct sockaddr_in6 *) ss;
95620
95621 - i = atomic_inc_return(&addr_str_seq) & ADDR_STR_COUNT_MASK;
95622 + i = atomic_inc_return_unchecked(&addr_str_seq) & ADDR_STR_COUNT_MASK;
95623 s = addr_str[i];
95624
95625 switch (ss->ss_family) {
95626 diff --git a/net/compat.c b/net/compat.c
95627 index f50161f..94fa415 100644
95628 --- a/net/compat.c
95629 +++ b/net/compat.c
95630 @@ -73,9 +73,9 @@ int get_compat_msghdr(struct msghdr *kmsg, struct compat_msghdr __user *umsg)
95631 return -EFAULT;
95632 if (kmsg->msg_namelen > sizeof(struct sockaddr_storage))
95633 kmsg->msg_namelen = sizeof(struct sockaddr_storage);
95634 - kmsg->msg_name = compat_ptr(tmp1);
95635 - kmsg->msg_iov = compat_ptr(tmp2);
95636 - kmsg->msg_control = compat_ptr(tmp3);
95637 + kmsg->msg_name = (void __force_kernel *)compat_ptr(tmp1);
95638 + kmsg->msg_iov = (void __force_kernel *)compat_ptr(tmp2);
95639 + kmsg->msg_control = (void __force_kernel *)compat_ptr(tmp3);
95640 return 0;
95641 }
95642
95643 @@ -87,7 +87,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
95644
95645 if (kern_msg->msg_namelen) {
95646 if (mode == VERIFY_READ) {
95647 - int err = move_addr_to_kernel(kern_msg->msg_name,
95648 + int err = move_addr_to_kernel((void __force_user *)kern_msg->msg_name,
95649 kern_msg->msg_namelen,
95650 kern_address);
95651 if (err < 0)
95652 @@ -99,7 +99,7 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
95653 kern_msg->msg_name = NULL;
95654
95655 tot_len = iov_from_user_compat_to_kern(kern_iov,
95656 - (struct compat_iovec __user *)kern_msg->msg_iov,
95657 + (struct compat_iovec __force_user *)kern_msg->msg_iov,
95658 kern_msg->msg_iovlen);
95659 if (tot_len >= 0)
95660 kern_msg->msg_iov = kern_iov;
95661 @@ -119,20 +119,20 @@ int verify_compat_iovec(struct msghdr *kern_msg, struct iovec *kern_iov,
95662
95663 #define CMSG_COMPAT_FIRSTHDR(msg) \
95664 (((msg)->msg_controllen) >= sizeof(struct compat_cmsghdr) ? \
95665 - (struct compat_cmsghdr __user *)((msg)->msg_control) : \
95666 + (struct compat_cmsghdr __force_user *)((msg)->msg_control) : \
95667 (struct compat_cmsghdr __user *)NULL)
95668
95669 #define CMSG_COMPAT_OK(ucmlen, ucmsg, mhdr) \
95670 ((ucmlen) >= sizeof(struct compat_cmsghdr) && \
95671 (ucmlen) <= (unsigned long) \
95672 ((mhdr)->msg_controllen - \
95673 - ((char *)(ucmsg) - (char *)(mhdr)->msg_control)))
95674 + ((char __force_kernel *)(ucmsg) - (char *)(mhdr)->msg_control)))
95675
95676 static inline struct compat_cmsghdr __user *cmsg_compat_nxthdr(struct msghdr *msg,
95677 struct compat_cmsghdr __user *cmsg, int cmsg_len)
95678 {
95679 char __user *ptr = (char __user *)cmsg + CMSG_COMPAT_ALIGN(cmsg_len);
95680 - if ((unsigned long)(ptr + 1 - (char __user *)msg->msg_control) >
95681 + if ((unsigned long)(ptr + 1 - (char __force_user *)msg->msg_control) >
95682 msg->msg_controllen)
95683 return NULL;
95684 return (struct compat_cmsghdr __user *)ptr;
95685 @@ -222,7 +222,7 @@ Efault:
95686
95687 int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *data)
95688 {
95689 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
95690 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
95691 struct compat_cmsghdr cmhdr;
95692 struct compat_timeval ctv;
95693 struct compat_timespec cts[3];
95694 @@ -278,7 +278,7 @@ int put_cmsg_compat(struct msghdr *kmsg, int level, int type, int len, void *dat
95695
95696 void scm_detach_fds_compat(struct msghdr *kmsg, struct scm_cookie *scm)
95697 {
95698 - struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __user *) kmsg->msg_control;
95699 + struct compat_cmsghdr __user *cm = (struct compat_cmsghdr __force_user *) kmsg->msg_control;
95700 int fdmax = (kmsg->msg_controllen - sizeof(struct compat_cmsghdr)) / sizeof(int);
95701 int fdnum = scm->fp->count;
95702 struct file **fp = scm->fp->fp;
95703 @@ -366,7 +366,7 @@ static int do_set_sock_timeout(struct socket *sock, int level,
95704 return -EFAULT;
95705 old_fs = get_fs();
95706 set_fs(KERNEL_DS);
95707 - err = sock_setsockopt(sock, level, optname, (char *)&ktime, sizeof(ktime));
95708 + err = sock_setsockopt(sock, level, optname, (char __force_user *)&ktime, sizeof(ktime));
95709 set_fs(old_fs);
95710
95711 return err;
95712 @@ -427,7 +427,7 @@ static int do_get_sock_timeout(struct socket *sock, int level, int optname,
95713 len = sizeof(ktime);
95714 old_fs = get_fs();
95715 set_fs(KERNEL_DS);
95716 - err = sock_getsockopt(sock, level, optname, (char *) &ktime, &len);
95717 + err = sock_getsockopt(sock, level, optname, (char __force_user *) &ktime, (int __force_user *)&len);
95718 set_fs(old_fs);
95719
95720 if (!err) {
95721 @@ -570,7 +570,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
95722 case MCAST_JOIN_GROUP:
95723 case MCAST_LEAVE_GROUP:
95724 {
95725 - struct compat_group_req __user *gr32 = (void *)optval;
95726 + struct compat_group_req __user *gr32 = (void __user *)optval;
95727 struct group_req __user *kgr =
95728 compat_alloc_user_space(sizeof(struct group_req));
95729 u32 interface;
95730 @@ -591,7 +591,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
95731 case MCAST_BLOCK_SOURCE:
95732 case MCAST_UNBLOCK_SOURCE:
95733 {
95734 - struct compat_group_source_req __user *gsr32 = (void *)optval;
95735 + struct compat_group_source_req __user *gsr32 = (void __user *)optval;
95736 struct group_source_req __user *kgsr = compat_alloc_user_space(
95737 sizeof(struct group_source_req));
95738 u32 interface;
95739 @@ -612,7 +612,7 @@ int compat_mc_setsockopt(struct sock *sock, int level, int optname,
95740 }
95741 case MCAST_MSFILTER:
95742 {
95743 - struct compat_group_filter __user *gf32 = (void *)optval;
95744 + struct compat_group_filter __user *gf32 = (void __user *)optval;
95745 struct group_filter __user *kgf;
95746 u32 interface, fmode, numsrc;
95747
95748 @@ -650,7 +650,7 @@ int compat_mc_getsockopt(struct sock *sock, int level, int optname,
95749 char __user *optval, int __user *optlen,
95750 int (*getsockopt)(struct sock *, int, int, char __user *, int __user *))
95751 {
95752 - struct compat_group_filter __user *gf32 = (void *)optval;
95753 + struct compat_group_filter __user *gf32 = (void __user *)optval;
95754 struct group_filter __user *kgf;
95755 int __user *koptlen;
95756 u32 interface, fmode, numsrc;
95757 @@ -803,7 +803,7 @@ asmlinkage long compat_sys_socketcall(int call, u32 __user *args)
95758
95759 if (call < SYS_SOCKET || call > SYS_SENDMMSG)
95760 return -EINVAL;
95761 - if (copy_from_user(a, args, nas[call]))
95762 + if (nas[call] > sizeof a || copy_from_user(a, args, nas[call]))
95763 return -EFAULT;
95764 a0 = a[0];
95765 a1 = a[1];
95766 diff --git a/net/core/datagram.c b/net/core/datagram.c
95767 index a16ed7b..eb44d17 100644
95768 --- a/net/core/datagram.c
95769 +++ b/net/core/datagram.c
95770 @@ -301,7 +301,7 @@ int skb_kill_datagram(struct sock *sk, struct sk_buff *skb, unsigned int flags)
95771 }
95772
95773 kfree_skb(skb);
95774 - atomic_inc(&sk->sk_drops);
95775 + atomic_inc_unchecked(&sk->sk_drops);
95776 sk_mem_reclaim_partial(sk);
95777
95778 return err;
95779 diff --git a/net/core/dev.c b/net/core/dev.c
95780 index 0ce469e..dfb53d2 100644
95781 --- a/net/core/dev.c
95782 +++ b/net/core/dev.c
95783 @@ -1684,14 +1684,14 @@ int dev_forward_skb(struct net_device *dev, struct sk_buff *skb)
95784 {
95785 if (skb_shinfo(skb)->tx_flags & SKBTX_DEV_ZEROCOPY) {
95786 if (skb_copy_ubufs(skb, GFP_ATOMIC)) {
95787 - atomic_long_inc(&dev->rx_dropped);
95788 + atomic_long_inc_unchecked(&dev->rx_dropped);
95789 kfree_skb(skb);
95790 return NET_RX_DROP;
95791 }
95792 }
95793
95794 if (unlikely(!is_skb_forwardable(dev, skb))) {
95795 - atomic_long_inc(&dev->rx_dropped);
95796 + atomic_long_inc_unchecked(&dev->rx_dropped);
95797 kfree_skb(skb);
95798 return NET_RX_DROP;
95799 }
95800 @@ -2434,7 +2434,7 @@ static int illegal_highdma(struct net_device *dev, struct sk_buff *skb)
95801
95802 struct dev_gso_cb {
95803 void (*destructor)(struct sk_buff *skb);
95804 -};
95805 +} __no_const;
95806
95807 #define DEV_GSO_CB(skb) ((struct dev_gso_cb *)(skb)->cb)
95808
95809 @@ -3222,7 +3222,7 @@ enqueue:
95810
95811 local_irq_restore(flags);
95812
95813 - atomic_long_inc(&skb->dev->rx_dropped);
95814 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
95815 kfree_skb(skb);
95816 return NET_RX_DROP;
95817 }
95818 @@ -3294,7 +3294,7 @@ int netif_rx_ni(struct sk_buff *skb)
95819 }
95820 EXPORT_SYMBOL(netif_rx_ni);
95821
95822 -static void net_tx_action(struct softirq_action *h)
95823 +static __latent_entropy void net_tx_action(void)
95824 {
95825 struct softnet_data *sd = &__get_cpu_var(softnet_data);
95826
95827 @@ -3628,7 +3628,7 @@ ncls:
95828 ret = pt_prev->func(skb, skb->dev, pt_prev, orig_dev);
95829 } else {
95830 drop:
95831 - atomic_long_inc(&skb->dev->rx_dropped);
95832 + atomic_long_inc_unchecked(&skb->dev->rx_dropped);
95833 kfree_skb(skb);
95834 /* Jamal, now you will not able to escape explaining
95835 * me how you were going to use this. :-)
95836 @@ -4288,7 +4288,7 @@ void netif_napi_del(struct napi_struct *napi)
95837 }
95838 EXPORT_SYMBOL(netif_napi_del);
95839
95840 -static void net_rx_action(struct softirq_action *h)
95841 +static __latent_entropy void net_rx_action(void)
95842 {
95843 struct softnet_data *sd = &__get_cpu_var(softnet_data);
95844 unsigned long time_limit = jiffies + 2;
95845 @@ -6177,7 +6177,7 @@ struct rtnl_link_stats64 *dev_get_stats(struct net_device *dev,
95846 } else {
95847 netdev_stats_to_stats64(storage, &dev->stats);
95848 }
95849 - storage->rx_dropped += atomic_long_read(&dev->rx_dropped);
95850 + storage->rx_dropped += atomic_long_read_unchecked(&dev->rx_dropped);
95851 return storage;
95852 }
95853 EXPORT_SYMBOL(dev_get_stats);
95854 diff --git a/net/core/dev_ioctl.c b/net/core/dev_ioctl.c
95855 index 5b7d0e1..cb960fc 100644
95856 --- a/net/core/dev_ioctl.c
95857 +++ b/net/core/dev_ioctl.c
95858 @@ -365,9 +365,13 @@ void dev_load(struct net *net, const char *name)
95859 if (no_module && capable(CAP_NET_ADMIN))
95860 no_module = request_module("netdev-%s", name);
95861 if (no_module && capable(CAP_SYS_MODULE)) {
95862 +#ifdef CONFIG_GRKERNSEC_MODHARDEN
95863 + ___request_module(true, "grsec_modharden_netdev", "%s", name);
95864 +#else
95865 if (!request_module("%s", name))
95866 pr_warn("Loading kernel module for a network device with CAP_SYS_MODULE (deprecated). Use CAP_NET_ADMIN and alias netdev-%s instead.\n",
95867 name);
95868 +#endif
95869 }
95870 }
95871 EXPORT_SYMBOL(dev_load);
95872 diff --git a/net/core/filter.c b/net/core/filter.c
95873 index ad30d62..c2757df 100644
95874 --- a/net/core/filter.c
95875 +++ b/net/core/filter.c
95876 @@ -679,7 +679,7 @@ int sk_unattached_filter_create(struct sk_filter **pfp,
95877 fp = kmalloc(sk_filter_size(fprog->len), GFP_KERNEL);
95878 if (!fp)
95879 return -ENOMEM;
95880 - memcpy(fp->insns, fprog->filter, fsize);
95881 + memcpy(fp->insns, (void __force_kernel *)fprog->filter, fsize);
95882
95883 atomic_set(&fp->refcnt, 1);
95884 fp->len = fprog->len;
95885 diff --git a/net/core/flow.c b/net/core/flow.c
95886 index dfa602c..3103d88 100644
95887 --- a/net/core/flow.c
95888 +++ b/net/core/flow.c
95889 @@ -61,7 +61,7 @@ struct flow_cache {
95890 struct timer_list rnd_timer;
95891 };
95892
95893 -atomic_t flow_cache_genid = ATOMIC_INIT(0);
95894 +atomic_unchecked_t flow_cache_genid = ATOMIC_INIT(0);
95895 EXPORT_SYMBOL(flow_cache_genid);
95896 static struct flow_cache flow_cache_global;
95897 static struct kmem_cache *flow_cachep __read_mostly;
95898 @@ -86,7 +86,7 @@ static void flow_cache_new_hashrnd(unsigned long arg)
95899
95900 static int flow_entry_valid(struct flow_cache_entry *fle)
95901 {
95902 - if (atomic_read(&flow_cache_genid) != fle->genid)
95903 + if (atomic_read_unchecked(&flow_cache_genid) != fle->genid)
95904 return 0;
95905 if (fle->object && !fle->object->ops->check(fle->object))
95906 return 0;
95907 @@ -258,7 +258,7 @@ flow_cache_lookup(struct net *net, const struct flowi *key, u16 family, u8 dir,
95908 hlist_add_head(&fle->u.hlist, &fcp->hash_table[hash]);
95909 fcp->hash_count++;
95910 }
95911 - } else if (likely(fle->genid == atomic_read(&flow_cache_genid))) {
95912 + } else if (likely(fle->genid == atomic_read_unchecked(&flow_cache_genid))) {
95913 flo = fle->object;
95914 if (!flo)
95915 goto ret_object;
95916 @@ -279,7 +279,7 @@ nocache:
95917 }
95918 flo = resolver(net, key, family, dir, flo, ctx);
95919 if (fle) {
95920 - fle->genid = atomic_read(&flow_cache_genid);
95921 + fle->genid = atomic_read_unchecked(&flow_cache_genid);
95922 if (!IS_ERR(flo))
95923 fle->object = flo;
95924 else
95925 diff --git a/net/core/iovec.c b/net/core/iovec.c
95926 index b618694..192bbba 100644
95927 --- a/net/core/iovec.c
95928 +++ b/net/core/iovec.c
95929 @@ -42,7 +42,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
95930 if (m->msg_namelen) {
95931 if (mode == VERIFY_READ) {
95932 void __user *namep;
95933 - namep = (void __user __force *) m->msg_name;
95934 + namep = (void __force_user *) m->msg_name;
95935 err = move_addr_to_kernel(namep, m->msg_namelen,
95936 address);
95937 if (err < 0)
95938 @@ -55,7 +55,7 @@ int verify_iovec(struct msghdr *m, struct iovec *iov, struct sockaddr_storage *a
95939 }
95940
95941 size = m->msg_iovlen * sizeof(struct iovec);
95942 - if (copy_from_user(iov, (void __user __force *) m->msg_iov, size))
95943 + if (copy_from_user(iov, (void __force_user *) m->msg_iov, size))
95944 return -EFAULT;
95945
95946 m->msg_iov = iov;
95947 diff --git a/net/core/neighbour.c b/net/core/neighbour.c
95948 index 932c6d7..7c7aa10 100644
95949 --- a/net/core/neighbour.c
95950 +++ b/net/core/neighbour.c
95951 @@ -2775,7 +2775,7 @@ static int proc_unres_qlen(struct ctl_table *ctl, int write,
95952 void __user *buffer, size_t *lenp, loff_t *ppos)
95953 {
95954 int size, ret;
95955 - struct ctl_table tmp = *ctl;
95956 + ctl_table_no_const tmp = *ctl;
95957
95958 tmp.extra1 = &zero;
95959 tmp.extra2 = &unres_qlen_max;
95960 diff --git a/net/core/net-procfs.c b/net/core/net-procfs.c
95961 index 2bf8329..7960607 100644
95962 --- a/net/core/net-procfs.c
95963 +++ b/net/core/net-procfs.c
95964 @@ -283,8 +283,13 @@ static int ptype_seq_show(struct seq_file *seq, void *v)
95965 else
95966 seq_printf(seq, "%04x", ntohs(pt->type));
95967
95968 +#ifdef CONFIG_GRKERNSEC_HIDESYM
95969 + seq_printf(seq, " %-8s %pf\n",
95970 + pt->dev ? pt->dev->name : "", NULL);
95971 +#else
95972 seq_printf(seq, " %-8s %pf\n",
95973 pt->dev ? pt->dev->name : "", pt->func);
95974 +#endif
95975 }
95976
95977 return 0;
95978 diff --git a/net/core/net-sysfs.c b/net/core/net-sysfs.c
95979 index f3edf96..3cd8b40 100644
95980 --- a/net/core/net-sysfs.c
95981 +++ b/net/core/net-sysfs.c
95982 @@ -1358,7 +1358,7 @@ void netdev_class_remove_file_ns(struct class_attribute *class_attr,
95983 }
95984 EXPORT_SYMBOL(netdev_class_remove_file_ns);
95985
95986 -int netdev_kobject_init(void)
95987 +int __init netdev_kobject_init(void)
95988 {
95989 kobj_ns_type_register(&net_ns_type_operations);
95990 return class_register(&net_class);
95991 diff --git a/net/core/net_namespace.c b/net/core/net_namespace.c
95992 index 81d3a9a..a0bd7a8 100644
95993 --- a/net/core/net_namespace.c
95994 +++ b/net/core/net_namespace.c
95995 @@ -443,7 +443,7 @@ static int __register_pernet_operations(struct list_head *list,
95996 int error;
95997 LIST_HEAD(net_exit_list);
95998
95999 - list_add_tail(&ops->list, list);
96000 + pax_list_add_tail((struct list_head *)&ops->list, list);
96001 if (ops->init || (ops->id && ops->size)) {
96002 for_each_net(net) {
96003 error = ops_init(ops, net);
96004 @@ -456,7 +456,7 @@ static int __register_pernet_operations(struct list_head *list,
96005
96006 out_undo:
96007 /* If I have an error cleanup all namespaces I initialized */
96008 - list_del(&ops->list);
96009 + pax_list_del((struct list_head *)&ops->list);
96010 ops_exit_list(ops, &net_exit_list);
96011 ops_free_list(ops, &net_exit_list);
96012 return error;
96013 @@ -467,7 +467,7 @@ static void __unregister_pernet_operations(struct pernet_operations *ops)
96014 struct net *net;
96015 LIST_HEAD(net_exit_list);
96016
96017 - list_del(&ops->list);
96018 + pax_list_del((struct list_head *)&ops->list);
96019 for_each_net(net)
96020 list_add_tail(&net->exit_list, &net_exit_list);
96021 ops_exit_list(ops, &net_exit_list);
96022 @@ -601,7 +601,7 @@ int register_pernet_device(struct pernet_operations *ops)
96023 mutex_lock(&net_mutex);
96024 error = register_pernet_operations(&pernet_list, ops);
96025 if (!error && (first_device == &pernet_list))
96026 - first_device = &ops->list;
96027 + first_device = (struct list_head *)&ops->list;
96028 mutex_unlock(&net_mutex);
96029 return error;
96030 }
96031 diff --git a/net/core/netpoll.c b/net/core/netpoll.c
96032 index 19fe9c7..b6bb620 100644
96033 --- a/net/core/netpoll.c
96034 +++ b/net/core/netpoll.c
96035 @@ -435,7 +435,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
96036 struct udphdr *udph;
96037 struct iphdr *iph;
96038 struct ethhdr *eth;
96039 - static atomic_t ip_ident;
96040 + static atomic_unchecked_t ip_ident;
96041 struct ipv6hdr *ip6h;
96042
96043 udp_len = len + sizeof(*udph);
96044 @@ -506,7 +506,7 @@ void netpoll_send_udp(struct netpoll *np, const char *msg, int len)
96045 put_unaligned(0x45, (unsigned char *)iph);
96046 iph->tos = 0;
96047 put_unaligned(htons(ip_len), &(iph->tot_len));
96048 - iph->id = htons(atomic_inc_return(&ip_ident));
96049 + iph->id = htons(atomic_inc_return_unchecked(&ip_ident));
96050 iph->frag_off = 0;
96051 iph->ttl = 64;
96052 iph->protocol = IPPROTO_UDP;
96053 diff --git a/net/core/rtnetlink.c b/net/core/rtnetlink.c
96054 index cf67144..12bf94c 100644
96055 --- a/net/core/rtnetlink.c
96056 +++ b/net/core/rtnetlink.c
96057 @@ -58,7 +58,7 @@ struct rtnl_link {
96058 rtnl_doit_func doit;
96059 rtnl_dumpit_func dumpit;
96060 rtnl_calcit_func calcit;
96061 -};
96062 +} __no_const;
96063
96064 static DEFINE_MUTEX(rtnl_mutex);
96065
96066 @@ -299,10 +299,13 @@ int __rtnl_link_register(struct rtnl_link_ops *ops)
96067 if (rtnl_link_ops_get(ops->kind))
96068 return -EEXIST;
96069
96070 - if (!ops->dellink)
96071 - ops->dellink = unregister_netdevice_queue;
96072 + if (!ops->dellink) {
96073 + pax_open_kernel();
96074 + *(void **)&ops->dellink = unregister_netdevice_queue;
96075 + pax_close_kernel();
96076 + }
96077
96078 - list_add_tail(&ops->list, &link_ops);
96079 + pax_list_add_tail((struct list_head *)&ops->list, &link_ops);
96080 return 0;
96081 }
96082 EXPORT_SYMBOL_GPL(__rtnl_link_register);
96083 @@ -349,7 +352,7 @@ void __rtnl_link_unregister(struct rtnl_link_ops *ops)
96084 for_each_net(net) {
96085 __rtnl_kill_links(net, ops);
96086 }
96087 - list_del(&ops->list);
96088 + pax_list_del((struct list_head *)&ops->list);
96089 }
96090 EXPORT_SYMBOL_GPL(__rtnl_link_unregister);
96091
96092 diff --git a/net/core/scm.c b/net/core/scm.c
96093 index b442e7e..6f5b5a2 100644
96094 --- a/net/core/scm.c
96095 +++ b/net/core/scm.c
96096 @@ -210,7 +210,7 @@ EXPORT_SYMBOL(__scm_send);
96097 int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
96098 {
96099 struct cmsghdr __user *cm
96100 - = (__force struct cmsghdr __user *)msg->msg_control;
96101 + = (struct cmsghdr __force_user *)msg->msg_control;
96102 struct cmsghdr cmhdr;
96103 int cmlen = CMSG_LEN(len);
96104 int err;
96105 @@ -233,7 +233,7 @@ int put_cmsg(struct msghdr * msg, int level, int type, int len, void *data)
96106 err = -EFAULT;
96107 if (copy_to_user(cm, &cmhdr, sizeof cmhdr))
96108 goto out;
96109 - if (copy_to_user(CMSG_DATA(cm), data, cmlen - sizeof(struct cmsghdr)))
96110 + if (copy_to_user((void __force_user *)CMSG_DATA((void __force_kernel *)cm), data, cmlen - sizeof(struct cmsghdr)))
96111 goto out;
96112 cmlen = CMSG_SPACE(len);
96113 if (msg->msg_controllen < cmlen)
96114 @@ -249,7 +249,7 @@ EXPORT_SYMBOL(put_cmsg);
96115 void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
96116 {
96117 struct cmsghdr __user *cm
96118 - = (__force struct cmsghdr __user*)msg->msg_control;
96119 + = (struct cmsghdr __force_user *)msg->msg_control;
96120
96121 int fdmax = 0;
96122 int fdnum = scm->fp->count;
96123 @@ -269,7 +269,7 @@ void scm_detach_fds(struct msghdr *msg, struct scm_cookie *scm)
96124 if (fdnum < fdmax)
96125 fdmax = fdnum;
96126
96127 - for (i=0, cmfptr=(__force int __user *)CMSG_DATA(cm); i<fdmax;
96128 + for (i=0, cmfptr=(int __force_user *)CMSG_DATA((void __force_kernel *)cm); i<fdmax;
96129 i++, cmfptr++)
96130 {
96131 struct socket *sock;
96132 diff --git a/net/core/skbuff.c b/net/core/skbuff.c
96133 index 0b5149c..24e9976 100644
96134 --- a/net/core/skbuff.c
96135 +++ b/net/core/skbuff.c
96136 @@ -2004,7 +2004,7 @@ EXPORT_SYMBOL(__skb_checksum);
96137 __wsum skb_checksum(const struct sk_buff *skb, int offset,
96138 int len, __wsum csum)
96139 {
96140 - const struct skb_checksum_ops ops = {
96141 + static const struct skb_checksum_ops ops = {
96142 .update = csum_partial_ext,
96143 .combine = csum_block_add_ext,
96144 };
96145 @@ -3117,13 +3117,15 @@ void __init skb_init(void)
96146 skbuff_head_cache = kmem_cache_create("skbuff_head_cache",
96147 sizeof(struct sk_buff),
96148 0,
96149 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
96150 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
96151 + SLAB_NO_SANITIZE,
96152 NULL);
96153 skbuff_fclone_cache = kmem_cache_create("skbuff_fclone_cache",
96154 (2*sizeof(struct sk_buff)) +
96155 sizeof(atomic_t),
96156 0,
96157 - SLAB_HWCACHE_ALIGN|SLAB_PANIC,
96158 + SLAB_HWCACHE_ALIGN|SLAB_PANIC|
96159 + SLAB_NO_SANITIZE,
96160 NULL);
96161 }
96162
96163 diff --git a/net/core/sock.c b/net/core/sock.c
96164 index 5393b4b..997c88b 100644
96165 --- a/net/core/sock.c
96166 +++ b/net/core/sock.c
96167 @@ -393,7 +393,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
96168 struct sk_buff_head *list = &sk->sk_receive_queue;
96169
96170 if (atomic_read(&sk->sk_rmem_alloc) >= sk->sk_rcvbuf) {
96171 - atomic_inc(&sk->sk_drops);
96172 + atomic_inc_unchecked(&sk->sk_drops);
96173 trace_sock_rcvqueue_full(sk, skb);
96174 return -ENOMEM;
96175 }
96176 @@ -403,7 +403,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
96177 return err;
96178
96179 if (!sk_rmem_schedule(sk, skb, skb->truesize)) {
96180 - atomic_inc(&sk->sk_drops);
96181 + atomic_inc_unchecked(&sk->sk_drops);
96182 return -ENOBUFS;
96183 }
96184
96185 @@ -423,7 +423,7 @@ int sock_queue_rcv_skb(struct sock *sk, struct sk_buff *skb)
96186 skb_dst_force(skb);
96187
96188 spin_lock_irqsave(&list->lock, flags);
96189 - skb->dropcount = atomic_read(&sk->sk_drops);
96190 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
96191 __skb_queue_tail(list, skb);
96192 spin_unlock_irqrestore(&list->lock, flags);
96193
96194 @@ -443,7 +443,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
96195 skb->dev = NULL;
96196
96197 if (sk_rcvqueues_full(sk, skb, sk->sk_rcvbuf)) {
96198 - atomic_inc(&sk->sk_drops);
96199 + atomic_inc_unchecked(&sk->sk_drops);
96200 goto discard_and_relse;
96201 }
96202 if (nested)
96203 @@ -461,7 +461,7 @@ int sk_receive_skb(struct sock *sk, struct sk_buff *skb, const int nested)
96204 mutex_release(&sk->sk_lock.dep_map, 1, _RET_IP_);
96205 } else if (sk_add_backlog(sk, skb, sk->sk_rcvbuf)) {
96206 bh_unlock_sock(sk);
96207 - atomic_inc(&sk->sk_drops);
96208 + atomic_inc_unchecked(&sk->sk_drops);
96209 goto discard_and_relse;
96210 }
96211
96212 @@ -950,12 +950,12 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
96213 struct timeval tm;
96214 } v;
96215
96216 - int lv = sizeof(int);
96217 - int len;
96218 + unsigned int lv = sizeof(int);
96219 + unsigned int len;
96220
96221 if (get_user(len, optlen))
96222 return -EFAULT;
96223 - if (len < 0)
96224 + if (len > INT_MAX)
96225 return -EINVAL;
96226
96227 memset(&v, 0, sizeof(v));
96228 @@ -1107,11 +1107,11 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
96229
96230 case SO_PEERNAME:
96231 {
96232 - char address[128];
96233 + char address[_K_SS_MAXSIZE];
96234
96235 if (sock->ops->getname(sock, (struct sockaddr *)address, &lv, 2))
96236 return -ENOTCONN;
96237 - if (lv < len)
96238 + if (lv < len || sizeof address < len)
96239 return -EINVAL;
96240 if (copy_to_user(optval, address, len))
96241 return -EFAULT;
96242 @@ -1188,7 +1188,7 @@ int sock_getsockopt(struct socket *sock, int level, int optname,
96243
96244 if (len > lv)
96245 len = lv;
96246 - if (copy_to_user(optval, &v, len))
96247 + if (len > sizeof(v) || copy_to_user(optval, &v, len))
96248 return -EFAULT;
96249 lenout:
96250 if (put_user(len, optlen))
96251 @@ -2351,7 +2351,7 @@ void sock_init_data(struct socket *sock, struct sock *sk)
96252 */
96253 smp_wmb();
96254 atomic_set(&sk->sk_refcnt, 1);
96255 - atomic_set(&sk->sk_drops, 0);
96256 + atomic_set_unchecked(&sk->sk_drops, 0);
96257 }
96258 EXPORT_SYMBOL(sock_init_data);
96259
96260 @@ -2476,6 +2476,7 @@ void sock_enable_timestamp(struct sock *sk, int flag)
96261 int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
96262 int level, int type)
96263 {
96264 + struct sock_extended_err ee;
96265 struct sock_exterr_skb *serr;
96266 struct sk_buff *skb, *skb2;
96267 int copied, err;
96268 @@ -2497,7 +2498,8 @@ int sock_recv_errqueue(struct sock *sk, struct msghdr *msg, int len,
96269 sock_recv_timestamp(msg, sk, skb);
96270
96271 serr = SKB_EXT_ERR(skb);
96272 - put_cmsg(msg, level, type, sizeof(serr->ee), &serr->ee);
96273 + ee = serr->ee;
96274 + put_cmsg(msg, level, type, sizeof ee, &ee);
96275
96276 msg->msg_flags |= MSG_ERRQUEUE;
96277 err = copied;
96278 diff --git a/net/core/sock_diag.c b/net/core/sock_diag.c
96279 index a0e9cf6..ef7f9ed 100644
96280 --- a/net/core/sock_diag.c
96281 +++ b/net/core/sock_diag.c
96282 @@ -9,26 +9,33 @@
96283 #include <linux/inet_diag.h>
96284 #include <linux/sock_diag.h>
96285
96286 -static const struct sock_diag_handler *sock_diag_handlers[AF_MAX];
96287 +static const struct sock_diag_handler *sock_diag_handlers[AF_MAX] __read_only;
96288 static int (*inet_rcv_compat)(struct sk_buff *skb, struct nlmsghdr *nlh);
96289 static DEFINE_MUTEX(sock_diag_table_mutex);
96290
96291 int sock_diag_check_cookie(void *sk, __u32 *cookie)
96292 {
96293 +#ifndef CONFIG_GRKERNSEC_HIDESYM
96294 if ((cookie[0] != INET_DIAG_NOCOOKIE ||
96295 cookie[1] != INET_DIAG_NOCOOKIE) &&
96296 ((u32)(unsigned long)sk != cookie[0] ||
96297 (u32)((((unsigned long)sk) >> 31) >> 1) != cookie[1]))
96298 return -ESTALE;
96299 else
96300 +#endif
96301 return 0;
96302 }
96303 EXPORT_SYMBOL_GPL(sock_diag_check_cookie);
96304
96305 void sock_diag_save_cookie(void *sk, __u32 *cookie)
96306 {
96307 +#ifdef CONFIG_GRKERNSEC_HIDESYM
96308 + cookie[0] = 0;
96309 + cookie[1] = 0;
96310 +#else
96311 cookie[0] = (u32)(unsigned long)sk;
96312 cookie[1] = (u32)(((unsigned long)sk >> 31) >> 1);
96313 +#endif
96314 }
96315 EXPORT_SYMBOL_GPL(sock_diag_save_cookie);
96316
96317 @@ -113,8 +120,11 @@ int sock_diag_register(const struct sock_diag_handler *hndl)
96318 mutex_lock(&sock_diag_table_mutex);
96319 if (sock_diag_handlers[hndl->family])
96320 err = -EBUSY;
96321 - else
96322 + else {
96323 + pax_open_kernel();
96324 sock_diag_handlers[hndl->family] = hndl;
96325 + pax_close_kernel();
96326 + }
96327 mutex_unlock(&sock_diag_table_mutex);
96328
96329 return err;
96330 @@ -130,7 +140,9 @@ void sock_diag_unregister(const struct sock_diag_handler *hnld)
96331
96332 mutex_lock(&sock_diag_table_mutex);
96333 BUG_ON(sock_diag_handlers[family] != hnld);
96334 + pax_open_kernel();
96335 sock_diag_handlers[family] = NULL;
96336 + pax_close_kernel();
96337 mutex_unlock(&sock_diag_table_mutex);
96338 }
96339 EXPORT_SYMBOL_GPL(sock_diag_unregister);
96340 diff --git a/net/core/sysctl_net_core.c b/net/core/sysctl_net_core.c
96341 index cca4441..5e616de 100644
96342 --- a/net/core/sysctl_net_core.c
96343 +++ b/net/core/sysctl_net_core.c
96344 @@ -32,7 +32,7 @@ static int rps_sock_flow_sysctl(struct ctl_table *table, int write,
96345 {
96346 unsigned int orig_size, size;
96347 int ret, i;
96348 - struct ctl_table tmp = {
96349 + ctl_table_no_const tmp = {
96350 .data = &size,
96351 .maxlen = sizeof(size),
96352 .mode = table->mode
96353 @@ -199,7 +199,7 @@ static int set_default_qdisc(struct ctl_table *table, int write,
96354 void __user *buffer, size_t *lenp, loff_t *ppos)
96355 {
96356 char id[IFNAMSIZ];
96357 - struct ctl_table tbl = {
96358 + ctl_table_no_const tbl = {
96359 .data = id,
96360 .maxlen = IFNAMSIZ,
96361 };
96362 @@ -378,13 +378,12 @@ static struct ctl_table netns_core_table[] = {
96363
96364 static __net_init int sysctl_core_net_init(struct net *net)
96365 {
96366 - struct ctl_table *tbl;
96367 + ctl_table_no_const *tbl = NULL;
96368
96369 net->core.sysctl_somaxconn = SOMAXCONN;
96370
96371 - tbl = netns_core_table;
96372 if (!net_eq(net, &init_net)) {
96373 - tbl = kmemdup(tbl, sizeof(netns_core_table), GFP_KERNEL);
96374 + tbl = kmemdup(netns_core_table, sizeof(netns_core_table), GFP_KERNEL);
96375 if (tbl == NULL)
96376 goto err_dup;
96377
96378 @@ -394,17 +393,16 @@ static __net_init int sysctl_core_net_init(struct net *net)
96379 if (net->user_ns != &init_user_ns) {
96380 tbl[0].procname = NULL;
96381 }
96382 - }
96383 -
96384 - net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
96385 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", tbl);
96386 + } else
96387 + net->core.sysctl_hdr = register_net_sysctl(net, "net/core", netns_core_table);
96388 if (net->core.sysctl_hdr == NULL)
96389 goto err_reg;
96390
96391 return 0;
96392
96393 err_reg:
96394 - if (tbl != netns_core_table)
96395 - kfree(tbl);
96396 + kfree(tbl);
96397 err_dup:
96398 return -ENOMEM;
96399 }
96400 @@ -419,7 +417,7 @@ static __net_exit void sysctl_core_net_exit(struct net *net)
96401 kfree(tbl);
96402 }
96403
96404 -static __net_initdata struct pernet_operations sysctl_core_ops = {
96405 +static __net_initconst struct pernet_operations sysctl_core_ops = {
96406 .init = sysctl_core_net_init,
96407 .exit = sysctl_core_net_exit,
96408 };
96409 diff --git a/net/decnet/af_decnet.c b/net/decnet/af_decnet.c
96410 index dd4d506..fb2fb87 100644
96411 --- a/net/decnet/af_decnet.c
96412 +++ b/net/decnet/af_decnet.c
96413 @@ -465,6 +465,7 @@ static struct proto dn_proto = {
96414 .sysctl_rmem = sysctl_decnet_rmem,
96415 .max_header = DN_MAX_NSP_DATA_HEADER + 64,
96416 .obj_size = sizeof(struct dn_sock),
96417 + .slab_flags = SLAB_USERCOPY,
96418 };
96419
96420 static struct sock *dn_alloc_sock(struct net *net, struct socket *sock, gfp_t gfp)
96421 diff --git a/net/decnet/dn_dev.c b/net/decnet/dn_dev.c
96422 index dd0dfb2..fdbc764 100644
96423 --- a/net/decnet/dn_dev.c
96424 +++ b/net/decnet/dn_dev.c
96425 @@ -200,7 +200,7 @@ static struct dn_dev_sysctl_table {
96426 .extra1 = &min_t3,
96427 .extra2 = &max_t3
96428 },
96429 - {0}
96430 + { }
96431 },
96432 };
96433
96434 diff --git a/net/decnet/sysctl_net_decnet.c b/net/decnet/sysctl_net_decnet.c
96435 index 5325b54..a0d4d69 100644
96436 --- a/net/decnet/sysctl_net_decnet.c
96437 +++ b/net/decnet/sysctl_net_decnet.c
96438 @@ -174,7 +174,7 @@ static int dn_node_address_handler(struct ctl_table *table, int write,
96439
96440 if (len > *lenp) len = *lenp;
96441
96442 - if (copy_to_user(buffer, addr, len))
96443 + if (len > sizeof addr || copy_to_user(buffer, addr, len))
96444 return -EFAULT;
96445
96446 *lenp = len;
96447 @@ -237,7 +237,7 @@ static int dn_def_dev_handler(struct ctl_table *table, int write,
96448
96449 if (len > *lenp) len = *lenp;
96450
96451 - if (copy_to_user(buffer, devname, len))
96452 + if (len > sizeof devname || copy_to_user(buffer, devname, len))
96453 return -EFAULT;
96454
96455 *lenp = len;
96456 diff --git a/net/ieee802154/dgram.c b/net/ieee802154/dgram.c
96457 index 1865fdf..581a595 100644
96458 --- a/net/ieee802154/dgram.c
96459 +++ b/net/ieee802154/dgram.c
96460 @@ -315,8 +315,9 @@ static int dgram_recvmsg(struct kiocb *iocb, struct sock *sk,
96461 if (saddr) {
96462 saddr->family = AF_IEEE802154;
96463 saddr->addr = mac_cb(skb)->sa;
96464 + }
96465 + if (addr_len)
96466 *addr_len = sizeof(*saddr);
96467 - }
96468
96469 if (flags & MSG_TRUNC)
96470 copied = skb->len;
96471 diff --git a/net/ipv4/af_inet.c b/net/ipv4/af_inet.c
96472 index 70011e0..454ca6a 100644
96473 --- a/net/ipv4/af_inet.c
96474 +++ b/net/ipv4/af_inet.c
96475 @@ -1683,13 +1683,9 @@ static int __init inet_init(void)
96476
96477 BUILD_BUG_ON(sizeof(struct inet_skb_parm) > FIELD_SIZEOF(struct sk_buff, cb));
96478
96479 - sysctl_local_reserved_ports = kzalloc(65536 / 8, GFP_KERNEL);
96480 - if (!sysctl_local_reserved_ports)
96481 - goto out;
96482 -
96483 rc = proto_register(&tcp_prot, 1);
96484 if (rc)
96485 - goto out_free_reserved_ports;
96486 + goto out;
96487
96488 rc = proto_register(&udp_prot, 1);
96489 if (rc)
96490 @@ -1796,8 +1792,6 @@ out_unregister_udp_proto:
96491 proto_unregister(&udp_prot);
96492 out_unregister_tcp_proto:
96493 proto_unregister(&tcp_prot);
96494 -out_free_reserved_ports:
96495 - kfree(sysctl_local_reserved_ports);
96496 goto out;
96497 }
96498
96499 diff --git a/net/ipv4/devinet.c b/net/ipv4/devinet.c
96500 index a1b5bcb..62ec5c6 100644
96501 --- a/net/ipv4/devinet.c
96502 +++ b/net/ipv4/devinet.c
96503 @@ -1533,7 +1533,7 @@ static int inet_dump_ifaddr(struct sk_buff *skb, struct netlink_callback *cb)
96504 idx = 0;
96505 head = &net->dev_index_head[h];
96506 rcu_read_lock();
96507 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
96508 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
96509 net->dev_base_seq;
96510 hlist_for_each_entry_rcu(dev, head, index_hlist) {
96511 if (idx < s_idx)
96512 @@ -1844,7 +1844,7 @@ static int inet_netconf_dump_devconf(struct sk_buff *skb,
96513 idx = 0;
96514 head = &net->dev_index_head[h];
96515 rcu_read_lock();
96516 - cb->seq = atomic_read(&net->ipv4.dev_addr_genid) ^
96517 + cb->seq = atomic_read_unchecked(&net->ipv4.dev_addr_genid) ^
96518 net->dev_base_seq;
96519 hlist_for_each_entry_rcu(dev, head, index_hlist) {
96520 if (idx < s_idx)
96521 @@ -2069,7 +2069,7 @@ static int ipv4_doint_and_flush(struct ctl_table *ctl, int write,
96522 #define DEVINET_SYSCTL_FLUSHING_ENTRY(attr, name) \
96523 DEVINET_SYSCTL_COMPLEX_ENTRY(attr, name, ipv4_doint_and_flush)
96524
96525 -static struct devinet_sysctl_table {
96526 +static const struct devinet_sysctl_table {
96527 struct ctl_table_header *sysctl_header;
96528 struct ctl_table devinet_vars[__IPV4_DEVCONF_MAX];
96529 } devinet_sysctl = {
96530 @@ -2191,7 +2191,7 @@ static __net_init int devinet_init_net(struct net *net)
96531 int err;
96532 struct ipv4_devconf *all, *dflt;
96533 #ifdef CONFIG_SYSCTL
96534 - struct ctl_table *tbl = ctl_forward_entry;
96535 + ctl_table_no_const *tbl = NULL;
96536 struct ctl_table_header *forw_hdr;
96537 #endif
96538
96539 @@ -2209,7 +2209,7 @@ static __net_init int devinet_init_net(struct net *net)
96540 goto err_alloc_dflt;
96541
96542 #ifdef CONFIG_SYSCTL
96543 - tbl = kmemdup(tbl, sizeof(ctl_forward_entry), GFP_KERNEL);
96544 + tbl = kmemdup(ctl_forward_entry, sizeof(ctl_forward_entry), GFP_KERNEL);
96545 if (tbl == NULL)
96546 goto err_alloc_ctl;
96547
96548 @@ -2229,7 +2229,10 @@ static __net_init int devinet_init_net(struct net *net)
96549 goto err_reg_dflt;
96550
96551 err = -ENOMEM;
96552 - forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
96553 + if (!net_eq(net, &init_net))
96554 + forw_hdr = register_net_sysctl(net, "net/ipv4", tbl);
96555 + else
96556 + forw_hdr = register_net_sysctl(net, "net/ipv4", ctl_forward_entry);
96557 if (forw_hdr == NULL)
96558 goto err_reg_ctl;
96559 net->ipv4.forw_hdr = forw_hdr;
96560 @@ -2245,8 +2248,7 @@ err_reg_ctl:
96561 err_reg_dflt:
96562 __devinet_sysctl_unregister(all);
96563 err_reg_all:
96564 - if (tbl != ctl_forward_entry)
96565 - kfree(tbl);
96566 + kfree(tbl);
96567 err_alloc_ctl:
96568 #endif
96569 if (dflt != &ipv4_devconf_dflt)
96570 diff --git a/net/ipv4/fib_frontend.c b/net/ipv4/fib_frontend.c
96571 index c7539e2..b455e51 100644
96572 --- a/net/ipv4/fib_frontend.c
96573 +++ b/net/ipv4/fib_frontend.c
96574 @@ -1015,12 +1015,12 @@ static int fib_inetaddr_event(struct notifier_block *this, unsigned long event,
96575 #ifdef CONFIG_IP_ROUTE_MULTIPATH
96576 fib_sync_up(dev);
96577 #endif
96578 - atomic_inc(&net->ipv4.dev_addr_genid);
96579 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
96580 rt_cache_flush(dev_net(dev));
96581 break;
96582 case NETDEV_DOWN:
96583 fib_del_ifaddr(ifa, NULL);
96584 - atomic_inc(&net->ipv4.dev_addr_genid);
96585 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
96586 if (ifa->ifa_dev->ifa_list == NULL) {
96587 /* Last address was deleted from this interface.
96588 * Disable IP.
96589 @@ -1058,7 +1058,7 @@ static int fib_netdev_event(struct notifier_block *this, unsigned long event, vo
96590 #ifdef CONFIG_IP_ROUTE_MULTIPATH
96591 fib_sync_up(dev);
96592 #endif
96593 - atomic_inc(&net->ipv4.dev_addr_genid);
96594 + atomic_inc_unchecked(&net->ipv4.dev_addr_genid);
96595 rt_cache_flush(net);
96596 break;
96597 case NETDEV_DOWN:
96598 diff --git a/net/ipv4/fib_semantics.c b/net/ipv4/fib_semantics.c
96599 index e63f47a..e5c531d 100644
96600 --- a/net/ipv4/fib_semantics.c
96601 +++ b/net/ipv4/fib_semantics.c
96602 @@ -766,7 +766,7 @@ __be32 fib_info_update_nh_saddr(struct net *net, struct fib_nh *nh)
96603 nh->nh_saddr = inet_select_addr(nh->nh_dev,
96604 nh->nh_gw,
96605 nh->nh_parent->fib_scope);
96606 - nh->nh_saddr_genid = atomic_read(&net->ipv4.dev_addr_genid);
96607 + nh->nh_saddr_genid = atomic_read_unchecked(&net->ipv4.dev_addr_genid);
96608
96609 return nh->nh_saddr;
96610 }
96611 diff --git a/net/ipv4/inet_connection_sock.c b/net/ipv4/inet_connection_sock.c
96612 index fc0e649..febfa65 100644
96613 --- a/net/ipv4/inet_connection_sock.c
96614 +++ b/net/ipv4/inet_connection_sock.c
96615 @@ -29,7 +29,7 @@ const char inet_csk_timer_bug_msg[] = "inet_csk BUG: unknown timer value\n";
96616 EXPORT_SYMBOL(inet_csk_timer_bug_msg);
96617 #endif
96618
96619 -unsigned long *sysctl_local_reserved_ports;
96620 +unsigned long sysctl_local_reserved_ports[65536 / 8 / sizeof(unsigned long)];
96621 EXPORT_SYMBOL(sysctl_local_reserved_ports);
96622
96623 void inet_get_local_port_range(struct net *net, int *low, int *high)
96624 diff --git a/net/ipv4/inet_hashtables.c b/net/ipv4/inet_hashtables.c
96625 index 8b9cf27..0d8d592 100644
96626 --- a/net/ipv4/inet_hashtables.c
96627 +++ b/net/ipv4/inet_hashtables.c
96628 @@ -18,6 +18,7 @@
96629 #include <linux/sched.h>
96630 #include <linux/slab.h>
96631 #include <linux/wait.h>
96632 +#include <linux/security.h>
96633
96634 #include <net/inet_connection_sock.h>
96635 #include <net/inet_hashtables.h>
96636 @@ -49,6 +50,8 @@ static unsigned int inet_sk_ehashfn(const struct sock *sk)
96637 return inet_ehashfn(net, laddr, lport, faddr, fport);
96638 }
96639
96640 +extern void gr_update_task_in_ip_table(struct task_struct *task, const struct inet_sock *inet);
96641 +
96642 /*
96643 * Allocate and initialize a new local port bind bucket.
96644 * The bindhash mutex for snum's hash chain must be held here.
96645 @@ -554,6 +557,8 @@ ok:
96646 twrefcnt += inet_twsk_bind_unhash(tw, hinfo);
96647 spin_unlock(&head->lock);
96648
96649 + gr_update_task_in_ip_table(current, inet_sk(sk));
96650 +
96651 if (tw) {
96652 inet_twsk_deschedule(tw, death_row);
96653 while (twrefcnt) {
96654 diff --git a/net/ipv4/inetpeer.c b/net/ipv4/inetpeer.c
96655 index 33d5537..da337a4 100644
96656 --- a/net/ipv4/inetpeer.c
96657 +++ b/net/ipv4/inetpeer.c
96658 @@ -503,8 +503,8 @@ relookup:
96659 if (p) {
96660 p->daddr = *daddr;
96661 atomic_set(&p->refcnt, 1);
96662 - atomic_set(&p->rid, 0);
96663 - atomic_set(&p->ip_id_count,
96664 + atomic_set_unchecked(&p->rid, 0);
96665 + atomic_set_unchecked(&p->ip_id_count,
96666 (daddr->family == AF_INET) ?
96667 secure_ip_id(daddr->addr.a4) :
96668 secure_ipv6_id(daddr->addr.a6));
96669 diff --git a/net/ipv4/ip_fragment.c b/net/ipv4/ip_fragment.c
96670 index 2481993..2d9a7a7 100644
96671 --- a/net/ipv4/ip_fragment.c
96672 +++ b/net/ipv4/ip_fragment.c
96673 @@ -283,7 +283,7 @@ static inline int ip_frag_too_far(struct ipq *qp)
96674 return 0;
96675
96676 start = qp->rid;
96677 - end = atomic_inc_return(&peer->rid);
96678 + end = atomic_inc_return_unchecked(&peer->rid);
96679 qp->rid = end;
96680
96681 rc = qp->q.fragments && (end - start) > max;
96682 @@ -760,12 +760,11 @@ static struct ctl_table ip4_frags_ctl_table[] = {
96683
96684 static int __net_init ip4_frags_ns_ctl_register(struct net *net)
96685 {
96686 - struct ctl_table *table;
96687 + ctl_table_no_const *table = NULL;
96688 struct ctl_table_header *hdr;
96689
96690 - table = ip4_frags_ns_ctl_table;
96691 if (!net_eq(net, &init_net)) {
96692 - table = kmemdup(table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
96693 + table = kmemdup(ip4_frags_ns_ctl_table, sizeof(ip4_frags_ns_ctl_table), GFP_KERNEL);
96694 if (table == NULL)
96695 goto err_alloc;
96696
96697 @@ -776,9 +775,10 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
96698 /* Don't export sysctls to unprivileged users */
96699 if (net->user_ns != &init_user_ns)
96700 table[0].procname = NULL;
96701 - }
96702 + hdr = register_net_sysctl(net, "net/ipv4", table);
96703 + } else
96704 + hdr = register_net_sysctl(net, "net/ipv4", ip4_frags_ns_ctl_table);
96705
96706 - hdr = register_net_sysctl(net, "net/ipv4", table);
96707 if (hdr == NULL)
96708 goto err_reg;
96709
96710 @@ -786,8 +786,7 @@ static int __net_init ip4_frags_ns_ctl_register(struct net *net)
96711 return 0;
96712
96713 err_reg:
96714 - if (!net_eq(net, &init_net))
96715 - kfree(table);
96716 + kfree(table);
96717 err_alloc:
96718 return -ENOMEM;
96719 }
96720 diff --git a/net/ipv4/ip_gre.c b/net/ipv4/ip_gre.c
96721 index d306360..1c1a1f1 100644
96722 --- a/net/ipv4/ip_gre.c
96723 +++ b/net/ipv4/ip_gre.c
96724 @@ -115,7 +115,7 @@ static bool log_ecn_error = true;
96725 module_param(log_ecn_error, bool, 0644);
96726 MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
96727
96728 -static struct rtnl_link_ops ipgre_link_ops __read_mostly;
96729 +static struct rtnl_link_ops ipgre_link_ops;
96730 static int ipgre_tunnel_init(struct net_device *dev);
96731
96732 static int ipgre_net_id __read_mostly;
96733 @@ -732,7 +732,7 @@ static const struct nla_policy ipgre_policy[IFLA_GRE_MAX + 1] = {
96734 [IFLA_GRE_PMTUDISC] = { .type = NLA_U8 },
96735 };
96736
96737 -static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
96738 +static struct rtnl_link_ops ipgre_link_ops = {
96739 .kind = "gre",
96740 .maxtype = IFLA_GRE_MAX,
96741 .policy = ipgre_policy,
96742 @@ -746,7 +746,7 @@ static struct rtnl_link_ops ipgre_link_ops __read_mostly = {
96743 .fill_info = ipgre_fill_info,
96744 };
96745
96746 -static struct rtnl_link_ops ipgre_tap_ops __read_mostly = {
96747 +static struct rtnl_link_ops ipgre_tap_ops = {
96748 .kind = "gretap",
96749 .maxtype = IFLA_GRE_MAX,
96750 .policy = ipgre_policy,
96751 diff --git a/net/ipv4/ip_sockglue.c b/net/ipv4/ip_sockglue.c
96752 index ddf32a6..3fdeea9 100644
96753 --- a/net/ipv4/ip_sockglue.c
96754 +++ b/net/ipv4/ip_sockglue.c
96755 @@ -1172,7 +1172,8 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
96756 len = min_t(unsigned int, len, opt->optlen);
96757 if (put_user(len, optlen))
96758 return -EFAULT;
96759 - if (copy_to_user(optval, opt->__data, len))
96760 + if ((len > (sizeof(optbuf) - sizeof(struct ip_options))) ||
96761 + copy_to_user(optval, opt->__data, len))
96762 return -EFAULT;
96763 return 0;
96764 }
96765 @@ -1303,7 +1304,7 @@ static int do_ip_getsockopt(struct sock *sk, int level, int optname,
96766 if (sk->sk_type != SOCK_STREAM)
96767 return -ENOPROTOOPT;
96768
96769 - msg.msg_control = optval;
96770 + msg.msg_control = (void __force_kernel *)optval;
96771 msg.msg_controllen = len;
96772 msg.msg_flags = flags;
96773
96774 diff --git a/net/ipv4/ip_vti.c b/net/ipv4/ip_vti.c
96775 index 52b802a..b725179 100644
96776 --- a/net/ipv4/ip_vti.c
96777 +++ b/net/ipv4/ip_vti.c
96778 @@ -44,7 +44,7 @@
96779 #include <net/net_namespace.h>
96780 #include <net/netns/generic.h>
96781
96782 -static struct rtnl_link_ops vti_link_ops __read_mostly;
96783 +static struct rtnl_link_ops vti_link_ops;
96784
96785 static int vti_net_id __read_mostly;
96786 static int vti_tunnel_init(struct net_device *dev);
96787 @@ -360,7 +360,7 @@ static const struct nla_policy vti_policy[IFLA_VTI_MAX + 1] = {
96788 [IFLA_VTI_REMOTE] = { .len = FIELD_SIZEOF(struct iphdr, daddr) },
96789 };
96790
96791 -static struct rtnl_link_ops vti_link_ops __read_mostly = {
96792 +static struct rtnl_link_ops vti_link_ops = {
96793 .kind = "vti",
96794 .maxtype = IFLA_VTI_MAX,
96795 .policy = vti_policy,
96796 diff --git a/net/ipv4/ipconfig.c b/net/ipv4/ipconfig.c
96797 index efa1138..20dbba0 100644
96798 --- a/net/ipv4/ipconfig.c
96799 +++ b/net/ipv4/ipconfig.c
96800 @@ -334,7 +334,7 @@ static int __init ic_devinet_ioctl(unsigned int cmd, struct ifreq *arg)
96801
96802 mm_segment_t oldfs = get_fs();
96803 set_fs(get_ds());
96804 - res = devinet_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
96805 + res = devinet_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
96806 set_fs(oldfs);
96807 return res;
96808 }
96809 @@ -345,7 +345,7 @@ static int __init ic_dev_ioctl(unsigned int cmd, struct ifreq *arg)
96810
96811 mm_segment_t oldfs = get_fs();
96812 set_fs(get_ds());
96813 - res = dev_ioctl(&init_net, cmd, (struct ifreq __user *) arg);
96814 + res = dev_ioctl(&init_net, cmd, (struct ifreq __force_user *) arg);
96815 set_fs(oldfs);
96816 return res;
96817 }
96818 @@ -356,7 +356,7 @@ static int __init ic_route_ioctl(unsigned int cmd, struct rtentry *arg)
96819
96820 mm_segment_t oldfs = get_fs();
96821 set_fs(get_ds());
96822 - res = ip_rt_ioctl(&init_net, cmd, (void __user *) arg);
96823 + res = ip_rt_ioctl(&init_net, cmd, (void __force_user *) arg);
96824 set_fs(oldfs);
96825 return res;
96826 }
96827 diff --git a/net/ipv4/ipip.c b/net/ipv4/ipip.c
96828 index fe3e9f7..4956990 100644
96829 --- a/net/ipv4/ipip.c
96830 +++ b/net/ipv4/ipip.c
96831 @@ -124,7 +124,7 @@ MODULE_PARM_DESC(log_ecn_error, "Log packets received with corrupted ECN");
96832 static int ipip_net_id __read_mostly;
96833
96834 static int ipip_tunnel_init(struct net_device *dev);
96835 -static struct rtnl_link_ops ipip_link_ops __read_mostly;
96836 +static struct rtnl_link_ops ipip_link_ops;
96837
96838 static int ipip_err(struct sk_buff *skb, u32 info)
96839 {
96840 @@ -409,7 +409,7 @@ static const struct nla_policy ipip_policy[IFLA_IPTUN_MAX + 1] = {
96841 [IFLA_IPTUN_PMTUDISC] = { .type = NLA_U8 },
96842 };
96843
96844 -static struct rtnl_link_ops ipip_link_ops __read_mostly = {
96845 +static struct rtnl_link_ops ipip_link_ops = {
96846 .kind = "ipip",
96847 .maxtype = IFLA_IPTUN_MAX,
96848 .policy = ipip_policy,
96849 diff --git a/net/ipv4/netfilter/arp_tables.c b/net/ipv4/netfilter/arp_tables.c
96850 index 59da7cd..e318de1 100644
96851 --- a/net/ipv4/netfilter/arp_tables.c
96852 +++ b/net/ipv4/netfilter/arp_tables.c
96853 @@ -885,14 +885,14 @@ static int compat_table_info(const struct xt_table_info *info,
96854 #endif
96855
96856 static int get_info(struct net *net, void __user *user,
96857 - const int *len, int compat)
96858 + int len, int compat)
96859 {
96860 char name[XT_TABLE_MAXNAMELEN];
96861 struct xt_table *t;
96862 int ret;
96863
96864 - if (*len != sizeof(struct arpt_getinfo)) {
96865 - duprintf("length %u != %Zu\n", *len,
96866 + if (len != sizeof(struct arpt_getinfo)) {
96867 + duprintf("length %u != %Zu\n", len,
96868 sizeof(struct arpt_getinfo));
96869 return -EINVAL;
96870 }
96871 @@ -929,7 +929,7 @@ static int get_info(struct net *net, void __user *user,
96872 info.size = private->size;
96873 strcpy(info.name, name);
96874
96875 - if (copy_to_user(user, &info, *len) != 0)
96876 + if (copy_to_user(user, &info, len) != 0)
96877 ret = -EFAULT;
96878 else
96879 ret = 0;
96880 @@ -1688,7 +1688,7 @@ static int compat_do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user,
96881
96882 switch (cmd) {
96883 case ARPT_SO_GET_INFO:
96884 - ret = get_info(sock_net(sk), user, len, 1);
96885 + ret = get_info(sock_net(sk), user, *len, 1);
96886 break;
96887 case ARPT_SO_GET_ENTRIES:
96888 ret = compat_get_entries(sock_net(sk), user, len);
96889 @@ -1733,7 +1733,7 @@ static int do_arpt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len
96890
96891 switch (cmd) {
96892 case ARPT_SO_GET_INFO:
96893 - ret = get_info(sock_net(sk), user, len, 0);
96894 + ret = get_info(sock_net(sk), user, *len, 0);
96895 break;
96896
96897 case ARPT_SO_GET_ENTRIES:
96898 diff --git a/net/ipv4/netfilter/ip_tables.c b/net/ipv4/netfilter/ip_tables.c
96899 index 718dfbd..cef4152 100644
96900 --- a/net/ipv4/netfilter/ip_tables.c
96901 +++ b/net/ipv4/netfilter/ip_tables.c
96902 @@ -1073,14 +1073,14 @@ static int compat_table_info(const struct xt_table_info *info,
96903 #endif
96904
96905 static int get_info(struct net *net, void __user *user,
96906 - const int *len, int compat)
96907 + int len, int compat)
96908 {
96909 char name[XT_TABLE_MAXNAMELEN];
96910 struct xt_table *t;
96911 int ret;
96912
96913 - if (*len != sizeof(struct ipt_getinfo)) {
96914 - duprintf("length %u != %zu\n", *len,
96915 + if (len != sizeof(struct ipt_getinfo)) {
96916 + duprintf("length %u != %zu\n", len,
96917 sizeof(struct ipt_getinfo));
96918 return -EINVAL;
96919 }
96920 @@ -1117,7 +1117,7 @@ static int get_info(struct net *net, void __user *user,
96921 info.size = private->size;
96922 strcpy(info.name, name);
96923
96924 - if (copy_to_user(user, &info, *len) != 0)
96925 + if (copy_to_user(user, &info, len) != 0)
96926 ret = -EFAULT;
96927 else
96928 ret = 0;
96929 @@ -1971,7 +1971,7 @@ compat_do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
96930
96931 switch (cmd) {
96932 case IPT_SO_GET_INFO:
96933 - ret = get_info(sock_net(sk), user, len, 1);
96934 + ret = get_info(sock_net(sk), user, *len, 1);
96935 break;
96936 case IPT_SO_GET_ENTRIES:
96937 ret = compat_get_entries(sock_net(sk), user, len);
96938 @@ -2018,7 +2018,7 @@ do_ipt_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
96939
96940 switch (cmd) {
96941 case IPT_SO_GET_INFO:
96942 - ret = get_info(sock_net(sk), user, len, 0);
96943 + ret = get_info(sock_net(sk), user, *len, 0);
96944 break;
96945
96946 case IPT_SO_GET_ENTRIES:
96947 diff --git a/net/ipv4/ping.c b/net/ipv4/ping.c
96948 index 242e7f4..a084e95 100644
96949 --- a/net/ipv4/ping.c
96950 +++ b/net/ipv4/ping.c
96951 @@ -55,7 +55,7 @@
96952
96953
96954 struct ping_table ping_table;
96955 -struct pingv6_ops pingv6_ops;
96956 +struct pingv6_ops *pingv6_ops;
96957 EXPORT_SYMBOL_GPL(pingv6_ops);
96958
96959 static u16 ping_port_rover;
96960 @@ -334,7 +334,7 @@ static int ping_check_bind_addr(struct sock *sk, struct inet_sock *isk,
96961 return -ENODEV;
96962 }
96963 }
96964 - has_addr = pingv6_ops.ipv6_chk_addr(net, &addr->sin6_addr, dev,
96965 + has_addr = pingv6_ops->ipv6_chk_addr(net, &addr->sin6_addr, dev,
96966 scoped);
96967 rcu_read_unlock();
96968
96969 @@ -542,7 +542,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
96970 }
96971 #if IS_ENABLED(CONFIG_IPV6)
96972 } else if (skb->protocol == htons(ETH_P_IPV6)) {
96973 - harderr = pingv6_ops.icmpv6_err_convert(type, code, &err);
96974 + harderr = pingv6_ops->icmpv6_err_convert(type, code, &err);
96975 #endif
96976 }
96977
96978 @@ -560,7 +560,7 @@ void ping_err(struct sk_buff *skb, int offset, u32 info)
96979 info, (u8 *)icmph);
96980 #if IS_ENABLED(CONFIG_IPV6)
96981 } else if (family == AF_INET6) {
96982 - pingv6_ops.ipv6_icmp_error(sk, skb, err, 0,
96983 + pingv6_ops->ipv6_icmp_error(sk, skb, err, 0,
96984 info, (u8 *)icmph);
96985 #endif
96986 }
96987 @@ -830,6 +830,8 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
96988 {
96989 struct inet_sock *isk = inet_sk(sk);
96990 int family = sk->sk_family;
96991 + struct sockaddr_in *sin;
96992 + struct sockaddr_in6 *sin6;
96993 struct sk_buff *skb;
96994 int copied, err;
96995
96996 @@ -839,12 +841,19 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
96997 if (flags & MSG_OOB)
96998 goto out;
96999
97000 + if (addr_len) {
97001 + if (family == AF_INET)
97002 + *addr_len = sizeof(*sin);
97003 + else if (family == AF_INET6 && addr_len)
97004 + *addr_len = sizeof(*sin6);
97005 + }
97006 +
97007 if (flags & MSG_ERRQUEUE) {
97008 if (family == AF_INET) {
97009 return ip_recv_error(sk, msg, len, addr_len);
97010 #if IS_ENABLED(CONFIG_IPV6)
97011 } else if (family == AF_INET6) {
97012 - return pingv6_ops.ipv6_recv_error(sk, msg, len,
97013 + return pingv6_ops->ipv6_recv_error(sk, msg, len,
97014 addr_len);
97015 #endif
97016 }
97017 @@ -876,7 +885,6 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97018 sin->sin_port = 0 /* skb->h.uh->source */;
97019 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
97020 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
97021 - *addr_len = sizeof(*sin);
97022 }
97023
97024 if (isk->cmsg_flags)
97025 @@ -899,11 +907,10 @@ int ping_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97026 sin6->sin6_scope_id =
97027 ipv6_iface_scope_id(&sin6->sin6_addr,
97028 IP6CB(skb)->iif);
97029 - *addr_len = sizeof(*sin6);
97030 }
97031
97032 if (inet6_sk(sk)->rxopt.all)
97033 - pingv6_ops.ip6_datagram_recv_ctl(sk, msg, skb);
97034 + pingv6_ops->ip6_datagram_recv_ctl(sk, msg, skb);
97035 #endif
97036 } else {
97037 BUG();
97038 @@ -1093,7 +1100,7 @@ static void ping_v4_format_sock(struct sock *sp, struct seq_file *f,
97039 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
97040 0, sock_i_ino(sp),
97041 atomic_read(&sp->sk_refcnt), sp,
97042 - atomic_read(&sp->sk_drops));
97043 + atomic_read_unchecked(&sp->sk_drops));
97044 }
97045
97046 static int ping_v4_seq_show(struct seq_file *seq, void *v)
97047 diff --git a/net/ipv4/raw.c b/net/ipv4/raw.c
97048 index 23c3e5b..cdb8b36 100644
97049 --- a/net/ipv4/raw.c
97050 +++ b/net/ipv4/raw.c
97051 @@ -311,7 +311,7 @@ static int raw_rcv_skb(struct sock *sk, struct sk_buff *skb)
97052 int raw_rcv(struct sock *sk, struct sk_buff *skb)
97053 {
97054 if (!xfrm4_policy_check(sk, XFRM_POLICY_IN, skb)) {
97055 - atomic_inc(&sk->sk_drops);
97056 + atomic_inc_unchecked(&sk->sk_drops);
97057 kfree_skb(skb);
97058 return NET_RX_DROP;
97059 }
97060 @@ -696,6 +696,9 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97061 if (flags & MSG_OOB)
97062 goto out;
97063
97064 + if (addr_len)
97065 + *addr_len = sizeof(*sin);
97066 +
97067 if (flags & MSG_ERRQUEUE) {
97068 err = ip_recv_error(sk, msg, len, addr_len);
97069 goto out;
97070 @@ -723,7 +726,6 @@ static int raw_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97071 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
97072 sin->sin_port = 0;
97073 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
97074 - *addr_len = sizeof(*sin);
97075 }
97076 if (inet->cmsg_flags)
97077 ip_cmsg_recv(msg, skb);
97078 @@ -748,16 +750,20 @@ static int raw_init(struct sock *sk)
97079
97080 static int raw_seticmpfilter(struct sock *sk, char __user *optval, int optlen)
97081 {
97082 + struct icmp_filter filter;
97083 +
97084 if (optlen > sizeof(struct icmp_filter))
97085 optlen = sizeof(struct icmp_filter);
97086 - if (copy_from_user(&raw_sk(sk)->filter, optval, optlen))
97087 + if (copy_from_user(&filter, optval, optlen))
97088 return -EFAULT;
97089 + raw_sk(sk)->filter = filter;
97090 return 0;
97091 }
97092
97093 static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *optlen)
97094 {
97095 int len, ret = -EFAULT;
97096 + struct icmp_filter filter;
97097
97098 if (get_user(len, optlen))
97099 goto out;
97100 @@ -767,8 +773,8 @@ static int raw_geticmpfilter(struct sock *sk, char __user *optval, int __user *o
97101 if (len > sizeof(struct icmp_filter))
97102 len = sizeof(struct icmp_filter);
97103 ret = -EFAULT;
97104 - if (put_user(len, optlen) ||
97105 - copy_to_user(optval, &raw_sk(sk)->filter, len))
97106 + filter = raw_sk(sk)->filter;
97107 + if (put_user(len, optlen) || len > sizeof filter || copy_to_user(optval, &filter, len))
97108 goto out;
97109 ret = 0;
97110 out: return ret;
97111 @@ -997,7 +1003,7 @@ static void raw_sock_seq_show(struct seq_file *seq, struct sock *sp, int i)
97112 0, 0L, 0,
97113 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sp)),
97114 0, sock_i_ino(sp),
97115 - atomic_read(&sp->sk_refcnt), sp, atomic_read(&sp->sk_drops));
97116 + atomic_read(&sp->sk_refcnt), sp, atomic_read_unchecked(&sp->sk_drops));
97117 }
97118
97119 static int raw_seq_show(struct seq_file *seq, void *v)
97120 diff --git a/net/ipv4/route.c b/net/ipv4/route.c
97121 index f8da282..133a1c7 100644
97122 --- a/net/ipv4/route.c
97123 +++ b/net/ipv4/route.c
97124 @@ -2621,34 +2621,34 @@ static struct ctl_table ipv4_route_flush_table[] = {
97125 .maxlen = sizeof(int),
97126 .mode = 0200,
97127 .proc_handler = ipv4_sysctl_rtcache_flush,
97128 + .extra1 = &init_net,
97129 },
97130 { },
97131 };
97132
97133 static __net_init int sysctl_route_net_init(struct net *net)
97134 {
97135 - struct ctl_table *tbl;
97136 + ctl_table_no_const *tbl = NULL;
97137
97138 - tbl = ipv4_route_flush_table;
97139 if (!net_eq(net, &init_net)) {
97140 - tbl = kmemdup(tbl, sizeof(ipv4_route_flush_table), GFP_KERNEL);
97141 + tbl = kmemdup(ipv4_route_flush_table, sizeof(ipv4_route_flush_table), GFP_KERNEL);
97142 if (tbl == NULL)
97143 goto err_dup;
97144
97145 /* Don't export sysctls to unprivileged users */
97146 if (net->user_ns != &init_user_ns)
97147 tbl[0].procname = NULL;
97148 - }
97149 - tbl[0].extra1 = net;
97150 + tbl[0].extra1 = net;
97151 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
97152 + } else
97153 + net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", ipv4_route_flush_table);
97154
97155 - net->ipv4.route_hdr = register_net_sysctl(net, "net/ipv4/route", tbl);
97156 if (net->ipv4.route_hdr == NULL)
97157 goto err_reg;
97158 return 0;
97159
97160 err_reg:
97161 - if (tbl != ipv4_route_flush_table)
97162 - kfree(tbl);
97163 + kfree(tbl);
97164 err_dup:
97165 return -ENOMEM;
97166 }
97167 @@ -2671,8 +2671,8 @@ static __net_initdata struct pernet_operations sysctl_route_ops = {
97168
97169 static __net_init int rt_genid_init(struct net *net)
97170 {
97171 - atomic_set(&net->ipv4.rt_genid, 0);
97172 - atomic_set(&net->fnhe_genid, 0);
97173 + atomic_set_unchecked(&net->ipv4.rt_genid, 0);
97174 + atomic_set_unchecked(&net->fnhe_genid, 0);
97175 get_random_bytes(&net->ipv4.dev_addr_genid,
97176 sizeof(net->ipv4.dev_addr_genid));
97177 return 0;
97178 diff --git a/net/ipv4/sysctl_net_ipv4.c b/net/ipv4/sysctl_net_ipv4.c
97179 index 3d69ec8..57207b4 100644
97180 --- a/net/ipv4/sysctl_net_ipv4.c
97181 +++ b/net/ipv4/sysctl_net_ipv4.c
97182 @@ -60,7 +60,7 @@ static int ipv4_local_port_range(struct ctl_table *table, int write,
97183 container_of(table->data, struct net, ipv4.sysctl_local_ports.range);
97184 int ret;
97185 int range[2];
97186 - struct ctl_table tmp = {
97187 + ctl_table_no_const tmp = {
97188 .data = &range,
97189 .maxlen = sizeof(range),
97190 .mode = table->mode,
97191 @@ -118,7 +118,7 @@ static int ipv4_ping_group_range(struct ctl_table *table, int write,
97192 int ret;
97193 gid_t urange[2];
97194 kgid_t low, high;
97195 - struct ctl_table tmp = {
97196 + ctl_table_no_const tmp = {
97197 .data = &urange,
97198 .maxlen = sizeof(urange),
97199 .mode = table->mode,
97200 @@ -149,7 +149,7 @@ static int proc_tcp_congestion_control(struct ctl_table *ctl, int write,
97201 void __user *buffer, size_t *lenp, loff_t *ppos)
97202 {
97203 char val[TCP_CA_NAME_MAX];
97204 - struct ctl_table tbl = {
97205 + ctl_table_no_const tbl = {
97206 .data = val,
97207 .maxlen = TCP_CA_NAME_MAX,
97208 };
97209 @@ -168,7 +168,7 @@ static int proc_tcp_available_congestion_control(struct ctl_table *ctl,
97210 void __user *buffer, size_t *lenp,
97211 loff_t *ppos)
97212 {
97213 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX, };
97214 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX, };
97215 int ret;
97216
97217 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
97218 @@ -185,7 +185,7 @@ static int proc_allowed_congestion_control(struct ctl_table *ctl,
97219 void __user *buffer, size_t *lenp,
97220 loff_t *ppos)
97221 {
97222 - struct ctl_table tbl = { .maxlen = TCP_CA_BUF_MAX };
97223 + ctl_table_no_const tbl = { .maxlen = TCP_CA_BUF_MAX };
97224 int ret;
97225
97226 tbl.data = kmalloc(tbl.maxlen, GFP_USER);
97227 @@ -204,7 +204,7 @@ static int proc_tcp_fastopen_key(struct ctl_table *ctl, int write,
97228 void __user *buffer, size_t *lenp,
97229 loff_t *ppos)
97230 {
97231 - struct ctl_table tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
97232 + ctl_table_no_const tbl = { .maxlen = (TCP_FASTOPEN_KEY_LENGTH * 2 + 10) };
97233 struct tcp_fastopen_context *ctxt;
97234 int ret;
97235 u32 user_key[4]; /* 16 bytes, matching TCP_FASTOPEN_KEY_LENGTH */
97236 @@ -445,7 +445,7 @@ static struct ctl_table ipv4_table[] = {
97237 },
97238 {
97239 .procname = "ip_local_reserved_ports",
97240 - .data = NULL, /* initialized in sysctl_ipv4_init */
97241 + .data = sysctl_local_reserved_ports,
97242 .maxlen = 65536,
97243 .mode = 0644,
97244 .proc_handler = proc_do_large_bitmap,
97245 @@ -827,13 +827,12 @@ static struct ctl_table ipv4_net_table[] = {
97246
97247 static __net_init int ipv4_sysctl_init_net(struct net *net)
97248 {
97249 - struct ctl_table *table;
97250 + ctl_table_no_const *table = NULL;
97251
97252 - table = ipv4_net_table;
97253 if (!net_eq(net, &init_net)) {
97254 int i;
97255
97256 - table = kmemdup(table, sizeof(ipv4_net_table), GFP_KERNEL);
97257 + table = kmemdup(ipv4_net_table, sizeof(ipv4_net_table), GFP_KERNEL);
97258 if (table == NULL)
97259 goto err_alloc;
97260
97261 @@ -856,15 +855,17 @@ static __net_init int ipv4_sysctl_init_net(struct net *net)
97262 net->ipv4.sysctl_local_ports.range[0] = 32768;
97263 net->ipv4.sysctl_local_ports.range[1] = 61000;
97264
97265 - net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
97266 + if (!net_eq(net, &init_net))
97267 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", table);
97268 + else
97269 + net->ipv4.ipv4_hdr = register_net_sysctl(net, "net/ipv4", ipv4_net_table);
97270 if (net->ipv4.ipv4_hdr == NULL)
97271 goto err_reg;
97272
97273 return 0;
97274
97275 err_reg:
97276 - if (!net_eq(net, &init_net))
97277 - kfree(table);
97278 + kfree(table);
97279 err_alloc:
97280 return -ENOMEM;
97281 }
97282 @@ -886,16 +887,6 @@ static __net_initdata struct pernet_operations ipv4_sysctl_ops = {
97283 static __init int sysctl_ipv4_init(void)
97284 {
97285 struct ctl_table_header *hdr;
97286 - struct ctl_table *i;
97287 -
97288 - for (i = ipv4_table; i->procname; i++) {
97289 - if (strcmp(i->procname, "ip_local_reserved_ports") == 0) {
97290 - i->data = sysctl_local_reserved_ports;
97291 - break;
97292 - }
97293 - }
97294 - if (!i->procname)
97295 - return -EINVAL;
97296
97297 hdr = register_net_sysctl(&init_net, "net/ipv4", ipv4_table);
97298 if (hdr == NULL)
97299 diff --git a/net/ipv4/tcp_input.c b/net/ipv4/tcp_input.c
97300 index c53b7f3..a89aadd 100644
97301 --- a/net/ipv4/tcp_input.c
97302 +++ b/net/ipv4/tcp_input.c
97303 @@ -759,7 +759,7 @@ static void tcp_update_pacing_rate(struct sock *sk)
97304 * without any lock. We want to make sure compiler wont store
97305 * intermediate values in this location.
97306 */
97307 - ACCESS_ONCE(sk->sk_pacing_rate) = min_t(u64, rate,
97308 + ACCESS_ONCE_RW(sk->sk_pacing_rate) = min_t(u64, rate,
97309 sk->sk_max_pacing_rate);
97310 }
97311
97312 @@ -4482,7 +4482,7 @@ static struct sk_buff *tcp_collapse_one(struct sock *sk, struct sk_buff *skb,
97313 * simplifies code)
97314 */
97315 static void
97316 -tcp_collapse(struct sock *sk, struct sk_buff_head *list,
97317 +__intentional_overflow(5,6) tcp_collapse(struct sock *sk, struct sk_buff_head *list,
97318 struct sk_buff *head, struct sk_buff *tail,
97319 u32 start, u32 end)
97320 {
97321 @@ -5559,6 +5559,7 @@ discard:
97322 tcp_paws_reject(&tp->rx_opt, 0))
97323 goto discard_and_undo;
97324
97325 +#ifndef CONFIG_GRKERNSEC_NO_SIMULT_CONNECT
97326 if (th->syn) {
97327 /* We see SYN without ACK. It is attempt of
97328 * simultaneous connect with crossed SYNs.
97329 @@ -5609,6 +5610,7 @@ discard:
97330 goto discard;
97331 #endif
97332 }
97333 +#endif
97334 /* "fifth, if neither of the SYN or RST bits is set then
97335 * drop the segment and return."
97336 */
97337 @@ -5655,7 +5657,7 @@ int tcp_rcv_state_process(struct sock *sk, struct sk_buff *skb,
97338 goto discard;
97339
97340 if (th->syn) {
97341 - if (th->fin)
97342 + if (th->fin || th->urg || th->psh)
97343 goto discard;
97344 if (icsk->icsk_af_ops->conn_request(sk, skb) < 0)
97345 return 1;
97346 diff --git a/net/ipv4/tcp_ipv4.c b/net/ipv4/tcp_ipv4.c
97347 index 0672139..cacc17d 100644
97348 --- a/net/ipv4/tcp_ipv4.c
97349 +++ b/net/ipv4/tcp_ipv4.c
97350 @@ -91,6 +91,10 @@ int sysctl_tcp_low_latency __read_mostly;
97351 EXPORT_SYMBOL(sysctl_tcp_low_latency);
97352
97353
97354 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97355 +extern int grsec_enable_blackhole;
97356 +#endif
97357 +
97358 #ifdef CONFIG_TCP_MD5SIG
97359 static int tcp_v4_md5_hash_hdr(char *md5_hash, const struct tcp_md5sig_key *key,
97360 __be32 daddr, __be32 saddr, const struct tcphdr *th);
97361 @@ -1830,6 +1834,9 @@ int tcp_v4_do_rcv(struct sock *sk, struct sk_buff *skb)
97362 return 0;
97363
97364 reset:
97365 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97366 + if (!grsec_enable_blackhole)
97367 +#endif
97368 tcp_v4_send_reset(rsk, skb);
97369 discard:
97370 kfree_skb(skb);
97371 @@ -1975,12 +1982,19 @@ int tcp_v4_rcv(struct sk_buff *skb)
97372 TCP_SKB_CB(skb)->sacked = 0;
97373
97374 sk = __inet_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
97375 - if (!sk)
97376 + if (!sk) {
97377 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97378 + ret = 1;
97379 +#endif
97380 goto no_tcp_socket;
97381 -
97382 + }
97383 process:
97384 - if (sk->sk_state == TCP_TIME_WAIT)
97385 + if (sk->sk_state == TCP_TIME_WAIT) {
97386 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97387 + ret = 2;
97388 +#endif
97389 goto do_time_wait;
97390 + }
97391
97392 if (unlikely(iph->ttl < inet_sk(sk)->min_ttl)) {
97393 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
97394 @@ -2034,6 +2048,10 @@ csum_error:
97395 bad_packet:
97396 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
97397 } else {
97398 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97399 + if (!grsec_enable_blackhole || (ret == 1 &&
97400 + (skb->dev->flags & IFF_LOOPBACK)))
97401 +#endif
97402 tcp_v4_send_reset(NULL, skb);
97403 }
97404
97405 diff --git a/net/ipv4/tcp_minisocks.c b/net/ipv4/tcp_minisocks.c
97406 index 97b6841..0893357 100644
97407 --- a/net/ipv4/tcp_minisocks.c
97408 +++ b/net/ipv4/tcp_minisocks.c
97409 @@ -27,6 +27,10 @@
97410 #include <net/inet_common.h>
97411 #include <net/xfrm.h>
97412
97413 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97414 +extern int grsec_enable_blackhole;
97415 +#endif
97416 +
97417 int sysctl_tcp_syncookies __read_mostly = 1;
97418 EXPORT_SYMBOL(sysctl_tcp_syncookies);
97419
97420 @@ -708,7 +712,10 @@ embryonic_reset:
97421 * avoid becoming vulnerable to outside attack aiming at
97422 * resetting legit local connections.
97423 */
97424 - req->rsk_ops->send_reset(sk, skb);
97425 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97426 + if (!grsec_enable_blackhole)
97427 +#endif
97428 + req->rsk_ops->send_reset(sk, skb);
97429 } else if (fastopen) { /* received a valid RST pkt */
97430 reqsk_fastopen_remove(sk, req, true);
97431 tcp_reset(sk);
97432 diff --git a/net/ipv4/tcp_probe.c b/net/ipv4/tcp_probe.c
97433 index 8b97d71..9d7ccf5 100644
97434 --- a/net/ipv4/tcp_probe.c
97435 +++ b/net/ipv4/tcp_probe.c
97436 @@ -238,7 +238,7 @@ static ssize_t tcpprobe_read(struct file *file, char __user *buf,
97437 if (cnt + width >= len)
97438 break;
97439
97440 - if (copy_to_user(buf + cnt, tbuf, width))
97441 + if (width > sizeof tbuf || copy_to_user(buf + cnt, tbuf, width))
97442 return -EFAULT;
97443 cnt += width;
97444 }
97445 diff --git a/net/ipv4/tcp_timer.c b/net/ipv4/tcp_timer.c
97446 index 64f0354..a81b39d 100644
97447 --- a/net/ipv4/tcp_timer.c
97448 +++ b/net/ipv4/tcp_timer.c
97449 @@ -22,6 +22,10 @@
97450 #include <linux/gfp.h>
97451 #include <net/tcp.h>
97452
97453 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97454 +extern int grsec_lastack_retries;
97455 +#endif
97456 +
97457 int sysctl_tcp_syn_retries __read_mostly = TCP_SYN_RETRIES;
97458 int sysctl_tcp_synack_retries __read_mostly = TCP_SYNACK_RETRIES;
97459 int sysctl_tcp_keepalive_time __read_mostly = TCP_KEEPALIVE_TIME;
97460 @@ -189,6 +193,13 @@ static int tcp_write_timeout(struct sock *sk)
97461 }
97462 }
97463
97464 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97465 + if ((sk->sk_state == TCP_LAST_ACK) &&
97466 + (grsec_lastack_retries > 0) &&
97467 + (grsec_lastack_retries < retry_until))
97468 + retry_until = grsec_lastack_retries;
97469 +#endif
97470 +
97471 if (retransmits_timed_out(sk, retry_until,
97472 syn_set ? 0 : icsk->icsk_user_timeout, syn_set)) {
97473 /* Has it gone just too far? */
97474 diff --git a/net/ipv4/udp.c b/net/ipv4/udp.c
97475 index a7e4729..2758946 100644
97476 --- a/net/ipv4/udp.c
97477 +++ b/net/ipv4/udp.c
97478 @@ -87,6 +87,7 @@
97479 #include <linux/types.h>
97480 #include <linux/fcntl.h>
97481 #include <linux/module.h>
97482 +#include <linux/security.h>
97483 #include <linux/socket.h>
97484 #include <linux/sockios.h>
97485 #include <linux/igmp.h>
97486 @@ -113,6 +114,10 @@
97487 #include <net/busy_poll.h>
97488 #include "udp_impl.h"
97489
97490 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97491 +extern int grsec_enable_blackhole;
97492 +#endif
97493 +
97494 struct udp_table udp_table __read_mostly;
97495 EXPORT_SYMBOL(udp_table);
97496
97497 @@ -615,6 +620,9 @@ found:
97498 return s;
97499 }
97500
97501 +extern int gr_search_udp_recvmsg(struct sock *sk, const struct sk_buff *skb);
97502 +extern int gr_search_udp_sendmsg(struct sock *sk, struct sockaddr_in *addr);
97503 +
97504 /*
97505 * This routine is called by the ICMP module when it gets some
97506 * sort of error condition. If err < 0 then the socket should
97507 @@ -914,9 +922,18 @@ int udp_sendmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97508 dport = usin->sin_port;
97509 if (dport == 0)
97510 return -EINVAL;
97511 +
97512 + err = gr_search_udp_sendmsg(sk, usin);
97513 + if (err)
97514 + return err;
97515 } else {
97516 if (sk->sk_state != TCP_ESTABLISHED)
97517 return -EDESTADDRREQ;
97518 +
97519 + err = gr_search_udp_sendmsg(sk, NULL);
97520 + if (err)
97521 + return err;
97522 +
97523 daddr = inet->inet_daddr;
97524 dport = inet->inet_dport;
97525 /* Open fast path for connected socket.
97526 @@ -1163,7 +1180,7 @@ static unsigned int first_packet_length(struct sock *sk)
97527 IS_UDPLITE(sk));
97528 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
97529 IS_UDPLITE(sk));
97530 - atomic_inc(&sk->sk_drops);
97531 + atomic_inc_unchecked(&sk->sk_drops);
97532 __skb_unlink(skb, rcvq);
97533 __skb_queue_tail(&list_kill, skb);
97534 }
97535 @@ -1234,6 +1251,12 @@ int udp_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *msg,
97536 int is_udplite = IS_UDPLITE(sk);
97537 bool slow;
97538
97539 + /*
97540 + * Check any passed addresses
97541 + */
97542 + if (addr_len)
97543 + *addr_len = sizeof(*sin);
97544 +
97545 if (flags & MSG_ERRQUEUE)
97546 return ip_recv_error(sk, msg, len, addr_len);
97547
97548 @@ -1243,6 +1266,10 @@ try_again:
97549 if (!skb)
97550 goto out;
97551
97552 + err = gr_search_udp_recvmsg(sk, skb);
97553 + if (err)
97554 + goto out_free;
97555 +
97556 ulen = skb->len - sizeof(struct udphdr);
97557 copied = len;
97558 if (copied > ulen)
97559 @@ -1276,7 +1303,7 @@ try_again:
97560 if (unlikely(err)) {
97561 trace_kfree_skb(skb, udp_recvmsg);
97562 if (!peeked) {
97563 - atomic_inc(&sk->sk_drops);
97564 + atomic_inc_unchecked(&sk->sk_drops);
97565 UDP_INC_STATS_USER(sock_net(sk),
97566 UDP_MIB_INERRORS, is_udplite);
97567 }
97568 @@ -1295,7 +1322,6 @@ try_again:
97569 sin->sin_port = udp_hdr(skb)->source;
97570 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
97571 memset(sin->sin_zero, 0, sizeof(sin->sin_zero));
97572 - *addr_len = sizeof(*sin);
97573 }
97574 if (inet->cmsg_flags)
97575 ip_cmsg_recv(msg, skb);
97576 @@ -1566,7 +1592,7 @@ csum_error:
97577 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
97578 drop:
97579 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
97580 - atomic_inc(&sk->sk_drops);
97581 + atomic_inc_unchecked(&sk->sk_drops);
97582 kfree_skb(skb);
97583 return -1;
97584 }
97585 @@ -1585,7 +1611,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
97586 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
97587
97588 if (!skb1) {
97589 - atomic_inc(&sk->sk_drops);
97590 + atomic_inc_unchecked(&sk->sk_drops);
97591 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
97592 IS_UDPLITE(sk));
97593 UDP_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
97594 @@ -1786,6 +1812,9 @@ int __udp4_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
97595 goto csum_error;
97596
97597 UDP_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
97598 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
97599 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
97600 +#endif
97601 icmp_send(skb, ICMP_DEST_UNREACH, ICMP_PORT_UNREACH, 0);
97602
97603 /*
97604 @@ -2350,7 +2379,7 @@ static void udp4_format_sock(struct sock *sp, struct seq_file *f,
97605 from_kuid_munged(seq_user_ns(f), sock_i_uid(sp)),
97606 0, sock_i_ino(sp),
97607 atomic_read(&sp->sk_refcnt), sp,
97608 - atomic_read(&sp->sk_drops));
97609 + atomic_read_unchecked(&sp->sk_drops));
97610 }
97611
97612 int udp4_seq_show(struct seq_file *seq, void *v)
97613 diff --git a/net/ipv4/xfrm4_policy.c b/net/ipv4/xfrm4_policy.c
97614 index e1a6393..f634ce5 100644
97615 --- a/net/ipv4/xfrm4_policy.c
97616 +++ b/net/ipv4/xfrm4_policy.c
97617 @@ -186,11 +186,11 @@ _decode_session4(struct sk_buff *skb, struct flowi *fl, int reverse)
97618 fl4->flowi4_tos = iph->tos;
97619 }
97620
97621 -static inline int xfrm4_garbage_collect(struct dst_ops *ops)
97622 +static int xfrm4_garbage_collect(struct dst_ops *ops)
97623 {
97624 struct net *net = container_of(ops, struct net, xfrm.xfrm4_dst_ops);
97625
97626 - xfrm4_policy_afinfo.garbage_collect(net);
97627 + xfrm_garbage_collect_deferred(net);
97628 return (dst_entries_get_slow(ops) > ops->gc_thresh * 2);
97629 }
97630
97631 @@ -269,19 +269,18 @@ static struct ctl_table xfrm4_policy_table[] = {
97632
97633 static int __net_init xfrm4_net_init(struct net *net)
97634 {
97635 - struct ctl_table *table;
97636 + ctl_table_no_const *table = NULL;
97637 struct ctl_table_header *hdr;
97638
97639 - table = xfrm4_policy_table;
97640 if (!net_eq(net, &init_net)) {
97641 - table = kmemdup(table, sizeof(xfrm4_policy_table), GFP_KERNEL);
97642 + table = kmemdup(xfrm4_policy_table, sizeof(xfrm4_policy_table), GFP_KERNEL);
97643 if (!table)
97644 goto err_alloc;
97645
97646 table[0].data = &net->xfrm.xfrm4_dst_ops.gc_thresh;
97647 - }
97648 -
97649 - hdr = register_net_sysctl(net, "net/ipv4", table);
97650 + hdr = register_net_sysctl(net, "net/ipv4", table);
97651 + } else
97652 + hdr = register_net_sysctl(net, "net/ipv4", xfrm4_policy_table);
97653 if (!hdr)
97654 goto err_reg;
97655
97656 @@ -289,8 +288,7 @@ static int __net_init xfrm4_net_init(struct net *net)
97657 return 0;
97658
97659 err_reg:
97660 - if (!net_eq(net, &init_net))
97661 - kfree(table);
97662 + kfree(table);
97663 err_alloc:
97664 return -ENOMEM;
97665 }
97666 diff --git a/net/ipv6/addrconf.c b/net/ipv6/addrconf.c
97667 index 4b6b720..272c0c5 100644
97668 --- a/net/ipv6/addrconf.c
97669 +++ b/net/ipv6/addrconf.c
97670 @@ -589,7 +589,7 @@ static int inet6_netconf_dump_devconf(struct sk_buff *skb,
97671 idx = 0;
97672 head = &net->dev_index_head[h];
97673 rcu_read_lock();
97674 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^
97675 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^
97676 net->dev_base_seq;
97677 hlist_for_each_entry_rcu(dev, head, index_hlist) {
97678 if (idx < s_idx)
97679 @@ -2334,7 +2334,7 @@ int addrconf_set_dstaddr(struct net *net, void __user *arg)
97680 p.iph.ihl = 5;
97681 p.iph.protocol = IPPROTO_IPV6;
97682 p.iph.ttl = 64;
97683 - ifr.ifr_ifru.ifru_data = (__force void __user *)&p;
97684 + ifr.ifr_ifru.ifru_data = (void __force_user *)&p;
97685
97686 if (ops->ndo_do_ioctl) {
97687 mm_segment_t oldfs = get_fs();
97688 @@ -3962,7 +3962,7 @@ static int inet6_dump_addr(struct sk_buff *skb, struct netlink_callback *cb,
97689 s_ip_idx = ip_idx = cb->args[2];
97690
97691 rcu_read_lock();
97692 - cb->seq = atomic_read(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
97693 + cb->seq = atomic_read_unchecked(&net->ipv6.dev_addr_genid) ^ net->dev_base_seq;
97694 for (h = s_h; h < NETDEV_HASHENTRIES; h++, s_idx = 0) {
97695 idx = 0;
97696 head = &net->dev_index_head[h];
97697 @@ -4569,7 +4569,7 @@ static void __ipv6_ifa_notify(int event, struct inet6_ifaddr *ifp)
97698 dst_free(&ifp->rt->dst);
97699 break;
97700 }
97701 - atomic_inc(&net->ipv6.dev_addr_genid);
97702 + atomic_inc_unchecked(&net->ipv6.dev_addr_genid);
97703 rt_genid_bump_ipv6(net);
97704 }
97705
97706 @@ -4590,7 +4590,7 @@ int addrconf_sysctl_forward(struct ctl_table *ctl, int write,
97707 int *valp = ctl->data;
97708 int val = *valp;
97709 loff_t pos = *ppos;
97710 - struct ctl_table lctl;
97711 + ctl_table_no_const lctl;
97712 int ret;
97713
97714 /*
97715 @@ -4675,7 +4675,7 @@ int addrconf_sysctl_disable(struct ctl_table *ctl, int write,
97716 int *valp = ctl->data;
97717 int val = *valp;
97718 loff_t pos = *ppos;
97719 - struct ctl_table lctl;
97720 + ctl_table_no_const lctl;
97721 int ret;
97722
97723 /*
97724 diff --git a/net/ipv6/af_inet6.c b/net/ipv6/af_inet6.c
97725 index 4fbdb70..f6411f2 100644
97726 --- a/net/ipv6/af_inet6.c
97727 +++ b/net/ipv6/af_inet6.c
97728 @@ -776,7 +776,7 @@ static int __net_init inet6_net_init(struct net *net)
97729
97730 net->ipv6.sysctl.bindv6only = 0;
97731 net->ipv6.sysctl.icmpv6_time = 1*HZ;
97732 - atomic_set(&net->ipv6.rt_genid, 0);
97733 + atomic_set_unchecked(&net->ipv6.rt_genid, 0);
97734
97735 err = ipv6_init_mibs(net);
97736 if (err)
97737 diff --git a/net/ipv6/datagram.c b/net/ipv6/datagram.c
97738 index 93b1aa3..e902855 100644
97739 --- a/net/ipv6/datagram.c
97740 +++ b/net/ipv6/datagram.c
97741 @@ -906,5 +906,5 @@ void ip6_dgram_sock_seq_show(struct seq_file *seq, struct sock *sp,
97742 0,
97743 sock_i_ino(sp),
97744 atomic_read(&sp->sk_refcnt), sp,
97745 - atomic_read(&sp->sk_drops));
97746 + atomic_read_unchecked(&sp->sk_drops));
97747 }
97748 diff --git a/net/ipv6/icmp.c b/net/ipv6/icmp.c
97749 index eef8d94..cfa1852 100644
97750 --- a/net/ipv6/icmp.c
97751 +++ b/net/ipv6/icmp.c
97752 @@ -997,7 +997,7 @@ struct ctl_table ipv6_icmp_table_template[] = {
97753
97754 struct ctl_table * __net_init ipv6_icmp_sysctl_init(struct net *net)
97755 {
97756 - struct ctl_table *table;
97757 + ctl_table_no_const *table;
97758
97759 table = kmemdup(ipv6_icmp_table_template,
97760 sizeof(ipv6_icmp_table_template),
97761 diff --git a/net/ipv6/ip6_gre.c b/net/ipv6/ip6_gre.c
97762 index 8acb286..840dd06 100644
97763 --- a/net/ipv6/ip6_gre.c
97764 +++ b/net/ipv6/ip6_gre.c
97765 @@ -74,7 +74,7 @@ struct ip6gre_net {
97766 struct net_device *fb_tunnel_dev;
97767 };
97768
97769 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly;
97770 +static struct rtnl_link_ops ip6gre_link_ops;
97771 static int ip6gre_tunnel_init(struct net_device *dev);
97772 static void ip6gre_tunnel_setup(struct net_device *dev);
97773 static void ip6gre_tunnel_link(struct ip6gre_net *ign, struct ip6_tnl *t);
97774 @@ -1294,7 +1294,7 @@ static void ip6gre_fb_tunnel_init(struct net_device *dev)
97775 }
97776
97777
97778 -static struct inet6_protocol ip6gre_protocol __read_mostly = {
97779 +static struct inet6_protocol ip6gre_protocol = {
97780 .handler = ip6gre_rcv,
97781 .err_handler = ip6gre_err,
97782 .flags = INET6_PROTO_NOPOLICY|INET6_PROTO_FINAL,
97783 @@ -1637,7 +1637,7 @@ static const struct nla_policy ip6gre_policy[IFLA_GRE_MAX + 1] = {
97784 [IFLA_GRE_FLAGS] = { .type = NLA_U32 },
97785 };
97786
97787 -static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
97788 +static struct rtnl_link_ops ip6gre_link_ops = {
97789 .kind = "ip6gre",
97790 .maxtype = IFLA_GRE_MAX,
97791 .policy = ip6gre_policy,
97792 @@ -1650,7 +1650,7 @@ static struct rtnl_link_ops ip6gre_link_ops __read_mostly = {
97793 .fill_info = ip6gre_fill_info,
97794 };
97795
97796 -static struct rtnl_link_ops ip6gre_tap_ops __read_mostly = {
97797 +static struct rtnl_link_ops ip6gre_tap_ops = {
97798 .kind = "ip6gretap",
97799 .maxtype = IFLA_GRE_MAX,
97800 .policy = ip6gre_policy,
97801 diff --git a/net/ipv6/ip6_tunnel.c b/net/ipv6/ip6_tunnel.c
97802 index 7881965..9cf62c4 100644
97803 --- a/net/ipv6/ip6_tunnel.c
97804 +++ b/net/ipv6/ip6_tunnel.c
97805 @@ -89,7 +89,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
97806
97807 static int ip6_tnl_dev_init(struct net_device *dev);
97808 static void ip6_tnl_dev_setup(struct net_device *dev);
97809 -static struct rtnl_link_ops ip6_link_ops __read_mostly;
97810 +static struct rtnl_link_ops ip6_link_ops;
97811
97812 static int ip6_tnl_net_id __read_mostly;
97813 struct ip6_tnl_net {
97814 @@ -1717,7 +1717,7 @@ static const struct nla_policy ip6_tnl_policy[IFLA_IPTUN_MAX + 1] = {
97815 [IFLA_IPTUN_PROTO] = { .type = NLA_U8 },
97816 };
97817
97818 -static struct rtnl_link_ops ip6_link_ops __read_mostly = {
97819 +static struct rtnl_link_ops ip6_link_ops = {
97820 .kind = "ip6tnl",
97821 .maxtype = IFLA_IPTUN_MAX,
97822 .policy = ip6_tnl_policy,
97823 diff --git a/net/ipv6/ip6_vti.c b/net/ipv6/ip6_vti.c
97824 index 7b42d5e..1eff693 100644
97825 --- a/net/ipv6/ip6_vti.c
97826 +++ b/net/ipv6/ip6_vti.c
97827 @@ -63,7 +63,7 @@ static u32 HASH(const struct in6_addr *addr1, const struct in6_addr *addr2)
97828
97829 static int vti6_dev_init(struct net_device *dev);
97830 static void vti6_dev_setup(struct net_device *dev);
97831 -static struct rtnl_link_ops vti6_link_ops __read_mostly;
97832 +static struct rtnl_link_ops vti6_link_ops;
97833
97834 static int vti6_net_id __read_mostly;
97835 struct vti6_net {
97836 @@ -902,7 +902,7 @@ static const struct nla_policy vti6_policy[IFLA_VTI_MAX + 1] = {
97837 [IFLA_VTI_OKEY] = { .type = NLA_U32 },
97838 };
97839
97840 -static struct rtnl_link_ops vti6_link_ops __read_mostly = {
97841 +static struct rtnl_link_ops vti6_link_ops = {
97842 .kind = "vti6",
97843 .maxtype = IFLA_VTI_MAX,
97844 .policy = vti6_policy,
97845 diff --git a/net/ipv6/ipv6_sockglue.c b/net/ipv6/ipv6_sockglue.c
97846 index 1c6ce31..299e566 100644
97847 --- a/net/ipv6/ipv6_sockglue.c
97848 +++ b/net/ipv6/ipv6_sockglue.c
97849 @@ -991,7 +991,7 @@ static int do_ipv6_getsockopt(struct sock *sk, int level, int optname,
97850 if (sk->sk_type != SOCK_STREAM)
97851 return -ENOPROTOOPT;
97852
97853 - msg.msg_control = optval;
97854 + msg.msg_control = (void __force_kernel *)optval;
97855 msg.msg_controllen = len;
97856 msg.msg_flags = flags;
97857
97858 diff --git a/net/ipv6/netfilter/ip6_tables.c b/net/ipv6/netfilter/ip6_tables.c
97859 index 710238f..0fd1816 100644
97860 --- a/net/ipv6/netfilter/ip6_tables.c
97861 +++ b/net/ipv6/netfilter/ip6_tables.c
97862 @@ -1083,14 +1083,14 @@ static int compat_table_info(const struct xt_table_info *info,
97863 #endif
97864
97865 static int get_info(struct net *net, void __user *user,
97866 - const int *len, int compat)
97867 + int len, int compat)
97868 {
97869 char name[XT_TABLE_MAXNAMELEN];
97870 struct xt_table *t;
97871 int ret;
97872
97873 - if (*len != sizeof(struct ip6t_getinfo)) {
97874 - duprintf("length %u != %zu\n", *len,
97875 + if (len != sizeof(struct ip6t_getinfo)) {
97876 + duprintf("length %u != %zu\n", len,
97877 sizeof(struct ip6t_getinfo));
97878 return -EINVAL;
97879 }
97880 @@ -1127,7 +1127,7 @@ static int get_info(struct net *net, void __user *user,
97881 info.size = private->size;
97882 strcpy(info.name, name);
97883
97884 - if (copy_to_user(user, &info, *len) != 0)
97885 + if (copy_to_user(user, &info, len) != 0)
97886 ret = -EFAULT;
97887 else
97888 ret = 0;
97889 @@ -1981,7 +1981,7 @@ compat_do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97890
97891 switch (cmd) {
97892 case IP6T_SO_GET_INFO:
97893 - ret = get_info(sock_net(sk), user, len, 1);
97894 + ret = get_info(sock_net(sk), user, *len, 1);
97895 break;
97896 case IP6T_SO_GET_ENTRIES:
97897 ret = compat_get_entries(sock_net(sk), user, len);
97898 @@ -2028,7 +2028,7 @@ do_ip6t_get_ctl(struct sock *sk, int cmd, void __user *user, int *len)
97899
97900 switch (cmd) {
97901 case IP6T_SO_GET_INFO:
97902 - ret = get_info(sock_net(sk), user, len, 0);
97903 + ret = get_info(sock_net(sk), user, *len, 0);
97904 break;
97905
97906 case IP6T_SO_GET_ENTRIES:
97907 diff --git a/net/ipv6/netfilter/nf_conntrack_reasm.c b/net/ipv6/netfilter/nf_conntrack_reasm.c
97908 index 767ab8d..c5ec70a 100644
97909 --- a/net/ipv6/netfilter/nf_conntrack_reasm.c
97910 +++ b/net/ipv6/netfilter/nf_conntrack_reasm.c
97911 @@ -90,12 +90,11 @@ static struct ctl_table nf_ct_frag6_sysctl_table[] = {
97912
97913 static int nf_ct_frag6_sysctl_register(struct net *net)
97914 {
97915 - struct ctl_table *table;
97916 + ctl_table_no_const *table = NULL;
97917 struct ctl_table_header *hdr;
97918
97919 - table = nf_ct_frag6_sysctl_table;
97920 if (!net_eq(net, &init_net)) {
97921 - table = kmemdup(table, sizeof(nf_ct_frag6_sysctl_table),
97922 + table = kmemdup(nf_ct_frag6_sysctl_table, sizeof(nf_ct_frag6_sysctl_table),
97923 GFP_KERNEL);
97924 if (table == NULL)
97925 goto err_alloc;
97926 @@ -103,9 +102,9 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
97927 table[0].data = &net->nf_frag.frags.timeout;
97928 table[1].data = &net->nf_frag.frags.low_thresh;
97929 table[2].data = &net->nf_frag.frags.high_thresh;
97930 - }
97931 -
97932 - hdr = register_net_sysctl(net, "net/netfilter", table);
97933 + hdr = register_net_sysctl(net, "net/netfilter", table);
97934 + } else
97935 + hdr = register_net_sysctl(net, "net/netfilter", nf_ct_frag6_sysctl_table);
97936 if (hdr == NULL)
97937 goto err_reg;
97938
97939 @@ -113,8 +112,7 @@ static int nf_ct_frag6_sysctl_register(struct net *net)
97940 return 0;
97941
97942 err_reg:
97943 - if (!net_eq(net, &init_net))
97944 - kfree(table);
97945 + kfree(table);
97946 err_alloc:
97947 return -ENOMEM;
97948 }
97949 diff --git a/net/ipv6/output_core.c b/net/ipv6/output_core.c
97950 index 827f795..7e28e82 100644
97951 --- a/net/ipv6/output_core.c
97952 +++ b/net/ipv6/output_core.c
97953 @@ -9,8 +9,8 @@
97954
97955 void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
97956 {
97957 - static atomic_t ipv6_fragmentation_id;
97958 - int old, new;
97959 + static atomic_unchecked_t ipv6_fragmentation_id;
97960 + int id;
97961
97962 #if IS_ENABLED(CONFIG_IPV6)
97963 if (rt && !(rt->dst.flags & DST_NOPEER)) {
97964 @@ -26,13 +26,10 @@ void ipv6_select_ident(struct frag_hdr *fhdr, struct rt6_info *rt)
97965 }
97966 }
97967 #endif
97968 - do {
97969 - old = atomic_read(&ipv6_fragmentation_id);
97970 - new = old + 1;
97971 - if (!new)
97972 - new = 1;
97973 - } while (atomic_cmpxchg(&ipv6_fragmentation_id, old, new) != old);
97974 - fhdr->identification = htonl(new);
97975 + id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
97976 + if (!id)
97977 + id = atomic_inc_return_unchecked(&ipv6_fragmentation_id);
97978 + fhdr->identification = htonl(id);
97979 }
97980 EXPORT_SYMBOL(ipv6_select_ident);
97981
97982 diff --git a/net/ipv6/ping.c b/net/ipv6/ping.c
97983 index a83243c..a1ca589 100644
97984 --- a/net/ipv6/ping.c
97985 +++ b/net/ipv6/ping.c
97986 @@ -246,6 +246,22 @@ static struct pernet_operations ping_v6_net_ops = {
97987 };
97988 #endif
97989
97990 +static struct pingv6_ops real_pingv6_ops = {
97991 + .ipv6_recv_error = ipv6_recv_error,
97992 + .ip6_datagram_recv_ctl = ip6_datagram_recv_ctl,
97993 + .icmpv6_err_convert = icmpv6_err_convert,
97994 + .ipv6_icmp_error = ipv6_icmp_error,
97995 + .ipv6_chk_addr = ipv6_chk_addr,
97996 +};
97997 +
97998 +static struct pingv6_ops dummy_pingv6_ops = {
97999 + .ipv6_recv_error = dummy_ipv6_recv_error,
98000 + .ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl,
98001 + .icmpv6_err_convert = dummy_icmpv6_err_convert,
98002 + .ipv6_icmp_error = dummy_ipv6_icmp_error,
98003 + .ipv6_chk_addr = dummy_ipv6_chk_addr,
98004 +};
98005 +
98006 int __init pingv6_init(void)
98007 {
98008 #ifdef CONFIG_PROC_FS
98009 @@ -253,11 +269,7 @@ int __init pingv6_init(void)
98010 if (ret)
98011 return ret;
98012 #endif
98013 - pingv6_ops.ipv6_recv_error = ipv6_recv_error;
98014 - pingv6_ops.ip6_datagram_recv_ctl = ip6_datagram_recv_ctl;
98015 - pingv6_ops.icmpv6_err_convert = icmpv6_err_convert;
98016 - pingv6_ops.ipv6_icmp_error = ipv6_icmp_error;
98017 - pingv6_ops.ipv6_chk_addr = ipv6_chk_addr;
98018 + pingv6_ops = &real_pingv6_ops;
98019 return inet6_register_protosw(&pingv6_protosw);
98020 }
98021
98022 @@ -266,11 +278,7 @@ int __init pingv6_init(void)
98023 */
98024 void pingv6_exit(void)
98025 {
98026 - pingv6_ops.ipv6_recv_error = dummy_ipv6_recv_error;
98027 - pingv6_ops.ip6_datagram_recv_ctl = dummy_ip6_datagram_recv_ctl;
98028 - pingv6_ops.icmpv6_err_convert = dummy_icmpv6_err_convert;
98029 - pingv6_ops.ipv6_icmp_error = dummy_ipv6_icmp_error;
98030 - pingv6_ops.ipv6_chk_addr = dummy_ipv6_chk_addr;
98031 + pingv6_ops = &dummy_pingv6_ops;
98032 #ifdef CONFIG_PROC_FS
98033 unregister_pernet_subsys(&ping_v6_net_ops);
98034 #endif
98035 diff --git a/net/ipv6/raw.c b/net/ipv6/raw.c
98036 index b6bb87e..06cc9ed 100644
98037 --- a/net/ipv6/raw.c
98038 +++ b/net/ipv6/raw.c
98039 @@ -384,7 +384,7 @@ static inline int rawv6_rcv_skb(struct sock *sk, struct sk_buff *skb)
98040 {
98041 if ((raw6_sk(sk)->checksum || rcu_access_pointer(sk->sk_filter)) &&
98042 skb_checksum_complete(skb)) {
98043 - atomic_inc(&sk->sk_drops);
98044 + atomic_inc_unchecked(&sk->sk_drops);
98045 kfree_skb(skb);
98046 return NET_RX_DROP;
98047 }
98048 @@ -412,7 +412,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
98049 struct raw6_sock *rp = raw6_sk(sk);
98050
98051 if (!xfrm6_policy_check(sk, XFRM_POLICY_IN, skb)) {
98052 - atomic_inc(&sk->sk_drops);
98053 + atomic_inc_unchecked(&sk->sk_drops);
98054 kfree_skb(skb);
98055 return NET_RX_DROP;
98056 }
98057 @@ -436,7 +436,7 @@ int rawv6_rcv(struct sock *sk, struct sk_buff *skb)
98058
98059 if (inet->hdrincl) {
98060 if (skb_checksum_complete(skb)) {
98061 - atomic_inc(&sk->sk_drops);
98062 + atomic_inc_unchecked(&sk->sk_drops);
98063 kfree_skb(skb);
98064 return NET_RX_DROP;
98065 }
98066 @@ -465,6 +465,9 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
98067 if (flags & MSG_OOB)
98068 return -EOPNOTSUPP;
98069
98070 + if (addr_len)
98071 + *addr_len=sizeof(*sin6);
98072 +
98073 if (flags & MSG_ERRQUEUE)
98074 return ipv6_recv_error(sk, msg, len, addr_len);
98075
98076 @@ -503,7 +506,6 @@ static int rawv6_recvmsg(struct kiocb *iocb, struct sock *sk,
98077 sin6->sin6_flowinfo = 0;
98078 sin6->sin6_scope_id = ipv6_iface_scope_id(&sin6->sin6_addr,
98079 IP6CB(skb)->iif);
98080 - *addr_len = sizeof(*sin6);
98081 }
98082
98083 sock_recv_ts_and_drops(msg, sk, skb);
98084 @@ -606,7 +608,7 @@ out:
98085 return err;
98086 }
98087
98088 -static int rawv6_send_hdrinc(struct sock *sk, void *from, int length,
98089 +static int rawv6_send_hdrinc(struct sock *sk, void *from, unsigned int length,
98090 struct flowi6 *fl6, struct dst_entry **dstp,
98091 unsigned int flags)
98092 {
98093 @@ -918,12 +920,15 @@ do_confirm:
98094 static int rawv6_seticmpfilter(struct sock *sk, int level, int optname,
98095 char __user *optval, int optlen)
98096 {
98097 + struct icmp6_filter filter;
98098 +
98099 switch (optname) {
98100 case ICMPV6_FILTER:
98101 if (optlen > sizeof(struct icmp6_filter))
98102 optlen = sizeof(struct icmp6_filter);
98103 - if (copy_from_user(&raw6_sk(sk)->filter, optval, optlen))
98104 + if (copy_from_user(&filter, optval, optlen))
98105 return -EFAULT;
98106 + raw6_sk(sk)->filter = filter;
98107 return 0;
98108 default:
98109 return -ENOPROTOOPT;
98110 @@ -936,6 +941,7 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
98111 char __user *optval, int __user *optlen)
98112 {
98113 int len;
98114 + struct icmp6_filter filter;
98115
98116 switch (optname) {
98117 case ICMPV6_FILTER:
98118 @@ -947,7 +953,8 @@ static int rawv6_geticmpfilter(struct sock *sk, int level, int optname,
98119 len = sizeof(struct icmp6_filter);
98120 if (put_user(len, optlen))
98121 return -EFAULT;
98122 - if (copy_to_user(optval, &raw6_sk(sk)->filter, len))
98123 + filter = raw6_sk(sk)->filter;
98124 + if (len > sizeof filter || copy_to_user(optval, &filter, len))
98125 return -EFAULT;
98126 return 0;
98127 default:
98128 diff --git a/net/ipv6/reassembly.c b/net/ipv6/reassembly.c
98129 index cc85a9b..526a133 100644
98130 --- a/net/ipv6/reassembly.c
98131 +++ b/net/ipv6/reassembly.c
98132 @@ -626,12 +626,11 @@ static struct ctl_table ip6_frags_ctl_table[] = {
98133
98134 static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
98135 {
98136 - struct ctl_table *table;
98137 + ctl_table_no_const *table = NULL;
98138 struct ctl_table_header *hdr;
98139
98140 - table = ip6_frags_ns_ctl_table;
98141 if (!net_eq(net, &init_net)) {
98142 - table = kmemdup(table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
98143 + table = kmemdup(ip6_frags_ns_ctl_table, sizeof(ip6_frags_ns_ctl_table), GFP_KERNEL);
98144 if (table == NULL)
98145 goto err_alloc;
98146
98147 @@ -642,9 +641,10 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
98148 /* Don't export sysctls to unprivileged users */
98149 if (net->user_ns != &init_user_ns)
98150 table[0].procname = NULL;
98151 - }
98152 + hdr = register_net_sysctl(net, "net/ipv6", table);
98153 + } else
98154 + hdr = register_net_sysctl(net, "net/ipv6", ip6_frags_ns_ctl_table);
98155
98156 - hdr = register_net_sysctl(net, "net/ipv6", table);
98157 if (hdr == NULL)
98158 goto err_reg;
98159
98160 @@ -652,8 +652,7 @@ static int __net_init ip6_frags_ns_sysctl_register(struct net *net)
98161 return 0;
98162
98163 err_reg:
98164 - if (!net_eq(net, &init_net))
98165 - kfree(table);
98166 + kfree(table);
98167 err_alloc:
98168 return -ENOMEM;
98169 }
98170 diff --git a/net/ipv6/route.c b/net/ipv6/route.c
98171 index 4b4944c..4580b91 100644
98172 --- a/net/ipv6/route.c
98173 +++ b/net/ipv6/route.c
98174 @@ -2954,7 +2954,7 @@ struct ctl_table ipv6_route_table_template[] = {
98175
98176 struct ctl_table * __net_init ipv6_route_sysctl_init(struct net *net)
98177 {
98178 - struct ctl_table *table;
98179 + ctl_table_no_const *table;
98180
98181 table = kmemdup(ipv6_route_table_template,
98182 sizeof(ipv6_route_table_template),
98183 diff --git a/net/ipv6/sit.c b/net/ipv6/sit.c
98184 index d3005b3..b36df4a 100644
98185 --- a/net/ipv6/sit.c
98186 +++ b/net/ipv6/sit.c
98187 @@ -74,7 +74,7 @@ static void ipip6_tunnel_setup(struct net_device *dev);
98188 static void ipip6_dev_free(struct net_device *dev);
98189 static bool check_6rd(struct ip_tunnel *tunnel, const struct in6_addr *v6dst,
98190 __be32 *v4dst);
98191 -static struct rtnl_link_ops sit_link_ops __read_mostly;
98192 +static struct rtnl_link_ops sit_link_ops;
98193
98194 static int sit_net_id __read_mostly;
98195 struct sit_net {
98196 @@ -1664,7 +1664,7 @@ static void ipip6_dellink(struct net_device *dev, struct list_head *head)
98197 unregister_netdevice_queue(dev, head);
98198 }
98199
98200 -static struct rtnl_link_ops sit_link_ops __read_mostly = {
98201 +static struct rtnl_link_ops sit_link_ops = {
98202 .kind = "sit",
98203 .maxtype = IFLA_IPTUN_MAX,
98204 .policy = ipip6_policy,
98205 diff --git a/net/ipv6/sysctl_net_ipv6.c b/net/ipv6/sysctl_net_ipv6.c
98206 index 107b2f1..72741a9 100644
98207 --- a/net/ipv6/sysctl_net_ipv6.c
98208 +++ b/net/ipv6/sysctl_net_ipv6.c
98209 @@ -40,7 +40,7 @@ static struct ctl_table ipv6_rotable[] = {
98210
98211 static int __net_init ipv6_sysctl_net_init(struct net *net)
98212 {
98213 - struct ctl_table *ipv6_table;
98214 + ctl_table_no_const *ipv6_table;
98215 struct ctl_table *ipv6_route_table;
98216 struct ctl_table *ipv6_icmp_table;
98217 int err;
98218 diff --git a/net/ipv6/tcp_ipv6.c b/net/ipv6/tcp_ipv6.c
98219 index f67033b..6f974fc 100644
98220 --- a/net/ipv6/tcp_ipv6.c
98221 +++ b/net/ipv6/tcp_ipv6.c
98222 @@ -104,6 +104,10 @@ static void inet6_sk_rx_dst_set(struct sock *sk, const struct sk_buff *skb)
98223 inet6_sk(sk)->rx_dst_cookie = rt->rt6i_node->fn_sernum;
98224 }
98225
98226 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98227 +extern int grsec_enable_blackhole;
98228 +#endif
98229 +
98230 static void tcp_v6_hash(struct sock *sk)
98231 {
98232 if (sk->sk_state != TCP_CLOSE) {
98233 @@ -1397,6 +1401,9 @@ static int tcp_v6_do_rcv(struct sock *sk, struct sk_buff *skb)
98234 return 0;
98235
98236 reset:
98237 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98238 + if (!grsec_enable_blackhole)
98239 +#endif
98240 tcp_v6_send_reset(sk, skb);
98241 discard:
98242 if (opt_skb)
98243 @@ -1479,12 +1486,20 @@ static int tcp_v6_rcv(struct sk_buff *skb)
98244 TCP_SKB_CB(skb)->sacked = 0;
98245
98246 sk = __inet6_lookup_skb(&tcp_hashinfo, skb, th->source, th->dest);
98247 - if (!sk)
98248 + if (!sk) {
98249 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98250 + ret = 1;
98251 +#endif
98252 goto no_tcp_socket;
98253 + }
98254
98255 process:
98256 - if (sk->sk_state == TCP_TIME_WAIT)
98257 + if (sk->sk_state == TCP_TIME_WAIT) {
98258 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98259 + ret = 2;
98260 +#endif
98261 goto do_time_wait;
98262 + }
98263
98264 if (hdr->hop_limit < inet6_sk(sk)->min_hopcount) {
98265 NET_INC_STATS_BH(net, LINUX_MIB_TCPMINTTLDROP);
98266 @@ -1536,6 +1551,10 @@ csum_error:
98267 bad_packet:
98268 TCP_INC_STATS_BH(net, TCP_MIB_INERRS);
98269 } else {
98270 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98271 + if (!grsec_enable_blackhole || (ret == 1 &&
98272 + (skb->dev->flags & IFF_LOOPBACK)))
98273 +#endif
98274 tcp_v6_send_reset(NULL, skb);
98275 }
98276
98277 diff --git a/net/ipv6/udp.c b/net/ipv6/udp.c
98278 index 089c741..cfee117 100644
98279 --- a/net/ipv6/udp.c
98280 +++ b/net/ipv6/udp.c
98281 @@ -76,6 +76,10 @@ static unsigned int udp6_ehashfn(struct net *net,
98282 udp_ipv6_hash_secret + net_hash_mix(net));
98283 }
98284
98285 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98286 +extern int grsec_enable_blackhole;
98287 +#endif
98288 +
98289 int ipv6_rcv_saddr_equal(const struct sock *sk, const struct sock *sk2)
98290 {
98291 const struct in6_addr *sk2_rcv_saddr6 = inet6_rcv_saddr(sk2);
98292 @@ -392,6 +396,9 @@ int udpv6_recvmsg(struct kiocb *iocb, struct sock *sk,
98293 int is_udp4;
98294 bool slow;
98295
98296 + if (addr_len)
98297 + *addr_len = sizeof(struct sockaddr_in6);
98298 +
98299 if (flags & MSG_ERRQUEUE)
98300 return ipv6_recv_error(sk, msg, len, addr_len);
98301
98302 @@ -435,7 +442,7 @@ try_again:
98303 if (unlikely(err)) {
98304 trace_kfree_skb(skb, udpv6_recvmsg);
98305 if (!peeked) {
98306 - atomic_inc(&sk->sk_drops);
98307 + atomic_inc_unchecked(&sk->sk_drops);
98308 if (is_udp4)
98309 UDP_INC_STATS_USER(sock_net(sk),
98310 UDP_MIB_INERRORS,
98311 @@ -477,7 +484,7 @@ try_again:
98312 ipv6_iface_scope_id(&sin6->sin6_addr,
98313 IP6CB(skb)->iif);
98314 }
98315 - *addr_len = sizeof(*sin6);
98316 +
98317 }
98318 if (is_udp4) {
98319 if (inet->cmsg_flags)
98320 @@ -685,7 +692,7 @@ csum_error:
98321 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_CSUMERRORS, is_udplite);
98322 drop:
98323 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS, is_udplite);
98324 - atomic_inc(&sk->sk_drops);
98325 + atomic_inc_unchecked(&sk->sk_drops);
98326 kfree_skb(skb);
98327 return -1;
98328 }
98329 @@ -742,7 +749,7 @@ static void flush_stack(struct sock **stack, unsigned int count,
98330 if (likely(skb1 == NULL))
98331 skb1 = (i == final) ? skb : skb_clone(skb, GFP_ATOMIC);
98332 if (!skb1) {
98333 - atomic_inc(&sk->sk_drops);
98334 + atomic_inc_unchecked(&sk->sk_drops);
98335 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_RCVBUFERRORS,
98336 IS_UDPLITE(sk));
98337 UDP6_INC_STATS_BH(sock_net(sk), UDP_MIB_INERRORS,
98338 @@ -881,6 +888,9 @@ int __udp6_lib_rcv(struct sk_buff *skb, struct udp_table *udptable,
98339 goto csum_error;
98340
98341 UDP6_INC_STATS_BH(net, UDP_MIB_NOPORTS, proto == IPPROTO_UDPLITE);
98342 +#ifdef CONFIG_GRKERNSEC_BLACKHOLE
98343 + if (!grsec_enable_blackhole || (skb->dev->flags & IFF_LOOPBACK))
98344 +#endif
98345 icmpv6_send(skb, ICMPV6_DEST_UNREACH, ICMPV6_PORT_UNREACH, 0);
98346
98347 kfree_skb(skb);
98348 diff --git a/net/ipv6/xfrm6_policy.c b/net/ipv6/xfrm6_policy.c
98349 index 5f8e128..865d38e 100644
98350 --- a/net/ipv6/xfrm6_policy.c
98351 +++ b/net/ipv6/xfrm6_policy.c
98352 @@ -212,11 +212,11 @@ _decode_session6(struct sk_buff *skb, struct flowi *fl, int reverse)
98353 }
98354 }
98355
98356 -static inline int xfrm6_garbage_collect(struct dst_ops *ops)
98357 +static int xfrm6_garbage_collect(struct dst_ops *ops)
98358 {
98359 struct net *net = container_of(ops, struct net, xfrm.xfrm6_dst_ops);
98360
98361 - xfrm6_policy_afinfo.garbage_collect(net);
98362 + xfrm_garbage_collect_deferred(net);
98363 return dst_entries_get_fast(ops) > ops->gc_thresh * 2;
98364 }
98365
98366 @@ -329,19 +329,19 @@ static struct ctl_table xfrm6_policy_table[] = {
98367
98368 static int __net_init xfrm6_net_init(struct net *net)
98369 {
98370 - struct ctl_table *table;
98371 + ctl_table_no_const *table = NULL;
98372 struct ctl_table_header *hdr;
98373
98374 - table = xfrm6_policy_table;
98375 if (!net_eq(net, &init_net)) {
98376 - table = kmemdup(table, sizeof(xfrm6_policy_table), GFP_KERNEL);
98377 + table = kmemdup(xfrm6_policy_table, sizeof(xfrm6_policy_table), GFP_KERNEL);
98378 if (!table)
98379 goto err_alloc;
98380
98381 table[0].data = &net->xfrm.xfrm6_dst_ops.gc_thresh;
98382 - }
98383 + hdr = register_net_sysctl(net, "net/ipv6", table);
98384 + } else
98385 + hdr = register_net_sysctl(net, "net/ipv6", xfrm6_policy_table);
98386
98387 - hdr = register_net_sysctl(net, "net/ipv6", table);
98388 if (!hdr)
98389 goto err_reg;
98390
98391 @@ -349,8 +349,7 @@ static int __net_init xfrm6_net_init(struct net *net)
98392 return 0;
98393
98394 err_reg:
98395 - if (!net_eq(net, &init_net))
98396 - kfree(table);
98397 + kfree(table);
98398 err_alloc:
98399 return -ENOMEM;
98400 }
98401 diff --git a/net/irda/ircomm/ircomm_tty.c b/net/irda/ircomm/ircomm_tty.c
98402 index 41ac7938..75e3bb1 100644
98403 --- a/net/irda/ircomm/ircomm_tty.c
98404 +++ b/net/irda/ircomm/ircomm_tty.c
98405 @@ -319,11 +319,11 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
98406 add_wait_queue(&port->open_wait, &wait);
98407
98408 IRDA_DEBUG(2, "%s(%d):block_til_ready before block on %s open_count=%d\n",
98409 - __FILE__, __LINE__, tty->driver->name, port->count);
98410 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
98411
98412 spin_lock_irqsave(&port->lock, flags);
98413 if (!tty_hung_up_p(filp))
98414 - port->count--;
98415 + atomic_dec(&port->count);
98416 port->blocked_open++;
98417 spin_unlock_irqrestore(&port->lock, flags);
98418
98419 @@ -358,7 +358,7 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
98420 }
98421
98422 IRDA_DEBUG(1, "%s(%d):block_til_ready blocking on %s open_count=%d\n",
98423 - __FILE__, __LINE__, tty->driver->name, port->count);
98424 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
98425
98426 schedule();
98427 }
98428 @@ -368,12 +368,12 @@ static int ircomm_tty_block_til_ready(struct ircomm_tty_cb *self,
98429
98430 spin_lock_irqsave(&port->lock, flags);
98431 if (!tty_hung_up_p(filp))
98432 - port->count++;
98433 + atomic_inc(&port->count);
98434 port->blocked_open--;
98435 spin_unlock_irqrestore(&port->lock, flags);
98436
98437 IRDA_DEBUG(1, "%s(%d):block_til_ready after blocking on %s open_count=%d\n",
98438 - __FILE__, __LINE__, tty->driver->name, port->count);
98439 + __FILE__, __LINE__, tty->driver->name, atomic_read(&port->count));
98440
98441 if (!retval)
98442 port->flags |= ASYNC_NORMAL_ACTIVE;
98443 @@ -447,12 +447,12 @@ static int ircomm_tty_open(struct tty_struct *tty, struct file *filp)
98444
98445 /* ++ is not atomic, so this should be protected - Jean II */
98446 spin_lock_irqsave(&self->port.lock, flags);
98447 - self->port.count++;
98448 + atomic_inc(&self->port.count);
98449 spin_unlock_irqrestore(&self->port.lock, flags);
98450 tty_port_tty_set(&self->port, tty);
98451
98452 IRDA_DEBUG(1, "%s(), %s%d, count = %d\n", __func__ , tty->driver->name,
98453 - self->line, self->port.count);
98454 + self->line, atomic_read(&self->port.count));
98455
98456 /* Not really used by us, but lets do it anyway */
98457 self->port.low_latency = (self->port.flags & ASYNC_LOW_LATENCY) ? 1 : 0;
98458 @@ -989,7 +989,7 @@ static void ircomm_tty_hangup(struct tty_struct *tty)
98459 tty_kref_put(port->tty);
98460 }
98461 port->tty = NULL;
98462 - port->count = 0;
98463 + atomic_set(&port->count, 0);
98464 spin_unlock_irqrestore(&port->lock, flags);
98465
98466 wake_up_interruptible(&port->open_wait);
98467 @@ -1346,7 +1346,7 @@ static void ircomm_tty_line_info(struct ircomm_tty_cb *self, struct seq_file *m)
98468 seq_putc(m, '\n');
98469
98470 seq_printf(m, "Role: %s\n", self->client ? "client" : "server");
98471 - seq_printf(m, "Open count: %d\n", self->port.count);
98472 + seq_printf(m, "Open count: %d\n", atomic_read(&self->port.count));
98473 seq_printf(m, "Max data size: %d\n", self->max_data_size);
98474 seq_printf(m, "Max header size: %d\n", self->max_header_size);
98475
98476 diff --git a/net/iucv/af_iucv.c b/net/iucv/af_iucv.c
98477 index c4b7218..3e83259 100644
98478 --- a/net/iucv/af_iucv.c
98479 +++ b/net/iucv/af_iucv.c
98480 @@ -773,10 +773,10 @@ static int iucv_sock_autobind(struct sock *sk)
98481
98482 write_lock_bh(&iucv_sk_list.lock);
98483
98484 - sprintf(name, "%08x", atomic_inc_return(&iucv_sk_list.autobind_name));
98485 + sprintf(name, "%08x", atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
98486 while (__iucv_get_sock_by_name(name)) {
98487 sprintf(name, "%08x",
98488 - atomic_inc_return(&iucv_sk_list.autobind_name));
98489 + atomic_inc_return_unchecked(&iucv_sk_list.autobind_name));
98490 }
98491
98492 write_unlock_bh(&iucv_sk_list.lock);
98493 diff --git a/net/iucv/iucv.c b/net/iucv/iucv.c
98494 index cd5b8ec..f205e6b 100644
98495 --- a/net/iucv/iucv.c
98496 +++ b/net/iucv/iucv.c
98497 @@ -690,7 +690,7 @@ static int iucv_cpu_notify(struct notifier_block *self,
98498 return NOTIFY_OK;
98499 }
98500
98501 -static struct notifier_block __refdata iucv_cpu_notifier = {
98502 +static struct notifier_block iucv_cpu_notifier = {
98503 .notifier_call = iucv_cpu_notify,
98504 };
98505
98506 diff --git a/net/key/af_key.c b/net/key/af_key.c
98507 index 545f047..9757a9d 100644
98508 --- a/net/key/af_key.c
98509 +++ b/net/key/af_key.c
98510 @@ -3041,10 +3041,10 @@ static int pfkey_send_policy_notify(struct xfrm_policy *xp, int dir, const struc
98511 static u32 get_acqseq(void)
98512 {
98513 u32 res;
98514 - static atomic_t acqseq;
98515 + static atomic_unchecked_t acqseq;
98516
98517 do {
98518 - res = atomic_inc_return(&acqseq);
98519 + res = atomic_inc_return_unchecked(&acqseq);
98520 } while (!res);
98521 return res;
98522 }
98523 diff --git a/net/l2tp/l2tp_ip.c b/net/l2tp/l2tp_ip.c
98524 index da1a1ce..571db8d 100644
98525 --- a/net/l2tp/l2tp_ip.c
98526 +++ b/net/l2tp/l2tp_ip.c
98527 @@ -518,6 +518,9 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
98528 if (flags & MSG_OOB)
98529 goto out;
98530
98531 + if (addr_len)
98532 + *addr_len = sizeof(*sin);
98533 +
98534 skb = skb_recv_datagram(sk, flags, noblock, &err);
98535 if (!skb)
98536 goto out;
98537 @@ -540,7 +543,6 @@ static int l2tp_ip_recvmsg(struct kiocb *iocb, struct sock *sk, struct msghdr *m
98538 sin->sin_addr.s_addr = ip_hdr(skb)->saddr;
98539 sin->sin_port = 0;
98540 memset(&sin->sin_zero, 0, sizeof(sin->sin_zero));
98541 - *addr_len = sizeof(*sin);
98542 }
98543 if (inet->cmsg_flags)
98544 ip_cmsg_recv(msg, skb);
98545 diff --git a/net/mac80211/cfg.c b/net/mac80211/cfg.c
98546 index 364ce0c..3ebb5a4 100644
98547 --- a/net/mac80211/cfg.c
98548 +++ b/net/mac80211/cfg.c
98549 @@ -826,7 +826,7 @@ static int ieee80211_set_monitor_channel(struct wiphy *wiphy,
98550 ret = ieee80211_vif_use_channel(sdata, chandef,
98551 IEEE80211_CHANCTX_EXCLUSIVE);
98552 }
98553 - } else if (local->open_count == local->monitors) {
98554 + } else if (local_read(&local->open_count) == local->monitors) {
98555 local->_oper_chandef = *chandef;
98556 ieee80211_hw_config(local, 0);
98557 }
98558 @@ -3308,7 +3308,7 @@ static void ieee80211_mgmt_frame_register(struct wiphy *wiphy,
98559 else
98560 local->probe_req_reg--;
98561
98562 - if (!local->open_count)
98563 + if (!local_read(&local->open_count))
98564 break;
98565
98566 ieee80211_queue_work(&local->hw, &local->reconfig_filter);
98567 @@ -3771,8 +3771,8 @@ static int ieee80211_cfg_get_channel(struct wiphy *wiphy,
98568 if (chanctx_conf) {
98569 *chandef = chanctx_conf->def;
98570 ret = 0;
98571 - } else if (local->open_count > 0 &&
98572 - local->open_count == local->monitors &&
98573 + } else if (local_read(&local->open_count) > 0 &&
98574 + local_read(&local->open_count) == local->monitors &&
98575 sdata->vif.type == NL80211_IFTYPE_MONITOR) {
98576 if (local->use_chanctx)
98577 *chandef = local->monitor_chandef;
98578 diff --git a/net/mac80211/ieee80211_i.h b/net/mac80211/ieee80211_i.h
98579 index 4aea4e7..9e698d1 100644
98580 --- a/net/mac80211/ieee80211_i.h
98581 +++ b/net/mac80211/ieee80211_i.h
98582 @@ -28,6 +28,7 @@
98583 #include <net/ieee80211_radiotap.h>
98584 #include <net/cfg80211.h>
98585 #include <net/mac80211.h>
98586 +#include <asm/local.h>
98587 #include "key.h"
98588 #include "sta_info.h"
98589 #include "debug.h"
98590 @@ -961,7 +962,7 @@ struct ieee80211_local {
98591 /* also used to protect ampdu_ac_queue and amdpu_ac_stop_refcnt */
98592 spinlock_t queue_stop_reason_lock;
98593
98594 - int open_count;
98595 + local_t open_count;
98596 int monitors, cooked_mntrs;
98597 /* number of interfaces with corresponding FIF_ flags */
98598 int fif_fcsfail, fif_plcpfail, fif_control, fif_other_bss, fif_pspoll,
98599 diff --git a/net/mac80211/iface.c b/net/mac80211/iface.c
98600 index a075791..1d0027f 100644
98601 --- a/net/mac80211/iface.c
98602 +++ b/net/mac80211/iface.c
98603 @@ -519,7 +519,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98604 break;
98605 }
98606
98607 - if (local->open_count == 0) {
98608 + if (local_read(&local->open_count) == 0) {
98609 res = drv_start(local);
98610 if (res)
98611 goto err_del_bss;
98612 @@ -566,7 +566,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98613 res = drv_add_interface(local, sdata);
98614 if (res)
98615 goto err_stop;
98616 - } else if (local->monitors == 0 && local->open_count == 0) {
98617 + } else if (local->monitors == 0 && local_read(&local->open_count) == 0) {
98618 res = ieee80211_add_virtual_monitor(local);
98619 if (res)
98620 goto err_stop;
98621 @@ -675,7 +675,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98622 atomic_inc(&local->iff_promiscs);
98623
98624 if (coming_up)
98625 - local->open_count++;
98626 + local_inc(&local->open_count);
98627
98628 if (hw_reconf_flags)
98629 ieee80211_hw_config(local, hw_reconf_flags);
98630 @@ -713,7 +713,7 @@ int ieee80211_do_open(struct wireless_dev *wdev, bool coming_up)
98631 err_del_interface:
98632 drv_remove_interface(local, sdata);
98633 err_stop:
98634 - if (!local->open_count)
98635 + if (!local_read(&local->open_count))
98636 drv_stop(local);
98637 err_del_bss:
98638 sdata->bss = NULL;
98639 @@ -856,7 +856,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98640 }
98641
98642 if (going_down)
98643 - local->open_count--;
98644 + local_dec(&local->open_count);
98645
98646 switch (sdata->vif.type) {
98647 case NL80211_IFTYPE_AP_VLAN:
98648 @@ -923,7 +923,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98649 }
98650 spin_unlock_irqrestore(&local->queue_stop_reason_lock, flags);
98651
98652 - if (local->open_count == 0)
98653 + if (local_read(&local->open_count) == 0)
98654 ieee80211_clear_tx_pending(local);
98655
98656 /*
98657 @@ -963,7 +963,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98658
98659 ieee80211_recalc_ps(local, -1);
98660
98661 - if (local->open_count == 0) {
98662 + if (local_read(&local->open_count) == 0) {
98663 ieee80211_stop_device(local);
98664
98665 /* no reconfiguring after stop! */
98666 @@ -974,7 +974,7 @@ static void ieee80211_do_stop(struct ieee80211_sub_if_data *sdata,
98667 ieee80211_configure_filter(local);
98668 ieee80211_hw_config(local, hw_reconf_flags);
98669
98670 - if (local->monitors == local->open_count)
98671 + if (local->monitors == local_read(&local->open_count))
98672 ieee80211_add_virtual_monitor(local);
98673 }
98674
98675 diff --git a/net/mac80211/main.c b/net/mac80211/main.c
98676 index 7d1c3ac..b62dd29 100644
98677 --- a/net/mac80211/main.c
98678 +++ b/net/mac80211/main.c
98679 @@ -172,7 +172,7 @@ int ieee80211_hw_config(struct ieee80211_local *local, u32 changed)
98680 changed &= ~(IEEE80211_CONF_CHANGE_CHANNEL |
98681 IEEE80211_CONF_CHANGE_POWER);
98682
98683 - if (changed && local->open_count) {
98684 + if (changed && local_read(&local->open_count)) {
98685 ret = drv_config(local, changed);
98686 /*
98687 * Goal:
98688 diff --git a/net/mac80211/pm.c b/net/mac80211/pm.c
98689 index 3401262..d5cd68d 100644
98690 --- a/net/mac80211/pm.c
98691 +++ b/net/mac80211/pm.c
98692 @@ -12,7 +12,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
98693 struct ieee80211_sub_if_data *sdata;
98694 struct sta_info *sta;
98695
98696 - if (!local->open_count)
98697 + if (!local_read(&local->open_count))
98698 goto suspend;
98699
98700 ieee80211_scan_cancel(local);
98701 @@ -59,7 +59,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
98702 cancel_work_sync(&local->dynamic_ps_enable_work);
98703 del_timer_sync(&local->dynamic_ps_timer);
98704
98705 - local->wowlan = wowlan && local->open_count;
98706 + local->wowlan = wowlan && local_read(&local->open_count);
98707 if (local->wowlan) {
98708 int err = drv_suspend(local, wowlan);
98709 if (err < 0) {
98710 @@ -116,7 +116,7 @@ int __ieee80211_suspend(struct ieee80211_hw *hw, struct cfg80211_wowlan *wowlan)
98711 WARN_ON(!list_empty(&local->chanctx_list));
98712
98713 /* stop hardware - this must stop RX */
98714 - if (local->open_count)
98715 + if (local_read(&local->open_count))
98716 ieee80211_stop_device(local);
98717
98718 suspend:
98719 diff --git a/net/mac80211/rate.c b/net/mac80211/rate.c
98720 index 22b223f..ab70070 100644
98721 --- a/net/mac80211/rate.c
98722 +++ b/net/mac80211/rate.c
98723 @@ -734,7 +734,7 @@ int ieee80211_init_rate_ctrl_alg(struct ieee80211_local *local,
98724
98725 ASSERT_RTNL();
98726
98727 - if (local->open_count)
98728 + if (local_read(&local->open_count))
98729 return -EBUSY;
98730
98731 if (local->hw.flags & IEEE80211_HW_HAS_RATE_CONTROL) {
98732 diff --git a/net/mac80211/rc80211_pid_debugfs.c b/net/mac80211/rc80211_pid_debugfs.c
98733 index 6ff1346..936ca9a 100644
98734 --- a/net/mac80211/rc80211_pid_debugfs.c
98735 +++ b/net/mac80211/rc80211_pid_debugfs.c
98736 @@ -193,7 +193,7 @@ static ssize_t rate_control_pid_events_read(struct file *file, char __user *buf,
98737
98738 spin_unlock_irqrestore(&events->lock, status);
98739
98740 - if (copy_to_user(buf, pb, p))
98741 + if (p > sizeof(pb) || copy_to_user(buf, pb, p))
98742 return -EFAULT;
98743
98744 return p;
98745 diff --git a/net/mac80211/util.c b/net/mac80211/util.c
98746 index 9f9b9bd..d6fcf59 100644
98747 --- a/net/mac80211/util.c
98748 +++ b/net/mac80211/util.c
98749 @@ -1474,7 +1474,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
98750 }
98751 #endif
98752 /* everything else happens only if HW was up & running */
98753 - if (!local->open_count)
98754 + if (!local_read(&local->open_count))
98755 goto wake_up;
98756
98757 /*
98758 @@ -1699,7 +1699,7 @@ int ieee80211_reconfig(struct ieee80211_local *local)
98759 local->in_reconfig = false;
98760 barrier();
98761
98762 - if (local->monitors == local->open_count && local->monitors > 0)
98763 + if (local->monitors == local_read(&local->open_count) && local->monitors > 0)
98764 ieee80211_add_virtual_monitor(local);
98765
98766 /*
98767 diff --git a/net/netfilter/Kconfig b/net/netfilter/Kconfig
98768 index c3398cd..98ad3b4 100644
98769 --- a/net/netfilter/Kconfig
98770 +++ b/net/netfilter/Kconfig
98771 @@ -1002,6 +1002,16 @@ config NETFILTER_XT_MATCH_ESP
98772
98773 To compile it as a module, choose M here. If unsure, say N.
98774
98775 +config NETFILTER_XT_MATCH_GRADM
98776 + tristate '"gradm" match support'
98777 + depends on NETFILTER_XTABLES && NETFILTER_ADVANCED
98778 + depends on GRKERNSEC && !GRKERNSEC_NO_RBAC
98779 + ---help---
98780 + The gradm match allows to match on grsecurity RBAC being enabled.
98781 + It is useful when iptables rules are applied early on bootup to
98782 + prevent connections to the machine (except from a trusted host)
98783 + while the RBAC system is disabled.
98784 +
98785 config NETFILTER_XT_MATCH_HASHLIMIT
98786 tristate '"hashlimit" match support'
98787 depends on (IP6_NF_IPTABLES || IP6_NF_IPTABLES=n)
98788 diff --git a/net/netfilter/Makefile b/net/netfilter/Makefile
98789 index 394483b..ed51f2d 100644
98790 --- a/net/netfilter/Makefile
98791 +++ b/net/netfilter/Makefile
98792 @@ -130,6 +130,7 @@ obj-$(CONFIG_NETFILTER_XT_MATCH_DEVGROUP) += xt_devgroup.o
98793 obj-$(CONFIG_NETFILTER_XT_MATCH_DSCP) += xt_dscp.o
98794 obj-$(CONFIG_NETFILTER_XT_MATCH_ECN) += xt_ecn.o
98795 obj-$(CONFIG_NETFILTER_XT_MATCH_ESP) += xt_esp.o
98796 +obj-$(CONFIG_NETFILTER_XT_MATCH_GRADM) += xt_gradm.o
98797 obj-$(CONFIG_NETFILTER_XT_MATCH_HASHLIMIT) += xt_hashlimit.o
98798 obj-$(CONFIG_NETFILTER_XT_MATCH_HELPER) += xt_helper.o
98799 obj-$(CONFIG_NETFILTER_XT_MATCH_HL) += xt_hl.o
98800 diff --git a/net/netfilter/ipset/ip_set_core.c b/net/netfilter/ipset/ip_set_core.c
98801 index bac7e01..1d7a31a 100644
98802 --- a/net/netfilter/ipset/ip_set_core.c
98803 +++ b/net/netfilter/ipset/ip_set_core.c
98804 @@ -1950,7 +1950,7 @@ done:
98805 return ret;
98806 }
98807
98808 -static struct nf_sockopt_ops so_set __read_mostly = {
98809 +static struct nf_sockopt_ops so_set = {
98810 .pf = PF_INET,
98811 .get_optmin = SO_IP_SET,
98812 .get_optmax = SO_IP_SET + 1,
98813 diff --git a/net/netfilter/ipvs/ip_vs_conn.c b/net/netfilter/ipvs/ip_vs_conn.c
98814 index 4c8e5c0..5a79b4d 100644
98815 --- a/net/netfilter/ipvs/ip_vs_conn.c
98816 +++ b/net/netfilter/ipvs/ip_vs_conn.c
98817 @@ -556,7 +556,7 @@ ip_vs_bind_dest(struct ip_vs_conn *cp, struct ip_vs_dest *dest)
98818 /* Increase the refcnt counter of the dest */
98819 ip_vs_dest_hold(dest);
98820
98821 - conn_flags = atomic_read(&dest->conn_flags);
98822 + conn_flags = atomic_read_unchecked(&dest->conn_flags);
98823 if (cp->protocol != IPPROTO_UDP)
98824 conn_flags &= ~IP_VS_CONN_F_ONE_PACKET;
98825 flags = cp->flags;
98826 @@ -900,7 +900,7 @@ ip_vs_conn_new(const struct ip_vs_conn_param *p,
98827
98828 cp->control = NULL;
98829 atomic_set(&cp->n_control, 0);
98830 - atomic_set(&cp->in_pkts, 0);
98831 + atomic_set_unchecked(&cp->in_pkts, 0);
98832
98833 cp->packet_xmit = NULL;
98834 cp->app = NULL;
98835 @@ -1188,7 +1188,7 @@ static inline int todrop_entry(struct ip_vs_conn *cp)
98836
98837 /* Don't drop the entry if its number of incoming packets is not
98838 located in [0, 8] */
98839 - i = atomic_read(&cp->in_pkts);
98840 + i = atomic_read_unchecked(&cp->in_pkts);
98841 if (i > 8 || i < 0) return 0;
98842
98843 if (!todrop_rate[i]) return 0;
98844 diff --git a/net/netfilter/ipvs/ip_vs_core.c b/net/netfilter/ipvs/ip_vs_core.c
98845 index 4f26ee4..6a9d7c3 100644
98846 --- a/net/netfilter/ipvs/ip_vs_core.c
98847 +++ b/net/netfilter/ipvs/ip_vs_core.c
98848 @@ -567,7 +567,7 @@ int ip_vs_leave(struct ip_vs_service *svc, struct sk_buff *skb,
98849 ret = cp->packet_xmit(skb, cp, pd->pp, iph);
98850 /* do not touch skb anymore */
98851
98852 - atomic_inc(&cp->in_pkts);
98853 + atomic_inc_unchecked(&cp->in_pkts);
98854 ip_vs_conn_put(cp);
98855 return ret;
98856 }
98857 @@ -1706,7 +1706,7 @@ ip_vs_in(unsigned int hooknum, struct sk_buff *skb, int af)
98858 if (cp->flags & IP_VS_CONN_F_ONE_PACKET)
98859 pkts = sysctl_sync_threshold(ipvs);
98860 else
98861 - pkts = atomic_add_return(1, &cp->in_pkts);
98862 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
98863
98864 if (ipvs->sync_state & IP_VS_STATE_MASTER)
98865 ip_vs_sync_conn(net, cp, pkts);
98866 diff --git a/net/netfilter/ipvs/ip_vs_ctl.c b/net/netfilter/ipvs/ip_vs_ctl.c
98867 index 35be035..dad174b 100644
98868 --- a/net/netfilter/ipvs/ip_vs_ctl.c
98869 +++ b/net/netfilter/ipvs/ip_vs_ctl.c
98870 @@ -794,7 +794,7 @@ __ip_vs_update_dest(struct ip_vs_service *svc, struct ip_vs_dest *dest,
98871 */
98872 ip_vs_rs_hash(ipvs, dest);
98873 }
98874 - atomic_set(&dest->conn_flags, conn_flags);
98875 + atomic_set_unchecked(&dest->conn_flags, conn_flags);
98876
98877 /* bind the service */
98878 old_svc = rcu_dereference_protected(dest->svc, 1);
98879 @@ -1654,7 +1654,7 @@ proc_do_sync_ports(struct ctl_table *table, int write,
98880 * align with netns init in ip_vs_control_net_init()
98881 */
98882
98883 -static struct ctl_table vs_vars[] = {
98884 +static ctl_table_no_const vs_vars[] __read_only = {
98885 {
98886 .procname = "amemthresh",
98887 .maxlen = sizeof(int),
98888 @@ -2075,7 +2075,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
98889 " %-7s %-6d %-10d %-10d\n",
98890 &dest->addr.in6,
98891 ntohs(dest->port),
98892 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
98893 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
98894 atomic_read(&dest->weight),
98895 atomic_read(&dest->activeconns),
98896 atomic_read(&dest->inactconns));
98897 @@ -2086,7 +2086,7 @@ static int ip_vs_info_seq_show(struct seq_file *seq, void *v)
98898 "%-7s %-6d %-10d %-10d\n",
98899 ntohl(dest->addr.ip),
98900 ntohs(dest->port),
98901 - ip_vs_fwd_name(atomic_read(&dest->conn_flags)),
98902 + ip_vs_fwd_name(atomic_read_unchecked(&dest->conn_flags)),
98903 atomic_read(&dest->weight),
98904 atomic_read(&dest->activeconns),
98905 atomic_read(&dest->inactconns));
98906 @@ -2564,7 +2564,7 @@ __ip_vs_get_dest_entries(struct net *net, const struct ip_vs_get_dests *get,
98907
98908 entry.addr = dest->addr.ip;
98909 entry.port = dest->port;
98910 - entry.conn_flags = atomic_read(&dest->conn_flags);
98911 + entry.conn_flags = atomic_read_unchecked(&dest->conn_flags);
98912 entry.weight = atomic_read(&dest->weight);
98913 entry.u_threshold = dest->u_threshold;
98914 entry.l_threshold = dest->l_threshold;
98915 @@ -3107,7 +3107,7 @@ static int ip_vs_genl_fill_dest(struct sk_buff *skb, struct ip_vs_dest *dest)
98916 if (nla_put(skb, IPVS_DEST_ATTR_ADDR, sizeof(dest->addr), &dest->addr) ||
98917 nla_put_be16(skb, IPVS_DEST_ATTR_PORT, dest->port) ||
98918 nla_put_u32(skb, IPVS_DEST_ATTR_FWD_METHOD,
98919 - (atomic_read(&dest->conn_flags) &
98920 + (atomic_read_unchecked(&dest->conn_flags) &
98921 IP_VS_CONN_F_FWD_MASK)) ||
98922 nla_put_u32(skb, IPVS_DEST_ATTR_WEIGHT,
98923 atomic_read(&dest->weight)) ||
98924 @@ -3697,7 +3697,7 @@ static int __net_init ip_vs_control_net_init_sysctl(struct net *net)
98925 {
98926 int idx;
98927 struct netns_ipvs *ipvs = net_ipvs(net);
98928 - struct ctl_table *tbl;
98929 + ctl_table_no_const *tbl;
98930
98931 atomic_set(&ipvs->dropentry, 0);
98932 spin_lock_init(&ipvs->dropentry_lock);
98933 diff --git a/net/netfilter/ipvs/ip_vs_lblc.c b/net/netfilter/ipvs/ip_vs_lblc.c
98934 index ca056a3..9cf01ef 100644
98935 --- a/net/netfilter/ipvs/ip_vs_lblc.c
98936 +++ b/net/netfilter/ipvs/ip_vs_lblc.c
98937 @@ -118,7 +118,7 @@ struct ip_vs_lblc_table {
98938 * IPVS LBLC sysctl table
98939 */
98940 #ifdef CONFIG_SYSCTL
98941 -static struct ctl_table vs_vars_table[] = {
98942 +static ctl_table_no_const vs_vars_table[] __read_only = {
98943 {
98944 .procname = "lblc_expiration",
98945 .data = NULL,
98946 diff --git a/net/netfilter/ipvs/ip_vs_lblcr.c b/net/netfilter/ipvs/ip_vs_lblcr.c
98947 index 3f21a2f..a112e85 100644
98948 --- a/net/netfilter/ipvs/ip_vs_lblcr.c
98949 +++ b/net/netfilter/ipvs/ip_vs_lblcr.c
98950 @@ -289,7 +289,7 @@ struct ip_vs_lblcr_table {
98951 * IPVS LBLCR sysctl table
98952 */
98953
98954 -static struct ctl_table vs_vars_table[] = {
98955 +static ctl_table_no_const vs_vars_table[] __read_only = {
98956 {
98957 .procname = "lblcr_expiration",
98958 .data = NULL,
98959 diff --git a/net/netfilter/ipvs/ip_vs_sync.c b/net/netfilter/ipvs/ip_vs_sync.c
98960 index f63c238..1b87f8a 100644
98961 --- a/net/netfilter/ipvs/ip_vs_sync.c
98962 +++ b/net/netfilter/ipvs/ip_vs_sync.c
98963 @@ -609,7 +609,7 @@ static void ip_vs_sync_conn_v0(struct net *net, struct ip_vs_conn *cp,
98964 cp = cp->control;
98965 if (cp) {
98966 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
98967 - pkts = atomic_add_return(1, &cp->in_pkts);
98968 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
98969 else
98970 pkts = sysctl_sync_threshold(ipvs);
98971 ip_vs_sync_conn(net, cp->control, pkts);
98972 @@ -771,7 +771,7 @@ control:
98973 if (!cp)
98974 return;
98975 if (cp->flags & IP_VS_CONN_F_TEMPLATE)
98976 - pkts = atomic_add_return(1, &cp->in_pkts);
98977 + pkts = atomic_add_return_unchecked(1, &cp->in_pkts);
98978 else
98979 pkts = sysctl_sync_threshold(ipvs);
98980 goto sloop;
98981 @@ -895,7 +895,7 @@ static void ip_vs_proc_conn(struct net *net, struct ip_vs_conn_param *param,
98982
98983 if (opt)
98984 memcpy(&cp->in_seq, opt, sizeof(*opt));
98985 - atomic_set(&cp->in_pkts, sysctl_sync_threshold(ipvs));
98986 + atomic_set_unchecked(&cp->in_pkts, sysctl_sync_threshold(ipvs));
98987 cp->state = state;
98988 cp->old_state = cp->state;
98989 /*
98990 diff --git a/net/netfilter/ipvs/ip_vs_xmit.c b/net/netfilter/ipvs/ip_vs_xmit.c
98991 index c47444e..b0961c6 100644
98992 --- a/net/netfilter/ipvs/ip_vs_xmit.c
98993 +++ b/net/netfilter/ipvs/ip_vs_xmit.c
98994 @@ -1102,7 +1102,7 @@ ip_vs_icmp_xmit(struct sk_buff *skb, struct ip_vs_conn *cp,
98995 else
98996 rc = NF_ACCEPT;
98997 /* do not touch skb anymore */
98998 - atomic_inc(&cp->in_pkts);
98999 + atomic_inc_unchecked(&cp->in_pkts);
99000 goto out;
99001 }
99002
99003 @@ -1194,7 +1194,7 @@ ip_vs_icmp_xmit_v6(struct sk_buff *skb, struct ip_vs_conn *cp,
99004 else
99005 rc = NF_ACCEPT;
99006 /* do not touch skb anymore */
99007 - atomic_inc(&cp->in_pkts);
99008 + atomic_inc_unchecked(&cp->in_pkts);
99009 goto out;
99010 }
99011
99012 diff --git a/net/netfilter/nf_conntrack_acct.c b/net/netfilter/nf_conntrack_acct.c
99013 index a4b5e2a..13b1de3 100644
99014 --- a/net/netfilter/nf_conntrack_acct.c
99015 +++ b/net/netfilter/nf_conntrack_acct.c
99016 @@ -62,7 +62,7 @@ static struct nf_ct_ext_type acct_extend __read_mostly = {
99017 #ifdef CONFIG_SYSCTL
99018 static int nf_conntrack_acct_init_sysctl(struct net *net)
99019 {
99020 - struct ctl_table *table;
99021 + ctl_table_no_const *table;
99022
99023 table = kmemdup(acct_sysctl_table, sizeof(acct_sysctl_table),
99024 GFP_KERNEL);
99025 diff --git a/net/netfilter/nf_conntrack_core.c b/net/netfilter/nf_conntrack_core.c
99026 index 43549eb..0bbeace 100644
99027 --- a/net/netfilter/nf_conntrack_core.c
99028 +++ b/net/netfilter/nf_conntrack_core.c
99029 @@ -1605,6 +1605,10 @@ void nf_conntrack_init_end(void)
99030 #define DYING_NULLS_VAL ((1<<30)+1)
99031 #define TEMPLATE_NULLS_VAL ((1<<30)+2)
99032
99033 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99034 +static atomic_unchecked_t conntrack_cache_id = ATOMIC_INIT(0);
99035 +#endif
99036 +
99037 int nf_conntrack_init_net(struct net *net)
99038 {
99039 int ret;
99040 @@ -1619,7 +1623,11 @@ int nf_conntrack_init_net(struct net *net)
99041 goto err_stat;
99042 }
99043
99044 +#ifdef CONFIG_GRKERNSEC_HIDESYM
99045 + net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%08lx", atomic_inc_return_unchecked(&conntrack_cache_id));
99046 +#else
99047 net->ct.slabname = kasprintf(GFP_KERNEL, "nf_conntrack_%p", net);
99048 +#endif
99049 if (!net->ct.slabname) {
99050 ret = -ENOMEM;
99051 goto err_slabname;
99052 diff --git a/net/netfilter/nf_conntrack_ecache.c b/net/netfilter/nf_conntrack_ecache.c
99053 index 1df1761..ce8b88a 100644
99054 --- a/net/netfilter/nf_conntrack_ecache.c
99055 +++ b/net/netfilter/nf_conntrack_ecache.c
99056 @@ -188,7 +188,7 @@ static struct nf_ct_ext_type event_extend __read_mostly = {
99057 #ifdef CONFIG_SYSCTL
99058 static int nf_conntrack_event_init_sysctl(struct net *net)
99059 {
99060 - struct ctl_table *table;
99061 + ctl_table_no_const *table;
99062
99063 table = kmemdup(event_sysctl_table, sizeof(event_sysctl_table),
99064 GFP_KERNEL);
99065 diff --git a/net/netfilter/nf_conntrack_helper.c b/net/netfilter/nf_conntrack_helper.c
99066 index 974a2a4..52cc6ff 100644
99067 --- a/net/netfilter/nf_conntrack_helper.c
99068 +++ b/net/netfilter/nf_conntrack_helper.c
99069 @@ -57,7 +57,7 @@ static struct ctl_table helper_sysctl_table[] = {
99070
99071 static int nf_conntrack_helper_init_sysctl(struct net *net)
99072 {
99073 - struct ctl_table *table;
99074 + ctl_table_no_const *table;
99075
99076 table = kmemdup(helper_sysctl_table, sizeof(helper_sysctl_table),
99077 GFP_KERNEL);
99078 diff --git a/net/netfilter/nf_conntrack_proto.c b/net/netfilter/nf_conntrack_proto.c
99079 index ce30041..3861b5d 100644
99080 --- a/net/netfilter/nf_conntrack_proto.c
99081 +++ b/net/netfilter/nf_conntrack_proto.c
99082 @@ -52,7 +52,7 @@ nf_ct_register_sysctl(struct net *net,
99083
99084 static void
99085 nf_ct_unregister_sysctl(struct ctl_table_header **header,
99086 - struct ctl_table **table,
99087 + ctl_table_no_const **table,
99088 unsigned int users)
99089 {
99090 if (users > 0)
99091 diff --git a/net/netfilter/nf_conntrack_proto_dccp.c b/net/netfilter/nf_conntrack_proto_dccp.c
99092 index a99b6c3..cb372f9 100644
99093 --- a/net/netfilter/nf_conntrack_proto_dccp.c
99094 +++ b/net/netfilter/nf_conntrack_proto_dccp.c
99095 @@ -428,7 +428,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
99096 const char *msg;
99097 u_int8_t state;
99098
99099 - dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
99100 + dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
99101 BUG_ON(dh == NULL);
99102
99103 state = dccp_state_table[CT_DCCP_ROLE_CLIENT][dh->dccph_type][CT_DCCP_NONE];
99104 @@ -457,7 +457,7 @@ static bool dccp_new(struct nf_conn *ct, const struct sk_buff *skb,
99105 out_invalid:
99106 if (LOG_INVALID(net, IPPROTO_DCCP))
99107 nf_log_packet(net, nf_ct_l3num(ct), 0, skb, NULL, NULL,
99108 - NULL, msg);
99109 + NULL, "%s", msg);
99110 return false;
99111 }
99112
99113 @@ -486,7 +486,7 @@ static int dccp_packet(struct nf_conn *ct, const struct sk_buff *skb,
99114 u_int8_t type, old_state, new_state;
99115 enum ct_dccp_roles role;
99116
99117 - dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
99118 + dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
99119 BUG_ON(dh == NULL);
99120 type = dh->dccph_type;
99121
99122 @@ -577,7 +577,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
99123 unsigned int cscov;
99124 const char *msg;
99125
99126 - dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &dh);
99127 + dh = skb_header_pointer(skb, dataoff, sizeof(_dh), &_dh);
99128 if (dh == NULL) {
99129 msg = "nf_ct_dccp: short packet ";
99130 goto out_invalid;
99131 @@ -614,7 +614,7 @@ static int dccp_error(struct net *net, struct nf_conn *tmpl,
99132
99133 out_invalid:
99134 if (LOG_INVALID(net, IPPROTO_DCCP))
99135 - nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, msg);
99136 + nf_log_packet(net, pf, 0, skb, NULL, NULL, NULL, "%s", msg);
99137 return -NF_ACCEPT;
99138 }
99139
99140 diff --git a/net/netfilter/nf_conntrack_standalone.c b/net/netfilter/nf_conntrack_standalone.c
99141 index f641751..d3c5b51 100644
99142 --- a/net/netfilter/nf_conntrack_standalone.c
99143 +++ b/net/netfilter/nf_conntrack_standalone.c
99144 @@ -471,7 +471,7 @@ static struct ctl_table nf_ct_netfilter_table[] = {
99145
99146 static int nf_conntrack_standalone_init_sysctl(struct net *net)
99147 {
99148 - struct ctl_table *table;
99149 + ctl_table_no_const *table;
99150
99151 table = kmemdup(nf_ct_sysctl_table, sizeof(nf_ct_sysctl_table),
99152 GFP_KERNEL);
99153 diff --git a/net/netfilter/nf_conntrack_timestamp.c b/net/netfilter/nf_conntrack_timestamp.c
99154 index 7a394df..bd91a8a 100644
99155 --- a/net/netfilter/nf_conntrack_timestamp.c
99156 +++ b/net/netfilter/nf_conntrack_timestamp.c
99157 @@ -42,7 +42,7 @@ static struct nf_ct_ext_type tstamp_extend __read_mostly = {
99158 #ifdef CONFIG_SYSCTL
99159 static int nf_conntrack_tstamp_init_sysctl(struct net *net)
99160 {
99161 - struct ctl_table *table;
99162 + ctl_table_no_const *table;
99163
99164 table = kmemdup(tstamp_sysctl_table, sizeof(tstamp_sysctl_table),
99165 GFP_KERNEL);
99166 diff --git a/net/netfilter/nf_log.c b/net/netfilter/nf_log.c
99167 index 85296d4..8becdec 100644
99168 --- a/net/netfilter/nf_log.c
99169 +++ b/net/netfilter/nf_log.c
99170 @@ -243,7 +243,7 @@ static const struct file_operations nflog_file_ops = {
99171
99172 #ifdef CONFIG_SYSCTL
99173 static char nf_log_sysctl_fnames[NFPROTO_NUMPROTO-NFPROTO_UNSPEC][3];
99174 -static struct ctl_table nf_log_sysctl_table[NFPROTO_NUMPROTO+1];
99175 +static ctl_table_no_const nf_log_sysctl_table[NFPROTO_NUMPROTO+1] __read_only;
99176
99177 static int nf_log_proc_dostring(struct ctl_table *table, int write,
99178 void __user *buffer, size_t *lenp, loff_t *ppos)
99179 @@ -274,14 +274,16 @@ static int nf_log_proc_dostring(struct ctl_table *table, int write,
99180 rcu_assign_pointer(net->nf.nf_loggers[tindex], logger);
99181 mutex_unlock(&nf_log_mutex);
99182 } else {
99183 + ctl_table_no_const nf_log_table = *table;
99184 +
99185 mutex_lock(&nf_log_mutex);
99186 logger = rcu_dereference_protected(net->nf.nf_loggers[tindex],
99187 lockdep_is_held(&nf_log_mutex));
99188 if (!logger)
99189 - table->data = "NONE";
99190 + nf_log_table.data = "NONE";
99191 else
99192 - table->data = logger->name;
99193 - r = proc_dostring(table, write, buffer, lenp, ppos);
99194 + nf_log_table.data = logger->name;
99195 + r = proc_dostring(&nf_log_table, write, buffer, lenp, ppos);
99196 mutex_unlock(&nf_log_mutex);
99197 }
99198
99199 diff --git a/net/netfilter/nf_sockopt.c b/net/netfilter/nf_sockopt.c
99200 index f042ae5..30ea486 100644
99201 --- a/net/netfilter/nf_sockopt.c
99202 +++ b/net/netfilter/nf_sockopt.c
99203 @@ -45,7 +45,7 @@ int nf_register_sockopt(struct nf_sockopt_ops *reg)
99204 }
99205 }
99206
99207 - list_add(&reg->list, &nf_sockopts);
99208 + pax_list_add((struct list_head *)&reg->list, &nf_sockopts);
99209 out:
99210 mutex_unlock(&nf_sockopt_mutex);
99211 return ret;
99212 @@ -55,7 +55,7 @@ EXPORT_SYMBOL(nf_register_sockopt);
99213 void nf_unregister_sockopt(struct nf_sockopt_ops *reg)
99214 {
99215 mutex_lock(&nf_sockopt_mutex);
99216 - list_del(&reg->list);
99217 + pax_list_del((struct list_head *)&reg->list);
99218 mutex_unlock(&nf_sockopt_mutex);
99219 }
99220 EXPORT_SYMBOL(nf_unregister_sockopt);
99221 diff --git a/net/netfilter/nfnetlink_log.c b/net/netfilter/nfnetlink_log.c
99222 index a155d19..726b0f2 100644
99223 --- a/net/netfilter/nfnetlink_log.c
99224 +++ b/net/netfilter/nfnetlink_log.c
99225 @@ -82,7 +82,7 @@ static int nfnl_log_net_id __read_mostly;
99226 struct nfnl_log_net {
99227 spinlock_t instances_lock;
99228 struct hlist_head instance_table[INSTANCE_BUCKETS];
99229 - atomic_t global_seq;
99230 + atomic_unchecked_t global_seq;
99231 };
99232
99233 static struct nfnl_log_net *nfnl_log_pernet(struct net *net)
99234 @@ -564,7 +564,7 @@ __build_packet_message(struct nfnl_log_net *log,
99235 /* global sequence number */
99236 if ((inst->flags & NFULNL_CFG_F_SEQ_GLOBAL) &&
99237 nla_put_be32(inst->skb, NFULA_SEQ_GLOBAL,
99238 - htonl(atomic_inc_return(&log->global_seq))))
99239 + htonl(atomic_inc_return_unchecked(&log->global_seq))))
99240 goto nla_put_failure;
99241
99242 if (data_len) {
99243 diff --git a/net/netfilter/nft_compat.c b/net/netfilter/nft_compat.c
99244 index da0c1f4..f79737a 100644
99245 --- a/net/netfilter/nft_compat.c
99246 +++ b/net/netfilter/nft_compat.c
99247 @@ -216,7 +216,7 @@ target_dump_info(struct sk_buff *skb, const struct xt_target *t, const void *in)
99248 /* We want to reuse existing compat_to_user */
99249 old_fs = get_fs();
99250 set_fs(KERNEL_DS);
99251 - t->compat_to_user(out, in);
99252 + t->compat_to_user((void __force_user *)out, in);
99253 set_fs(old_fs);
99254 ret = nla_put(skb, NFTA_TARGET_INFO, XT_ALIGN(t->targetsize), out);
99255 kfree(out);
99256 @@ -403,7 +403,7 @@ match_dump_info(struct sk_buff *skb, const struct xt_match *m, const void *in)
99257 /* We want to reuse existing compat_to_user */
99258 old_fs = get_fs();
99259 set_fs(KERNEL_DS);
99260 - m->compat_to_user(out, in);
99261 + m->compat_to_user((void __force_user *)out, in);
99262 set_fs(old_fs);
99263 ret = nla_put(skb, NFTA_MATCH_INFO, XT_ALIGN(m->matchsize), out);
99264 kfree(out);
99265 diff --git a/net/netfilter/xt_gradm.c b/net/netfilter/xt_gradm.c
99266 new file mode 100644
99267 index 0000000..c566332
99268 --- /dev/null
99269 +++ b/net/netfilter/xt_gradm.c
99270 @@ -0,0 +1,51 @@
99271 +/*
99272 + * gradm match for netfilter
99273 + * Copyright © Zbigniew Krzystolik, 2010
99274 + *
99275 + * This program is free software; you can redistribute it and/or modify
99276 + * it under the terms of the GNU General Public License; either version
99277 + * 2 or 3 as published by the Free Software Foundation.
99278 + */
99279 +#include <linux/module.h>
99280 +#include <linux/moduleparam.h>
99281 +#include <linux/skbuff.h>
99282 +#include <linux/netfilter/x_tables.h>
99283 +#include <linux/grsecurity.h>
99284 +#include <linux/netfilter/xt_gradm.h>
99285 +
99286 +static bool
99287 +gradm_mt(const struct sk_buff *skb, struct xt_action_param *par)
99288 +{
99289 + const struct xt_gradm_mtinfo *info = par->matchinfo;
99290 + bool retval = false;
99291 + if (gr_acl_is_enabled())
99292 + retval = true;
99293 + return retval ^ info->invflags;
99294 +}
99295 +
99296 +static struct xt_match gradm_mt_reg __read_mostly = {
99297 + .name = "gradm",
99298 + .revision = 0,
99299 + .family = NFPROTO_UNSPEC,
99300 + .match = gradm_mt,
99301 + .matchsize = XT_ALIGN(sizeof(struct xt_gradm_mtinfo)),
99302 + .me = THIS_MODULE,
99303 +};
99304 +
99305 +static int __init gradm_mt_init(void)
99306 +{
99307 + return xt_register_match(&gradm_mt_reg);
99308 +}
99309 +
99310 +static void __exit gradm_mt_exit(void)
99311 +{
99312 + xt_unregister_match(&gradm_mt_reg);
99313 +}
99314 +
99315 +module_init(gradm_mt_init);
99316 +module_exit(gradm_mt_exit);
99317 +MODULE_AUTHOR("Zbigniew Krzystolik <zbyniu@destrukcja.pl>");
99318 +MODULE_DESCRIPTION("Xtables: Grsecurity RBAC match");
99319 +MODULE_LICENSE("GPL");
99320 +MODULE_ALIAS("ipt_gradm");
99321 +MODULE_ALIAS("ip6t_gradm");
99322 diff --git a/net/netfilter/xt_statistic.c b/net/netfilter/xt_statistic.c
99323 index 4fe4fb4..87a89e5 100644
99324 --- a/net/netfilter/xt_statistic.c
99325 +++ b/net/netfilter/xt_statistic.c
99326 @@ -19,7 +19,7 @@
99327 #include <linux/module.h>
99328
99329 struct xt_statistic_priv {
99330 - atomic_t count;
99331 + atomic_unchecked_t count;
99332 } ____cacheline_aligned_in_smp;
99333
99334 MODULE_LICENSE("GPL");
99335 @@ -42,9 +42,9 @@ statistic_mt(const struct sk_buff *skb, struct xt_action_param *par)
99336 break;
99337 case XT_STATISTIC_MODE_NTH:
99338 do {
99339 - oval = atomic_read(&info->master->count);
99340 + oval = atomic_read_unchecked(&info->master->count);
99341 nval = (oval == info->u.nth.every) ? 0 : oval + 1;
99342 - } while (atomic_cmpxchg(&info->master->count, oval, nval) != oval);
99343 + } while (atomic_cmpxchg_unchecked(&info->master->count, oval, nval) != oval);
99344 if (nval == 0)
99345 ret = !ret;
99346 break;
99347 @@ -64,7 +64,7 @@ static int statistic_mt_check(const struct xt_mtchk_param *par)
99348 info->master = kzalloc(sizeof(*info->master), GFP_KERNEL);
99349 if (info->master == NULL)
99350 return -ENOMEM;
99351 - atomic_set(&info->master->count, info->u.nth.count);
99352 + atomic_set_unchecked(&info->master->count, info->u.nth.count);
99353
99354 return 0;
99355 }
99356 diff --git a/net/netlink/af_netlink.c b/net/netlink/af_netlink.c
99357 index bca50b9..8f8a85e 100644
99358 --- a/net/netlink/af_netlink.c
99359 +++ b/net/netlink/af_netlink.c
99360 @@ -249,7 +249,7 @@ static void netlink_overrun(struct sock *sk)
99361 sk->sk_error_report(sk);
99362 }
99363 }
99364 - atomic_inc(&sk->sk_drops);
99365 + atomic_inc_unchecked(&sk->sk_drops);
99366 }
99367
99368 static void netlink_rcv_wake(struct sock *sk)
99369 @@ -2940,7 +2940,7 @@ static int netlink_seq_show(struct seq_file *seq, void *v)
99370 sk_wmem_alloc_get(s),
99371 nlk->cb_running,
99372 atomic_read(&s->sk_refcnt),
99373 - atomic_read(&s->sk_drops),
99374 + atomic_read_unchecked(&s->sk_drops),
99375 sock_i_ino(s)
99376 );
99377
99378 diff --git a/net/netrom/af_netrom.c b/net/netrom/af_netrom.c
99379 index 53c19a3..b0ac04a 100644
99380 --- a/net/netrom/af_netrom.c
99381 +++ b/net/netrom/af_netrom.c
99382 @@ -850,7 +850,6 @@ static int nr_getname(struct socket *sock, struct sockaddr *uaddr,
99383 *uaddr_len = sizeof(struct full_sockaddr_ax25);
99384 } else {
99385 sax->fsa_ax25.sax25_family = AF_NETROM;
99386 - sax->fsa_ax25.sax25_ndigis = 0;
99387 sax->fsa_ax25.sax25_call = nr->source_addr;
99388 *uaddr_len = sizeof(struct sockaddr_ax25);
99389 }
99390 diff --git a/net/packet/af_packet.c b/net/packet/af_packet.c
99391 index 88cfbc1..05d73f5 100644
99392 --- a/net/packet/af_packet.c
99393 +++ b/net/packet/af_packet.c
99394 @@ -1720,7 +1720,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
99395
99396 spin_lock(&sk->sk_receive_queue.lock);
99397 po->stats.stats1.tp_packets++;
99398 - skb->dropcount = atomic_read(&sk->sk_drops);
99399 + skb->dropcount = atomic_read_unchecked(&sk->sk_drops);
99400 __skb_queue_tail(&sk->sk_receive_queue, skb);
99401 spin_unlock(&sk->sk_receive_queue.lock);
99402 sk->sk_data_ready(sk, skb->len);
99403 @@ -1729,7 +1729,7 @@ static int packet_rcv(struct sk_buff *skb, struct net_device *dev,
99404 drop_n_acct:
99405 spin_lock(&sk->sk_receive_queue.lock);
99406 po->stats.stats1.tp_drops++;
99407 - atomic_inc(&sk->sk_drops);
99408 + atomic_inc_unchecked(&sk->sk_drops);
99409 spin_unlock(&sk->sk_receive_queue.lock);
99410
99411 drop_n_restore:
99412 @@ -3275,7 +3275,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
99413 case PACKET_HDRLEN:
99414 if (len > sizeof(int))
99415 len = sizeof(int);
99416 - if (copy_from_user(&val, optval, len))
99417 + if (len > sizeof(val) || copy_from_user(&val, optval, len))
99418 return -EFAULT;
99419 switch (val) {
99420 case TPACKET_V1:
99421 @@ -3318,7 +3318,7 @@ static int packet_getsockopt(struct socket *sock, int level, int optname,
99422 len = lv;
99423 if (put_user(len, optlen))
99424 return -EFAULT;
99425 - if (copy_to_user(optval, data, len))
99426 + if (len > sizeof(st) || copy_to_user(optval, data, len))
99427 return -EFAULT;
99428 return 0;
99429 }
99430 diff --git a/net/phonet/datagram.c b/net/phonet/datagram.c
99431 index 38946b2..12c30f3 100644
99432 --- a/net/phonet/datagram.c
99433 +++ b/net/phonet/datagram.c
99434 @@ -139,6 +139,9 @@ static int pn_recvmsg(struct kiocb *iocb, struct sock *sk,
99435 MSG_CMSG_COMPAT))
99436 goto out_nofree;
99437
99438 + if (addr_len)
99439 + *addr_len = sizeof(sa);
99440 +
99441 skb = skb_recv_datagram(sk, flags, noblock, &rval);
99442 if (skb == NULL)
99443 goto out_nofree;
99444 @@ -159,10 +162,8 @@ static int pn_recvmsg(struct kiocb *iocb, struct sock *sk,
99445
99446 rval = (flags & MSG_TRUNC) ? skb->len : copylen;
99447
99448 - if (msg->msg_name != NULL) {
99449 - memcpy(msg->msg_name, &sa, sizeof(sa));
99450 - *addr_len = sizeof(sa);
99451 - }
99452 + if (msg->msg_name != NULL)
99453 + memcpy(msg->msg_name, &sa, sizeof(struct sockaddr_pn));
99454
99455 out:
99456 skb_free_datagram(sk, skb);
99457 diff --git a/net/phonet/pep.c b/net/phonet/pep.c
99458 index e774117..900b8b7 100644
99459 --- a/net/phonet/pep.c
99460 +++ b/net/phonet/pep.c
99461 @@ -388,7 +388,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
99462
99463 case PNS_PEP_CTRL_REQ:
99464 if (skb_queue_len(&pn->ctrlreq_queue) >= PNPIPE_CTRLREQ_MAX) {
99465 - atomic_inc(&sk->sk_drops);
99466 + atomic_inc_unchecked(&sk->sk_drops);
99467 break;
99468 }
99469 __skb_pull(skb, 4);
99470 @@ -409,7 +409,7 @@ static int pipe_do_rcv(struct sock *sk, struct sk_buff *skb)
99471 }
99472
99473 if (pn->rx_credits == 0) {
99474 - atomic_inc(&sk->sk_drops);
99475 + atomic_inc_unchecked(&sk->sk_drops);
99476 err = -ENOBUFS;
99477 break;
99478 }
99479 @@ -580,7 +580,7 @@ static int pipe_handler_do_rcv(struct sock *sk, struct sk_buff *skb)
99480 }
99481
99482 if (pn->rx_credits == 0) {
99483 - atomic_inc(&sk->sk_drops);
99484 + atomic_inc_unchecked(&sk->sk_drops);
99485 err = NET_RX_DROP;
99486 break;
99487 }
99488 diff --git a/net/phonet/socket.c b/net/phonet/socket.c
99489 index 008214a..bb68240 100644
99490 --- a/net/phonet/socket.c
99491 +++ b/net/phonet/socket.c
99492 @@ -611,7 +611,7 @@ static int pn_sock_seq_show(struct seq_file *seq, void *v)
99493 from_kuid_munged(seq_user_ns(seq), sock_i_uid(sk)),
99494 sock_i_ino(sk),
99495 atomic_read(&sk->sk_refcnt), sk,
99496 - atomic_read(&sk->sk_drops));
99497 + atomic_read_unchecked(&sk->sk_drops));
99498 }
99499 seq_pad(seq, '\n');
99500 return 0;
99501 diff --git a/net/phonet/sysctl.c b/net/phonet/sysctl.c
99502 index c02a8c4..3c5b600 100644
99503 --- a/net/phonet/sysctl.c
99504 +++ b/net/phonet/sysctl.c
99505 @@ -67,7 +67,7 @@ static int proc_local_port_range(struct ctl_table *table, int write,
99506 {
99507 int ret;
99508 int range[2] = {local_port_range[0], local_port_range[1]};
99509 - struct ctl_table tmp = {
99510 + ctl_table_no_const tmp = {
99511 .data = &range,
99512 .maxlen = sizeof(range),
99513 .mode = table->mode,
99514 diff --git a/net/rds/cong.c b/net/rds/cong.c
99515 index e5b65ac..f3b6fb7 100644
99516 --- a/net/rds/cong.c
99517 +++ b/net/rds/cong.c
99518 @@ -78,7 +78,7 @@
99519 * finds that the saved generation number is smaller than the global generation
99520 * number, it wakes up the process.
99521 */
99522 -static atomic_t rds_cong_generation = ATOMIC_INIT(0);
99523 +static atomic_unchecked_t rds_cong_generation = ATOMIC_INIT(0);
99524
99525 /*
99526 * Congestion monitoring
99527 @@ -233,7 +233,7 @@ void rds_cong_map_updated(struct rds_cong_map *map, uint64_t portmask)
99528 rdsdebug("waking map %p for %pI4\n",
99529 map, &map->m_addr);
99530 rds_stats_inc(s_cong_update_received);
99531 - atomic_inc(&rds_cong_generation);
99532 + atomic_inc_unchecked(&rds_cong_generation);
99533 if (waitqueue_active(&map->m_waitq))
99534 wake_up(&map->m_waitq);
99535 if (waitqueue_active(&rds_poll_waitq))
99536 @@ -259,7 +259,7 @@ EXPORT_SYMBOL_GPL(rds_cong_map_updated);
99537
99538 int rds_cong_updated_since(unsigned long *recent)
99539 {
99540 - unsigned long gen = atomic_read(&rds_cong_generation);
99541 + unsigned long gen = atomic_read_unchecked(&rds_cong_generation);
99542
99543 if (likely(*recent == gen))
99544 return 0;
99545 diff --git a/net/rds/ib.h b/net/rds/ib.h
99546 index 7280ab8..e04f4ea 100644
99547 --- a/net/rds/ib.h
99548 +++ b/net/rds/ib.h
99549 @@ -128,7 +128,7 @@ struct rds_ib_connection {
99550 /* sending acks */
99551 unsigned long i_ack_flags;
99552 #ifdef KERNEL_HAS_ATOMIC64
99553 - atomic64_t i_ack_next; /* next ACK to send */
99554 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
99555 #else
99556 spinlock_t i_ack_lock; /* protect i_ack_next */
99557 u64 i_ack_next; /* next ACK to send */
99558 diff --git a/net/rds/ib_cm.c b/net/rds/ib_cm.c
99559 index 31b74f5..dc1fbfa 100644
99560 --- a/net/rds/ib_cm.c
99561 +++ b/net/rds/ib_cm.c
99562 @@ -717,7 +717,7 @@ void rds_ib_conn_shutdown(struct rds_connection *conn)
99563 /* Clear the ACK state */
99564 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
99565 #ifdef KERNEL_HAS_ATOMIC64
99566 - atomic64_set(&ic->i_ack_next, 0);
99567 + atomic64_set_unchecked(&ic->i_ack_next, 0);
99568 #else
99569 ic->i_ack_next = 0;
99570 #endif
99571 diff --git a/net/rds/ib_recv.c b/net/rds/ib_recv.c
99572 index b7ebe23..b6352f6 100644
99573 --- a/net/rds/ib_recv.c
99574 +++ b/net/rds/ib_recv.c
99575 @@ -596,7 +596,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
99576 static void rds_ib_set_ack(struct rds_ib_connection *ic, u64 seq,
99577 int ack_required)
99578 {
99579 - atomic64_set(&ic->i_ack_next, seq);
99580 + atomic64_set_unchecked(&ic->i_ack_next, seq);
99581 if (ack_required) {
99582 smp_mb__before_clear_bit();
99583 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
99584 @@ -608,7 +608,7 @@ static u64 rds_ib_get_ack(struct rds_ib_connection *ic)
99585 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
99586 smp_mb__after_clear_bit();
99587
99588 - return atomic64_read(&ic->i_ack_next);
99589 + return atomic64_read_unchecked(&ic->i_ack_next);
99590 }
99591 #endif
99592
99593 diff --git a/net/rds/iw.h b/net/rds/iw.h
99594 index 04ce3b1..48119a6 100644
99595 --- a/net/rds/iw.h
99596 +++ b/net/rds/iw.h
99597 @@ -134,7 +134,7 @@ struct rds_iw_connection {
99598 /* sending acks */
99599 unsigned long i_ack_flags;
99600 #ifdef KERNEL_HAS_ATOMIC64
99601 - atomic64_t i_ack_next; /* next ACK to send */
99602 + atomic64_unchecked_t i_ack_next; /* next ACK to send */
99603 #else
99604 spinlock_t i_ack_lock; /* protect i_ack_next */
99605 u64 i_ack_next; /* next ACK to send */
99606 diff --git a/net/rds/iw_cm.c b/net/rds/iw_cm.c
99607 index a91e1db..cf3053f 100644
99608 --- a/net/rds/iw_cm.c
99609 +++ b/net/rds/iw_cm.c
99610 @@ -663,7 +663,7 @@ void rds_iw_conn_shutdown(struct rds_connection *conn)
99611 /* Clear the ACK state */
99612 clear_bit(IB_ACK_IN_FLIGHT, &ic->i_ack_flags);
99613 #ifdef KERNEL_HAS_ATOMIC64
99614 - atomic64_set(&ic->i_ack_next, 0);
99615 + atomic64_set_unchecked(&ic->i_ack_next, 0);
99616 #else
99617 ic->i_ack_next = 0;
99618 #endif
99619 diff --git a/net/rds/iw_recv.c b/net/rds/iw_recv.c
99620 index 4503335..db566b4 100644
99621 --- a/net/rds/iw_recv.c
99622 +++ b/net/rds/iw_recv.c
99623 @@ -427,7 +427,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
99624 static void rds_iw_set_ack(struct rds_iw_connection *ic, u64 seq,
99625 int ack_required)
99626 {
99627 - atomic64_set(&ic->i_ack_next, seq);
99628 + atomic64_set_unchecked(&ic->i_ack_next, seq);
99629 if (ack_required) {
99630 smp_mb__before_clear_bit();
99631 set_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
99632 @@ -439,7 +439,7 @@ static u64 rds_iw_get_ack(struct rds_iw_connection *ic)
99633 clear_bit(IB_ACK_REQUESTED, &ic->i_ack_flags);
99634 smp_mb__after_clear_bit();
99635
99636 - return atomic64_read(&ic->i_ack_next);
99637 + return atomic64_read_unchecked(&ic->i_ack_next);
99638 }
99639 #endif
99640
99641 diff --git a/net/rds/rds.h b/net/rds/rds.h
99642 index 48f8ffc..0ef3eec 100644
99643 --- a/net/rds/rds.h
99644 +++ b/net/rds/rds.h
99645 @@ -449,7 +449,7 @@ struct rds_transport {
99646 void (*sync_mr)(void *trans_private, int direction);
99647 void (*free_mr)(void *trans_private, int invalidate);
99648 void (*flush_mrs)(void);
99649 -};
99650 +} __do_const;
99651
99652 struct rds_sock {
99653 struct sock rs_sk;
99654 diff --git a/net/rds/tcp.c b/net/rds/tcp.c
99655 index edac9ef..16bcb98 100644
99656 --- a/net/rds/tcp.c
99657 +++ b/net/rds/tcp.c
99658 @@ -59,7 +59,7 @@ void rds_tcp_nonagle(struct socket *sock)
99659 int val = 1;
99660
99661 set_fs(KERNEL_DS);
99662 - sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __user *)&val,
99663 + sock->ops->setsockopt(sock, SOL_TCP, TCP_NODELAY, (char __force_user *)&val,
99664 sizeof(val));
99665 set_fs(oldfs);
99666 }
99667 diff --git a/net/rds/tcp_send.c b/net/rds/tcp_send.c
99668 index 81cf5a4..b5826ff 100644
99669 --- a/net/rds/tcp_send.c
99670 +++ b/net/rds/tcp_send.c
99671 @@ -43,7 +43,7 @@ static void rds_tcp_cork(struct socket *sock, int val)
99672
99673 oldfs = get_fs();
99674 set_fs(KERNEL_DS);
99675 - sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __user *)&val,
99676 + sock->ops->setsockopt(sock, SOL_TCP, TCP_CORK, (char __force_user *)&val,
99677 sizeof(val));
99678 set_fs(oldfs);
99679 }
99680 diff --git a/net/rxrpc/af_rxrpc.c b/net/rxrpc/af_rxrpc.c
99681 index e61aa60..f07cc89 100644
99682 --- a/net/rxrpc/af_rxrpc.c
99683 +++ b/net/rxrpc/af_rxrpc.c
99684 @@ -40,7 +40,7 @@ static const struct proto_ops rxrpc_rpc_ops;
99685 __be32 rxrpc_epoch;
99686
99687 /* current debugging ID */
99688 -atomic_t rxrpc_debug_id;
99689 +atomic_unchecked_t rxrpc_debug_id;
99690
99691 /* count of skbs currently in use */
99692 atomic_t rxrpc_n_skbs;
99693 diff --git a/net/rxrpc/ar-ack.c b/net/rxrpc/ar-ack.c
99694 index e4d9cbc..b229649 100644
99695 --- a/net/rxrpc/ar-ack.c
99696 +++ b/net/rxrpc/ar-ack.c
99697 @@ -175,7 +175,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
99698
99699 _enter("{%d,%d,%d,%d},",
99700 call->acks_hard, call->acks_unacked,
99701 - atomic_read(&call->sequence),
99702 + atomic_read_unchecked(&call->sequence),
99703 CIRC_CNT(call->acks_head, call->acks_tail, call->acks_winsz));
99704
99705 stop = 0;
99706 @@ -199,7 +199,7 @@ static void rxrpc_resend(struct rxrpc_call *call)
99707
99708 /* each Tx packet has a new serial number */
99709 sp->hdr.serial =
99710 - htonl(atomic_inc_return(&call->conn->serial));
99711 + htonl(atomic_inc_return_unchecked(&call->conn->serial));
99712
99713 hdr = (struct rxrpc_header *) txb->head;
99714 hdr->serial = sp->hdr.serial;
99715 @@ -403,7 +403,7 @@ static void rxrpc_rotate_tx_window(struct rxrpc_call *call, u32 hard)
99716 */
99717 static void rxrpc_clear_tx_window(struct rxrpc_call *call)
99718 {
99719 - rxrpc_rotate_tx_window(call, atomic_read(&call->sequence));
99720 + rxrpc_rotate_tx_window(call, atomic_read_unchecked(&call->sequence));
99721 }
99722
99723 /*
99724 @@ -629,7 +629,7 @@ process_further:
99725
99726 latest = ntohl(sp->hdr.serial);
99727 hard = ntohl(ack.firstPacket);
99728 - tx = atomic_read(&call->sequence);
99729 + tx = atomic_read_unchecked(&call->sequence);
99730
99731 _proto("Rx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
99732 latest,
99733 @@ -1161,7 +1161,7 @@ void rxrpc_process_call(struct work_struct *work)
99734 goto maybe_reschedule;
99735
99736 send_ACK_with_skew:
99737 - ack.maxSkew = htons(atomic_read(&call->conn->hi_serial) -
99738 + ack.maxSkew = htons(atomic_read_unchecked(&call->conn->hi_serial) -
99739 ntohl(ack.serial));
99740 send_ACK:
99741 mtu = call->conn->trans->peer->if_mtu;
99742 @@ -1173,7 +1173,7 @@ send_ACK:
99743 ackinfo.rxMTU = htonl(5692);
99744 ackinfo.jumbo_max = htonl(4);
99745
99746 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
99747 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
99748 _proto("Tx ACK %%%u { m=%hu f=#%u p=#%u s=%%%u r=%s n=%u }",
99749 ntohl(hdr.serial),
99750 ntohs(ack.maxSkew),
99751 @@ -1191,7 +1191,7 @@ send_ACK:
99752 send_message:
99753 _debug("send message");
99754
99755 - hdr.serial = htonl(atomic_inc_return(&call->conn->serial));
99756 + hdr.serial = htonl(atomic_inc_return_unchecked(&call->conn->serial));
99757 _proto("Tx %s %%%u", rxrpc_pkts[hdr.type], ntohl(hdr.serial));
99758 send_message_2:
99759
99760 diff --git a/net/rxrpc/ar-call.c b/net/rxrpc/ar-call.c
99761 index a3bbb36..3341fb9 100644
99762 --- a/net/rxrpc/ar-call.c
99763 +++ b/net/rxrpc/ar-call.c
99764 @@ -83,7 +83,7 @@ static struct rxrpc_call *rxrpc_alloc_call(gfp_t gfp)
99765 spin_lock_init(&call->lock);
99766 rwlock_init(&call->state_lock);
99767 atomic_set(&call->usage, 1);
99768 - call->debug_id = atomic_inc_return(&rxrpc_debug_id);
99769 + call->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
99770 call->state = RXRPC_CALL_CLIENT_SEND_REQUEST;
99771
99772 memset(&call->sock_node, 0xed, sizeof(call->sock_node));
99773 diff --git a/net/rxrpc/ar-connection.c b/net/rxrpc/ar-connection.c
99774 index 4106ca9..a338d7a 100644
99775 --- a/net/rxrpc/ar-connection.c
99776 +++ b/net/rxrpc/ar-connection.c
99777 @@ -206,7 +206,7 @@ static struct rxrpc_connection *rxrpc_alloc_connection(gfp_t gfp)
99778 rwlock_init(&conn->lock);
99779 spin_lock_init(&conn->state_lock);
99780 atomic_set(&conn->usage, 1);
99781 - conn->debug_id = atomic_inc_return(&rxrpc_debug_id);
99782 + conn->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
99783 conn->avail_calls = RXRPC_MAXCALLS;
99784 conn->size_align = 4;
99785 conn->header_size = sizeof(struct rxrpc_header);
99786 diff --git a/net/rxrpc/ar-connevent.c b/net/rxrpc/ar-connevent.c
99787 index e7ed43a..6afa140 100644
99788 --- a/net/rxrpc/ar-connevent.c
99789 +++ b/net/rxrpc/ar-connevent.c
99790 @@ -109,7 +109,7 @@ static int rxrpc_abort_connection(struct rxrpc_connection *conn,
99791
99792 len = iov[0].iov_len + iov[1].iov_len;
99793
99794 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
99795 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
99796 _proto("Tx CONN ABORT %%%u { %d }", ntohl(hdr.serial), abort_code);
99797
99798 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
99799 diff --git a/net/rxrpc/ar-input.c b/net/rxrpc/ar-input.c
99800 index 529572f..c758ca7 100644
99801 --- a/net/rxrpc/ar-input.c
99802 +++ b/net/rxrpc/ar-input.c
99803 @@ -340,9 +340,9 @@ void rxrpc_fast_process_packet(struct rxrpc_call *call, struct sk_buff *skb)
99804 /* track the latest serial number on this connection for ACK packet
99805 * information */
99806 serial = ntohl(sp->hdr.serial);
99807 - hi_serial = atomic_read(&call->conn->hi_serial);
99808 + hi_serial = atomic_read_unchecked(&call->conn->hi_serial);
99809 while (serial > hi_serial)
99810 - hi_serial = atomic_cmpxchg(&call->conn->hi_serial, hi_serial,
99811 + hi_serial = atomic_cmpxchg_unchecked(&call->conn->hi_serial, hi_serial,
99812 serial);
99813
99814 /* request ACK generation for any ACK or DATA packet that requests
99815 diff --git a/net/rxrpc/ar-internal.h b/net/rxrpc/ar-internal.h
99816 index 5f43675..ca07817 100644
99817 --- a/net/rxrpc/ar-internal.h
99818 +++ b/net/rxrpc/ar-internal.h
99819 @@ -272,8 +272,8 @@ struct rxrpc_connection {
99820 int error; /* error code for local abort */
99821 int debug_id; /* debug ID for printks */
99822 unsigned int call_counter; /* call ID counter */
99823 - atomic_t serial; /* packet serial number counter */
99824 - atomic_t hi_serial; /* highest serial number received */
99825 + atomic_unchecked_t serial; /* packet serial number counter */
99826 + atomic_unchecked_t hi_serial; /* highest serial number received */
99827 u8 avail_calls; /* number of calls available */
99828 u8 size_align; /* data size alignment (for security) */
99829 u8 header_size; /* rxrpc + security header size */
99830 @@ -346,7 +346,7 @@ struct rxrpc_call {
99831 spinlock_t lock;
99832 rwlock_t state_lock; /* lock for state transition */
99833 atomic_t usage;
99834 - atomic_t sequence; /* Tx data packet sequence counter */
99835 + atomic_unchecked_t sequence; /* Tx data packet sequence counter */
99836 u32 abort_code; /* local/remote abort code */
99837 enum { /* current state of call */
99838 RXRPC_CALL_CLIENT_SEND_REQUEST, /* - client sending request phase */
99839 @@ -420,7 +420,7 @@ static inline void rxrpc_abort_call(struct rxrpc_call *call, u32 abort_code)
99840 */
99841 extern atomic_t rxrpc_n_skbs;
99842 extern __be32 rxrpc_epoch;
99843 -extern atomic_t rxrpc_debug_id;
99844 +extern atomic_unchecked_t rxrpc_debug_id;
99845 extern struct workqueue_struct *rxrpc_workqueue;
99846
99847 /*
99848 diff --git a/net/rxrpc/ar-local.c b/net/rxrpc/ar-local.c
99849 index 87f7135..74d3703 100644
99850 --- a/net/rxrpc/ar-local.c
99851 +++ b/net/rxrpc/ar-local.c
99852 @@ -45,7 +45,7 @@ struct rxrpc_local *rxrpc_alloc_local(struct sockaddr_rxrpc *srx)
99853 spin_lock_init(&local->lock);
99854 rwlock_init(&local->services_lock);
99855 atomic_set(&local->usage, 1);
99856 - local->debug_id = atomic_inc_return(&rxrpc_debug_id);
99857 + local->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
99858 memcpy(&local->srx, srx, sizeof(*srx));
99859 }
99860
99861 diff --git a/net/rxrpc/ar-output.c b/net/rxrpc/ar-output.c
99862 index e1ac183..b43e10e 100644
99863 --- a/net/rxrpc/ar-output.c
99864 +++ b/net/rxrpc/ar-output.c
99865 @@ -682,9 +682,9 @@ static int rxrpc_send_data(struct kiocb *iocb,
99866 sp->hdr.cid = call->cid;
99867 sp->hdr.callNumber = call->call_id;
99868 sp->hdr.seq =
99869 - htonl(atomic_inc_return(&call->sequence));
99870 + htonl(atomic_inc_return_unchecked(&call->sequence));
99871 sp->hdr.serial =
99872 - htonl(atomic_inc_return(&conn->serial));
99873 + htonl(atomic_inc_return_unchecked(&conn->serial));
99874 sp->hdr.type = RXRPC_PACKET_TYPE_DATA;
99875 sp->hdr.userStatus = 0;
99876 sp->hdr.securityIndex = conn->security_ix;
99877 diff --git a/net/rxrpc/ar-peer.c b/net/rxrpc/ar-peer.c
99878 index bebaa43..2644591 100644
99879 --- a/net/rxrpc/ar-peer.c
99880 +++ b/net/rxrpc/ar-peer.c
99881 @@ -72,7 +72,7 @@ static struct rxrpc_peer *rxrpc_alloc_peer(struct sockaddr_rxrpc *srx,
99882 INIT_LIST_HEAD(&peer->error_targets);
99883 spin_lock_init(&peer->lock);
99884 atomic_set(&peer->usage, 1);
99885 - peer->debug_id = atomic_inc_return(&rxrpc_debug_id);
99886 + peer->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
99887 memcpy(&peer->srx, srx, sizeof(*srx));
99888
99889 rxrpc_assess_MTU_size(peer);
99890 diff --git a/net/rxrpc/ar-proc.c b/net/rxrpc/ar-proc.c
99891 index 38047f7..9f48511 100644
99892 --- a/net/rxrpc/ar-proc.c
99893 +++ b/net/rxrpc/ar-proc.c
99894 @@ -164,8 +164,8 @@ static int rxrpc_connection_seq_show(struct seq_file *seq, void *v)
99895 atomic_read(&conn->usage),
99896 rxrpc_conn_states[conn->state],
99897 key_serial(conn->key),
99898 - atomic_read(&conn->serial),
99899 - atomic_read(&conn->hi_serial));
99900 + atomic_read_unchecked(&conn->serial),
99901 + atomic_read_unchecked(&conn->hi_serial));
99902
99903 return 0;
99904 }
99905 diff --git a/net/rxrpc/ar-transport.c b/net/rxrpc/ar-transport.c
99906 index 92df566..87ec1bf 100644
99907 --- a/net/rxrpc/ar-transport.c
99908 +++ b/net/rxrpc/ar-transport.c
99909 @@ -47,7 +47,7 @@ static struct rxrpc_transport *rxrpc_alloc_transport(struct rxrpc_local *local,
99910 spin_lock_init(&trans->client_lock);
99911 rwlock_init(&trans->conn_lock);
99912 atomic_set(&trans->usage, 1);
99913 - trans->debug_id = atomic_inc_return(&rxrpc_debug_id);
99914 + trans->debug_id = atomic_inc_return_unchecked(&rxrpc_debug_id);
99915
99916 if (peer->srx.transport.family == AF_INET) {
99917 switch (peer->srx.transport_type) {
99918 diff --git a/net/rxrpc/rxkad.c b/net/rxrpc/rxkad.c
99919 index f226709..0e735a8 100644
99920 --- a/net/rxrpc/rxkad.c
99921 +++ b/net/rxrpc/rxkad.c
99922 @@ -610,7 +610,7 @@ static int rxkad_issue_challenge(struct rxrpc_connection *conn)
99923
99924 len = iov[0].iov_len + iov[1].iov_len;
99925
99926 - hdr.serial = htonl(atomic_inc_return(&conn->serial));
99927 + hdr.serial = htonl(atomic_inc_return_unchecked(&conn->serial));
99928 _proto("Tx CHALLENGE %%%u", ntohl(hdr.serial));
99929
99930 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 2, len);
99931 @@ -660,7 +660,7 @@ static int rxkad_send_response(struct rxrpc_connection *conn,
99932
99933 len = iov[0].iov_len + iov[1].iov_len + iov[2].iov_len;
99934
99935 - hdr->serial = htonl(atomic_inc_return(&conn->serial));
99936 + hdr->serial = htonl(atomic_inc_return_unchecked(&conn->serial));
99937 _proto("Tx RESPONSE %%%u", ntohl(hdr->serial));
99938
99939 ret = kernel_sendmsg(conn->trans->local->socket, &msg, iov, 3, len);
99940 diff --git a/net/sctp/ipv6.c b/net/sctp/ipv6.c
99941 index 7567e6f..299382b 100644
99942 --- a/net/sctp/ipv6.c
99943 +++ b/net/sctp/ipv6.c
99944 @@ -964,7 +964,7 @@ static const struct inet6_protocol sctpv6_protocol = {
99945 .flags = INET6_PROTO_NOPOLICY | INET6_PROTO_FINAL,
99946 };
99947
99948 -static struct sctp_af sctp_af_inet6 = {
99949 +static struct sctp_af sctp_af_inet6 __read_only = {
99950 .sa_family = AF_INET6,
99951 .sctp_xmit = sctp_v6_xmit,
99952 .setsockopt = ipv6_setsockopt,
99953 @@ -996,7 +996,7 @@ static struct sctp_af sctp_af_inet6 = {
99954 #endif
99955 };
99956
99957 -static struct sctp_pf sctp_pf_inet6 = {
99958 +static struct sctp_pf sctp_pf_inet6 __read_only = {
99959 .event_msgname = sctp_inet6_event_msgname,
99960 .skb_msgname = sctp_inet6_skb_msgname,
99961 .af_supported = sctp_inet6_af_supported,
99962 @@ -1021,7 +1021,7 @@ void sctp_v6_pf_init(void)
99963
99964 void sctp_v6_pf_exit(void)
99965 {
99966 - list_del(&sctp_af_inet6.list);
99967 + pax_list_del(&sctp_af_inet6.list);
99968 }
99969
99970 /* Initialize IPv6 support and register with socket layer. */
99971 diff --git a/net/sctp/protocol.c b/net/sctp/protocol.c
99972 index 5e17092..19be1d4 100644
99973 --- a/net/sctp/protocol.c
99974 +++ b/net/sctp/protocol.c
99975 @@ -832,8 +832,10 @@ int sctp_register_af(struct sctp_af *af)
99976 return 0;
99977 }
99978
99979 + pax_open_kernel();
99980 INIT_LIST_HEAD(&af->list);
99981 - list_add_tail(&af->list, &sctp_address_families);
99982 + pax_close_kernel();
99983 + pax_list_add_tail(&af->list, &sctp_address_families);
99984 return 1;
99985 }
99986
99987 @@ -963,7 +965,7 @@ static inline int sctp_v4_xmit(struct sk_buff *skb,
99988
99989 static struct sctp_af sctp_af_inet;
99990
99991 -static struct sctp_pf sctp_pf_inet = {
99992 +static struct sctp_pf sctp_pf_inet __read_only = {
99993 .event_msgname = sctp_inet_event_msgname,
99994 .skb_msgname = sctp_inet_skb_msgname,
99995 .af_supported = sctp_inet_af_supported,
99996 @@ -1034,7 +1036,7 @@ static const struct net_protocol sctp_protocol = {
99997 };
99998
99999 /* IPv4 address related functions. */
100000 -static struct sctp_af sctp_af_inet = {
100001 +static struct sctp_af sctp_af_inet __read_only = {
100002 .sa_family = AF_INET,
100003 .sctp_xmit = sctp_v4_xmit,
100004 .setsockopt = ip_setsockopt,
100005 @@ -1119,7 +1121,7 @@ static void sctp_v4_pf_init(void)
100006
100007 static void sctp_v4_pf_exit(void)
100008 {
100009 - list_del(&sctp_af_inet.list);
100010 + pax_list_del(&sctp_af_inet.list);
100011 }
100012
100013 static int sctp_v4_protosw_init(void)
100014 diff --git a/net/sctp/sm_sideeffect.c b/net/sctp/sm_sideeffect.c
100015 index 1a6eef3..17e898f 100644
100016 --- a/net/sctp/sm_sideeffect.c
100017 +++ b/net/sctp/sm_sideeffect.c
100018 @@ -440,7 +440,7 @@ static void sctp_generate_sack_event(unsigned long data)
100019 sctp_generate_timeout_event(asoc, SCTP_EVENT_TIMEOUT_SACK);
100020 }
100021
100022 -sctp_timer_event_t *sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
100023 +sctp_timer_event_t * const sctp_timer_events[SCTP_NUM_TIMEOUT_TYPES] = {
100024 NULL,
100025 sctp_generate_t1_cookie_event,
100026 sctp_generate_t1_init_event,
100027 diff --git a/net/sctp/socket.c b/net/sctp/socket.c
100028 index 42b709c..e7d09ac 100644
100029 --- a/net/sctp/socket.c
100030 +++ b/net/sctp/socket.c
100031 @@ -2153,11 +2153,13 @@ static int sctp_setsockopt_events(struct sock *sk, char __user *optval,
100032 {
100033 struct sctp_association *asoc;
100034 struct sctp_ulpevent *event;
100035 + struct sctp_event_subscribe subscribe;
100036
100037 if (optlen > sizeof(struct sctp_event_subscribe))
100038 return -EINVAL;
100039 - if (copy_from_user(&sctp_sk(sk)->subscribe, optval, optlen))
100040 + if (copy_from_user(&subscribe, optval, optlen))
100041 return -EFAULT;
100042 + sctp_sk(sk)->subscribe = subscribe;
100043
100044 /*
100045 * At the time when a user app subscribes to SCTP_SENDER_DRY_EVENT,
100046 @@ -4229,13 +4231,16 @@ static int sctp_getsockopt_disable_fragments(struct sock *sk, int len,
100047 static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
100048 int __user *optlen)
100049 {
100050 + struct sctp_event_subscribe subscribe;
100051 +
100052 if (len <= 0)
100053 return -EINVAL;
100054 if (len > sizeof(struct sctp_event_subscribe))
100055 len = sizeof(struct sctp_event_subscribe);
100056 if (put_user(len, optlen))
100057 return -EFAULT;
100058 - if (copy_to_user(optval, &sctp_sk(sk)->subscribe, len))
100059 + subscribe = sctp_sk(sk)->subscribe;
100060 + if (copy_to_user(optval, &subscribe, len))
100061 return -EFAULT;
100062 return 0;
100063 }
100064 @@ -4253,6 +4258,8 @@ static int sctp_getsockopt_events(struct sock *sk, int len, char __user *optval,
100065 */
100066 static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optval, int __user *optlen)
100067 {
100068 + __u32 autoclose;
100069 +
100070 /* Applicable to UDP-style socket only */
100071 if (sctp_style(sk, TCP))
100072 return -EOPNOTSUPP;
100073 @@ -4261,7 +4268,8 @@ static int sctp_getsockopt_autoclose(struct sock *sk, int len, char __user *optv
100074 len = sizeof(int);
100075 if (put_user(len, optlen))
100076 return -EFAULT;
100077 - if (copy_to_user(optval, &sctp_sk(sk)->autoclose, sizeof(int)))
100078 + autoclose = sctp_sk(sk)->autoclose;
100079 + if (copy_to_user(optval, &autoclose, sizeof(int)))
100080 return -EFAULT;
100081 return 0;
100082 }
100083 @@ -4633,12 +4641,15 @@ static int sctp_getsockopt_delayed_ack(struct sock *sk, int len,
100084 */
100085 static int sctp_getsockopt_initmsg(struct sock *sk, int len, char __user *optval, int __user *optlen)
100086 {
100087 + struct sctp_initmsg initmsg;
100088 +
100089 if (len < sizeof(struct sctp_initmsg))
100090 return -EINVAL;
100091 len = sizeof(struct sctp_initmsg);
100092 if (put_user(len, optlen))
100093 return -EFAULT;
100094 - if (copy_to_user(optval, &sctp_sk(sk)->initmsg, len))
100095 + initmsg = sctp_sk(sk)->initmsg;
100096 + if (copy_to_user(optval, &initmsg, len))
100097 return -EFAULT;
100098 return 0;
100099 }
100100 @@ -4679,6 +4690,8 @@ static int sctp_getsockopt_peer_addrs(struct sock *sk, int len,
100101 addrlen = sctp_get_af_specific(temp.sa.sa_family)->sockaddr_len;
100102 if (space_left < addrlen)
100103 return -ENOMEM;
100104 + if (addrlen > sizeof(temp) || addrlen < 0)
100105 + return -EFAULT;
100106 if (copy_to_user(to, &temp, addrlen))
100107 return -EFAULT;
100108 to += addrlen;
100109 diff --git a/net/sctp/sysctl.c b/net/sctp/sysctl.c
100110 index b0565af..d135e6e 100644
100111 --- a/net/sctp/sysctl.c
100112 +++ b/net/sctp/sysctl.c
100113 @@ -305,7 +305,7 @@ static int proc_sctp_do_hmac_alg(struct ctl_table *ctl, int write,
100114 {
100115 struct net *net = current->nsproxy->net_ns;
100116 char tmp[8];
100117 - struct ctl_table tbl;
100118 + ctl_table_no_const tbl;
100119 int ret;
100120 int changed = 0;
100121 char *none = "none";
100122 @@ -352,7 +352,7 @@ static int proc_sctp_do_rto_min(struct ctl_table *ctl, int write,
100123 {
100124 struct net *net = current->nsproxy->net_ns;
100125 int new_value;
100126 - struct ctl_table tbl;
100127 + ctl_table_no_const tbl;
100128 unsigned int min = *(unsigned int *) ctl->extra1;
100129 unsigned int max = *(unsigned int *) ctl->extra2;
100130 int ret;
100131 @@ -379,7 +379,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
100132 {
100133 struct net *net = current->nsproxy->net_ns;
100134 int new_value;
100135 - struct ctl_table tbl;
100136 + ctl_table_no_const tbl;
100137 unsigned int min = *(unsigned int *) ctl->extra1;
100138 unsigned int max = *(unsigned int *) ctl->extra2;
100139 int ret;
100140 @@ -402,7 +402,7 @@ static int proc_sctp_do_rto_max(struct ctl_table *ctl, int write,
100141
100142 int sctp_sysctl_net_register(struct net *net)
100143 {
100144 - struct ctl_table *table;
100145 + ctl_table_no_const *table;
100146 int i;
100147
100148 table = kmemdup(sctp_net_table, sizeof(sctp_net_table), GFP_KERNEL);
100149 diff --git a/net/socket.c b/net/socket.c
100150 index e83c416..1094d88 100644
100151 --- a/net/socket.c
100152 +++ b/net/socket.c
100153 @@ -88,6 +88,7 @@
100154 #include <linux/magic.h>
100155 #include <linux/slab.h>
100156 #include <linux/xattr.h>
100157 +#include <linux/in.h>
100158
100159 #include <asm/uaccess.h>
100160 #include <asm/unistd.h>
100161 @@ -111,6 +112,8 @@ unsigned int sysctl_net_busy_read __read_mostly;
100162 unsigned int sysctl_net_busy_poll __read_mostly;
100163 #endif
100164
100165 +#include <linux/grsock.h>
100166 +
100167 static int sock_no_open(struct inode *irrelevant, struct file *dontcare);
100168 static ssize_t sock_aio_read(struct kiocb *iocb, const struct iovec *iov,
100169 unsigned long nr_segs, loff_t pos);
100170 @@ -162,7 +165,7 @@ static const struct file_operations socket_file_ops = {
100171 */
100172
100173 static DEFINE_SPINLOCK(net_family_lock);
100174 -static const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
100175 +const struct net_proto_family __rcu *net_families[NPROTO] __read_mostly;
100176
100177 /*
100178 * Statistics counters of the socket lists
100179 @@ -328,7 +331,7 @@ static struct dentry *sockfs_mount(struct file_system_type *fs_type,
100180 &sockfs_dentry_operations, SOCKFS_MAGIC);
100181 }
100182
100183 -static struct vfsmount *sock_mnt __read_mostly;
100184 +struct vfsmount *sock_mnt __read_mostly;
100185
100186 static struct file_system_type sock_fs_type = {
100187 .name = "sockfs",
100188 @@ -1255,6 +1258,8 @@ int __sock_create(struct net *net, int family, int type, int protocol,
100189 return -EAFNOSUPPORT;
100190 if (type < 0 || type >= SOCK_MAX)
100191 return -EINVAL;
100192 + if (protocol < 0)
100193 + return -EINVAL;
100194
100195 /* Compatibility.
100196
100197 @@ -1275,6 +1280,20 @@ int __sock_create(struct net *net, int family, int type, int protocol,
100198 if (err)
100199 return err;
100200
100201 + if(!kern && !gr_search_socket(family, type, protocol)) {
100202 + if (rcu_access_pointer(net_families[family]) == NULL)
100203 + return -EAFNOSUPPORT;
100204 + else
100205 + return -EACCES;
100206 + }
100207 +
100208 + if (!kern && gr_handle_sock_all(family, type, protocol)) {
100209 + if (rcu_access_pointer(net_families[family]) == NULL)
100210 + return -EAFNOSUPPORT;
100211 + else
100212 + return -EACCES;
100213 + }
100214 +
100215 /*
100216 * Allocate the socket and allow the family to set things up. if
100217 * the protocol is 0, the family is instructed to select an appropriate
100218 @@ -1513,6 +1532,14 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
100219 if (sock) {
100220 err = move_addr_to_kernel(umyaddr, addrlen, &address);
100221 if (err >= 0) {
100222 + if (gr_handle_sock_server((struct sockaddr *)&address)) {
100223 + err = -EACCES;
100224 + goto error;
100225 + }
100226 + err = gr_search_bind(sock, (struct sockaddr_in *)&address);
100227 + if (err)
100228 + goto error;
100229 +
100230 err = security_socket_bind(sock,
100231 (struct sockaddr *)&address,
100232 addrlen);
100233 @@ -1521,6 +1548,7 @@ SYSCALL_DEFINE3(bind, int, fd, struct sockaddr __user *, umyaddr, int, addrlen)
100234 (struct sockaddr *)
100235 &address, addrlen);
100236 }
100237 +error:
100238 fput_light(sock->file, fput_needed);
100239 }
100240 return err;
100241 @@ -1544,10 +1572,20 @@ SYSCALL_DEFINE2(listen, int, fd, int, backlog)
100242 if ((unsigned int)backlog > somaxconn)
100243 backlog = somaxconn;
100244
100245 + if (gr_handle_sock_server_other(sock->sk)) {
100246 + err = -EPERM;
100247 + goto error;
100248 + }
100249 +
100250 + err = gr_search_listen(sock);
100251 + if (err)
100252 + goto error;
100253 +
100254 err = security_socket_listen(sock, backlog);
100255 if (!err)
100256 err = sock->ops->listen(sock, backlog);
100257
100258 +error:
100259 fput_light(sock->file, fput_needed);
100260 }
100261 return err;
100262 @@ -1591,6 +1629,18 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
100263 newsock->type = sock->type;
100264 newsock->ops = sock->ops;
100265
100266 + if (gr_handle_sock_server_other(sock->sk)) {
100267 + err = -EPERM;
100268 + sock_release(newsock);
100269 + goto out_put;
100270 + }
100271 +
100272 + err = gr_search_accept(sock);
100273 + if (err) {
100274 + sock_release(newsock);
100275 + goto out_put;
100276 + }
100277 +
100278 /*
100279 * We don't need try_module_get here, as the listening socket (sock)
100280 * has the protocol module (sock->ops->owner) held.
100281 @@ -1636,6 +1686,8 @@ SYSCALL_DEFINE4(accept4, int, fd, struct sockaddr __user *, upeer_sockaddr,
100282 fd_install(newfd, newfile);
100283 err = newfd;
100284
100285 + gr_attach_curr_ip(newsock->sk);
100286 +
100287 out_put:
100288 fput_light(sock->file, fput_needed);
100289 out:
100290 @@ -1668,6 +1720,7 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
100291 int, addrlen)
100292 {
100293 struct socket *sock;
100294 + struct sockaddr *sck;
100295 struct sockaddr_storage address;
100296 int err, fput_needed;
100297
100298 @@ -1678,6 +1731,17 @@ SYSCALL_DEFINE3(connect, int, fd, struct sockaddr __user *, uservaddr,
100299 if (err < 0)
100300 goto out_put;
100301
100302 + sck = (struct sockaddr *)&address;
100303 +
100304 + if (gr_handle_sock_client(sck)) {
100305 + err = -EACCES;
100306 + goto out_put;
100307 + }
100308 +
100309 + err = gr_search_connect(sock, (struct sockaddr_in *)sck);
100310 + if (err)
100311 + goto out_put;
100312 +
100313 err =
100314 security_socket_connect(sock, (struct sockaddr *)&address, addrlen);
100315 if (err)
100316 @@ -1759,6 +1823,8 @@ SYSCALL_DEFINE3(getpeername, int, fd, struct sockaddr __user *, usockaddr,
100317 * the protocol.
100318 */
100319
100320 +asmlinkage long sys_sendto(int, void __user *, size_t, unsigned, struct sockaddr __user *, int);
100321 +
100322 SYSCALL_DEFINE6(sendto, int, fd, void __user *, buff, size_t, len,
100323 unsigned int, flags, struct sockaddr __user *, addr,
100324 int, addr_len)
100325 @@ -2047,7 +2113,7 @@ static int ___sys_sendmsg(struct socket *sock, struct msghdr __user *msg,
100326 * checking falls down on this.
100327 */
100328 if (copy_from_user(ctl_buf,
100329 - (void __user __force *)msg_sys->msg_control,
100330 + (void __force_user *)msg_sys->msg_control,
100331 ctl_len))
100332 goto out_freectl;
100333 msg_sys->msg_control = ctl_buf;
100334 @@ -2227,7 +2293,7 @@ static int ___sys_recvmsg(struct socket *sock, struct msghdr __user *msg,
100335 /* Save the user-mode address (verify_iovec will change the
100336 * kernel msghdr to use the kernel address space)
100337 */
100338 - uaddr = (__force void __user *)msg_sys->msg_name;
100339 + uaddr = (void __force_user *)msg_sys->msg_name;
100340 uaddr_len = COMPAT_NAMELEN(msg);
100341 if (MSG_CMSG_COMPAT & flags)
100342 err = verify_compat_iovec(msg_sys, iov, &addr, VERIFY_WRITE);
100343 @@ -2871,7 +2937,7 @@ static int ethtool_ioctl(struct net *net, struct compat_ifreq __user *ifr32)
100344 ifr = compat_alloc_user_space(buf_size);
100345 rxnfc = (void __user *)ifr + ALIGN(sizeof(struct ifreq), 8);
100346
100347 - if (copy_in_user(&ifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
100348 + if (copy_in_user(ifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
100349 return -EFAULT;
100350
100351 if (put_user(convert_in ? rxnfc : compat_ptr(data),
100352 @@ -2985,14 +3051,14 @@ static int bond_ioctl(struct net *net, unsigned int cmd,
100353 old_fs = get_fs();
100354 set_fs(KERNEL_DS);
100355 err = dev_ioctl(net, cmd,
100356 - (struct ifreq __user __force *) &kifr);
100357 + (struct ifreq __force_user *) &kifr);
100358 set_fs(old_fs);
100359
100360 return err;
100361 case SIOCBONDSLAVEINFOQUERY:
100362 case SIOCBONDINFOQUERY:
100363 uifr = compat_alloc_user_space(sizeof(*uifr));
100364 - if (copy_in_user(&uifr->ifr_name, &ifr32->ifr_name, IFNAMSIZ))
100365 + if (copy_in_user(uifr->ifr_name, ifr32->ifr_name, IFNAMSIZ))
100366 return -EFAULT;
100367
100368 if (get_user(data, &ifr32->ifr_ifru.ifru_data))
100369 @@ -3094,7 +3160,7 @@ static int compat_sioc_ifmap(struct net *net, unsigned int cmd,
100370
100371 old_fs = get_fs();
100372 set_fs(KERNEL_DS);
100373 - err = dev_ioctl(net, cmd, (void __user __force *)&ifr);
100374 + err = dev_ioctl(net, cmd, (void __force_user *)&ifr);
100375 set_fs(old_fs);
100376
100377 if (cmd == SIOCGIFMAP && !err) {
100378 @@ -3199,7 +3265,7 @@ static int routing_ioctl(struct net *net, struct socket *sock,
100379 ret |= get_user(rtdev, &(ur4->rt_dev));
100380 if (rtdev) {
100381 ret |= copy_from_user(devname, compat_ptr(rtdev), 15);
100382 - r4.rt_dev = (char __user __force *)devname;
100383 + r4.rt_dev = (char __force_user *)devname;
100384 devname[15] = 0;
100385 } else
100386 r4.rt_dev = NULL;
100387 @@ -3425,8 +3491,8 @@ int kernel_getsockopt(struct socket *sock, int level, int optname,
100388 int __user *uoptlen;
100389 int err;
100390
100391 - uoptval = (char __user __force *) optval;
100392 - uoptlen = (int __user __force *) optlen;
100393 + uoptval = (char __force_user *) optval;
100394 + uoptlen = (int __force_user *) optlen;
100395
100396 set_fs(KERNEL_DS);
100397 if (level == SOL_SOCKET)
100398 @@ -3446,7 +3512,7 @@ int kernel_setsockopt(struct socket *sock, int level, int optname,
100399 char __user *uoptval;
100400 int err;
100401
100402 - uoptval = (char __user __force *) optval;
100403 + uoptval = (char __force_user *) optval;
100404
100405 set_fs(KERNEL_DS);
100406 if (level == SOL_SOCKET)
100407 diff --git a/net/sunrpc/auth_gss/svcauth_gss.c b/net/sunrpc/auth_gss/svcauth_gss.c
100408 index 1b94a9c..496f7f5 100644
100409 --- a/net/sunrpc/auth_gss/svcauth_gss.c
100410 +++ b/net/sunrpc/auth_gss/svcauth_gss.c
100411 @@ -1140,7 +1140,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
100412 uint64_t *handle)
100413 {
100414 struct rsc rsci, *rscp = NULL;
100415 - static atomic64_t ctxhctr;
100416 + static atomic64_unchecked_t ctxhctr = ATOMIC64_INIT(0);
100417 long long ctxh;
100418 struct gss_api_mech *gm = NULL;
100419 time_t expiry;
100420 @@ -1151,7 +1151,7 @@ static int gss_proxy_save_rsc(struct cache_detail *cd,
100421 status = -ENOMEM;
100422 /* the handle needs to be just a unique id,
100423 * use a static counter */
100424 - ctxh = atomic64_inc_return(&ctxhctr);
100425 + ctxh = atomic64_inc_return_unchecked(&ctxhctr);
100426
100427 /* make a copy for the caller */
100428 *handle = ctxh;
100429 diff --git a/net/sunrpc/clnt.c b/net/sunrpc/clnt.c
100430 index e726e16..393c39e 100644
100431 --- a/net/sunrpc/clnt.c
100432 +++ b/net/sunrpc/clnt.c
100433 @@ -1415,7 +1415,9 @@ call_start(struct rpc_task *task)
100434 (RPC_IS_ASYNC(task) ? "async" : "sync"));
100435
100436 /* Increment call count */
100437 - task->tk_msg.rpc_proc->p_count++;
100438 + pax_open_kernel();
100439 + (*(unsigned int *)&task->tk_msg.rpc_proc->p_count)++;
100440 + pax_close_kernel();
100441 clnt->cl_stats->rpccnt++;
100442 task->tk_action = call_reserve;
100443 }
100444 diff --git a/net/sunrpc/sched.c b/net/sunrpc/sched.c
100445 index ff3cc4b..7612a9e 100644
100446 --- a/net/sunrpc/sched.c
100447 +++ b/net/sunrpc/sched.c
100448 @@ -261,9 +261,9 @@ static int rpc_wait_bit_killable(void *word)
100449 #if defined(RPC_DEBUG) || defined(RPC_TRACEPOINTS)
100450 static void rpc_task_set_debuginfo(struct rpc_task *task)
100451 {
100452 - static atomic_t rpc_pid;
100453 + static atomic_unchecked_t rpc_pid;
100454
100455 - task->tk_pid = atomic_inc_return(&rpc_pid);
100456 + task->tk_pid = atomic_inc_return_unchecked(&rpc_pid);
100457 }
100458 #else
100459 static inline void rpc_task_set_debuginfo(struct rpc_task *task)
100460 diff --git a/net/sunrpc/svc.c b/net/sunrpc/svc.c
100461 index e7fbe36..8052603 100644
100462 --- a/net/sunrpc/svc.c
100463 +++ b/net/sunrpc/svc.c
100464 @@ -1158,7 +1158,9 @@ svc_process_common(struct svc_rqst *rqstp, struct kvec *argv, struct kvec *resv)
100465 svc_putnl(resv, RPC_SUCCESS);
100466
100467 /* Bump per-procedure stats counter */
100468 - procp->pc_count++;
100469 + pax_open_kernel();
100470 + (*(unsigned int *)&procp->pc_count)++;
100471 + pax_close_kernel();
100472
100473 /* Initialize storage for argp and resp */
100474 memset(rqstp->rq_argp, 0, procp->pc_argsize);
100475 diff --git a/net/sunrpc/svcauth_unix.c b/net/sunrpc/svcauth_unix.c
100476 index 621ca7b..59421dd 100644
100477 --- a/net/sunrpc/svcauth_unix.c
100478 +++ b/net/sunrpc/svcauth_unix.c
100479 @@ -414,7 +414,7 @@ struct unix_gid {
100480 struct group_info *gi;
100481 };
100482
100483 -static int unix_gid_hash(kuid_t uid)
100484 +static int __intentional_overflow(-1) unix_gid_hash(kuid_t uid)
100485 {
100486 return hash_long(from_kuid(&init_user_ns, uid), GID_HASHBITS);
100487 }
100488 @@ -470,7 +470,7 @@ static void unix_gid_request(struct cache_detail *cd,
100489 (*bpp)[-1] = '\n';
100490 }
100491
100492 -static struct unix_gid *unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
100493 +static struct unix_gid * __intentional_overflow(-1) unix_gid_lookup(struct cache_detail *cd, kuid_t uid);
100494
100495 static int unix_gid_parse(struct cache_detail *cd,
100496 char *mesg, int mlen)
100497 diff --git a/net/sunrpc/xprtrdma/svc_rdma.c b/net/sunrpc/xprtrdma/svc_rdma.c
100498 index c1b6270..05089c1 100644
100499 --- a/net/sunrpc/xprtrdma/svc_rdma.c
100500 +++ b/net/sunrpc/xprtrdma/svc_rdma.c
100501 @@ -62,15 +62,15 @@ unsigned int svcrdma_max_req_size = RPCRDMA_MAX_REQ_SIZE;
100502 static unsigned int min_max_inline = 4096;
100503 static unsigned int max_max_inline = 65536;
100504
100505 -atomic_t rdma_stat_recv;
100506 -atomic_t rdma_stat_read;
100507 -atomic_t rdma_stat_write;
100508 -atomic_t rdma_stat_sq_starve;
100509 -atomic_t rdma_stat_rq_starve;
100510 -atomic_t rdma_stat_rq_poll;
100511 -atomic_t rdma_stat_rq_prod;
100512 -atomic_t rdma_stat_sq_poll;
100513 -atomic_t rdma_stat_sq_prod;
100514 +atomic_unchecked_t rdma_stat_recv;
100515 +atomic_unchecked_t rdma_stat_read;
100516 +atomic_unchecked_t rdma_stat_write;
100517 +atomic_unchecked_t rdma_stat_sq_starve;
100518 +atomic_unchecked_t rdma_stat_rq_starve;
100519 +atomic_unchecked_t rdma_stat_rq_poll;
100520 +atomic_unchecked_t rdma_stat_rq_prod;
100521 +atomic_unchecked_t rdma_stat_sq_poll;
100522 +atomic_unchecked_t rdma_stat_sq_prod;
100523
100524 /* Temporary NFS request map and context caches */
100525 struct kmem_cache *svc_rdma_map_cachep;
100526 @@ -110,7 +110,7 @@ static int read_reset_stat(struct ctl_table *table, int write,
100527 len -= *ppos;
100528 if (len > *lenp)
100529 len = *lenp;
100530 - if (len && copy_to_user(buffer, str_buf, len))
100531 + if (len > sizeof str_buf || (len && copy_to_user(buffer, str_buf, len)))
100532 return -EFAULT;
100533 *lenp = len;
100534 *ppos += len;
100535 @@ -151,63 +151,63 @@ static struct ctl_table svcrdma_parm_table[] = {
100536 {
100537 .procname = "rdma_stat_read",
100538 .data = &rdma_stat_read,
100539 - .maxlen = sizeof(atomic_t),
100540 + .maxlen = sizeof(atomic_unchecked_t),
100541 .mode = 0644,
100542 .proc_handler = read_reset_stat,
100543 },
100544 {
100545 .procname = "rdma_stat_recv",
100546 .data = &rdma_stat_recv,
100547 - .maxlen = sizeof(atomic_t),
100548 + .maxlen = sizeof(atomic_unchecked_t),
100549 .mode = 0644,
100550 .proc_handler = read_reset_stat,
100551 },
100552 {
100553 .procname = "rdma_stat_write",
100554 .data = &rdma_stat_write,
100555 - .maxlen = sizeof(atomic_t),
100556 + .maxlen = sizeof(atomic_unchecked_t),
100557 .mode = 0644,
100558 .proc_handler = read_reset_stat,
100559 },
100560 {
100561 .procname = "rdma_stat_sq_starve",
100562 .data = &rdma_stat_sq_starve,
100563 - .maxlen = sizeof(atomic_t),
100564 + .maxlen = sizeof(atomic_unchecked_t),
100565 .mode = 0644,
100566 .proc_handler = read_reset_stat,
100567 },
100568 {
100569 .procname = "rdma_stat_rq_starve",
100570 .data = &rdma_stat_rq_starve,
100571 - .maxlen = sizeof(atomic_t),
100572 + .maxlen = sizeof(atomic_unchecked_t),
100573 .mode = 0644,
100574 .proc_handler = read_reset_stat,
100575 },
100576 {
100577 .procname = "rdma_stat_rq_poll",
100578 .data = &rdma_stat_rq_poll,
100579 - .maxlen = sizeof(atomic_t),
100580 + .maxlen = sizeof(atomic_unchecked_t),
100581 .mode = 0644,
100582 .proc_handler = read_reset_stat,
100583 },
100584 {
100585 .procname = "rdma_stat_rq_prod",
100586 .data = &rdma_stat_rq_prod,
100587 - .maxlen = sizeof(atomic_t),
100588 + .maxlen = sizeof(atomic_unchecked_t),
100589 .mode = 0644,
100590 .proc_handler = read_reset_stat,
100591 },
100592 {
100593 .procname = "rdma_stat_sq_poll",
100594 .data = &rdma_stat_sq_poll,
100595 - .maxlen = sizeof(atomic_t),
100596 + .maxlen = sizeof(atomic_unchecked_t),
100597 .mode = 0644,
100598 .proc_handler = read_reset_stat,
100599 },
100600 {
100601 .procname = "rdma_stat_sq_prod",
100602 .data = &rdma_stat_sq_prod,
100603 - .maxlen = sizeof(atomic_t),
100604 + .maxlen = sizeof(atomic_unchecked_t),
100605 .mode = 0644,
100606 .proc_handler = read_reset_stat,
100607 },
100608 diff --git a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
100609 index 0ce7552..d074459 100644
100610 --- a/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
100611 +++ b/net/sunrpc/xprtrdma/svc_rdma_recvfrom.c
100612 @@ -501,7 +501,7 @@ next_sge:
100613 svc_rdma_put_context(ctxt, 0);
100614 goto out;
100615 }
100616 - atomic_inc(&rdma_stat_read);
100617 + atomic_inc_unchecked(&rdma_stat_read);
100618
100619 if (read_wr.num_sge < chl_map->ch[ch_no].count) {
100620 chl_map->ch[ch_no].count -= read_wr.num_sge;
100621 @@ -611,7 +611,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
100622 dto_q);
100623 list_del_init(&ctxt->dto_q);
100624 } else {
100625 - atomic_inc(&rdma_stat_rq_starve);
100626 + atomic_inc_unchecked(&rdma_stat_rq_starve);
100627 clear_bit(XPT_DATA, &xprt->xpt_flags);
100628 ctxt = NULL;
100629 }
100630 @@ -631,7 +631,7 @@ int svc_rdma_recvfrom(struct svc_rqst *rqstp)
100631 dprintk("svcrdma: processing ctxt=%p on xprt=%p, rqstp=%p, status=%d\n",
100632 ctxt, rdma_xprt, rqstp, ctxt->wc_status);
100633 BUG_ON(ctxt->wc_status != IB_WC_SUCCESS);
100634 - atomic_inc(&rdma_stat_recv);
100635 + atomic_inc_unchecked(&rdma_stat_recv);
100636
100637 /* Build up the XDR from the receive buffers. */
100638 rdma_build_arg_xdr(rqstp, ctxt, ctxt->byte_len);
100639 diff --git a/net/sunrpc/xprtrdma/svc_rdma_sendto.c b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
100640 index c1d124d..acfc59e 100644
100641 --- a/net/sunrpc/xprtrdma/svc_rdma_sendto.c
100642 +++ b/net/sunrpc/xprtrdma/svc_rdma_sendto.c
100643 @@ -362,7 +362,7 @@ static int send_write(struct svcxprt_rdma *xprt, struct svc_rqst *rqstp,
100644 write_wr.wr.rdma.remote_addr = to;
100645
100646 /* Post It */
100647 - atomic_inc(&rdma_stat_write);
100648 + atomic_inc_unchecked(&rdma_stat_write);
100649 if (svc_rdma_send(xprt, &write_wr))
100650 goto err;
100651 return 0;
100652 diff --git a/net/sunrpc/xprtrdma/svc_rdma_transport.c b/net/sunrpc/xprtrdma/svc_rdma_transport.c
100653 index 62e4f9b..dd3f2d7 100644
100654 --- a/net/sunrpc/xprtrdma/svc_rdma_transport.c
100655 +++ b/net/sunrpc/xprtrdma/svc_rdma_transport.c
100656 @@ -292,7 +292,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
100657 return;
100658
100659 ib_req_notify_cq(xprt->sc_rq_cq, IB_CQ_NEXT_COMP);
100660 - atomic_inc(&rdma_stat_rq_poll);
100661 + atomic_inc_unchecked(&rdma_stat_rq_poll);
100662
100663 while ((ret = ib_poll_cq(xprt->sc_rq_cq, 1, &wc)) > 0) {
100664 ctxt = (struct svc_rdma_op_ctxt *)(unsigned long)wc.wr_id;
100665 @@ -314,7 +314,7 @@ static void rq_cq_reap(struct svcxprt_rdma *xprt)
100666 }
100667
100668 if (ctxt)
100669 - atomic_inc(&rdma_stat_rq_prod);
100670 + atomic_inc_unchecked(&rdma_stat_rq_prod);
100671
100672 set_bit(XPT_DATA, &xprt->sc_xprt.xpt_flags);
100673 /*
100674 @@ -386,7 +386,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
100675 return;
100676
100677 ib_req_notify_cq(xprt->sc_sq_cq, IB_CQ_NEXT_COMP);
100678 - atomic_inc(&rdma_stat_sq_poll);
100679 + atomic_inc_unchecked(&rdma_stat_sq_poll);
100680 while ((ret = ib_poll_cq(cq, 1, &wc)) > 0) {
100681 if (wc.status != IB_WC_SUCCESS)
100682 /* Close the transport */
100683 @@ -404,7 +404,7 @@ static void sq_cq_reap(struct svcxprt_rdma *xprt)
100684 }
100685
100686 if (ctxt)
100687 - atomic_inc(&rdma_stat_sq_prod);
100688 + atomic_inc_unchecked(&rdma_stat_sq_prod);
100689 }
100690
100691 static void sq_comp_handler(struct ib_cq *cq, void *cq_context)
100692 @@ -1262,7 +1262,7 @@ int svc_rdma_send(struct svcxprt_rdma *xprt, struct ib_send_wr *wr)
100693 spin_lock_bh(&xprt->sc_lock);
100694 if (xprt->sc_sq_depth < atomic_read(&xprt->sc_sq_count) + wr_count) {
100695 spin_unlock_bh(&xprt->sc_lock);
100696 - atomic_inc(&rdma_stat_sq_starve);
100697 + atomic_inc_unchecked(&rdma_stat_sq_starve);
100698
100699 /* See if we can opportunistically reap SQ WR to make room */
100700 sq_cq_reap(xprt);
100701 diff --git a/net/sysctl_net.c b/net/sysctl_net.c
100702 index e7000be..e3b0ba7 100644
100703 --- a/net/sysctl_net.c
100704 +++ b/net/sysctl_net.c
100705 @@ -46,7 +46,7 @@ static int net_ctl_permissions(struct ctl_table_header *head,
100706 kgid_t root_gid = make_kgid(net->user_ns, 0);
100707
100708 /* Allow network administrator to have same access as root. */
100709 - if (ns_capable(net->user_ns, CAP_NET_ADMIN) ||
100710 + if (ns_capable_nolog(net->user_ns, CAP_NET_ADMIN) ||
100711 uid_eq(root_uid, current_euid())) {
100712 int mode = (table->mode >> 6) & 7;
100713 return (mode << 6) | (mode << 3) | mode;
100714 diff --git a/net/tipc/subscr.c b/net/tipc/subscr.c
100715 index d38bb45..38d5df5 100644
100716 --- a/net/tipc/subscr.c
100717 +++ b/net/tipc/subscr.c
100718 @@ -98,7 +98,7 @@ static void subscr_send_event(struct tipc_subscription *sub, u32 found_lower,
100719 struct kvec msg_sect;
100720 int ret;
100721
100722 - msg_sect.iov_base = (void *)&sub->evt;
100723 + msg_sect.iov_base = &sub->evt;
100724 msg_sect.iov_len = sizeof(struct tipc_event);
100725
100726 sub->evt.event = htohl(event, sub->swap);
100727 diff --git a/net/unix/af_unix.c b/net/unix/af_unix.c
100728 index a427623..387c80b 100644
100729 --- a/net/unix/af_unix.c
100730 +++ b/net/unix/af_unix.c
100731 @@ -790,6 +790,12 @@ static struct sock *unix_find_other(struct net *net,
100732 err = -ECONNREFUSED;
100733 if (!S_ISSOCK(inode->i_mode))
100734 goto put_fail;
100735 +
100736 + if (!gr_acl_handle_unix(path.dentry, path.mnt)) {
100737 + err = -EACCES;
100738 + goto put_fail;
100739 + }
100740 +
100741 u = unix_find_socket_byinode(inode);
100742 if (!u)
100743 goto put_fail;
100744 @@ -810,6 +816,13 @@ static struct sock *unix_find_other(struct net *net,
100745 if (u) {
100746 struct dentry *dentry;
100747 dentry = unix_sk(u)->path.dentry;
100748 +
100749 + if (!gr_handle_chroot_unix(pid_vnr(u->sk_peer_pid))) {
100750 + err = -EPERM;
100751 + sock_put(u);
100752 + goto fail;
100753 + }
100754 +
100755 if (dentry)
100756 touch_atime(&unix_sk(u)->path);
100757 } else
100758 @@ -843,12 +856,18 @@ static int unix_mknod(const char *sun_path, umode_t mode, struct path *res)
100759 */
100760 err = security_path_mknod(&path, dentry, mode, 0);
100761 if (!err) {
100762 + if (!gr_acl_handle_mknod(dentry, path.dentry, path.mnt, mode)) {
100763 + err = -EACCES;
100764 + goto out;
100765 + }
100766 err = vfs_mknod(path.dentry->d_inode, dentry, mode, 0);
100767 if (!err) {
100768 res->mnt = mntget(path.mnt);
100769 res->dentry = dget(dentry);
100770 + gr_handle_create(dentry, path.mnt);
100771 }
100772 }
100773 +out:
100774 done_path_create(&path, dentry);
100775 return err;
100776 }
100777 @@ -2336,9 +2355,13 @@ static int unix_seq_show(struct seq_file *seq, void *v)
100778 seq_puts(seq, "Num RefCount Protocol Flags Type St "
100779 "Inode Path\n");
100780 else {
100781 - struct sock *s = v;
100782 + struct sock *s = v, *peer;
100783 struct unix_sock *u = unix_sk(s);
100784 unix_state_lock(s);
100785 + peer = unix_peer(s);
100786 + unix_state_unlock(s);
100787 +
100788 + unix_state_double_lock(s, peer);
100789
100790 seq_printf(seq, "%pK: %08X %08X %08X %04X %02X %5lu",
100791 s,
100792 @@ -2365,8 +2388,10 @@ static int unix_seq_show(struct seq_file *seq, void *v)
100793 }
100794 for ( ; i < len; i++)
100795 seq_putc(seq, u->addr->name->sun_path[i]);
100796 - }
100797 - unix_state_unlock(s);
100798 + } else if (peer)
100799 + seq_printf(seq, " P%lu", sock_i_ino(peer));
100800 +
100801 + unix_state_double_unlock(s, peer);
100802 seq_putc(seq, '\n');
100803 }
100804
100805 diff --git a/net/unix/sysctl_net_unix.c b/net/unix/sysctl_net_unix.c
100806 index b3d5150..ff3a837 100644
100807 --- a/net/unix/sysctl_net_unix.c
100808 +++ b/net/unix/sysctl_net_unix.c
100809 @@ -28,7 +28,7 @@ static struct ctl_table unix_table[] = {
100810
100811 int __net_init unix_sysctl_register(struct net *net)
100812 {
100813 - struct ctl_table *table;
100814 + ctl_table_no_const *table;
100815
100816 table = kmemdup(unix_table, sizeof(unix_table), GFP_KERNEL);
100817 if (table == NULL)
100818 diff --git a/net/vmw_vsock/vmci_transport_notify.c b/net/vmw_vsock/vmci_transport_notify.c
100819 index 9a73074..aecba9a 100644
100820 --- a/net/vmw_vsock/vmci_transport_notify.c
100821 +++ b/net/vmw_vsock/vmci_transport_notify.c
100822 @@ -662,19 +662,19 @@ static void vmci_transport_notify_pkt_process_negotiate(struct sock *sk)
100823
100824 /* Socket control packet based operations. */
100825 struct vmci_transport_notify_ops vmci_transport_notify_pkt_ops = {
100826 - vmci_transport_notify_pkt_socket_init,
100827 - vmci_transport_notify_pkt_socket_destruct,
100828 - vmci_transport_notify_pkt_poll_in,
100829 - vmci_transport_notify_pkt_poll_out,
100830 - vmci_transport_notify_pkt_handle_pkt,
100831 - vmci_transport_notify_pkt_recv_init,
100832 - vmci_transport_notify_pkt_recv_pre_block,
100833 - vmci_transport_notify_pkt_recv_pre_dequeue,
100834 - vmci_transport_notify_pkt_recv_post_dequeue,
100835 - vmci_transport_notify_pkt_send_init,
100836 - vmci_transport_notify_pkt_send_pre_block,
100837 - vmci_transport_notify_pkt_send_pre_enqueue,
100838 - vmci_transport_notify_pkt_send_post_enqueue,
100839 - vmci_transport_notify_pkt_process_request,
100840 - vmci_transport_notify_pkt_process_negotiate,
100841 + .socket_init = vmci_transport_notify_pkt_socket_init,
100842 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
100843 + .poll_in = vmci_transport_notify_pkt_poll_in,
100844 + .poll_out = vmci_transport_notify_pkt_poll_out,
100845 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
100846 + .recv_init = vmci_transport_notify_pkt_recv_init,
100847 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
100848 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
100849 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
100850 + .send_init = vmci_transport_notify_pkt_send_init,
100851 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
100852 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
100853 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
100854 + .process_request = vmci_transport_notify_pkt_process_request,
100855 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
100856 };
100857 diff --git a/net/vmw_vsock/vmci_transport_notify_qstate.c b/net/vmw_vsock/vmci_transport_notify_qstate.c
100858 index 622bd7a..b92086c 100644
100859 --- a/net/vmw_vsock/vmci_transport_notify_qstate.c
100860 +++ b/net/vmw_vsock/vmci_transport_notify_qstate.c
100861 @@ -420,19 +420,19 @@ vmci_transport_notify_pkt_send_pre_enqueue(
100862
100863 /* Socket always on control packet based operations. */
100864 struct vmci_transport_notify_ops vmci_transport_notify_pkt_q_state_ops = {
100865 - vmci_transport_notify_pkt_socket_init,
100866 - vmci_transport_notify_pkt_socket_destruct,
100867 - vmci_transport_notify_pkt_poll_in,
100868 - vmci_transport_notify_pkt_poll_out,
100869 - vmci_transport_notify_pkt_handle_pkt,
100870 - vmci_transport_notify_pkt_recv_init,
100871 - vmci_transport_notify_pkt_recv_pre_block,
100872 - vmci_transport_notify_pkt_recv_pre_dequeue,
100873 - vmci_transport_notify_pkt_recv_post_dequeue,
100874 - vmci_transport_notify_pkt_send_init,
100875 - vmci_transport_notify_pkt_send_pre_block,
100876 - vmci_transport_notify_pkt_send_pre_enqueue,
100877 - vmci_transport_notify_pkt_send_post_enqueue,
100878 - vmci_transport_notify_pkt_process_request,
100879 - vmci_transport_notify_pkt_process_negotiate,
100880 + .socket_init = vmci_transport_notify_pkt_socket_init,
100881 + .socket_destruct = vmci_transport_notify_pkt_socket_destruct,
100882 + .poll_in = vmci_transport_notify_pkt_poll_in,
100883 + .poll_out = vmci_transport_notify_pkt_poll_out,
100884 + .handle_notify_pkt = vmci_transport_notify_pkt_handle_pkt,
100885 + .recv_init = vmci_transport_notify_pkt_recv_init,
100886 + .recv_pre_block = vmci_transport_notify_pkt_recv_pre_block,
100887 + .recv_pre_dequeue = vmci_transport_notify_pkt_recv_pre_dequeue,
100888 + .recv_post_dequeue = vmci_transport_notify_pkt_recv_post_dequeue,
100889 + .send_init = vmci_transport_notify_pkt_send_init,
100890 + .send_pre_block = vmci_transport_notify_pkt_send_pre_block,
100891 + .send_pre_enqueue = vmci_transport_notify_pkt_send_pre_enqueue,
100892 + .send_post_enqueue = vmci_transport_notify_pkt_send_post_enqueue,
100893 + .process_request = vmci_transport_notify_pkt_process_request,
100894 + .process_negotiate = vmci_transport_notify_pkt_process_negotiate,
100895 };
100896 diff --git a/net/wireless/wext-core.c b/net/wireless/wext-core.c
100897 index c8717c1..08539f5 100644
100898 --- a/net/wireless/wext-core.c
100899 +++ b/net/wireless/wext-core.c
100900 @@ -748,8 +748,7 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
100901 */
100902
100903 /* Support for very large requests */
100904 - if ((descr->flags & IW_DESCR_FLAG_NOMAX) &&
100905 - (user_length > descr->max_tokens)) {
100906 + if (user_length > descr->max_tokens) {
100907 /* Allow userspace to GET more than max so
100908 * we can support any size GET requests.
100909 * There is still a limit : -ENOMEM.
100910 @@ -788,22 +787,6 @@ static int ioctl_standard_iw_point(struct iw_point *iwp, unsigned int cmd,
100911 }
100912 }
100913
100914 - if (IW_IS_GET(cmd) && !(descr->flags & IW_DESCR_FLAG_NOMAX)) {
100915 - /*
100916 - * If this is a GET, but not NOMAX, it means that the extra
100917 - * data is not bounded by userspace, but by max_tokens. Thus
100918 - * set the length to max_tokens. This matches the extra data
100919 - * allocation.
100920 - * The driver should fill it with the number of tokens it
100921 - * provided, and it may check iwp->length rather than having
100922 - * knowledge of max_tokens. If the driver doesn't change the
100923 - * iwp->length, this ioctl just copies back max_token tokens
100924 - * filled with zeroes. Hopefully the driver isn't claiming
100925 - * them to be valid data.
100926 - */
100927 - iwp->length = descr->max_tokens;
100928 - }
100929 -
100930 err = handler(dev, info, (union iwreq_data *) iwp, extra);
100931
100932 iwp->length += essid_compat;
100933 diff --git a/net/x25/sysctl_net_x25.c b/net/x25/sysctl_net_x25.c
100934 index 4323952..a06dfe1 100644
100935 --- a/net/x25/sysctl_net_x25.c
100936 +++ b/net/x25/sysctl_net_x25.c
100937 @@ -70,7 +70,7 @@ static struct ctl_table x25_table[] = {
100938 .mode = 0644,
100939 .proc_handler = proc_dointvec,
100940 },
100941 - { 0, },
100942 + { },
100943 };
100944
100945 void __init x25_register_sysctl(void)
100946 diff --git a/net/xfrm/xfrm_policy.c b/net/xfrm/xfrm_policy.c
100947 index 9a91f74..502f6605 100644
100948 --- a/net/xfrm/xfrm_policy.c
100949 +++ b/net/xfrm/xfrm_policy.c
100950 @@ -332,7 +332,7 @@ static void xfrm_policy_kill(struct xfrm_policy *policy)
100951 {
100952 policy->walk.dead = 1;
100953
100954 - atomic_inc(&policy->genid);
100955 + atomic_inc_unchecked(&policy->genid);
100956
100957 if (del_timer(&policy->polq.hold_timer))
100958 xfrm_pol_put(policy);
100959 @@ -660,7 +660,7 @@ int xfrm_policy_insert(int dir, struct xfrm_policy *policy, int excl)
100960 hlist_add_head(&policy->bydst, chain);
100961 xfrm_pol_hold(policy);
100962 net->xfrm.policy_count[dir]++;
100963 - atomic_inc(&flow_cache_genid);
100964 + atomic_inc_unchecked(&flow_cache_genid);
100965
100966 /* After previous checking, family can either be AF_INET or AF_INET6 */
100967 if (policy->family == AF_INET)
100968 @@ -1636,7 +1636,7 @@ free_dst:
100969 goto out;
100970 }
100971
100972 -static int inline
100973 +static inline int
100974 xfrm_dst_alloc_copy(void **target, const void *src, int size)
100975 {
100976 if (!*target) {
100977 @@ -1648,7 +1648,7 @@ xfrm_dst_alloc_copy(void **target, const void *src, int size)
100978 return 0;
100979 }
100980
100981 -static int inline
100982 +static inline int
100983 xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
100984 {
100985 #ifdef CONFIG_XFRM_SUB_POLICY
100986 @@ -1660,7 +1660,7 @@ xfrm_dst_update_parent(struct dst_entry *dst, const struct xfrm_selector *sel)
100987 #endif
100988 }
100989
100990 -static int inline
100991 +static inline int
100992 xfrm_dst_update_origin(struct dst_entry *dst, const struct flowi *fl)
100993 {
100994 #ifdef CONFIG_XFRM_SUB_POLICY
100995 @@ -1754,7 +1754,7 @@ xfrm_resolve_and_create_bundle(struct xfrm_policy **pols, int num_pols,
100996
100997 xdst->num_pols = num_pols;
100998 memcpy(xdst->pols, pols, sizeof(struct xfrm_policy*) * num_pols);
100999 - xdst->policy_genid = atomic_read(&pols[0]->genid);
101000 + xdst->policy_genid = atomic_read_unchecked(&pols[0]->genid);
101001
101002 return xdst;
101003 }
101004 @@ -2582,11 +2582,12 @@ void xfrm_garbage_collect(struct net *net)
101005 }
101006 EXPORT_SYMBOL(xfrm_garbage_collect);
101007
101008 -static void xfrm_garbage_collect_deferred(struct net *net)
101009 +void xfrm_garbage_collect_deferred(struct net *net)
101010 {
101011 flow_cache_flush_deferred();
101012 __xfrm_garbage_collect(net);
101013 }
101014 +EXPORT_SYMBOL(xfrm_garbage_collect_deferred);
101015
101016 static void xfrm_init_pmtu(struct dst_entry *dst)
101017 {
101018 @@ -2636,7 +2637,7 @@ static int xfrm_bundle_ok(struct xfrm_dst *first)
101019 if (xdst->xfrm_genid != dst->xfrm->genid)
101020 return 0;
101021 if (xdst->num_pols > 0 &&
101022 - xdst->policy_genid != atomic_read(&xdst->pols[0]->genid))
101023 + xdst->policy_genid != atomic_read_unchecked(&xdst->pols[0]->genid))
101024 return 0;
101025
101026 mtu = dst_mtu(dst->child);
101027 @@ -2724,8 +2725,6 @@ int xfrm_policy_register_afinfo(struct xfrm_policy_afinfo *afinfo)
101028 dst_ops->link_failure = xfrm_link_failure;
101029 if (likely(dst_ops->neigh_lookup == NULL))
101030 dst_ops->neigh_lookup = xfrm_neigh_lookup;
101031 - if (likely(afinfo->garbage_collect == NULL))
101032 - afinfo->garbage_collect = xfrm_garbage_collect_deferred;
101033 rcu_assign_pointer(xfrm_policy_afinfo[afinfo->family], afinfo);
101034 }
101035 spin_unlock(&xfrm_policy_afinfo_lock);
101036 @@ -2779,7 +2778,6 @@ int xfrm_policy_unregister_afinfo(struct xfrm_policy_afinfo *afinfo)
101037 dst_ops->check = NULL;
101038 dst_ops->negative_advice = NULL;
101039 dst_ops->link_failure = NULL;
101040 - afinfo->garbage_collect = NULL;
101041 }
101042 return err;
101043 }
101044 @@ -3162,7 +3160,7 @@ static int xfrm_policy_migrate(struct xfrm_policy *pol,
101045 sizeof(pol->xfrm_vec[i].saddr));
101046 pol->xfrm_vec[i].encap_family = mp->new_family;
101047 /* flush bundles */
101048 - atomic_inc(&pol->genid);
101049 + atomic_inc_unchecked(&pol->genid);
101050 }
101051 }
101052
101053 diff --git a/net/xfrm/xfrm_state.c b/net/xfrm/xfrm_state.c
101054 index 68c2f35..9eb05ca 100644
101055 --- a/net/xfrm/xfrm_state.c
101056 +++ b/net/xfrm/xfrm_state.c
101057 @@ -174,12 +174,14 @@ int xfrm_register_type(const struct xfrm_type *type, unsigned short family)
101058
101059 if (unlikely(afinfo == NULL))
101060 return -EAFNOSUPPORT;
101061 - typemap = afinfo->type_map;
101062 + typemap = (const struct xfrm_type **)afinfo->type_map;
101063 spin_lock_bh(&xfrm_type_lock);
101064
101065 - if (likely(typemap[type->proto] == NULL))
101066 + if (likely(typemap[type->proto] == NULL)) {
101067 + pax_open_kernel();
101068 typemap[type->proto] = type;
101069 - else
101070 + pax_close_kernel();
101071 + } else
101072 err = -EEXIST;
101073 spin_unlock_bh(&xfrm_type_lock);
101074 xfrm_state_put_afinfo(afinfo);
101075 @@ -195,13 +197,16 @@ int xfrm_unregister_type(const struct xfrm_type *type, unsigned short family)
101076
101077 if (unlikely(afinfo == NULL))
101078 return -EAFNOSUPPORT;
101079 - typemap = afinfo->type_map;
101080 + typemap = (const struct xfrm_type **)afinfo->type_map;
101081 spin_lock_bh(&xfrm_type_lock);
101082
101083 if (unlikely(typemap[type->proto] != type))
101084 err = -ENOENT;
101085 - else
101086 + else {
101087 + pax_open_kernel();
101088 typemap[type->proto] = NULL;
101089 + pax_close_kernel();
101090 + }
101091 spin_unlock_bh(&xfrm_type_lock);
101092 xfrm_state_put_afinfo(afinfo);
101093 return err;
101094 @@ -211,7 +216,6 @@ EXPORT_SYMBOL(xfrm_unregister_type);
101095 static const struct xfrm_type *xfrm_get_type(u8 proto, unsigned short family)
101096 {
101097 struct xfrm_state_afinfo *afinfo;
101098 - const struct xfrm_type **typemap;
101099 const struct xfrm_type *type;
101100 int modload_attempted = 0;
101101
101102 @@ -219,9 +223,8 @@ retry:
101103 afinfo = xfrm_state_get_afinfo(family);
101104 if (unlikely(afinfo == NULL))
101105 return NULL;
101106 - typemap = afinfo->type_map;
101107
101108 - type = typemap[proto];
101109 + type = afinfo->type_map[proto];
101110 if (unlikely(type && !try_module_get(type->owner)))
101111 type = NULL;
101112 if (!type && !modload_attempted) {
101113 @@ -255,7 +258,7 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
101114 return -EAFNOSUPPORT;
101115
101116 err = -EEXIST;
101117 - modemap = afinfo->mode_map;
101118 + modemap = (struct xfrm_mode **)afinfo->mode_map;
101119 spin_lock_bh(&xfrm_mode_lock);
101120 if (modemap[mode->encap])
101121 goto out;
101122 @@ -264,8 +267,10 @@ int xfrm_register_mode(struct xfrm_mode *mode, int family)
101123 if (!try_module_get(afinfo->owner))
101124 goto out;
101125
101126 - mode->afinfo = afinfo;
101127 + pax_open_kernel();
101128 + *(const void **)&mode->afinfo = afinfo;
101129 modemap[mode->encap] = mode;
101130 + pax_close_kernel();
101131 err = 0;
101132
101133 out:
101134 @@ -289,10 +294,12 @@ int xfrm_unregister_mode(struct xfrm_mode *mode, int family)
101135 return -EAFNOSUPPORT;
101136
101137 err = -ENOENT;
101138 - modemap = afinfo->mode_map;
101139 + modemap = (struct xfrm_mode **)afinfo->mode_map;
101140 spin_lock_bh(&xfrm_mode_lock);
101141 if (likely(modemap[mode->encap] == mode)) {
101142 + pax_open_kernel();
101143 modemap[mode->encap] = NULL;
101144 + pax_close_kernel();
101145 module_put(mode->afinfo->owner);
101146 err = 0;
101147 }
101148 @@ -1486,10 +1493,10 @@ EXPORT_SYMBOL(xfrm_find_acq_byseq);
101149 u32 xfrm_get_acqseq(void)
101150 {
101151 u32 res;
101152 - static atomic_t acqseq;
101153 + static atomic_unchecked_t acqseq;
101154
101155 do {
101156 - res = atomic_inc_return(&acqseq);
101157 + res = atomic_inc_return_unchecked(&acqseq);
101158 } while (!res);
101159
101160 return res;
101161 diff --git a/net/xfrm/xfrm_sysctl.c b/net/xfrm/xfrm_sysctl.c
101162 index 05a6e3d..6716ec9 100644
101163 --- a/net/xfrm/xfrm_sysctl.c
101164 +++ b/net/xfrm/xfrm_sysctl.c
101165 @@ -42,7 +42,7 @@ static struct ctl_table xfrm_table[] = {
101166
101167 int __net_init xfrm_sysctl_init(struct net *net)
101168 {
101169 - struct ctl_table *table;
101170 + ctl_table_no_const *table;
101171
101172 __xfrm_sysctl_init(net);
101173
101174 diff --git a/scripts/Makefile b/scripts/Makefile
101175 index 01e7adb..6176d5d 100644
101176 --- a/scripts/Makefile
101177 +++ b/scripts/Makefile
101178 @@ -40,3 +40,5 @@ subdir-$(CONFIG_DTC) += dtc
101179
101180 # Let clean descend into subdirs
101181 subdir- += basic kconfig package selinux
101182 +
101183 +clean-files := randstruct.seed
101184 diff --git a/scripts/Makefile.build b/scripts/Makefile.build
101185 index d5d859c..781cbcb 100644
101186 --- a/scripts/Makefile.build
101187 +++ b/scripts/Makefile.build
101188 @@ -111,7 +111,7 @@ endif
101189 endif
101190
101191 # Do not include host rules unless needed
101192 -ifneq ($(hostprogs-y)$(hostprogs-m),)
101193 +ifneq ($(hostprogs-y)$(hostprogs-m)$(hostlibs-y)$(hostlibs-m)$(hostcxxlibs-y)$(hostcxxlibs-m),)
101194 include scripts/Makefile.host
101195 endif
101196
101197 diff --git a/scripts/Makefile.clean b/scripts/Makefile.clean
101198 index 686cb0d..9d653bf 100644
101199 --- a/scripts/Makefile.clean
101200 +++ b/scripts/Makefile.clean
101201 @@ -43,7 +43,8 @@ subdir-ymn := $(addprefix $(obj)/,$(subdir-ymn))
101202 __clean-files := $(extra-y) $(always) \
101203 $(targets) $(clean-files) \
101204 $(host-progs) \
101205 - $(hostprogs-y) $(hostprogs-m) $(hostprogs-)
101206 + $(hostprogs-y) $(hostprogs-m) $(hostprogs-) \
101207 + $(hostlibs-y) $(hostlibs-m) $(hostlibs-)
101208
101209 __clean-files := $(filter-out $(no-clean-files), $(__clean-files))
101210
101211 diff --git a/scripts/Makefile.host b/scripts/Makefile.host
101212 index 1ac414f..38575f7 100644
101213 --- a/scripts/Makefile.host
101214 +++ b/scripts/Makefile.host
101215 @@ -31,6 +31,8 @@
101216 # Note: Shared libraries consisting of C++ files are not supported
101217
101218 __hostprogs := $(sort $(hostprogs-y) $(hostprogs-m))
101219 +__hostlibs := $(sort $(hostlibs-y) $(hostlibs-m))
101220 +__hostcxxlibs := $(sort $(hostcxxlibs-y) $(hostcxxlibs-m))
101221
101222 # C code
101223 # Executables compiled from a single .c file
101224 @@ -54,11 +56,15 @@ host-cxxobjs := $(sort $(foreach m,$(host-cxxmulti),$($(m)-cxxobjs)))
101225 # Shared libaries (only .c supported)
101226 # Shared libraries (.so) - all .so files referenced in "xxx-objs"
101227 host-cshlib := $(sort $(filter %.so, $(host-cobjs)))
101228 +host-cshlib += $(sort $(filter %.so, $(__hostlibs)))
101229 +host-cxxshlib := $(sort $(filter %.so, $(__hostcxxlibs)))
101230 # Remove .so files from "xxx-objs"
101231 host-cobjs := $(filter-out %.so,$(host-cobjs))
101232 +host-cxxobjs := $(filter-out %.so,$(host-cxxobjs))
101233
101234 -#Object (.o) files used by the shared libaries
101235 +# Object (.o) files used by the shared libaries
101236 host-cshobjs := $(sort $(foreach m,$(host-cshlib),$($(m:.so=-objs))))
101237 +host-cxxshobjs := $(sort $(foreach m,$(host-cxxshlib),$($(m:.so=-objs))))
101238
101239 # output directory for programs/.o files
101240 # hostprogs-y := tools/build may have been specified. Retrieve directory
101241 @@ -82,7 +88,9 @@ host-cobjs := $(addprefix $(obj)/,$(host-cobjs))
101242 host-cxxmulti := $(addprefix $(obj)/,$(host-cxxmulti))
101243 host-cxxobjs := $(addprefix $(obj)/,$(host-cxxobjs))
101244 host-cshlib := $(addprefix $(obj)/,$(host-cshlib))
101245 +host-cxxshlib := $(addprefix $(obj)/,$(host-cxxshlib))
101246 host-cshobjs := $(addprefix $(obj)/,$(host-cshobjs))
101247 +host-cxxshobjs := $(addprefix $(obj)/,$(host-cxxshobjs))
101248 host-objdirs := $(addprefix $(obj)/,$(host-objdirs))
101249
101250 obj-dirs += $(host-objdirs)
101251 @@ -156,6 +164,13 @@ quiet_cmd_host-cshobjs = HOSTCC -fPIC $@
101252 $(host-cshobjs): $(obj)/%.o: $(src)/%.c FORCE
101253 $(call if_changed_dep,host-cshobjs)
101254
101255 +# Compile .c file, create position independent .o file
101256 +# host-cxxshobjs -> .o
101257 +quiet_cmd_host-cxxshobjs = HOSTCXX -fPIC $@
101258 + cmd_host-cxxshobjs = $(HOSTCXX) $(hostcxx_flags) -fPIC -c -o $@ $<
101259 +$(host-cxxshobjs): $(obj)/%.o: $(src)/%.c FORCE
101260 + $(call if_changed_dep,host-cxxshobjs)
101261 +
101262 # Link a shared library, based on position independent .o files
101263 # *.o -> .so shared library (host-cshlib)
101264 quiet_cmd_host-cshlib = HOSTLLD -shared $@
101265 @@ -165,6 +180,15 @@ quiet_cmd_host-cshlib = HOSTLLD -shared $@
101266 $(host-cshlib): $(obj)/%: $(host-cshobjs) FORCE
101267 $(call if_changed,host-cshlib)
101268
101269 +# Link a shared library, based on position independent .o files
101270 +# *.o -> .so shared library (host-cxxshlib)
101271 +quiet_cmd_host-cxxshlib = HOSTLLD -shared $@
101272 + cmd_host-cxxshlib = $(HOSTCXX) $(HOSTLDFLAGS) -shared -o $@ \
101273 + $(addprefix $(obj)/,$($(@F:.so=-objs))) \
101274 + $(HOST_LOADLIBES) $(HOSTLOADLIBES_$(@F))
101275 +$(host-cxxshlib): $(obj)/%: $(host-cxxshobjs) FORCE
101276 + $(call if_changed,host-cxxshlib)
101277 +
101278 targets += $(host-csingle) $(host-cmulti) $(host-cobjs)\
101279 - $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs)
101280 + $(host-cxxmulti) $(host-cxxobjs) $(host-cshlib) $(host-cshobjs) $(host-cxxshlib) $(host-cxxshobjs)
101281
101282 diff --git a/scripts/basic/fixdep.c b/scripts/basic/fixdep.c
101283 index 078fe1d..fbdb363 100644
101284 --- a/scripts/basic/fixdep.c
101285 +++ b/scripts/basic/fixdep.c
101286 @@ -161,7 +161,7 @@ static unsigned int strhash(const char *str, unsigned int sz)
101287 /*
101288 * Lookup a value in the configuration string.
101289 */
101290 -static int is_defined_config(const char *name, int len, unsigned int hash)
101291 +static int is_defined_config(const char *name, unsigned int len, unsigned int hash)
101292 {
101293 struct item *aux;
101294
101295 @@ -211,10 +211,10 @@ static void clear_config(void)
101296 /*
101297 * Record the use of a CONFIG_* word.
101298 */
101299 -static void use_config(const char *m, int slen)
101300 +static void use_config(const char *m, unsigned int slen)
101301 {
101302 unsigned int hash = strhash(m, slen);
101303 - int c, i;
101304 + unsigned int c, i;
101305
101306 if (is_defined_config(m, slen, hash))
101307 return;
101308 @@ -235,9 +235,9 @@ static void use_config(const char *m, int slen)
101309
101310 static void parse_config_file(const char *map, size_t len)
101311 {
101312 - const int *end = (const int *) (map + len);
101313 + const unsigned int *end = (const unsigned int *) (map + len);
101314 /* start at +1, so that p can never be < map */
101315 - const int *m = (const int *) map + 1;
101316 + const unsigned int *m = (const unsigned int *) map + 1;
101317 const char *p, *q;
101318
101319 for (; m < end; m++) {
101320 @@ -435,7 +435,7 @@ static void print_deps(void)
101321 static void traps(void)
101322 {
101323 static char test[] __attribute__((aligned(sizeof(int)))) = "CONF";
101324 - int *p = (int *)test;
101325 + unsigned int *p = (unsigned int *)test;
101326
101327 if (*p != INT_CONF) {
101328 fprintf(stderr, "fixdep: sizeof(int) != 4 or wrong endianness? %#x\n",
101329 diff --git a/scripts/gcc-plugin.sh b/scripts/gcc-plugin.sh
101330 new file mode 100644
101331 index 0000000..5e0222d
101332 --- /dev/null
101333 +++ b/scripts/gcc-plugin.sh
101334 @@ -0,0 +1,17 @@
101335 +#!/bin/bash
101336 +plugincc=`$1 -E -shared - -o /dev/null -I\`$3 -print-file-name=plugin\`/include 2>&1 <<EOF
101337 +#include "gcc-plugin.h"
101338 +#include "tree.h"
101339 +#include "tm.h"
101340 +#include "rtl.h"
101341 +#ifdef ENABLE_BUILD_WITH_CXX
101342 +#warning $2
101343 +#else
101344 +#warning $1
101345 +#endif
101346 +EOF`
101347 +if [ $? -eq 0 ]
101348 +then
101349 + [[ "$plugincc" =~ "$1" ]] && echo "$1"
101350 + [[ "$plugincc" =~ "$2" ]] && echo "$2"
101351 +fi
101352 diff --git a/scripts/headers_install.sh b/scripts/headers_install.sh
101353 index 5de5660..d3deb89 100644
101354 --- a/scripts/headers_install.sh
101355 +++ b/scripts/headers_install.sh
101356 @@ -32,6 +32,7 @@ do
101357 FILE="$(basename "$i")"
101358 sed -r \
101359 -e 's/([ \t(])(__user|__force|__iomem)[ \t]/\1/g' \
101360 + -e 's/__intentional_overflow\([- \t,0-9]*\)//g' \
101361 -e 's/__attribute_const__([ \t]|$)/\1/g' \
101362 -e 's@^#include <linux/compiler.h>@@' \
101363 -e 's/(^|[^a-zA-Z0-9])__packed([^a-zA-Z0-9_]|$)/\1__attribute__((packed))\2/g' \
101364 diff --git a/scripts/link-vmlinux.sh b/scripts/link-vmlinux.sh
101365 index 2dcb377..a82c500 100644
101366 --- a/scripts/link-vmlinux.sh
101367 +++ b/scripts/link-vmlinux.sh
101368 @@ -162,7 +162,7 @@ else
101369 fi;
101370
101371 # final build of init/
101372 -${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init
101373 +${MAKE} -f "${srctree}/scripts/Makefile.build" obj=init GCC_PLUGINS_CFLAGS="${GCC_PLUGINS_CFLAGS}" GCC_PLUGINS_AFLAGS="${GCC_PLUGINS_AFLAGS}"
101374
101375 kallsymso=""
101376 kallsyms_vmlinux=""
101377 diff --git a/scripts/mod/file2alias.c b/scripts/mod/file2alias.c
101378 index 2370863..212fbca 100644
101379 --- a/scripts/mod/file2alias.c
101380 +++ b/scripts/mod/file2alias.c
101381 @@ -142,7 +142,7 @@ static void device_id_check(const char *modname, const char *device_id,
101382 unsigned long size, unsigned long id_size,
101383 void *symval)
101384 {
101385 - int i;
101386 + unsigned int i;
101387
101388 if (size % id_size || size < id_size) {
101389 fatal("%s: sizeof(struct %s_device_id)=%lu is not a modulo "
101390 @@ -170,7 +170,7 @@ static void device_id_check(const char *modname, const char *device_id,
101391 /* USB is special because the bcdDevice can be matched against a numeric range */
101392 /* Looks like "usb:vNpNdNdcNdscNdpNicNiscNipNinN" */
101393 static void do_usb_entry(void *symval,
101394 - unsigned int bcdDevice_initial, int bcdDevice_initial_digits,
101395 + unsigned int bcdDevice_initial, unsigned int bcdDevice_initial_digits,
101396 unsigned char range_lo, unsigned char range_hi,
101397 unsigned char max, struct module *mod)
101398 {
101399 @@ -280,7 +280,7 @@ static void do_usb_entry_multi(void *symval, struct module *mod)
101400 {
101401 unsigned int devlo, devhi;
101402 unsigned char chi, clo, max;
101403 - int ndigits;
101404 + unsigned int ndigits;
101405
101406 DEF_FIELD(symval, usb_device_id, match_flags);
101407 DEF_FIELD(symval, usb_device_id, idVendor);
101408 @@ -533,7 +533,7 @@ static void do_pnp_device_entry(void *symval, unsigned long size,
101409 for (i = 0; i < count; i++) {
101410 DEF_FIELD_ADDR(symval + i*id_size, pnp_device_id, id);
101411 char acpi_id[sizeof(*id)];
101412 - int j;
101413 + unsigned int j;
101414
101415 buf_printf(&mod->dev_table_buf,
101416 "MODULE_ALIAS(\"pnp:d%s*\");\n", *id);
101417 @@ -562,7 +562,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
101418
101419 for (j = 0; j < PNP_MAX_DEVICES; j++) {
101420 const char *id = (char *)(*devs)[j].id;
101421 - int i2, j2;
101422 + unsigned int i2, j2;
101423 int dup = 0;
101424
101425 if (!id[0])
101426 @@ -588,7 +588,7 @@ static void do_pnp_card_entries(void *symval, unsigned long size,
101427 /* add an individual alias for every device entry */
101428 if (!dup) {
101429 char acpi_id[PNP_ID_LEN];
101430 - int k;
101431 + unsigned int k;
101432
101433 buf_printf(&mod->dev_table_buf,
101434 "MODULE_ALIAS(\"pnp:d%s*\");\n", id);
101435 @@ -940,7 +940,7 @@ static void dmi_ascii_filter(char *d, const char *s)
101436 static int do_dmi_entry(const char *filename, void *symval,
101437 char *alias)
101438 {
101439 - int i, j;
101440 + unsigned int i, j;
101441 DEF_FIELD_ADDR(symval, dmi_system_id, matches);
101442 sprintf(alias, "dmi*");
101443
101444 diff --git a/scripts/mod/modpost.c b/scripts/mod/modpost.c
101445 index 1785576..5e8e06a 100644
101446 --- a/scripts/mod/modpost.c
101447 +++ b/scripts/mod/modpost.c
101448 @@ -941,6 +941,7 @@ enum mismatch {
101449 ANY_INIT_TO_ANY_EXIT,
101450 ANY_EXIT_TO_ANY_INIT,
101451 EXPORT_TO_INIT_EXIT,
101452 + DATA_TO_TEXT
101453 };
101454
101455 struct sectioncheck {
101456 @@ -1027,6 +1028,12 @@ const struct sectioncheck sectioncheck[] = {
101457 .tosec = { INIT_SECTIONS, EXIT_SECTIONS, NULL },
101458 .mismatch = EXPORT_TO_INIT_EXIT,
101459 .symbol_white_list = { DEFAULT_SYMBOL_WHITE_LIST, NULL },
101460 +},
101461 +/* Do not reference code from writable data */
101462 +{
101463 + .fromsec = { DATA_SECTIONS, NULL },
101464 + .tosec = { TEXT_SECTIONS, NULL },
101465 + .mismatch = DATA_TO_TEXT
101466 }
101467 };
101468
101469 @@ -1147,10 +1154,10 @@ static Elf_Sym *find_elf_symbol(struct elf_info *elf, Elf64_Sword addr,
101470 continue;
101471 if (ELF_ST_TYPE(sym->st_info) == STT_SECTION)
101472 continue;
101473 - if (sym->st_value == addr)
101474 - return sym;
101475 /* Find a symbol nearby - addr are maybe negative */
101476 d = sym->st_value - addr;
101477 + if (d == 0)
101478 + return sym;
101479 if (d < 0)
101480 d = addr - sym->st_value;
101481 if (d < distance) {
101482 @@ -1428,6 +1435,14 @@ static void report_sec_mismatch(const char *modname,
101483 tosym, prl_to, prl_to, tosym);
101484 free(prl_to);
101485 break;
101486 + case DATA_TO_TEXT:
101487 +#if 0
101488 + fprintf(stderr,
101489 + "The %s %s:%s references\n"
101490 + "the %s %s:%s%s\n",
101491 + from, fromsec, fromsym, to, tosec, tosym, to_p);
101492 +#endif
101493 + break;
101494 }
101495 fprintf(stderr, "\n");
101496 }
101497 @@ -1662,7 +1677,7 @@ static void section_rel(const char *modname, struct elf_info *elf,
101498 static void check_sec_ref(struct module *mod, const char *modname,
101499 struct elf_info *elf)
101500 {
101501 - int i;
101502 + unsigned int i;
101503 Elf_Shdr *sechdrs = elf->sechdrs;
101504
101505 /* Walk through all sections */
101506 @@ -1781,7 +1796,7 @@ void __attribute__((format(printf, 2, 3))) buf_printf(struct buffer *buf,
101507 va_end(ap);
101508 }
101509
101510 -void buf_write(struct buffer *buf, const char *s, int len)
101511 +void buf_write(struct buffer *buf, const char *s, unsigned int len)
101512 {
101513 if (buf->size - buf->pos < len) {
101514 buf->size += len + SZ;
101515 @@ -2000,7 +2015,7 @@ static void write_if_changed(struct buffer *b, const char *fname)
101516 if (fstat(fileno(file), &st) < 0)
101517 goto close_write;
101518
101519 - if (st.st_size != b->pos)
101520 + if (st.st_size != (off_t)b->pos)
101521 goto close_write;
101522
101523 tmp = NOFAIL(malloc(b->pos));
101524 diff --git a/scripts/mod/modpost.h b/scripts/mod/modpost.h
101525 index 51207e4..f7d603d 100644
101526 --- a/scripts/mod/modpost.h
101527 +++ b/scripts/mod/modpost.h
101528 @@ -92,15 +92,15 @@ void *do_nofail(void *ptr, const char *expr);
101529
101530 struct buffer {
101531 char *p;
101532 - int pos;
101533 - int size;
101534 + unsigned int pos;
101535 + unsigned int size;
101536 };
101537
101538 void __attribute__((format(printf, 2, 3)))
101539 buf_printf(struct buffer *buf, const char *fmt, ...);
101540
101541 void
101542 -buf_write(struct buffer *buf, const char *s, int len);
101543 +buf_write(struct buffer *buf, const char *s, unsigned int len);
101544
101545 struct module {
101546 struct module *next;
101547 diff --git a/scripts/mod/sumversion.c b/scripts/mod/sumversion.c
101548 index deb2994..af4f63e 100644
101549 --- a/scripts/mod/sumversion.c
101550 +++ b/scripts/mod/sumversion.c
101551 @@ -470,7 +470,7 @@ static void write_version(const char *filename, const char *sum,
101552 goto out;
101553 }
101554
101555 - if (write(fd, sum, strlen(sum)+1) != strlen(sum)+1) {
101556 + if (write(fd, sum, strlen(sum)+1) != (ssize_t)strlen(sum)+1) {
101557 warn("writing sum in %s failed: %s\n",
101558 filename, strerror(errno));
101559 goto out;
101560 diff --git a/scripts/module-common.lds b/scripts/module-common.lds
101561 index 0865b3e..7235dd4 100644
101562 --- a/scripts/module-common.lds
101563 +++ b/scripts/module-common.lds
101564 @@ -6,6 +6,10 @@
101565 SECTIONS {
101566 /DISCARD/ : { *(.discard) }
101567
101568 + .rodata : {
101569 + *(.rodata) *(.rodata.*)
101570 + *(.data..read_only)
101571 + }
101572 __ksymtab : { *(SORT(___ksymtab+*)) }
101573 __ksymtab_gpl : { *(SORT(___ksymtab_gpl+*)) }
101574 __ksymtab_unused : { *(SORT(___ksymtab_unused+*)) }
101575 diff --git a/scripts/package/builddeb b/scripts/package/builddeb
101576 index 90e521f..e9eaf8f 100644
101577 --- a/scripts/package/builddeb
101578 +++ b/scripts/package/builddeb
101579 @@ -281,6 +281,7 @@ fi
101580 (cd $srctree; find . -name Makefile\* -o -name Kconfig\* -o -name \*.pl > "$objtree/debian/hdrsrcfiles")
101581 (cd $srctree; find arch/$SRCARCH/include include scripts -type f >> "$objtree/debian/hdrsrcfiles")
101582 (cd $objtree; find arch/$SRCARCH/include Module.symvers include scripts -type f >> "$objtree/debian/hdrobjfiles")
101583 +(cd $objtree; find tools/gcc -name \*.so >> "$objtree/debian/hdrobjfiles")
101584 destdir=$kernel_headers_dir/usr/src/linux-headers-$version
101585 mkdir -p "$destdir"
101586 (cd $srctree; tar -c -f - -T "$objtree/debian/hdrsrcfiles") | (cd $destdir; tar -xf -)
101587 diff --git a/scripts/pnmtologo.c b/scripts/pnmtologo.c
101588 index 68bb4ef..2f419e1 100644
101589 --- a/scripts/pnmtologo.c
101590 +++ b/scripts/pnmtologo.c
101591 @@ -244,14 +244,14 @@ static void write_header(void)
101592 fprintf(out, " * Linux logo %s\n", logoname);
101593 fputs(" */\n\n", out);
101594 fputs("#include <linux/linux_logo.h>\n\n", out);
101595 - fprintf(out, "static unsigned char %s_data[] __initdata = {\n",
101596 + fprintf(out, "static unsigned char %s_data[] = {\n",
101597 logoname);
101598 }
101599
101600 static void write_footer(void)
101601 {
101602 fputs("\n};\n\n", out);
101603 - fprintf(out, "const struct linux_logo %s __initconst = {\n", logoname);
101604 + fprintf(out, "const struct linux_logo %s = {\n", logoname);
101605 fprintf(out, "\t.type\t\t= %s,\n", logo_types[logo_type]);
101606 fprintf(out, "\t.width\t\t= %d,\n", logo_width);
101607 fprintf(out, "\t.height\t\t= %d,\n", logo_height);
101608 @@ -381,7 +381,7 @@ static void write_logo_clut224(void)
101609 fputs("\n};\n\n", out);
101610
101611 /* write logo clut */
101612 - fprintf(out, "static unsigned char %s_clut[] __initdata = {\n",
101613 + fprintf(out, "static unsigned char %s_clut[] = {\n",
101614 logoname);
101615 write_hex_cnt = 0;
101616 for (i = 0; i < logo_clutsize; i++) {
101617 diff --git a/scripts/sortextable.h b/scripts/sortextable.h
101618 index 8fac3fd..32ff38d 100644
101619 --- a/scripts/sortextable.h
101620 +++ b/scripts/sortextable.h
101621 @@ -108,9 +108,9 @@ do_func(Elf_Ehdr *ehdr, char const *const fname, table_sort_t custom_sort)
101622 const char *secstrtab;
101623 const char *strtab;
101624 char *extab_image;
101625 - int extab_index = 0;
101626 - int i;
101627 - int idx;
101628 + unsigned int extab_index = 0;
101629 + unsigned int i;
101630 + unsigned int idx;
101631 unsigned int num_sections;
101632 unsigned int secindex_strings;
101633
101634 diff --git a/security/Kconfig b/security/Kconfig
101635 index e9c6ac7..0ebde711 100644
101636 --- a/security/Kconfig
101637 +++ b/security/Kconfig
101638 @@ -4,6 +4,959 @@
101639
101640 menu "Security options"
101641
101642 +menu "Grsecurity"
101643 +
101644 + config ARCH_TRACK_EXEC_LIMIT
101645 + bool
101646 +
101647 + config PAX_KERNEXEC_PLUGIN
101648 + bool
101649 +
101650 + config PAX_PER_CPU_PGD
101651 + bool
101652 +
101653 + config TASK_SIZE_MAX_SHIFT
101654 + int
101655 + depends on X86_64
101656 + default 47 if !PAX_PER_CPU_PGD
101657 + default 42 if PAX_PER_CPU_PGD
101658 +
101659 + config PAX_ENABLE_PAE
101660 + bool
101661 + default y if (X86_32 && (MPENTIUM4 || MK8 || MPSC || MCORE2 || MATOM))
101662 +
101663 + config PAX_USERCOPY_SLABS
101664 + bool
101665 +
101666 +config GRKERNSEC
101667 + bool "Grsecurity"
101668 + select CRYPTO
101669 + select CRYPTO_SHA256
101670 + select PROC_FS
101671 + select STOP_MACHINE
101672 + select TTY
101673 + select DEBUG_KERNEL
101674 + select DEBUG_LIST
101675 + help
101676 + If you say Y here, you will be able to configure many features
101677 + that will enhance the security of your system. It is highly
101678 + recommended that you say Y here and read through the help
101679 + for each option so that you fully understand the features and
101680 + can evaluate their usefulness for your machine.
101681 +
101682 +choice
101683 + prompt "Configuration Method"
101684 + depends on GRKERNSEC
101685 + default GRKERNSEC_CONFIG_CUSTOM
101686 + help
101687 +
101688 +config GRKERNSEC_CONFIG_AUTO
101689 + bool "Automatic"
101690 + help
101691 + If you choose this configuration method, you'll be able to answer a small
101692 + number of simple questions about how you plan to use this kernel.
101693 + The settings of grsecurity and PaX will be automatically configured for
101694 + the highest commonly-used settings within the provided constraints.
101695 +
101696 + If you require additional configuration, custom changes can still be made
101697 + from the "custom configuration" menu.
101698 +
101699 +config GRKERNSEC_CONFIG_CUSTOM
101700 + bool "Custom"
101701 + help
101702 + If you choose this configuration method, you'll be able to configure all
101703 + grsecurity and PaX settings manually. Via this method, no options are
101704 + automatically enabled.
101705 +
101706 +endchoice
101707 +
101708 +choice
101709 + prompt "Usage Type"
101710 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
101711 + default GRKERNSEC_CONFIG_SERVER
101712 + help
101713 +
101714 +config GRKERNSEC_CONFIG_SERVER
101715 + bool "Server"
101716 + help
101717 + Choose this option if you plan to use this kernel on a server.
101718 +
101719 +config GRKERNSEC_CONFIG_DESKTOP
101720 + bool "Desktop"
101721 + help
101722 + Choose this option if you plan to use this kernel on a desktop.
101723 +
101724 +endchoice
101725 +
101726 +choice
101727 + prompt "Virtualization Type"
101728 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO)
101729 + default GRKERNSEC_CONFIG_VIRT_NONE
101730 + help
101731 +
101732 +config GRKERNSEC_CONFIG_VIRT_NONE
101733 + bool "None"
101734 + help
101735 + Choose this option if this kernel will be run on bare metal.
101736 +
101737 +config GRKERNSEC_CONFIG_VIRT_GUEST
101738 + bool "Guest"
101739 + help
101740 + Choose this option if this kernel will be run as a VM guest.
101741 +
101742 +config GRKERNSEC_CONFIG_VIRT_HOST
101743 + bool "Host"
101744 + help
101745 + Choose this option if this kernel will be run as a VM host.
101746 +
101747 +endchoice
101748 +
101749 +choice
101750 + prompt "Virtualization Hardware"
101751 + depends on (GRKERNSEC && X86 && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
101752 + help
101753 +
101754 +config GRKERNSEC_CONFIG_VIRT_EPT
101755 + bool "EPT/RVI Processor Support"
101756 + depends on X86
101757 + help
101758 + Choose this option if your CPU supports the EPT or RVI features of 2nd-gen
101759 + hardware virtualization. This allows for additional kernel hardening protections
101760 + to operate without additional performance impact.
101761 +
101762 + To see if your Intel processor supports EPT, see:
101763 + http://ark.intel.com/Products/VirtualizationTechnology
101764 + (Most Core i3/5/7 support EPT)
101765 +
101766 + To see if your AMD processor supports RVI, see:
101767 + http://support.amd.com/us/kbarticles/Pages/GPU120AMDRVICPUsHyperVWin8.aspx
101768 +
101769 +config GRKERNSEC_CONFIG_VIRT_SOFT
101770 + bool "First-gen/No Hardware Virtualization"
101771 + help
101772 + Choose this option if you use an Atom/Pentium/Core 2 processor that either doesn't
101773 + support hardware virtualization or doesn't support the EPT/RVI extensions.
101774 +
101775 +endchoice
101776 +
101777 +choice
101778 + prompt "Virtualization Software"
101779 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_GUEST || GRKERNSEC_CONFIG_VIRT_HOST))
101780 + help
101781 +
101782 +config GRKERNSEC_CONFIG_VIRT_XEN
101783 + bool "Xen"
101784 + help
101785 + Choose this option if this kernel is running as a Xen guest or host.
101786 +
101787 +config GRKERNSEC_CONFIG_VIRT_VMWARE
101788 + bool "VMWare"
101789 + help
101790 + Choose this option if this kernel is running as a VMWare guest or host.
101791 +
101792 +config GRKERNSEC_CONFIG_VIRT_KVM
101793 + bool "KVM"
101794 + help
101795 + Choose this option if this kernel is running as a KVM guest or host.
101796 +
101797 +config GRKERNSEC_CONFIG_VIRT_VIRTUALBOX
101798 + bool "VirtualBox"
101799 + help
101800 + Choose this option if this kernel is running as a VirtualBox guest or host.
101801 +
101802 +endchoice
101803 +
101804 +choice
101805 + prompt "Required Priorities"
101806 + depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
101807 + default GRKERNSEC_CONFIG_PRIORITY_PERF
101808 + help
101809 +
101810 +config GRKERNSEC_CONFIG_PRIORITY_PERF
101811 + bool "Performance"
101812 + help
101813 + Choose this option if performance is of highest priority for this deployment
101814 + of grsecurity. Features like UDEREF on a 64bit kernel, kernel stack clearing,
101815 + clearing of structures intended for userland, and freed memory sanitizing will
101816 + be disabled.
101817 +
101818 +config GRKERNSEC_CONFIG_PRIORITY_SECURITY
101819 + bool "Security"
101820 + help
101821 + Choose this option if security is of highest priority for this deployment of
101822 + grsecurity. UDEREF, kernel stack clearing, clearing of structures intended
101823 + for userland, and freed memory sanitizing will be enabled for this kernel.
101824 + In a worst-case scenario, these features can introduce a 20% performance hit
101825 + (UDEREF on x64 contributing half of this hit).
101826 +
101827 +endchoice
101828 +
101829 +menu "Default Special Groups"
101830 +depends on (GRKERNSEC && GRKERNSEC_CONFIG_AUTO)
101831 +
101832 +config GRKERNSEC_PROC_GID
101833 + int "GID exempted from /proc restrictions"
101834 + default 1001
101835 + help
101836 + Setting this GID determines which group will be exempted from
101837 + grsecurity's /proc restrictions, allowing users of the specified
101838 + group to view network statistics and the existence of other users'
101839 + processes on the system. This GID may also be chosen at boot time
101840 + via "grsec_proc_gid=" on the kernel commandline.
101841 +
101842 +config GRKERNSEC_TPE_UNTRUSTED_GID
101843 + int "GID for TPE-untrusted users"
101844 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && !GRKERNSEC_TPE_INVERT
101845 + default 1005
101846 + help
101847 + Setting this GID determines which group untrusted users should
101848 + be added to. These users will be placed under grsecurity's Trusted Path
101849 + Execution mechanism, preventing them from executing their own binaries.
101850 + The users will only be able to execute binaries in directories owned and
101851 + writable only by the root user. If the sysctl option is enabled, a sysctl
101852 + option with name "tpe_gid" is created.
101853 +
101854 +config GRKERNSEC_TPE_TRUSTED_GID
101855 + int "GID for TPE-trusted users"
101856 + depends on GRKERNSEC_CONFIG_SERVER && GRKERNSEC_TPE && GRKERNSEC_TPE_INVERT
101857 + default 1005
101858 + help
101859 + Setting this GID determines what group TPE restrictions will be
101860 + *disabled* for. If the sysctl option is enabled, a sysctl option
101861 + with name "tpe_gid" is created.
101862 +
101863 +config GRKERNSEC_SYMLINKOWN_GID
101864 + int "GID for users with kernel-enforced SymlinksIfOwnerMatch"
101865 + depends on GRKERNSEC_CONFIG_SERVER
101866 + default 1006
101867 + help
101868 + Setting this GID determines what group kernel-enforced
101869 + SymlinksIfOwnerMatch will be enabled for. If the sysctl option
101870 + is enabled, a sysctl option with name "symlinkown_gid" is created.
101871 +
101872 +
101873 +endmenu
101874 +
101875 +menu "Customize Configuration"
101876 +depends on GRKERNSEC
101877 +
101878 +menu "PaX"
101879 +
101880 +config PAX
101881 + bool "Enable various PaX features"
101882 + default y if GRKERNSEC_CONFIG_AUTO
101883 + depends on GRKERNSEC && (ALPHA || ARM || AVR32 || IA64 || MIPS || PARISC || PPC || SPARC || X86)
101884 + help
101885 + This allows you to enable various PaX features. PaX adds
101886 + intrusion prevention mechanisms to the kernel that reduce
101887 + the risks posed by exploitable memory corruption bugs.
101888 +
101889 +menu "PaX Control"
101890 + depends on PAX
101891 +
101892 +config PAX_SOFTMODE
101893 + bool 'Support soft mode'
101894 + help
101895 + Enabling this option will allow you to run PaX in soft mode, that
101896 + is, PaX features will not be enforced by default, only on executables
101897 + marked explicitly. You must also enable PT_PAX_FLAGS or XATTR_PAX_FLAGS
101898 + support as they are the only way to mark executables for soft mode use.
101899 +
101900 + Soft mode can be activated by using the "pax_softmode=1" kernel command
101901 + line option on boot. Furthermore you can control various PaX features
101902 + at runtime via the entries in /proc/sys/kernel/pax.
101903 +
101904 +config PAX_EI_PAX
101905 + bool 'Use legacy ELF header marking'
101906 + default y if GRKERNSEC_CONFIG_AUTO
101907 + help
101908 + Enabling this option will allow you to control PaX features on
101909 + a per executable basis via the 'chpax' utility available at
101910 + http://pax.grsecurity.net/. The control flags will be read from
101911 + an otherwise reserved part of the ELF header. This marking has
101912 + numerous drawbacks (no support for soft-mode, toolchain does not
101913 + know about the non-standard use of the ELF header) therefore it
101914 + has been deprecated in favour of PT_PAX_FLAGS and XATTR_PAX_FLAGS
101915 + support.
101916 +
101917 + Note that if you enable PT_PAX_FLAGS or XATTR_PAX_FLAGS marking
101918 + support as well, they will override the legacy EI_PAX marks.
101919 +
101920 + If you enable none of the marking options then all applications
101921 + will run with PaX enabled on them by default.
101922 +
101923 +config PAX_PT_PAX_FLAGS
101924 + bool 'Use ELF program header marking'
101925 + default y if GRKERNSEC_CONFIG_AUTO
101926 + help
101927 + Enabling this option will allow you to control PaX features on
101928 + a per executable basis via the 'paxctl' utility available at
101929 + http://pax.grsecurity.net/. The control flags will be read from
101930 + a PaX specific ELF program header (PT_PAX_FLAGS). This marking
101931 + has the benefits of supporting both soft mode and being fully
101932 + integrated into the toolchain (the binutils patch is available
101933 + from http://pax.grsecurity.net).
101934 +
101935 + Note that if you enable the legacy EI_PAX marking support as well,
101936 + the EI_PAX marks will be overridden by the PT_PAX_FLAGS marks.
101937 +
101938 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
101939 + must make sure that the marks are the same if a binary has both marks.
101940 +
101941 + If you enable none of the marking options then all applications
101942 + will run with PaX enabled on them by default.
101943 +
101944 +config PAX_XATTR_PAX_FLAGS
101945 + bool 'Use filesystem extended attributes marking'
101946 + default y if GRKERNSEC_CONFIG_AUTO
101947 + select CIFS_XATTR if CIFS
101948 + select EXT2_FS_XATTR if EXT2_FS
101949 + select EXT3_FS_XATTR if EXT3_FS
101950 + select JFFS2_FS_XATTR if JFFS2_FS
101951 + select REISERFS_FS_XATTR if REISERFS_FS
101952 + select SQUASHFS_XATTR if SQUASHFS
101953 + select TMPFS_XATTR if TMPFS
101954 + select UBIFS_FS_XATTR if UBIFS_FS
101955 + help
101956 + Enabling this option will allow you to control PaX features on
101957 + a per executable basis via the 'setfattr' utility. The control
101958 + flags will be read from the user.pax.flags extended attribute of
101959 + the file. This marking has the benefit of supporting binary-only
101960 + applications that self-check themselves (e.g., skype) and would
101961 + not tolerate chpax/paxctl changes. The main drawback is that
101962 + extended attributes are not supported by some filesystems (e.g.,
101963 + isofs, udf, vfat) so copying files through such filesystems will
101964 + lose the extended attributes and these PaX markings.
101965 +
101966 + Note that if you enable the legacy EI_PAX marking support as well,
101967 + the EI_PAX marks will be overridden by the XATTR_PAX_FLAGS marks.
101968 +
101969 + If you enable both PT_PAX_FLAGS and XATTR_PAX_FLAGS support then you
101970 + must make sure that the marks are the same if a binary has both marks.
101971 +
101972 + If you enable none of the marking options then all applications
101973 + will run with PaX enabled on them by default.
101974 +
101975 +choice
101976 + prompt 'MAC system integration'
101977 + default PAX_HAVE_ACL_FLAGS
101978 + help
101979 + Mandatory Access Control systems have the option of controlling
101980 + PaX flags on a per executable basis, choose the method supported
101981 + by your particular system.
101982 +
101983 + - "none": if your MAC system does not interact with PaX,
101984 + - "direct": if your MAC system defines pax_set_initial_flags() itself,
101985 + - "hook": if your MAC system uses the pax_set_initial_flags_func callback.
101986 +
101987 + NOTE: this option is for developers/integrators only.
101988 +
101989 + config PAX_NO_ACL_FLAGS
101990 + bool 'none'
101991 +
101992 + config PAX_HAVE_ACL_FLAGS
101993 + bool 'direct'
101994 +
101995 + config PAX_HOOK_ACL_FLAGS
101996 + bool 'hook'
101997 +endchoice
101998 +
101999 +endmenu
102000 +
102001 +menu "Non-executable pages"
102002 + depends on PAX
102003 +
102004 +config PAX_NOEXEC
102005 + bool "Enforce non-executable pages"
102006 + default y if GRKERNSEC_CONFIG_AUTO
102007 + depends on ALPHA || (ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || IA64 || MIPS || PARISC || PPC || S390 || SPARC || X86
102008 + help
102009 + By design some architectures do not allow for protecting memory
102010 + pages against execution or even if they do, Linux does not make
102011 + use of this feature. In practice this means that if a page is
102012 + readable (such as the stack or heap) it is also executable.
102013 +
102014 + There is a well known exploit technique that makes use of this
102015 + fact and a common programming mistake where an attacker can
102016 + introduce code of his choice somewhere in the attacked program's
102017 + memory (typically the stack or the heap) and then execute it.
102018 +
102019 + If the attacked program was running with different (typically
102020 + higher) privileges than that of the attacker, then he can elevate
102021 + his own privilege level (e.g. get a root shell, write to files for
102022 + which he does not have write access to, etc).
102023 +
102024 + Enabling this option will let you choose from various features
102025 + that prevent the injection and execution of 'foreign' code in
102026 + a program.
102027 +
102028 + This will also break programs that rely on the old behaviour and
102029 + expect that dynamically allocated memory via the malloc() family
102030 + of functions is executable (which it is not). Notable examples
102031 + are the XFree86 4.x server, the java runtime and wine.
102032 +
102033 +config PAX_PAGEEXEC
102034 + bool "Paging based non-executable pages"
102035 + default y if GRKERNSEC_CONFIG_AUTO
102036 + 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)
102037 + select ARCH_TRACK_EXEC_LIMIT if X86_32
102038 + help
102039 + This implementation is based on the paging feature of the CPU.
102040 + On i386 without hardware non-executable bit support there is a
102041 + variable but usually low performance impact, however on Intel's
102042 + P4 core based CPUs it is very high so you should not enable this
102043 + for kernels meant to be used on such CPUs.
102044 +
102045 + On alpha, avr32, ia64, parisc, sparc, sparc64, x86_64 and i386
102046 + with hardware non-executable bit support there is no performance
102047 + impact, on ppc the impact is negligible.
102048 +
102049 + Note that several architectures require various emulations due to
102050 + badly designed userland ABIs, this will cause a performance impact
102051 + but will disappear as soon as userland is fixed. For example, ppc
102052 + userland MUST have been built with secure-plt by a recent toolchain.
102053 +
102054 +config PAX_SEGMEXEC
102055 + bool "Segmentation based non-executable pages"
102056 + default y if GRKERNSEC_CONFIG_AUTO
102057 + depends on PAX_NOEXEC && X86_32
102058 + help
102059 + This implementation is based on the segmentation feature of the
102060 + CPU and has a very small performance impact, however applications
102061 + will be limited to a 1.5 GB address space instead of the normal
102062 + 3 GB.
102063 +
102064 +config PAX_EMUTRAMP
102065 + bool "Emulate trampolines" if (PAX_PAGEEXEC || PAX_SEGMEXEC) && (PARISC || X86)
102066 + default y if PARISC
102067 + help
102068 + There are some programs and libraries that for one reason or
102069 + another attempt to execute special small code snippets from
102070 + non-executable memory pages. Most notable examples are the
102071 + signal handler return code generated by the kernel itself and
102072 + the GCC trampolines.
102073 +
102074 + If you enabled CONFIG_PAX_PAGEEXEC or CONFIG_PAX_SEGMEXEC then
102075 + such programs will no longer work under your kernel.
102076 +
102077 + As a remedy you can say Y here and use the 'chpax' or 'paxctl'
102078 + utilities to enable trampoline emulation for the affected programs
102079 + yet still have the protection provided by the non-executable pages.
102080 +
102081 + On parisc you MUST enable this option and EMUSIGRT as well, otherwise
102082 + your system will not even boot.
102083 +
102084 + Alternatively you can say N here and use the 'chpax' or 'paxctl'
102085 + utilities to disable CONFIG_PAX_PAGEEXEC and CONFIG_PAX_SEGMEXEC
102086 + for the affected files.
102087 +
102088 + NOTE: enabling this feature *may* open up a loophole in the
102089 + protection provided by non-executable pages that an attacker
102090 + could abuse. Therefore the best solution is to not have any
102091 + files on your system that would require this option. This can
102092 + be achieved by not using libc5 (which relies on the kernel
102093 + signal handler return code) and not using or rewriting programs
102094 + that make use of the nested function implementation of GCC.
102095 + Skilled users can just fix GCC itself so that it implements
102096 + nested function calls in a way that does not interfere with PaX.
102097 +
102098 +config PAX_EMUSIGRT
102099 + bool "Automatically emulate sigreturn trampolines"
102100 + depends on PAX_EMUTRAMP && PARISC
102101 + default y
102102 + help
102103 + Enabling this option will have the kernel automatically detect
102104 + and emulate signal return trampolines executing on the stack
102105 + that would otherwise lead to task termination.
102106 +
102107 + This solution is intended as a temporary one for users with
102108 + legacy versions of libc (libc5, glibc 2.0, uClibc before 0.9.17,
102109 + Modula-3 runtime, etc) or executables linked to such, basically
102110 + everything that does not specify its own SA_RESTORER function in
102111 + normal executable memory like glibc 2.1+ does.
102112 +
102113 + On parisc you MUST enable this option, otherwise your system will
102114 + not even boot.
102115 +
102116 + NOTE: this feature cannot be disabled on a per executable basis
102117 + and since it *does* open up a loophole in the protection provided
102118 + by non-executable pages, the best solution is to not have any
102119 + files on your system that would require this option.
102120 +
102121 +config PAX_MPROTECT
102122 + bool "Restrict mprotect()"
102123 + default y if GRKERNSEC_CONFIG_AUTO
102124 + depends on (PAX_PAGEEXEC || PAX_SEGMEXEC)
102125 + help
102126 + Enabling this option will prevent programs from
102127 + - changing the executable status of memory pages that were
102128 + not originally created as executable,
102129 + - making read-only executable pages writable again,
102130 + - creating executable pages from anonymous memory,
102131 + - making read-only-after-relocations (RELRO) data pages writable again.
102132 +
102133 + You should say Y here to complete the protection provided by
102134 + the enforcement of non-executable pages.
102135 +
102136 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
102137 + this feature on a per file basis.
102138 +
102139 +config PAX_MPROTECT_COMPAT
102140 + bool "Use legacy/compat protection demoting (read help)"
102141 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
102142 + depends on PAX_MPROTECT
102143 + help
102144 + The current implementation of PAX_MPROTECT denies RWX allocations/mprotects
102145 + by sending the proper error code to the application. For some broken
102146 + userland, this can cause problems with Python or other applications. The
102147 + current implementation however allows for applications like clamav to
102148 + detect if JIT compilation/execution is allowed and to fall back gracefully
102149 + to an interpreter-based mode if it does not. While we encourage everyone
102150 + to use the current implementation as-is and push upstream to fix broken
102151 + userland (note that the RWX logging option can assist with this), in some
102152 + environments this may not be possible. Having to disable MPROTECT
102153 + completely on certain binaries reduces the security benefit of PaX,
102154 + so this option is provided for those environments to revert to the old
102155 + behavior.
102156 +
102157 +config PAX_ELFRELOCS
102158 + bool "Allow ELF text relocations (read help)"
102159 + depends on PAX_MPROTECT
102160 + default n
102161 + help
102162 + Non-executable pages and mprotect() restrictions are effective
102163 + in preventing the introduction of new executable code into an
102164 + attacked task's address space. There remain only two venues
102165 + for this kind of attack: if the attacker can execute already
102166 + existing code in the attacked task then he can either have it
102167 + create and mmap() a file containing his code or have it mmap()
102168 + an already existing ELF library that does not have position
102169 + independent code in it and use mprotect() on it to make it
102170 + writable and copy his code there. While protecting against
102171 + the former approach is beyond PaX, the latter can be prevented
102172 + by having only PIC ELF libraries on one's system (which do not
102173 + need to relocate their code). If you are sure this is your case,
102174 + as is the case with all modern Linux distributions, then leave
102175 + this option disabled. You should say 'n' here.
102176 +
102177 +config PAX_ETEXECRELOCS
102178 + bool "Allow ELF ET_EXEC text relocations"
102179 + depends on PAX_MPROTECT && (ALPHA || IA64 || PARISC)
102180 + select PAX_ELFRELOCS
102181 + default y
102182 + help
102183 + On some architectures there are incorrectly created applications
102184 + that require text relocations and would not work without enabling
102185 + this option. If you are an alpha, ia64 or parisc user, you should
102186 + enable this option and disable it once you have made sure that
102187 + none of your applications need it.
102188 +
102189 +config PAX_EMUPLT
102190 + bool "Automatically emulate ELF PLT"
102191 + depends on PAX_MPROTECT && (ALPHA || PARISC || SPARC)
102192 + default y
102193 + help
102194 + Enabling this option will have the kernel automatically detect
102195 + and emulate the Procedure Linkage Table entries in ELF files.
102196 + On some architectures such entries are in writable memory, and
102197 + become non-executable leading to task termination. Therefore
102198 + it is mandatory that you enable this option on alpha, parisc,
102199 + sparc and sparc64, otherwise your system would not even boot.
102200 +
102201 + NOTE: this feature *does* open up a loophole in the protection
102202 + provided by the non-executable pages, therefore the proper
102203 + solution is to modify the toolchain to produce a PLT that does
102204 + not need to be writable.
102205 +
102206 +config PAX_DLRESOLVE
102207 + bool 'Emulate old glibc resolver stub'
102208 + depends on PAX_EMUPLT && SPARC
102209 + default n
102210 + help
102211 + This option is needed if userland has an old glibc (before 2.4)
102212 + that puts a 'save' instruction into the runtime generated resolver
102213 + stub that needs special emulation.
102214 +
102215 +config PAX_KERNEXEC
102216 + bool "Enforce non-executable kernel pages"
102217 + default y if GRKERNSEC_CONFIG_AUTO && (GRKERNSEC_CONFIG_VIRT_NONE || (GRKERNSEC_CONFIG_VIRT_EPT && GRKERNSEC_CONFIG_VIRT_GUEST) || (GRKERNSEC_CONFIG_VIRT_EPT && GRKERNSEC_CONFIG_VIRT_KVM))
102218 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !(ARM_LPAE && MODULES))) && !XEN
102219 + select PAX_PER_CPU_PGD if X86_64 || (X86_32 && X86_PAE)
102220 + select PAX_KERNEXEC_PLUGIN if X86_64
102221 + help
102222 + This is the kernel land equivalent of PAGEEXEC and MPROTECT,
102223 + that is, enabling this option will make it harder to inject
102224 + and execute 'foreign' code in kernel memory itself.
102225 +
102226 +choice
102227 + prompt "Return Address Instrumentation Method"
102228 + default PAX_KERNEXEC_PLUGIN_METHOD_BTS
102229 + depends on PAX_KERNEXEC_PLUGIN
102230 + help
102231 + Select the method used to instrument function pointer dereferences.
102232 + Note that binary modules cannot be instrumented by this approach.
102233 +
102234 + Note that the implementation requires a gcc with plugin support,
102235 + i.e., gcc 4.5 or newer. You may need to install the supporting
102236 + headers explicitly in addition to the normal gcc package.
102237 +
102238 + config PAX_KERNEXEC_PLUGIN_METHOD_BTS
102239 + bool "bts"
102240 + help
102241 + This method is compatible with binary only modules but has
102242 + a higher runtime overhead.
102243 +
102244 + config PAX_KERNEXEC_PLUGIN_METHOD_OR
102245 + bool "or"
102246 + depends on !PARAVIRT
102247 + help
102248 + This method is incompatible with binary only modules but has
102249 + a lower runtime overhead.
102250 +endchoice
102251 +
102252 +config PAX_KERNEXEC_PLUGIN_METHOD
102253 + string
102254 + default "bts" if PAX_KERNEXEC_PLUGIN_METHOD_BTS
102255 + default "or" if PAX_KERNEXEC_PLUGIN_METHOD_OR
102256 + default ""
102257 +
102258 +config PAX_KERNEXEC_MODULE_TEXT
102259 + int "Minimum amount of memory reserved for module code"
102260 + default "4" if (!GRKERNSEC_CONFIG_AUTO || GRKERNSEC_CONFIG_SERVER)
102261 + default "12" if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_DESKTOP)
102262 + depends on PAX_KERNEXEC && X86_32
102263 + help
102264 + Due to implementation details the kernel must reserve a fixed
102265 + amount of memory for runtime allocated code (such as modules)
102266 + at compile time that cannot be changed at runtime. Here you
102267 + can specify the minimum amount in MB that will be reserved.
102268 + Due to the same implementation details this size will always
102269 + be rounded up to the next 2/4 MB boundary (depends on PAE) so
102270 + the actually available memory for runtime allocated code will
102271 + usually be more than this minimum.
102272 +
102273 + The default 4 MB should be enough for most users but if you have
102274 + an excessive number of modules (e.g., most distribution configs
102275 + compile many drivers as modules) or use huge modules such as
102276 + nvidia's kernel driver, you will need to adjust this amount.
102277 + A good rule of thumb is to look at your currently loaded kernel
102278 + modules and add up their sizes.
102279 +
102280 +endmenu
102281 +
102282 +menu "Address Space Layout Randomization"
102283 + depends on PAX
102284 +
102285 +config PAX_ASLR
102286 + bool "Address Space Layout Randomization"
102287 + default y if GRKERNSEC_CONFIG_AUTO
102288 + help
102289 + Many if not most exploit techniques rely on the knowledge of
102290 + certain addresses in the attacked program. The following options
102291 + will allow the kernel to apply a certain amount of randomization
102292 + to specific parts of the program thereby forcing an attacker to
102293 + guess them in most cases. Any failed guess will most likely crash
102294 + the attacked program which allows the kernel to detect such attempts
102295 + and react on them. PaX itself provides no reaction mechanisms,
102296 + instead it is strongly encouraged that you make use of Nergal's
102297 + segvguard (ftp://ftp.pl.openwall.com/misc/segvguard/) or grsecurity's
102298 + (http://www.grsecurity.net/) built-in crash detection features or
102299 + develop one yourself.
102300 +
102301 + By saying Y here you can choose to randomize the following areas:
102302 + - top of the task's kernel stack
102303 + - top of the task's userland stack
102304 + - base address for mmap() requests that do not specify one
102305 + (this includes all libraries)
102306 + - base address of the main executable
102307 +
102308 + It is strongly recommended to say Y here as address space layout
102309 + randomization has negligible impact on performance yet it provides
102310 + a very effective protection.
102311 +
102312 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control
102313 + this feature on a per file basis.
102314 +
102315 +config PAX_RANDKSTACK
102316 + bool "Randomize kernel stack base"
102317 + default y if GRKERNSEC_CONFIG_AUTO && !(GRKERNSEC_CONFIG_VIRT_HOST && GRKERNSEC_CONFIG_VIRT_VIRTUALBOX)
102318 + depends on X86_TSC && X86
102319 + help
102320 + By saying Y here the kernel will randomize every task's kernel
102321 + stack on every system call. This will not only force an attacker
102322 + to guess it but also prevent him from making use of possible
102323 + leaked information about it.
102324 +
102325 + Since the kernel stack is a rather scarce resource, randomization
102326 + may cause unexpected stack overflows, therefore you should very
102327 + carefully test your system. Note that once enabled in the kernel
102328 + configuration, this feature cannot be disabled on a per file basis.
102329 +
102330 +config PAX_RANDUSTACK
102331 + bool "Randomize user stack base"
102332 + default y if GRKERNSEC_CONFIG_AUTO
102333 + depends on PAX_ASLR
102334 + help
102335 + By saying Y here the kernel will randomize every task's userland
102336 + stack. The randomization is done in two steps where the second
102337 + one may apply a big amount of shift to the top of the stack and
102338 + cause problems for programs that want to use lots of memory (more
102339 + than 2.5 GB if SEGMEXEC is not active, or 1.25 GB when it is).
102340 + For this reason the second step can be controlled by 'chpax' or
102341 + 'paxctl' on a per file basis.
102342 +
102343 +config PAX_RANDMMAP
102344 + bool "Randomize mmap() base"
102345 + default y if GRKERNSEC_CONFIG_AUTO
102346 + depends on PAX_ASLR
102347 + help
102348 + By saying Y here the kernel will use a randomized base address for
102349 + mmap() requests that do not specify one themselves. As a result
102350 + all dynamically loaded libraries will appear at random addresses
102351 + and therefore be harder to exploit by a technique where an attacker
102352 + attempts to execute library code for his purposes (e.g. spawn a
102353 + shell from an exploited program that is running at an elevated
102354 + privilege level).
102355 +
102356 + Furthermore, if a program is relinked as a dynamic ELF file, its
102357 + base address will be randomized as well, completing the full
102358 + randomization of the address space layout. Attacking such programs
102359 + becomes a guess game. You can find an example of doing this at
102360 + http://pax.grsecurity.net/et_dyn.tar.gz and practical samples at
102361 + http://www.grsecurity.net/grsec-gcc-specs.tar.gz .
102362 +
102363 + NOTE: you can use the 'chpax' or 'paxctl' utilities to control this
102364 + feature on a per file basis.
102365 +
102366 +endmenu
102367 +
102368 +menu "Miscellaneous hardening features"
102369 +
102370 +config PAX_MEMORY_SANITIZE
102371 + bool "Sanitize all freed memory"
102372 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
102373 + help
102374 + By saying Y here the kernel will erase memory pages and slab objects
102375 + as soon as they are freed. This in turn reduces the lifetime of data
102376 + stored in them, making it less likely that sensitive information such
102377 + as passwords, cryptographic secrets, etc stay in memory for too long.
102378 +
102379 + This is especially useful for programs whose runtime is short, long
102380 + lived processes and the kernel itself benefit from this as long as
102381 + they ensure timely freeing of memory that may hold sensitive
102382 + information.
102383 +
102384 + A nice side effect of the sanitization of slab objects is the
102385 + reduction of possible info leaks caused by padding bytes within the
102386 + leaky structures. Use-after-free bugs for structures containing
102387 + pointers can also be detected as dereferencing the sanitized pointer
102388 + will generate an access violation.
102389 +
102390 + The tradeoff is performance impact, on a single CPU system kernel
102391 + compilation sees a 3% slowdown, other systems and workloads may vary
102392 + and you are advised to test this feature on your expected workload
102393 + before deploying it.
102394 +
102395 + To reduce the performance penalty by sanitizing pages only, albeit
102396 + limiting the effectiveness of this feature at the same time, slab
102397 + sanitization can be disabled with the kernel commandline parameter
102398 + "pax_sanitize_slab=0".
102399 +
102400 + Note that this feature does not protect data stored in live pages,
102401 + e.g., process memory swapped to disk may stay there for a long time.
102402 +
102403 +config PAX_MEMORY_STACKLEAK
102404 + bool "Sanitize kernel stack"
102405 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
102406 + depends on X86
102407 + help
102408 + By saying Y here the kernel will erase the kernel stack before it
102409 + returns from a system call. This in turn reduces the information
102410 + that a kernel stack leak bug can reveal.
102411 +
102412 + Note that such a bug can still leak information that was put on
102413 + the stack by the current system call (the one eventually triggering
102414 + the bug) but traces of earlier system calls on the kernel stack
102415 + cannot leak anymore.
102416 +
102417 + The tradeoff is performance impact: on a single CPU system kernel
102418 + compilation sees a 1% slowdown, other systems and workloads may vary
102419 + and you are advised to test this feature on your expected workload
102420 + before deploying it.
102421 +
102422 + Note that the full feature requires a gcc with plugin support,
102423 + i.e., gcc 4.5 or newer. You may need to install the supporting
102424 + headers explicitly in addition to the normal gcc package. Using
102425 + older gcc versions means that functions with large enough stack
102426 + frames may leave uninitialized memory behind that may be exposed
102427 + to a later syscall leaking the stack.
102428 +
102429 +config PAX_MEMORY_STRUCTLEAK
102430 + bool "Forcibly initialize local variables copied to userland"
102431 + default y if (GRKERNSEC_CONFIG_AUTO && GRKERNSEC_CONFIG_PRIORITY_SECURITY)
102432 + help
102433 + By saying Y here the kernel will zero initialize some local
102434 + variables that are going to be copied to userland. This in
102435 + turn prevents unintended information leakage from the kernel
102436 + stack should later code forget to explicitly set all parts of
102437 + the copied variable.
102438 +
102439 + The tradeoff is less performance impact than PAX_MEMORY_STACKLEAK
102440 + at a much smaller coverage.
102441 +
102442 + Note that the implementation requires a gcc with plugin support,
102443 + i.e., gcc 4.5 or newer. You may need to install the supporting
102444 + headers explicitly in addition to the normal gcc package.
102445 +
102446 +config PAX_MEMORY_UDEREF
102447 + bool "Prevent invalid userland pointer dereference"
102448 + default y if GRKERNSEC_CONFIG_AUTO && !(X86_64 && GRKERNSEC_CONFIG_PRIORITY_PERF) && (GRKERNSEC_CONFIG_VIRT_NONE || GRKERNSEC_CONFIG_VIRT_EPT)
102449 + depends on (X86 || (ARM && (CPU_V6 || CPU_V6K || CPU_V7) && !ARM_LPAE)) && !UML_X86 && !XEN
102450 + select PAX_PER_CPU_PGD if X86_64
102451 + help
102452 + By saying Y here the kernel will be prevented from dereferencing
102453 + userland pointers in contexts where the kernel expects only kernel
102454 + pointers. This is both a useful runtime debugging feature and a
102455 + security measure that prevents exploiting a class of kernel bugs.
102456 +
102457 + The tradeoff is that some virtualization solutions may experience
102458 + a huge slowdown and therefore you should not enable this feature
102459 + for kernels meant to run in such environments. Whether a given VM
102460 + solution is affected or not is best determined by simply trying it
102461 + out, the performance impact will be obvious right on boot as this
102462 + mechanism engages from very early on. A good rule of thumb is that
102463 + VMs running on CPUs without hardware virtualization support (i.e.,
102464 + the majority of IA-32 CPUs) will likely experience the slowdown.
102465 +
102466 + On X86_64 the kernel will make use of PCID support when available
102467 + (Intel's Westmere, Sandy Bridge, etc) for better security (default)
102468 + or performance impact. Pass pax_weakuderef on the kernel command
102469 + line to choose the latter.
102470 +
102471 +config PAX_REFCOUNT
102472 + bool "Prevent various kernel object reference counter overflows"
102473 + default y if GRKERNSEC_CONFIG_AUTO
102474 + depends on GRKERNSEC && ((ARM && (CPU_V6 || CPU_V6K || CPU_V7)) || MIPS || SPARC64 || X86)
102475 + help
102476 + By saying Y here the kernel will detect and prevent overflowing
102477 + various (but not all) kinds of object reference counters. Such
102478 + overflows can normally occur due to bugs only and are often, if
102479 + not always, exploitable.
102480 +
102481 + The tradeoff is that data structures protected by an overflowed
102482 + refcount will never be freed and therefore will leak memory. Note
102483 + that this leak also happens even without this protection but in
102484 + that case the overflow can eventually trigger the freeing of the
102485 + data structure while it is still being used elsewhere, resulting
102486 + in the exploitable situation that this feature prevents.
102487 +
102488 + Since this has a negligible performance impact, you should enable
102489 + this feature.
102490 +
102491 +config PAX_CONSTIFY_PLUGIN
102492 + bool "Automatically constify eligible structures"
102493 + default y
102494 + depends on !UML && PAX_KERNEXEC
102495 + help
102496 + By saying Y here the compiler will automatically constify a class
102497 + of types that contain only function pointers. This reduces the
102498 + kernel's attack surface and also produces a better memory layout.
102499 +
102500 + Note that the implementation requires a gcc with plugin support,
102501 + i.e., gcc 4.5 or newer. You may need to install the supporting
102502 + headers explicitly in addition to the normal gcc package.
102503 +
102504 + Note that if some code really has to modify constified variables
102505 + then the source code will have to be patched to allow it. Examples
102506 + can be found in PaX itself (the no_const attribute) and for some
102507 + out-of-tree modules at http://www.grsecurity.net/~paxguy1/ .
102508 +
102509 +config PAX_USERCOPY
102510 + bool "Harden heap object copies between kernel and userland"
102511 + default y if GRKERNSEC_CONFIG_AUTO
102512 + depends on ARM || IA64 || PPC || SPARC || X86
102513 + depends on GRKERNSEC && (SLAB || SLUB || SLOB)
102514 + select PAX_USERCOPY_SLABS
102515 + help
102516 + By saying Y here the kernel will enforce the size of heap objects
102517 + when they are copied in either direction between the kernel and
102518 + userland, even if only a part of the heap object is copied.
102519 +
102520 + Specifically, this checking prevents information leaking from the
102521 + kernel heap during kernel to userland copies (if the kernel heap
102522 + object is otherwise fully initialized) and prevents kernel heap
102523 + overflows during userland to kernel copies.
102524 +
102525 + Note that the current implementation provides the strictest bounds
102526 + checks for the SLUB allocator.
102527 +
102528 + Enabling this option also enables per-slab cache protection against
102529 + data in a given cache being copied into/out of via userland
102530 + accessors. Though the whitelist of regions will be reduced over
102531 + time, it notably protects important data structures like task structs.
102532 +
102533 + If frame pointers are enabled on x86, this option will also restrict
102534 + copies into and out of the kernel stack to local variables within a
102535 + single frame.
102536 +
102537 + Since this has a negligible performance impact, you should enable
102538 + this feature.
102539 +
102540 +config PAX_USERCOPY_DEBUG
102541 + bool
102542 + depends on X86 && PAX_USERCOPY
102543 + default n
102544 +
102545 +config PAX_SIZE_OVERFLOW
102546 + bool "Prevent various integer overflows in function size parameters"
102547 + default y if GRKERNSEC_CONFIG_AUTO
102548 + depends on X86
102549 + help
102550 + By saying Y here the kernel recomputes expressions of function
102551 + arguments marked by a size_overflow attribute with double integer
102552 + precision (DImode/TImode for 32/64 bit integer types).
102553 +
102554 + The recomputed argument is checked against TYPE_MAX and an event
102555 + is logged on overflow and the triggering process is killed.
102556 +
102557 + Homepage: http://www.grsecurity.net/~ephox/overflow_plugin/
102558 +
102559 + Note that the implementation requires a gcc with plugin support,
102560 + i.e., gcc 4.5 or newer. You may need to install the supporting
102561 + headers explicitly in addition to the normal gcc package.
102562 +
102563 +config PAX_LATENT_ENTROPY
102564 + bool "Generate some entropy during boot and runtime"
102565 + default y if GRKERNSEC_CONFIG_AUTO
102566 + help
102567 + By saying Y here the kernel will instrument some kernel code to
102568 + extract some entropy from both original and artificially created
102569 + program state. This will help especially embedded systems where
102570 + there is little 'natural' source of entropy normally. The cost
102571 + is some slowdown of the boot process and fork and irq processing.
102572 +
102573 + When pax_extra_latent_entropy is passed on the kernel command line,
102574 + entropy will be extracted from up to the first 4GB of RAM while the
102575 + runtime memory allocator is being initialized. This costs even more
102576 + slowdown of the boot process.
102577 +
102578 + Note that the implementation requires a gcc with plugin support,
102579 + i.e., gcc 4.5 or newer. You may need to install the supporting
102580 + headers explicitly in addition to the normal gcc package.
102581 +
102582 + Note that entropy extracted this way is not cryptographically
102583 + secure!
102584 +
102585 +endmenu
102586 +
102587 +endmenu
102588 +
102589 +source grsecurity/Kconfig
102590 +
102591 +endmenu
102592 +
102593 +endmenu
102594 +
102595 source security/keys/Kconfig
102596
102597 config SECURITY_DMESG_RESTRICT
102598 @@ -103,7 +1056,7 @@ config INTEL_TXT
102599 config LSM_MMAP_MIN_ADDR
102600 int "Low address space for LSM to protect from user allocation"
102601 depends on SECURITY && SECURITY_SELINUX
102602 - default 32768 if ARM
102603 + default 32768 if ALPHA || ARM || PARISC || SPARC32
102604 default 65536
102605 help
102606 This is the portion of low virtual memory which should be protected
102607 diff --git a/security/apparmor/lsm.c b/security/apparmor/lsm.c
102608 index 4257b7e..f0c9438 100644
102609 --- a/security/apparmor/lsm.c
102610 +++ b/security/apparmor/lsm.c
102611 @@ -615,7 +615,7 @@ static int apparmor_task_setrlimit(struct task_struct *task,
102612 return error;
102613 }
102614
102615 -static struct security_operations apparmor_ops = {
102616 +static struct security_operations apparmor_ops __read_only = {
102617 .name = "apparmor",
102618
102619 .ptrace_access_check = apparmor_ptrace_access_check,
102620 diff --git a/security/commoncap.c b/security/commoncap.c
102621 index b9d613e..f68305c 100644
102622 --- a/security/commoncap.c
102623 +++ b/security/commoncap.c
102624 @@ -424,6 +424,32 @@ int get_vfs_caps_from_disk(const struct dentry *dentry, struct cpu_vfs_cap_data
102625 return 0;
102626 }
102627
102628 +/* returns:
102629 + 1 for suid privilege
102630 + 2 for sgid privilege
102631 + 3 for fscap privilege
102632 +*/
102633 +int is_privileged_binary(const struct dentry *dentry)
102634 +{
102635 + struct cpu_vfs_cap_data capdata;
102636 + struct inode *inode = dentry->d_inode;
102637 +
102638 + if (!inode || S_ISDIR(inode->i_mode))
102639 + return 0;
102640 +
102641 + if (inode->i_mode & S_ISUID)
102642 + return 1;
102643 + if ((inode->i_mode & (S_ISGID | S_IXGRP)) == (S_ISGID | S_IXGRP))
102644 + return 2;
102645 +
102646 + if (!get_vfs_caps_from_disk(dentry, &capdata)) {
102647 + if (!cap_isclear(capdata.inheritable) || !cap_isclear(capdata.permitted))
102648 + return 3;
102649 + }
102650 +
102651 + return 0;
102652 +}
102653 +
102654 /*
102655 * Attempt to get the on-exec apply capability sets for an executable file from
102656 * its xattrs and, if present, apply them to the proposed credentials being
102657 @@ -592,6 +618,9 @@ int cap_bprm_secureexec(struct linux_binprm *bprm)
102658 const struct cred *cred = current_cred();
102659 kuid_t root_uid = make_kuid(cred->user_ns, 0);
102660
102661 + if (gr_acl_enable_at_secure())
102662 + return 1;
102663 +
102664 if (!uid_eq(cred->uid, root_uid)) {
102665 if (bprm->cap_effective)
102666 return 1;
102667 diff --git a/security/integrity/ima/ima.h b/security/integrity/ima/ima.h
102668 index 0356e1d..72332ab 100644
102669 --- a/security/integrity/ima/ima.h
102670 +++ b/security/integrity/ima/ima.h
102671 @@ -118,8 +118,8 @@ int ima_init_template(void);
102672 extern spinlock_t ima_queue_lock;
102673
102674 struct ima_h_table {
102675 - atomic_long_t len; /* number of stored measurements in the list */
102676 - atomic_long_t violations;
102677 + atomic_long_unchecked_t len; /* number of stored measurements in the list */
102678 + atomic_long_unchecked_t violations;
102679 struct hlist_head queue[IMA_MEASURE_HTABLE_SIZE];
102680 };
102681 extern struct ima_h_table ima_htable;
102682 diff --git a/security/integrity/ima/ima_api.c b/security/integrity/ima/ima_api.c
102683 index c38bbce..f45133d 100644
102684 --- a/security/integrity/ima/ima_api.c
102685 +++ b/security/integrity/ima/ima_api.c
102686 @@ -137,7 +137,7 @@ void ima_add_violation(struct file *file, const unsigned char *filename,
102687 int result;
102688
102689 /* can overflow, only indicator */
102690 - atomic_long_inc(&ima_htable.violations);
102691 + atomic_long_inc_unchecked(&ima_htable.violations);
102692
102693 result = ima_alloc_init_template(NULL, file, filename,
102694 NULL, 0, &entry);
102695 diff --git a/security/integrity/ima/ima_fs.c b/security/integrity/ima/ima_fs.c
102696 index db01125..61f6597 100644
102697 --- a/security/integrity/ima/ima_fs.c
102698 +++ b/security/integrity/ima/ima_fs.c
102699 @@ -28,12 +28,12 @@
102700 static int valid_policy = 1;
102701 #define TMPBUFLEN 12
102702 static ssize_t ima_show_htable_value(char __user *buf, size_t count,
102703 - loff_t *ppos, atomic_long_t *val)
102704 + loff_t *ppos, atomic_long_unchecked_t *val)
102705 {
102706 char tmpbuf[TMPBUFLEN];
102707 ssize_t len;
102708
102709 - len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read(val));
102710 + len = scnprintf(tmpbuf, TMPBUFLEN, "%li\n", atomic_long_read_unchecked(val));
102711 return simple_read_from_buffer(buf, count, ppos, tmpbuf, len);
102712 }
102713
102714 diff --git a/security/integrity/ima/ima_queue.c b/security/integrity/ima/ima_queue.c
102715 index d85e997..6992813 100644
102716 --- a/security/integrity/ima/ima_queue.c
102717 +++ b/security/integrity/ima/ima_queue.c
102718 @@ -80,7 +80,7 @@ static int ima_add_digest_entry(struct ima_template_entry *entry)
102719 INIT_LIST_HEAD(&qe->later);
102720 list_add_tail_rcu(&qe->later, &ima_measurements);
102721
102722 - atomic_long_inc(&ima_htable.len);
102723 + atomic_long_inc_unchecked(&ima_htable.len);
102724 key = ima_hash_key(entry->digest);
102725 hlist_add_head_rcu(&qe->hnext, &ima_htable.queue[key]);
102726 return 0;
102727 diff --git a/security/keys/compat.c b/security/keys/compat.c
102728 index bbd32c7..c60c927 100644
102729 --- a/security/keys/compat.c
102730 +++ b/security/keys/compat.c
102731 @@ -44,7 +44,7 @@ static long compat_keyctl_instantiate_key_iov(
102732 if (ret == 0)
102733 goto no_payload_free;
102734
102735 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
102736 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
102737 err:
102738 if (iov != iovstack)
102739 kfree(iov);
102740 diff --git a/security/keys/internal.h b/security/keys/internal.h
102741 index 80b2aac..bb7ee65 100644
102742 --- a/security/keys/internal.h
102743 +++ b/security/keys/internal.h
102744 @@ -253,7 +253,7 @@ extern long keyctl_instantiate_key_iov(key_serial_t,
102745 extern long keyctl_invalidate_key(key_serial_t);
102746
102747 extern long keyctl_instantiate_key_common(key_serial_t,
102748 - const struct iovec *,
102749 + const struct iovec __user *,
102750 unsigned, size_t, key_serial_t);
102751 #ifdef CONFIG_PERSISTENT_KEYRINGS
102752 extern long keyctl_get_persistent(uid_t, key_serial_t);
102753 diff --git a/security/keys/key.c b/security/keys/key.c
102754 index 6e21c11..9ed67ca 100644
102755 --- a/security/keys/key.c
102756 +++ b/security/keys/key.c
102757 @@ -285,7 +285,7 @@ struct key *key_alloc(struct key_type *type, const char *desc,
102758
102759 atomic_set(&key->usage, 1);
102760 init_rwsem(&key->sem);
102761 - lockdep_set_class(&key->sem, &type->lock_class);
102762 + lockdep_set_class(&key->sem, (struct lock_class_key *)&type->lock_class);
102763 key->index_key.type = type;
102764 key->user = user;
102765 key->quotalen = quotalen;
102766 @@ -1036,7 +1036,9 @@ int register_key_type(struct key_type *ktype)
102767 struct key_type *p;
102768 int ret;
102769
102770 - memset(&ktype->lock_class, 0, sizeof(ktype->lock_class));
102771 + pax_open_kernel();
102772 + memset((void *)&ktype->lock_class, 0, sizeof(ktype->lock_class));
102773 + pax_close_kernel();
102774
102775 ret = -EEXIST;
102776 down_write(&key_types_sem);
102777 @@ -1048,7 +1050,7 @@ int register_key_type(struct key_type *ktype)
102778 }
102779
102780 /* store the type */
102781 - list_add(&ktype->link, &key_types_list);
102782 + pax_list_add((struct list_head *)&ktype->link, &key_types_list);
102783
102784 pr_notice("Key type %s registered\n", ktype->name);
102785 ret = 0;
102786 @@ -1070,7 +1072,7 @@ EXPORT_SYMBOL(register_key_type);
102787 void unregister_key_type(struct key_type *ktype)
102788 {
102789 down_write(&key_types_sem);
102790 - list_del_init(&ktype->link);
102791 + pax_list_del_init((struct list_head *)&ktype->link);
102792 downgrade_write(&key_types_sem);
102793 key_gc_keytype(ktype);
102794 pr_notice("Key type %s unregistered\n", ktype->name);
102795 @@ -1088,10 +1090,10 @@ void __init key_init(void)
102796 0, SLAB_HWCACHE_ALIGN|SLAB_PANIC, NULL);
102797
102798 /* add the special key types */
102799 - list_add_tail(&key_type_keyring.link, &key_types_list);
102800 - list_add_tail(&key_type_dead.link, &key_types_list);
102801 - list_add_tail(&key_type_user.link, &key_types_list);
102802 - list_add_tail(&key_type_logon.link, &key_types_list);
102803 + pax_list_add_tail((struct list_head *)&key_type_keyring.link, &key_types_list);
102804 + pax_list_add_tail((struct list_head *)&key_type_dead.link, &key_types_list);
102805 + pax_list_add_tail((struct list_head *)&key_type_user.link, &key_types_list);
102806 + pax_list_add_tail((struct list_head *)&key_type_logon.link, &key_types_list);
102807
102808 /* record the root user tracking */
102809 rb_link_node(&root_key_user.node,
102810 diff --git a/security/keys/keyctl.c b/security/keys/keyctl.c
102811 index cee72ce..e46074a 100644
102812 --- a/security/keys/keyctl.c
102813 +++ b/security/keys/keyctl.c
102814 @@ -987,7 +987,7 @@ static int keyctl_change_reqkey_auth(struct key *key)
102815 /*
102816 * Copy the iovec data from userspace
102817 */
102818 -static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
102819 +static long copy_from_user_iovec(void *buffer, const struct iovec __user *iov,
102820 unsigned ioc)
102821 {
102822 for (; ioc > 0; ioc--) {
102823 @@ -1009,7 +1009,7 @@ static long copy_from_user_iovec(void *buffer, const struct iovec *iov,
102824 * If successful, 0 will be returned.
102825 */
102826 long keyctl_instantiate_key_common(key_serial_t id,
102827 - const struct iovec *payload_iov,
102828 + const struct iovec __user *payload_iov,
102829 unsigned ioc,
102830 size_t plen,
102831 key_serial_t ringid)
102832 @@ -1104,7 +1104,7 @@ long keyctl_instantiate_key(key_serial_t id,
102833 [0].iov_len = plen
102834 };
102835
102836 - return keyctl_instantiate_key_common(id, iov, 1, plen, ringid);
102837 + return keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, 1, plen, ringid);
102838 }
102839
102840 return keyctl_instantiate_key_common(id, NULL, 0, 0, ringid);
102841 @@ -1137,7 +1137,7 @@ long keyctl_instantiate_key_iov(key_serial_t id,
102842 if (ret == 0)
102843 goto no_payload_free;
102844
102845 - ret = keyctl_instantiate_key_common(id, iov, ioc, ret, ringid);
102846 + ret = keyctl_instantiate_key_common(id, (const struct iovec __force_user *)iov, ioc, ret, ringid);
102847 err:
102848 if (iov != iovstack)
102849 kfree(iov);
102850 diff --git a/security/min_addr.c b/security/min_addr.c
102851 index f728728..6457a0c 100644
102852 --- a/security/min_addr.c
102853 +++ b/security/min_addr.c
102854 @@ -14,6 +14,7 @@ unsigned long dac_mmap_min_addr = CONFIG_DEFAULT_MMAP_MIN_ADDR;
102855 */
102856 static void update_mmap_min_addr(void)
102857 {
102858 +#ifndef SPARC
102859 #ifdef CONFIG_LSM_MMAP_MIN_ADDR
102860 if (dac_mmap_min_addr > CONFIG_LSM_MMAP_MIN_ADDR)
102861 mmap_min_addr = dac_mmap_min_addr;
102862 @@ -22,6 +23,7 @@ static void update_mmap_min_addr(void)
102863 #else
102864 mmap_min_addr = dac_mmap_min_addr;
102865 #endif
102866 +#endif
102867 }
102868
102869 /*
102870 diff --git a/security/security.c b/security/security.c
102871 index 15b6928..60d03ec 100644
102872 --- a/security/security.c
102873 +++ b/security/security.c
102874 @@ -33,8 +33,8 @@
102875 static __initdata char chosen_lsm[SECURITY_NAME_MAX + 1] =
102876 CONFIG_DEFAULT_SECURITY;
102877
102878 -static struct security_operations *security_ops;
102879 -static struct security_operations default_security_ops = {
102880 +struct security_operations *security_ops __read_only;
102881 +struct security_operations default_security_ops __read_only = {
102882 .name = "default",
102883 };
102884
102885 @@ -73,11 +73,6 @@ int __init security_init(void)
102886 return 0;
102887 }
102888
102889 -void reset_security_ops(void)
102890 -{
102891 - security_ops = &default_security_ops;
102892 -}
102893 -
102894 /* Save user chosen LSM */
102895 static int __init choose_lsm(char *str)
102896 {
102897 diff --git a/security/selinux/avc.c b/security/selinux/avc.c
102898 index fc3e662..7844c60 100644
102899 --- a/security/selinux/avc.c
102900 +++ b/security/selinux/avc.c
102901 @@ -59,7 +59,7 @@ struct avc_node {
102902 struct avc_cache {
102903 struct hlist_head slots[AVC_CACHE_SLOTS]; /* head for avc_node->list */
102904 spinlock_t slots_lock[AVC_CACHE_SLOTS]; /* lock for writes */
102905 - atomic_t lru_hint; /* LRU hint for reclaim scan */
102906 + atomic_unchecked_t lru_hint; /* LRU hint for reclaim scan */
102907 atomic_t active_nodes;
102908 u32 latest_notif; /* latest revocation notification */
102909 };
102910 @@ -167,7 +167,7 @@ void __init avc_init(void)
102911 spin_lock_init(&avc_cache.slots_lock[i]);
102912 }
102913 atomic_set(&avc_cache.active_nodes, 0);
102914 - atomic_set(&avc_cache.lru_hint, 0);
102915 + atomic_set_unchecked(&avc_cache.lru_hint, 0);
102916
102917 avc_node_cachep = kmem_cache_create("avc_node", sizeof(struct avc_node),
102918 0, SLAB_PANIC, NULL);
102919 @@ -242,7 +242,7 @@ static inline int avc_reclaim_node(void)
102920 spinlock_t *lock;
102921
102922 for (try = 0, ecx = 0; try < AVC_CACHE_SLOTS; try++) {
102923 - hvalue = atomic_inc_return(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
102924 + hvalue = atomic_inc_return_unchecked(&avc_cache.lru_hint) & (AVC_CACHE_SLOTS - 1);
102925 head = &avc_cache.slots[hvalue];
102926 lock = &avc_cache.slots_lock[hvalue];
102927
102928 diff --git a/security/selinux/hooks.c b/security/selinux/hooks.c
102929 index 57b0b49..402063e 100644
102930 --- a/security/selinux/hooks.c
102931 +++ b/security/selinux/hooks.c
102932 @@ -96,8 +96,6 @@
102933 #include "audit.h"
102934 #include "avc_ss.h"
102935
102936 -extern struct security_operations *security_ops;
102937 -
102938 /* SECMARK reference count */
102939 static atomic_t selinux_secmark_refcount = ATOMIC_INIT(0);
102940
102941 @@ -5745,7 +5743,7 @@ static int selinux_key_getsecurity(struct key *key, char **_buffer)
102942
102943 #endif
102944
102945 -static struct security_operations selinux_ops = {
102946 +static struct security_operations selinux_ops __read_only = {
102947 .name = "selinux",
102948
102949 .ptrace_access_check = selinux_ptrace_access_check,
102950 @@ -6098,6 +6096,9 @@ static void selinux_nf_ip_exit(void)
102951 #ifdef CONFIG_SECURITY_SELINUX_DISABLE
102952 static int selinux_disabled;
102953
102954 +extern struct security_operations *security_ops;
102955 +extern struct security_operations default_security_ops;
102956 +
102957 int selinux_disable(void)
102958 {
102959 if (ss_initialized) {
102960 @@ -6115,7 +6116,9 @@ int selinux_disable(void)
102961 selinux_disabled = 1;
102962 selinux_enabled = 0;
102963
102964 - reset_security_ops();
102965 + pax_open_kernel();
102966 + security_ops = &default_security_ops;
102967 + pax_close_kernel();
102968
102969 /* Try to destroy the avc node cache */
102970 avc_disable();
102971 diff --git a/security/selinux/include/xfrm.h b/security/selinux/include/xfrm.h
102972 index 48c3cc9..8022cf7 100644
102973 --- a/security/selinux/include/xfrm.h
102974 +++ b/security/selinux/include/xfrm.h
102975 @@ -45,7 +45,7 @@ static inline void selinux_xfrm_notify_policyload(void)
102976 {
102977 struct net *net;
102978
102979 - atomic_inc(&flow_cache_genid);
102980 + atomic_inc_unchecked(&flow_cache_genid);
102981 rtnl_lock();
102982 for_each_net(net)
102983 rt_genid_bump_all(net);
102984 diff --git a/security/selinux/ss/services.c b/security/selinux/ss/services.c
102985 index d106733..539aadd 100644
102986 --- a/security/selinux/ss/services.c
102987 +++ b/security/selinux/ss/services.c
102988 @@ -1232,6 +1232,10 @@ static int security_context_to_sid_core(const char *scontext, u32 scontext_len,
102989 struct context context;
102990 int rc = 0;
102991
102992 + /* An empty security context is never valid. */
102993 + if (!scontext_len)
102994 + return -EINVAL;
102995 +
102996 if (!ss_initialized) {
102997 int i;
102998
102999 diff --git a/security/smack/smack_lsm.c b/security/smack/smack_lsm.c
103000 index b0be893..646bd94 100644
103001 --- a/security/smack/smack_lsm.c
103002 +++ b/security/smack/smack_lsm.c
103003 @@ -3731,7 +3731,7 @@ static int smack_inode_getsecctx(struct inode *inode, void **ctx, u32 *ctxlen)
103004 return 0;
103005 }
103006
103007 -struct security_operations smack_ops = {
103008 +struct security_operations smack_ops __read_only = {
103009 .name = "smack",
103010
103011 .ptrace_access_check = smack_ptrace_access_check,
103012 diff --git a/security/tomoyo/mount.c b/security/tomoyo/mount.c
103013 index 390c646..f2f8db3 100644
103014 --- a/security/tomoyo/mount.c
103015 +++ b/security/tomoyo/mount.c
103016 @@ -118,6 +118,10 @@ static int tomoyo_mount_acl(struct tomoyo_request_info *r,
103017 type == tomoyo_mounts[TOMOYO_MOUNT_MOVE]) {
103018 need_dev = -1; /* dev_name is a directory */
103019 } else {
103020 + if (!capable(CAP_SYS_ADMIN)) {
103021 + error = -EPERM;
103022 + goto out;
103023 + }
103024 fstype = get_fs_type(type);
103025 if (!fstype) {
103026 error = -ENODEV;
103027 diff --git a/security/tomoyo/tomoyo.c b/security/tomoyo/tomoyo.c
103028 index f0b756e..b129202 100644
103029 --- a/security/tomoyo/tomoyo.c
103030 +++ b/security/tomoyo/tomoyo.c
103031 @@ -503,7 +503,7 @@ static int tomoyo_socket_sendmsg(struct socket *sock, struct msghdr *msg,
103032 * tomoyo_security_ops is a "struct security_operations" which is used for
103033 * registering TOMOYO.
103034 */
103035 -static struct security_operations tomoyo_security_ops = {
103036 +static struct security_operations tomoyo_security_ops __read_only = {
103037 .name = "tomoyo",
103038 .cred_alloc_blank = tomoyo_cred_alloc_blank,
103039 .cred_prepare = tomoyo_cred_prepare,
103040 diff --git a/security/yama/Kconfig b/security/yama/Kconfig
103041 index 20ef514..4182bed 100644
103042 --- a/security/yama/Kconfig
103043 +++ b/security/yama/Kconfig
103044 @@ -1,6 +1,6 @@
103045 config SECURITY_YAMA
103046 bool "Yama support"
103047 - depends on SECURITY
103048 + depends on SECURITY && !GRKERNSEC
103049 select SECURITYFS
103050 select SECURITY_PATH
103051 default n
103052 diff --git a/security/yama/yama_lsm.c b/security/yama/yama_lsm.c
103053 index 13c88fbc..f8c115e 100644
103054 --- a/security/yama/yama_lsm.c
103055 +++ b/security/yama/yama_lsm.c
103056 @@ -365,7 +365,7 @@ int yama_ptrace_traceme(struct task_struct *parent)
103057 }
103058
103059 #ifndef CONFIG_SECURITY_YAMA_STACKED
103060 -static struct security_operations yama_ops = {
103061 +static struct security_operations yama_ops __read_only = {
103062 .name = "yama",
103063
103064 .ptrace_access_check = yama_ptrace_access_check,
103065 @@ -376,28 +376,24 @@ static struct security_operations yama_ops = {
103066 #endif
103067
103068 #ifdef CONFIG_SYSCTL
103069 +static int zero __read_only;
103070 +static int max_scope __read_only = YAMA_SCOPE_NO_ATTACH;
103071 +
103072 static int yama_dointvec_minmax(struct ctl_table *table, int write,
103073 void __user *buffer, size_t *lenp, loff_t *ppos)
103074 {
103075 - int rc;
103076 + ctl_table_no_const yama_table;
103077
103078 if (write && !capable(CAP_SYS_PTRACE))
103079 return -EPERM;
103080
103081 - rc = proc_dointvec_minmax(table, write, buffer, lenp, ppos);
103082 - if (rc)
103083 - return rc;
103084 -
103085 + yama_table = *table;
103086 /* Lock the max value if it ever gets set. */
103087 - if (write && *(int *)table->data == *(int *)table->extra2)
103088 - table->extra1 = table->extra2;
103089 -
103090 - return rc;
103091 + if (ptrace_scope == max_scope)
103092 + yama_table.extra1 = &max_scope;
103093 + return proc_dointvec_minmax(&yama_table, write, buffer, lenp, ppos);
103094 }
103095
103096 -static int zero;
103097 -static int max_scope = YAMA_SCOPE_NO_ATTACH;
103098 -
103099 struct ctl_path yama_sysctl_path[] = {
103100 { .procname = "kernel", },
103101 { .procname = "yama", },
103102 diff --git a/sound/aoa/codecs/onyx.c b/sound/aoa/codecs/onyx.c
103103 index 4cedc69..e59d8a3 100644
103104 --- a/sound/aoa/codecs/onyx.c
103105 +++ b/sound/aoa/codecs/onyx.c
103106 @@ -54,7 +54,7 @@ struct onyx {
103107 spdif_locked:1,
103108 analog_locked:1,
103109 original_mute:2;
103110 - int open_count;
103111 + local_t open_count;
103112 struct codec_info *codec_info;
103113
103114 /* mutex serializes concurrent access to the device
103115 @@ -753,7 +753,7 @@ static int onyx_open(struct codec_info_item *cii,
103116 struct onyx *onyx = cii->codec_data;
103117
103118 mutex_lock(&onyx->mutex);
103119 - onyx->open_count++;
103120 + local_inc(&onyx->open_count);
103121 mutex_unlock(&onyx->mutex);
103122
103123 return 0;
103124 @@ -765,8 +765,7 @@ static int onyx_close(struct codec_info_item *cii,
103125 struct onyx *onyx = cii->codec_data;
103126
103127 mutex_lock(&onyx->mutex);
103128 - onyx->open_count--;
103129 - if (!onyx->open_count)
103130 + if (local_dec_and_test(&onyx->open_count))
103131 onyx->spdif_locked = onyx->analog_locked = 0;
103132 mutex_unlock(&onyx->mutex);
103133
103134 diff --git a/sound/aoa/codecs/onyx.h b/sound/aoa/codecs/onyx.h
103135 index ffd2025..df062c9 100644
103136 --- a/sound/aoa/codecs/onyx.h
103137 +++ b/sound/aoa/codecs/onyx.h
103138 @@ -11,6 +11,7 @@
103139 #include <linux/i2c.h>
103140 #include <asm/pmac_low_i2c.h>
103141 #include <asm/prom.h>
103142 +#include <asm/local.h>
103143
103144 /* PCM3052 register definitions */
103145
103146 diff --git a/sound/core/oss/pcm_oss.c b/sound/core/oss/pcm_oss.c
103147 index 4c1cc51..16040040 100644
103148 --- a/sound/core/oss/pcm_oss.c
103149 +++ b/sound/core/oss/pcm_oss.c
103150 @@ -1189,10 +1189,10 @@ snd_pcm_sframes_t snd_pcm_oss_write3(struct snd_pcm_substream *substream, const
103151 if (in_kernel) {
103152 mm_segment_t fs;
103153 fs = snd_enter_user();
103154 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
103155 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
103156 snd_leave_user(fs);
103157 } else {
103158 - ret = snd_pcm_lib_write(substream, (void __force __user *)ptr, frames);
103159 + ret = snd_pcm_lib_write(substream, (void __force_user *)ptr, frames);
103160 }
103161 if (ret != -EPIPE && ret != -ESTRPIPE)
103162 break;
103163 @@ -1234,10 +1234,10 @@ snd_pcm_sframes_t snd_pcm_oss_read3(struct snd_pcm_substream *substream, char *p
103164 if (in_kernel) {
103165 mm_segment_t fs;
103166 fs = snd_enter_user();
103167 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
103168 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
103169 snd_leave_user(fs);
103170 } else {
103171 - ret = snd_pcm_lib_read(substream, (void __force __user *)ptr, frames);
103172 + ret = snd_pcm_lib_read(substream, (void __force_user *)ptr, frames);
103173 }
103174 if (ret == -EPIPE) {
103175 if (runtime->status->state == SNDRV_PCM_STATE_DRAINING) {
103176 @@ -1337,7 +1337,7 @@ static ssize_t snd_pcm_oss_write2(struct snd_pcm_substream *substream, const cha
103177 struct snd_pcm_plugin_channel *channels;
103178 size_t oss_frame_bytes = (runtime->oss.plugin_first->src_width * runtime->oss.plugin_first->src_format.channels) / 8;
103179 if (!in_kernel) {
103180 - if (copy_from_user(runtime->oss.buffer, (const char __force __user *)buf, bytes))
103181 + if (copy_from_user(runtime->oss.buffer, (const char __force_user *)buf, bytes))
103182 return -EFAULT;
103183 buf = runtime->oss.buffer;
103184 }
103185 @@ -1407,7 +1407,7 @@ static ssize_t snd_pcm_oss_write1(struct snd_pcm_substream *substream, const cha
103186 }
103187 } else {
103188 tmp = snd_pcm_oss_write2(substream,
103189 - (const char __force *)buf,
103190 + (const char __force_kernel *)buf,
103191 runtime->oss.period_bytes, 0);
103192 if (tmp <= 0)
103193 goto err;
103194 @@ -1433,7 +1433,7 @@ static ssize_t snd_pcm_oss_read2(struct snd_pcm_substream *substream, char *buf,
103195 struct snd_pcm_runtime *runtime = substream->runtime;
103196 snd_pcm_sframes_t frames, frames1;
103197 #ifdef CONFIG_SND_PCM_OSS_PLUGINS
103198 - char __user *final_dst = (char __force __user *)buf;
103199 + char __user *final_dst = (char __force_user *)buf;
103200 if (runtime->oss.plugin_first) {
103201 struct snd_pcm_plugin_channel *channels;
103202 size_t oss_frame_bytes = (runtime->oss.plugin_last->dst_width * runtime->oss.plugin_last->dst_format.channels) / 8;
103203 @@ -1495,7 +1495,7 @@ static ssize_t snd_pcm_oss_read1(struct snd_pcm_substream *substream, char __use
103204 xfer += tmp;
103205 runtime->oss.buffer_used -= tmp;
103206 } else {
103207 - tmp = snd_pcm_oss_read2(substream, (char __force *)buf,
103208 + tmp = snd_pcm_oss_read2(substream, (char __force_kernel *)buf,
103209 runtime->oss.period_bytes, 0);
103210 if (tmp <= 0)
103211 goto err;
103212 @@ -1663,7 +1663,7 @@ static int snd_pcm_oss_sync(struct snd_pcm_oss_file *pcm_oss_file)
103213 size1);
103214 size1 /= runtime->channels; /* frames */
103215 fs = snd_enter_user();
103216 - snd_pcm_lib_write(substream, (void __force __user *)runtime->oss.buffer, size1);
103217 + snd_pcm_lib_write(substream, (void __force_user *)runtime->oss.buffer, size1);
103218 snd_leave_user(fs);
103219 }
103220 } else if (runtime->access == SNDRV_PCM_ACCESS_RW_NONINTERLEAVED) {
103221 diff --git a/sound/core/pcm_compat.c b/sound/core/pcm_compat.c
103222 index af49721..e85058e 100644
103223 --- a/sound/core/pcm_compat.c
103224 +++ b/sound/core/pcm_compat.c
103225 @@ -31,7 +31,7 @@ static int snd_pcm_ioctl_delay_compat(struct snd_pcm_substream *substream,
103226 int err;
103227
103228 fs = snd_enter_user();
103229 - err = snd_pcm_delay(substream, &delay);
103230 + err = snd_pcm_delay(substream, (snd_pcm_sframes_t __force_user *)&delay);
103231 snd_leave_user(fs);
103232 if (err < 0)
103233 return err;
103234 diff --git a/sound/core/pcm_native.c b/sound/core/pcm_native.c
103235 index 01a5e05..c6bb425 100644
103236 --- a/sound/core/pcm_native.c
103237 +++ b/sound/core/pcm_native.c
103238 @@ -2811,11 +2811,11 @@ int snd_pcm_kernel_ioctl(struct snd_pcm_substream *substream,
103239 switch (substream->stream) {
103240 case SNDRV_PCM_STREAM_PLAYBACK:
103241 result = snd_pcm_playback_ioctl1(NULL, substream, cmd,
103242 - (void __user *)arg);
103243 + (void __force_user *)arg);
103244 break;
103245 case SNDRV_PCM_STREAM_CAPTURE:
103246 result = snd_pcm_capture_ioctl1(NULL, substream, cmd,
103247 - (void __user *)arg);
103248 + (void __force_user *)arg);
103249 break;
103250 default:
103251 result = -EINVAL;
103252 diff --git a/sound/core/seq/oss/seq_oss.c b/sound/core/seq/oss/seq_oss.c
103253 index 8d4d5e8..fdd0826 100644
103254 --- a/sound/core/seq/oss/seq_oss.c
103255 +++ b/sound/core/seq/oss/seq_oss.c
103256 @@ -75,8 +75,8 @@ static int __init alsa_seq_oss_init(void)
103257 {
103258 int rc;
103259 static struct snd_seq_dev_ops ops = {
103260 - snd_seq_oss_synth_register,
103261 - snd_seq_oss_synth_unregister,
103262 + .init_device = snd_seq_oss_synth_register,
103263 + .free_device = snd_seq_oss_synth_unregister,
103264 };
103265
103266 snd_seq_autoload_lock();
103267 diff --git a/sound/core/seq/seq_device.c b/sound/core/seq/seq_device.c
103268 index 040c60e..989a19a 100644
103269 --- a/sound/core/seq/seq_device.c
103270 +++ b/sound/core/seq/seq_device.c
103271 @@ -64,7 +64,7 @@ struct ops_list {
103272 int argsize; /* argument size */
103273
103274 /* operators */
103275 - struct snd_seq_dev_ops ops;
103276 + struct snd_seq_dev_ops *ops;
103277
103278 /* registered devices */
103279 struct list_head dev_list; /* list of devices */
103280 @@ -333,7 +333,7 @@ int snd_seq_device_register_driver(char *id, struct snd_seq_dev_ops *entry,
103281
103282 mutex_lock(&ops->reg_mutex);
103283 /* copy driver operators */
103284 - ops->ops = *entry;
103285 + ops->ops = entry;
103286 ops->driver |= DRIVER_LOADED;
103287 ops->argsize = argsize;
103288
103289 @@ -463,7 +463,7 @@ static int init_device(struct snd_seq_device *dev, struct ops_list *ops)
103290 dev->name, ops->id, ops->argsize, dev->argsize);
103291 return -EINVAL;
103292 }
103293 - if (ops->ops.init_device(dev) >= 0) {
103294 + if (ops->ops->init_device(dev) >= 0) {
103295 dev->status = SNDRV_SEQ_DEVICE_REGISTERED;
103296 ops->num_init_devices++;
103297 } else {
103298 @@ -490,7 +490,7 @@ static int free_device(struct snd_seq_device *dev, struct ops_list *ops)
103299 dev->name, ops->id, ops->argsize, dev->argsize);
103300 return -EINVAL;
103301 }
103302 - if ((result = ops->ops.free_device(dev)) >= 0 || result == -ENXIO) {
103303 + if ((result = ops->ops->free_device(dev)) >= 0 || result == -ENXIO) {
103304 dev->status = SNDRV_SEQ_DEVICE_FREE;
103305 dev->driver_data = NULL;
103306 ops->num_init_devices--;
103307 diff --git a/sound/core/seq/seq_midi.c b/sound/core/seq/seq_midi.c
103308 index 64069db..3c6d392 100644
103309 --- a/sound/core/seq/seq_midi.c
103310 +++ b/sound/core/seq/seq_midi.c
103311 @@ -462,8 +462,8 @@ snd_seq_midisynth_unregister_port(struct snd_seq_device *dev)
103312 static int __init alsa_seq_midi_init(void)
103313 {
103314 static struct snd_seq_dev_ops ops = {
103315 - snd_seq_midisynth_register_port,
103316 - snd_seq_midisynth_unregister_port,
103317 + .init_device = snd_seq_midisynth_register_port,
103318 + .free_device = snd_seq_midisynth_unregister_port,
103319 };
103320 memset(&synths, 0, sizeof(synths));
103321 snd_seq_autoload_lock();
103322 diff --git a/sound/core/sound.c b/sound/core/sound.c
103323 index 437c25e..cd040ab 100644
103324 --- a/sound/core/sound.c
103325 +++ b/sound/core/sound.c
103326 @@ -86,7 +86,7 @@ static void snd_request_other(int minor)
103327 case SNDRV_MINOR_TIMER: str = "snd-timer"; break;
103328 default: return;
103329 }
103330 - request_module(str);
103331 + request_module("%s", str);
103332 }
103333
103334 #endif /* modular kernel */
103335 diff --git a/sound/drivers/mts64.c b/sound/drivers/mts64.c
103336 index 4e0dd22..7a1f32c 100644
103337 --- a/sound/drivers/mts64.c
103338 +++ b/sound/drivers/mts64.c
103339 @@ -29,6 +29,7 @@
103340 #include <sound/initval.h>
103341 #include <sound/rawmidi.h>
103342 #include <sound/control.h>
103343 +#include <asm/local.h>
103344
103345 #define CARD_NAME "Miditerminal 4140"
103346 #define DRIVER_NAME "MTS64"
103347 @@ -67,7 +68,7 @@ struct mts64 {
103348 struct pardevice *pardev;
103349 int pardev_claimed;
103350
103351 - int open_count;
103352 + local_t open_count;
103353 int current_midi_output_port;
103354 int current_midi_input_port;
103355 u8 mode[MTS64_NUM_INPUT_PORTS];
103356 @@ -697,7 +698,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
103357 {
103358 struct mts64 *mts = substream->rmidi->private_data;
103359
103360 - if (mts->open_count == 0) {
103361 + if (local_read(&mts->open_count) == 0) {
103362 /* We don't need a spinlock here, because this is just called
103363 if the device has not been opened before.
103364 So there aren't any IRQs from the device */
103365 @@ -705,7 +706,7 @@ static int snd_mts64_rawmidi_open(struct snd_rawmidi_substream *substream)
103366
103367 msleep(50);
103368 }
103369 - ++(mts->open_count);
103370 + local_inc(&mts->open_count);
103371
103372 return 0;
103373 }
103374 @@ -715,8 +716,7 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
103375 struct mts64 *mts = substream->rmidi->private_data;
103376 unsigned long flags;
103377
103378 - --(mts->open_count);
103379 - if (mts->open_count == 0) {
103380 + if (local_dec_return(&mts->open_count) == 0) {
103381 /* We need the spinlock_irqsave here because we can still
103382 have IRQs at this point */
103383 spin_lock_irqsave(&mts->lock, flags);
103384 @@ -725,8 +725,8 @@ static int snd_mts64_rawmidi_close(struct snd_rawmidi_substream *substream)
103385
103386 msleep(500);
103387
103388 - } else if (mts->open_count < 0)
103389 - mts->open_count = 0;
103390 + } else if (local_read(&mts->open_count) < 0)
103391 + local_set(&mts->open_count, 0);
103392
103393 return 0;
103394 }
103395 diff --git a/sound/drivers/opl3/opl3_seq.c b/sound/drivers/opl3/opl3_seq.c
103396 index 6839953..7a0f4b9 100644
103397 --- a/sound/drivers/opl3/opl3_seq.c
103398 +++ b/sound/drivers/opl3/opl3_seq.c
103399 @@ -281,8 +281,8 @@ static int __init alsa_opl3_seq_init(void)
103400 {
103401 static struct snd_seq_dev_ops ops =
103402 {
103403 - snd_opl3_seq_new_device,
103404 - snd_opl3_seq_delete_device
103405 + .init_device = snd_opl3_seq_new_device,
103406 + .free_device = snd_opl3_seq_delete_device
103407 };
103408
103409 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL3, &ops,
103410 diff --git a/sound/drivers/opl4/opl4_lib.c b/sound/drivers/opl4/opl4_lib.c
103411 index b953fb4..1999c01 100644
103412 --- a/sound/drivers/opl4/opl4_lib.c
103413 +++ b/sound/drivers/opl4/opl4_lib.c
103414 @@ -29,7 +29,7 @@ MODULE_AUTHOR("Clemens Ladisch <clemens@ladisch.de>");
103415 MODULE_DESCRIPTION("OPL4 driver");
103416 MODULE_LICENSE("GPL");
103417
103418 -static void inline snd_opl4_wait(struct snd_opl4 *opl4)
103419 +static inline void snd_opl4_wait(struct snd_opl4 *opl4)
103420 {
103421 int timeout = 10;
103422 while ((inb(opl4->fm_port) & OPL4_STATUS_BUSY) && --timeout > 0)
103423 diff --git a/sound/drivers/opl4/opl4_seq.c b/sound/drivers/opl4/opl4_seq.c
103424 index 9919769..d7de36c 100644
103425 --- a/sound/drivers/opl4/opl4_seq.c
103426 +++ b/sound/drivers/opl4/opl4_seq.c
103427 @@ -198,8 +198,8 @@ static int snd_opl4_seq_delete_device(struct snd_seq_device *dev)
103428 static int __init alsa_opl4_synth_init(void)
103429 {
103430 static struct snd_seq_dev_ops ops = {
103431 - snd_opl4_seq_new_device,
103432 - snd_opl4_seq_delete_device
103433 + .init_device = snd_opl4_seq_new_device,
103434 + .free_device = snd_opl4_seq_delete_device
103435 };
103436
103437 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_OPL4, &ops,
103438 diff --git a/sound/drivers/portman2x4.c b/sound/drivers/portman2x4.c
103439 index 991018d..8984740 100644
103440 --- a/sound/drivers/portman2x4.c
103441 +++ b/sound/drivers/portman2x4.c
103442 @@ -48,6 +48,7 @@
103443 #include <sound/initval.h>
103444 #include <sound/rawmidi.h>
103445 #include <sound/control.h>
103446 +#include <asm/local.h>
103447
103448 #define CARD_NAME "Portman 2x4"
103449 #define DRIVER_NAME "portman"
103450 @@ -85,7 +86,7 @@ struct portman {
103451 struct pardevice *pardev;
103452 int pardev_claimed;
103453
103454 - int open_count;
103455 + local_t open_count;
103456 int mode[PORTMAN_NUM_INPUT_PORTS];
103457 struct snd_rawmidi_substream *midi_input[PORTMAN_NUM_INPUT_PORTS];
103458 };
103459 diff --git a/sound/firewire/amdtp.c b/sound/firewire/amdtp.c
103460 index 9048777..2d8b1fc 100644
103461 --- a/sound/firewire/amdtp.c
103462 +++ b/sound/firewire/amdtp.c
103463 @@ -488,7 +488,7 @@ static void queue_out_packet(struct amdtp_out_stream *s, unsigned int cycle)
103464 ptr = s->pcm_buffer_pointer + data_blocks;
103465 if (ptr >= pcm->runtime->buffer_size)
103466 ptr -= pcm->runtime->buffer_size;
103467 - ACCESS_ONCE(s->pcm_buffer_pointer) = ptr;
103468 + ACCESS_ONCE_RW(s->pcm_buffer_pointer) = ptr;
103469
103470 s->pcm_period_pointer += data_blocks;
103471 if (s->pcm_period_pointer >= pcm->runtime->period_size) {
103472 @@ -655,7 +655,7 @@ EXPORT_SYMBOL(amdtp_out_stream_pcm_pointer);
103473 */
103474 void amdtp_out_stream_update(struct amdtp_out_stream *s)
103475 {
103476 - ACCESS_ONCE(s->source_node_id_field) =
103477 + ACCESS_ONCE_RW(s->source_node_id_field) =
103478 (fw_parent_device(s->unit)->card->node_id & 0x3f) << 24;
103479 }
103480 EXPORT_SYMBOL(amdtp_out_stream_update);
103481 diff --git a/sound/firewire/amdtp.h b/sound/firewire/amdtp.h
103482 index 2746ecd..c35dedd 100644
103483 --- a/sound/firewire/amdtp.h
103484 +++ b/sound/firewire/amdtp.h
103485 @@ -135,7 +135,7 @@ static inline bool amdtp_out_streaming_error(struct amdtp_out_stream *s)
103486 static inline void amdtp_out_stream_pcm_trigger(struct amdtp_out_stream *s,
103487 struct snd_pcm_substream *pcm)
103488 {
103489 - ACCESS_ONCE(s->pcm) = pcm;
103490 + ACCESS_ONCE_RW(s->pcm) = pcm;
103491 }
103492
103493 static inline bool cip_sfc_is_base_44100(enum cip_sfc sfc)
103494 diff --git a/sound/firewire/isight.c b/sound/firewire/isight.c
103495 index fd42e6b..c041971 100644
103496 --- a/sound/firewire/isight.c
103497 +++ b/sound/firewire/isight.c
103498 @@ -96,7 +96,7 @@ static void isight_update_pointers(struct isight *isight, unsigned int count)
103499 ptr += count;
103500 if (ptr >= runtime->buffer_size)
103501 ptr -= runtime->buffer_size;
103502 - ACCESS_ONCE(isight->buffer_pointer) = ptr;
103503 + ACCESS_ONCE_RW(isight->buffer_pointer) = ptr;
103504
103505 isight->period_counter += count;
103506 if (isight->period_counter >= runtime->period_size) {
103507 @@ -299,7 +299,7 @@ static int isight_hw_params(struct snd_pcm_substream *substream,
103508 if (err < 0)
103509 return err;
103510
103511 - ACCESS_ONCE(isight->pcm_active) = true;
103512 + ACCESS_ONCE_RW(isight->pcm_active) = true;
103513
103514 return 0;
103515 }
103516 @@ -337,7 +337,7 @@ static int isight_hw_free(struct snd_pcm_substream *substream)
103517 {
103518 struct isight *isight = substream->private_data;
103519
103520 - ACCESS_ONCE(isight->pcm_active) = false;
103521 + ACCESS_ONCE_RW(isight->pcm_active) = false;
103522
103523 mutex_lock(&isight->mutex);
103524 isight_stop_streaming(isight);
103525 @@ -430,10 +430,10 @@ static int isight_trigger(struct snd_pcm_substream *substream, int cmd)
103526
103527 switch (cmd) {
103528 case SNDRV_PCM_TRIGGER_START:
103529 - ACCESS_ONCE(isight->pcm_running) = true;
103530 + ACCESS_ONCE_RW(isight->pcm_running) = true;
103531 break;
103532 case SNDRV_PCM_TRIGGER_STOP:
103533 - ACCESS_ONCE(isight->pcm_running) = false;
103534 + ACCESS_ONCE_RW(isight->pcm_running) = false;
103535 break;
103536 default:
103537 return -EINVAL;
103538 diff --git a/sound/firewire/scs1x.c b/sound/firewire/scs1x.c
103539 index 858023c..83b3d3c 100644
103540 --- a/sound/firewire/scs1x.c
103541 +++ b/sound/firewire/scs1x.c
103542 @@ -74,7 +74,7 @@ static void scs_output_trigger(struct snd_rawmidi_substream *stream, int up)
103543 {
103544 struct scs *scs = stream->rmidi->private_data;
103545
103546 - ACCESS_ONCE(scs->output) = up ? stream : NULL;
103547 + ACCESS_ONCE_RW(scs->output) = up ? stream : NULL;
103548 if (up) {
103549 scs->output_idle = false;
103550 tasklet_schedule(&scs->tasklet);
103551 @@ -257,7 +257,7 @@ static void scs_input_trigger(struct snd_rawmidi_substream *stream, int up)
103552 {
103553 struct scs *scs = stream->rmidi->private_data;
103554
103555 - ACCESS_ONCE(scs->input) = up ? stream : NULL;
103556 + ACCESS_ONCE_RW(scs->input) = up ? stream : NULL;
103557 }
103558
103559 static void scs_input_escaped_byte(struct snd_rawmidi_substream *stream,
103560 @@ -473,8 +473,8 @@ static void scs_remove(struct fw_unit *unit)
103561
103562 snd_card_disconnect(scs->card);
103563
103564 - ACCESS_ONCE(scs->output) = NULL;
103565 - ACCESS_ONCE(scs->input) = NULL;
103566 + ACCESS_ONCE_RW(scs->output) = NULL;
103567 + ACCESS_ONCE_RW(scs->input) = NULL;
103568
103569 wait_event(scs->idle_wait, scs->output_idle);
103570
103571 diff --git a/sound/isa/sb/emu8000_synth.c b/sound/isa/sb/emu8000_synth.c
103572 index 4e3fcfb..ab45a9d 100644
103573 --- a/sound/isa/sb/emu8000_synth.c
103574 +++ b/sound/isa/sb/emu8000_synth.c
103575 @@ -120,8 +120,8 @@ static int __init alsa_emu8000_init(void)
103576 {
103577
103578 static struct snd_seq_dev_ops ops = {
103579 - snd_emu8000_new_device,
103580 - snd_emu8000_delete_device,
103581 + .init_device = snd_emu8000_new_device,
103582 + .free_device = snd_emu8000_delete_device,
103583 };
103584 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU8000, &ops,
103585 sizeof(struct snd_emu8000*));
103586 diff --git a/sound/oss/sb_audio.c b/sound/oss/sb_audio.c
103587 index 048439a..3be9f6f 100644
103588 --- a/sound/oss/sb_audio.c
103589 +++ b/sound/oss/sb_audio.c
103590 @@ -904,7 +904,7 @@ sb16_copy_from_user(int dev,
103591 buf16 = (signed short *)(localbuf + localoffs);
103592 while (c)
103593 {
103594 - locallen = (c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
103595 + locallen = ((unsigned)c >= LBUFCOPYSIZE ? LBUFCOPYSIZE : c);
103596 if (copy_from_user(lbuf8,
103597 userbuf+useroffs + p,
103598 locallen))
103599 diff --git a/sound/oss/swarm_cs4297a.c b/sound/oss/swarm_cs4297a.c
103600 index 7d8803a..559f8d0 100644
103601 --- a/sound/oss/swarm_cs4297a.c
103602 +++ b/sound/oss/swarm_cs4297a.c
103603 @@ -2621,7 +2621,6 @@ static int __init cs4297a_init(void)
103604 {
103605 struct cs4297a_state *s;
103606 u32 pwr, id;
103607 - mm_segment_t fs;
103608 int rval;
103609 #ifndef CONFIG_BCM_CS4297A_CSWARM
103610 u64 cfg;
103611 @@ -2711,22 +2710,23 @@ static int __init cs4297a_init(void)
103612 if (!rval) {
103613 char *sb1250_duart_present;
103614
103615 +#if 0
103616 + mm_segment_t fs;
103617 fs = get_fs();
103618 set_fs(KERNEL_DS);
103619 -#if 0
103620 val = SOUND_MASK_LINE;
103621 mixer_ioctl(s, SOUND_MIXER_WRITE_RECSRC, (unsigned long) &val);
103622 for (i = 0; i < ARRAY_SIZE(initvol); i++) {
103623 val = initvol[i].vol;
103624 mixer_ioctl(s, initvol[i].mixch, (unsigned long) &val);
103625 }
103626 + set_fs(fs);
103627 // cs4297a_write_ac97(s, 0x18, 0x0808);
103628 #else
103629 // cs4297a_write_ac97(s, 0x5e, 0x180);
103630 cs4297a_write_ac97(s, 0x02, 0x0808);
103631 cs4297a_write_ac97(s, 0x18, 0x0808);
103632 #endif
103633 - set_fs(fs);
103634
103635 list_add(&s->list, &cs4297a_devs);
103636
103637 diff --git a/sound/pci/emu10k1/emu10k1_synth.c b/sound/pci/emu10k1/emu10k1_synth.c
103638 index 4c41c90..37f3631 100644
103639 --- a/sound/pci/emu10k1/emu10k1_synth.c
103640 +++ b/sound/pci/emu10k1/emu10k1_synth.c
103641 @@ -108,8 +108,8 @@ static int __init alsa_emu10k1_synth_init(void)
103642 {
103643
103644 static struct snd_seq_dev_ops ops = {
103645 - snd_emu10k1_synth_new_device,
103646 - snd_emu10k1_synth_delete_device,
103647 + .init_device = snd_emu10k1_synth_new_device,
103648 + .free_device = snd_emu10k1_synth_delete_device,
103649 };
103650 return snd_seq_device_register_driver(SNDRV_SEQ_DEV_ID_EMU10K1_SYNTH, &ops,
103651 sizeof(struct snd_emu10k1_synth_arg));
103652 diff --git a/sound/pci/hda/hda_codec.c b/sound/pci/hda/hda_codec.c
103653 index 69178c4..4493d52 100644
103654 --- a/sound/pci/hda/hda_codec.c
103655 +++ b/sound/pci/hda/hda_codec.c
103656 @@ -976,14 +976,10 @@ find_codec_preset(struct hda_codec *codec)
103657 mutex_unlock(&preset_mutex);
103658
103659 if (mod_requested < HDA_MODREQ_MAX_COUNT) {
103660 - char name[32];
103661 if (!mod_requested)
103662 - snprintf(name, sizeof(name), "snd-hda-codec-id:%08x",
103663 - codec->vendor_id);
103664 + request_module("snd-hda-codec-id:%08x", codec->vendor_id);
103665 else
103666 - snprintf(name, sizeof(name), "snd-hda-codec-id:%04x*",
103667 - (codec->vendor_id >> 16) & 0xffff);
103668 - request_module(name);
103669 + request_module("snd-hda-codec-id:%04x*", (codec->vendor_id >> 16) & 0xffff);
103670 mod_requested++;
103671 goto again;
103672 }
103673 @@ -2668,7 +2664,7 @@ static int get_kctl_0dB_offset(struct snd_kcontrol *kctl, int *step_to_check)
103674 /* FIXME: set_fs() hack for obtaining user-space TLV data */
103675 mm_segment_t fs = get_fs();
103676 set_fs(get_ds());
103677 - if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), _tlv))
103678 + if (!kctl->tlv.c(kctl, 0, sizeof(_tlv), (unsigned int __force_user *)_tlv))
103679 tlv = _tlv;
103680 set_fs(fs);
103681 } else if (kctl->vd[0].access & SNDRV_CTL_ELEM_ACCESS_TLV_READ)
103682 diff --git a/sound/pci/ymfpci/ymfpci.h b/sound/pci/ymfpci/ymfpci.h
103683 index 4631a23..001ae57 100644
103684 --- a/sound/pci/ymfpci/ymfpci.h
103685 +++ b/sound/pci/ymfpci/ymfpci.h
103686 @@ -358,7 +358,7 @@ struct snd_ymfpci {
103687 spinlock_t reg_lock;
103688 spinlock_t voice_lock;
103689 wait_queue_head_t interrupt_sleep;
103690 - atomic_t interrupt_sleep_count;
103691 + atomic_unchecked_t interrupt_sleep_count;
103692 struct snd_info_entry *proc_entry;
103693 const struct firmware *dsp_microcode;
103694 const struct firmware *controller_microcode;
103695 diff --git a/sound/pci/ymfpci/ymfpci_main.c b/sound/pci/ymfpci/ymfpci_main.c
103696 index d591c15..8cb8f94 100644
103697 --- a/sound/pci/ymfpci/ymfpci_main.c
103698 +++ b/sound/pci/ymfpci/ymfpci_main.c
103699 @@ -202,8 +202,8 @@ static void snd_ymfpci_hw_stop(struct snd_ymfpci *chip)
103700 if ((snd_ymfpci_readl(chip, YDSXGR_STATUS) & 2) == 0)
103701 break;
103702 }
103703 - if (atomic_read(&chip->interrupt_sleep_count)) {
103704 - atomic_set(&chip->interrupt_sleep_count, 0);
103705 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
103706 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
103707 wake_up(&chip->interrupt_sleep);
103708 }
103709 __end:
103710 @@ -787,7 +787,7 @@ static void snd_ymfpci_irq_wait(struct snd_ymfpci *chip)
103711 continue;
103712 init_waitqueue_entry(&wait, current);
103713 add_wait_queue(&chip->interrupt_sleep, &wait);
103714 - atomic_inc(&chip->interrupt_sleep_count);
103715 + atomic_inc_unchecked(&chip->interrupt_sleep_count);
103716 schedule_timeout_uninterruptible(msecs_to_jiffies(50));
103717 remove_wait_queue(&chip->interrupt_sleep, &wait);
103718 }
103719 @@ -825,8 +825,8 @@ static irqreturn_t snd_ymfpci_interrupt(int irq, void *dev_id)
103720 snd_ymfpci_writel(chip, YDSXGR_MODE, mode);
103721 spin_unlock(&chip->reg_lock);
103722
103723 - if (atomic_read(&chip->interrupt_sleep_count)) {
103724 - atomic_set(&chip->interrupt_sleep_count, 0);
103725 + if (atomic_read_unchecked(&chip->interrupt_sleep_count)) {
103726 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
103727 wake_up(&chip->interrupt_sleep);
103728 }
103729 }
103730 @@ -2421,7 +2421,7 @@ int snd_ymfpci_create(struct snd_card *card,
103731 spin_lock_init(&chip->reg_lock);
103732 spin_lock_init(&chip->voice_lock);
103733 init_waitqueue_head(&chip->interrupt_sleep);
103734 - atomic_set(&chip->interrupt_sleep_count, 0);
103735 + atomic_set_unchecked(&chip->interrupt_sleep_count, 0);
103736 chip->card = card;
103737 chip->pci = pci;
103738 chip->irq = -1;
103739 diff --git a/sound/soc/fsl/fsl_ssi.c b/sound/soc/fsl/fsl_ssi.c
103740 index 35e2773..6d6ceee 100644
103741 --- a/sound/soc/fsl/fsl_ssi.c
103742 +++ b/sound/soc/fsl/fsl_ssi.c
103743 @@ -857,7 +857,7 @@ static int fsl_ssi_probe(struct platform_device *pdev)
103744 {
103745 struct fsl_ssi_private *ssi_private;
103746 int ret = 0;
103747 - struct device_attribute *dev_attr = NULL;
103748 + device_attribute_no_const *dev_attr = NULL;
103749 struct device_node *np = pdev->dev.of_node;
103750 const char *p, *sprop;
103751 const uint32_t *iprop;
103752 diff --git a/sound/soc/soc-core.c b/sound/soc/soc-core.c
103753 index a66783e..ed1d791 100644
103754 --- a/sound/soc/soc-core.c
103755 +++ b/sound/soc/soc-core.c
103756 @@ -2253,8 +2253,10 @@ int snd_soc_set_ac97_ops_of_reset(struct snd_ac97_bus_ops *ops,
103757 if (ret)
103758 return ret;
103759
103760 - ops->warm_reset = snd_soc_ac97_warm_reset;
103761 - ops->reset = snd_soc_ac97_reset;
103762 + pax_open_kernel();
103763 + *(void **)&ops->warm_reset = snd_soc_ac97_warm_reset;
103764 + *(void **)&ops->reset = snd_soc_ac97_reset;
103765 + pax_close_kernel();
103766
103767 snd_ac97_rst_cfg = cfg;
103768 return 0;
103769 diff --git a/sound/synth/emux/emux_seq.c b/sound/synth/emux/emux_seq.c
103770 index 7778b8e..3d619fc 100644
103771 --- a/sound/synth/emux/emux_seq.c
103772 +++ b/sound/synth/emux/emux_seq.c
103773 @@ -33,13 +33,13 @@ static int snd_emux_unuse(void *private_data, struct snd_seq_port_subscribe *inf
103774 * MIDI emulation operators
103775 */
103776 static struct snd_midi_op emux_ops = {
103777 - snd_emux_note_on,
103778 - snd_emux_note_off,
103779 - snd_emux_key_press,
103780 - snd_emux_terminate_note,
103781 - snd_emux_control,
103782 - snd_emux_nrpn,
103783 - snd_emux_sysex,
103784 + .note_on = snd_emux_note_on,
103785 + .note_off = snd_emux_note_off,
103786 + .key_press = snd_emux_key_press,
103787 + .note_terminate = snd_emux_terminate_note,
103788 + .control = snd_emux_control,
103789 + .nrpn = snd_emux_nrpn,
103790 + .sysex = snd_emux_sysex,
103791 };
103792
103793
103794 diff --git a/tools/gcc/.gitignore b/tools/gcc/.gitignore
103795 new file mode 100644
103796 index 0000000..4c2c45c
103797 --- /dev/null
103798 +++ b/tools/gcc/.gitignore
103799 @@ -0,0 +1,2 @@
103800 +randomize_layout_seed.h
103801 +size_overflow_hash.h
103802 diff --git a/tools/gcc/Makefile b/tools/gcc/Makefile
103803 new file mode 100644
103804 index 0000000..b198b6d
103805 --- /dev/null
103806 +++ b/tools/gcc/Makefile
103807 @@ -0,0 +1,54 @@
103808 +#CC := gcc
103809 +#PLUGIN_SOURCE_FILES := pax_plugin.c
103810 +#PLUGIN_OBJECT_FILES := $(patsubst %.c,%.o,$(PLUGIN_SOURCE_FILES))
103811 +GCCPLUGINS_DIR := $(shell $(CC) -print-file-name=plugin)
103812 +#CFLAGS += -I$(GCCPLUGINS_DIR)/include -fPIC -O2 -Wall -W -std=gnu99
103813 +
103814 +ifeq ($(PLUGINCC),$(HOSTCC))
103815 +HOSTLIBS := hostlibs
103816 +HOST_EXTRACFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu99 -ggdb
103817 +else
103818 +HOSTLIBS := hostcxxlibs
103819 +HOST_EXTRACXXFLAGS += -I$(GCCPLUGINS_DIR)/include -std=gnu++98 -fno-rtti -ggdb -Wno-unused-parameter -Wno-narrowing
103820 +endif
103821 +
103822 +$(HOSTLIBS)-$(CONFIG_PAX_CONSTIFY_PLUGIN) := constify_plugin.so
103823 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STACKLEAK) += stackleak_plugin.so
103824 +$(HOSTLIBS)-$(CONFIG_KALLOCSTAT_PLUGIN) += kallocstat_plugin.so
103825 +$(HOSTLIBS)-$(CONFIG_PAX_KERNEXEC_PLUGIN) += kernexec_plugin.so
103826 +$(HOSTLIBS)-$(CONFIG_CHECKER_PLUGIN) += checker_plugin.so
103827 +$(HOSTLIBS)-y += colorize_plugin.so
103828 +$(HOSTLIBS)-$(CONFIG_PAX_SIZE_OVERFLOW) += size_overflow_plugin.so
103829 +$(HOSTLIBS)-$(CONFIG_PAX_LATENT_ENTROPY) += latent_entropy_plugin.so
103830 +$(HOSTLIBS)-$(CONFIG_PAX_MEMORY_STRUCTLEAK) += structleak_plugin.so
103831 +$(HOSTLIBS)-$(CONFIG_GRKERNSEC_RANDSTRUCT) += randomize_layout_plugin.so
103832 +
103833 +always := $($(HOSTLIBS)-y)
103834 +
103835 +constify_plugin-objs := constify_plugin.o
103836 +stackleak_plugin-objs := stackleak_plugin.o
103837 +kallocstat_plugin-objs := kallocstat_plugin.o
103838 +kernexec_plugin-objs := kernexec_plugin.o
103839 +checker_plugin-objs := checker_plugin.o
103840 +colorize_plugin-objs := colorize_plugin.o
103841 +size_overflow_plugin-objs := size_overflow_plugin.o
103842 +latent_entropy_plugin-objs := latent_entropy_plugin.o
103843 +structleak_plugin-objs := structleak_plugin.o
103844 +randomize_layout_plugin-objs := randomize_layout_plugin.o
103845 +
103846 +$(obj)/size_overflow_plugin.o: $(objtree)/$(obj)/size_overflow_hash.h
103847 +$(obj)/randomize_layout_plugin.o: $(objtree)/$(obj)/randomize_layout_seed.h
103848 +
103849 +quiet_cmd_build_size_overflow_hash = GENHASH $@
103850 + cmd_build_size_overflow_hash = \
103851 + $(CONFIG_SHELL) $(srctree)/$(src)/generate_size_overflow_hash.sh -d $< -o $@
103852 +$(objtree)/$(obj)/size_overflow_hash.h: $(src)/size_overflow_hash.data FORCE
103853 + $(call if_changed,build_size_overflow_hash)
103854 +
103855 +quiet_cmd_create_randomize_layout_seed = GENSEED $@
103856 + cmd_create_randomize_layout_seed = \
103857 + $(CONFIG_SHELL) $(srctree)/$(src)/gen-random-seed.sh $@ $(objtree)/include/generated/randomize_layout_hash.h
103858 +$(objtree)/$(obj)/randomize_layout_seed.h: FORCE
103859 + $(call if_changed,create_randomize_layout_seed)
103860 +
103861 +targets += size_overflow_hash.h randomize_layout_seed.h randomize_layout_hash.h
103862 diff --git a/tools/gcc/checker_plugin.c b/tools/gcc/checker_plugin.c
103863 new file mode 100644
103864 index 0000000..5452feea
103865 --- /dev/null
103866 +++ b/tools/gcc/checker_plugin.c
103867 @@ -0,0 +1,150 @@
103868 +/*
103869 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
103870 + * Licensed under the GPL v2
103871 + *
103872 + * Note: the choice of the license means that the compilation process is
103873 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
103874 + * but for the kernel it doesn't matter since it doesn't link against
103875 + * any of the gcc libraries
103876 + *
103877 + * gcc plugin to implement various sparse (source code checker) features
103878 + *
103879 + * TODO:
103880 + * - define separate __iomem, __percpu and __rcu address spaces (lots of code to patch)
103881 + *
103882 + * BUGS:
103883 + * - none known
103884 + */
103885 +
103886 +#include "gcc-common.h"
103887 +
103888 +extern void c_register_addr_space (const char *str, addr_space_t as);
103889 +extern enum machine_mode default_addr_space_pointer_mode (addr_space_t);
103890 +extern enum machine_mode default_addr_space_address_mode (addr_space_t);
103891 +extern bool default_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as);
103892 +extern bool default_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as);
103893 +extern rtx default_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as);
103894 +
103895 +int plugin_is_GPL_compatible;
103896 +
103897 +static struct plugin_info checker_plugin_info = {
103898 + .version = "201304082245",
103899 + .help = NULL,
103900 +};
103901 +
103902 +#define ADDR_SPACE_KERNEL 0
103903 +#define ADDR_SPACE_FORCE_KERNEL 1
103904 +#define ADDR_SPACE_USER 2
103905 +#define ADDR_SPACE_FORCE_USER 3
103906 +#define ADDR_SPACE_IOMEM 0
103907 +#define ADDR_SPACE_FORCE_IOMEM 0
103908 +#define ADDR_SPACE_PERCPU 0
103909 +#define ADDR_SPACE_FORCE_PERCPU 0
103910 +#define ADDR_SPACE_RCU 0
103911 +#define ADDR_SPACE_FORCE_RCU 0
103912 +
103913 +static enum machine_mode checker_addr_space_pointer_mode(addr_space_t addrspace)
103914 +{
103915 + return default_addr_space_pointer_mode(ADDR_SPACE_GENERIC);
103916 +}
103917 +
103918 +static enum machine_mode checker_addr_space_address_mode(addr_space_t addrspace)
103919 +{
103920 + return default_addr_space_address_mode(ADDR_SPACE_GENERIC);
103921 +}
103922 +
103923 +static bool checker_addr_space_valid_pointer_mode(enum machine_mode mode, addr_space_t as)
103924 +{
103925 + return default_addr_space_valid_pointer_mode(mode, as);
103926 +}
103927 +
103928 +static bool checker_addr_space_legitimate_address_p(enum machine_mode mode, rtx mem, bool strict, addr_space_t as)
103929 +{
103930 + return default_addr_space_legitimate_address_p(mode, mem, strict, ADDR_SPACE_GENERIC);
103931 +}
103932 +
103933 +static rtx checker_addr_space_legitimize_address(rtx x, rtx oldx, enum machine_mode mode, addr_space_t as)
103934 +{
103935 + return default_addr_space_legitimize_address(x, oldx, mode, as);
103936 +}
103937 +
103938 +static bool checker_addr_space_subset_p(addr_space_t subset, addr_space_t superset)
103939 +{
103940 + if (subset == ADDR_SPACE_FORCE_KERNEL && superset == ADDR_SPACE_KERNEL)
103941 + return true;
103942 +
103943 + if (subset == ADDR_SPACE_FORCE_USER && superset == ADDR_SPACE_USER)
103944 + return true;
103945 +
103946 + if (subset == ADDR_SPACE_FORCE_IOMEM && superset == ADDR_SPACE_IOMEM)
103947 + return true;
103948 +
103949 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_USER)
103950 + return true;
103951 +
103952 + if (subset == ADDR_SPACE_KERNEL && superset == ADDR_SPACE_FORCE_IOMEM)
103953 + return true;
103954 +
103955 + if (subset == ADDR_SPACE_USER && superset == ADDR_SPACE_FORCE_KERNEL)
103956 + return true;
103957 +
103958 + if (subset == ADDR_SPACE_IOMEM && superset == ADDR_SPACE_FORCE_KERNEL)
103959 + return true;
103960 +
103961 + return subset == superset;
103962 +}
103963 +
103964 +static rtx checker_addr_space_convert(rtx op, tree from_type, tree to_type)
103965 +{
103966 +// addr_space_t from_as = TYPE_ADDR_SPACE(TREE_TYPE(from_type));
103967 +// addr_space_t to_as = TYPE_ADDR_SPACE(TREE_TYPE(to_type));
103968 +
103969 + return op;
103970 +}
103971 +
103972 +static void register_checker_address_spaces(void *event_data, void *data)
103973 +{
103974 + c_register_addr_space("__kernel", ADDR_SPACE_KERNEL);
103975 + c_register_addr_space("__force_kernel", ADDR_SPACE_FORCE_KERNEL);
103976 + c_register_addr_space("__user", ADDR_SPACE_USER);
103977 + c_register_addr_space("__force_user", ADDR_SPACE_FORCE_USER);
103978 +// c_register_addr_space("__iomem", ADDR_SPACE_IOMEM);
103979 +// c_register_addr_space("__force_iomem", ADDR_SPACE_FORCE_IOMEM);
103980 +// c_register_addr_space("__percpu", ADDR_SPACE_PERCPU);
103981 +// c_register_addr_space("__force_percpu", ADDR_SPACE_FORCE_PERCPU);
103982 +// c_register_addr_space("__rcu", ADDR_SPACE_RCU);
103983 +// c_register_addr_space("__force_rcu", ADDR_SPACE_FORCE_RCU);
103984 +
103985 + targetm.addr_space.pointer_mode = checker_addr_space_pointer_mode;
103986 + targetm.addr_space.address_mode = checker_addr_space_address_mode;
103987 + targetm.addr_space.valid_pointer_mode = checker_addr_space_valid_pointer_mode;
103988 + targetm.addr_space.legitimate_address_p = checker_addr_space_legitimate_address_p;
103989 +// targetm.addr_space.legitimize_address = checker_addr_space_legitimize_address;
103990 + targetm.addr_space.subset_p = checker_addr_space_subset_p;
103991 + targetm.addr_space.convert = checker_addr_space_convert;
103992 +}
103993 +
103994 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
103995 +{
103996 + const char * const plugin_name = plugin_info->base_name;
103997 + const int argc = plugin_info->argc;
103998 + const struct plugin_argument * const argv = plugin_info->argv;
103999 + int i;
104000 +
104001 + if (!plugin_default_version_check(version, &gcc_version)) {
104002 + error(G_("incompatible gcc/plugin versions"));
104003 + return 1;
104004 + }
104005 +
104006 + register_callback(plugin_name, PLUGIN_INFO, NULL, &checker_plugin_info);
104007 +
104008 + for (i = 0; i < argc; ++i)
104009 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
104010 +
104011 + if (TARGET_64BIT == 0)
104012 + return 0;
104013 +
104014 + register_callback(plugin_name, PLUGIN_PRAGMAS, register_checker_address_spaces, NULL);
104015 +
104016 + return 0;
104017 +}
104018 diff --git a/tools/gcc/colorize_plugin.c b/tools/gcc/colorize_plugin.c
104019 new file mode 100644
104020 index 0000000..06dcfda
104021 --- /dev/null
104022 +++ b/tools/gcc/colorize_plugin.c
104023 @@ -0,0 +1,169 @@
104024 +/*
104025 + * Copyright 2012-2014 by PaX Team <pageexec@freemail.hu>
104026 + * Licensed under the GPL v2
104027 + *
104028 + * Note: the choice of the license means that the compilation process is
104029 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
104030 + * but for the kernel it doesn't matter since it doesn't link against
104031 + * any of the gcc libraries
104032 + *
104033 + * gcc plugin to colorize diagnostic output
104034 + *
104035 + */
104036 +
104037 +#include "gcc-common.h"
104038 +
104039 +int plugin_is_GPL_compatible;
104040 +
104041 +static struct plugin_info colorize_plugin_info = {
104042 + .version = "201401260140",
104043 + .help = NULL,
104044 +};
104045 +
104046 +#define GREEN "\033[32m\033[2m"
104047 +#define LIGHTGREEN "\033[32m\033[1m"
104048 +#define YELLOW "\033[33m\033[2m"
104049 +#define LIGHTYELLOW "\033[33m\033[1m"
104050 +#define RED "\033[31m\033[2m"
104051 +#define LIGHTRED "\033[31m\033[1m"
104052 +#define BLUE "\033[34m\033[2m"
104053 +#define LIGHTBLUE "\033[34m\033[1m"
104054 +#define BRIGHT "\033[m\033[1m"
104055 +#define NORMAL "\033[m"
104056 +
104057 +static diagnostic_starter_fn old_starter;
104058 +static diagnostic_finalizer_fn old_finalizer;
104059 +
104060 +static void start_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
104061 +{
104062 + const char *color;
104063 + char *newprefix;
104064 +
104065 + switch (diagnostic->kind) {
104066 + case DK_NOTE:
104067 + color = LIGHTBLUE;
104068 + break;
104069 +
104070 + case DK_PEDWARN:
104071 + case DK_WARNING:
104072 + color = LIGHTYELLOW;
104073 + break;
104074 +
104075 + case DK_ERROR:
104076 + case DK_FATAL:
104077 + case DK_ICE:
104078 + case DK_PERMERROR:
104079 + case DK_SORRY:
104080 + color = LIGHTRED;
104081 + break;
104082 +
104083 + default:
104084 + color = NORMAL;
104085 + }
104086 +
104087 + old_starter(context, diagnostic);
104088 + if (-1 == asprintf(&newprefix, "%s%s" NORMAL, color, context->printer->prefix))
104089 + return;
104090 + pp_destroy_prefix(context->printer);
104091 + pp_set_prefix(context->printer, newprefix);
104092 +}
104093 +
104094 +static void finalize_colorize(diagnostic_context *context, diagnostic_info *diagnostic)
104095 +{
104096 + old_finalizer(context, diagnostic);
104097 +}
104098 +
104099 +static void colorize_arm(void)
104100 +{
104101 + old_starter = diagnostic_starter(global_dc);
104102 + old_finalizer = diagnostic_finalizer(global_dc);
104103 +
104104 + diagnostic_starter(global_dc) = start_colorize;
104105 + diagnostic_finalizer(global_dc) = finalize_colorize;
104106 +}
104107 +
104108 +static unsigned int execute_colorize_rearm(void)
104109 +{
104110 + if (diagnostic_starter(global_dc) == start_colorize)
104111 + return 0;
104112 +
104113 + colorize_arm();
104114 + return 0;
104115 +}
104116 +
104117 +#if BUILDING_GCC_VERSION >= 4009
104118 +static const struct pass_data colorize_rearm_pass_data = {
104119 +#else
104120 +struct simple_ipa_opt_pass colorize_rearm_pass = {
104121 + .pass = {
104122 +#endif
104123 + .type = SIMPLE_IPA_PASS,
104124 + .name = "colorize_rearm",
104125 +#if BUILDING_GCC_VERSION >= 4008
104126 + .optinfo_flags = OPTGROUP_NONE,
104127 +#endif
104128 +#if BUILDING_GCC_VERSION >= 4009
104129 + .has_gate = false,
104130 + .has_execute = true,
104131 +#else
104132 + .gate = NULL,
104133 + .execute = execute_colorize_rearm,
104134 + .sub = NULL,
104135 + .next = NULL,
104136 + .static_pass_number = 0,
104137 +#endif
104138 + .tv_id = TV_NONE,
104139 + .properties_required = 0,
104140 + .properties_provided = 0,
104141 + .properties_destroyed = 0,
104142 + .todo_flags_start = 0,
104143 + .todo_flags_finish = 0
104144 +#if BUILDING_GCC_VERSION < 4009
104145 + }
104146 +#endif
104147 +};
104148 +
104149 +#if BUILDING_GCC_VERSION >= 4009
104150 +namespace {
104151 +class colorize_rearm_pass : public simple_ipa_opt_pass {
104152 +public:
104153 + colorize_rearm_pass() : simple_ipa_opt_pass(colorize_rearm_pass_data, g) {}
104154 + unsigned int execute() { return execute_colorize_rearm(); }
104155 +};
104156 +}
104157 +#endif
104158 +
104159 +static struct opt_pass *make_colorize_rearm_pass(void)
104160 +{
104161 +#if BUILDING_GCC_VERSION >= 4009
104162 + return new colorize_rearm_pass();
104163 +#else
104164 + return &colorize_rearm_pass.pass;
104165 +#endif
104166 +}
104167 +
104168 +static void colorize_start_unit(void *gcc_data, void *user_data)
104169 +{
104170 + colorize_arm();
104171 +}
104172 +
104173 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
104174 +{
104175 + const char * const plugin_name = plugin_info->base_name;
104176 + struct register_pass_info colorize_rearm_pass_info;
104177 +
104178 + colorize_rearm_pass_info.pass = make_colorize_rearm_pass();
104179 + colorize_rearm_pass_info.reference_pass_name = "*free_lang_data";
104180 + colorize_rearm_pass_info.ref_pass_instance_number = 1;
104181 + colorize_rearm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
104182 +
104183 + if (!plugin_default_version_check(version, &gcc_version)) {
104184 + error(G_("incompatible gcc/plugin versions"));
104185 + return 1;
104186 + }
104187 +
104188 + register_callback(plugin_name, PLUGIN_INFO, NULL, &colorize_plugin_info);
104189 + register_callback(plugin_name, PLUGIN_START_UNIT, &colorize_start_unit, NULL);
104190 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &colorize_rearm_pass_info);
104191 + return 0;
104192 +}
104193 diff --git a/tools/gcc/constify_plugin.c b/tools/gcc/constify_plugin.c
104194 new file mode 100644
104195 index 0000000..4f67ac1
104196 --- /dev/null
104197 +++ b/tools/gcc/constify_plugin.c
104198 @@ -0,0 +1,552 @@
104199 +/*
104200 + * Copyright 2011 by Emese Revfy <re.emese@gmail.com>
104201 + * Copyright 2011-2014 by PaX Team <pageexec@freemail.hu>
104202 + * Licensed under the GPL v2, or (at your option) v3
104203 + *
104204 + * This gcc plugin constifies all structures which contain only function pointers or are explicitly marked for constification.
104205 + *
104206 + * Homepage:
104207 + * http://www.grsecurity.net/~ephox/const_plugin/
104208 + *
104209 + * Usage:
104210 + * $ gcc -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -o constify_plugin.so constify_plugin.c
104211 + * $ gcc -fplugin=constify_plugin.so test.c -O2
104212 + */
104213 +
104214 +#include "gcc-common.h"
104215 +
104216 +// unused C type flag in all versions 4.5-4.9
104217 +#define TYPE_CONSTIFY_VISITED(TYPE) TYPE_LANG_FLAG_4(TYPE)
104218 +
104219 +int plugin_is_GPL_compatible;
104220 +
104221 +static struct plugin_info const_plugin_info = {
104222 + .version = "201401270210",
104223 + .help = "no-constify\tturn off constification\n",
104224 +};
104225 +
104226 +typedef struct {
104227 + bool has_fptr_field;
104228 + bool has_writable_field;
104229 + bool has_do_const_field;
104230 + bool has_no_const_field;
104231 +} constify_info;
104232 +
104233 +static const_tree get_field_type(const_tree field)
104234 +{
104235 + return strip_array_types(TREE_TYPE(field));
104236 +}
104237 +
104238 +static bool is_fptr(const_tree field)
104239 +{
104240 + const_tree ptr = get_field_type(field);
104241 +
104242 + if (TREE_CODE(ptr) != POINTER_TYPE)
104243 + return false;
104244 +
104245 + return TREE_CODE(TREE_TYPE(ptr)) == FUNCTION_TYPE;
104246 +}
104247 +
104248 +/*
104249 + * determine whether the given structure type meets the requirements for automatic constification,
104250 + * including the constification attributes on nested structure types
104251 + */
104252 +static void constifiable(const_tree node, constify_info *cinfo)
104253 +{
104254 + const_tree field;
104255 +
104256 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
104257 +
104258 + // e.g., pointer to structure fields while still constructing the structure type
104259 + if (TYPE_FIELDS(node) == NULL_TREE)
104260 + return;
104261 +
104262 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
104263 + const_tree type = get_field_type(field);
104264 + enum tree_code code = TREE_CODE(type);
104265 +
104266 + if (node == type)
104267 + continue;
104268 +
104269 + if (is_fptr(field))
104270 + cinfo->has_fptr_field = true;
104271 + else if (!TREE_READONLY(field))
104272 + cinfo->has_writable_field = true;
104273 +
104274 + if (code == RECORD_TYPE || code == UNION_TYPE) {
104275 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
104276 + cinfo->has_do_const_field = true;
104277 + else if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type)))
104278 + cinfo->has_no_const_field = true;
104279 + else
104280 + constifiable(type, cinfo);
104281 + }
104282 + }
104283 +}
104284 +
104285 +static bool constified(const_tree node)
104286 +{
104287 + constify_info cinfo = {
104288 + .has_fptr_field = false,
104289 + .has_writable_field = false,
104290 + .has_do_const_field = false,
104291 + .has_no_const_field = false
104292 + };
104293 +
104294 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
104295 +
104296 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(node))) {
104297 +// gcc_assert(!TYPE_READONLY(node));
104298 + return false;
104299 + }
104300 +
104301 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(node))) {
104302 + gcc_assert(TYPE_READONLY(node));
104303 + return true;
104304 + }
104305 +
104306 + constifiable(node, &cinfo);
104307 + if ((!cinfo.has_fptr_field || cinfo.has_writable_field) && !cinfo.has_do_const_field)
104308 + return false;
104309 +
104310 + return TYPE_READONLY(node);
104311 +}
104312 +
104313 +static void deconstify_tree(tree node);
104314 +
104315 +static void deconstify_type(tree type)
104316 +{
104317 + tree field;
104318 +
104319 + gcc_assert(TREE_CODE(type) == RECORD_TYPE || TREE_CODE(type) == UNION_TYPE);
104320 +
104321 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
104322 + const_tree fieldtype = get_field_type(field);
104323 +
104324 + // special case handling of simple ptr-to-same-array-type members
104325 + if (TREE_CODE(TREE_TYPE(field)) == POINTER_TYPE) {
104326 + tree ptrtype = TREE_TYPE(TREE_TYPE(field));
104327 +
104328 + if (TREE_TYPE(TREE_TYPE(field)) == type)
104329 + continue;
104330 + if (TREE_CODE(ptrtype) != RECORD_TYPE && TREE_CODE(ptrtype) != UNION_TYPE)
104331 + continue;
104332 + if (!constified(ptrtype))
104333 + continue;
104334 + if (TYPE_MAIN_VARIANT(ptrtype) == TYPE_MAIN_VARIANT(type)) {
104335 + TREE_TYPE(field) = copy_node(TREE_TYPE(field));
104336 + TREE_TYPE(TREE_TYPE(field)) = build_qualified_type(type, TYPE_QUALS(ptrtype) & ~TYPE_QUAL_CONST);
104337 + }
104338 + continue;
104339 + }
104340 + if (TREE_CODE(fieldtype) != RECORD_TYPE && TREE_CODE(fieldtype) != UNION_TYPE)
104341 + continue;
104342 + if (!constified(fieldtype))
104343 + continue;
104344 +
104345 + deconstify_tree(field);
104346 + TREE_READONLY(field) = 0;
104347 + }
104348 + TYPE_READONLY(type) = 0;
104349 + C_TYPE_FIELDS_READONLY(type) = 0;
104350 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
104351 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
104352 + TYPE_ATTRIBUTES(type) = remove_attribute("do_const", TYPE_ATTRIBUTES(type));
104353 + }
104354 +}
104355 +
104356 +static void deconstify_tree(tree node)
104357 +{
104358 + tree old_type, new_type, field;
104359 +
104360 + old_type = TREE_TYPE(node);
104361 + while (TREE_CODE(old_type) == ARRAY_TYPE && TREE_CODE(TREE_TYPE(old_type)) != ARRAY_TYPE) {
104362 + node = TREE_TYPE(node) = copy_node(old_type);
104363 + old_type = TREE_TYPE(old_type);
104364 + }
104365 +
104366 + gcc_assert(TREE_CODE(old_type) == RECORD_TYPE || TREE_CODE(old_type) == UNION_TYPE);
104367 + gcc_assert(TYPE_READONLY(old_type) && (TYPE_QUALS(old_type) & TYPE_QUAL_CONST));
104368 +
104369 + new_type = build_qualified_type(old_type, TYPE_QUALS(old_type) & ~TYPE_QUAL_CONST);
104370 + TYPE_FIELDS(new_type) = copy_list(TYPE_FIELDS(new_type));
104371 + for (field = TYPE_FIELDS(new_type); field; field = TREE_CHAIN(field))
104372 + DECL_FIELD_CONTEXT(field) = new_type;
104373 +
104374 + deconstify_type(new_type);
104375 +
104376 + TREE_TYPE(node) = new_type;
104377 +}
104378 +
104379 +static tree handle_no_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
104380 +{
104381 + tree type;
104382 + constify_info cinfo = {
104383 + .has_fptr_field = false,
104384 + .has_writable_field = false,
104385 + .has_do_const_field = false,
104386 + .has_no_const_field = false
104387 + };
104388 +
104389 + *no_add_attrs = true;
104390 + if (TREE_CODE(*node) == FUNCTION_DECL) {
104391 + error("%qE attribute does not apply to functions (%qF)", name, *node);
104392 + return NULL_TREE;
104393 + }
104394 +
104395 + if (TREE_CODE(*node) == PARM_DECL) {
104396 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
104397 + return NULL_TREE;
104398 + }
104399 +
104400 + if (TREE_CODE(*node) == VAR_DECL) {
104401 + error("%qE attribute does not apply to variables (%qD)", name, *node);
104402 + return NULL_TREE;
104403 + }
104404 +
104405 + if (TYPE_P(*node)) {
104406 + type = *node;
104407 + } else {
104408 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
104409 + type = TREE_TYPE(*node);
104410 + }
104411 +
104412 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE) {
104413 + error("%qE attribute used on %qT applies to struct and union types only", name, type);
104414 + return NULL_TREE;
104415 + }
104416 +
104417 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
104418 + error("%qE attribute is already applied to the type %qT", name, type);
104419 + return NULL_TREE;
104420 + }
104421 +
104422 + if (TYPE_P(*node)) {
104423 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type)))
104424 + error("%qE attribute used on type %qT is incompatible with 'do_const'", name, type);
104425 + else
104426 + *no_add_attrs = false;
104427 + return NULL_TREE;
104428 + }
104429 +
104430 + constifiable(type, &cinfo);
104431 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
104432 + deconstify_tree(*node);
104433 + TYPE_CONSTIFY_VISITED(TREE_TYPE(*node)) = 1;
104434 + return NULL_TREE;
104435 + }
104436 +
104437 + error("%qE attribute used on type %qT that is not constified", name, type);
104438 + return NULL_TREE;
104439 +}
104440 +
104441 +static void constify_type(tree type)
104442 +{
104443 + TYPE_READONLY(type) = 1;
104444 + C_TYPE_FIELDS_READONLY(type) = 1;
104445 + TYPE_CONSTIFY_VISITED(type) = 1;
104446 +// TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
104447 +// TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("do_const"), NULL_TREE, TYPE_ATTRIBUTES(type));
104448 +}
104449 +
104450 +static tree handle_do_const_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
104451 +{
104452 + *no_add_attrs = true;
104453 + if (!TYPE_P(*node)) {
104454 + error("%qE attribute applies to types only (%qD)", name, *node);
104455 + return NULL_TREE;
104456 + }
104457 +
104458 + if (TREE_CODE(*node) != RECORD_TYPE && TREE_CODE(*node) != UNION_TYPE) {
104459 + error("%qE attribute used on %qT applies to struct and union types only", name, *node);
104460 + return NULL_TREE;
104461 + }
104462 +
104463 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(*node))) {
104464 + error("%qE attribute used on %qT is already applied to the type", name, *node);
104465 + return NULL_TREE;
104466 + }
104467 +
104468 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(*node))) {
104469 + error("%qE attribute used on %qT is incompatible with 'no_const'", name, *node);
104470 + return NULL_TREE;
104471 + }
104472 +
104473 + *no_add_attrs = false;
104474 + return NULL_TREE;
104475 +}
104476 +
104477 +static struct attribute_spec no_const_attr = {
104478 + .name = "no_const",
104479 + .min_length = 0,
104480 + .max_length = 0,
104481 + .decl_required = false,
104482 + .type_required = false,
104483 + .function_type_required = false,
104484 + .handler = handle_no_const_attribute,
104485 +#if BUILDING_GCC_VERSION >= 4007
104486 + .affects_type_identity = true
104487 +#endif
104488 +};
104489 +
104490 +static struct attribute_spec do_const_attr = {
104491 + .name = "do_const",
104492 + .min_length = 0,
104493 + .max_length = 0,
104494 + .decl_required = false,
104495 + .type_required = false,
104496 + .function_type_required = false,
104497 + .handler = handle_do_const_attribute,
104498 +#if BUILDING_GCC_VERSION >= 4007
104499 + .affects_type_identity = true
104500 +#endif
104501 +};
104502 +
104503 +static void register_attributes(void *event_data, void *data)
104504 +{
104505 + register_attribute(&no_const_attr);
104506 + register_attribute(&do_const_attr);
104507 +}
104508 +
104509 +static void finish_type(void *event_data, void *data)
104510 +{
104511 + tree type = (tree)event_data;
104512 + constify_info cinfo = {
104513 + .has_fptr_field = false,
104514 + .has_writable_field = false,
104515 + .has_do_const_field = false,
104516 + .has_no_const_field = false
104517 + };
104518 +
104519 + if (type == NULL_TREE || type == error_mark_node)
104520 + return;
104521 +
104522 + if (TYPE_FIELDS(type) == NULL_TREE || TYPE_CONSTIFY_VISITED(type))
104523 + return;
104524 +
104525 + constifiable(type, &cinfo);
104526 +
104527 + if (lookup_attribute("no_const", TYPE_ATTRIBUTES(type))) {
104528 + if ((cinfo.has_fptr_field && !cinfo.has_writable_field) || cinfo.has_do_const_field) {
104529 + deconstify_type(type);
104530 + TYPE_CONSTIFY_VISITED(type) = 1;
104531 + } else
104532 + error("'no_const' attribute used on type %qT that is not constified", type);
104533 + return;
104534 + }
104535 +
104536 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
104537 + if (!cinfo.has_writable_field) {
104538 + error("'do_const' attribute used on type %qT that is%sconstified", type, cinfo.has_fptr_field ? " " : " not ");
104539 + return;
104540 + }
104541 + constify_type(type);
104542 + return;
104543 + }
104544 +
104545 + if (cinfo.has_fptr_field && !cinfo.has_writable_field) {
104546 + if (lookup_attribute("do_const", TYPE_ATTRIBUTES(type))) {
104547 + error("'do_const' attribute used on type %qT that is constified", type);
104548 + return;
104549 + }
104550 + constify_type(type);
104551 + return;
104552 + }
104553 +
104554 + deconstify_type(type);
104555 + TYPE_CONSTIFY_VISITED(type) = 1;
104556 +}
104557 +
104558 +static void check_global_variables(void *event_data, void *data)
104559 +{
104560 + struct varpool_node *node;
104561 +
104562 + FOR_EACH_VARIABLE(node) {
104563 + tree var = NODE_DECL(node);
104564 + tree type = TREE_TYPE(var);
104565 +
104566 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
104567 + continue;
104568 +
104569 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
104570 + continue;
104571 +
104572 + if (!TYPE_CONSTIFY_VISITED(type))
104573 + continue;
104574 +
104575 + if (DECL_EXTERNAL(var))
104576 + continue;
104577 +
104578 + if (DECL_INITIAL(var))
104579 + continue;
104580 +
104581 + // this works around a gcc bug/feature where uninitialized globals
104582 + // are moved into the .bss section regardless of any constification
104583 + DECL_INITIAL(var) = build_constructor(type, NULL);
104584 +// inform(DECL_SOURCE_LOCATION(var), "constified variable %qE moved into .rodata", var);
104585 + }
104586 +}
104587 +
104588 +static unsigned int check_local_variables(void)
104589 +{
104590 + unsigned int ret = 0;
104591 + tree var;
104592 +
104593 + unsigned int i;
104594 +
104595 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
104596 + tree type = TREE_TYPE(var);
104597 +
104598 + gcc_assert(DECL_P(var));
104599 + if (is_global_var(var))
104600 + continue;
104601 +
104602 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
104603 + continue;
104604 +
104605 + if (!TYPE_READONLY(type) || !C_TYPE_FIELDS_READONLY(type))
104606 + continue;
104607 +
104608 + if (!TYPE_CONSTIFY_VISITED(type))
104609 + continue;
104610 +
104611 + error_at(DECL_SOURCE_LOCATION(var), "constified variable %qE cannot be local", var);
104612 + ret = 1;
104613 + }
104614 + return ret;
104615 +}
104616 +
104617 +#if BUILDING_GCC_VERSION >= 4009
104618 +static const struct pass_data check_local_variables_pass_data = {
104619 +#else
104620 +static struct gimple_opt_pass check_local_variables_pass = {
104621 + .pass = {
104622 +#endif
104623 + .type = GIMPLE_PASS,
104624 + .name = "check_local_variables",
104625 +#if BUILDING_GCC_VERSION >= 4008
104626 + .optinfo_flags = OPTGROUP_NONE,
104627 +#endif
104628 +#if BUILDING_GCC_VERSION >= 4009
104629 + .has_gate = false,
104630 + .has_execute = true,
104631 +#else
104632 + .gate = NULL,
104633 + .execute = check_local_variables,
104634 + .sub = NULL,
104635 + .next = NULL,
104636 + .static_pass_number = 0,
104637 +#endif
104638 + .tv_id = TV_NONE,
104639 + .properties_required = 0,
104640 + .properties_provided = 0,
104641 + .properties_destroyed = 0,
104642 + .todo_flags_start = 0,
104643 + .todo_flags_finish = 0
104644 +#if BUILDING_GCC_VERSION < 4009
104645 + }
104646 +#endif
104647 +};
104648 +
104649 +#if BUILDING_GCC_VERSION >= 4009
104650 +namespace {
104651 +class check_local_variables_pass : public gimple_opt_pass {
104652 +public:
104653 + check_local_variables_pass() : gimple_opt_pass(check_local_variables_pass_data, g) {}
104654 + unsigned int execute() { return check_local_variables(); }
104655 +};
104656 +}
104657 +#endif
104658 +
104659 +static struct opt_pass *make_check_local_variables_pass(void)
104660 +{
104661 +#if BUILDING_GCC_VERSION >= 4009
104662 + return new check_local_variables_pass();
104663 +#else
104664 + return &check_local_variables_pass.pass;
104665 +#endif
104666 +}
104667 +
104668 +static struct {
104669 + const char *name;
104670 + const char *asm_op;
104671 +} sections[] = {
104672 + {".init.rodata", "\t.section\t.init.rodata,\"a\""},
104673 + {".ref.rodata", "\t.section\t.ref.rodata,\"a\""},
104674 + {".devinit.rodata", "\t.section\t.devinit.rodata,\"a\""},
104675 + {".devexit.rodata", "\t.section\t.devexit.rodata,\"a\""},
104676 + {".cpuinit.rodata", "\t.section\t.cpuinit.rodata,\"a\""},
104677 + {".cpuexit.rodata", "\t.section\t.cpuexit.rodata,\"a\""},
104678 + {".meminit.rodata", "\t.section\t.meminit.rodata,\"a\""},
104679 + {".memexit.rodata", "\t.section\t.memexit.rodata,\"a\""},
104680 + {".data..read_only", "\t.section\t.data..read_only,\"a\""},
104681 +};
104682 +
104683 +static unsigned int (*old_section_type_flags)(tree decl, const char *name, int reloc);
104684 +
104685 +static unsigned int constify_section_type_flags(tree decl, const char *name, int reloc)
104686 +{
104687 + size_t i;
104688 +
104689 + for (i = 0; i < ARRAY_SIZE(sections); i++)
104690 + if (!strcmp(sections[i].name, name))
104691 + return 0;
104692 + return old_section_type_flags(decl, name, reloc);
104693 +}
104694 +
104695 +static void constify_start_unit(void *gcc_data, void *user_data)
104696 +{
104697 +// size_t i;
104698 +
104699 +// for (i = 0; i < ARRAY_SIZE(sections); i++)
104700 +// sections[i].section = get_unnamed_section(0, output_section_asm_op, sections[i].asm_op);
104701 +// sections[i].section = get_section(sections[i].name, 0, NULL);
104702 +
104703 + old_section_type_flags = targetm.section_type_flags;
104704 + targetm.section_type_flags = constify_section_type_flags;
104705 +}
104706 +
104707 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
104708 +{
104709 + const char * const plugin_name = plugin_info->base_name;
104710 + const int argc = plugin_info->argc;
104711 + const struct plugin_argument * const argv = plugin_info->argv;
104712 + int i;
104713 + bool constify = true;
104714 +
104715 + struct register_pass_info check_local_variables_pass_info;
104716 +
104717 + check_local_variables_pass_info.pass = make_check_local_variables_pass();
104718 + check_local_variables_pass_info.reference_pass_name = "ssa";
104719 + check_local_variables_pass_info.ref_pass_instance_number = 1;
104720 + check_local_variables_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
104721 +
104722 + if (!plugin_default_version_check(version, &gcc_version)) {
104723 + error(G_("incompatible gcc/plugin versions"));
104724 + return 1;
104725 + }
104726 +
104727 + for (i = 0; i < argc; ++i) {
104728 + if (!(strcmp(argv[i].key, "no-constify"))) {
104729 + constify = false;
104730 + continue;
104731 + }
104732 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
104733 + }
104734 +
104735 + if (strcmp(lang_hooks.name, "GNU C")) {
104736 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
104737 + constify = false;
104738 + }
104739 +
104740 + register_callback(plugin_name, PLUGIN_INFO, NULL, &const_plugin_info);
104741 + if (constify) {
104742 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
104743 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
104744 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &check_local_variables_pass_info);
104745 + register_callback(plugin_name, PLUGIN_START_UNIT, constify_start_unit, NULL);
104746 + }
104747 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
104748 +
104749 + return 0;
104750 +}
104751 diff --git a/tools/gcc/gcc-common.h b/tools/gcc/gcc-common.h
104752 new file mode 100644
104753 index 0000000..312d3b6
104754 --- /dev/null
104755 +++ b/tools/gcc/gcc-common.h
104756 @@ -0,0 +1,268 @@
104757 +#ifndef GCC_COMMON_H_INCLUDED
104758 +#define GCC_COMMON_H_INCLUDED
104759 +
104760 +#include "plugin.h"
104761 +#include "bversion.h"
104762 +#include "plugin-version.h"
104763 +#include "config.h"
104764 +#include "system.h"
104765 +#include "coretypes.h"
104766 +#include "tm.h"
104767 +#include "line-map.h"
104768 +#include "input.h"
104769 +#include "tree.h"
104770 +
104771 +#include "tree-inline.h"
104772 +#include "version.h"
104773 +#include "rtl.h"
104774 +#include "tm_p.h"
104775 +#include "flags.h"
104776 +//#include "insn-attr.h"
104777 +//#include "insn-config.h"
104778 +//#include "insn-flags.h"
104779 +#include "hard-reg-set.h"
104780 +//#include "recog.h"
104781 +#include "output.h"
104782 +#include "except.h"
104783 +#include "function.h"
104784 +#include "toplev.h"
104785 +//#include "expr.h"
104786 +#include "basic-block.h"
104787 +#include "intl.h"
104788 +#include "ggc.h"
104789 +//#include "regs.h"
104790 +#include "timevar.h"
104791 +
104792 +#include "params.h"
104793 +#include "pointer-set.h"
104794 +#include "emit-rtl.h"
104795 +//#include "reload.h"
104796 +//#include "ira.h"
104797 +//#include "dwarf2asm.h"
104798 +#include "debug.h"
104799 +#include "target.h"
104800 +#include "langhooks.h"
104801 +#include "cfgloop.h"
104802 +//#include "hosthooks.h"
104803 +#include "cgraph.h"
104804 +#include "opts.h"
104805 +//#include "coverage.h"
104806 +//#include "value-prof.h"
104807 +
104808 +#if BUILDING_GCC_VERSION >= 4007
104809 +#include "tree-pretty-print.h"
104810 +#include "gimple-pretty-print.h"
104811 +#include "c-tree.h"
104812 +//#include "alloc-pool.h"
104813 +#endif
104814 +
104815 +#if BUILDING_GCC_VERSION <= 4008
104816 +#include "tree-flow.h"
104817 +#endif
104818 +
104819 +#include "diagnostic.h"
104820 +//#include "tree-diagnostic.h"
104821 +#include "tree-dump.h"
104822 +#include "tree-pass.h"
104823 +//#include "df.h"
104824 +#include "predict.h"
104825 +//#include "lto-streamer.h"
104826 +#include "ipa-utils.h"
104827 +
104828 +#if BUILDING_GCC_VERSION >= 4009
104829 +#include "varasm.h"
104830 +#include "stor-layout.h"
104831 +#include "internal-fn.h"
104832 +#include "gimple-expr.h"
104833 +//#include "diagnostic-color.h"
104834 +#include "context.h"
104835 +#include "tree-ssa-alias.h"
104836 +#include "stringpool.h"
104837 +#include "tree-ssanames.h"
104838 +#include "print-tree.h"
104839 +#include "tree-eh.h"
104840 +#endif
104841 +
104842 +#include "gimple.h"
104843 +
104844 +#if BUILDING_GCC_VERSION >= 4009
104845 +#include "tree-ssa-operands.h"
104846 +#include "tree-phinodes.h"
104847 +#include "tree-cfg.h"
104848 +#include "gimple-iterator.h"
104849 +#include "gimple-ssa.h"
104850 +#include "ssa-iterators.h"
104851 +#endif
104852 +
104853 +//#include "expr.h" where are you...
104854 +extern rtx emit_move_insn(rtx x, rtx y);
104855 +
104856 +#define __unused __attribute__((__unused__))
104857 +
104858 +#define DECL_NAME_POINTER(node) IDENTIFIER_POINTER(DECL_NAME(node))
104859 +#define DECL_NAME_LENGTH(node) IDENTIFIER_LENGTH(DECL_NAME(node))
104860 +
104861 +#if BUILDING_GCC_VERSION == 4005
104862 +#define FOR_EACH_LOCAL_DECL(FUN, I, D) for (tree vars = (FUN)->local_decls; vars && (D = TREE_VALUE(vars)); vars = TREE_CHAIN(vars), I)
104863 +#define DECL_CHAIN(NODE) (TREE_CHAIN(DECL_MINIMAL_CHECK(NODE)))
104864 +#define FOR_EACH_VEC_ELT(T, V, I, P) for (I = 0; VEC_iterate(T, (V), (I), (P)); ++(I))
104865 +
104866 +static inline bool gimple_call_builtin_p(gimple stmt, enum built_in_function code)
104867 +{
104868 + tree fndecl;
104869 +
104870 + if (!is_gimple_call(stmt))
104871 + return false;
104872 + fndecl = gimple_call_fndecl(stmt);
104873 + if (!fndecl || DECL_BUILT_IN_CLASS(fndecl) != BUILT_IN_NORMAL)
104874 + return false;
104875 +// print_node(stderr, "pax", fndecl, 4);
104876 + return DECL_FUNCTION_CODE(fndecl) == code;
104877 +}
104878 +
104879 +static inline bool is_simple_builtin(tree decl)
104880 +{
104881 + if (decl && DECL_BUILT_IN_CLASS(decl) != BUILT_IN_NORMAL)
104882 + return false;
104883 +
104884 + switch (DECL_FUNCTION_CODE(decl)) {
104885 + /* Builtins that expand to constants. */
104886 + case BUILT_IN_CONSTANT_P:
104887 + case BUILT_IN_EXPECT:
104888 + case BUILT_IN_OBJECT_SIZE:
104889 + case BUILT_IN_UNREACHABLE:
104890 + /* Simple register moves or loads from stack. */
104891 + case BUILT_IN_RETURN_ADDRESS:
104892 + case BUILT_IN_EXTRACT_RETURN_ADDR:
104893 + case BUILT_IN_FROB_RETURN_ADDR:
104894 + case BUILT_IN_RETURN:
104895 + case BUILT_IN_AGGREGATE_INCOMING_ADDRESS:
104896 + case BUILT_IN_FRAME_ADDRESS:
104897 + case BUILT_IN_VA_END:
104898 + case BUILT_IN_STACK_SAVE:
104899 + case BUILT_IN_STACK_RESTORE:
104900 + /* Exception state returns or moves registers around. */
104901 + case BUILT_IN_EH_FILTER:
104902 + case BUILT_IN_EH_POINTER:
104903 + case BUILT_IN_EH_COPY_VALUES:
104904 + return true;
104905 +
104906 + default:
104907 + return false;
104908 + }
104909 +}
104910 +#endif
104911 +
104912 +#if BUILDING_GCC_VERSION <= 4006
104913 +#define ANY_RETURN_P(rtx) (GET_CODE(rtx) == RETURN)
104914 +#define C_DECL_REGISTER(EXP) DECL_LANG_FLAG_4(EXP)
104915 +
104916 +// should come from c-tree.h if only it were installed for gcc 4.5...
104917 +#define C_TYPE_FIELDS_READONLY(TYPE) TREE_LANG_FLAG_1(TYPE)
104918 +
104919 +#define get_random_seed(noinit) ({ \
104920 + unsigned HOST_WIDE_INT seed; \
104921 + sscanf(get_random_seed(noinit), "%" HOST_WIDE_INT_PRINT "x", &seed); \
104922 + seed * seed; })
104923 +
104924 +static inline bool gimple_clobber_p(gimple s)
104925 +{
104926 + return false;
104927 +}
104928 +
104929 +static inline tree builtin_decl_implicit(enum built_in_function fncode)
104930 +{
104931 + return implicit_built_in_decls[fncode];
104932 +}
104933 +
104934 +static inline struct cgraph_node *cgraph_get_create_node(tree decl)
104935 +{
104936 + struct cgraph_node *node = cgraph_get_node(decl);
104937 +
104938 + return node ? node : cgraph_node(decl);
104939 +}
104940 +
104941 +static inline bool cgraph_function_with_gimple_body_p(struct cgraph_node *node)
104942 +{
104943 + return node->analyzed && !node->thunk.thunk_p && !node->alias;
104944 +}
104945 +
104946 +static inline struct cgraph_node *cgraph_first_function_with_gimple_body(void)
104947 +{
104948 + struct cgraph_node *node;
104949 +
104950 + for (node = cgraph_nodes; node; node = node->next)
104951 + if (cgraph_function_with_gimple_body_p(node))
104952 + return node;
104953 + return NULL;
104954 +}
104955 +
104956 +static inline struct cgraph_node *cgraph_next_function_with_gimple_body(struct cgraph_node *node)
104957 +{
104958 + for (node = node->next; node; node = node->next)
104959 + if (cgraph_function_with_gimple_body_p(node))
104960 + return node;
104961 + return NULL;
104962 +}
104963 +
104964 +#define FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) \
104965 + for ((node) = cgraph_first_function_with_gimple_body(); (node); \
104966 + (node) = cgraph_next_function_with_gimple_body(node))
104967 +#endif
104968 +
104969 +#if BUILDING_GCC_VERSION == 4006
104970 +extern void debug_gimple_stmt(gimple);
104971 +extern void debug_gimple_seq(gimple_seq);
104972 +extern void print_gimple_seq(FILE *, gimple_seq, int, int);
104973 +extern void print_gimple_stmt(FILE *, gimple, int, int);
104974 +extern void print_gimple_expr(FILE *, gimple, int, int);
104975 +extern void dump_gimple_stmt(pretty_printer *, gimple, int, int);
104976 +#endif
104977 +
104978 +#if BUILDING_GCC_VERSION <= 4007
104979 +#define FOR_EACH_VARIABLE(node) for (node = varpool_nodes; node; node = node->next)
104980 +
104981 +static inline bool gimple_store_p(gimple gs)
104982 +{
104983 + tree lhs = gimple_get_lhs(gs);
104984 + return lhs && !is_gimple_reg(lhs);
104985 +}
104986 +#endif
104987 +
104988 +#if BUILDING_GCC_VERSION >= 4007
104989 +#define cgraph_create_edge(caller, callee, call_stmt, count, freq, nest) \
104990 + cgraph_create_edge((caller), (callee), (call_stmt), (count), (freq))
104991 +#endif
104992 +
104993 +#if BUILDING_GCC_VERSION <= 4008
104994 +#define ENTRY_BLOCK_PTR_FOR_FN(FN) ENTRY_BLOCK_PTR_FOR_FUNCTION(FN)
104995 +#define EXIT_BLOCK_PTR_FOR_FN(FN) EXIT_BLOCK_PTR_FOR_FUNCTION(FN)
104996 +
104997 +static inline const char *get_tree_code_name(enum tree_code code)
104998 +{
104999 + gcc_assert(code < MAX_TREE_CODES);
105000 + return tree_code_name[code];
105001 +}
105002 +
105003 +#define ipa_remove_stmt_references(cnode, stmt)
105004 +#endif
105005 +
105006 +#if BUILDING_GCC_VERSION == 4008
105007 +#define NODE_DECL(node) node->symbol.decl
105008 +#else
105009 +#define NODE_DECL(node) node->decl
105010 +#endif
105011 +
105012 +#if BUILDING_GCC_VERSION >= 4008
105013 +#define add_referenced_var(var)
105014 +#define mark_sym_for_renaming(var)
105015 +#define varpool_mark_needed_node(node)
105016 +#define TODO_dump_func 0
105017 +#define TODO_dump_cgraph 0
105018 +#endif
105019 +
105020 +#if BUILDING_GCC_VERSION >= 4009
105021 +#define TODO_ggc_collect 0
105022 +#endif
105023 +
105024 +#endif
105025 diff --git a/tools/gcc/gen-random-seed.sh b/tools/gcc/gen-random-seed.sh
105026 new file mode 100644
105027 index 0000000..7514850
105028 --- /dev/null
105029 +++ b/tools/gcc/gen-random-seed.sh
105030 @@ -0,0 +1,8 @@
105031 +#!/bin/sh
105032 +
105033 +if [ ! -f "$1" ]; then
105034 + SEED=`od -A n -t x8 -N 32 /dev/urandom | tr -d ' \n'`
105035 + echo "const char *randstruct_seed = \"$SEED\";" > "$1"
105036 + HASH=`echo -n "$SEED" | sha256sum | cut -d" " -f1 | tr -d ' \n'`
105037 + echo "#define RANDSTRUCT_HASHED_SEED \"$HASH\"" > "$2"
105038 +fi
105039 diff --git a/tools/gcc/generate_size_overflow_hash.sh b/tools/gcc/generate_size_overflow_hash.sh
105040 new file mode 100644
105041 index 0000000..e518932
105042 --- /dev/null
105043 +++ b/tools/gcc/generate_size_overflow_hash.sh
105044 @@ -0,0 +1,94 @@
105045 +#!/bin/bash
105046 +
105047 +# This script generates the hash table (size_overflow_hash.h) for the size_overflow gcc plugin (size_overflow_plugin.c).
105048 +
105049 +header1="size_overflow_hash.h"
105050 +database="size_overflow_hash.data"
105051 +n=65536
105052 +
105053 +usage() {
105054 +cat <<EOF
105055 +usage: $0 options
105056 +OPTIONS:
105057 + -h|--help help
105058 + -o header file
105059 + -d database file
105060 + -n hash array size
105061 +EOF
105062 + return 0
105063 +}
105064 +
105065 +while true
105066 +do
105067 + case "$1" in
105068 + -h|--help) usage && exit 0;;
105069 + -n) n=$2; shift 2;;
105070 + -o) header1="$2"; shift 2;;
105071 + -d) database="$2"; shift 2;;
105072 + --) shift 1; break ;;
105073 + *) break ;;
105074 + esac
105075 +done
105076 +
105077 +create_defines() {
105078 + for i in `seq 0 31`
105079 + do
105080 + echo -e "#define PARAM"$i" (1U << "$i")" >> "$header1"
105081 + done
105082 + echo >> "$header1"
105083 +}
105084 +
105085 +create_structs() {
105086 + rm -f "$header1"
105087 +
105088 + create_defines
105089 +
105090 + cat "$database" | while read data
105091 + do
105092 + data_array=($data)
105093 + struct_hash_name="${data_array[0]}"
105094 + funcn="${data_array[1]}"
105095 + params="${data_array[2]}"
105096 + next="${data_array[4]}"
105097 +
105098 + echo "const struct size_overflow_hash $struct_hash_name = {" >> "$header1"
105099 +
105100 + echo -e "\t.next\t= $next,\n\t.name\t= \"$funcn\"," >> "$header1"
105101 + echo -en "\t.param\t= " >> "$header1"
105102 + line=
105103 + for param_num in ${params//-/ };
105104 + do
105105 + line="${line}PARAM"$param_num"|"
105106 + done
105107 +
105108 + echo -e "${line%?},\n};\n" >> "$header1"
105109 + done
105110 +}
105111 +
105112 +create_headers() {
105113 + echo "const struct size_overflow_hash * const size_overflow_hash[$n] = {" >> "$header1"
105114 +}
105115 +
105116 +create_array_elements() {
105117 + index=0
105118 + grep -v "nohasharray" $database | sort -n -k 4 | while read data
105119 + do
105120 + data_array=($data)
105121 + i="${data_array[3]}"
105122 + hash="${data_array[0]}"
105123 + while [[ $index -lt $i ]]
105124 + do
105125 + echo -e "\t["$index"]\t= NULL," >> "$header1"
105126 + index=$(($index + 1))
105127 + done
105128 + index=$(($index + 1))
105129 + echo -e "\t["$i"]\t= &"$hash"," >> "$header1"
105130 + done
105131 + echo '};' >> $header1
105132 +}
105133 +
105134 +create_structs
105135 +create_headers
105136 +create_array_elements
105137 +
105138 +exit 0
105139 diff --git a/tools/gcc/kallocstat_plugin.c b/tools/gcc/kallocstat_plugin.c
105140 new file mode 100644
105141 index 0000000..b559327
105142 --- /dev/null
105143 +++ b/tools/gcc/kallocstat_plugin.c
105144 @@ -0,0 +1,182 @@
105145 +/*
105146 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
105147 + * Licensed under the GPL v2
105148 + *
105149 + * Note: the choice of the license means that the compilation process is
105150 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
105151 + * but for the kernel it doesn't matter since it doesn't link against
105152 + * any of the gcc libraries
105153 + *
105154 + * gcc plugin to find the distribution of k*alloc sizes
105155 + *
105156 + * TODO:
105157 + *
105158 + * BUGS:
105159 + * - none known
105160 + */
105161 +
105162 +#include "gcc-common.h"
105163 +
105164 +int plugin_is_GPL_compatible;
105165 +
105166 +static struct plugin_info kallocstat_plugin_info = {
105167 + .version = "201401260140",
105168 + .help = NULL
105169 +};
105170 +
105171 +static const char * const kalloc_functions[] = {
105172 + "__kmalloc",
105173 + "kmalloc",
105174 + "kmalloc_large",
105175 + "kmalloc_node",
105176 + "kmalloc_order",
105177 + "kmalloc_order_trace",
105178 + "kmalloc_slab",
105179 + "kzalloc",
105180 + "kzalloc_node",
105181 +};
105182 +
105183 +static bool is_kalloc(const char *fnname)
105184 +{
105185 + size_t i;
105186 +
105187 + for (i = 0; i < ARRAY_SIZE(kalloc_functions); i++)
105188 + if (!strcmp(fnname, kalloc_functions[i]))
105189 + return true;
105190 + return false;
105191 +}
105192 +
105193 +static unsigned int execute_kallocstat(void)
105194 +{
105195 + basic_block bb;
105196 +
105197 + // 1. loop through BBs and GIMPLE statements
105198 + FOR_EACH_BB_FN(bb, cfun) {
105199 + gimple_stmt_iterator gsi;
105200 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
105201 + // gimple match:
105202 + tree fndecl, size;
105203 + gimple stmt;
105204 + const char *fnname;
105205 +
105206 + // is it a call
105207 + stmt = gsi_stmt(gsi);
105208 + if (!is_gimple_call(stmt))
105209 + continue;
105210 + fndecl = gimple_call_fndecl(stmt);
105211 + if (fndecl == NULL_TREE)
105212 + continue;
105213 + if (TREE_CODE(fndecl) != FUNCTION_DECL)
105214 + continue;
105215 +
105216 + // is it a call to k*alloc
105217 + fnname = DECL_NAME_POINTER(fndecl);
105218 + if (!is_kalloc(fnname))
105219 + continue;
105220 +
105221 + // is the size arg const or the result of a simple const assignment
105222 + size = gimple_call_arg(stmt, 0);
105223 + while (true) {
105224 + expanded_location xloc;
105225 + size_t size_val;
105226 +
105227 + if (TREE_CONSTANT(size)) {
105228 + xloc = expand_location(gimple_location(stmt));
105229 + if (!xloc.file)
105230 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
105231 + size_val = TREE_INT_CST_LOW(size);
105232 + fprintf(stderr, "kallocsize: %8zu %8zx %s %s:%u\n", size_val, size_val, fnname, xloc.file, xloc.line);
105233 + break;
105234 + }
105235 +
105236 + if (TREE_CODE(size) != SSA_NAME)
105237 + break;
105238 + stmt = SSA_NAME_DEF_STMT(size);
105239 +//debug_gimple_stmt(stmt);
105240 +//debug_tree(size);
105241 + if (!stmt || !is_gimple_assign(stmt))
105242 + break;
105243 + if (gimple_num_ops(stmt) != 2)
105244 + break;
105245 + size = gimple_assign_rhs1(stmt);
105246 + }
105247 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
105248 +//debug_tree(gimple_call_fn(call_stmt));
105249 +//print_node(stderr, "pax", fndecl, 4);
105250 + }
105251 + }
105252 +
105253 + return 0;
105254 +}
105255 +
105256 +#if BUILDING_GCC_VERSION >= 4009
105257 +static const struct pass_data kallocstat_pass_data = {
105258 +#else
105259 +static struct gimple_opt_pass kallocstat_pass = {
105260 + .pass = {
105261 +#endif
105262 + .type = GIMPLE_PASS,
105263 + .name = "kallocstat",
105264 +#if BUILDING_GCC_VERSION >= 4008
105265 + .optinfo_flags = OPTGROUP_NONE,
105266 +#endif
105267 +#if BUILDING_GCC_VERSION >= 4009
105268 + .has_gate = false,
105269 + .has_execute = true,
105270 +#else
105271 + .gate = NULL,
105272 + .execute = execute_kallocstat,
105273 + .sub = NULL,
105274 + .next = NULL,
105275 + .static_pass_number = 0,
105276 +#endif
105277 + .tv_id = TV_NONE,
105278 + .properties_required = 0,
105279 + .properties_provided = 0,
105280 + .properties_destroyed = 0,
105281 + .todo_flags_start = 0,
105282 + .todo_flags_finish = 0
105283 +#if BUILDING_GCC_VERSION < 4009
105284 + }
105285 +#endif
105286 +};
105287 +
105288 +#if BUILDING_GCC_VERSION >= 4009
105289 +namespace {
105290 +class kallocstat_pass : public gimple_opt_pass {
105291 +public:
105292 + kallocstat_pass() : gimple_opt_pass(kallocstat_pass_data, g) {}
105293 + unsigned int execute() { return execute_kallocstat(); }
105294 +};
105295 +}
105296 +#endif
105297 +
105298 +static struct opt_pass *make_kallocstat_pass(void)
105299 +{
105300 +#if BUILDING_GCC_VERSION >= 4009
105301 + return new kallocstat_pass();
105302 +#else
105303 + return &kallocstat_pass.pass;
105304 +#endif
105305 +}
105306 +
105307 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
105308 +{
105309 + const char * const plugin_name = plugin_info->base_name;
105310 + struct register_pass_info kallocstat_pass_info;
105311 +
105312 + kallocstat_pass_info.pass = make_kallocstat_pass();
105313 + kallocstat_pass_info.reference_pass_name = "ssa";
105314 + kallocstat_pass_info.ref_pass_instance_number = 1;
105315 + kallocstat_pass_info.pos_op = PASS_POS_INSERT_AFTER;
105316 +
105317 + if (!plugin_default_version_check(version, &gcc_version)) {
105318 + error(G_("incompatible gcc/plugin versions"));
105319 + return 1;
105320 + }
105321 +
105322 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kallocstat_plugin_info);
105323 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kallocstat_pass_info);
105324 +
105325 + return 0;
105326 +}
105327 diff --git a/tools/gcc/kernexec_plugin.c b/tools/gcc/kernexec_plugin.c
105328 new file mode 100644
105329 index 0000000..dd73713
105330 --- /dev/null
105331 +++ b/tools/gcc/kernexec_plugin.c
105332 @@ -0,0 +1,519 @@
105333 +/*
105334 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
105335 + * Licensed under the GPL v2
105336 + *
105337 + * Note: the choice of the license means that the compilation process is
105338 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
105339 + * but for the kernel it doesn't matter since it doesn't link against
105340 + * any of the gcc libraries
105341 + *
105342 + * gcc plugin to make KERNEXEC/amd64 almost as good as it is on i386
105343 + *
105344 + * TODO:
105345 + *
105346 + * BUGS:
105347 + * - none known
105348 + */
105349 +
105350 +#include "gcc-common.h"
105351 +
105352 +int plugin_is_GPL_compatible;
105353 +
105354 +static struct plugin_info kernexec_plugin_info = {
105355 + .version = "201401260140",
105356 + .help = "method=[bts|or]\tinstrumentation method\n"
105357 +};
105358 +
105359 +static void (*kernexec_instrument_fptr)(gimple_stmt_iterator *);
105360 +static void (*kernexec_instrument_retaddr)(rtx);
105361 +
105362 +/*
105363 + * add special KERNEXEC instrumentation: reload %r12 after it has been clobbered
105364 + */
105365 +static void kernexec_reload_fptr_mask(gimple_stmt_iterator *gsi)
105366 +{
105367 + gimple asm_movabs_stmt;
105368 +
105369 + // build asm volatile("movabs $0x8000000000000000, %%r12\n\t" : : : );
105370 + asm_movabs_stmt = gimple_build_asm_vec("movabs $0x8000000000000000, %%r12\n\t", NULL, NULL, NULL, NULL);
105371 + gimple_asm_set_volatile(asm_movabs_stmt, true);
105372 + gsi_insert_after(gsi, asm_movabs_stmt, GSI_CONTINUE_LINKING);
105373 + update_stmt(asm_movabs_stmt);
105374 +}
105375 +
105376 +/*
105377 + * find all asm() stmts that clobber r12 and add a reload of r12
105378 + */
105379 +static unsigned int execute_kernexec_reload(void)
105380 +{
105381 + basic_block bb;
105382 +
105383 + // 1. loop through BBs and GIMPLE statements
105384 + FOR_EACH_BB_FN(bb, cfun) {
105385 + gimple_stmt_iterator gsi;
105386 +
105387 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
105388 + // gimple match: __asm__ ("" : : : "r12");
105389 + gimple asm_stmt;
105390 + size_t nclobbers;
105391 +
105392 + // is it an asm ...
105393 + asm_stmt = gsi_stmt(gsi);
105394 + if (gimple_code(asm_stmt) != GIMPLE_ASM)
105395 + continue;
105396 +
105397 + // ... clobbering r12
105398 + nclobbers = gimple_asm_nclobbers(asm_stmt);
105399 + while (nclobbers--) {
105400 + tree op = gimple_asm_clobber_op(asm_stmt, nclobbers);
105401 + if (strcmp(TREE_STRING_POINTER(TREE_VALUE(op)), "r12"))
105402 + continue;
105403 + kernexec_reload_fptr_mask(&gsi);
105404 +//print_gimple_stmt(stderr, asm_stmt, 0, TDF_LINENO);
105405 + break;
105406 + }
105407 + }
105408 + }
105409 +
105410 + return 0;
105411 +}
105412 +
105413 +/*
105414 + * add special KERNEXEC instrumentation: force MSB of fptr to 1, which will produce
105415 + * a non-canonical address from a userland ptr and will just trigger a GPF on dereference
105416 + */
105417 +static void kernexec_instrument_fptr_bts(gimple_stmt_iterator *gsi)
105418 +{
105419 + gimple assign_intptr, assign_new_fptr, call_stmt;
105420 + tree intptr, orptr, old_fptr, new_fptr, kernexec_mask;
105421 +
105422 + call_stmt = gsi_stmt(*gsi);
105423 + old_fptr = gimple_call_fn(call_stmt);
105424 +
105425 + // create temporary unsigned long variable used for bitops and cast fptr to it
105426 + intptr = create_tmp_var(long_unsigned_type_node, "kernexec_bts");
105427 + add_referenced_var(intptr);
105428 + intptr = make_ssa_name(intptr, NULL);
105429 + assign_intptr = gimple_build_assign(intptr, fold_convert(long_unsigned_type_node, old_fptr));
105430 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
105431 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
105432 + update_stmt(assign_intptr);
105433 +
105434 + // apply logical or to temporary unsigned long and bitmask
105435 + kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0x8000000000000000LL);
105436 +// kernexec_mask = build_int_cstu(long_long_unsigned_type_node, 0xffffffff80000000LL);
105437 + orptr = fold_build2(BIT_IOR_EXPR, long_long_unsigned_type_node, intptr, kernexec_mask);
105438 + intptr = make_ssa_name(SSA_NAME_VAR(intptr), NULL);
105439 + assign_intptr = gimple_build_assign(intptr, orptr);
105440 + SSA_NAME_DEF_STMT(intptr) = assign_intptr;
105441 + gsi_insert_before(gsi, assign_intptr, GSI_SAME_STMT);
105442 + update_stmt(assign_intptr);
105443 +
105444 + // cast temporary unsigned long back to a temporary fptr variable
105445 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_fptr");
105446 + add_referenced_var(new_fptr);
105447 + new_fptr = make_ssa_name(new_fptr, NULL);
105448 + assign_new_fptr = gimple_build_assign(new_fptr, fold_convert(TREE_TYPE(old_fptr), intptr));
105449 + SSA_NAME_DEF_STMT(new_fptr) = assign_new_fptr;
105450 + gsi_insert_before(gsi, assign_new_fptr, GSI_SAME_STMT);
105451 + update_stmt(assign_new_fptr);
105452 +
105453 + // replace call stmt fn with the new fptr
105454 + gimple_call_set_fn(call_stmt, new_fptr);
105455 + update_stmt(call_stmt);
105456 +}
105457 +
105458 +static void kernexec_instrument_fptr_or(gimple_stmt_iterator *gsi)
105459 +{
105460 + gimple asm_or_stmt, call_stmt;
105461 + tree old_fptr, new_fptr, input, output;
105462 +#if BUILDING_GCC_VERSION <= 4007
105463 + VEC(tree, gc) *inputs = NULL;
105464 + VEC(tree, gc) *outputs = NULL;
105465 +#else
105466 + vec<tree, va_gc> *inputs = NULL;
105467 + vec<tree, va_gc> *outputs = NULL;
105468 +#endif
105469 +
105470 + call_stmt = gsi_stmt(*gsi);
105471 + old_fptr = gimple_call_fn(call_stmt);
105472 +
105473 + // create temporary fptr variable
105474 + new_fptr = create_tmp_var(TREE_TYPE(old_fptr), "kernexec_or");
105475 + add_referenced_var(new_fptr);
105476 + new_fptr = make_ssa_name(new_fptr, NULL);
105477 +
105478 + // build asm volatile("orq %%r12, %0\n\t" : "=r"(new_fptr) : "0"(old_fptr));
105479 + input = build_tree_list(NULL_TREE, build_string(1, "0"));
105480 + input = chainon(NULL_TREE, build_tree_list(input, old_fptr));
105481 + output = build_tree_list(NULL_TREE, build_string(2, "=r"));
105482 + output = chainon(NULL_TREE, build_tree_list(output, new_fptr));
105483 +#if BUILDING_GCC_VERSION <= 4007
105484 + VEC_safe_push(tree, gc, inputs, input);
105485 + VEC_safe_push(tree, gc, outputs, output);
105486 +#else
105487 + vec_safe_push(inputs, input);
105488 + vec_safe_push(outputs, output);
105489 +#endif
105490 + asm_or_stmt = gimple_build_asm_vec("orq %%r12, %0\n\t", inputs, outputs, NULL, NULL);
105491 + SSA_NAME_DEF_STMT(new_fptr) = asm_or_stmt;
105492 + gimple_asm_set_volatile(asm_or_stmt, true);
105493 + gsi_insert_before(gsi, asm_or_stmt, GSI_SAME_STMT);
105494 + update_stmt(asm_or_stmt);
105495 +
105496 + // replace call stmt fn with the new fptr
105497 + gimple_call_set_fn(call_stmt, new_fptr);
105498 + update_stmt(call_stmt);
105499 +}
105500 +
105501 +/*
105502 + * find all C level function pointer dereferences and forcibly set the highest bit of the pointer
105503 + */
105504 +static unsigned int execute_kernexec_fptr(void)
105505 +{
105506 + basic_block bb;
105507 +
105508 + // 1. loop through BBs and GIMPLE statements
105509 + FOR_EACH_BB_FN(bb, cfun) {
105510 + gimple_stmt_iterator gsi;
105511 +
105512 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
105513 + // gimple match: h_1 = get_fptr (); D.2709_3 = h_1 (x_2(D));
105514 + tree fn;
105515 + gimple call_stmt;
105516 +
105517 + // is it a call ...
105518 + call_stmt = gsi_stmt(gsi);
105519 + if (!is_gimple_call(call_stmt))
105520 + continue;
105521 + fn = gimple_call_fn(call_stmt);
105522 + if (TREE_CODE(fn) == ADDR_EXPR)
105523 + continue;
105524 + if (TREE_CODE(fn) != SSA_NAME)
105525 + gcc_unreachable();
105526 +
105527 + // ... through a function pointer
105528 + if (SSA_NAME_VAR(fn) != NULL_TREE) {
105529 + fn = SSA_NAME_VAR(fn);
105530 + if (TREE_CODE(fn) != VAR_DECL && TREE_CODE(fn) != PARM_DECL) {
105531 + debug_tree(fn);
105532 + gcc_unreachable();
105533 + }
105534 + }
105535 + fn = TREE_TYPE(fn);
105536 + if (TREE_CODE(fn) != POINTER_TYPE)
105537 + continue;
105538 + fn = TREE_TYPE(fn);
105539 + if (TREE_CODE(fn) != FUNCTION_TYPE)
105540 + continue;
105541 +
105542 + kernexec_instrument_fptr(&gsi);
105543 +
105544 +//debug_tree(gimple_call_fn(call_stmt));
105545 +//print_gimple_stmt(stderr, call_stmt, 0, TDF_LINENO);
105546 + }
105547 + }
105548 +
105549 + return 0;
105550 +}
105551 +
105552 +// add special KERNEXEC instrumentation: btsq $63,(%rsp) just before retn
105553 +static void kernexec_instrument_retaddr_bts(rtx insn)
105554 +{
105555 + rtx btsq;
105556 + rtvec argvec, constraintvec, labelvec;
105557 + int line;
105558 +
105559 + // create asm volatile("btsq $63,(%%rsp)":::)
105560 + argvec = rtvec_alloc(0);
105561 + constraintvec = rtvec_alloc(0);
105562 + labelvec = rtvec_alloc(0);
105563 + line = expand_location(RTL_LOCATION(insn)).line;
105564 + btsq = gen_rtx_ASM_OPERANDS(VOIDmode, "btsq $63,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
105565 + MEM_VOLATILE_P(btsq) = 1;
105566 +// RTX_FRAME_RELATED_P(btsq) = 1; // not for ASM_OPERANDS
105567 + emit_insn_before(btsq, insn);
105568 +}
105569 +
105570 +// add special KERNEXEC instrumentation: orq %r12,(%rsp) just before retn
105571 +static void kernexec_instrument_retaddr_or(rtx insn)
105572 +{
105573 + rtx orq;
105574 + rtvec argvec, constraintvec, labelvec;
105575 + int line;
105576 +
105577 + // create asm volatile("orq %%r12,(%%rsp)":::)
105578 + argvec = rtvec_alloc(0);
105579 + constraintvec = rtvec_alloc(0);
105580 + labelvec = rtvec_alloc(0);
105581 + line = expand_location(RTL_LOCATION(insn)).line;
105582 + orq = gen_rtx_ASM_OPERANDS(VOIDmode, "orq %%r12,(%%rsp)", empty_string, 0, argvec, constraintvec, labelvec, line);
105583 + MEM_VOLATILE_P(orq) = 1;
105584 +// RTX_FRAME_RELATED_P(orq) = 1; // not for ASM_OPERANDS
105585 + emit_insn_before(orq, insn);
105586 +}
105587 +
105588 +/*
105589 + * find all asm level function returns and forcibly set the highest bit of the return address
105590 + */
105591 +static unsigned int execute_kernexec_retaddr(void)
105592 +{
105593 + rtx insn;
105594 +
105595 +// if (stack_realign_drap)
105596 +// inform(DECL_SOURCE_LOCATION(current_function_decl), "drap detected in %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
105597 +
105598 + // 1. find function returns
105599 + for (insn = get_insns(); insn; insn = NEXT_INSN(insn)) {
105600 + // rtl match: (jump_insn 41 40 42 2 (return) fptr.c:42 634 {return_internal} (nil))
105601 + // (jump_insn 12 9 11 2 (parallel [ (return) (unspec [ (0) ] UNSPEC_REP) ]) fptr.c:46 635 {return_internal_long} (nil))
105602 + // (jump_insn 97 96 98 6 (simple_return) fptr.c:50 -1 (nil) -> simple_return)
105603 + rtx body;
105604 +
105605 + // is it a retn
105606 + if (!JUMP_P(insn))
105607 + continue;
105608 + body = PATTERN(insn);
105609 + if (GET_CODE(body) == PARALLEL)
105610 + body = XVECEXP(body, 0, 0);
105611 + if (!ANY_RETURN_P(body))
105612 + continue;
105613 + kernexec_instrument_retaddr(insn);
105614 + }
105615 +
105616 +// print_simple_rtl(stderr, get_insns());
105617 +// print_rtl(stderr, get_insns());
105618 +
105619 + return 0;
105620 +}
105621 +
105622 +static bool kernexec_cmodel_check(void)
105623 +{
105624 + tree section;
105625 +
105626 + if (ix86_cmodel != CM_KERNEL)
105627 + return false;
105628 +
105629 + section = lookup_attribute("section", DECL_ATTRIBUTES(current_function_decl));
105630 + if (!section || !TREE_VALUE(section))
105631 + return true;
105632 +
105633 + section = TREE_VALUE(TREE_VALUE(section));
105634 + if (strncmp(TREE_STRING_POINTER(section), ".vsyscall_", 10))
105635 + return true;
105636 +
105637 + return false;
105638 +}
105639 +
105640 +#if BUILDING_GCC_VERSION >= 4009
105641 +static const struct pass_data kernexec_reload_pass_data = {
105642 +#else
105643 +static struct gimple_opt_pass kernexec_reload_pass = {
105644 + .pass = {
105645 +#endif
105646 + .type = GIMPLE_PASS,
105647 + .name = "kernexec_reload",
105648 +#if BUILDING_GCC_VERSION >= 4008
105649 + .optinfo_flags = OPTGROUP_NONE,
105650 +#endif
105651 +#if BUILDING_GCC_VERSION >= 4009
105652 + .has_gate = true,
105653 + .has_execute = true,
105654 +#else
105655 + .gate = kernexec_cmodel_check,
105656 + .execute = execute_kernexec_reload,
105657 + .sub = NULL,
105658 + .next = NULL,
105659 + .static_pass_number = 0,
105660 +#endif
105661 + .tv_id = TV_NONE,
105662 + .properties_required = 0,
105663 + .properties_provided = 0,
105664 + .properties_destroyed = 0,
105665 + .todo_flags_start = 0,
105666 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
105667 +#if BUILDING_GCC_VERSION < 4009
105668 + }
105669 +#endif
105670 +};
105671 +
105672 +#if BUILDING_GCC_VERSION >= 4009
105673 +static const struct pass_data kernexec_fptr_pass_data = {
105674 +#else
105675 +static struct gimple_opt_pass kernexec_fptr_pass = {
105676 + .pass = {
105677 +#endif
105678 + .type = GIMPLE_PASS,
105679 + .name = "kernexec_fptr",
105680 +#if BUILDING_GCC_VERSION >= 4008
105681 + .optinfo_flags = OPTGROUP_NONE,
105682 +#endif
105683 +#if BUILDING_GCC_VERSION >= 4009
105684 + .has_gate = true,
105685 + .has_execute = true,
105686 +#else
105687 + .gate = kernexec_cmodel_check,
105688 + .execute = execute_kernexec_fptr,
105689 + .sub = NULL,
105690 + .next = NULL,
105691 + .static_pass_number = 0,
105692 +#endif
105693 + .tv_id = TV_NONE,
105694 + .properties_required = 0,
105695 + .properties_provided = 0,
105696 + .properties_destroyed = 0,
105697 + .todo_flags_start = 0,
105698 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_remove_unused_locals | TODO_update_ssa_no_phi
105699 +#if BUILDING_GCC_VERSION < 4009
105700 + }
105701 +#endif
105702 +};
105703 +
105704 +#if BUILDING_GCC_VERSION >= 4009
105705 +static const struct pass_data kernexec_retaddr_pass_data = {
105706 +#else
105707 +static struct rtl_opt_pass kernexec_retaddr_pass = {
105708 + .pass = {
105709 +#endif
105710 + .type = RTL_PASS,
105711 + .name = "kernexec_retaddr",
105712 +#if BUILDING_GCC_VERSION >= 4008
105713 + .optinfo_flags = OPTGROUP_NONE,
105714 +#endif
105715 +#if BUILDING_GCC_VERSION >= 4009
105716 + .has_gate = true,
105717 + .has_execute = true,
105718 +#else
105719 + .gate = kernexec_cmodel_check,
105720 + .execute = execute_kernexec_retaddr,
105721 + .sub = NULL,
105722 + .next = NULL,
105723 + .static_pass_number = 0,
105724 +#endif
105725 + .tv_id = TV_NONE,
105726 + .properties_required = 0,
105727 + .properties_provided = 0,
105728 + .properties_destroyed = 0,
105729 + .todo_flags_start = 0,
105730 + .todo_flags_finish = TODO_dump_func | TODO_ggc_collect
105731 +#if BUILDING_GCC_VERSION < 4009
105732 + }
105733 +#endif
105734 +};
105735 +
105736 +#if BUILDING_GCC_VERSION >= 4009
105737 +namespace {
105738 +class kernexec_reload_pass : public gimple_opt_pass {
105739 +public:
105740 + kernexec_reload_pass() : gimple_opt_pass(kernexec_reload_pass_data, g) {}
105741 + bool gate() { return kernexec_cmodel_check(); }
105742 + unsigned int execute() { return execute_kernexec_reload(); }
105743 +};
105744 +
105745 +class kernexec_fptr_pass : public gimple_opt_pass {
105746 +public:
105747 + kernexec_fptr_pass() : gimple_opt_pass(kernexec_fptr_pass_data, g) {}
105748 + bool gate() { return kernexec_cmodel_check(); }
105749 + unsigned int execute() { return execute_kernexec_fptr(); }
105750 +};
105751 +
105752 +class kernexec_retaddr_pass : public rtl_opt_pass {
105753 +public:
105754 + kernexec_retaddr_pass() : rtl_opt_pass(kernexec_retaddr_pass_data, g) {}
105755 + bool gate() { return kernexec_cmodel_check(); }
105756 + unsigned int execute() { return execute_kernexec_retaddr(); }
105757 +};
105758 +}
105759 +#endif
105760 +
105761 +static struct opt_pass *make_kernexec_reload_pass(void)
105762 +{
105763 +#if BUILDING_GCC_VERSION >= 4009
105764 + return new kernexec_reload_pass();
105765 +#else
105766 + return &kernexec_reload_pass.pass;
105767 +#endif
105768 +}
105769 +
105770 +static struct opt_pass *make_kernexec_fptr_pass(void)
105771 +{
105772 +#if BUILDING_GCC_VERSION >= 4009
105773 + return new kernexec_fptr_pass();
105774 +#else
105775 + return &kernexec_fptr_pass.pass;
105776 +#endif
105777 +}
105778 +
105779 +static struct opt_pass *make_kernexec_retaddr_pass(void)
105780 +{
105781 +#if BUILDING_GCC_VERSION >= 4009
105782 + return new kernexec_retaddr_pass();
105783 +#else
105784 + return &kernexec_retaddr_pass.pass;
105785 +#endif
105786 +}
105787 +
105788 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
105789 +{
105790 + const char * const plugin_name = plugin_info->base_name;
105791 + const int argc = plugin_info->argc;
105792 + const struct plugin_argument * const argv = plugin_info->argv;
105793 + int i;
105794 + struct register_pass_info kernexec_reload_pass_info;
105795 + struct register_pass_info kernexec_fptr_pass_info;
105796 + struct register_pass_info kernexec_retaddr_pass_info;
105797 +
105798 + kernexec_reload_pass_info.pass = make_kernexec_reload_pass();
105799 + kernexec_reload_pass_info.reference_pass_name = "ssa";
105800 + kernexec_reload_pass_info.ref_pass_instance_number = 1;
105801 + kernexec_reload_pass_info.pos_op = PASS_POS_INSERT_AFTER;
105802 +
105803 + kernexec_fptr_pass_info.pass = make_kernexec_fptr_pass();
105804 + kernexec_fptr_pass_info.reference_pass_name = "ssa";
105805 + kernexec_fptr_pass_info.ref_pass_instance_number = 1;
105806 + kernexec_fptr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
105807 +
105808 + kernexec_retaddr_pass_info.pass = make_kernexec_retaddr_pass();
105809 + kernexec_retaddr_pass_info.reference_pass_name = "pro_and_epilogue";
105810 + kernexec_retaddr_pass_info.ref_pass_instance_number = 1;
105811 + kernexec_retaddr_pass_info.pos_op = PASS_POS_INSERT_AFTER;
105812 +
105813 + if (!plugin_default_version_check(version, &gcc_version)) {
105814 + error(G_("incompatible gcc/plugin versions"));
105815 + return 1;
105816 + }
105817 +
105818 + register_callback(plugin_name, PLUGIN_INFO, NULL, &kernexec_plugin_info);
105819 +
105820 + if (TARGET_64BIT == 0)
105821 + return 0;
105822 +
105823 + for (i = 0; i < argc; ++i) {
105824 + if (!strcmp(argv[i].key, "method")) {
105825 + if (!argv[i].value) {
105826 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
105827 + continue;
105828 + }
105829 + if (!strcmp(argv[i].value, "bts")) {
105830 + kernexec_instrument_fptr = kernexec_instrument_fptr_bts;
105831 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_bts;
105832 + } else if (!strcmp(argv[i].value, "or")) {
105833 + kernexec_instrument_fptr = kernexec_instrument_fptr_or;
105834 + kernexec_instrument_retaddr = kernexec_instrument_retaddr_or;
105835 + fix_register("r12", 1, 1);
105836 + } else
105837 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
105838 + continue;
105839 + }
105840 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
105841 + }
105842 + if (!kernexec_instrument_fptr || !kernexec_instrument_retaddr)
105843 + error(G_("no instrumentation method was selected via '-fplugin-arg-%s-method'"), plugin_name);
105844 +
105845 + if (kernexec_instrument_fptr == kernexec_instrument_fptr_or)
105846 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_reload_pass_info);
105847 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_fptr_pass_info);
105848 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &kernexec_retaddr_pass_info);
105849 +
105850 + return 0;
105851 +}
105852 diff --git a/tools/gcc/latent_entropy_plugin.c b/tools/gcc/latent_entropy_plugin.c
105853 new file mode 100644
105854 index 0000000..515d689
105855 --- /dev/null
105856 +++ b/tools/gcc/latent_entropy_plugin.c
105857 @@ -0,0 +1,337 @@
105858 +/*
105859 + * Copyright 2012-2014 by the PaX Team <pageexec@freemail.hu>
105860 + * Licensed under the GPL v2
105861 + *
105862 + * Note: the choice of the license means that the compilation process is
105863 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
105864 + * but for the kernel it doesn't matter since it doesn't link against
105865 + * any of the gcc libraries
105866 + *
105867 + * gcc plugin to help generate a little bit of entropy from program state,
105868 + * used during boot in the kernel
105869 + *
105870 + * TODO:
105871 + * - add ipa pass to identify not explicitly marked candidate functions
105872 + * - mix in more program state (function arguments/return values, loop variables, etc)
105873 + * - more instrumentation control via attribute parameters
105874 + *
105875 + * BUGS:
105876 + * - LTO needs -flto-partition=none for now
105877 + */
105878 +
105879 +#include "gcc-common.h"
105880 +
105881 +int plugin_is_GPL_compatible;
105882 +
105883 +static tree latent_entropy_decl;
105884 +
105885 +static struct plugin_info latent_entropy_plugin_info = {
105886 + .version = "201402131900",
105887 + .help = NULL
105888 +};
105889 +
105890 +static unsigned HOST_WIDE_INT seed;
105891 +static unsigned HOST_WIDE_INT get_random_const(void)
105892 +{
105893 + seed = (seed >> 1U) ^ (-(seed & 1ULL) & 0xD800000000000000ULL);
105894 + return seed;
105895 +}
105896 +
105897 +static tree handle_latent_entropy_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
105898 +{
105899 + switch (TREE_CODE(*node)) {
105900 + default:
105901 + *no_add_attrs = true;
105902 + error("%qE attribute only applies to functions and variables", name);
105903 + break;
105904 +
105905 + case VAR_DECL:
105906 + if (DECL_INITIAL(*node)) {
105907 + *no_add_attrs = true;
105908 + error("variable %qD with %qE attribute must not be initialized", *node, name);
105909 + break;
105910 + }
105911 + DECL_INITIAL(*node) = build_int_cstu(long_long_unsigned_type_node, get_random_const());
105912 + break;
105913 +
105914 + case FUNCTION_DECL:
105915 + break;
105916 + }
105917 +
105918 + return NULL_TREE;
105919 +}
105920 +
105921 +static struct attribute_spec latent_entropy_attr = {
105922 + .name = "latent_entropy",
105923 + .min_length = 0,
105924 + .max_length = 0,
105925 + .decl_required = true,
105926 + .type_required = false,
105927 + .function_type_required = false,
105928 + .handler = handle_latent_entropy_attribute,
105929 +#if BUILDING_GCC_VERSION >= 4007
105930 + .affects_type_identity = false
105931 +#endif
105932 +};
105933 +
105934 +static void register_attributes(void *event_data, void *data)
105935 +{
105936 + register_attribute(&latent_entropy_attr);
105937 +}
105938 +
105939 +static bool gate_latent_entropy(void)
105940 +{
105941 + tree latent_entropy_attr;
105942 +
105943 + latent_entropy_attr = lookup_attribute("latent_entropy", DECL_ATTRIBUTES(current_function_decl));
105944 + return latent_entropy_attr != NULL_TREE;
105945 +}
105946 +
105947 +static enum tree_code get_op(tree *rhs)
105948 +{
105949 + static enum tree_code op;
105950 + unsigned HOST_WIDE_INT random_const;
105951 +
105952 + random_const = get_random_const();
105953 +
105954 + switch (op) {
105955 + case BIT_XOR_EXPR:
105956 + op = PLUS_EXPR;
105957 + break;
105958 +
105959 + case PLUS_EXPR:
105960 + if (rhs) {
105961 + op = LROTATE_EXPR;
105962 + random_const &= HOST_BITS_PER_WIDE_INT - 1;
105963 + break;
105964 + }
105965 +
105966 + case LROTATE_EXPR:
105967 + default:
105968 + op = BIT_XOR_EXPR;
105969 + break;
105970 + }
105971 + if (rhs)
105972 + *rhs = build_int_cstu(unsigned_intDI_type_node, random_const);
105973 + return op;
105974 +}
105975 +
105976 +static void perturb_local_entropy(basic_block bb, tree local_entropy)
105977 +{
105978 + gimple_stmt_iterator gsi;
105979 + gimple assign;
105980 + tree addxorrol, rhs;
105981 + enum tree_code op;
105982 +
105983 + op = get_op(&rhs);
105984 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, op, unsigned_intDI_type_node, local_entropy, rhs);
105985 + assign = gimple_build_assign(local_entropy, addxorrol);
105986 + gsi = gsi_after_labels(bb);
105987 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
105988 + update_stmt(assign);
105989 +//debug_bb(bb);
105990 +}
105991 +
105992 +static void perturb_latent_entropy(basic_block bb, tree rhs)
105993 +{
105994 + gimple_stmt_iterator gsi;
105995 + gimple assign;
105996 + tree addxorrol, temp;
105997 +
105998 + // 1. create temporary copy of latent_entropy
105999 + temp = create_tmp_var(unsigned_intDI_type_node, "temp_latent_entropy");
106000 + add_referenced_var(temp);
106001 +
106002 + // 2. read...
106003 + temp = make_ssa_name(temp, NULL);
106004 + assign = gimple_build_assign(temp, latent_entropy_decl);
106005 + SSA_NAME_DEF_STMT(temp) = assign;
106006 + add_referenced_var(latent_entropy_decl);
106007 + gsi = gsi_after_labels(bb);
106008 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
106009 + update_stmt(assign);
106010 +
106011 + // 3. ...modify...
106012 + addxorrol = fold_build2_loc(UNKNOWN_LOCATION, get_op(NULL), unsigned_intDI_type_node, temp, rhs);
106013 + temp = make_ssa_name(SSA_NAME_VAR(temp), NULL);
106014 + assign = gimple_build_assign(temp, addxorrol);
106015 + SSA_NAME_DEF_STMT(temp) = assign;
106016 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
106017 + update_stmt(assign);
106018 +
106019 + // 4. ...write latent_entropy
106020 + assign = gimple_build_assign(latent_entropy_decl, temp);
106021 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
106022 + update_stmt(assign);
106023 +}
106024 +
106025 +static unsigned int execute_latent_entropy(void)
106026 +{
106027 + basic_block bb;
106028 + gimple assign;
106029 + gimple_stmt_iterator gsi;
106030 + tree local_entropy;
106031 +
106032 + if (!latent_entropy_decl) {
106033 + struct varpool_node *node;
106034 +
106035 + FOR_EACH_VARIABLE(node) {
106036 + tree var = NODE_DECL(node);
106037 +
106038 + if (strcmp(IDENTIFIER_POINTER(DECL_NAME(var)), "latent_entropy"))
106039 + continue;
106040 + latent_entropy_decl = var;
106041 +// debug_tree(var);
106042 + break;
106043 + }
106044 + if (!latent_entropy_decl) {
106045 +// debug_tree(current_function_decl);
106046 + return 0;
106047 + }
106048 + }
106049 +
106050 +//fprintf(stderr, "latent_entropy: %s\n", IDENTIFIER_POINTER(DECL_NAME(current_function_decl)));
106051 +
106052 + // 1. create local entropy variable
106053 + local_entropy = create_tmp_var(unsigned_intDI_type_node, "local_entropy");
106054 + add_referenced_var(local_entropy);
106055 + mark_sym_for_renaming(local_entropy);
106056 +
106057 + // 2. initialize local entropy variable
106058 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
106059 + if (dom_info_available_p(CDI_DOMINATORS))
106060 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
106061 + gsi = gsi_start_bb(bb);
106062 +
106063 + assign = gimple_build_assign(local_entropy, build_int_cstu(unsigned_intDI_type_node, get_random_const()));
106064 +// gimple_set_location(assign, loc);
106065 + gsi_insert_after(&gsi, assign, GSI_NEW_STMT);
106066 + update_stmt(assign);
106067 +//debug_bb(bb);
106068 + bb = bb->next_bb;
106069 +
106070 + // 3. instrument each BB with an operation on the local entropy variable
106071 + while (bb != EXIT_BLOCK_PTR_FOR_FN(cfun)) {
106072 + perturb_local_entropy(bb, local_entropy);
106073 +//debug_bb(bb);
106074 + bb = bb->next_bb;
106075 + };
106076 +
106077 + // 4. mix local entropy into the global entropy variable
106078 + perturb_latent_entropy(EXIT_BLOCK_PTR_FOR_FN(cfun)->prev_bb, local_entropy);
106079 +//debug_bb(EXIT_BLOCK_PTR_FOR_FN(cfun)->prev_bb);
106080 + return 0;
106081 +}
106082 +
106083 +static void latent_entropy_start_unit(void *gcc_data, void *user_data)
106084 +{
106085 + tree latent_entropy_type;
106086 +
106087 + seed = get_random_seed(false);
106088 +
106089 + if (in_lto_p)
106090 + return;
106091 +
106092 + // extern volatile u64 latent_entropy
106093 + gcc_assert(TYPE_PRECISION(long_long_unsigned_type_node) == 64);
106094 + latent_entropy_type = build_qualified_type(long_long_unsigned_type_node, TYPE_QUALS(long_long_unsigned_type_node) | TYPE_QUAL_VOLATILE);
106095 + latent_entropy_decl = build_decl(UNKNOWN_LOCATION, VAR_DECL, get_identifier("latent_entropy"), latent_entropy_type);
106096 +
106097 + TREE_STATIC(latent_entropy_decl) = 1;
106098 + TREE_PUBLIC(latent_entropy_decl) = 1;
106099 + TREE_USED(latent_entropy_decl) = 1;
106100 + TREE_THIS_VOLATILE(latent_entropy_decl) = 1;
106101 + DECL_EXTERNAL(latent_entropy_decl) = 1;
106102 + DECL_ARTIFICIAL(latent_entropy_decl) = 1;
106103 + lang_hooks.decls.pushdecl(latent_entropy_decl);
106104 +// DECL_ASSEMBLER_NAME(latent_entropy_decl);
106105 +// varpool_finalize_decl(latent_entropy_decl);
106106 +// varpool_mark_needed_node(latent_entropy_decl);
106107 +}
106108 +
106109 +#if BUILDING_GCC_VERSION >= 4009
106110 +static const struct pass_data latent_entropy_pass_data = {
106111 +#else
106112 +static struct gimple_opt_pass latent_entropy_pass = {
106113 + .pass = {
106114 +#endif
106115 + .type = GIMPLE_PASS,
106116 + .name = "latent_entropy",
106117 +#if BUILDING_GCC_VERSION >= 4008
106118 + .optinfo_flags = OPTGROUP_NONE,
106119 +#endif
106120 +#if BUILDING_GCC_VERSION >= 4009
106121 + .has_gate = true,
106122 + .has_execute = true,
106123 +#else
106124 + .gate = gate_latent_entropy,
106125 + .execute = execute_latent_entropy,
106126 + .sub = NULL,
106127 + .next = NULL,
106128 + .static_pass_number = 0,
106129 +#endif
106130 + .tv_id = TV_NONE,
106131 + .properties_required = PROP_gimple_leh | PROP_cfg,
106132 + .properties_provided = 0,
106133 + .properties_destroyed = 0,
106134 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
106135 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
106136 +#if BUILDING_GCC_VERSION < 4009
106137 + }
106138 +#endif
106139 +};
106140 +
106141 +#if BUILDING_GCC_VERSION >= 4009
106142 +namespace {
106143 +class latent_entropy_pass : public gimple_opt_pass {
106144 +public:
106145 + latent_entropy_pass() : gimple_opt_pass(latent_entropy_pass_data, g) {}
106146 + bool gate() { return gate_latent_entropy(); }
106147 + unsigned int execute() { return execute_latent_entropy(); }
106148 +};
106149 +}
106150 +#endif
106151 +
106152 +static struct opt_pass *make_latent_entropy_pass(void)
106153 +{
106154 +#if BUILDING_GCC_VERSION >= 4009
106155 + return new latent_entropy_pass();
106156 +#else
106157 + return &latent_entropy_pass.pass;
106158 +#endif
106159 +}
106160 +
106161 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
106162 +{
106163 + const char * const plugin_name = plugin_info->base_name;
106164 + struct register_pass_info latent_entropy_pass_info;
106165 +
106166 + latent_entropy_pass_info.pass = make_latent_entropy_pass();
106167 + latent_entropy_pass_info.reference_pass_name = "optimized";
106168 + latent_entropy_pass_info.ref_pass_instance_number = 1;
106169 + latent_entropy_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
106170 + static const struct ggc_root_tab gt_ggc_r_gt_latent_entropy[] = {
106171 + {
106172 + .base = &latent_entropy_decl,
106173 + .nelt = 1,
106174 + .stride = sizeof(latent_entropy_decl),
106175 + .cb = &gt_ggc_mx_tree_node,
106176 + .pchw = &gt_pch_nx_tree_node
106177 + },
106178 + LAST_GGC_ROOT_TAB
106179 + };
106180 +
106181 + if (!plugin_default_version_check(version, &gcc_version)) {
106182 + error(G_("incompatible gcc/plugin versions"));
106183 + return 1;
106184 + }
106185 +
106186 + register_callback(plugin_name, PLUGIN_INFO, NULL, &latent_entropy_plugin_info);
106187 + register_callback(plugin_name, PLUGIN_START_UNIT, &latent_entropy_start_unit, NULL);
106188 + if (!in_lto_p)
106189 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_latent_entropy);
106190 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &latent_entropy_pass_info);
106191 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
106192 +
106193 + return 0;
106194 +}
106195 diff --git a/tools/gcc/randomize_layout_plugin.c b/tools/gcc/randomize_layout_plugin.c
106196 new file mode 100644
106197 index 0000000..bc490ca
106198 --- /dev/null
106199 +++ b/tools/gcc/randomize_layout_plugin.c
106200 @@ -0,0 +1,906 @@
106201 +/*
106202 + * Copyright 2014 by Open Source Security, Inc., Brad Spengler <spender@grsecurity.net>
106203 + * and PaX Team <pageexec@freemail.hu>
106204 + * Licensed under the GPL v2
106205 + *
106206 + * Usage:
106207 + * $ # for 4.5/4.6/C based 4.7
106208 + * $ 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
106209 + * $ # for C++ based 4.7/4.8+
106210 + * $ 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
106211 + * $ gcc -fplugin=./randomize_layout_plugin.so test.c -O2
106212 + */
106213 +
106214 +#include "gcc-common.h"
106215 +#include "randomize_layout_seed.h"
106216 +
106217 +#if BUILDING_GCC_MAJOR < 4 || BUILDING_GCC_MINOR < 6 || (BUILDING_GCC_MINOR == 6 && BUILDING_GCC_PATCHLEVEL < 4)
106218 +#error "The RANDSTRUCT plugin requires GCC 4.6.4 or newer."
106219 +#endif
106220 +
106221 +#define ORIG_TYPE_NAME(node) \
106222 + (TYPE_NAME(TYPE_MAIN_VARIANT(node)) != NULL_TREE ? ((const unsigned char *)IDENTIFIER_POINTER(TYPE_NAME(TYPE_MAIN_VARIANT(node)))) : (const unsigned char *)"anonymous")
106223 +
106224 +int plugin_is_GPL_compatible;
106225 +
106226 +static int performance_mode;
106227 +
106228 +static struct plugin_info randomize_layout_plugin_info = {
106229 + .version = "201402061950",
106230 + .help = "disable\t\t\tdo not activate plugin\n"
106231 + "performance-mode\tenable cacheline-aware layout randomization\n"
106232 +};
106233 +
106234 +/* from old Linux dcache.h */
106235 +static inline unsigned long
106236 +partial_name_hash(unsigned long c, unsigned long prevhash)
106237 +{
106238 + return (prevhash + (c << 4) + (c >> 4)) * 11;
106239 +}
106240 +static inline unsigned int
106241 +name_hash(const unsigned char *name)
106242 +{
106243 + unsigned long hash = 0;
106244 + unsigned int len = strlen((const char *)name);
106245 + while (len--)
106246 + hash = partial_name_hash(*name++, hash);
106247 + return (unsigned int)hash;
106248 +}
106249 +
106250 +static tree handle_randomize_layout_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
106251 +{
106252 + tree type;
106253 +
106254 + *no_add_attrs = true;
106255 + if (TREE_CODE(*node) == FUNCTION_DECL) {
106256 + error("%qE attribute does not apply to functions (%qF)", name, *node);
106257 + return NULL_TREE;
106258 + }
106259 +
106260 + if (TREE_CODE(*node) == PARM_DECL) {
106261 + error("%qE attribute does not apply to function parameters (%qD)", name, *node);
106262 + return NULL_TREE;
106263 + }
106264 +
106265 + if (TREE_CODE(*node) == VAR_DECL) {
106266 + error("%qE attribute does not apply to variables (%qD)", name, *node);
106267 + return NULL_TREE;
106268 + }
106269 +
106270 + if (TYPE_P(*node)) {
106271 + type = *node;
106272 + } else {
106273 + gcc_assert(TREE_CODE(*node) == TYPE_DECL);
106274 + type = TREE_TYPE(*node);
106275 + }
106276 +
106277 + if (TREE_CODE(type) != RECORD_TYPE) {
106278 + error("%qE attribute used on %qT applies to struct types only", name, type);
106279 + return NULL_TREE;
106280 + }
106281 +
106282 + if (lookup_attribute(IDENTIFIER_POINTER(name), TYPE_ATTRIBUTES(type))) {
106283 + error("%qE attribute is already applied to the type %qT", name, type);
106284 + return NULL_TREE;
106285 + }
106286 +
106287 + *no_add_attrs = false;
106288 +
106289 + return NULL_TREE;
106290 +}
106291 +
106292 +/* set on complete types that we don't need to inspect further at all */
106293 +static tree handle_randomize_considered_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
106294 +{
106295 + *no_add_attrs = false;
106296 + return NULL_TREE;
106297 +}
106298 +
106299 +/*
106300 + * set on types that we've performed a shuffle on, to prevent re-shuffling
106301 + * this does not preclude us from inspecting its fields for potential shuffles
106302 + */
106303 +static tree handle_randomize_performed_attr(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
106304 +{
106305 + *no_add_attrs = false;
106306 + return NULL_TREE;
106307 +}
106308 +
106309 +/*
106310 + * 64bit variant of Bob Jenkins' public domain PRNG
106311 + * 256 bits of internal state
106312 + */
106313 +
106314 +typedef unsigned long long u64;
106315 +
106316 +typedef struct ranctx { u64 a; u64 b; u64 c; u64 d; } ranctx;
106317 +
106318 +#define rot(x,k) (((x)<<(k))|((x)>>(64-(k))))
106319 +static u64 ranval(ranctx *x) {
106320 + u64 e = x->a - rot(x->b, 7);
106321 + x->a = x->b ^ rot(x->c, 13);
106322 + x->b = x->c + rot(x->d, 37);
106323 + x->c = x->d + e;
106324 + x->d = e + x->a;
106325 + return x->d;
106326 +}
106327 +
106328 +static void raninit(ranctx *x, u64 *seed) {
106329 + int i;
106330 +
106331 + x->a = seed[0];
106332 + x->b = seed[1];
106333 + x->c = seed[2];
106334 + x->d = seed[3];
106335 +
106336 + for (i=0; i < 30; ++i)
106337 + (void)ranval(x);
106338 +}
106339 +
106340 +static u64 shuffle_seed[4];
106341 +
106342 +struct partition_group {
106343 + tree tree_start;
106344 + unsigned long start;
106345 + unsigned long length;
106346 +};
106347 +
106348 +static void partition_struct(tree *fields, unsigned long length, struct partition_group *size_groups, unsigned long *num_groups)
106349 +{
106350 + unsigned long i;
106351 + unsigned long accum_size = 0;
106352 + unsigned long accum_length = 0;
106353 + unsigned long group_idx = 0;
106354 +
106355 + gcc_assert(length < INT_MAX);
106356 +
106357 + memset(size_groups, 0, sizeof(struct partition_group) * length);
106358 +
106359 + for (i = 0; i < length; i++) {
106360 + if (size_groups[group_idx].tree_start == NULL_TREE) {
106361 + size_groups[group_idx].tree_start = fields[i];
106362 + size_groups[group_idx].start = i;
106363 + accum_length = 0;
106364 + accum_size = 0;
106365 + }
106366 + accum_size += (unsigned long)int_size_in_bytes(TREE_TYPE(fields[i]));
106367 + accum_length++;
106368 + if (accum_size >= 64) {
106369 + size_groups[group_idx].length = accum_length;
106370 + accum_length = 0;
106371 + group_idx++;
106372 + }
106373 + }
106374 +
106375 + if (size_groups[group_idx].tree_start != NULL_TREE &&
106376 + !size_groups[group_idx].length) {
106377 + size_groups[group_idx].length = accum_length;
106378 + group_idx++;
106379 + }
106380 +
106381 + *num_groups = group_idx;
106382 +}
106383 +
106384 +static void performance_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
106385 +{
106386 + unsigned long i, x;
106387 + struct partition_group size_group[length];
106388 + unsigned long num_groups = 0;
106389 + unsigned long randnum;
106390 +
106391 + partition_struct(newtree, length, (struct partition_group *)&size_group, &num_groups);
106392 + for (i = num_groups - 1; i > 0; i--) {
106393 + struct partition_group tmp;
106394 + randnum = ranval(prng_state) % (i + 1);
106395 + tmp = size_group[i];
106396 + size_group[i] = size_group[randnum];
106397 + size_group[randnum] = tmp;
106398 + }
106399 +
106400 + for (x = 0; x < num_groups; x++) {
106401 + for (i = size_group[x].start + size_group[x].length - 1; i > size_group[x].start; i--) {
106402 + tree tmp;
106403 + if (DECL_BIT_FIELD_TYPE(newtree[i]))
106404 + continue;
106405 + randnum = ranval(prng_state) % (i + 1);
106406 + // we could handle this case differently if desired
106407 + if (DECL_BIT_FIELD_TYPE(newtree[randnum]))
106408 + continue;
106409 + tmp = newtree[i];
106410 + newtree[i] = newtree[randnum];
106411 + newtree[randnum] = tmp;
106412 + }
106413 + }
106414 +}
106415 +
106416 +static void full_shuffle(tree *newtree, unsigned long length, ranctx *prng_state)
106417 +{
106418 + unsigned long i, randnum;
106419 +
106420 + for (i = length - 1; i > 0; i--) {
106421 + tree tmp;
106422 + randnum = ranval(prng_state) % (i + 1);
106423 + tmp = newtree[i];
106424 + newtree[i] = newtree[randnum];
106425 + newtree[randnum] = tmp;
106426 + }
106427 +}
106428 +
106429 +/* modern in-place Fisher-Yates shuffle */
106430 +static void shuffle(const_tree type, tree *newtree, unsigned long length)
106431 +{
106432 + unsigned long i;
106433 + u64 seed[4];
106434 + ranctx prng_state;
106435 + const unsigned char *structname;
106436 +
106437 + if (length == 0)
106438 + return;
106439 +
106440 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
106441 +
106442 + structname = ORIG_TYPE_NAME(type);
106443 +
106444 +#ifdef __DEBUG_PLUGIN
106445 + fprintf(stderr, "Shuffling struct %s %p\n", (const char *)structname, type);
106446 +#ifdef __DEBUG_VERBOSE
106447 + debug_tree((tree)type);
106448 +#endif
106449 +#endif
106450 +
106451 + for (i = 0; i < 4; i++) {
106452 + seed[i] = shuffle_seed[i];
106453 + seed[i] ^= name_hash(structname);
106454 + }
106455 +
106456 + raninit(&prng_state, (u64 *)&seed);
106457 +
106458 + if (performance_mode)
106459 + performance_shuffle(newtree, length, &prng_state);
106460 + else
106461 + full_shuffle(newtree, length, &prng_state);
106462 +}
106463 +
106464 +static bool is_flexible_array(const_tree field)
106465 +{
106466 + const_tree fieldtype;
106467 + const_tree typesize;
106468 + const_tree elemtype;
106469 + const_tree elemsize;
106470 +
106471 + fieldtype = TREE_TYPE(field);
106472 + typesize = TYPE_SIZE(fieldtype);
106473 +
106474 + if (TREE_CODE(fieldtype) != ARRAY_TYPE)
106475 + return false;
106476 +
106477 + elemtype = TREE_TYPE(fieldtype);
106478 + elemsize = TYPE_SIZE(elemtype);
106479 +
106480 + /* size of type is represented in bits */
106481 +
106482 + if (typesize == NULL_TREE && TYPE_DOMAIN(fieldtype) != NULL_TREE &&
106483 + TYPE_MAX_VALUE(TYPE_DOMAIN(fieldtype)) == NULL_TREE)
106484 + return true;
106485 +
106486 + if (typesize != NULL_TREE &&
106487 + (TREE_CONSTANT(typesize) && (!TREE_INT_CST_LOW(typesize) ||
106488 + TREE_INT_CST_LOW(typesize) == TREE_INT_CST_LOW(elemsize))))
106489 + return true;
106490 +
106491 + return false;
106492 +}
106493 +
106494 +static int relayout_struct(tree type)
106495 +{
106496 + unsigned long num_fields = (unsigned long)list_length(TYPE_FIELDS(type));
106497 + unsigned long shuffle_length = num_fields;
106498 + tree field;
106499 + tree newtree[num_fields];
106500 + unsigned long i;
106501 + tree list;
106502 + tree variant;
106503 + expanded_location xloc;
106504 +
106505 + if (TYPE_FIELDS(type) == NULL_TREE)
106506 + return 0;
106507 +
106508 + if (num_fields < 2)
106509 + return 0;
106510 +
106511 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
106512 +
106513 + gcc_assert(num_fields < INT_MAX);
106514 +
106515 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)) ||
106516 + lookup_attribute("no_randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))))
106517 + return 0;
106518 +
106519 + /* throw out any structs in uapi */
106520 + xloc = expand_location(DECL_SOURCE_LOCATION(TYPE_FIELDS(type)));
106521 +
106522 + if (strstr(xloc.file, "/uapi/"))
106523 + error(G_("attempted to randomize userland API struct %s"), ORIG_TYPE_NAME(type));
106524 +
106525 + for (field = TYPE_FIELDS(type), i = 0; field; field = TREE_CHAIN(field), i++) {
106526 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
106527 + newtree[i] = field;
106528 + }
106529 +
106530 + /*
106531 + * enforce that we don't randomize the layout of the last
106532 + * element of a struct if it's a 0 or 1-length array
106533 + * or a proper flexible array
106534 + */
106535 + if (is_flexible_array(newtree[num_fields - 1]))
106536 + shuffle_length--;
106537 +
106538 + shuffle(type, (tree *)newtree, shuffle_length);
106539 +
106540 + /*
106541 + * set up a bogus anonymous struct field designed to error out on unnamed struct initializers
106542 + * as gcc provides no other way to detect such code
106543 + */
106544 + list = make_node(FIELD_DECL);
106545 + TREE_CHAIN(list) = newtree[0];
106546 + TREE_TYPE(list) = void_type_node;
106547 + DECL_SIZE(list) = bitsize_zero_node;
106548 + DECL_NONADDRESSABLE_P(list) = 1;
106549 + DECL_FIELD_BIT_OFFSET(list) = bitsize_zero_node;
106550 + DECL_SIZE_UNIT(list) = size_zero_node;
106551 + DECL_FIELD_OFFSET(list) = size_zero_node;
106552 + // to satisfy the constify plugin
106553 + TREE_READONLY(list) = 1;
106554 +
106555 + for (i = 0; i < num_fields - 1; i++)
106556 + TREE_CHAIN(newtree[i]) = newtree[i+1];
106557 + TREE_CHAIN(newtree[num_fields - 1]) = NULL_TREE;
106558 +
106559 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
106560 + TYPE_FIELDS(variant) = list;
106561 + TYPE_ATTRIBUTES(variant) = copy_list(TYPE_ATTRIBUTES(variant));
106562 + TYPE_ATTRIBUTES(variant) = tree_cons(get_identifier("randomize_performed"), NULL_TREE, TYPE_ATTRIBUTES(variant));
106563 + // force a re-layout
106564 + TYPE_SIZE(variant) = NULL_TREE;
106565 + layout_type(variant);
106566 + }
106567 +
106568 + return 1;
106569 +}
106570 +
106571 +/* from constify plugin */
106572 +static const_tree get_field_type(const_tree field)
106573 +{
106574 + return strip_array_types(TREE_TYPE(field));
106575 +}
106576 +
106577 +/* from constify plugin */
106578 +static bool is_fptr(const_tree fieldtype)
106579 +{
106580 + if (TREE_CODE(fieldtype) != POINTER_TYPE)
106581 + return false;
106582 +
106583 + return TREE_CODE(TREE_TYPE(fieldtype)) == FUNCTION_TYPE;
106584 +}
106585 +
106586 +/* derived from constify plugin */
106587 +static int is_pure_ops_struct(const_tree node)
106588 +{
106589 + const_tree field;
106590 +
106591 + gcc_assert(TREE_CODE(node) == RECORD_TYPE || TREE_CODE(node) == UNION_TYPE);
106592 +
106593 + for (field = TYPE_FIELDS(node); field; field = TREE_CHAIN(field)) {
106594 + const_tree fieldtype = get_field_type(field);
106595 + enum tree_code code = TREE_CODE(fieldtype);
106596 +
106597 + if (node == fieldtype)
106598 + continue;
106599 +
106600 + if (!is_fptr(fieldtype))
106601 + return 0;
106602 +
106603 + if (code != RECORD_TYPE && code != UNION_TYPE)
106604 + continue;
106605 +
106606 + if (!is_pure_ops_struct(fieldtype))
106607 + return 0;
106608 + }
106609 +
106610 + return 1;
106611 +}
106612 +
106613 +static void randomize_type(tree type)
106614 +{
106615 + tree variant;
106616 +
106617 + gcc_assert(TREE_CODE(type) == RECORD_TYPE);
106618 +
106619 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
106620 + return;
106621 +
106622 + if (lookup_attribute("randomize_layout", TYPE_ATTRIBUTES(TYPE_MAIN_VARIANT(type))) || is_pure_ops_struct(type))
106623 + relayout_struct(type);
106624 +
106625 + for (variant = TYPE_MAIN_VARIANT(type); variant; variant = TYPE_NEXT_VARIANT(variant)) {
106626 + TYPE_ATTRIBUTES(type) = copy_list(TYPE_ATTRIBUTES(type));
106627 + TYPE_ATTRIBUTES(type) = tree_cons(get_identifier("randomize_considered"), NULL_TREE, TYPE_ATTRIBUTES(type));
106628 + }
106629 +#ifdef __DEBUG_PLUGIN
106630 + fprintf(stderr, "Marking randomize_considered on struct %s\n", ORIG_TYPE_NAME(type));
106631 +#ifdef __DEBUG_VERBOSE
106632 + debug_tree(type);
106633 +#endif
106634 +#endif
106635 +}
106636 +
106637 +static void randomize_layout_finish_decl(void *event_data, void *data)
106638 +{
106639 + tree decl = (tree)event_data;
106640 + tree type;
106641 +
106642 + if (decl == NULL_TREE || decl == error_mark_node)
106643 + return;
106644 +
106645 + type = TREE_TYPE(decl);
106646 +
106647 + if (TREE_CODE(decl) != VAR_DECL)
106648 + return;
106649 +
106650 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
106651 + return;
106652 +
106653 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(type)))
106654 + return;
106655 +
106656 + relayout_decl(decl);
106657 +}
106658 +
106659 +static void finish_type(void *event_data, void *data)
106660 +{
106661 + tree type = (tree)event_data;
106662 +
106663 + if (type == NULL_TREE || type == error_mark_node)
106664 + return;
106665 +
106666 + if (TREE_CODE(type) != RECORD_TYPE)
106667 + return;
106668 +
106669 + if (TYPE_FIELDS(type) == NULL_TREE)
106670 + return;
106671 +
106672 + if (lookup_attribute("randomize_considered", TYPE_ATTRIBUTES(type)))
106673 + return;
106674 +
106675 +#ifdef __DEBUG_PLUGIN
106676 + fprintf(stderr, "Calling randomize_type on %s\n", ORIG_TYPE_NAME(type));
106677 +#endif
106678 +#ifdef __DEBUG_VERBOSE
106679 + debug_tree(type);
106680 +#endif
106681 + randomize_type(type);
106682 +
106683 + return;
106684 +}
106685 +
106686 +static struct attribute_spec randomize_layout_attr = {
106687 + .name = "randomize_layout",
106688 + // related to args
106689 + .min_length = 0,
106690 + .max_length = 0,
106691 + .decl_required = false,
106692 + // need type declaration
106693 + .type_required = true,
106694 + .function_type_required = false,
106695 + .handler = handle_randomize_layout_attr,
106696 +#if BUILDING_GCC_VERSION >= 4007
106697 + .affects_type_identity = true
106698 +#endif
106699 +};
106700 +
106701 +static struct attribute_spec no_randomize_layout_attr = {
106702 + .name = "no_randomize_layout",
106703 + // related to args
106704 + .min_length = 0,
106705 + .max_length = 0,
106706 + .decl_required = false,
106707 + // need type declaration
106708 + .type_required = true,
106709 + .function_type_required = false,
106710 + .handler = handle_randomize_layout_attr,
106711 +#if BUILDING_GCC_VERSION >= 4007
106712 + .affects_type_identity = true
106713 +#endif
106714 +};
106715 +
106716 +static struct attribute_spec randomize_considered_attr = {
106717 + .name = "randomize_considered",
106718 + // related to args
106719 + .min_length = 0,
106720 + .max_length = 0,
106721 + .decl_required = false,
106722 + // need type declaration
106723 + .type_required = true,
106724 + .function_type_required = false,
106725 + .handler = handle_randomize_considered_attr,
106726 +#if BUILDING_GCC_VERSION >= 4007
106727 + .affects_type_identity = false
106728 +#endif
106729 +};
106730 +
106731 +static struct attribute_spec randomize_performed_attr = {
106732 + .name = "randomize_performed",
106733 + // related to args
106734 + .min_length = 0,
106735 + .max_length = 0,
106736 + .decl_required = false,
106737 + // need type declaration
106738 + .type_required = true,
106739 + .function_type_required = false,
106740 + .handler = handle_randomize_performed_attr,
106741 +#if BUILDING_GCC_VERSION >= 4007
106742 + .affects_type_identity = false
106743 +#endif
106744 +};
106745 +
106746 +static void register_attributes(void *event_data, void *data)
106747 +{
106748 + register_attribute(&randomize_layout_attr);
106749 + register_attribute(&no_randomize_layout_attr);
106750 + register_attribute(&randomize_considered_attr);
106751 + register_attribute(&randomize_performed_attr);
106752 +}
106753 +
106754 +static void check_bad_casts_in_constructor(tree var, tree init)
106755 +{
106756 + unsigned HOST_WIDE_INT idx;
106757 + tree field, val;
106758 + tree field_type, val_type;
106759 +
106760 + FOR_EACH_CONSTRUCTOR_ELT(CONSTRUCTOR_ELTS(init), idx, field, val) {
106761 + if (TREE_CODE(val) == CONSTRUCTOR) {
106762 + check_bad_casts_in_constructor(var, val);
106763 + continue;
106764 + }
106765 +
106766 + field_type = TREE_TYPE(field);
106767 + val_type = TREE_TYPE(val);
106768 +
106769 + if (TREE_CODE(field_type) != POINTER_TYPE || TREE_CODE(val_type) != POINTER_TYPE)
106770 + continue;
106771 +
106772 + if (field_type == val_type)
106773 + continue;
106774 +
106775 + field_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(field_type))));
106776 + val_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(val_type))));
106777 +
106778 + if (field_type == void_type_node)
106779 + continue;
106780 + if (field_type == val_type)
106781 + continue;
106782 + if (TREE_CODE(val_type) != RECORD_TYPE)
106783 + continue;
106784 +
106785 + if (!lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(val_type)))
106786 + continue;
106787 + inform(DECL_SOURCE_LOCATION(var), "found mismatched struct pointer types: %qT and %qT\n", TYPE_MAIN_VARIANT(field_type), TYPE_MAIN_VARIANT(val_type));
106788 + }
106789 +}
106790 +
106791 +/* derived from the constify plugin */
106792 +static void check_global_variables(void *event_data, void *data)
106793 +{
106794 + struct varpool_node *node;
106795 + tree init;
106796 +
106797 + FOR_EACH_VARIABLE(node) {
106798 + tree var = NODE_DECL(node);
106799 + init = DECL_INITIAL(var);
106800 + if (init == NULL_TREE)
106801 + continue;
106802 +
106803 + if (TREE_CODE(init) != CONSTRUCTOR)
106804 + continue;
106805 +
106806 + check_bad_casts_in_constructor(var, init);
106807 + }
106808 +}
106809 +
106810 +static bool dominated_by_is_err(const_tree rhs, basic_block bb)
106811 +{
106812 + basic_block dom;
106813 + gimple dom_stmt;
106814 + gimple call_stmt;
106815 + const_tree dom_lhs;
106816 + const_tree poss_is_err_cond;
106817 + const_tree poss_is_err_func;
106818 + const_tree is_err_arg;
106819 +
106820 + dom = get_immediate_dominator(CDI_DOMINATORS, bb);
106821 + if (!dom)
106822 + return false;
106823 +
106824 + dom_stmt = last_stmt(dom);
106825 + if (!dom_stmt)
106826 + return false;
106827 +
106828 + if (gimple_code(dom_stmt) != GIMPLE_COND)
106829 + return false;
106830 +
106831 + if (gimple_cond_code(dom_stmt) != NE_EXPR)
106832 + return false;
106833 +
106834 + if (!integer_zerop(gimple_cond_rhs(dom_stmt)))
106835 + return false;
106836 +
106837 + poss_is_err_cond = gimple_cond_lhs(dom_stmt);
106838 +
106839 + if (TREE_CODE(poss_is_err_cond) != SSA_NAME)
106840 + return false;
106841 +
106842 + call_stmt = SSA_NAME_DEF_STMT(poss_is_err_cond);
106843 +
106844 + if (gimple_code(call_stmt) != GIMPLE_CALL)
106845 + return false;
106846 +
106847 + dom_lhs = gimple_get_lhs(call_stmt);
106848 + poss_is_err_func = gimple_call_fndecl(call_stmt);
106849 + if (!poss_is_err_func)
106850 + return false;
106851 + if (dom_lhs != poss_is_err_cond)
106852 + return false;
106853 + if (strcmp(DECL_NAME_POINTER(poss_is_err_func), "IS_ERR"))
106854 + return false;
106855 +
106856 + is_err_arg = gimple_call_arg(call_stmt, 0);
106857 + if (!is_err_arg)
106858 + return false;
106859 +
106860 + if (is_err_arg != rhs)
106861 + return false;
106862 +
106863 + return true;
106864 +}
106865 +
106866 +static void handle_local_var_initializers(void)
106867 +{
106868 + tree var;
106869 + unsigned int i;
106870 +
106871 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
106872 + tree init = DECL_INITIAL(var);
106873 + if (!init)
106874 + continue;
106875 + if (TREE_CODE(init) != CONSTRUCTOR)
106876 + continue;
106877 + check_bad_casts_in_constructor(var, init);
106878 + }
106879 +}
106880 +
106881 +/*
106882 + * iterate over all statements to find "bad" casts:
106883 + * those where the address of the start of a structure is cast
106884 + * to a pointer of a structure of a different type, or a
106885 + * structure pointer type is cast to a different structure pointer type
106886 + */
106887 +static unsigned int find_bad_casts(void)
106888 +{
106889 + basic_block bb;
106890 +
106891 + handle_local_var_initializers();
106892 +
106893 + FOR_ALL_BB_FN(bb, cfun) {
106894 + gimple_stmt_iterator gsi;
106895 +
106896 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
106897 + gimple stmt;
106898 + const_tree lhs;
106899 + const_tree lhs_type;
106900 + const_tree rhs1;
106901 + const_tree rhs_type;
106902 + const_tree ptr_lhs_type;
106903 + const_tree ptr_rhs_type;
106904 + const_tree op0;
106905 + const_tree op0_type;
106906 + enum tree_code rhs_code;
106907 +
106908 + stmt = gsi_stmt(gsi);
106909 +
106910 +#ifdef __DEBUG_PLUGIN
106911 +#ifdef __DEBUG_VERBOSE
106912 + debug_gimple_stmt(stmt);
106913 + debug_tree(gimple_get_lhs(stmt));
106914 +#endif
106915 +#endif
106916 +
106917 + if (gimple_code(stmt) != GIMPLE_ASSIGN)
106918 + continue;
106919 +
106920 +#ifdef __DEBUG_PLUGIN
106921 +#ifdef __DEBUG_VERBOSE
106922 + debug_tree(gimple_assign_rhs1(stmt));
106923 +#endif
106924 +#endif
106925 +
106926 + rhs_code = gimple_assign_rhs_code(stmt);
106927 +
106928 + if (rhs_code != ADDR_EXPR && rhs_code != SSA_NAME)
106929 + continue;
106930 +
106931 + lhs = gimple_get_lhs(stmt);
106932 + lhs_type = TREE_TYPE(lhs);
106933 + rhs1 = gimple_assign_rhs1(stmt);
106934 + rhs_type = TREE_TYPE(rhs1);
106935 +
106936 + if (TREE_CODE(rhs_type) != POINTER_TYPE ||
106937 + TREE_CODE(lhs_type) != POINTER_TYPE)
106938 + continue;
106939 +
106940 + ptr_lhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(lhs_type))));
106941 + ptr_rhs_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(rhs_type))));
106942 +
106943 + if (ptr_rhs_type == void_type_node)
106944 + continue;
106945 +
106946 + if (ptr_lhs_type == void_type_node)
106947 + continue;
106948 +
106949 + if (dominated_by_is_err(rhs1, bb))
106950 + continue;
106951 +
106952 + if (TREE_CODE(ptr_rhs_type) != RECORD_TYPE) {
106953 +#ifndef __DEBUG_PLUGIN
106954 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_lhs_type)))
106955 +#endif
106956 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
106957 + continue;
106958 + }
106959 +
106960 + if (rhs_code == SSA_NAME && ptr_lhs_type == ptr_rhs_type)
106961 + continue;
106962 +
106963 + if (rhs_code == ADDR_EXPR) {
106964 + op0 = TREE_OPERAND(rhs1, 0);
106965 +
106966 + if (op0 == NULL_TREE)
106967 + continue;
106968 +
106969 + if (TREE_CODE(op0) != VAR_DECL)
106970 + continue;
106971 +
106972 + op0_type = TYPE_MAIN_VARIANT(strip_array_types(TYPE_MAIN_VARIANT(TREE_TYPE(op0))));
106973 + if (op0_type == ptr_lhs_type)
106974 + continue;
106975 +
106976 +#ifndef __DEBUG_PLUGIN
106977 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(op0_type)))
106978 +#endif
106979 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, op0_type);
106980 + } else {
106981 + const_tree ssa_name_var = SSA_NAME_VAR(rhs1);
106982 + /* skip bogus type casts introduced by container_of */
106983 + if (ssa_name_var != NULL_TREE && DECL_NAME(ssa_name_var) &&
106984 + !strcmp((const char *)DECL_NAME_POINTER(ssa_name_var), "__mptr"))
106985 + continue;
106986 +#ifndef __DEBUG_PLUGIN
106987 + if (lookup_attribute("randomize_performed", TYPE_ATTRIBUTES(ptr_rhs_type)))
106988 +#endif
106989 + inform(gimple_location(stmt), "found mismatched struct pointer types: %qT and %qT\n", ptr_lhs_type, ptr_rhs_type);
106990 + }
106991 +
106992 + }
106993 + }
106994 + return 0;
106995 +}
106996 +
106997 +#if BUILDING_GCC_VERSION >= 4009
106998 +static const struct pass_data randomize_layout_bad_cast_data = {
106999 +#else
107000 +static struct gimple_opt_pass randomize_layout_bad_cast = {
107001 + .pass = {
107002 +#endif
107003 + .type = GIMPLE_PASS,
107004 + .name = "randomize_layout_bad_cast",
107005 +#if BUILDING_GCC_VERSION >= 4008
107006 + .optinfo_flags = OPTGROUP_NONE,
107007 +#endif
107008 +#if BUILDING_GCC_VERSION >= 4009
107009 + .has_gate = false,
107010 + .has_execute = true,
107011 +#else
107012 + .gate = NULL,
107013 + .execute = find_bad_casts,
107014 + .sub = NULL,
107015 + .next = NULL,
107016 + .static_pass_number = 0,
107017 +#endif
107018 + .tv_id = TV_NONE,
107019 + .properties_required = PROP_cfg,
107020 + .properties_provided = 0,
107021 + .properties_destroyed = 0,
107022 + .todo_flags_start = 0,
107023 + .todo_flags_finish = TODO_dump_func
107024 +#if BUILDING_GCC_VERSION < 4009
107025 + }
107026 +#endif
107027 +};
107028 +
107029 +#if BUILDING_GCC_VERSION >= 4009
107030 +namespace {
107031 +class randomize_layout_bad_cast : public gimple_opt_pass {
107032 +public:
107033 + randomize_layout_bad_cast() : gimple_opt_pass(randomize_layout_bad_cast_data, g) {}
107034 + unsigned int execute() { return find_bad_casts(); }
107035 +};
107036 +}
107037 +#endif
107038 +
107039 +static struct opt_pass *make_randomize_layout_bad_cast(void)
107040 +{
107041 +#if BUILDING_GCC_VERSION >= 4009
107042 + return new randomize_layout_bad_cast();
107043 +#else
107044 + return &randomize_layout_bad_cast.pass;
107045 +#endif
107046 +}
107047 +
107048 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
107049 +{
107050 + int i;
107051 + const char * const plugin_name = plugin_info->base_name;
107052 + const int argc = plugin_info->argc;
107053 + const struct plugin_argument * const argv = plugin_info->argv;
107054 + bool enable = true;
107055 + int obtained_seed = 0;
107056 + struct register_pass_info randomize_layout_bad_cast_info;
107057 +
107058 + randomize_layout_bad_cast_info.pass = make_randomize_layout_bad_cast();
107059 + randomize_layout_bad_cast_info.reference_pass_name = "ssa";
107060 + randomize_layout_bad_cast_info.ref_pass_instance_number = 1;
107061 + randomize_layout_bad_cast_info.pos_op = PASS_POS_INSERT_AFTER;
107062 +
107063 + if (!plugin_default_version_check(version, &gcc_version)) {
107064 + error(G_("incompatible gcc/plugin versions"));
107065 + return 1;
107066 + }
107067 +
107068 + if (strcmp(lang_hooks.name, "GNU C")) {
107069 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
107070 + enable = false;
107071 + }
107072 +
107073 + for (i = 0; i < argc; ++i) {
107074 + if (!strcmp(argv[i].key, "disable")) {
107075 + enable = false;
107076 + continue;
107077 + }
107078 + if (!strcmp(argv[i].key, "performance-mode")) {
107079 + performance_mode = 1;
107080 + continue;
107081 + }
107082 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
107083 + }
107084 +
107085 + if (strlen(randstruct_seed) != 64) {
107086 + error(G_("invalid seed value supplied for %s plugin"), plugin_name);
107087 + return 1;
107088 + }
107089 + obtained_seed = sscanf(randstruct_seed, "%016llx%016llx%016llx%016llx",
107090 + &shuffle_seed[0], &shuffle_seed[1], &shuffle_seed[2], &shuffle_seed[3]);
107091 + if (obtained_seed != 4) {
107092 + error(G_("Invalid seed supplied for %s plugin"), plugin_name);
107093 + return 1;
107094 + }
107095 +
107096 + register_callback(plugin_name, PLUGIN_INFO, NULL, &randomize_layout_plugin_info);
107097 + if (enable) {
107098 + register_callback(plugin_name, PLUGIN_ALL_IPA_PASSES_START, check_global_variables, NULL);
107099 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &randomize_layout_bad_cast_info);
107100 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
107101 + register_callback(plugin_name, PLUGIN_FINISH_DECL, randomize_layout_finish_decl, NULL);
107102 + }
107103 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
107104 +
107105 + return 0;
107106 +}
107107 diff --git a/tools/gcc/size_overflow_hash.data b/tools/gcc/size_overflow_hash.data
107108 new file mode 100644
107109 index 0000000..102f0d6
107110 --- /dev/null
107111 +++ b/tools/gcc/size_overflow_hash.data
107112 @@ -0,0 +1,5703 @@
107113 +intel_fake_agp_alloc_by_type_1 intel_fake_agp_alloc_by_type 1 1 NULL
107114 +ocfs2_get_refcount_tree_3 ocfs2_get_refcount_tree 0 3 NULL
107115 +storvsc_connect_to_vsp_22 storvsc_connect_to_vsp 2 22 NULL
107116 +compat_sock_setsockopt_23 compat_sock_setsockopt 5 23 NULL
107117 +carl9170_alloc_27 carl9170_alloc 1 27 NULL
107118 +sel_read_policyvers_55 sel_read_policyvers 3 55 NULL nohasharray
107119 +padzero_55 padzero 1 55 &sel_read_policyvers_55
107120 +cfg80211_disconnected_57 cfg80211_disconnected 4 57 NULL
107121 +__skb_to_sgvec_72 __skb_to_sgvec 0 72 NULL
107122 +snd_korg1212_copy_to_92 snd_korg1212_copy_to 6 92 NULL
107123 +load_msg_95 load_msg 2 95 NULL
107124 +ipath_verbs_send_117 ipath_verbs_send 5-3 117 NULL
107125 +init_q_132 init_q 4 132 NULL
107126 +memstick_alloc_host_142 memstick_alloc_host 1 142 NULL
107127 +hva_to_gfn_memslot_149 hva_to_gfn_memslot 0-1 149 NULL
107128 +ping_v6_sendmsg_152 ping_v6_sendmsg 4 152 NULL
107129 +ext4_ext_get_actual_len_153 ext4_ext_get_actual_len 0 153 NULL nohasharray
107130 +tracing_trace_options_write_153 tracing_trace_options_write 3 153 &ext4_ext_get_actual_len_153
107131 +pci_request_selected_regions_169 pci_request_selected_regions 0 169 NULL
107132 +xfs_buf_item_get_format_189 xfs_buf_item_get_format 2 189 NULL
107133 +iscsi_session_setup_196 iscsi_session_setup 4-5 196 NULL
107134 +br_port_info_size_268 br_port_info_size 0 268 NULL
107135 +generic_file_direct_write_291 generic_file_direct_write 0 291 NULL
107136 +read_file_war_stats_292 read_file_war_stats 3 292 NULL
107137 +SYSC_connect_304 SYSC_connect 3 304 NULL
107138 +syslog_print_307 syslog_print 2 307 NULL
107139 +dn_setsockopt_314 dn_setsockopt 5 314 NULL
107140 +mlx5_core_access_reg_361 mlx5_core_access_reg 3-5 361 NULL
107141 +hw_device_state_409 hw_device_state 0 409 NULL
107142 +aio_read_events_ring_410 aio_read_events_ring 3-0 410 NULL
107143 +lbs_rdmac_read_418 lbs_rdmac_read 3 418 NULL
107144 +snd_ca0106_ptr_read_467 snd_ca0106_ptr_read 0 467 NULL
107145 +cfs_trace_set_debug_mb_usrstr_486 cfs_trace_set_debug_mb_usrstr 2 486 NULL
107146 +nvme_trans_modesel_data_488 nvme_trans_modesel_data 4 488 NULL
107147 +iwl_dbgfs_protection_mode_write_502 iwl_dbgfs_protection_mode_write 3 502 NULL
107148 +rx_rx_defrag_end_read_505 rx_rx_defrag_end_read 3 505 NULL
107149 +ocfs2_validate_meta_ecc_bhs_527 ocfs2_validate_meta_ecc_bhs 0 527 NULL
107150 +zlib_deflate_workspacesize_537 zlib_deflate_workspacesize 0-1-2 537 NULL
107151 +iwl_dbgfs_wowlan_sram_read_540 iwl_dbgfs_wowlan_sram_read 3 540 NULL
107152 +sco_sock_setsockopt_552 sco_sock_setsockopt 5 552 NULL
107153 +lpfc_nlp_state_name_556 lpfc_nlp_state_name 2 556 NULL
107154 +snd_aw2_saa7146_get_hw_ptr_playback_558 snd_aw2_saa7146_get_hw_ptr_playback 0 558 NULL
107155 +start_isoc_chain_565 start_isoc_chain 2 565 NULL nohasharray
107156 +dev_hard_header_565 dev_hard_header 0 565 &start_isoc_chain_565
107157 +ocfs2_refcounted_xattr_delete_need_584 ocfs2_refcounted_xattr_delete_need 0 584 NULL
107158 +osl_pktget_590 osl_pktget 2 590 NULL
107159 +smk_write_load_self2_591 smk_write_load_self2 3 591 NULL
107160 +btrfs_stack_file_extent_offset_607 btrfs_stack_file_extent_offset 0 607 NULL
107161 +ni_gpct_device_construct_610 ni_gpct_device_construct 5 610 NULL
107162 +fuse_request_alloc_nofs_617 fuse_request_alloc_nofs 1 617 NULL
107163 +ptlrpc_lprocfs_nrs_seq_write_621 ptlrpc_lprocfs_nrs_seq_write 3 621 NULL
107164 +viafb_dfpl_proc_write_627 viafb_dfpl_proc_write 3 627 NULL
107165 +clone_split_bio_633 clone_split_bio 6 633 NULL
107166 +ceph_osdc_new_request_635 ceph_osdc_new_request 6 635 NULL
107167 +cfs_hash_bkt_size_643 cfs_hash_bkt_size 0 643 NULL
107168 +unlink_queued_645 unlink_queued 4 645 NULL
107169 +dtim_interval_read_654 dtim_interval_read 3 654 NULL
107170 +mem_rx_free_mem_blks_read_675 mem_rx_free_mem_blks_read 3 675 NULL
107171 +persistent_ram_vmap_709 persistent_ram_vmap 1-2 709 NULL
107172 +sctp_setsockopt_peer_addr_params_734 sctp_setsockopt_peer_addr_params 3 734 NULL
107173 +dvb_video_write_754 dvb_video_write 3 754 NULL
107174 +cfs_trace_allocate_string_buffer_781 cfs_trace_allocate_string_buffer 2 781 NULL
107175 +ath6kl_disconnect_timeout_write_794 ath6kl_disconnect_timeout_write 3 794 NULL
107176 +if_writecmd_815 if_writecmd 2 815 NULL
107177 +aac_change_queue_depth_825 aac_change_queue_depth 2 825 NULL
107178 +error_state_read_859 error_state_read 6 859 NULL
107179 +o2net_send_message_vec_879 o2net_send_message_vec 4 879 NULL nohasharray
107180 +iwl_dbgfs_fh_reg_read_879 iwl_dbgfs_fh_reg_read 3 879 &o2net_send_message_vec_879
107181 +snd_pcm_action_single_905 snd_pcm_action_single 0 905 NULL
107182 +carl9170_cmd_buf_950 carl9170_cmd_buf 3 950 NULL
107183 +__nodes_weight_956 __nodes_weight 2-0 956 NULL
107184 +bnx2x_fill_fw_str_968 bnx2x_fill_fw_str 3 968 NULL
107185 +memcmp_990 memcmp 0 990 NULL
107186 +readreg_1017 readreg 0-1 1017 NULL
107187 +smk_write_cipso2_1021 smk_write_cipso2 3 1021 NULL
107188 +gigaset_initdriver_1060 gigaset_initdriver 2 1060 NULL
107189 +mce_request_packet_1073 mce_request_packet 3 1073 NULL
107190 +agp_create_memory_1075 agp_create_memory 1 1075 NULL
107191 +_scsih_adjust_queue_depth_1083 _scsih_adjust_queue_depth 2 1083 NULL
107192 +llcp_sock_sendmsg_1092 llcp_sock_sendmsg 4 1092 NULL
107193 +llc_mac_hdr_init_1094 llc_mac_hdr_init 0 1094 NULL
107194 +nfs4_init_nonuniform_client_string_1097 nfs4_init_nonuniform_client_string 3 1097 NULL
107195 +utf8s_to_utf16s_1115 utf8s_to_utf16s 0 1115 NULL
107196 +cfg80211_report_obss_beacon_1133 cfg80211_report_obss_beacon 3 1133 NULL
107197 +i2400m_rx_ctl_1157 i2400m_rx_ctl 4 1157 NULL
107198 +ipc_alloc_1192 ipc_alloc 1 1192 NULL
107199 +ib_create_send_mad_1196 ib_create_send_mad 5 1196 NULL
107200 +pstore_ftrace_knob_write_1198 pstore_ftrace_knob_write 3 1198 NULL
107201 +i2400m_rx_ctl_ack_1199 i2400m_rx_ctl_ack 3 1199 NULL
107202 +dgrp_dpa_read_1204 dgrp_dpa_read 3 1204 NULL
107203 +i2cdev_read_1206 i2cdev_read 3 1206 NULL
107204 +lov_ost_pool_init_1215 lov_ost_pool_init 2 1215 NULL
107205 +ocfs2_extend_file_1266 ocfs2_extend_file 3 1266 NULL
107206 +qla4xxx_change_queue_depth_1268 qla4xxx_change_queue_depth 2 1268 NULL
107207 +ioctl_private_iw_point_1273 ioctl_private_iw_point 7 1273 NULL
107208 +SyS_flistxattr_1287 SyS_flistxattr 3 1287 NULL
107209 +tx_frag_in_process_called_read_1290 tx_frag_in_process_called_read 3 1290 NULL
107210 +ffs_1322 ffs 0 1322 NULL
107211 +qlcnic_pci_sriov_configure_1327 qlcnic_pci_sriov_configure 2 1327 NULL
107212 +btrfs_submit_compressed_write_1347 btrfs_submit_compressed_write 5 1347 NULL
107213 +snd_pcm_lib_write1_1358 snd_pcm_lib_write1 0-3 1358 NULL
107214 +ipx_sendmsg_1362 ipx_sendmsg 4 1362 NULL
107215 +fw_stats_raw_read_1369 fw_stats_raw_read 3 1369 NULL
107216 +ocfs2_prepare_inode_for_write_1372 ocfs2_prepare_inode_for_write 3 1372 NULL
107217 +sctp_setsockopt_initmsg_1383 sctp_setsockopt_initmsg 3 1383 NULL
107218 +do_msgsnd_1387 do_msgsnd 4 1387 NULL
107219 +SYSC_io_getevents_1392 SYSC_io_getevents 3 1392 NULL
107220 +file_read_actor_1401 file_read_actor 4-0 1401 NULL
107221 +cfs_trace_copyout_string_1416 cfs_trace_copyout_string 2 1416 NULL
107222 +init_rs_internal_1436 init_rs_internal 1 1436 NULL
107223 +stack_max_size_read_1445 stack_max_size_read 3 1445 NULL
107224 +tx_queue_len_read_1463 tx_queue_len_read 3 1463 NULL
107225 +xprt_alloc_1475 xprt_alloc 2 1475 NULL
107226 +SYSC_syslog_1477 SYSC_syslog 3 1477 NULL
107227 +sta_num_ps_buf_frames_read_1488 sta_num_ps_buf_frames_read 3 1488 NULL
107228 +fpregs_set_1497 fpregs_set 4 1497 NULL
107229 +tomoyo_round2_1518 tomoyo_round2 0 1518 NULL
107230 +alloc_perm_bits_1532 alloc_perm_bits 2 1532 NULL
107231 +ath6kl_init_get_fwcaps_1557 ath6kl_init_get_fwcaps 3 1557 NULL
107232 +ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime_1589 ieee80211_if_read_dot11MeshHWMPnetDiameterTraversalTime 3 1589 NULL
107233 +ipath_ht_handle_hwerrors_1592 ipath_ht_handle_hwerrors 3 1592 NULL
107234 +packet_buffer_init_1607 packet_buffer_init 2 1607 NULL
107235 +btmrvl_hscmd_read_1614 btmrvl_hscmd_read 3 1614 NULL
107236 +v9fs_fid_xattr_get_1618 v9fs_fid_xattr_get 0 1618 NULL
107237 +ikconfig_read_current_1658 ikconfig_read_current 3 1658 NULL
107238 +mei_cl_recv_1665 mei_cl_recv 3 1665 NULL
107239 +rmap_add_1677 rmap_add 3 1677 NULL
107240 +configfs_read_file_1683 configfs_read_file 3 1683 NULL
107241 +pdu_write_u_1710 pdu_write_u 3 1710 NULL
107242 +coda_psdev_write_1711 coda_psdev_write 3 1711 NULL
107243 +internal_create_group_1733 internal_create_group 0 1733 NULL
107244 +dev_irnet_read_1741 dev_irnet_read 3 1741 NULL
107245 +tx_frag_called_read_1748 tx_frag_called_read 3 1748 NULL
107246 +cosa_write_1774 cosa_write 3 1774 NULL
107247 +fcoe_ctlr_device_add_1793 fcoe_ctlr_device_add 3 1793 NULL
107248 +__nodelist_scnprintf_1815 __nodelist_scnprintf 2-0 1815 NULL
107249 +sb_issue_zeroout_1884 sb_issue_zeroout 3 1884 NULL
107250 +rx_defrag_called_read_1897 rx_defrag_called_read 3 1897 NULL
107251 +nfs_parse_server_name_1899 nfs_parse_server_name 2 1899 NULL
107252 +SyS_add_key_1900 SyS_add_key 4 1900 NULL
107253 +uhid_char_read_1920 uhid_char_read 3 1920 NULL
107254 +tx_tx_retry_data_read_1926 tx_tx_retry_data_read 3 1926 NULL
107255 +bdev_erase_1933 bdev_erase 3 1933 NULL
107256 +ext3_fiemap_1936 ext3_fiemap 4 1936 NULL
107257 +cyttsp_probe_1940 cyttsp_probe 4 1940 NULL
107258 +ieee80211_if_fmt_dot11MeshConfirmTimeout_1945 ieee80211_if_fmt_dot11MeshConfirmTimeout 3 1945 NULL
107259 +ivtv_v4l2_read_1964 ivtv_v4l2_read 3 1964 NULL
107260 +sel_read_avc_hash_stats_1984 sel_read_avc_hash_stats 3 1984 NULL
107261 +gpio_power_write_1991 gpio_power_write 3 1991 NULL
107262 +__alloc_bootmem_node_1992 __alloc_bootmem_node 2 1992 NULL
107263 +rx_rx_defrag_read_2010 rx_rx_defrag_read 3 2010 NULL
107264 +ocfs2_global_qinit_alloc_2018 ocfs2_global_qinit_alloc 0 2018 NULL
107265 +write_flush_pipefs_2021 write_flush_pipefs 3 2021 NULL
107266 +BcmCopySection_2035 BcmCopySection 5 2035 NULL
107267 +ath6kl_fwlog_mask_read_2050 ath6kl_fwlog_mask_read 3 2050 NULL
107268 +ocfs2_expand_inline_dir_2063 ocfs2_expand_inline_dir 3 2063 NULL
107269 +__generic_copy_from_user_intel_2073 __generic_copy_from_user_intel 0-3 2073 NULL
107270 +diva_set_driver_dbg_mask_2077 diva_set_driver_dbg_mask 0 2077 NULL
107271 +iwl_dbgfs_current_sleep_command_read_2081 iwl_dbgfs_current_sleep_command_read 3 2081 NULL
107272 +idetape_chrdev_read_2097 idetape_chrdev_read 3 2097 NULL
107273 +audit_expand_2098 audit_expand 0 2098 NULL
107274 +iwl_dbgfs_log_event_read_2107 iwl_dbgfs_log_event_read 3 2107 NULL
107275 +ecryptfs_encrypt_and_encode_filename_2109 ecryptfs_encrypt_and_encode_filename 6 2109 NULL
107276 +enable_read_2117 enable_read 3 2117 NULL
107277 +pcf50633_write_block_2124 pcf50633_write_block 2-3 2124 NULL
107278 +check_load_and_stores_2143 check_load_and_stores 2 2143 NULL
107279 +iov_iter_count_2152 iov_iter_count 0 2152 NULL
107280 +__copy_to_user_ll_2157 __copy_to_user_ll 0-3 2157 NULL
107281 +_ore_get_io_state_2166 _ore_get_io_state 3-4-5 2166 NULL
107282 +bio_integrity_alloc_2194 bio_integrity_alloc 3 2194 NULL
107283 +picolcd_debug_reset_write_2195 picolcd_debug_reset_write 3 2195 NULL
107284 +u32_array_read_2219 u32_array_read 3 2219 NULL nohasharray
107285 +mei_dbgfs_read_meclients_2219 mei_dbgfs_read_meclients 3 2219 &u32_array_read_2219
107286 +vhci_write_2224 vhci_write 3 2224 NULL
107287 +__ocfs2_journal_access_2241 __ocfs2_journal_access 0 2241 NULL
107288 +ieee80211_if_read_dot11MeshHWMPRannInterval_2249 ieee80211_if_read_dot11MeshHWMPRannInterval 3 2249 NULL
107289 +netlbl_secattr_catmap_walk_2255 netlbl_secattr_catmap_walk 0-2 2255 NULL
107290 +sel_write_avc_cache_threshold_2256 sel_write_avc_cache_threshold 3 2256 NULL
107291 +do_update_counters_2259 do_update_counters 4 2259 NULL
107292 +ath6kl_wmi_bssinfo_event_rx_2275 ath6kl_wmi_bssinfo_event_rx 3 2275 NULL
107293 +debug_debug5_read_2291 debug_debug5_read 3 2291 NULL
107294 +kvm_clear_guest_page_2308 kvm_clear_guest_page 4 2308 NULL
107295 +intel_sdvo_set_value_2311 intel_sdvo_set_value 4 2311 NULL
107296 +hfsplus_find_init_2318 hfsplus_find_init 0 2318 NULL nohasharray
107297 +picolcd_fb_write_2318 picolcd_fb_write 3 2318 &hfsplus_find_init_2318
107298 +dice_hwdep_read_2326 dice_hwdep_read 3 2326 NULL
107299 +__erst_read_to_erange_2341 __erst_read_to_erange 0 2341 NULL
107300 +zr364xx_read_2354 zr364xx_read 3 2354 NULL
107301 +sysfs_add_file_mode_ns_2362 sysfs_add_file_mode_ns 0 2362 NULL
107302 +viafb_iga2_odev_proc_write_2363 viafb_iga2_odev_proc_write 3 2363 NULL
107303 +xfs_buf_map_from_irec_2368 xfs_buf_map_from_irec 5 2368 NULL nohasharray
107304 +rose_recvmsg_2368 rose_recvmsg 4 2368 &xfs_buf_map_from_irec_2368
107305 +il_dbgfs_sensitivity_read_2370 il_dbgfs_sensitivity_read 3 2370 NULL
107306 +rxpipe_rx_prep_beacon_drop_read_2403 rxpipe_rx_prep_beacon_drop_read 3 2403 NULL
107307 +isdn_v110_open_2418 isdn_v110_open 3 2418 NULL
107308 +raid1_size_2419 raid1_size 0-2 2419 NULL
107309 +b43legacy_debugfs_read_2473 b43legacy_debugfs_read 3 2473 NULL
107310 +wiphy_new_2482 wiphy_new 2 2482 NULL
107311 +bio_alloc_bioset_2484 bio_alloc_bioset 2 2484 NULL
107312 +hfsplus_user_setxattr_2485 hfsplus_user_setxattr 4 2485 NULL
107313 +squashfs_read_fragment_index_table_2506 squashfs_read_fragment_index_table 4 2506 NULL
107314 +v9fs_cached_file_read_2514 v9fs_cached_file_read 3 2514 NULL
107315 +ext4_get_inode_loc_2516 ext4_get_inode_loc 0 2516 NULL
107316 +batadv_tvlv_container_list_size_2524 batadv_tvlv_container_list_size 0 2524 NULL
107317 +gspca_dev_probe_2570 gspca_dev_probe 4 2570 NULL
107318 +pcm_sanity_check_2574 pcm_sanity_check 0 2574 NULL
107319 +mdc_max_rpcs_in_flight_seq_write_2594 mdc_max_rpcs_in_flight_seq_write 3 2594 NULL
107320 +slot_bytes_2609 slot_bytes 0 2609 NULL
107321 +smk_write_logging_2618 smk_write_logging 3 2618 NULL
107322 +switch_status_2629 switch_status 5 2629 NULL
107323 +tcp_xmit_size_goal_2661 tcp_xmit_size_goal 2 2661 NULL
107324 +osc_build_ppga_2670 osc_build_ppga 2 2670 NULL
107325 +ffs_ep0_read_2672 ffs_ep0_read 3 2672 NULL
107326 +oti6858_write_2692 oti6858_write 4 2692 NULL
107327 +nfc_llcp_send_ui_frame_2702 nfc_llcp_send_ui_frame 5 2702 NULL
107328 +memcpy_fromiovecend_2707 memcpy_fromiovecend 3-4 2707 NULL
107329 +lprocfs_stats_counter_size_2708 lprocfs_stats_counter_size 0 2708 NULL
107330 +xfs_readdir_2767 xfs_readdir 3 2767 NULL
107331 +mon_bin_ioctl_2771 mon_bin_ioctl 3 2771 NULL
107332 +device_add_attrs_2789 device_add_attrs 0 2789 NULL
107333 +iwl_dbgfs_clear_ucode_statistics_write_2804 iwl_dbgfs_clear_ucode_statistics_write 3 2804 NULL
107334 +sel_read_enforce_2828 sel_read_enforce 3 2828 NULL
107335 +vb2_dc_get_userptr_2829 vb2_dc_get_userptr 2-3 2829 NULL
107336 +wait_for_avail_2847 wait_for_avail 0 2847 NULL
107337 +sfq_alloc_2861 sfq_alloc 1 2861 NULL
107338 +irnet_ctrl_read_2863 irnet_ctrl_read 4 2863 NULL
107339 +move_addr_to_user_2868 move_addr_to_user 2 2868 NULL
107340 +nla_padlen_2883 nla_padlen 1 2883 NULL
107341 +cmm_write_2896 cmm_write 3 2896 NULL
107342 +osc_import_seq_write_2923 osc_import_seq_write 3 2923 NULL
107343 +xfs_trans_get_buf_map_2927 xfs_trans_get_buf_map 4 2927 NULL
107344 +nes_read_indexed_2946 nes_read_indexed 0 2946 NULL
107345 +tm6000_i2c_recv_regs16_2949 tm6000_i2c_recv_regs16 5 2949 NULL
107346 +i40e_dbg_prep_dump_buf_2951 i40e_dbg_prep_dump_buf 2 2951 NULL
107347 +set_fast_connectable_2952 set_fast_connectable 4 2952 NULL
107348 +free_area_init_core_2962 free_area_init_core 2-3 2962 NULL
107349 +do_strnlen_user_2976 do_strnlen_user 0-2 2976 NULL
107350 +p9_nr_pages_2992 p9_nr_pages 0-2 2992 NULL
107351 +lov_stripetype_seq_write_3013 lov_stripetype_seq_write 3 3013 NULL
107352 +do_dmabuf_dirty_sou_3017 do_dmabuf_dirty_sou 7 3017 NULL
107353 +depth_write_3021 depth_write 3 3021 NULL
107354 +snd_azf3328_codec_inl_3022 snd_azf3328_codec_inl 0 3022 NULL
107355 +kvm_unmap_hva_3028 kvm_unmap_hva 2 3028 NULL
107356 +xfrm_dst_alloc_copy_3034 xfrm_dst_alloc_copy 3 3034 NULL
107357 +lpfc_idiag_mbxacc_write_3038 lpfc_idiag_mbxacc_write 3 3038 NULL nohasharray
107358 +iwl_dbgfs_sleep_level_override_read_3038 iwl_dbgfs_sleep_level_override_read 3 3038 &lpfc_idiag_mbxacc_write_3038
107359 +nr_free_buffer_pages_3044 nr_free_buffer_pages 0 3044 NULL
107360 +il3945_ucode_rx_stats_read_3048 il3945_ucode_rx_stats_read 3 3048 NULL
107361 +qp_alloc_ppn_set_3068 qp_alloc_ppn_set 2-4 3068 NULL
107362 +__blk_end_bidi_request_3070 __blk_end_bidi_request 3-4 3070 NULL
107363 +dac960_user_command_proc_write_3071 dac960_user_command_proc_write 3 3071 NULL
107364 +read_file_antenna_diversity_3077 read_file_antenna_diversity 3 3077 NULL
107365 +clone_bio_3100 clone_bio 6 3100 NULL nohasharray
107366 +ttusb2_msg_3100 ttusb2_msg 4 3100 &clone_bio_3100
107367 +rb_alloc_3102 rb_alloc 1 3102 NULL
107368 +simple_write_to_buffer_3122 simple_write_to_buffer 5-2 3122 NULL
107369 +print_time_3132 print_time 0 3132 NULL
107370 +fill_write_buffer_3142 fill_write_buffer 3 3142 NULL
107371 +CIFSSMBSetPosixACL_3154 CIFSSMBSetPosixACL 5 3154 NULL
107372 +compat_sys_migrate_pages_3157 compat_sys_migrate_pages 2 3157 NULL
107373 +uv_num_possible_blades_3177 uv_num_possible_blades 0 3177 NULL
107374 +uvc_video_stats_dump_3181 uvc_video_stats_dump 3 3181 NULL
107375 +compat_do_ip6t_set_ctl_3184 compat_do_ip6t_set_ctl 4 3184 NULL
107376 +mempool_create_node_3191 mempool_create_node 1 3191 NULL
107377 +alloc_context_3194 alloc_context 1 3194 NULL
107378 +shmem_pread_slow_3198 shmem_pread_slow 3-2 3198 NULL
107379 +codec_reg_write_file_3204 codec_reg_write_file 3 3204 NULL
107380 +SyS_sendto_3219 SyS_sendto 6 3219 NULL
107381 +btrfs_prealloc_file_range_3227 btrfs_prealloc_file_range 3 3227 NULL
107382 +kimage_crash_alloc_3233 kimage_crash_alloc 3 3233 NULL
107383 +write_adapter_mem_3234 write_adapter_mem 3 3234 NULL
107384 +do_read_log_to_user_3236 do_read_log_to_user 4 3236 NULL
107385 +ext3_xattr_find_entry_3237 ext3_xattr_find_entry 0 3237 NULL
107386 +key_key_read_3241 key_key_read 3 3241 NULL
107387 +__ilog2_u64_3284 __ilog2_u64 0 3284 NULL
107388 +__iovec_copy_from_user_inatomic_3314 __iovec_copy_from_user_inatomic 0-4-3 3314 NULL
107389 +dbDiscardAG_3322 dbDiscardAG 3 3322 NULL
107390 +compat_sys_setsockopt_3326 compat_sys_setsockopt 5 3326 NULL
107391 +ocfs2_extend_xattr_bucket_3328 ocfs2_extend_xattr_bucket 4 3328 NULL
107392 +read_from_oldmem_3337 read_from_oldmem 2 3337 NULL
107393 +sysfs_create_group_3339 sysfs_create_group 0 3339 NULL
107394 +tty_port_register_device_attr_3341 tty_port_register_device_attr 3 3341 NULL
107395 +il_dbgfs_interrupt_read_3351 il_dbgfs_interrupt_read 3 3351 NULL
107396 +gsm_control_rls_3353 gsm_control_rls 3 3353 NULL
107397 +scnprintf_3360 scnprintf 0-2 3360 NULL
107398 +ReadByteAmd7930_3365 ReadByteAmd7930 0 3365 NULL
107399 +sr_read_3366 sr_read 3 3366 NULL
107400 +mtdchar_writeoob_3393 mtdchar_writeoob 4 3393 NULL
107401 +send_stream_3397 send_stream 4 3397 NULL
107402 +isdn_readbchan_3401 isdn_readbchan 0-5 3401 NULL
107403 +mei_io_cb_alloc_resp_buf_3414 mei_io_cb_alloc_resp_buf 2 3414 NULL
107404 +pci_add_cap_save_buffer_3426 pci_add_cap_save_buffer 3 3426 NULL
107405 +crystalhd_create_dio_pool_3427 crystalhd_create_dio_pool 2 3427 NULL
107406 +SyS_msgsnd_3436 SyS_msgsnd 3 3436 NULL
107407 +pipe_iov_copy_to_user_3447 pipe_iov_copy_to_user 3 3447 NULL
107408 +s3fb_ddc_read_3451 s3fb_ddc_read 0 3451 NULL
107409 +softsynth_write_3455 softsynth_write 3 3455 NULL
107410 +snd_pcm_lib_readv_transfer_3464 snd_pcm_lib_readv_transfer 5-4-2 3464 NULL nohasharray
107411 +jffs2_acl_setxattr_3464 jffs2_acl_setxattr 4 3464 &snd_pcm_lib_readv_transfer_3464
107412 +security_context_to_sid_default_3492 security_context_to_sid_default 2 3492 NULL
107413 +xfrm_migrate_msgsize_3496 xfrm_migrate_msgsize 1 3496 NULL
107414 +mem_tx_free_mem_blks_read_3521 mem_tx_free_mem_blks_read 3 3521 NULL
107415 +SyS_semtimedop_3532 SyS_semtimedop 3 3532 NULL
107416 +SyS_readv_3539 SyS_readv 3 3539 NULL
107417 +btrfs_dir_name_len_3549 btrfs_dir_name_len 0 3549 NULL
107418 +alloc_smp_resp_3566 alloc_smp_resp 1 3566 NULL
107419 +evtchn_read_3569 evtchn_read 3 3569 NULL
107420 +ll_track_ppid_seq_write_3582 ll_track_ppid_seq_write 3 3582 NULL
107421 +vc_resize_3585 vc_resize 3-2 3585 NULL
107422 +kvm_mmu_notifier_change_pte_3596 kvm_mmu_notifier_change_pte 3 3596 NULL
107423 +sctp_getsockopt_events_3607 sctp_getsockopt_events 2 3607 NULL
107424 +edac_mc_alloc_3611 edac_mc_alloc 4 3611 NULL
107425 +tx_tx_starts_read_3617 tx_tx_starts_read 3 3617 NULL
107426 +aligned_kmalloc_3628 aligned_kmalloc 1 3628 NULL
107427 +ath6kl_disconnect_timeout_read_3650 ath6kl_disconnect_timeout_read 3 3650 NULL
107428 +i915_compat_ioctl_3656 i915_compat_ioctl 2 3656 NULL
107429 +snd_m3_assp_read_3703 snd_m3_assp_read 0 3703 NULL
107430 +ci_ll_write_3740 ci_ll_write 4 3740 NULL nohasharray
107431 +ath6kl_mgmt_tx_3740 ath6kl_mgmt_tx 7 3740 &ci_ll_write_3740
107432 +sctp_setsockopt_auth_key_3793 sctp_setsockopt_auth_key 3 3793 NULL
107433 +ncp_file_write_3813 ncp_file_write 3 3813 NULL
107434 +llc_ui_recvmsg_3826 llc_ui_recvmsg 4 3826 NULL
107435 +hfsplus_direct_IO_3835 hfsplus_direct_IO 4 3835 NULL
107436 +create_one_cdev_3852 create_one_cdev 2 3852 NULL
107437 +smk_read_onlycap_3855 smk_read_onlycap 3 3855 NULL
107438 +get_fd_set_3866 get_fd_set 1 3866 NULL
107439 +apei_res_sub_3873 apei_res_sub 0 3873 NULL
107440 +garp_attr_create_3883 garp_attr_create 3 3883 NULL
107441 +efivarfs_file_read_3893 efivarfs_file_read 3 3893 NULL
107442 +nvram_write_3894 nvram_write 3 3894 NULL
107443 +pipeline_pre_proc_swi_read_3898 pipeline_pre_proc_swi_read 3 3898 NULL
107444 +comedi_buf_read_n_available_3899 comedi_buf_read_n_available 0 3899 NULL
107445 +vcs_write_3910 vcs_write 3 3910 NULL
107446 +SyS_move_pages_3920 SyS_move_pages 2 3920 NULL
107447 +hdlc_irq_one_3944 hdlc_irq_one 2 3944 NULL
107448 +brcmf_debugfs_fws_stats_read_3947 brcmf_debugfs_fws_stats_read 3 3947 NULL
107449 +ll_get_max_mdsize_3962 ll_get_max_mdsize 0 3962 NULL
107450 +mite_bytes_written_to_memory_lb_3987 mite_bytes_written_to_memory_lb 0 3987 NULL
107451 +do_add_counters_3992 do_add_counters 3 3992 NULL
107452 +obd_alloc_memmd_4002 obd_alloc_memmd 0 4002 NULL
107453 +userspace_status_4004 userspace_status 4 4004 NULL
107454 +xfs_check_block_4005 xfs_check_block 4 4005 NULL nohasharray
107455 +mei_write_4005 mei_write 3 4005 &xfs_check_block_4005
107456 +snd_hdsp_capture_copy_4011 snd_hdsp_capture_copy 5 4011 NULL
107457 +blk_end_request_4024 blk_end_request 3 4024 NULL
107458 +ext4_xattr_find_entry_4025 ext4_xattr_find_entry 0 4025 NULL
107459 +mtip_hw_read_registers_4037 mtip_hw_read_registers 3 4037 NULL
107460 +read_file_queues_4078 read_file_queues 3 4078 NULL
107461 +fbcon_do_set_font_4079 fbcon_do_set_font 2-3 4079 NULL
107462 +C_SYSC_rt_sigpending_4114 C_SYSC_rt_sigpending 2 4114 NULL
107463 +tm6000_read_4151 tm6000_read 3 4151 NULL
107464 +mpt_raid_phys_disk_get_num_paths_4155 mpt_raid_phys_disk_get_num_paths 0 4155 NULL
107465 +msg_bits_4158 msg_bits 0-3-4 4158 NULL
107466 +get_alua_req_4166 get_alua_req 3 4166 NULL
107467 +blk_dropped_read_4168 blk_dropped_read 3 4168 NULL
107468 +read_file_bool_4180 read_file_bool 3 4180 NULL
107469 +ocfs2_find_cpos_for_right_leaf_4194 ocfs2_find_cpos_for_right_leaf 0 4194 NULL
107470 +vring_new_virtqueue_4199 vring_new_virtqueue 2 4199 NULL
107471 +f1x_determine_channel_4202 f1x_determine_channel 2 4202 NULL
107472 +_osd_req_list_objects_4204 _osd_req_list_objects 6 4204 NULL
107473 +__snd_gf1_read_addr_4210 __snd_gf1_read_addr 0 4210 NULL
107474 +ath6kl_force_roam_write_4282 ath6kl_force_roam_write 3 4282 NULL
107475 +goldfish_audio_write_4284 goldfish_audio_write 3 4284 NULL
107476 +__usbnet_read_cmd_4299 __usbnet_read_cmd 7 4299 NULL
107477 +dvb_ringbuffer_pkt_read_user_4303 dvb_ringbuffer_pkt_read_user 3-2-5 4303 NULL
107478 +count_strings_4315 count_strings 0 4315 NULL
107479 +__sysfs_add_one_4326 __sysfs_add_one 0 4326 NULL
107480 +nouveau_fifo_create__4327 nouveau_fifo_create_ 5-6 4327 NULL
107481 +snd_rawmidi_kernel_read_4328 snd_rawmidi_kernel_read 3 4328 NULL
107482 +__copy_from_user_inatomic_4365 __copy_from_user_inatomic 0-3 4365 NULL nohasharray
107483 +lookup_string_4365 lookup_string 0 4365 &__copy_from_user_inatomic_4365
107484 +irda_sendmsg_4388 irda_sendmsg 4 4388 NULL
107485 +access_process_vm_4412 access_process_vm 0 4412 NULL nohasharray
107486 +cxacru_cm_get_array_4412 cxacru_cm_get_array 4 4412 &access_process_vm_4412
107487 +libfc_vport_create_4415 libfc_vport_create 2 4415 NULL
107488 +rtw_android_get_rssi_4421 rtw_android_get_rssi 0 4421 NULL
107489 +do_pages_stat_4437 do_pages_stat 2 4437 NULL
107490 +at76_set_card_command_4471 at76_set_card_command 4 4471 NULL
107491 +snd_seq_expand_var_event_4481 snd_seq_expand_var_event 5-0 4481 NULL
107492 +vmbus_establish_gpadl_4495 vmbus_establish_gpadl 3 4495 NULL
107493 +set_link_security_4502 set_link_security 4 4502 NULL
107494 +ll_max_readahead_per_file_mb_seq_write_4531 ll_max_readahead_per_file_mb_seq_write 3 4531 NULL
107495 +tty_register_device_4544 tty_register_device 2 4544 NULL
107496 +btrfs_file_extent_inline_item_len_4575 btrfs_file_extent_inline_item_len 0 4575 NULL
107497 +xfs_buf_get_maps_4581 xfs_buf_get_maps 2 4581 NULL
107498 +bch_alloc_4593 bch_alloc 1 4593 NULL
107499 +ocfs2_refcount_lock_4595 ocfs2_refcount_lock 0 4595 NULL
107500 +ll_rw_extents_stats_seq_write_4633 ll_rw_extents_stats_seq_write 3 4633 NULL
107501 +iwl_dbgfs_tx_queue_read_4635 iwl_dbgfs_tx_queue_read 3 4635 NULL
107502 +skb_add_data_nocache_4682 skb_add_data_nocache 4 4682 NULL
107503 +cx18_read_pos_4683 cx18_read_pos 3 4683 NULL
107504 +short_retry_limit_read_4687 short_retry_limit_read 3 4687 NULL
107505 +kone_receive_4690 kone_receive 4 4690 NULL
107506 +hash_netportnet6_expire_4702 hash_netportnet6_expire 4 4702 NULL
107507 +cxgbi_alloc_big_mem_4707 cxgbi_alloc_big_mem 1 4707 NULL
107508 +ati_create_gatt_pages_4722 ati_create_gatt_pages 1 4722 NULL nohasharray
107509 +show_header_4722 show_header 3 4722 &ati_create_gatt_pages_4722
107510 +bitmap_startwrite_4736 bitmap_startwrite 2 4736 NULL nohasharray
107511 +ll_rw_offset_stats_seq_write_4736 ll_rw_offset_stats_seq_write 3 4736 &bitmap_startwrite_4736
107512 +lu_buf_alloc_4753 lu_buf_alloc 2 4753 NULL
107513 +pwr_rcvd_bcns_cnt_read_4774 pwr_rcvd_bcns_cnt_read 3 4774 NULL
107514 +create_subvol_4791 create_subvol 4 4791 NULL
107515 +ncp__vol2io_4804 ncp__vol2io 5 4804 NULL
107516 +repair_io_failure_4815 repair_io_failure 4-3 4815 NULL
107517 +comedi_buf_write_free_4847 comedi_buf_write_free 2 4847 NULL
107518 +gigaset_if_receive_4861 gigaset_if_receive 3 4861 NULL
107519 +key_tx_spec_read_4862 key_tx_spec_read 3 4862 NULL
107520 +ocfs2_defrag_extent_4873 ocfs2_defrag_extent 2 4873 NULL
107521 +hid_register_field_4874 hid_register_field 2-3 4874 NULL
107522 +vga_arb_read_4886 vga_arb_read 3 4886 NULL
107523 +ieee80211_if_fmt_ave_beacon_4941 ieee80211_if_fmt_ave_beacon 3 4941 NULL
107524 +ocfs2_should_refresh_lock_res_4958 ocfs2_should_refresh_lock_res 0 4958 NULL
107525 +compat_rawv6_setsockopt_4967 compat_rawv6_setsockopt 5 4967 NULL
107526 +ath10k_read_chip_id_4969 ath10k_read_chip_id 3 4969 NULL
107527 +skb_network_header_len_4971 skb_network_header_len 0 4971 NULL
107528 +ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval_4976 ieee80211_if_fmt_dot11MeshHWMPconfirmationInterval 3 4976 NULL
107529 +compat_SyS_ipc_5000 compat_SyS_ipc 3 5000 NULL
107530 +do_mincore_5018 do_mincore 0-2-1 5018 NULL
107531 +btrfs_punch_hole_5041 btrfs_punch_hole 2 5041 NULL
107532 +cfg80211_rx_mgmt_5056 cfg80211_rx_mgmt 5 5056 NULL
107533 +ocfs2_check_range_for_holes_5066 ocfs2_check_range_for_holes 3-2 5066 NULL
107534 +snd_mixart_BA1_read_5082 snd_mixart_BA1_read 5 5082 NULL
107535 +snd_emu10k1_ptr20_read_5087 snd_emu10k1_ptr20_read 0 5087 NULL
107536 +kfifo_copy_from_user_5091 kfifo_copy_from_user 3-4-0 5091 NULL nohasharray
107537 +get_random_bytes_5091 get_random_bytes 2 5091 &kfifo_copy_from_user_5091 nohasharray
107538 +blk_rq_sectors_5091 blk_rq_sectors 0 5091 &get_random_bytes_5091
107539 +sound_write_5102 sound_write 3 5102 NULL
107540 +i40e_dbg_netdev_ops_write_5117 i40e_dbg_netdev_ops_write 3 5117 NULL
107541 +qib_7220_handle_hwerrors_5142 qib_7220_handle_hwerrors 3 5142 NULL
107542 +__uwb_addr_print_5161 __uwb_addr_print 2 5161 NULL
107543 +iwl_dbgfs_status_read_5171 iwl_dbgfs_status_read 3 5171 NULL
107544 +acpi_pcc_get_sqty_5176 acpi_pcc_get_sqty 0 5176 NULL
107545 +ppp_cp_parse_cr_5214 ppp_cp_parse_cr 4 5214 NULL
107546 +dwc2_hcd_urb_alloc_5217 dwc2_hcd_urb_alloc 2 5217 NULL
107547 +ath6kl_debug_roam_tbl_event_5224 ath6kl_debug_roam_tbl_event 3 5224 NULL
107548 +usb_descriptor_fillbuf_5302 usb_descriptor_fillbuf 0 5302 NULL
107549 +r592_write_fifo_pio_5315 r592_write_fifo_pio 3 5315 NULL
107550 +sbc_get_write_same_sectors_5317 sbc_get_write_same_sectors 0 5317 NULL
107551 +pwr_elp_enter_read_5324 pwr_elp_enter_read 3 5324 NULL
107552 +cq_free_res_5355 cq_free_res 5 5355 NULL
107553 +ps_pspoll_utilization_read_5361 ps_pspoll_utilization_read 3 5361 NULL
107554 +cciss_allocate_sg_chain_blocks_5368 cciss_allocate_sg_chain_blocks 3-2 5368 NULL
107555 +__split_bvec_across_targets_5454 __split_bvec_across_targets 3 5454 NULL
107556 +xfs_efd_init_5463 xfs_efd_init 3 5463 NULL
107557 +xfs_efi_init_5476 xfs_efi_init 2 5476 NULL
107558 +cifs_security_flags_proc_write_5484 cifs_security_flags_proc_write 3 5484 NULL
107559 +tty_write_5494 tty_write 3 5494 NULL
107560 +tomoyo_update_domain_5498 tomoyo_update_domain 2 5498 NULL nohasharray
107561 +ieee80211_if_fmt_last_beacon_5498 ieee80211_if_fmt_last_beacon 3 5498 &tomoyo_update_domain_5498
107562 +__max_nr_grant_frames_5505 __max_nr_grant_frames 0 5505 NULL
107563 +ieee80211_if_fmt_auto_open_plinks_5534 ieee80211_if_fmt_auto_open_plinks 3 5534 NULL
107564 +get_entry_msg_len_5552 get_entry_msg_len 0 5552 NULL
107565 +le_readq_5557 le_readq 0 5557 NULL
107566 +inw_5558 inw 0 5558 NULL
107567 +bioset_create_5580 bioset_create 1 5580 NULL
107568 +oz_ep_alloc_5587 oz_ep_alloc 1 5587 NULL
107569 +SYSC_fsetxattr_5639 SYSC_fsetxattr 4 5639 NULL
107570 +ext4_xattr_get_5661 ext4_xattr_get 0 5661 NULL
107571 +posix_clock_register_5662 posix_clock_register 2 5662 NULL
107572 +get_arg_5694 get_arg 3 5694 NULL
107573 +subbuf_read_actor_5708 subbuf_read_actor 3 5708 NULL
107574 +vmw_kms_readback_5727 vmw_kms_readback 6 5727 NULL
107575 +rts51x_transfer_data_partial_5735 rts51x_transfer_data_partial 6 5735 NULL
107576 +sctp_setsockopt_autoclose_5775 sctp_setsockopt_autoclose 3 5775 NULL
107577 +__vxge_hw_blockpool_malloc_5786 __vxge_hw_blockpool_malloc 2 5786 NULL
107578 +nvme_trans_bdev_char_page_5797 nvme_trans_bdev_char_page 3 5797 NULL
107579 +skb_copy_datagram_iovec_5806 skb_copy_datagram_iovec 2-4 5806 NULL
107580 +nv50_disp_pioc_create__5812 nv50_disp_pioc_create_ 5 5812 NULL
107581 +ceph_x_encrypt_buflen_5829 ceph_x_encrypt_buflen 0-1 5829 NULL
107582 +ceph_msg_new_5846 ceph_msg_new 2 5846 NULL
107583 +setup_req_5848 setup_req 3-0 5848 NULL
107584 +ria_page_count_5849 ria_page_count 0 5849 NULL
107585 +rx_filter_max_arp_queue_dep_read_5851 rx_filter_max_arp_queue_dep_read 3 5851 NULL
107586 +config_buf_5862 config_buf 0 5862 NULL
107587 +iwl_dbgfs_scan_ant_rxchain_write_5877 iwl_dbgfs_scan_ant_rxchain_write 3 5877 NULL
107588 +lprocfs_fid_width_seq_write_5889 lprocfs_fid_width_seq_write 3 5889 NULL
107589 +port_show_regs_5904 port_show_regs 3 5904 NULL
107590 +rbd_segment_length_5907 rbd_segment_length 0-3-2 5907 NULL
107591 +uhci_debug_read_5911 uhci_debug_read 3 5911 NULL
107592 +lbs_highsnr_read_5931 lbs_highsnr_read 3 5931 NULL
107593 +ps_poll_ps_poll_timeouts_read_5934 ps_poll_ps_poll_timeouts_read 3 5934 NULL
107594 +edac_device_alloc_ctl_info_5941 edac_device_alloc_ctl_info 1 5941 NULL
107595 +ll_statahead_one_5962 ll_statahead_one 3 5962 NULL
107596 +__apu_get_register_5967 __apu_get_register 0 5967 NULL
107597 +ieee80211_if_fmt_rc_rateidx_mask_5ghz_5971 ieee80211_if_fmt_rc_rateidx_mask_5ghz 3 5971 NULL
107598 +SyS_semop_5980 SyS_semop 3 5980 NULL
107599 +alloc_msg_6072 alloc_msg 1 6072 NULL
107600 +sctp_setsockopt_connectx_6073 sctp_setsockopt_connectx 3 6073 NULL
107601 +rts51x_ms_rw_multi_sector_6076 rts51x_ms_rw_multi_sector 3-4 6076 NULL
107602 +ipmi_addr_length_6110 ipmi_addr_length 0 6110 NULL
107603 +dfs_global_file_write_6112 dfs_global_file_write 3 6112 NULL
107604 +nouveau_parent_create__6131 nouveau_parent_create_ 7 6131 NULL
107605 +ieee80211_if_fmt_beacon_timeout_6153 ieee80211_if_fmt_beacon_timeout 3 6153 NULL
107606 +ivtv_copy_buf_to_user_6159 ivtv_copy_buf_to_user 4 6159 NULL
107607 +wl1251_cmd_template_set_6172 wl1251_cmd_template_set 4 6172 NULL
107608 +SyS_setgroups_6182 SyS_setgroups 1 6182 NULL
107609 +mxt_show_instance_6207 mxt_show_instance 2-0 6207 NULL
107610 +v4l2_ctrl_new_std_menu_6221 v4l2_ctrl_new_std_menu 4 6221 NULL
107611 +mqueue_read_file_6228 mqueue_read_file 3 6228 NULL
107612 +f_hidg_read_6238 f_hidg_read 3 6238 NULL
107613 +fbcon_prepare_logo_6246 fbcon_prepare_logo 5 6246 NULL
107614 +tx_tx_start_null_frame_read_6281 tx_tx_start_null_frame_read 3 6281 NULL
107615 +snd_hda_override_conn_list_6282 snd_hda_override_conn_list 3-0 6282 NULL nohasharray
107616 +xenbus_file_write_6282 xenbus_file_write 3 6282 &snd_hda_override_conn_list_6282
107617 +posix_acl_fix_xattr_to_user_6283 posix_acl_fix_xattr_to_user 2 6283 NULL
107618 +serial_port_in_6291 serial_port_in 0 6291 NULL
107619 +qlcnic_sriov_alloc_bc_msg_6309 qlcnic_sriov_alloc_bc_msg 2 6309 NULL
107620 +hfa384x_inw_6329 hfa384x_inw 0 6329 NULL nohasharray
107621 +SyS_mincore_6329 SyS_mincore 2-1 6329 &hfa384x_inw_6329
107622 +fuse_get_req_for_background_6337 fuse_get_req_for_background 2 6337 NULL
107623 +ucs2_strnlen_6342 ucs2_strnlen 0 6342 NULL
107624 +regcache_sync_block_raw_6350 regcache_sync_block_raw 5-4 6350 NULL
107625 +mei_dbgfs_read_devstate_6352 mei_dbgfs_read_devstate 3 6352 NULL
107626 +_proc_do_string_6376 _proc_do_string 2 6376 NULL
107627 +osd_req_read_sg_kern_6378 osd_req_read_sg_kern 5 6378 NULL
107628 +posix_acl_fix_xattr_userns_6420 posix_acl_fix_xattr_userns 4 6420 NULL
107629 +add_transaction_credits_6422 add_transaction_credits 2-3 6422 NULL
107630 +ipr_change_queue_depth_6431 ipr_change_queue_depth 2 6431 NULL
107631 +__alloc_bootmem_node_nopanic_6432 __alloc_bootmem_node_nopanic 2 6432 NULL
107632 +ieee80211_if_fmt_dot11MeshMaxRetries_6476 ieee80211_if_fmt_dot11MeshMaxRetries 3 6476 NULL
107633 +qp_memcpy_from_queue_6479 qp_memcpy_from_queue 5-4 6479 NULL
107634 +cipso_v4_map_lvl_hton_6490 cipso_v4_map_lvl_hton 0 6490 NULL
107635 +dbg_intr_buf_6501 dbg_intr_buf 2 6501 NULL
107636 +mei_read_6507 mei_read 3 6507 NULL
107637 +rndis_set_oid_6547 rndis_set_oid 4 6547 NULL
107638 +wdm_read_6549 wdm_read 3 6549 NULL
107639 +dm_stats_create_6551 dm_stats_create 4-2-3 6551 NULL
107640 +fb_alloc_cmap_6554 fb_alloc_cmap 2 6554 NULL
107641 +SyS_semtimedop_6563 SyS_semtimedop 3 6563 NULL
107642 +ecryptfs_filldir_6622 ecryptfs_filldir 3 6622 NULL
107643 +xfs_do_div_6649 xfs_do_div 0-2 6649 NULL
107644 +process_rcvd_data_6679 process_rcvd_data 3 6679 NULL
107645 +btrfs_lookup_csums_range_6696 btrfs_lookup_csums_range 2-3 6696 NULL
107646 +ps_pspoll_max_apturn_read_6699 ps_pspoll_max_apturn_read 3 6699 NULL
107647 +bnad_debugfs_write_regrd_6706 bnad_debugfs_write_regrd 3 6706 NULL
107648 +mpeg_read_6708 mpeg_read 3 6708 NULL
107649 +ibmpex_query_sensor_count_6709 ibmpex_query_sensor_count 0 6709 NULL
107650 +video_proc_write_6724 video_proc_write 3 6724 NULL
107651 +posix_acl_xattr_count_6725 posix_acl_xattr_count 0-1 6725 NULL
107652 +kobject_add_varg_6781 kobject_add_varg 0 6781 NULL
107653 +iwl_dbgfs_channels_read_6784 iwl_dbgfs_channels_read 3 6784 NULL
107654 +ieee80211_if_read_6785 ieee80211_if_read 3 6785 NULL
107655 +zone_spanned_pages_in_node_6787 zone_spanned_pages_in_node 0-3-4 6787 NULL
107656 +hdlcdrv_register_6792 hdlcdrv_register 2 6792 NULL
107657 +tx_tx_done_data_read_6799 tx_tx_done_data_read 3 6799 NULL
107658 +lbs_rdrf_write_6826 lbs_rdrf_write 3 6826 NULL
107659 +calc_pages_for_6838 calc_pages_for 0-1-2 6838 NULL
107660 +mon_bin_read_6841 mon_bin_read 3 6841 NULL
107661 +snd_cs4281_BA0_read_6847 snd_cs4281_BA0_read 5 6847 NULL
107662 +perf_output_sample_ustack_6868 perf_output_sample_ustack 2 6868 NULL
107663 +dio_complete_6879 dio_complete 0-2-3 6879 NULL
107664 +raw_seticmpfilter_6888 raw_seticmpfilter 3 6888 NULL nohasharray
107665 +ieee80211_if_fmt_path_refresh_time_6888 ieee80211_if_fmt_path_refresh_time 3 6888 &raw_seticmpfilter_6888
107666 +dlmfs_file_write_6892 dlmfs_file_write 3 6892 NULL
107667 +proc_sessionid_read_6911 proc_sessionid_read 3 6911 NULL nohasharray
107668 +spi_show_regs_6911 spi_show_regs 3 6911 &proc_sessionid_read_6911 nohasharray
107669 +acm_alloc_minor_6911 acm_alloc_minor 0 6911 &spi_show_regs_6911
107670 +__kfifo_dma_in_finish_r_6913 __kfifo_dma_in_finish_r 2-3 6913 NULL
107671 +do_msgrcv_6921 do_msgrcv 3 6921 NULL
107672 +cache_do_downcall_6926 cache_do_downcall 3 6926 NULL
107673 +ipath_verbs_send_dma_6929 ipath_verbs_send_dma 6 6929 NULL
107674 +qsfp_cks_6945 qsfp_cks 2-0 6945 NULL
107675 +tg3_nvram_write_block_unbuffered_6955 tg3_nvram_write_block_unbuffered 3 6955 NULL
107676 +pch_uart_hal_read_6961 pch_uart_hal_read 0 6961 NULL
107677 +rsa_extract_mpi_6973 rsa_extract_mpi 5 6973 NULL nohasharray
107678 +i40e_dbg_dump_write_6973 i40e_dbg_dump_write 3 6973 &rsa_extract_mpi_6973
107679 +request_key_async_6990 request_key_async 4 6990 NULL
107680 +tpl_write_6998 tpl_write 3 6998 NULL
107681 +r871x_set_wpa_ie_7000 r871x_set_wpa_ie 3 7000 NULL
107682 +cipso_v4_gentag_enum_7006 cipso_v4_gentag_enum 0 7006 NULL
107683 +tracing_cpumask_read_7010 tracing_cpumask_read 3 7010 NULL
107684 +ld_usb_write_7022 ld_usb_write 3 7022 NULL
107685 +wimax_msg_7030 wimax_msg 4 7030 NULL
107686 +ipath_get_base_info_7043 ipath_get_base_info 3 7043 NULL
107687 +snd_pcm_oss_bytes_7051 snd_pcm_oss_bytes 2 7051 NULL
107688 +hci_sock_recvmsg_7072 hci_sock_recvmsg 4 7072 NULL
107689 +event_enable_read_7074 event_enable_read 3 7074 NULL
107690 +beacon_interval_read_7091 beacon_interval_read 3 7091 NULL
107691 +pipeline_enc_rx_stat_fifo_int_read_7107 pipeline_enc_rx_stat_fifo_int_read 3 7107 NULL
107692 +osc_resend_count_seq_write_7120 osc_resend_count_seq_write 3 7120 NULL
107693 +qib_format_hwerrors_7133 qib_format_hwerrors 5 7133 NULL
107694 +kvm_mmu_notifier_test_young_7139 kvm_mmu_notifier_test_young 3 7139 NULL
107695 +__alloc_objio_seg_7203 __alloc_objio_seg 1 7203 NULL
107696 +hdlc_loop_7255 hdlc_loop 0 7255 NULL
107697 +f_midi_start_ep_7270 f_midi_start_ep 0 7270 NULL
107698 +rx_rate_rx_frames_per_rates_read_7282 rx_rate_rx_frames_per_rates_read 3 7282 NULL
107699 +get_string_7302 get_string 0 7302 NULL
107700 +mgmt_control_7349 mgmt_control 3 7349 NULL
107701 +at_est2timeout_7365 at_est2timeout 0-1 7365 NULL
107702 +ieee80211_if_read_dot11MeshHWMPactivePathTimeout_7368 ieee80211_if_read_dot11MeshHWMPactivePathTimeout 3 7368 NULL
107703 +ath10k_read_fw_stats_7387 ath10k_read_fw_stats 3 7387 NULL
107704 +hweight_long_7388 hweight_long 1-0 7388 NULL
107705 +sl_change_mtu_7396 sl_change_mtu 2 7396 NULL
107706 +_ore_add_stripe_unit_7399 _ore_add_stripe_unit 6-3 7399 NULL
107707 +readb_7401 readb 0 7401 NULL
107708 +drm_property_create_blob_7414 drm_property_create_blob 2 7414 NULL
107709 +__copy_to_user_nocheck_7443 __copy_to_user_nocheck 0-3 7443 NULL
107710 +ip_options_get_alloc_7448 ip_options_get_alloc 1 7448 NULL
107711 +SYSC_setgroups_7454 SYSC_setgroups 1 7454 NULL
107712 +rt2x00debug_read_queue_stats_7455 rt2x00debug_read_queue_stats 3 7455 NULL
107713 +l2tp_ip6_sendmsg_7461 l2tp_ip6_sendmsg 4 7461 NULL
107714 +garp_request_join_7471 garp_request_join 4 7471 NULL nohasharray
107715 +ReadHSCX_7471 ReadHSCX 0 7471 &garp_request_join_7471
107716 +snd_pcm_lib_read1_7491 snd_pcm_lib_read1 0-3 7491 NULL
107717 +iwl_mvm_power_dbgfs_read_7502 iwl_mvm_power_dbgfs_read 0 7502 NULL
107718 +ahash_instance_headroom_7509 ahash_instance_headroom 0 7509 NULL nohasharray
107719 +sdhci_alloc_host_7509 sdhci_alloc_host 2 7509 &ahash_instance_headroom_7509
107720 +array_zalloc_7519 array_zalloc 1-2 7519 NULL
107721 +ath10k_read_htt_stats_mask_7557 ath10k_read_htt_stats_mask 3 7557 NULL
107722 +smk_read_mapped_7562 smk_read_mapped 3 7562 NULL
107723 +cfs_cpt_num_estimate_7571 cfs_cpt_num_estimate 0 7571 NULL
107724 +ocfs2_lock_create_7612 ocfs2_lock_create 0 7612 NULL
107725 +groups_alloc_7614 groups_alloc 1 7614 NULL nohasharray
107726 +create_dir_7614 create_dir 0 7614 &groups_alloc_7614
107727 +_rtw_zmalloc_7636 _rtw_zmalloc 1 7636 NULL
107728 +fault_inject_write_7662 fault_inject_write 3 7662 NULL
107729 +acpi_ex_allocate_name_string_7685 acpi_ex_allocate_name_string 2-1 7685 NULL
107730 +acpi_ns_get_pathname_length_7699 acpi_ns_get_pathname_length 0 7699 NULL
107731 +dev_write_7708 dev_write 3 7708 NULL
107732 +pci_raw_set_power_state_7729 pci_raw_set_power_state 0 7729 NULL
107733 +vxge_device_register_7752 vxge_device_register 4 7752 NULL
107734 +iwl_dbgfs_bt_cmd_read_7770 iwl_dbgfs_bt_cmd_read 3 7770 NULL
107735 +alloc_candev_7776 alloc_candev 1-2 7776 NULL
107736 +dfs_global_file_read_7787 dfs_global_file_read 3 7787 NULL
107737 +bnx2_nvram_write_7790 bnx2_nvram_write 4-2 7790 NULL
107738 +diva_os_copy_from_user_7792 diva_os_copy_from_user 4 7792 NULL nohasharray
107739 +lustre_packed_msg_size_7792 lustre_packed_msg_size 0 7792 &diva_os_copy_from_user_7792
107740 +cfs_trace_dump_debug_buffer_usrstr_7861 cfs_trace_dump_debug_buffer_usrstr 2 7861 NULL
107741 +tipc_alloc_entry_7875 tipc_alloc_entry 2 7875 NULL
107742 +config_desc_7878 config_desc 0 7878 NULL
107743 +dvb_dmxdev_read_sec_7892 dvb_dmxdev_read_sec 4 7892 NULL
107744 +xfs_trans_get_efi_7898 xfs_trans_get_efi 2 7898 NULL
107745 +libfc_host_alloc_7917 libfc_host_alloc 2 7917 NULL
107746 +f_hidg_write_7932 f_hidg_write 3 7932 NULL
107747 +integrity_digsig_verify_7956 integrity_digsig_verify 3-0 7956 NULL
107748 +smk_write_load_self_7958 smk_write_load_self 3 7958 NULL
107749 +tt3650_ci_msg_locked_8013 tt3650_ci_msg_locked 4 8013 NULL
107750 +vcs_read_8017 vcs_read 3 8017 NULL
107751 +vhost_add_used_and_signal_n_8038 vhost_add_used_and_signal_n 4 8038 NULL
107752 +ms_read_multiple_pages_8052 ms_read_multiple_pages 5-4 8052 NULL
107753 +dgrp_mon_read_8065 dgrp_mon_read 3 8065 NULL
107754 +spi_write_then_read_8073 spi_write_then_read 5-3 8073 NULL
107755 +qla4xxx_post_ping_evt_work_8074 qla4xxx_post_ping_evt_work 4 8074 NULL
107756 +venus_lookup_8121 venus_lookup 4 8121 NULL
107757 +ieee80211_if_fmt_num_buffered_multicast_8127 ieee80211_if_fmt_num_buffered_multicast 3 8127 NULL
107758 +xfs_file_fallocate_8150 xfs_file_fallocate 3-4 8150 NULL
107759 +__sk_mem_schedule_8185 __sk_mem_schedule 2 8185 NULL
107760 +ieee80211_if_fmt_dot11MeshHoldingTimeout_8187 ieee80211_if_fmt_dot11MeshHoldingTimeout 3 8187 NULL
107761 +recent_mt_proc_write_8206 recent_mt_proc_write 3 8206 NULL
107762 +__ocfs2_lock_refcount_tree_8207 __ocfs2_lock_refcount_tree 0 8207 NULL
107763 +rt2x00debug_write_bbp_8212 rt2x00debug_write_bbp 3 8212 NULL
107764 +ad7879_spi_multi_read_8218 ad7879_spi_multi_read 3 8218 NULL
107765 +play_iframe_8219 play_iframe 3 8219 NULL
107766 +kvm_mmu_page_set_gfn_8225 kvm_mmu_page_set_gfn 2 8225 NULL
107767 +sctp_ssnmap_size_8228 sctp_ssnmap_size 0-1-2 8228 NULL
107768 +ceph_sync_write_8233 ceph_sync_write 4 8233 NULL
107769 +check_xattr_ref_inode_8244 check_xattr_ref_inode 0 8244 NULL
107770 +t3_init_l2t_8261 t3_init_l2t 1 8261 NULL
107771 +init_cdev_8274 init_cdev 1 8274 NULL
107772 +rproc_recovery_write_8281 rproc_recovery_write 3 8281 NULL
107773 +qib_decode_7220_err_8315 qib_decode_7220_err 3 8315 NULL
107774 +ipwireless_send_packet_8328 ipwireless_send_packet 4 8328 NULL
107775 +tracing_entries_read_8345 tracing_entries_read 3 8345 NULL
107776 +ieee80211_if_fmt_ht_opmode_8347 ieee80211_if_fmt_ht_opmode 3 8347 NULL
107777 +generic_write_sync_8358 generic_write_sync 0 8358 NULL
107778 +ping_getfrag_8360 ping_getfrag 4-3 8360 NULL
107779 +ath6kl_lrssi_roam_write_8362 ath6kl_lrssi_roam_write 3 8362 NULL
107780 +xdi_copy_from_user_8395 xdi_copy_from_user 4 8395 NULL
107781 +zd_rf_scnprint_id_8406 zd_rf_scnprint_id 0-3 8406 NULL
107782 +smk_write_change_rule_8411 smk_write_change_rule 3 8411 NULL nohasharray
107783 +uvc_v4l2_ioctl_8411 uvc_v4l2_ioctl 2 8411 &smk_write_change_rule_8411
107784 +roccat_common2_sysfs_read_8431 roccat_common2_sysfs_read 6 8431 NULL
107785 +afs_cell_lookup_8482 afs_cell_lookup 2 8482 NULL
107786 +fore200e_chunk_alloc_8501 fore200e_chunk_alloc 4-3 8501 NULL
107787 +batadv_tt_len_8502 batadv_tt_len 0-1 8502 NULL
107788 +dev_config_8506 dev_config 3 8506 NULL
107789 +ACL_to_cifs_posix_8509 ACL_to_cifs_posix 3 8509 NULL
107790 +opticon_process_data_packet_8524 opticon_process_data_packet 3 8524 NULL
107791 +user_on_off_8552 user_on_off 2 8552 NULL
107792 +profile_remove_8556 profile_remove 3 8556 NULL
107793 +cache_slow_downcall_8570 cache_slow_downcall 2 8570 NULL
107794 +isr_dma0_done_read_8574 isr_dma0_done_read 3 8574 NULL
107795 +tower_write_8580 tower_write 3 8580 NULL
107796 +cfs_cpt_number_8618 cfs_cpt_number 0 8618 NULL
107797 +shash_setkey_unaligned_8620 shash_setkey_unaligned 3 8620 NULL
107798 +it821x_firmware_command_8628 it821x_firmware_command 3 8628 NULL
107799 +scsi_dma_map_8632 scsi_dma_map 0 8632 NULL
107800 +fuse_send_write_pages_8636 fuse_send_write_pages 0-5 8636 NULL
107801 +generic_acl_set_8658 generic_acl_set 4 8658 NULL
107802 +mlx5_vzalloc_8663 mlx5_vzalloc 1 8663 NULL
107803 +dio_bio_alloc_8677 dio_bio_alloc 5 8677 NULL
107804 +lbs_bcnmiss_read_8678 lbs_bcnmiss_read 3 8678 NULL
107805 +rproc_trace_read_8686 rproc_trace_read 3 8686 NULL
107806 +skb_frag_size_8695 skb_frag_size 0 8695 NULL
107807 +arcfb_write_8702 arcfb_write 3 8702 NULL
107808 +i_size_read_8703 i_size_read 0 8703 NULL nohasharray
107809 +init_header_8703 init_header 0 8703 &i_size_read_8703
107810 +HDLC_irq_8709 HDLC_irq 2 8709 NULL
107811 +ctrl_out_8712 ctrl_out 3-5 8712 NULL
107812 +tracing_max_lat_write_8728 tracing_max_lat_write 3 8728 NULL
107813 +jffs2_acl_count_8729 jffs2_acl_count 0-1 8729 NULL
107814 +__create_irqs_8733 __create_irqs 2 8733 NULL
107815 +tx_tx_exch_expiry_read_8749 tx_tx_exch_expiry_read 3 8749 NULL
107816 +compound_order_8750 compound_order 0 8750 NULL
107817 +ocfs2_find_path_8754 ocfs2_find_path 0 8754 NULL
107818 +yurex_write_8761 yurex_write 3 8761 NULL
107819 +joydev_compat_ioctl_8765 joydev_compat_ioctl 2 8765 NULL
107820 +kstrtoint_from_user_8778 kstrtoint_from_user 2 8778 NULL
107821 +paging32_prefetch_gpte_8783 paging32_prefetch_gpte 4 8783 NULL
107822 +ext4_try_to_write_inline_data_8785 ext4_try_to_write_inline_data 3-4 8785 NULL
107823 +__bitmap_weight_8796 __bitmap_weight 0-2 8796 NULL
107824 +cpuset_common_file_read_8800 cpuset_common_file_read 5 8800 NULL
107825 +metronomefb_write_8823 metronomefb_write 3 8823 NULL
107826 +SyS_llistxattr_8824 SyS_llistxattr 3 8824 NULL
107827 +get_queue_depth_8833 get_queue_depth 0 8833 NULL
107828 +dvb_ringbuffer_pkt_next_8834 dvb_ringbuffer_pkt_next 0-2 8834 NULL
107829 +usb_ep_queue_8839 usb_ep_queue 0 8839 NULL
107830 +debug_debug1_read_8856 debug_debug1_read 3 8856 NULL
107831 +wa_nep_queue_8858 wa_nep_queue 2 8858 NULL
107832 +radeon_drm_ioctl_8875 radeon_drm_ioctl 2 8875 NULL
107833 +compressed_bio_size_8887 compressed_bio_size 0-2 8887 NULL
107834 +ab3100_get_set_reg_8890 ab3100_get_set_reg 3 8890 NULL nohasharray
107835 +tracing_max_lat_read_8890 tracing_max_lat_read 3 8890 &ab3100_get_set_reg_8890
107836 +sdio_max_byte_size_8907 sdio_max_byte_size 0 8907 NULL
107837 +sysfs_merge_group_8917 sysfs_merge_group 0 8917 NULL
107838 +write_file_ani_8918 write_file_ani 3 8918 NULL
107839 +layout_commit_8926 layout_commit 3 8926 NULL
107840 +adjust_priv_size_8935 adjust_priv_size 0-1 8935 NULL
107841 +driver_stats_read_8944 driver_stats_read 3 8944 NULL
107842 +read_file_tgt_stats_8959 read_file_tgt_stats 3 8959 NULL
107843 +usb_allocate_stream_buffers_8964 usb_allocate_stream_buffers 3 8964 NULL
107844 +qib_qsfp_dump_8966 qib_qsfp_dump 0-3 8966 NULL
107845 +venus_mkdir_8967 venus_mkdir 4 8967 NULL
107846 +seq_open_net_8968 seq_open_net 4 8968 NULL nohasharray
107847 +vol_cdev_read_8968 vol_cdev_read 3 8968 &seq_open_net_8968
107848 +bio_integrity_get_tag_8974 bio_integrity_get_tag 3 8974 NULL
107849 +jbd2_journal_blocks_per_page_9004 jbd2_journal_blocks_per_page 0 9004 NULL
107850 +il_dbgfs_clear_ucode_stats_write_9016 il_dbgfs_clear_ucode_stats_write 3 9016 NULL
107851 +snd_emu10k1_ptr_read_9026 snd_emu10k1_ptr_read 0-2 9026 NULL
107852 +fd_ioctl_9028 fd_ioctl 3 9028 NULL
107853 +nla_put_9042 nla_put 3 9042 NULL
107854 +snd_emu10k1_synth_copy_from_user_9061 snd_emu10k1_synth_copy_from_user 3-5 9061 NULL
107855 +snd_gus_dram_peek_9062 snd_gus_dram_peek 4 9062 NULL
107856 +fib_info_hash_alloc_9075 fib_info_hash_alloc 1 9075 NULL
107857 +create_queues_9088 create_queues 2-3 9088 NULL
107858 +ftdi_prepare_write_buffer_9093 ftdi_prepare_write_buffer 3 9093 NULL
107859 +adxl34x_spi_read_block_9108 adxl34x_spi_read_block 3 9108 NULL
107860 +caif_stream_sendmsg_9110 caif_stream_sendmsg 4 9110 NULL nohasharray
107861 +gfn_to_rmap_9110 gfn_to_rmap 3-2 9110 &caif_stream_sendmsg_9110
107862 +udf_direct_IO_9111 udf_direct_IO 4 9111 NULL
107863 +pmcraid_change_queue_depth_9116 pmcraid_change_queue_depth 2 9116 NULL
107864 +apei_resources_merge_9149 apei_resources_merge 0 9149 NULL
107865 +vb2_dma_sg_alloc_9157 vb2_dma_sg_alloc 2 9157 NULL
107866 +dbg_command_buf_9165 dbg_command_buf 2 9165 NULL
107867 +isr_irqs_read_9181 isr_irqs_read 3 9181 NULL
107868 +count_leading_zeros_9183 count_leading_zeros 0 9183 NULL
107869 +altera_swap_ir_9194 altera_swap_ir 2 9194 NULL
107870 +snd_m3_get_pointer_9206 snd_m3_get_pointer 0 9206 NULL
107871 +virtqueue_add_9217 virtqueue_add 4-5 9217 NULL
107872 +tx_tx_prepared_descs_read_9221 tx_tx_prepared_descs_read 3 9221 NULL
107873 +sctp_getsockopt_delayed_ack_9232 sctp_getsockopt_delayed_ack 2 9232 NULL
107874 +hfsplus_bnode_read_u16_9262 hfsplus_bnode_read_u16 0 9262 NULL
107875 +hdpvr_read_9273 hdpvr_read 3 9273 NULL
107876 +flakey_status_9274 flakey_status 5 9274 NULL
107877 +iwl_dbgfs_stations_read_9309 iwl_dbgfs_stations_read 3 9309 NULL
107878 +ceph_sync_setxattr_9310 ceph_sync_setxattr 4 9310 NULL
107879 +ieee80211_if_fmt_txpower_9334 ieee80211_if_fmt_txpower 3 9334 NULL
107880 +nvme_trans_fmt_get_parm_header_9340 nvme_trans_fmt_get_parm_header 2 9340 NULL
107881 +ocfs2_orphan_for_truncate_9342 ocfs2_orphan_for_truncate 4 9342 NULL
107882 +ll_direct_rw_pages_9361 ll_direct_rw_pages 0 9361 NULL
107883 +sta_beacon_loss_count_read_9370 sta_beacon_loss_count_read 3 9370 NULL
107884 +get_request_type_9393 get_request_type 0 9393 NULL nohasharray
107885 +mlx4_bitmap_init_9393 mlx4_bitmap_init 5-2 9393 &get_request_type_9393
107886 +virtqueue_add_outbuf_9395 virtqueue_add_outbuf 3 9395 NULL
107887 +read_9397 read 3 9397 NULL
107888 +hash_ipportip4_expire_9415 hash_ipportip4_expire 4 9415 NULL
107889 +btrfs_drop_extents_9423 btrfs_drop_extents 4 9423 NULL
107890 +bm_realloc_pages_9431 bm_realloc_pages 2 9431 NULL
107891 +ffs_ep0_write_9438 ffs_ep0_write 3 9438 NULL
107892 +ieee80211_if_fmt_fwded_unicast_9454 ieee80211_if_fmt_fwded_unicast 3 9454 NULL
107893 +ext3_xattr_set_acl_9467 ext3_xattr_set_acl 4 9467 NULL
107894 +agp_generic_alloc_user_9470 agp_generic_alloc_user 1 9470 NULL nohasharray
107895 +get_registers_9470 get_registers 4 9470 &agp_generic_alloc_user_9470
107896 +crypt_status_9492 crypt_status 5 9492 NULL
107897 +lbs_threshold_write_9502 lbs_threshold_write 5 9502 NULL
107898 +lp_write_9511 lp_write 3 9511 NULL
107899 +mext_calc_swap_extents_9517 mext_calc_swap_extents 4 9517 NULL
107900 +scsi_tgt_kspace_exec_9522 scsi_tgt_kspace_exec 8 9522 NULL
107901 +ll_max_read_ahead_whole_mb_seq_write_9528 ll_max_read_ahead_whole_mb_seq_write 3 9528 NULL
107902 +read_file_dma_9530 read_file_dma 3 9530 NULL
107903 +iwl_dbgfs_bf_params_read_9542 iwl_dbgfs_bf_params_read 3 9542 NULL
107904 +il_dbgfs_missed_beacon_write_9546 il_dbgfs_missed_beacon_write 3 9546 NULL
107905 +compat_SyS_pwritev64_9548 compat_SyS_pwritev64 3 9548 NULL
107906 +fw_node_create_9559 fw_node_create 2 9559 NULL
107907 +kobj_map_9566 kobj_map 2-3 9566 NULL
107908 +f2fs_read_data_pages_9574 f2fs_read_data_pages 4 9574 NULL
107909 +snd_emu10k1_fx8010_read_9605 snd_emu10k1_fx8010_read 5-6 9605 NULL
107910 +lov_ost_pool_add_9626 lov_ost_pool_add 3 9626 NULL
107911 +saa7164_buffer_alloc_user_9627 saa7164_buffer_alloc_user 2 9627 NULL
107912 +ceph_copy_user_to_page_vector_9635 ceph_copy_user_to_page_vector 4-3 9635 NULL
107913 +acpi_ex_insert_into_field_9638 acpi_ex_insert_into_field 3 9638 NULL
107914 +compat_sys_keyctl_9639 compat_sys_keyctl 4 9639 NULL
107915 +ll_checksum_seq_write_9648 ll_checksum_seq_write 3 9648 NULL
107916 +ocfs2_xattr_get_rec_9652 ocfs2_xattr_get_rec 0 9652 NULL
107917 +queue_received_packet_9657 queue_received_packet 5 9657 NULL
107918 +snd_opl4_mem_proc_write_9670 snd_opl4_mem_proc_write 5 9670 NULL
107919 +dns_query_9676 dns_query 3 9676 NULL
107920 +qib_7322_handle_hwerrors_9678 qib_7322_handle_hwerrors 3 9678 NULL
107921 +__erst_read_from_storage_9690 __erst_read_from_storage 0 9690 NULL
107922 +vx_transfer_end_9701 vx_transfer_end 0 9701 NULL
107923 +fuse_iter_npages_9705 fuse_iter_npages 0 9705 NULL nohasharray
107924 +ieee80211_if_read_aid_9705 ieee80211_if_read_aid 3 9705 &fuse_iter_npages_9705
107925 +cfg80211_tx_mlme_mgmt_9715 cfg80211_tx_mlme_mgmt 3 9715 NULL
107926 +btrfs_stack_file_extent_num_bytes_9720 btrfs_stack_file_extent_num_bytes 0 9720 NULL
107927 +SYSC_ppoll_9721 SYSC_ppoll 2 9721 NULL
107928 +nla_get_u8_9736 nla_get_u8 0 9736 NULL
107929 +ieee80211_if_fmt_num_mcast_sta_9738 ieee80211_if_fmt_num_mcast_sta 3 9738 NULL
107930 +ddb_input_read_9743 ddb_input_read 3-0 9743 NULL
107931 +sta_last_ack_signal_read_9751 sta_last_ack_signal_read 3 9751 NULL
107932 +btrfs_super_root_9763 btrfs_super_root 0 9763 NULL
107933 +__blk_queue_init_tags_9778 __blk_queue_init_tags 2 9778 NULL
107934 +snd_mem_proc_write_9786 snd_mem_proc_write 3 9786 NULL
107935 +kvm_age_hva_9795 kvm_age_hva 2 9795 NULL
107936 +parse_uac2_sample_rate_range_9801 parse_uac2_sample_rate_range 0 9801 NULL
107937 +tpm_data_in_9802 tpm_data_in 0 9802 NULL
107938 +udpv6_recvmsg_9813 udpv6_recvmsg 4 9813 NULL nohasharray
107939 +ieee80211_if_read_state_9813 ieee80211_if_read_state 3 9813 &udpv6_recvmsg_9813
107940 +pmcraid_alloc_sglist_9864 pmcraid_alloc_sglist 1 9864 NULL
107941 +btrfs_free_reserved_extent_9867 btrfs_free_reserved_extent 2 9867 NULL
107942 +f1x_translate_sysaddr_to_cs_9868 f1x_translate_sysaddr_to_cs 2 9868 NULL
107943 +wil_read_file_ioblob_9878 wil_read_file_ioblob 3 9878 NULL
107944 +snd_midi_event_new_9893 snd_midi_event_new 1 9893 NULL nohasharray
107945 +bm_register_write_9893 bm_register_write 3 9893 &snd_midi_event_new_9893
107946 +snd_gf1_pcm_playback_copy_9895 snd_gf1_pcm_playback_copy 5-3 9895 NULL
107947 +nonpaging_page_fault_9908 nonpaging_page_fault 2 9908 NULL
107948 +root_nfs_parse_options_9937 root_nfs_parse_options 3 9937 NULL
107949 +pstore_ftrace_knob_read_9947 pstore_ftrace_knob_read 3 9947 NULL
107950 +read_file_misc_9948 read_file_misc 3 9948 NULL
107951 +csum_partial_copy_fromiovecend_9957 csum_partial_copy_fromiovecend 3-4 9957 NULL
107952 +SyS_gethostname_9964 SyS_gethostname 2 9964 NULL
107953 +get_free_serial_index_9969 get_free_serial_index 0 9969 NULL
107954 +btrfs_add_link_9973 btrfs_add_link 5 9973 NULL
107955 +gameport_read_9983 gameport_read 0 9983 NULL
107956 +SYSC_move_pages_9986 SYSC_move_pages 2 9986 NULL
107957 +aat2870_dump_reg_10019 aat2870_dump_reg 0 10019 NULL
107958 +ieee80211_set_probe_resp_10077 ieee80211_set_probe_resp 3 10077 NULL
107959 +get_elem_size_10110 get_elem_size 0-2 10110 NULL nohasharray
107960 +dynamic_ps_timeout_read_10110 dynamic_ps_timeout_read 3 10110 &get_elem_size_10110
107961 +gfs2_meta_read_10112 gfs2_meta_read 0 10112 NULL
107962 +SyS_migrate_pages_10134 SyS_migrate_pages 2 10134 NULL
107963 +aes_decrypt_packets_read_10155 aes_decrypt_packets_read 3 10155 NULL
107964 +rx_out_of_mem_read_10157 rx_out_of_mem_read 3 10157 NULL
107965 +hidg_alloc_ep_req_10159 hidg_alloc_ep_req 2 10159 NULL
107966 +asd_store_update_bios_10165 asd_store_update_bios 4 10165 NULL
107967 +kstrtol_from_user_10168 kstrtol_from_user 2 10168 NULL
107968 +proc_pid_attr_read_10173 proc_pid_attr_read 3 10173 NULL
107969 +jffs2_user_setxattr_10182 jffs2_user_setxattr 4 10182 NULL
107970 +hdlc_rpr_irq_10240 hdlc_rpr_irq 2 10240 NULL
107971 +cciss_proc_write_10259 cciss_proc_write 3 10259 NULL
107972 +__qlcnic_pci_sriov_enable_10281 __qlcnic_pci_sriov_enable 2 10281 NULL
107973 +snd_rme9652_capture_copy_10287 snd_rme9652_capture_copy 5 10287 NULL
107974 +read_emulate_10310 read_emulate 2-4 10310 NULL
107975 +read_file_spectral_count_10320 read_file_spectral_count 3 10320 NULL
107976 +compat_SyS_writev_10327 compat_SyS_writev 3 10327 NULL
107977 +tun_sendmsg_10337 tun_sendmsg 4 10337 NULL
107978 +ufx_alloc_urb_list_10349 ufx_alloc_urb_list 3 10349 NULL
107979 +whci_add_cap_10350 whci_add_cap 0 10350 NULL
107980 +dbAllocAny_10354 dbAllocAny 0 10354 NULL
107981 +ath6kl_listen_int_read_10355 ath6kl_listen_int_read 3 10355 NULL
107982 +ms_write_multiple_pages_10362 ms_write_multiple_pages 6-5 10362 NULL
107983 +sta_ht_capa_read_10366 sta_ht_capa_read 3 10366 NULL
107984 +ecryptfs_decode_and_decrypt_filename_10379 ecryptfs_decode_and_decrypt_filename 5 10379 NULL
107985 +do_compat_pselect_10398 do_compat_pselect 1 10398 NULL
107986 +fwtty_rx_10434 fwtty_rx 3 10434 NULL
107987 +event_phy_transmit_error_read_10471 event_phy_transmit_error_read 3 10471 NULL
107988 +hash_ipportip6_expire_10478 hash_ipportip6_expire 4 10478 NULL
107989 +nouveau_pwr_create__10483 nouveau_pwr_create_ 4 10483 NULL
107990 +ext4_itable_unused_count_10501 ext4_itable_unused_count 0 10501 NULL
107991 +qib_alloc_fast_reg_page_list_10507 qib_alloc_fast_reg_page_list 2 10507 NULL
107992 +sel_write_disable_10511 sel_write_disable 3 10511 NULL
107993 +osd_req_write_sg_kern_10514 osd_req_write_sg_kern 5 10514 NULL
107994 +rds_message_alloc_10517 rds_message_alloc 1 10517 NULL
107995 +qlcnic_pci_sriov_enable_10519 qlcnic_pci_sriov_enable 2 10519 NULL
107996 +kstrtouint_from_user_10536 kstrtouint_from_user 2 10536 NULL nohasharray
107997 +snd_pcm_lib_read_10536 snd_pcm_lib_read 0-3 10536 &kstrtouint_from_user_10536
107998 +ext4_write_begin_10576 ext4_write_begin 3-4 10576 NULL
107999 +scrub_remap_extent_10588 scrub_remap_extent 2 10588 NULL
108000 +otp_read_10594 otp_read 2-4-5 10594 NULL
108001 +supply_map_read_file_10608 supply_map_read_file 3 10608 NULL
108002 +ima_show_htable_violations_10619 ima_show_htable_violations 3 10619 NULL
108003 +nfs_idmap_lookup_id_10660 nfs_idmap_lookup_id 2 10660 NULL
108004 +efx_max_tx_len_10662 efx_max_tx_len 0-2 10662 NULL
108005 +parport_write_10669 parport_write 0 10669 NULL
108006 +edge_write_10692 edge_write 4 10692 NULL
108007 +selinux_inode_setxattr_10708 selinux_inode_setxattr 4 10708 NULL nohasharray
108008 +inl_10708 inl 0 10708 &selinux_inode_setxattr_10708
108009 +shash_async_setkey_10720 shash_async_setkey 3 10720 NULL nohasharray
108010 +pvr2_ioread_read_10720 pvr2_ioread_read 3 10720 &shash_async_setkey_10720
108011 +spi_sync_10731 spi_sync 0 10731 NULL
108012 +apu_get_register_10737 apu_get_register 0 10737 NULL nohasharray
108013 +sctp_getsockopt_maxseg_10737 sctp_getsockopt_maxseg 2 10737 &apu_get_register_10737
108014 +SyS_io_getevents_10756 SyS_io_getevents 3 10756 NULL
108015 +vhost_add_used_n_10760 vhost_add_used_n 3 10760 NULL
108016 +kvm_read_guest_atomic_10765 kvm_read_guest_atomic 4 10765 NULL
108017 +__qp_memcpy_to_queue_10779 __qp_memcpy_to_queue 2-4 10779 NULL
108018 +diva_set_trace_filter_10820 diva_set_trace_filter 0-1 10820 NULL
108019 +lbs_sleepparams_read_10840 lbs_sleepparams_read 3 10840 NULL
108020 +ida_get_new_above_10853 ida_get_new_above 0 10853 NULL
108021 +fuse_conn_max_background_read_10855 fuse_conn_max_background_read 3 10855 NULL
108022 +snd_pcm_oss_write1_10872 snd_pcm_oss_write1 3 10872 NULL
108023 +wiidebug_drm_write_10879 wiidebug_drm_write 3 10879 NULL
108024 +get_scq_10897 get_scq 2 10897 NULL
108025 +cgroup_write_string_10900 cgroup_write_string 5 10900 NULL
108026 +tifm_alloc_adapter_10903 tifm_alloc_adapter 1 10903 NULL
108027 +lprocfs_wr_atomic_10912 lprocfs_wr_atomic 3 10912 NULL
108028 +__copy_from_user_10918 __copy_from_user 0-3 10918 NULL
108029 +kobject_add_10919 kobject_add 0 10919 NULL
108030 +ar9003_dump_modal_eeprom_10959 ar9003_dump_modal_eeprom 3-2-0 10959 NULL
108031 +ci_port_test_write_10962 ci_port_test_write 3 10962 NULL
108032 +bm_entry_read_10976 bm_entry_read 3 10976 NULL
108033 +sched_autogroup_write_10984 sched_autogroup_write 3 10984 NULL
108034 +xfrm_hash_alloc_10997 xfrm_hash_alloc 1 10997 NULL
108035 +rx_filter_accum_arp_pend_requests_read_11003 rx_filter_accum_arp_pend_requests_read 3 11003 NULL
108036 +SetLineNumber_11023 SetLineNumber 0 11023 NULL
108037 +tda10048_writeregbulk_11050 tda10048_writeregbulk 4 11050 NULL
108038 +insert_inline_extent_backref_11063 insert_inline_extent_backref 8 11063 NULL
108039 +tcp_send_mss_11079 tcp_send_mss 0 11079 NULL
108040 +count_argc_11083 count_argc 0 11083 NULL
108041 +ocfs2_blocks_per_xattr_bucket_11099 ocfs2_blocks_per_xattr_bucket 0 11099 NULL
108042 +kvm_write_guest_cached_11106 kvm_write_guest_cached 4 11106 NULL
108043 +tw_change_queue_depth_11116 tw_change_queue_depth 2 11116 NULL
108044 +page_offset_11120 page_offset 0 11120 NULL
108045 +cea_db_payload_len_11124 cea_db_payload_len 0 11124 NULL nohasharray
108046 +tracing_buffers_read_11124 tracing_buffers_read 3 11124 &cea_db_payload_len_11124
108047 +alloc_alien_cache_11127 alloc_alien_cache 2 11127 NULL
108048 +snd_gf1_pcm_playback_silence_11172 snd_gf1_pcm_playback_silence 4-3 11172 NULL
108049 +il_dbgfs_rx_queue_read_11221 il_dbgfs_rx_queue_read 3 11221 NULL
108050 +comedi_alloc_spriv_11234 comedi_alloc_spriv 2 11234 NULL
108051 +hugetlbfs_read_11268 hugetlbfs_read 3 11268 NULL
108052 +ath6kl_power_params_write_11274 ath6kl_power_params_write 3 11274 NULL
108053 +__proc_daemon_file_11305 __proc_daemon_file 5 11305 NULL
108054 +ext4_xattr_check_names_11314 ext4_xattr_check_names 0 11314 NULL
108055 +bcache_dev_sectors_dirty_add_11315 bcache_dev_sectors_dirty_add 3-4 11315 NULL
108056 +sk_filter_size_11316 sk_filter_size 0 11316 NULL nohasharray
108057 +tcp_send_rcvq_11316 tcp_send_rcvq 3 11316 &sk_filter_size_11316
108058 +construct_key_11329 construct_key 3 11329 NULL nohasharray
108059 +__kfifo_out_peek_11329 __kfifo_out_peek 0-3 11329 &construct_key_11329
108060 +next_segment_11330 next_segment 0-2-1 11330 NULL
108061 +persistent_ram_buffer_map_11332 persistent_ram_buffer_map 2-1 11332 NULL
108062 +ext4_get_inline_size_11349 ext4_get_inline_size 0 11349 NULL
108063 +sel_write_create_11353 sel_write_create 3 11353 NULL nohasharray
108064 +nl80211_send_mgmt_11353 nl80211_send_mgmt 7 11353 &sel_write_create_11353
108065 +qib_get_base_info_11369 qib_get_base_info 3 11369 NULL
108066 +nft_value_dump_11381 nft_value_dump 3 11381 NULL
108067 +isku_sysfs_read_keys_capslock_11392 isku_sysfs_read_keys_capslock 6 11392 NULL
108068 +dev_irnet_write_11398 dev_irnet_write 3 11398 NULL
108069 +lprocfs_wr_evict_client_11402 lprocfs_wr_evict_client 3 11402 NULL
108070 +___alloc_bootmem_11410 ___alloc_bootmem 1 11410 NULL
108071 +str_to_user_11411 str_to_user 2 11411 NULL
108072 +mem_fw_gen_free_mem_blks_read_11413 mem_fw_gen_free_mem_blks_read 3 11413 NULL
108073 +ath6kl_wmi_test_rx_11414 ath6kl_wmi_test_rx 3 11414 NULL
108074 +adis16480_show_firmware_revision_11417 adis16480_show_firmware_revision 3 11417 NULL nohasharray
108075 +import_sec_validate_get_11417 import_sec_validate_get 0 11417 &adis16480_show_firmware_revision_11417
108076 +trace_options_read_11419 trace_options_read 3 11419 NULL
108077 +i40e_dbg_command_write_11421 i40e_dbg_command_write 3 11421 NULL
108078 +xd_read_multiple_pages_11422 xd_read_multiple_pages 5-4 11422 NULL
108079 +bttv_read_11432 bttv_read 3 11432 NULL
108080 +create_zero_mask_11453 create_zero_mask 0-1 11453 NULL
108081 +do_blockdev_direct_IO_11455 do_blockdev_direct_IO 0-6 11455 NULL
108082 +pci_set_power_state_11479 pci_set_power_state 0 11479 NULL nohasharray
108083 +sca3000_read_first_n_hw_rb_11479 sca3000_read_first_n_hw_rb 2 11479 &pci_set_power_state_11479
108084 +xfs_file_buffered_aio_write_11492 xfs_file_buffered_aio_write 4 11492 NULL
108085 +sd_do_mode_sense_11507 sd_do_mode_sense 5 11507 NULL
108086 +kmem_zalloc_11510 kmem_zalloc 1 11510 NULL
108087 +ll_direct_IO_26_seg_11518 ll_direct_IO_26_seg 0 11518 NULL
108088 +twl_direction_in_11527 twl_direction_in 2 11527 NULL
108089 +skb_cow_data_11565 skb_cow_data 0 11565 NULL
108090 +lpfc_idiag_ctlacc_write_11576 lpfc_idiag_ctlacc_write 3 11576 NULL
108091 +oprofilefs_ulong_to_user_11582 oprofilefs_ulong_to_user 3 11582 NULL
108092 +batadv_iv_ogm_orig_add_if_11586 batadv_iv_ogm_orig_add_if 2 11586 NULL
108093 +snd_pcm_action_11589 snd_pcm_action 0 11589 NULL
108094 +fw_device_op_ioctl_11595 fw_device_op_ioctl 2 11595 NULL
108095 +batadv_iv_ogm_orig_del_if_11604 batadv_iv_ogm_orig_del_if 2 11604 NULL
108096 +SYSC_mq_timedsend_11607 SYSC_mq_timedsend 3 11607 NULL
108097 +sisusb_send_bridge_packet_11649 sisusb_send_bridge_packet 2 11649 NULL
108098 +nla_total_size_11658 nla_total_size 1-0 11658 NULL
108099 +slab_ksize_11664 slab_ksize 0 11664 NULL
108100 +ide_queue_pc_tail_11673 ide_queue_pc_tail 5 11673 NULL
108101 +compat_SyS_msgsnd_11675 compat_SyS_msgsnd 3 11675 NULL
108102 +btrfs_alloc_delayed_item_11678 btrfs_alloc_delayed_item 1 11678 NULL
108103 +sctp_setsockopt_hmac_ident_11687 sctp_setsockopt_hmac_ident 3 11687 NULL
108104 +split_11691 split 2 11691 NULL
108105 +snd_ctl_elem_user_tlv_11695 snd_ctl_elem_user_tlv 3 11695 NULL
108106 +blk_rq_cur_bytes_11723 blk_rq_cur_bytes 0 11723 NULL
108107 +dm_bio_prison_create_11749 dm_bio_prison_create 1 11749 NULL
108108 +iwl_dbgfs_qos_read_11753 iwl_dbgfs_qos_read 3 11753 NULL
108109 +ps_pspoll_timeouts_read_11776 ps_pspoll_timeouts_read 3 11776 NULL
108110 +btrfs_key_blockptr_11786 btrfs_key_blockptr 0 11786 NULL
108111 +pcpu_fc_alloc_11818 pcpu_fc_alloc 2 11818 NULL
108112 +umc_device_register_11824 umc_device_register 0 11824 NULL
108113 +zerocopy_sg_from_iovec_11828 zerocopy_sg_from_iovec 3 11828 NULL
108114 +sctp_setsockopt_maxseg_11829 sctp_setsockopt_maxseg 3 11829 NULL
108115 +rts51x_read_status_11830 rts51x_read_status 4 11830 NULL
108116 +unix_stream_connect_11844 unix_stream_connect 3 11844 NULL
108117 +ecryptfs_copy_filename_11868 ecryptfs_copy_filename 4 11868 NULL
108118 +ieee80211_rx_bss_info_11887 ieee80211_rx_bss_info 3 11887 NULL
108119 +mdc_rename_11899 mdc_rename 4-6 11899 NULL
108120 +xstateregs_get_11906 xstateregs_get 4 11906 NULL
108121 +ti_write_11916 ti_write 4 11916 NULL
108122 +fs_devrw_entry_11924 fs_devrw_entry 3 11924 NULL
108123 +bitmap_remap_11929 bitmap_remap 5 11929 NULL
108124 +atomic_sub_return_11939 atomic_sub_return 0-1 11939 NULL
108125 +r1_sync_page_io_11963 r1_sync_page_io 3 11963 NULL
108126 +f1x_swap_interleaved_region_11970 f1x_swap_interleaved_region 0-2 11970 NULL
108127 +read_and_add_raw_conns_11987 read_and_add_raw_conns 0 11987 NULL
108128 +i40e_pci_sriov_configure_12011 i40e_pci_sriov_configure 2 12011 NULL
108129 +ftdi_elan_total_command_size_12045 ftdi_elan_total_command_size 0 12045 NULL
108130 +ieee80211_if_read_user_power_level_12050 ieee80211_if_read_user_power_level 3 12050 NULL
108131 +il4965_ucode_tx_stats_read_12064 il4965_ucode_tx_stats_read 3 12064 NULL
108132 +ptc_proc_write_12076 ptc_proc_write 3 12076 NULL
108133 +batadv_tt_global_size_mod_12085 batadv_tt_global_size_mod 3 12085 NULL
108134 +rtw_malloc2d_12102 rtw_malloc2d 1-2-3 12102 NULL
108135 +alloc_bulk_urbs_generic_12127 alloc_bulk_urbs_generic 5 12127 NULL
108136 +set_powered_12129 set_powered 4 12129 NULL
108137 +ramoops_init_prz_12134 ramoops_init_prz 5 12134 NULL
108138 +xfs_handle_to_dentry_12135 xfs_handle_to_dentry 3 12135 NULL
108139 +rawv6_seticmpfilter_12137 rawv6_seticmpfilter 5 12137 NULL
108140 +rawsock_recvmsg_12144 rawsock_recvmsg 4 12144 NULL
108141 +btmrvl_sdio_host_to_card_12152 btmrvl_sdio_host_to_card 3 12152 NULL
108142 +vmbus_open_12154 vmbus_open 2-3 12154 NULL
108143 +fnic_reset_stats_write_12177 fnic_reset_stats_write 3 12177 NULL
108144 +LNetEQAlloc_12178 LNetEQAlloc 1 12178 NULL
108145 +ddp_make_gl_12179 ddp_make_gl 1 12179 NULL
108146 +compat_do_arpt_set_ctl_12184 compat_do_arpt_set_ctl 4 12184 NULL
108147 +ip_generic_getfrag_12187 ip_generic_getfrag 3-4 12187 NULL
108148 +snd_pcm_kernel_ioctl_12219 snd_pcm_kernel_ioctl 0 12219 NULL
108149 +fuse_get_req_12221 fuse_get_req 2 12221 NULL nohasharray
108150 +aat2870_reg_read_file_12221 aat2870_reg_read_file 3 12221 &fuse_get_req_12221
108151 +__alloc_bootmem_low_nopanic_12235 __alloc_bootmem_low_nopanic 1 12235 NULL
108152 +ib_uverbs_unmarshall_recv_12251 ib_uverbs_unmarshall_recv 5 12251 NULL
108153 +shash_compat_setkey_12267 shash_compat_setkey 3 12267 NULL
108154 +add_sctp_bind_addr_12269 add_sctp_bind_addr 3 12269 NULL
108155 +note_last_dentry_12285 note_last_dentry 3 12285 NULL
108156 +roundup_to_multiple_of_64_12288 roundup_to_multiple_of_64 0-1 12288 NULL nohasharray
108157 +il_dbgfs_nvm_read_12288 il_dbgfs_nvm_read 3 12288 &roundup_to_multiple_of_64_12288
108158 +bt_sock_recvmsg_12316 bt_sock_recvmsg 4 12316 NULL
108159 +pcbit_writecmd_12332 pcbit_writecmd 2 12332 NULL
108160 +mptctl_ioctl_12355 mptctl_ioctl 2 12355 NULL
108161 +__nf_ct_ext_add_length_12364 __nf_ct_ext_add_length 3 12364 NULL
108162 +xfs_iext_inline_to_direct_12384 xfs_iext_inline_to_direct 2 12384 NULL
108163 +btrfs_file_extent_ram_bytes_12391 btrfs_file_extent_ram_bytes 0 12391 NULL nohasharray
108164 +populate_dir_12391 populate_dir 0 12391 &btrfs_file_extent_ram_bytes_12391 nohasharray
108165 +write_file_dump_12391 write_file_dump 3 12391 &populate_dir_12391
108166 +hbucket_elem_add_12416 hbucket_elem_add 3 12416 NULL
108167 +ieee80211_if_read_num_mcast_sta_12419 ieee80211_if_read_num_mcast_sta 3 12419 NULL
108168 +ptlrpc_set_wait_12426 ptlrpc_set_wait 0 12426 NULL
108169 +cfs_array_alloc_12441 cfs_array_alloc 2 12441 NULL
108170 +skb_do_copy_data_nocache_12465 skb_do_copy_data_nocache 5 12465 NULL
108171 +x25_sendmsg_12487 x25_sendmsg 4 12487 NULL
108172 +fnic_trace_ctrl_read_12497 fnic_trace_ctrl_read 3 12497 NULL
108173 +qib_alloc_fast_reg_mr_12526 qib_alloc_fast_reg_mr 2 12526 NULL
108174 +xfs_get_extsz_hint_12531 xfs_get_extsz_hint 0 12531 NULL
108175 +hvc_alloc_12579 hvc_alloc 4 12579 NULL
108176 +pcpu_extend_area_map_12589 pcpu_extend_area_map 2 12589 NULL
108177 +tlbflush_write_file_12598 tlbflush_write_file 3 12598 NULL
108178 +vhci_put_user_12604 vhci_put_user 4 12604 NULL
108179 +sdhci_pltfm_init_12627 sdhci_pltfm_init 3 12627 NULL
108180 +pwr_rcvd_awake_bcns_cnt_read_12632 pwr_rcvd_awake_bcns_cnt_read 3 12632 NULL
108181 +pn_sendmsg_12640 pn_sendmsg 4 12640 NULL
108182 +dwc3_link_state_write_12641 dwc3_link_state_write 3 12641 NULL
108183 +nr_recvmsg_12649 nr_recvmsg 4 12649 NULL
108184 +rtw_android_get_link_speed_12655 rtw_android_get_link_speed 0 12655 NULL
108185 +ocfs2_read_block_12659 ocfs2_read_block 0 12659 NULL
108186 +lustre_pack_request_v2_12665 lustre_pack_request_v2 0 12665 NULL
108187 +sel_read_class_12669 sel_read_class 3 12669 NULL nohasharray
108188 +sparse_mem_maps_populate_node_12669 sparse_mem_maps_populate_node 4 12669 &sel_read_class_12669
108189 +ext4_writepage_trans_blocks_12674 ext4_writepage_trans_blocks 0 12674 NULL
108190 +iwl_dbgfs_calib_disabled_write_12707 iwl_dbgfs_calib_disabled_write 3 12707 NULL
108191 +ieee80211_if_read_num_buffered_multicast_12716 ieee80211_if_read_num_buffered_multicast 3 12716 NULL
108192 +ivtv_write_12721 ivtv_write 3 12721 NULL
108193 +key_rx_spec_read_12736 key_rx_spec_read 3 12736 NULL
108194 +__mei_cl_async_send_12737 __mei_cl_async_send 3 12737 NULL
108195 +ieee80211_if_read_dot11MeshMaxRetries_12756 ieee80211_if_read_dot11MeshMaxRetries 3 12756 NULL
108196 +listxattr_12769 listxattr 3 12769 NULL
108197 +sctp_ssnmap_init_12772 sctp_ssnmap_init 2-3 12772 NULL
108198 +scsi_adjust_queue_depth_12802 scsi_adjust_queue_depth 3 12802 NULL
108199 +xfs_inumbers_fmt_12817 xfs_inumbers_fmt 3 12817 NULL
108200 +readq_12825 readq 0 12825 NULL
108201 +SyS_add_key_12834 SyS_add_key 4 12834 NULL
108202 +TSS_authhmac_12839 TSS_authhmac 3 12839 NULL
108203 +spidev_sync_12842 spidev_sync 0 12842 NULL
108204 +spidev_ioctl_12846 spidev_ioctl 2 12846 NULL
108205 +ath9k_dump_4k_modal_eeprom_12883 ath9k_dump_4k_modal_eeprom 3-2 12883 NULL
108206 +get_leb_cnt_12892 get_leb_cnt 0-2 12892 NULL
108207 +get_virtual_node_size_12908 get_virtual_node_size 0 12908 NULL
108208 +rds_pages_in_vec_12922 rds_pages_in_vec 0 12922 NULL
108209 +do_inode_permission_12946 do_inode_permission 0 12946 NULL
108210 +bm_status_write_12964 bm_status_write 3 12964 NULL
108211 +raid56_parity_recover_12987 raid56_parity_recover 5 12987 NULL
108212 +TransmitTcb_12989 TransmitTcb 4 12989 NULL
108213 +sk_peek_offset_12991 sk_peek_offset 0 12991 NULL
108214 +subsystem_filter_write_13022 subsystem_filter_write 3 13022 NULL
108215 +generic_segment_checks_13041 generic_segment_checks 0 13041 NULL
108216 +ocfs2_write_begin_13045 ocfs2_write_begin 3-4 13045 NULL
108217 +__dn_setsockopt_13060 __dn_setsockopt 5 13060 NULL nohasharray
108218 +ptlrpc_lprocfs_threads_min_seq_write_13060 ptlrpc_lprocfs_threads_min_seq_write 3 13060 &__dn_setsockopt_13060
108219 +biovec_create_pool_13079 biovec_create_pool 2 13079 NULL
108220 +xattr_getsecurity_13090 xattr_getsecurity 0 13090 NULL
108221 +ttm_dma_pool_alloc_new_pages_13105 ttm_dma_pool_alloc_new_pages 3 13105 NULL
108222 +SyS_msgrcv_13109 SyS_msgrcv 3 13109 NULL
108223 +snd_rme96_playback_copy_13111 snd_rme96_playback_copy 5 13111 NULL
108224 +bfad_debugfs_read_13119 bfad_debugfs_read 3 13119 NULL
108225 +blk_update_request_13146 blk_update_request 3 13146 NULL
108226 +ocfs2_quota_trans_credits_13150 ocfs2_quota_trans_credits 0 13150 NULL
108227 +caif_stream_recvmsg_13173 caif_stream_recvmsg 4 13173 NULL
108228 +pwr_disable_ps_read_13176 pwr_disable_ps_read 3 13176 NULL
108229 +ucs2_strlen_13178 ucs2_strlen 0 13178 NULL
108230 +dgrp_net_ioctl_13183 dgrp_net_ioctl 2 13183 NULL
108231 +create_trace_uprobe_13184 create_trace_uprobe 1 13184 NULL
108232 +comedi_read_13199 comedi_read 3 13199 NULL
108233 +hash_ipport4_expire_13201 hash_ipport4_expire 4 13201 NULL
108234 +mmc_ext_csd_read_13205 mmc_ext_csd_read 3 13205 NULL
108235 +svm_msrpm_offset_13220 svm_msrpm_offset 0-1 13220 NULL
108236 +fnic_trace_ctrl_write_13229 fnic_trace_ctrl_write 3 13229 NULL
108237 +asix_read_cmd_13245 asix_read_cmd 5 13245 NULL
108238 +init_tid_tabs_13252 init_tid_tabs 2-3-4 13252 NULL
108239 +bio_integrity_trim_13259 bio_integrity_trim 3 13259 NULL
108240 +simple_attr_write_13260 simple_attr_write 3 13260 NULL
108241 +pmcraid_notify_aen_13274 pmcraid_notify_aen 3 13274 NULL
108242 +il4965_stats_flag_13281 il4965_stats_flag 3-0 13281 NULL
108243 +lpfc_idiag_mbxacc_get_setup_13282 lpfc_idiag_mbxacc_get_setup 0 13282 NULL
108244 +sd_major_13294 sd_major 0-1 13294 NULL
108245 +module_param_sysfs_setup_13296 module_param_sysfs_setup 0 13296 NULL
108246 +__clone_and_map_data_bio_13334 __clone_and_map_data_bio 4-8 13334 NULL
108247 +kvm_read_nested_guest_page_13337 kvm_read_nested_guest_page 5 13337 NULL
108248 +hscx_empty_fifo_13360 hscx_empty_fifo 2 13360 NULL
108249 +iso_sched_alloc_13377 iso_sched_alloc 1 13377 NULL nohasharray
108250 +wep_key_not_found_read_13377 wep_key_not_found_read 3 13377 &iso_sched_alloc_13377
108251 +ext4_meta_trans_blocks_13380 ext4_meta_trans_blocks 0-3-2 13380 NULL
108252 +lov_mds_md_size_13388 lov_mds_md_size 0-1 13388 NULL nohasharray
108253 +dis_bypass_write_13388 dis_bypass_write 3 13388 &lov_mds_md_size_13388
108254 +netxen_alloc_sds_rings_13417 netxen_alloc_sds_rings 2 13417 NULL
108255 +sctp_setsockopt_peer_primary_addr_13440 sctp_setsockopt_peer_primary_addr 3 13440 NULL
108256 +ath6kl_cfg80211_connect_event_13443 ath6kl_cfg80211_connect_event 8-9-7 13443 NULL
108257 +sb_init_dio_done_wq_13482 sb_init_dio_done_wq 0 13482 NULL
108258 +data_read_13494 data_read 3 13494 NULL
108259 +ioat_chansts_32_13506 ioat_chansts_32 0 13506 NULL
108260 +ocfs2_align_bytes_to_blocks_13512 ocfs2_align_bytes_to_blocks 0-2 13512 NULL
108261 +core_status_13515 core_status 4 13515 NULL
108262 +smk_write_mapped_13519 smk_write_mapped 3 13519 NULL
108263 +bm_init_13529 bm_init 2 13529 NULL
108264 +llcp_sock_recvmsg_13556 llcp_sock_recvmsg 4 13556 NULL
108265 +ieee80211_if_read_ap_power_level_13558 ieee80211_if_read_ap_power_level 3 13558 NULL
108266 +hash_net4_expire_13559 hash_net4_expire 4 13559 NULL
108267 +read_file_antenna_13574 read_file_antenna 3 13574 NULL
108268 +cache_write_13589 cache_write 3 13589 NULL
108269 +Rd_Indx_13602 Rd_Indx 3-2 13602 NULL
108270 +wm8994_bulk_write_13615 wm8994_bulk_write 2-3 13615 NULL
108271 +pmcraid_get_minor_13619 pmcraid_get_minor 0 13619 NULL
108272 +packet_snd_13634 packet_snd 3 13634 NULL
108273 +blk_msg_write_13655 blk_msg_write 3 13655 NULL
108274 +cache_downcall_13666 cache_downcall 3 13666 NULL
108275 +ext3_xattr_list_entries_13682 ext3_xattr_list_entries 0 13682 NULL
108276 +nv94_aux_13689 nv94_aux 2-5 13689 NULL
108277 +usb_get_string_13693 usb_get_string 0 13693 NULL
108278 +fw_iso_buffer_alloc_13704 fw_iso_buffer_alloc 2 13704 NULL
108279 +audit_unpack_string_13748 audit_unpack_string 3 13748 NULL
108280 +ieee802154_alloc_device_13767 ieee802154_alloc_device 1 13767 NULL
108281 +fb_sys_read_13778 fb_sys_read 3 13778 NULL
108282 +ath6kl_mgmt_powersave_ap_13791 ath6kl_mgmt_powersave_ap 6 13791 NULL
108283 +random_read_13815 random_read 3 13815 NULL
108284 +mutex_lock_interruptible_nested_13817 mutex_lock_interruptible_nested 0 13817 NULL
108285 +hsi_register_board_info_13820 hsi_register_board_info 2 13820 NULL
108286 +___mei_cl_send_13821 ___mei_cl_send 3 13821 NULL
108287 +enc_pools_insert_13849 enc_pools_insert 3 13849 NULL
108288 +evdev_ioctl_compat_13851 evdev_ioctl_compat 2 13851 NULL
108289 +compat_ip_setsockopt_13870 compat_ip_setsockopt 5 13870 NULL
108290 +qp_memcpy_to_queue_13886 qp_memcpy_to_queue 5-2 13886 NULL
108291 +snd_pcm_aio_read_13900 snd_pcm_aio_read 3 13900 NULL
108292 +cfg80211_inform_bss_width_13933 cfg80211_inform_bss_width 9 13933 NULL
108293 +ext3_xattr_block_get_13936 ext3_xattr_block_get 0 13936 NULL
108294 +ieee80211_if_read_dot11MeshForwarding_13940 ieee80211_if_read_dot11MeshForwarding 3 13940 NULL nohasharray
108295 +ocfs2_xa_value_truncate_13940 ocfs2_xa_value_truncate 2 13940 &ieee80211_if_read_dot11MeshForwarding_13940
108296 +iwl_dbgfs_protection_mode_read_13943 iwl_dbgfs_protection_mode_read 3 13943 NULL
108297 +ieee80211_if_read_min_discovery_timeout_13946 ieee80211_if_read_min_discovery_timeout 3 13946 NULL
108298 +lpfc_idiag_queacc_read_13950 lpfc_idiag_queacc_read 3 13950 NULL
108299 +osc_grant_shrink_interval_seq_write_13952 osc_grant_shrink_interval_seq_write 3 13952 NULL
108300 +ocfs2_refresh_slot_info_13957 ocfs2_refresh_slot_info 0 13957 NULL
108301 +snd_pcm_plug_slave_size_13967 snd_pcm_plug_slave_size 0-2 13967 NULL
108302 +qcam_read_13977 qcam_read 3 13977 NULL
108303 +dsp_read_13980 dsp_read 2 13980 NULL
108304 +dvb_demux_read_13981 dvb_demux_read 3 13981 NULL
108305 +create_files_14003 create_files 0 14003 NULL
108306 +sddr09_write_data_14014 sddr09_write_data 3 14014 NULL
108307 +btrfs_get_blocks_direct_14016 btrfs_get_blocks_direct 2 14016 NULL
108308 +dmi_format_ids_14018 dmi_format_ids 2 14018 NULL
108309 +iscsi_create_flashnode_conn_14022 iscsi_create_flashnode_conn 4 14022 NULL
108310 +dvb_usercopy_14036 dvb_usercopy 2 14036 NULL
108311 +read_def_modal_eeprom_14041 read_def_modal_eeprom 3 14041 NULL
108312 +ieee80211_if_fmt_aid_14055 ieee80211_if_fmt_aid 3 14055 NULL
108313 +ovs_nla_alloc_flow_actions_14056 ovs_nla_alloc_flow_actions 1 14056 NULL
108314 +sta_agg_status_read_14058 sta_agg_status_read 3 14058 NULL
108315 +lov_stripeoffset_seq_write_14078 lov_stripeoffset_seq_write 3 14078 NULL
108316 +do_proc_readlink_14096 do_proc_readlink 3 14096 NULL
108317 +compat_sys_pselect6_14105 compat_sys_pselect6 1 14105 NULL
108318 +ext4_journal_blocks_per_page_14127 ext4_journal_blocks_per_page 0 14127 NULL
108319 +isku_sysfs_read_light_14140 isku_sysfs_read_light 6 14140 NULL
108320 +em_canid_change_14150 em_canid_change 3 14150 NULL
108321 +gsm_dlci_data_14155 gsm_dlci_data 3 14155 NULL
108322 +print_input_mask_14168 print_input_mask 3-0 14168 NULL
108323 +ocfs2_xattr_value_truncate_14183 ocfs2_xattr_value_truncate 3 14183 NULL
108324 +datafab_read_data_14186 datafab_read_data 4 14186 NULL
108325 +hfsplus_brec_find_14200 hfsplus_brec_find 0 14200 NULL
108326 +alloc_async_14208 alloc_async 1 14208 NULL
108327 +ath6kl_regread_write_14220 ath6kl_regread_write 3 14220 NULL
108328 +ieee80211_if_write_uapsd_max_sp_len_14233 ieee80211_if_write_uapsd_max_sp_len 3 14233 NULL
108329 +dma_declare_coherent_memory_14244 dma_declare_coherent_memory 4 14244 NULL
108330 +ath6kl_connect_event_14267 ath6kl_connect_event 7-8-9 14267 NULL
108331 +rr_status_14293 rr_status 5 14293 NULL
108332 +read_default_ldt_14302 read_default_ldt 2 14302 NULL
108333 +oo_objects_14319 oo_objects 0 14319 NULL
108334 +ll_get_user_pages_14328 ll_get_user_pages 3-2-0 14328 NULL
108335 +p9_client_zc_rpc_14345 p9_client_zc_rpc 7 14345 NULL
108336 +alloc_tx_struct_14349 alloc_tx_struct 1 14349 NULL
108337 +hash_ipportnet4_expire_14354 hash_ipportnet4_expire 4 14354 NULL
108338 +snd_pcm_lib_readv_14363 snd_pcm_lib_readv 0-3 14363 NULL
108339 +ath6kl_regdump_read_14393 ath6kl_regdump_read 3 14393 NULL
108340 +smk_write_onlycap_14400 smk_write_onlycap 3 14400 NULL
108341 +mtd_concat_create_14416 mtd_concat_create 2 14416 NULL
108342 +get_kcore_size_14425 get_kcore_size 0 14425 NULL
108343 +block_size_14443 block_size 0 14443 NULL
108344 +lmv_user_md_size_14456 lmv_user_md_size 0-1 14456 NULL
108345 +snd_emu10k1_proc_spdif_status_14457 snd_emu10k1_proc_spdif_status 4-5 14457 NULL
108346 +ath10k_write_htt_stats_mask_14458 ath10k_write_htt_stats_mask 3 14458 NULL
108347 +lustre_msg_size_v2_14470 lustre_msg_size_v2 0 14470 NULL
108348 +dma_transfer_size_14473 dma_transfer_size 0 14473 NULL
108349 +udplite_getfrag_14479 udplite_getfrag 3-4 14479 NULL
108350 +ieee80211_if_read_dot11MeshGateAnnouncementProtocol_14486 ieee80211_if_read_dot11MeshGateAnnouncementProtocol 3 14486 NULL
108351 +ocfs2_debug_read_14507 ocfs2_debug_read 3 14507 NULL
108352 +ep0_write_14536 ep0_write 3 14536 NULL nohasharray
108353 +dataflash_read_user_otp_14536 dataflash_read_user_otp 3-2 14536 &ep0_write_14536
108354 +picolcd_debug_eeprom_read_14549 picolcd_debug_eeprom_read 3 14549 NULL
108355 +qp_host_alloc_queue_14566 qp_host_alloc_queue 1 14566 NULL
108356 +SyS_setdomainname_14569 SyS_setdomainname 2 14569 NULL
108357 +idmap_pipe_downcall_14591 idmap_pipe_downcall 3 14591 NULL
108358 +ceph_osdc_alloc_request_14597 ceph_osdc_alloc_request 3 14597 NULL
108359 +dbJoin_14644 dbJoin 0 14644 NULL
108360 +profile_replace_14652 profile_replace 3 14652 NULL
108361 +min_bytes_needed_14675 min_bytes_needed 0 14675 NULL
108362 +nvme_trans_log_info_exceptions_14677 nvme_trans_log_info_exceptions 3 14677 NULL
108363 +pipeline_enc_tx_stat_fifo_int_read_14680 pipeline_enc_tx_stat_fifo_int_read 3 14680 NULL
108364 +ieee80211_if_fmt_rc_rateidx_mask_2ghz_14683 ieee80211_if_fmt_rc_rateidx_mask_2ghz 3 14683 NULL
108365 +SyS_fsetxattr_14702 SyS_fsetxattr 4 14702 NULL
108366 +persistent_ram_ecc_string_14704 persistent_ram_ecc_string 0 14704 NULL
108367 +u_audio_playback_14709 u_audio_playback 3 14709 NULL
108368 +rtw_cbuf_alloc_14710 rtw_cbuf_alloc 1 14710 NULL
108369 +cgroup_path_14713 cgroup_path 3 14713 NULL
108370 +vfd_write_14717 vfd_write 3 14717 NULL
108371 +__blk_end_request_14729 __blk_end_request 3 14729 NULL
108372 +raid1_resize_14740 raid1_resize 2 14740 NULL
108373 +i915_error_state_buf_init_14742 i915_error_state_buf_init 2 14742 NULL
108374 +btrfs_inode_extref_name_len_14752 btrfs_inode_extref_name_len 0 14752 NULL
108375 +rx_rx_cmplt_read_14753 rx_rx_cmplt_read 3 14753 NULL
108376 +regmap_range_read_file_14775 regmap_range_read_file 3 14775 NULL
108377 +sta_dev_read_14782 sta_dev_read 3 14782 NULL
108378 +keys_proc_write_14792 keys_proc_write 3 14792 NULL
108379 +ext4_kvmalloc_14796 ext4_kvmalloc 1 14796 NULL
108380 +__kfifo_in_14797 __kfifo_in 3-0 14797 NULL
108381 +hpet_readl_14801 hpet_readl 0 14801 NULL nohasharray
108382 +snd_als300_gcr_read_14801 snd_als300_gcr_read 0 14801 &hpet_readl_14801
108383 +do_tune_cpucache_14828 do_tune_cpucache 2 14828 NULL
108384 +mrp_attr_create_14853 mrp_attr_create 3 14853 NULL
108385 +lcd_write_14857 lcd_write 3 14857 NULL
108386 +get_user_cpu_mask_14861 get_user_cpu_mask 2 14861 NULL
108387 +gmux_index_read8_14890 gmux_index_read8 0 14890 NULL
108388 +acpi_os_allocate_14892 acpi_os_allocate 1 14892 NULL
108389 +SYSC_readv_14901 SYSC_readv 3 14901 NULL
108390 +__arch_hweight64_14923 __arch_hweight64 0 14923 NULL nohasharray
108391 +qp_memcpy_to_queue_iov_14923 qp_memcpy_to_queue_iov 5-2 14923 &__arch_hweight64_14923
108392 +ocfs2_expand_nonsparse_inode_14936 ocfs2_expand_nonsparse_inode 3-4 14936 NULL
108393 +queue_cnt_14951 queue_cnt 0 14951 NULL
108394 +unix_dgram_recvmsg_14952 unix_dgram_recvmsg 4 14952 NULL
108395 +videobuf_read_stream_14956 videobuf_read_stream 3 14956 NULL
108396 +mce_flush_rx_buffer_14976 mce_flush_rx_buffer 2 14976 NULL
108397 +setkey_14987 setkey 3 14987 NULL nohasharray
108398 +gpio_twl4030_write_14987 gpio_twl4030_write 1 14987 &setkey_14987
108399 +xfs_dinode_size_14996 xfs_dinode_size 0 14996 NULL
108400 +blk_integrity_tuple_size_15027 blk_integrity_tuple_size 0 15027 NULL
108401 +cld_pipe_downcall_15058 cld_pipe_downcall 3 15058 NULL
108402 +ieee80211_if_read_uapsd_max_sp_len_15067 ieee80211_if_read_uapsd_max_sp_len 3 15067 NULL
108403 +nfs4_write_cached_acl_15070 nfs4_write_cached_acl 4 15070 NULL
108404 +ntfs_copy_from_user_15072 ntfs_copy_from_user 3-5-0 15072 NULL
108405 +pppoe_recvmsg_15073 pppoe_recvmsg 4 15073 NULL
108406 +ceph_calc_ceph_pg_15075 ceph_calc_ceph_pg 0 15075 NULL
108407 +smscore_load_firmware_family2_15086 smscore_load_firmware_family2 3 15086 NULL
108408 +compat_SyS_pwritev_15118 compat_SyS_pwritev 3 15118 NULL
108409 +hex_dump_to_buffer_15121 hex_dump_to_buffer 6 15121 NULL
108410 +start_port_15124 start_port 0 15124 NULL
108411 +ipwireless_ppp_mru_15153 ipwireless_ppp_mru 0 15153 NULL
108412 +iwl_dbgfs_sta_drain_write_15167 iwl_dbgfs_sta_drain_write 3 15167 NULL
108413 +SYSC_setdomainname_15180 SYSC_setdomainname 2 15180 NULL
108414 +iscsi_create_endpoint_15193 iscsi_create_endpoint 1 15193 NULL
108415 +mtt_alloc_res_15211 mtt_alloc_res 5 15211 NULL
108416 +bfad_debugfs_write_regrd_15218 bfad_debugfs_write_regrd 3 15218 NULL
108417 +iwl_dbgfs_sram_write_15239 iwl_dbgfs_sram_write 3 15239 NULL
108418 +il_dbgfs_rx_stats_read_15243 il_dbgfs_rx_stats_read 3 15243 NULL
108419 +simple_strtol_15273 simple_strtol 0 15273 NULL
108420 +fw_realloc_buffer_15280 fw_realloc_buffer 2 15280 NULL
108421 +ocfs2_read_refcount_block_15305 ocfs2_read_refcount_block 0 15305 NULL
108422 +xlog_ticket_alloc_15335 xlog_ticket_alloc 2 15335 NULL
108423 +kovaplus_sysfs_read_15337 kovaplus_sysfs_read 6 15337 NULL
108424 +ioread16_15342 ioread16 0 15342 NULL
108425 +ept_prefetch_gpte_15348 ept_prefetch_gpte 4 15348 NULL
108426 +acpi_ut_create_string_object_15360 acpi_ut_create_string_object 1 15360 NULL
108427 +ext4_direct_IO_15369 ext4_direct_IO 4 15369 NULL
108428 +graph_depth_read_15371 graph_depth_read 3 15371 NULL
108429 +compat_sys_process_vm_readv_15374 compat_sys_process_vm_readv 3-5 15374 NULL
108430 +fq_codel_zalloc_15378 fq_codel_zalloc 1 15378 NULL
108431 +alloc_fddidev_15382 alloc_fddidev 1 15382 NULL
108432 +pipeline_csum_to_rx_xfer_swi_read_15403 pipeline_csum_to_rx_xfer_swi_read 3 15403 NULL
108433 +get_modalias_15406 get_modalias 2 15406 NULL
108434 +blockdev_direct_IO_15408 blockdev_direct_IO 5 15408 NULL
108435 +__videobuf_copy_to_user_15423 __videobuf_copy_to_user 4-0 15423 NULL
108436 +tcp_mtu_to_mss_15438 tcp_mtu_to_mss 2-0 15438 NULL
108437 +hpsa_change_queue_depth_15449 hpsa_change_queue_depth 2 15449 NULL
108438 +memweight_15450 memweight 2 15450 NULL
108439 +zd_chip_is_zd1211b_15518 zd_chip_is_zd1211b 0 15518 NULL
108440 +ifx_spi_write_15531 ifx_spi_write 3 15531 NULL
108441 +p9_check_zc_errors_15534 p9_check_zc_errors 4 15534 NULL
108442 +xfrm_state_mtu_15548 xfrm_state_mtu 0-2 15548 NULL
108443 +persistent_status_15574 persistent_status 4 15574 NULL
108444 +bnx2fc_process_unsol_compl_15576 bnx2fc_process_unsol_compl 2 15576 NULL
108445 +vme_user_write_15587 vme_user_write 3 15587 NULL
108446 +compat_fillonedir_15620 compat_fillonedir 3 15620 NULL
108447 +proc_loginuid_read_15631 proc_loginuid_read 3 15631 NULL
108448 +tomoyo_scan_bprm_15642 tomoyo_scan_bprm 2-4 15642 NULL nohasharray
108449 +sk_memory_allocated_add_15642 sk_memory_allocated_add 2 15642 &tomoyo_scan_bprm_15642 nohasharray
108450 +pipeline_hs_tx_stat_fifo_int_read_15642 pipeline_hs_tx_stat_fifo_int_read 3 15642 &sk_memory_allocated_add_15642
108451 +joydev_handle_JSIOCSBTNMAP_15643 joydev_handle_JSIOCSBTNMAP 3 15643 NULL
108452 +fs_path_add_15648 fs_path_add 3 15648 NULL
108453 +xsd_read_15653 xsd_read 3 15653 NULL
108454 +unix_bind_15668 unix_bind 3 15668 NULL
108455 +dm_read_15674 dm_read 3 15674 NULL nohasharray
108456 +SyS_connect_15674 SyS_connect 3 15674 &dm_read_15674
108457 +tracing_snapshot_write_15719 tracing_snapshot_write 3 15719 NULL
108458 +HiSax_readstatus_15752 HiSax_readstatus 2 15752 NULL
108459 +bio_map_15794 bio_map 3-0 15794 NULL
108460 +smk_read_direct_15803 smk_read_direct 3 15803 NULL
108461 +nameseq_list_15817 nameseq_list 3-0 15817 NULL nohasharray
108462 +gnttab_expand_15817 gnttab_expand 1 15817 &nameseq_list_15817
108463 +afs_proc_rootcell_write_15822 afs_proc_rootcell_write 3 15822 NULL
108464 +brcmf_sdbrcm_died_dump_15841 brcmf_sdbrcm_died_dump 3 15841 NULL
108465 +table_size_15851 table_size 0-1-2 15851 NULL
108466 +write_file_tx99_15856 write_file_tx99 3 15856 NULL
108467 +media_entity_init_15870 media_entity_init 2-4 15870 NULL
108468 +__mptctl_ioctl_15875 __mptctl_ioctl 2 15875 NULL
108469 +nfs_map_group_to_gid_15892 nfs_map_group_to_gid 3 15892 NULL
108470 +native_read_msr_15905 native_read_msr 0 15905 NULL
108471 +parse_audio_stream_data_15937 parse_audio_stream_data 3 15937 NULL
108472 +power_read_15939 power_read 3 15939 NULL
108473 +lpfc_idiag_drbacc_read_15948 lpfc_idiag_drbacc_read 3 15948 NULL
108474 +snd_pcm_lib_read_transfer_15952 snd_pcm_lib_read_transfer 5-2-4 15952 NULL
108475 +viafb_vt1636_proc_write_16018 viafb_vt1636_proc_write 3 16018 NULL
108476 +dccp_recvmsg_16056 dccp_recvmsg 4 16056 NULL
108477 +read_file_spectral_period_16057 read_file_spectral_period 3 16057 NULL
108478 +si5351_msynth_params_address_16062 si5351_msynth_params_address 0-1 16062 NULL
108479 +isr_tx_exch_complete_read_16103 isr_tx_exch_complete_read 3 16103 NULL
108480 +isr_hw_pm_mode_changes_read_16110 isr_hw_pm_mode_changes_read 3 16110 NULL nohasharray
108481 +dma_tx_requested_read_16110 dma_tx_requested_read 3 16110 &isr_hw_pm_mode_changes_read_16110
108482 +snd_dma_pointer_16126 snd_dma_pointer 0-2 16126 NULL
108483 +compat_sys_select_16131 compat_sys_select 1 16131 NULL
108484 +fsm_init_16134 fsm_init 2 16134 NULL
108485 +ext4_xattr_block_get_16148 ext4_xattr_block_get 0 16148 NULL
108486 +optimal_reclaimed_pages_16172 optimal_reclaimed_pages 0 16172 NULL
108487 +mapping_level_16188 mapping_level 2-0 16188 NULL
108488 +i40e_allocate_virt_mem_d_16191 i40e_allocate_virt_mem_d 3 16191 NULL
108489 +ath10k_htt_rx_ring_size_16201 ath10k_htt_rx_ring_size 0 16201 NULL
108490 +cipso_v4_map_cat_rng_hton_16203 cipso_v4_map_cat_rng_hton 0 16203 NULL
108491 +SyS_pselect6_16210 SyS_pselect6 1 16210 NULL
108492 +create_table_16213 create_table 2 16213 NULL
108493 +ath9k_hw_ar9287_dump_eeprom_16224 ath9k_hw_ar9287_dump_eeprom 5-4 16224 NULL
108494 +atomic_read_file_16227 atomic_read_file 3 16227 NULL
108495 +BcmGetSectionValStartOffset_16235 BcmGetSectionValStartOffset 0 16235 NULL
108496 +lov_prep_brw_set_16246 lov_prep_brw_set 3 16246 NULL
108497 +btrfs_dev_extent_chunk_offset_16247 btrfs_dev_extent_chunk_offset 0 16247 NULL nohasharray
108498 +i40e_dbg_dump_read_16247 i40e_dbg_dump_read 3 16247 &btrfs_dev_extent_chunk_offset_16247
108499 +il_dbgfs_disable_ht40_write_16249 il_dbgfs_disable_ht40_write 3 16249 NULL
108500 +SyS_fgetxattr_16254 SyS_fgetxattr 4 16254 NULL
108501 +reiserfs_acl_count_16265 reiserfs_acl_count 0-1 16265 NULL
108502 +ocfs2_xattr_bucket_value_truncate_16279 ocfs2_xattr_bucket_value_truncate 4 16279 NULL
108503 +nand_bch_init_16280 nand_bch_init 3-2 16280 NULL nohasharray
108504 +drbd_setsockopt_16280 drbd_setsockopt 5 16280 &nand_bch_init_16280
108505 +account_16283 account 0-4-2 16283 NULL nohasharray
108506 +mirror_status_16283 mirror_status 5 16283 &account_16283
108507 +jumpshot_read_data_16287 jumpshot_read_data 4 16287 NULL
108508 +mo_xattr_get_16288 mo_xattr_get 0 16288 NULL
108509 +stk_allocate_buffers_16291 stk_allocate_buffers 2 16291 NULL
108510 +rbd_segment_offset_16293 rbd_segment_offset 0-2 16293 NULL
108511 +rsc_mgr_init_16299 rsc_mgr_init 3 16299 NULL
108512 +kvm_handle_hva_range_16312 kvm_handle_hva_range 3-2 16312 NULL
108513 +sysfs_create_groups_16360 sysfs_create_groups 0 16360 NULL
108514 +total_ps_buffered_read_16365 total_ps_buffered_read 3 16365 NULL
108515 +iscsi_tcp_conn_setup_16376 iscsi_tcp_conn_setup 2 16376 NULL
108516 +ieee80211_if_read_tsf_16420 ieee80211_if_read_tsf 3 16420 NULL
108517 +rxrpc_server_keyring_16431 rxrpc_server_keyring 3 16431 NULL
108518 +__bio_add_page_16435 __bio_add_page 0-4 16435 NULL
108519 +cmdline_store_16442 cmdline_store 4 16442 NULL
108520 +btrfs_truncate_inode_items_16452 btrfs_truncate_inode_items 4 16452 NULL
108521 +netlink_change_ngroups_16457 netlink_change_ngroups 2 16457 NULL
108522 +req_capsule_get_size_16467 req_capsule_get_size 0 16467 NULL
108523 +tracing_readme_read_16493 tracing_readme_read 3 16493 NULL
108524 +KEY_OFFSET_16504 KEY_OFFSET 0 16504 NULL
108525 +snd_interval_max_16529 snd_interval_max 0 16529 NULL
108526 +raid10_resize_16537 raid10_resize 2 16537 NULL
108527 +lpfc_debugfs_read_16566 lpfc_debugfs_read 3 16566 NULL
108528 +agp_allocate_memory_wrap_16576 agp_allocate_memory_wrap 1 16576 NULL
108529 +lustre_msg_hdr_size_v2_16589 lustre_msg_hdr_size_v2 0 16589 NULL
108530 +gmux_index_read32_16604 gmux_index_read32 0 16604 NULL
108531 +rtw_set_wpa_ie_16633 rtw_set_wpa_ie 3 16633 NULL
108532 +btrfs_get_token_32_16651 btrfs_get_token_32 0 16651 NULL
108533 +__wa_populate_dto_urb_16699 __wa_populate_dto_urb 3-4 16699 NULL
108534 +__proc_lnet_buffers_16717 __proc_lnet_buffers 5 16717 NULL
108535 +__copy_to_user_swizzled_16748 __copy_to_user_swizzled 3-4 16748 NULL
108536 +arcmsr_adjust_disk_queue_depth_16756 arcmsr_adjust_disk_queue_depth 2 16756 NULL
108537 +blk_rq_map_user_iov_16772 blk_rq_map_user_iov 5 16772 NULL
108538 +i2o_parm_issue_16790 i2o_parm_issue 0 16790 NULL
108539 +get_server_iovec_16804 get_server_iovec 2 16804 NULL
108540 +drm_malloc_ab_16831 drm_malloc_ab 1-2 16831 NULL
108541 +scsi_mode_sense_16835 scsi_mode_sense 5 16835 NULL
108542 +hfsplus_min_io_size_16859 hfsplus_min_io_size 0 16859 NULL
108543 +alloc_idx_lebs_16872 alloc_idx_lebs 2 16872 NULL
108544 +carl9170_debugfs_ampdu_state_read_16873 carl9170_debugfs_ampdu_state_read 3 16873 NULL
108545 +st_write_16874 st_write 3 16874 NULL
108546 +__kfifo_peek_n_16877 __kfifo_peek_n 0 16877 NULL
108547 +transport_init_session_tags_16878 transport_init_session_tags 1-2 16878 NULL
108548 +snd_gf1_mem_proc_dump_16926 snd_gf1_mem_proc_dump 5 16926 NULL nohasharray
108549 +psb_unlocked_ioctl_16926 psb_unlocked_ioctl 2 16926 &snd_gf1_mem_proc_dump_16926
108550 +_sp2d_alloc_16944 _sp2d_alloc 1-2-3 16944 NULL
108551 +squashfs_read_table_16945 squashfs_read_table 3 16945 NULL
108552 +keyctl_instantiate_key_iov_16969 keyctl_instantiate_key_iov 3 16969 NULL
108553 +ocfs2_read_quota_phys_block_16990 ocfs2_read_quota_phys_block 0 16990 NULL
108554 +ceph_read_dir_17005 ceph_read_dir 3 17005 NULL
108555 +copy_counters_to_user_17027 copy_counters_to_user 5 17027 NULL
108556 +jffs2_trusted_setxattr_17048 jffs2_trusted_setxattr 4 17048 NULL
108557 +__arch_hweight32_17060 __arch_hweight32 0 17060 NULL
108558 +sddr55_read_data_17072 sddr55_read_data 4 17072 NULL
108559 +dvb_dvr_read_17073 dvb_dvr_read 3 17073 NULL
108560 +simple_transaction_read_17076 simple_transaction_read 3 17076 NULL
108561 +carl9170_debugfs_mem_usage_read_17084 carl9170_debugfs_mem_usage_read 3 17084 NULL
108562 +entry_length_17093 entry_length 0 17093 NULL
108563 +ocfs2_get_refcount_cpos_end_17113 ocfs2_get_refcount_cpos_end 0 17113 NULL
108564 +write_mem_17114 write_mem 3 17114 NULL
108565 +pvr2_hdw_state_report_17121 pvr2_hdw_state_report 3 17121 NULL
108566 +nouveau_instobj_create__17144 nouveau_instobj_create_ 4 17144 NULL
108567 +jumpshot_write_data_17151 jumpshot_write_data 4 17151 NULL
108568 +sep_read_17161 sep_read 3 17161 NULL
108569 +befs_nls2utf_17163 befs_nls2utf 3 17163 NULL
108570 +tx_tx_start_templates_read_17164 tx_tx_start_templates_read 3 17164 NULL
108571 +UniStrnlen_17169 UniStrnlen 0 17169 NULL
108572 +access_remote_vm_17189 access_remote_vm 0 17189 NULL nohasharray
108573 +iwl_dbgfs_txfifo_flush_write_17189 iwl_dbgfs_txfifo_flush_write 3 17189 &access_remote_vm_17189 nohasharray
108574 +ocfs2_flock_handle_signal_17189 ocfs2_flock_handle_signal 0 17189 &iwl_dbgfs_txfifo_flush_write_17189
108575 +iscsit_find_cmd_from_itt_or_dump_17194 iscsit_find_cmd_from_itt_or_dump 3 17194 NULL nohasharray
108576 +driver_state_read_17194 driver_state_read 3 17194 &iscsit_find_cmd_from_itt_or_dump_17194
108577 +sync_request_17208 sync_request 2 17208 NULL
108578 +dn_recvmsg_17213 dn_recvmsg 4 17213 NULL
108579 +lprocfs_read_frac_helper_17261 lprocfs_read_frac_helper 0 17261 NULL
108580 +error_error_frame_cts_nul_flid_read_17262 error_error_frame_cts_nul_flid_read 3 17262 NULL
108581 +alloc_ep_17269 alloc_ep 1 17269 NULL
108582 +pg_read_17276 pg_read 3 17276 NULL
108583 +raw_recvmsg_17277 raw_recvmsg 4 17277 NULL
108584 +hmac_sha256_17278 hmac_sha256 2 17278 NULL
108585 +neigh_hash_grow_17283 neigh_hash_grow 2 17283 NULL
108586 +minstrel_stats_read_17290 minstrel_stats_read 3 17290 NULL
108587 +__ptlrpc_request_bufs_pack_17298 __ptlrpc_request_bufs_pack 0 17298 NULL
108588 +ieee80211_if_fmt_dot11MeshForwarding_17301 ieee80211_if_fmt_dot11MeshForwarding 3 17301 NULL
108589 +mb_cache_create_17307 mb_cache_create 2 17307 NULL
108590 +gnttab_map_frames_v2_17314 gnttab_map_frames_v2 2 17314 NULL
108591 +ieee80211_if_read_dot11MeshHWMPperrMinInterval_17346 ieee80211_if_read_dot11MeshHWMPperrMinInterval 3 17346 NULL
108592 +ath6kl_wmi_send_mgmt_cmd_17347 ath6kl_wmi_send_mgmt_cmd 7 17347 NULL
108593 +mdc_import_seq_write_17409 mdc_import_seq_write 3 17409 NULL
108594 +lpfc_debugfs_dif_err_write_17424 lpfc_debugfs_dif_err_write 3 17424 NULL
108595 +compat_sys_ppoll_17430 compat_sys_ppoll 2 17430 NULL
108596 +sta_connected_time_read_17435 sta_connected_time_read 3 17435 NULL
108597 +libcfs_ipif_enumerate_17445 libcfs_ipif_enumerate 0 17445 NULL
108598 +nla_get_u32_17455 nla_get_u32 0 17455 NULL
108599 +__ref_totlen_17461 __ref_totlen 0 17461 NULL
108600 +probe_kernel_write_17481 probe_kernel_write 3 17481 NULL
108601 +TSS_rawhmac_17486 TSS_rawhmac 3 17486 NULL
108602 +lbs_highrssi_write_17515 lbs_highrssi_write 3 17515 NULL
108603 +qp_free_res_17541 qp_free_res 5 17541 NULL
108604 +__copy_to_user_17551 __copy_to_user 3-0 17551 NULL
108605 +copy_from_user_17559 copy_from_user 0-3 17559 NULL
108606 +hash_netport4_expire_17573 hash_netport4_expire 4 17573 NULL
108607 +acpi_ut_create_package_object_17594 acpi_ut_create_package_object 1 17594 NULL
108608 +neigh_hash_alloc_17595 neigh_hash_alloc 1 17595 NULL
108609 +osst_execute_17607 osst_execute 7-6 17607 NULL
108610 +ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout_17618 ieee80211_if_read_dot11MeshHWMPactivePathToRootTimeout 3 17618 NULL
108611 +dma_map_page_17628 dma_map_page 0 17628 NULL
108612 +ocfs2_rotate_subtree_left_17634 ocfs2_rotate_subtree_left 5 17634 NULL
108613 +twl4030_set_gpio_direction_17645 twl4030_set_gpio_direction 1 17645 NULL
108614 +SYSC_migrate_pages_17657 SYSC_migrate_pages 2 17657 NULL
108615 +packet_setsockopt_17662 packet_setsockopt 5 17662 NULL
108616 +pwr_enable_ps_read_17686 pwr_enable_ps_read 3 17686 NULL
108617 +venus_rename_17707 venus_rename 4-5 17707 NULL nohasharray
108618 +__einj_error_trigger_17707 __einj_error_trigger 0 17707 &venus_rename_17707
108619 +exofs_read_lookup_dev_table_17733 exofs_read_lookup_dev_table 3 17733 NULL
108620 +sctpprobe_read_17741 sctpprobe_read 3 17741 NULL
108621 +dgap_do_fep_load_17765 dgap_do_fep_load 3 17765 NULL
108622 +brcmf_sdio_chip_verifynvram_17776 brcmf_sdio_chip_verifynvram 4 17776 NULL
108623 +shrink_slab_node_17794 shrink_slab_node 3 17794 NULL
108624 +gnet_stats_copy_app_17821 gnet_stats_copy_app 3 17821 NULL
108625 +cipso_v4_gentag_rbm_17836 cipso_v4_gentag_rbm 0 17836 NULL
108626 +dm_stats_message_17863 dm_stats_message 5 17863 NULL
108627 +sisusb_send_bulk_msg_17864 sisusb_send_bulk_msg 3 17864 NULL
108628 +alloc_sja1000dev_17868 alloc_sja1000dev 1 17868 NULL
108629 +virtio_cread32_17873 virtio_cread32 0 17873 NULL
108630 +ray_cs_essid_proc_write_17875 ray_cs_essid_proc_write 3 17875 NULL
108631 +orinoco_set_key_17878 orinoco_set_key 5-7 17878 NULL nohasharray
108632 +i40e_align_l2obj_base_17878 i40e_align_l2obj_base 0-1 17878 &orinoco_set_key_17878
108633 +init_per_cpu_17880 init_per_cpu 1 17880 NULL
108634 +ieee80211_if_fmt_dot11MeshMaxPeerLinks_17883 ieee80211_if_fmt_dot11MeshMaxPeerLinks 3 17883 NULL
108635 +ieee80211_if_fmt_dot11MeshHWMPRootMode_17890 ieee80211_if_fmt_dot11MeshHWMPRootMode 3 17890 NULL
108636 +xfs_buf_associate_memory_17915 xfs_buf_associate_memory 3 17915 NULL
108637 +scsi_bufflen_17933 scsi_bufflen 0 17933 NULL
108638 +__mutex_lock_check_stamp_17947 __mutex_lock_check_stamp 0 17947 NULL
108639 +beacon_interval_write_17952 beacon_interval_write 3 17952 NULL
108640 +calc_nr_buckets_17976 calc_nr_buckets 0 17976 NULL
108641 +ext4_ext_calc_credits_for_single_extent_17983 ext4_ext_calc_credits_for_single_extent 0-2 17983 NULL
108642 +smk_write_cipso_17989 smk_write_cipso 3 17989 NULL
108643 +gnttab_max_grant_frames_17993 gnttab_max_grant_frames 0 17993 NULL
108644 +pvr2_v4l2_read_18006 pvr2_v4l2_read 3 18006 NULL
108645 +alloc_rx_desc_ring_18016 alloc_rx_desc_ring 2 18016 NULL
108646 +cpufreq_add_dev_symlink_18028 cpufreq_add_dev_symlink 0 18028 NULL
108647 +o2hb_highest_node_18034 o2hb_highest_node 0 18034 NULL
108648 +cryptd_alloc_instance_18048 cryptd_alloc_instance 2-3 18048 NULL
108649 +ddebug_proc_write_18055 ddebug_proc_write 3 18055 NULL
108650 +lua_sysfs_read_18062 lua_sysfs_read 6 18062 NULL
108651 +fpregs_get_18066 fpregs_get 4 18066 NULL
108652 +kvm_read_guest_page_18074 kvm_read_guest_page 5 18074 NULL
108653 +SYSC_pselect6_18076 SYSC_pselect6 1 18076 NULL
108654 +SYSC_semtimedop_18091 SYSC_semtimedop 3 18091 NULL
108655 +mpi_alloc_18094 mpi_alloc 1 18094 NULL
108656 +hfs_direct_IO_18104 hfs_direct_IO 4 18104 NULL
108657 +dfs_file_read_18116 dfs_file_read 3 18116 NULL
108658 +svc_getnl_18120 svc_getnl 0 18120 NULL
108659 +paging32_gpte_to_gfn_lvl_18131 paging32_gpte_to_gfn_lvl 0-2-1 18131 NULL
108660 +selinux_inode_setsecurity_18148 selinux_inode_setsecurity 4 18148 NULL
108661 +pccard_store_cis_18176 pccard_store_cis 6 18176 NULL
108662 +orinoco_add_extscan_result_18207 orinoco_add_extscan_result 3 18207 NULL
108663 +gsm_control_message_18209 gsm_control_message 4 18209 NULL
108664 +do_ipv6_setsockopt_18215 do_ipv6_setsockopt 5 18215 NULL
108665 +gnttab_alloc_grant_references_18240 gnttab_alloc_grant_references 1 18240 NULL
108666 +alloc_trace_uprobe_18247 alloc_trace_uprobe 3 18247 NULL
108667 +rfcomm_sock_setsockopt_18254 rfcomm_sock_setsockopt 5 18254 NULL
108668 +qdisc_class_hash_alloc_18262 qdisc_class_hash_alloc 1 18262 NULL
108669 +gfs2_alloc_sort_buffer_18275 gfs2_alloc_sort_buffer 1 18275 NULL
108670 +alloc_ring_18278 alloc_ring 2-4 18278 NULL
108671 +bio_phys_segments_18281 bio_phys_segments 0 18281 NULL nohasharray
108672 +nouveau_subdev_create__18281 nouveau_subdev_create_ 7 18281 &bio_phys_segments_18281
108673 +ext4_readpages_18283 ext4_readpages 4 18283 NULL
108674 +mmc_send_bus_test_18285 mmc_send_bus_test 4 18285 NULL
108675 +um_idi_write_18293 um_idi_write 3 18293 NULL
108676 +nouveau_disp_create__18305 nouveau_disp_create_ 4-7 18305 NULL
108677 +vga_r_18310 vga_r 0 18310 NULL
108678 +class_add_profile_18315 class_add_profile 1-3-5 18315 NULL
108679 +csio_mem_read_18319 csio_mem_read 3 18319 NULL
108680 +alloc_and_copy_string_18321 alloc_and_copy_string 2 18321 NULL
108681 +ecryptfs_send_message_18322 ecryptfs_send_message 2 18322 NULL
108682 +bio_integrity_advance_18324 bio_integrity_advance 2 18324 NULL
108683 +lcd_proc_write_18351 lcd_proc_write 3 18351 NULL
108684 +pwr_power_save_off_read_18355 pwr_power_save_off_read 3 18355 NULL
108685 +SyS_process_vm_readv_18366 SyS_process_vm_readv 3-5 18366 NULL
108686 +ep_io_18367 ep_io 0 18367 NULL
108687 +qib_user_sdma_num_pages_18371 qib_user_sdma_num_pages 0 18371 NULL
108688 +ci_role_write_18388 ci_role_write 3 18388 NULL
108689 +hdlc_empty_fifo_18397 hdlc_empty_fifo 2 18397 NULL
108690 +adis16136_show_serial_18402 adis16136_show_serial 3 18402 NULL
108691 +crystalhd_user_data_18407 crystalhd_user_data 3 18407 NULL
108692 +iscsi_create_flashnode_sess_18433 iscsi_create_flashnode_sess 4 18433 NULL
108693 +snd_hda_get_connections_18437 snd_hda_get_connections 0 18437 NULL
108694 +flash_dev_cache_miss_18454 flash_dev_cache_miss 4 18454 NULL
108695 +fuse_perform_write_18457 fuse_perform_write 4 18457 NULL
108696 +regset_tls_set_18459 regset_tls_set 4 18459 NULL
108697 +pci_vpd_lrdt_size_18479 pci_vpd_lrdt_size 0 18479 NULL nohasharray
108698 +mite_bytes_in_transit_18479 mite_bytes_in_transit 0 18479 &pci_vpd_lrdt_size_18479
108699 +udpv6_setsockopt_18487 udpv6_setsockopt 5 18487 NULL
108700 +btrfs_fiemap_18501 btrfs_fiemap 3 18501 NULL
108701 +__copy_user_zeroing_intel_18510 __copy_user_zeroing_intel 0-3 18510 NULL
108702 +snd_vx_inb_18514 snd_vx_inb 0 18514 NULL
108703 +snd_gus_dram_poke_18525 snd_gus_dram_poke 4 18525 NULL
108704 +nouveau_fifo_channel_create__18530 nouveau_fifo_channel_create_ 9 18530 NULL
108705 +seq_copy_in_user_18543 seq_copy_in_user 3 18543 NULL
108706 +sas_change_queue_depth_18555 sas_change_queue_depth 2 18555 NULL
108707 +smk_write_rules_list_18565 smk_write_rules_list 3 18565 NULL
108708 +debug_output_18575 debug_output 3 18575 NULL
108709 +filemap_fdatawait_range_18600 filemap_fdatawait_range 0 18600 NULL nohasharray
108710 +slabinfo_write_18600 slabinfo_write 3 18600 &filemap_fdatawait_range_18600
108711 +iowarrior_write_18604 iowarrior_write 3 18604 NULL
108712 +nvc0_ram_create__18624 nvc0_ram_create_ 4 18624 NULL nohasharray
108713 +audio_get_endpoint_req_18624 audio_get_endpoint_req 0 18624 &nvc0_ram_create__18624
108714 +from_buffer_18625 from_buffer 3 18625 NULL
108715 +snd_pcm_oss_write3_18657 snd_pcm_oss_write3 0-3 18657 NULL
108716 +ieee80211_if_fmt_rssi_threshold_18664 ieee80211_if_fmt_rssi_threshold 3 18664 NULL
108717 +xfs_iext_insert_18667 xfs_iext_insert 3 18667 NULL
108718 +fnic_stats_debugfs_read_18688 fnic_stats_debugfs_read 3 18688 NULL
108719 +echo_client_prep_commit_18693 echo_client_prep_commit 8 18693 NULL
108720 +iwl_dbgfs_rx_handlers_read_18708 iwl_dbgfs_rx_handlers_read 3 18708 NULL
108721 +ceph_alloc_page_vector_18710 ceph_alloc_page_vector 1 18710 NULL
108722 +blk_rq_bytes_18715 blk_rq_bytes 0 18715 NULL
108723 +snd_als4k_gcr_read_addr_18741 snd_als4k_gcr_read_addr 0 18741 NULL
108724 +o2hb_debug_create_18744 o2hb_debug_create 4 18744 NULL
108725 +__erst_read_to_erange_from_nvram_18748 __erst_read_to_erange_from_nvram 0 18748 NULL
108726 +wep_packets_read_18751 wep_packets_read 3 18751 NULL
108727 +read_file_dump_nfcal_18766 read_file_dump_nfcal 3 18766 NULL
108728 +ffs_epfile_read_18775 ffs_epfile_read 3 18775 NULL
108729 +SyS_lsetxattr_18776 SyS_lsetxattr 4 18776 NULL
108730 +alloc_fcdev_18780 alloc_fcdev 1 18780 NULL
108731 +prealloc_18800 prealloc 0 18800 NULL
108732 +dm_stats_print_18815 dm_stats_print 7 18815 NULL
108733 +sys_modify_ldt_18824 sys_modify_ldt 3 18824 NULL
108734 +mtf_test_write_18844 mtf_test_write 3 18844 NULL
108735 +sctp_setsockopt_events_18862 sctp_setsockopt_events 3 18862 NULL
108736 +ieee80211_if_read_element_ttl_18869 ieee80211_if_read_element_ttl 3 18869 NULL
108737 +xlog_find_verify_log_record_18870 xlog_find_verify_log_record 2 18870 NULL
108738 +ceph_setxattr_18913 ceph_setxattr 4 18913 NULL
108739 +ieee80211_rx_mgmt_disassoc_18927 ieee80211_rx_mgmt_disassoc 3 18927 NULL
108740 +snapshot_write_next_18937 snapshot_write_next 0 18937 NULL
108741 +__nla_reserve_18974 __nla_reserve 3 18974 NULL
108742 +__blockdev_direct_IO_18977 __blockdev_direct_IO 0-6 18977 NULL
108743 +layout_in_gaps_19006 layout_in_gaps 2 19006 NULL
108744 +huge_page_size_19008 huge_page_size 0 19008 NULL
108745 +hash_netport6_expire_19013 hash_netport6_expire 4 19013 NULL
108746 +sysfs_create_dir_ns_19033 sysfs_create_dir_ns 0 19033 NULL
108747 +revalidate_19043 revalidate 2 19043 NULL
108748 +afs_vnode_store_data_19048 afs_vnode_store_data 2-3-4-5 19048 NULL
108749 +osc_pinger_recov_seq_write_19056 osc_pinger_recov_seq_write 3 19056 NULL
108750 +create_gpadl_header_19064 create_gpadl_header 2 19064 NULL
108751 +ieee80211_key_alloc_19065 ieee80211_key_alloc 3 19065 NULL
108752 +ceph_create_snap_context_19082 ceph_create_snap_context 1 19082 NULL
108753 +sta_last_seq_ctrl_read_19106 sta_last_seq_ctrl_read 3 19106 NULL
108754 +cifs_readv_from_socket_19109 cifs_readv_from_socket 3 19109 NULL
108755 +ATOMIC_SUB_RETURN_19115 ATOMIC_SUB_RETURN 2 19115 NULL
108756 +snd_als4k_iobase_readl_19136 snd_als4k_iobase_readl 0 19136 NULL
108757 +alloc_irdadev_19140 alloc_irdadev 1 19140 NULL
108758 +sleep_auth_read_19159 sleep_auth_read 3 19159 NULL
108759 +smk_write_access2_19170 smk_write_access2 3 19170 NULL
108760 +iwl_dbgfs_reply_tx_error_read_19205 iwl_dbgfs_reply_tx_error_read 3 19205 NULL
108761 +vmw_unlocked_ioctl_19212 vmw_unlocked_ioctl 2 19212 NULL
108762 +__copy_to_user_inatomic_19214 __copy_to_user_inatomic 3-0 19214 NULL
108763 +dev_counters_read_19216 dev_counters_read 3 19216 NULL
108764 +wbcir_tx_19219 wbcir_tx 3 19219 NULL
108765 +snd_mask_max_19224 snd_mask_max 0 19224 NULL
108766 +bio_alloc_mddev_19238 bio_alloc_mddev 2 19238 NULL
108767 +ucma_query_19260 ucma_query 4 19260 NULL
108768 +il_dbgfs_rxon_filter_flags_read_19281 il_dbgfs_rxon_filter_flags_read 3 19281 NULL
108769 +batadv_tt_save_orig_buffer_19288 batadv_tt_save_orig_buffer 4 19288 NULL nohasharray
108770 +cfg80211_rx_unprot_mlme_mgmt_19288 cfg80211_rx_unprot_mlme_mgmt 3 19288 &batadv_tt_save_orig_buffer_19288
108771 +qc_capture_19298 qc_capture 3 19298 NULL
108772 +ocfs2_prepare_inode_for_refcount_19303 ocfs2_prepare_inode_for_refcount 4-3 19303 NULL
108773 +event_tx_stuck_read_19305 event_tx_stuck_read 3 19305 NULL
108774 +debug_read_19322 debug_read 3 19322 NULL
108775 +lbs_host_sleep_write_19332 lbs_host_sleep_write 3 19332 NULL nohasharray
108776 +cfg80211_inform_bss_19332 cfg80211_inform_bss 8 19332 &lbs_host_sleep_write_19332
108777 +closure_sub_19359 closure_sub 2 19359 NULL
108778 +firmware_data_write_19360 firmware_data_write 6-5 19360 NULL
108779 +read_zero_19366 read_zero 3 19366 NULL
108780 +interpret_user_input_19393 interpret_user_input 2 19393 NULL
108781 +sync_fill_pt_info_19397 sync_fill_pt_info 0 19397 NULL
108782 +pep_recvmsg_19402 pep_recvmsg 4 19402 NULL
108783 +dvbdmx_write_19423 dvbdmx_write 3 19423 NULL
108784 +SyS_sched_getaffinity_19444 SyS_sched_getaffinity 2 19444 NULL
108785 +xfrm_alg_auth_len_19454 xfrm_alg_auth_len 0 19454 NULL
108786 +gnet_stats_copy_19458 gnet_stats_copy 4 19458 NULL
108787 +gp2ap020a00f_get_thresh_reg_19468 gp2ap020a00f_get_thresh_reg 0 19468 NULL
108788 +sky2_read16_19475 sky2_read16 0 19475 NULL
108789 +__read_status_pciv2_19492 __read_status_pciv2 0 19492 NULL
108790 +kstrtoll_from_user_19500 kstrtoll_from_user 2 19500 NULL
108791 +ext4_add_new_descs_19509 ext4_add_new_descs 3 19509 NULL
108792 +batadv_tvlv_container_register_19520 batadv_tvlv_container_register 5 19520 NULL
108793 +apei_exec_pre_map_gars_19529 apei_exec_pre_map_gars 0 19529 NULL nohasharray
108794 +cfc_write_array_to_buffer_19529 cfc_write_array_to_buffer 3 19529 &apei_exec_pre_map_gars_19529
108795 +nfc_llcp_build_tlv_19536 nfc_llcp_build_tlv 3 19536 NULL
108796 +howmany_64_19548 howmany_64 2 19548 NULL
108797 +gfn_to_index_19558 gfn_to_index 0-1-3-2 19558 NULL
108798 +ocfs2_control_message_19564 ocfs2_control_message 3 19564 NULL
108799 +ieee80211_if_read_tkip_mic_test_19565 ieee80211_if_read_tkip_mic_test 3 19565 NULL
108800 +nfsd_read_19568 nfsd_read 5 19568 NULL
108801 +cgroup_read_s64_19570 cgroup_read_s64 5 19570 NULL
108802 +bm_status_read_19583 bm_status_read 3 19583 NULL
108803 +load_xattr_datum_19594 load_xattr_datum 0 19594 NULL
108804 +__mei_cl_recv_19636 __mei_cl_recv 3 19636 NULL
108805 +LoadBitmap_19658 LoadBitmap 2 19658 NULL
108806 +iwl_dbgfs_pm_params_write_19660 iwl_dbgfs_pm_params_write 3 19660 NULL
108807 +read_reg_19723 read_reg 0 19723 NULL
108808 +wm8350_block_write_19727 wm8350_block_write 2-3 19727 NULL
108809 +memcpy_toiovecend_19736 memcpy_toiovecend 4-3 19736 NULL
108810 +snd_es1968_get_dma_ptr_19747 snd_es1968_get_dma_ptr 0 19747 NULL
108811 +p9_client_read_19750 p9_client_read 5-0 19750 NULL
108812 +pnpbios_proc_write_19758 pnpbios_proc_write 3 19758 NULL
108813 +ocfs2_readpages_19759 ocfs2_readpages 4 19759 NULL
108814 +jffs2_acl_from_medium_19762 jffs2_acl_from_medium 2 19762 NULL
108815 +readhscx_19769 readhscx 0 19769 NULL
108816 +__set_print_fmt_19776 __set_print_fmt 0 19776 NULL
108817 +iwl_dbgfs_disable_power_off_write_19823 iwl_dbgfs_disable_power_off_write 3 19823 NULL
108818 +irda_setsockopt_19824 irda_setsockopt 5 19824 NULL
108819 +vfs_getxattr_19832 vfs_getxattr 0 19832 NULL
108820 +security_context_to_sid_19839 security_context_to_sid 2 19839 NULL
108821 +crypt_alloc_buffer_19846 crypt_alloc_buffer 2 19846 NULL
108822 +cfg80211_mlme_register_mgmt_19852 cfg80211_mlme_register_mgmt 5 19852 NULL
108823 +__nla_put_19857 __nla_put 3 19857 NULL
108824 +mrp_request_join_19882 mrp_request_join 4 19882 NULL
108825 +aes_decrypt_interrupt_read_19910 aes_decrypt_interrupt_read 3 19910 NULL
108826 +ps_upsd_max_apturn_read_19918 ps_upsd_max_apturn_read 3 19918 NULL
108827 +mangle_name_19923 mangle_name 0 19923 NULL
108828 +cgroup_task_count_19930 cgroup_task_count 0 19930 NULL
108829 +guest_read_tsc_19931 guest_read_tsc 0 19931 NULL
108830 +iwl_dbgfs_rx_queue_read_19943 iwl_dbgfs_rx_queue_read 3 19943 NULL
108831 +cfg80211_rx_assoc_resp_19944 cfg80211_rx_assoc_resp 4 19944 NULL
108832 +get_jack_mode_name_19976 get_jack_mode_name 4 19976 NULL
108833 +attach_hdlc_protocol_19986 attach_hdlc_protocol 3 19986 NULL
108834 +rtw_set_wps_probe_resp_19989 rtw_set_wps_probe_resp 3 19989 NULL
108835 +lustre_pack_request_19992 lustre_pack_request 0 19992 NULL
108836 +diva_um_idi_read_20003 diva_um_idi_read 0 20003 NULL
108837 +lov_stripe_md_size_20009 lov_stripe_md_size 0-1 20009 NULL
108838 +SYSC_fgetxattr_20027 SYSC_fgetxattr 4 20027 NULL
108839 +split_scan_timeout_read_20029 split_scan_timeout_read 3 20029 NULL
108840 +alloc_ieee80211_20063 alloc_ieee80211 1 20063 NULL
108841 +iwl_mvm_power_mac_dbgfs_read_20067 iwl_mvm_power_mac_dbgfs_read 4 20067 NULL
108842 +target_message_20072 target_message 2 20072 NULL
108843 +rawv6_sendmsg_20080 rawv6_sendmsg 4 20080 NULL
108844 +fuse_conn_limit_read_20084 fuse_conn_limit_read 3 20084 NULL
108845 +aat2870_reg_write_file_20086 aat2870_reg_write_file 3 20086 NULL
108846 +team_options_register_20091 team_options_register 3 20091 NULL
108847 +qla2x00_adjust_sdev_qdepth_up_20097 qla2x00_adjust_sdev_qdepth_up 2 20097 NULL
108848 +root_nfs_copy_20111 root_nfs_copy 3 20111 NULL
108849 +hptiop_adjust_disk_queue_depth_20122 hptiop_adjust_disk_queue_depth 2 20122 NULL
108850 +tomoyo_commit_ok_20167 tomoyo_commit_ok 2 20167 NULL
108851 +read_flush_pipefs_20171 read_flush_pipefs 3 20171 NULL
108852 +wep_addr_key_count_read_20174 wep_addr_key_count_read 3 20174 NULL
108853 +create_trace_probe_20175 create_trace_probe 1 20175 NULL
108854 +crystalhd_map_dio_20181 crystalhd_map_dio 3 20181 NULL
108855 +pvr2_ctrl_value_to_sym_20229 pvr2_ctrl_value_to_sym 5 20229 NULL
108856 +rose_sendmsg_20249 rose_sendmsg 4 20249 NULL
108857 +tm6000_i2c_send_regs_20250 tm6000_i2c_send_regs 5 20250 NULL
108858 +r10_sync_page_io_20307 r10_sync_page_io 3 20307 NULL
108859 +dm_get_reserved_bio_based_ios_20315 dm_get_reserved_bio_based_ios 0 20315 NULL
108860 +tx_tx_burst_programmed_read_20320 tx_tx_burst_programmed_read 3 20320 NULL
108861 +vx_send_msg_nolock_20322 vx_send_msg_nolock 0 20322 NULL
108862 +snd_cs4281_BA1_read_20323 snd_cs4281_BA1_read 5 20323 NULL
108863 +gfs2_glock_nq_m_20347 gfs2_glock_nq_m 1 20347 NULL
108864 +handle_arr_calc_size_20355 handle_arr_calc_size 0-1 20355 NULL
108865 +smk_set_cipso_20379 smk_set_cipso 3 20379 NULL
108866 +snd_nm256_readl_20394 snd_nm256_readl 0 20394 NULL nohasharray
108867 +read_7220_creg32_20394 read_7220_creg32 0 20394 &snd_nm256_readl_20394
108868 +__kfifo_from_user_20399 __kfifo_from_user 3 20399 NULL nohasharray
108869 +SyS_get_mempolicy_20399 SyS_get_mempolicy 3 20399 &__kfifo_from_user_20399
108870 +nfs3_setxattr_20458 nfs3_setxattr 4 20458 NULL
108871 +compat_ipv6_setsockopt_20468 compat_ipv6_setsockopt 5 20468 NULL
108872 +read_buf_20469 read_buf 2 20469 NULL
108873 +bio_trim_20472 bio_trim 2 20472 NULL
108874 +btrfs_get_32_20476 btrfs_get_32 0 20476 NULL
108875 +xfs_iext_realloc_direct_20521 xfs_iext_realloc_direct 2 20521 NULL
108876 +drbd_bm_resize_20522 drbd_bm_resize 2 20522 NULL
108877 +amd_create_gatt_pages_20537 amd_create_gatt_pages 1 20537 NULL
108878 +scsi_report_opcode_20551 scsi_report_opcode 3 20551 NULL
108879 +venus_create_20555 venus_create 4 20555 NULL
108880 +btrfs_super_log_root_20565 btrfs_super_log_root 0 20565 NULL
108881 +crypto_ahash_reqsize_20569 crypto_ahash_reqsize 0 20569 NULL
108882 +ocfs2_cluster_lock_20588 ocfs2_cluster_lock 0 20588 NULL
108883 +kvm_test_age_hva_20593 kvm_test_age_hva 2 20593 NULL
108884 +sync_timeline_create_20601 sync_timeline_create 2 20601 NULL
108885 +lirc_write_20604 lirc_write 3 20604 NULL
108886 +qib_qsfp_write_20614 qib_qsfp_write 0-2-4 20614 NULL
108887 +snd_pcm_oss_prepare_20641 snd_pcm_oss_prepare 0 20641 NULL
108888 +get_extent_skip_holes_20642 get_extent_skip_holes 2 20642 NULL
108889 +kfifo_copy_to_user_20646 kfifo_copy_to_user 3-4 20646 NULL
108890 +cpulist_scnprintf_20648 cpulist_scnprintf 2-0 20648 NULL
108891 +oz_add_farewell_20652 oz_add_farewell 5 20652 NULL
108892 +oz_cdev_read_20659 oz_cdev_read 3 20659 NULL
108893 +snd_hdsp_playback_copy_20676 snd_hdsp_playback_copy 5 20676 NULL
108894 +dvb_dmxdev_buffer_read_20682 dvb_dmxdev_buffer_read 0-4 20682 NULL
108895 +cpumask_size_20683 cpumask_size 0 20683 NULL
108896 +btrfs_node_blockptr_20685 btrfs_node_blockptr 0 20685 NULL
108897 +read_file_tgt_int_stats_20697 read_file_tgt_int_stats 3 20697 NULL
108898 +__maestro_read_20700 __maestro_read 0 20700 NULL
108899 +cipso_v4_gentag_rng_20703 cipso_v4_gentag_rng 0 20703 NULL
108900 +pcpu_page_first_chunk_20712 pcpu_page_first_chunk 1 20712 NULL
108901 +ocfs2_read_xattr_bucket_20722 ocfs2_read_xattr_bucket 0 20722 NULL
108902 +security_context_to_sid_force_20724 security_context_to_sid_force 2 20724 NULL
108903 +fb_prepare_logo_20743 fb_prepare_logo 0 20743 NULL
108904 +vol_cdev_direct_write_20751 vol_cdev_direct_write 3 20751 NULL
108905 +ocfs2_align_bytes_to_clusters_20754 ocfs2_align_bytes_to_clusters 2 20754 NULL
108906 +brcmf_p2p_escan_20763 brcmf_p2p_escan 2 20763 NULL
108907 +fb_alloc_cmap_gfp_20792 fb_alloc_cmap_gfp 2 20792 NULL
108908 +iwl_dbgfs_rxon_flags_read_20795 iwl_dbgfs_rxon_flags_read 3 20795 NULL
108909 +strndup_user_20819 strndup_user 2 20819 NULL
108910 +tipc_msg_build_20825 tipc_msg_build 3 20825 NULL
108911 +wl1271_format_buffer_20834 wl1271_format_buffer 2 20834 NULL
108912 +uvc_alloc_entity_20836 uvc_alloc_entity 3-4 20836 NULL
108913 +p9_tag_alloc_20845 p9_tag_alloc 3 20845 NULL
108914 +nvme_trans_supported_vpd_pages_20847 nvme_trans_supported_vpd_pages 4 20847 NULL
108915 +get_name_20855 get_name 4 20855 NULL
108916 +iwl_dbgfs_pm_params_read_20866 iwl_dbgfs_pm_params_read 3 20866 NULL
108917 +snd_pcm_capture_avail_20867 snd_pcm_capture_avail 0 20867 NULL
108918 +srq_free_res_20868 srq_free_res 5 20868 NULL
108919 +cfs_cpt_table_create_20884 cfs_cpt_table_create 1 20884 NULL
108920 +rb_simple_write_20890 rb_simple_write 3 20890 NULL
108921 +sisusb_send_packet_20891 sisusb_send_packet 2 20891 NULL
108922 +key_icverrors_read_20895 key_icverrors_read 3 20895 NULL
108923 +vfio_msi_enable_20906 vfio_msi_enable 2 20906 NULL
108924 +lbs_rdbbp_write_20918 lbs_rdbbp_write 3 20918 NULL
108925 +htable_bits_20933 htable_bits 0 20933 NULL
108926 +altera_set_ir_post_20948 altera_set_ir_post 2 20948 NULL
108927 +rx_rx_phy_hdr_read_20950 rx_rx_phy_hdr_read 3 20950 NULL
108928 +rsxx_cram_read_20957 rsxx_cram_read 3 20957 NULL
108929 +nfs_map_name_to_uid_20962 nfs_map_name_to_uid 3 20962 NULL
108930 +snd_rme9652_playback_copy_20970 snd_rme9652_playback_copy 5 20970 NULL
108931 +alg_setsockopt_20985 alg_setsockopt 5 20985 NULL
108932 +qib_verbs_send_20999 qib_verbs_send 5-3 20999 NULL
108933 +btrfs_inode_ref_name_len_21024 btrfs_inode_ref_name_len 0 21024 NULL
108934 +rx_defrag_tkip_called_read_21031 rx_defrag_tkip_called_read 3 21031 NULL
108935 +srp_change_queue_depth_21038 srp_change_queue_depth 2 21038 NULL
108936 +lbs_threshold_read_21046 lbs_threshold_read 5 21046 NULL
108937 +reiserfs_direct_IO_21051 reiserfs_direct_IO 4 21051 NULL
108938 +proc_fault_inject_write_21058 proc_fault_inject_write 3 21058 NULL
108939 +qdisc_get_default_21072 qdisc_get_default 2 21072 NULL
108940 +event_calibration_read_21083 event_calibration_read 3 21083 NULL
108941 +bl_add_page_to_bio_21094 bl_add_page_to_bio 2 21094 NULL nohasharray
108942 +multipath_status_21094 multipath_status 5 21094 &bl_add_page_to_bio_21094
108943 +rate_control_pid_events_read_21099 rate_control_pid_events_read 3 21099 NULL
108944 +ocfs2_extend_meta_needed_21104 ocfs2_extend_meta_needed 0 21104 NULL
108945 +ath6kl_send_go_probe_resp_21113 ath6kl_send_go_probe_resp 3 21113 NULL
108946 +i2400m_rx_trace_21127 i2400m_rx_trace 3 21127 NULL
108947 +cx18_v4l2_read_21196 cx18_v4l2_read 3 21196 NULL
108948 +ipc_rcu_alloc_21208 ipc_rcu_alloc 1 21208 NULL
108949 +scsi_execute_req_flags_21215 scsi_execute_req_flags 5 21215 NULL
108950 +get_numpages_21227 get_numpages 0-1-2 21227 NULL
108951 +input_ff_create_21240 input_ff_create 2 21240 NULL
108952 +cfg80211_notify_new_peer_candidate_21242 cfg80211_notify_new_peer_candidate 4 21242 NULL
108953 +use_debug_keys_read_21251 use_debug_keys_read 3 21251 NULL
108954 +fru_length_21257 fru_length 0 21257 NULL
108955 +rtw_set_wps_beacon_21262 rtw_set_wps_beacon 3 21262 NULL
108956 +ocfs2_blocks_for_bytes_21268 ocfs2_blocks_for_bytes 0-2 21268 NULL
108957 +do_msg_fill_21307 do_msg_fill 3 21307 NULL
108958 +add_res_range_21310 add_res_range 4 21310 NULL
108959 +get_zeroed_page_21322 get_zeroed_page 0 21322 NULL
108960 +ftrace_profile_read_21327 ftrace_profile_read 3 21327 NULL
108961 +read_file_bool_bmps_21344 read_file_bool_bmps 3 21344 NULL
108962 +ocfs2_find_subtree_root_21351 ocfs2_find_subtree_root 0 21351 NULL
108963 +gfs2_ea_get_copy_21353 gfs2_ea_get_copy 0 21353 NULL
108964 +alloc_orinocodev_21371 alloc_orinocodev 1 21371 NULL
108965 +SYSC_rt_sigpending_21379 SYSC_rt_sigpending 2 21379 NULL
108966 +video_ioctl2_21380 video_ioctl2 2 21380 NULL
108967 +diva_get_driver_dbg_mask_21399 diva_get_driver_dbg_mask 0 21399 NULL
108968 +snd_m3_inw_21406 snd_m3_inw 0 21406 NULL
108969 +snapshot_read_next_21426 snapshot_read_next 0 21426 NULL
108970 +tcp_bound_to_half_wnd_21429 tcp_bound_to_half_wnd 0-2 21429 NULL
108971 +tracing_saved_cmdlines_read_21434 tracing_saved_cmdlines_read 3 21434 NULL
108972 +aggr_size_tx_agg_vs_rate_read_21438 aggr_size_tx_agg_vs_rate_read 3 21438 NULL
108973 +__ertm_hdr_size_21450 __ertm_hdr_size 0 21450 NULL
108974 +ReadISAR_21453 ReadISAR 0 21453 NULL
108975 +mei_nfc_send_21477 mei_nfc_send 3 21477 NULL
108976 +read_file_xmit_21487 read_file_xmit 3 21487 NULL
108977 +mmc_alloc_sg_21504 mmc_alloc_sg 1 21504 NULL
108978 +btrfs_file_aio_write_21520 btrfs_file_aio_write 4 21520 NULL
108979 +il_dbgfs_stations_read_21532 il_dbgfs_stations_read 3 21532 NULL
108980 +cipso_v4_map_cat_enum_hton_21540 cipso_v4_map_cat_enum_hton 0 21540 NULL
108981 +rxrpc_send_data_21553 rxrpc_send_data 5 21553 NULL
108982 +rx_rx_beacon_early_term_read_21559 rx_rx_beacon_early_term_read 3 21559 NULL
108983 +xfs_buf_read_uncached_21585 xfs_buf_read_uncached 3 21585 NULL
108984 +snd_es18xx_mixer_read_21586 snd_es18xx_mixer_read 0 21586 NULL
108985 +ocfs2_acl_from_xattr_21604 ocfs2_acl_from_xattr 2 21604 NULL
108986 +filemap_get_page_21606 filemap_get_page 2 21606 NULL
108987 +ocfs2_refcount_cow_hunk_21630 ocfs2_refcount_cow_hunk 3-4 21630 NULL
108988 +__jfs_getxattr_21631 __jfs_getxattr 0 21631 NULL
108989 +atalk_sendmsg_21677 atalk_sendmsg 4 21677 NULL
108990 +ocfs2_xattr_get_nolock_21678 ocfs2_xattr_get_nolock 0 21678 NULL
108991 +rtllib_alloc_txb_21687 rtllib_alloc_txb 1 21687 NULL
108992 +evdev_ioctl_handler_21705 evdev_ioctl_handler 2 21705 NULL
108993 +unix_skb_len_21722 unix_skb_len 0 21722 NULL
108994 +lprocfs_wr_import_21728 lprocfs_wr_import 3 21728 NULL
108995 +mthca_alloc_init_21754 mthca_alloc_init 2 21754 NULL
108996 +usbat_flash_read_data_21762 usbat_flash_read_data 4 21762 NULL
108997 +gen_pool_add_21776 gen_pool_add 3 21776 NULL
108998 +xfs_da_grow_inode_int_21785 xfs_da_grow_inode_int 3 21785 NULL
108999 +dvb_generic_ioctl_21810 dvb_generic_ioctl 2 21810 NULL
109000 +__ocfs2_cluster_lock_21812 __ocfs2_cluster_lock 0 21812 NULL
109001 +oom_adj_read_21847 oom_adj_read 3 21847 NULL
109002 +lpfc_idiag_extacc_avail_get_21865 lpfc_idiag_extacc_avail_get 0-3 21865 NULL
109003 +brcms_debugfs_hardware_read_21867 brcms_debugfs_hardware_read 3 21867 NULL
109004 +sisusbcon_bmove_21873 sisusbcon_bmove 6-5-7 21873 NULL
109005 +ldlm_lock_create_21888 ldlm_lock_create 7 21888 NULL
109006 +dbAllocCtl_21911 dbAllocCtl 0 21911 NULL
109007 +qsfp_1_read_21915 qsfp_1_read 3 21915 NULL
109008 +SYSC_prctl_21980 SYSC_prctl 4 21980 NULL
109009 +compat_rw_copy_check_uvector_22001 compat_rw_copy_check_uvector 0-3 22001 NULL nohasharray
109010 +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
109011 +regcache_sync_block_raw_flush_22021 regcache_sync_block_raw_flush 3-4 22021 NULL
109012 +btrfs_get_16_22023 btrfs_get_16 0 22023 NULL
109013 +_sp2d_min_pg_22032 _sp2d_min_pg 0 22032 NULL
109014 +zd_usb_read_fw_22049 zd_usb_read_fw 4 22049 NULL
109015 +ieee80211_if_fmt_dropped_frames_ttl_22054 ieee80211_if_fmt_dropped_frames_ttl 3 22054 NULL
109016 +btrfs_reloc_clone_csums_22077 btrfs_reloc_clone_csums 2-3 22077 NULL
109017 +mem_rw_22085 mem_rw 3 22085 NULL
109018 +kstrtos32_from_user_22087 kstrtos32_from_user 2 22087 NULL
109019 +rt2x00debug_read_crypto_stats_22109 rt2x00debug_read_crypto_stats 3 22109 NULL
109020 +snd_hda_codec_read_22130 snd_hda_codec_read 0 22130 NULL
109021 +SyS_sched_setaffinity_22148 SyS_sched_setaffinity 2 22148 NULL
109022 +do_tcp_sendpages_22155 do_tcp_sendpages 4 22155 NULL
109023 +__kfifo_alloc_22173 __kfifo_alloc 3 22173 NULL
109024 +rfcomm_sock_recvmsg_22227 rfcomm_sock_recvmsg 4 22227 NULL
109025 +mem_write_22232 mem_write 3 22232 NULL
109026 +p9_virtio_zc_request_22240 p9_virtio_zc_request 6-5 22240 NULL
109027 +prepare_to_wait_event_22247 prepare_to_wait_event 0 22247 NULL
109028 +compat_process_vm_rw_22254 compat_process_vm_rw 3-5 22254 NULL
109029 +ping_common_sendmsg_22261 ping_common_sendmsg 5 22261 NULL
109030 +add_res_tree_22263 add_res_tree 7 22263 NULL
109031 +__btrfs_direct_write_22273 __btrfs_direct_write 4 22273 NULL
109032 +queue_max_sectors_22280 queue_max_sectors 0 22280 NULL
109033 +__tun_chr_ioctl_22300 __tun_chr_ioctl 4 22300 NULL nohasharray
109034 +pci_vpd_srdt_size_22300 pci_vpd_srdt_size 0 22300 &__tun_chr_ioctl_22300
109035 +mesh_table_alloc_22305 mesh_table_alloc 1 22305 NULL
109036 +lov_setstripe_22307 lov_setstripe 2 22307 NULL
109037 +udpv6_sendmsg_22316 udpv6_sendmsg 4 22316 NULL
109038 +C_SYSC_msgrcv_22320 C_SYSC_msgrcv 3 22320 NULL
109039 +atomic_read_22342 atomic_read 0 22342 NULL
109040 +ll_lazystatfs_seq_write_22353 ll_lazystatfs_seq_write 3 22353 NULL
109041 +memcg_size_22360 memcg_size 0 22360 NULL
109042 +snd_pcm_alsa_frames_22363 snd_pcm_alsa_frames 2 22363 NULL
109043 +evdev_ioctl_22371 evdev_ioctl 2 22371 NULL
109044 +alloc_large_system_hash_22391 alloc_large_system_hash 2 22391 NULL
109045 +zoran_write_22404 zoran_write 3 22404 NULL
109046 +ATOMIC_ADD_RETURN_22413 ATOMIC_ADD_RETURN 2 22413 NULL
109047 +queue_reply_22416 queue_reply 3 22416 NULL
109048 +__set_enter_print_fmt_22431 __set_enter_print_fmt 0 22431 NULL
109049 +queue_max_segments_22441 queue_max_segments 0 22441 NULL
109050 +handle_received_packet_22457 handle_received_packet 3 22457 NULL
109051 +mem_cgroup_read_22461 mem_cgroup_read 5 22461 NULL
109052 +source_sink_start_ep_22472 source_sink_start_ep 0 22472 NULL
109053 +ecryptfs_write_22488 ecryptfs_write 4-3 22488 NULL
109054 +qib_user_sdma_alloc_header_22490 qib_user_sdma_alloc_header 2 22490 NULL
109055 +cache_write_procfs_22491 cache_write_procfs 3 22491 NULL
109056 +mutex_lock_interruptible_22505 mutex_lock_interruptible 0 22505 NULL
109057 +trim_no_bitmap_22524 trim_no_bitmap 4-3 22524 NULL
109058 +ocfs2_read_extent_block_22550 ocfs2_read_extent_block 0 22550 NULL
109059 +agp_alloc_page_array_22554 agp_alloc_page_array 1 22554 NULL
109060 +dbFindCtl_22587 dbFindCtl 0 22587 NULL
109061 +snapshot_read_22601 snapshot_read 3 22601 NULL
109062 +sctp_setsockopt_connectx_old_22631 sctp_setsockopt_connectx_old 3 22631 NULL
109063 +ide_core_cp_entry_22636 ide_core_cp_entry 3 22636 NULL
109064 +wl1271_rx_filter_get_fields_size_22638 wl1271_rx_filter_get_fields_size 0 22638 NULL
109065 +pwr_wake_on_timer_exp_read_22640 pwr_wake_on_timer_exp_read 3 22640 NULL
109066 +iwl_dbgfs_calib_disabled_read_22649 iwl_dbgfs_calib_disabled_read 3 22649 NULL
109067 +compat_SyS_msgrcv_22661 compat_SyS_msgrcv 3 22661 NULL
109068 +ext4_ext_direct_IO_22679 ext4_ext_direct_IO 4 22679 NULL
109069 +l2tp_ip_recvmsg_22681 l2tp_ip_recvmsg 4 22681 NULL
109070 +bch_dump_read_22685 bch_dump_read 3 22685 NULL
109071 +reg_umr_22686 reg_umr 5 22686 NULL
109072 +alloc_libipw_22708 alloc_libipw 1 22708 NULL
109073 +cx18_copy_buf_to_user_22735 cx18_copy_buf_to_user 4-0 22735 NULL
109074 +ceph_decode_32_22738 ceph_decode_32 0 22738 NULL nohasharray
109075 +__mei_cl_send_22738 __mei_cl_send 3 22738 &ceph_decode_32_22738
109076 +iio_debugfs_write_reg_22742 iio_debugfs_write_reg 3 22742 NULL
109077 +qlcnic_sriov_init_22762 qlcnic_sriov_init 2 22762 NULL
109078 +print_frame_22769 print_frame 0 22769 NULL
109079 +ftrace_arch_read_dyn_info_22773 ftrace_arch_read_dyn_info 0 22773 NULL
109080 +pla_ocp_write_22802 pla_ocp_write 4 22802 NULL
109081 +__generic_copy_to_user_intel_22806 __generic_copy_to_user_intel 0-3 22806 NULL
109082 +clone_bio_integrity_22842 clone_bio_integrity 4 22842 NULL
109083 +read_file_rcstat_22854 read_file_rcstat 3 22854 NULL
109084 +create_attr_set_22861 create_attr_set 1 22861 NULL
109085 +hash_ip6_expire_22867 hash_ip6_expire 4 22867 NULL
109086 +vmw_execbuf_process_22885 vmw_execbuf_process 5 22885 NULL
109087 +usblp_new_writeurb_22894 usblp_new_writeurb 2 22894 NULL
109088 +mdc800_device_read_22896 mdc800_device_read 3 22896 NULL
109089 +policy_emit_config_values_22900 policy_emit_config_values 3 22900 NULL
109090 +xstateregs_set_22932 xstateregs_set 4 22932 NULL
109091 +pcpu_mem_zalloc_22948 pcpu_mem_zalloc 1 22948 NULL
109092 +alloc_sglist_22960 alloc_sglist 2-3 22960 NULL
109093 +caif_seqpkt_sendmsg_22961 caif_seqpkt_sendmsg 4 22961 NULL
109094 +vme_get_size_22964 vme_get_size 0 22964 NULL
109095 +tx_frag_key_not_found_read_22971 tx_frag_key_not_found_read 3 22971 NULL
109096 +usb_get_langid_22983 usb_get_langid 0 22983 NULL
109097 +remote_settings_file_write_22987 remote_settings_file_write 3 22987 NULL
109098 +brcmf_sdio_chip_exit_download_23001 brcmf_sdio_chip_exit_download 4 23001 NULL
109099 +viafb_dvp0_proc_write_23023 viafb_dvp0_proc_write 3 23023 NULL
109100 +cifs_local_to_utf16_bytes_23025 cifs_local_to_utf16_bytes 0 23025 NULL
109101 +ocfs2_refcount_cow_xattr_23029 ocfs2_refcount_cow_xattr 0-6-7 23029 NULL
109102 +st_status_23032 st_status 5 23032 NULL
109103 +nv50_disp_chan_create__23056 nv50_disp_chan_create_ 5 23056 NULL
109104 +comedi_buf_write_n_available_23057 comedi_buf_write_n_available 0 23057 NULL
109105 +reiserfs_add_entry_23062 reiserfs_add_entry 4 23062 NULL nohasharray
109106 +unix_seqpacket_recvmsg_23062 unix_seqpacket_recvmsg 4 23062 &reiserfs_add_entry_23062
109107 +mei_cl_send_23068 mei_cl_send 3 23068 NULL
109108 +kvm_mmu_gva_to_gpa_write_23075 kvm_mmu_gva_to_gpa_write 0 23075 NULL
109109 +raw_sendmsg_23078 raw_sendmsg 4 23078 NULL
109110 +get_user_hdr_len_23079 get_user_hdr_len 0 23079 NULL
109111 +isr_tx_procs_read_23084 isr_tx_procs_read 3 23084 NULL
109112 +rt2x00debug_write_eeprom_23091 rt2x00debug_write_eeprom 3 23091 NULL
109113 +ntfs_ucstonls_23097 ntfs_ucstonls 3-5 23097 NULL
109114 +pipe_iov_copy_from_user_23102 pipe_iov_copy_from_user 3 23102 NULL
109115 +dgram_recvmsg_23104 dgram_recvmsg 4 23104 NULL
109116 +mwl8k_cmd_set_beacon_23110 mwl8k_cmd_set_beacon 4 23110 NULL
109117 +nl80211_send_rx_auth_23111 nl80211_send_rx_auth 4 23111 NULL
109118 +__clear_user_23118 __clear_user 0-2 23118 NULL
109119 +drm_mode_create_tv_properties_23122 drm_mode_create_tv_properties 2 23122 NULL
109120 +ata_scsi_change_queue_depth_23126 ata_scsi_change_queue_depth 2 23126 NULL
109121 +read_file_ani_23161 read_file_ani 3 23161 NULL
109122 +usblp_write_23178 usblp_write 3 23178 NULL
109123 +gss_pipe_downcall_23182 gss_pipe_downcall 3 23182 NULL
109124 +mpi_alloc_limb_space_23190 mpi_alloc_limb_space 1 23190 NULL
109125 +tty_buffer_request_room_23228 tty_buffer_request_room 2-0 23228 NULL
109126 +xlog_get_bp_23229 xlog_get_bp 2 23229 NULL nohasharray
109127 +__read_status_pci_23229 __read_status_pci 0 23229 &xlog_get_bp_23229
109128 +ft1000_read_dpram_mag_32_23232 ft1000_read_dpram_mag_32 0 23232 NULL
109129 +rxrpc_client_sendmsg_23236 rxrpc_client_sendmsg 5 23236 NULL
109130 +__gfn_to_rmap_23240 __gfn_to_rmap 2-1 23240 NULL
109131 +nv50_ram_create__23241 nv50_ram_create_ 4 23241 NULL
109132 +sctp_recvmsg_23265 sctp_recvmsg 4 23265 NULL
109133 +uwb_dev_addr_print_23282 uwb_dev_addr_print 2 23282 NULL
109134 +diva_get_trace_filter_23286 diva_get_trace_filter 0 23286 NULL
109135 +i2cdev_write_23310 i2cdev_write 3 23310 NULL
109136 +__aa_kvmalloc_23320 __aa_kvmalloc 1 23320 NULL
109137 +page_readlink_23346 page_readlink 3 23346 NULL
109138 +kmem_zalloc_large_23351 kmem_zalloc_large 1 23351 NULL
109139 +get_dst_timing_23358 get_dst_timing 0 23358 NULL
109140 +fd_setup_write_same_buf_23369 fd_setup_write_same_buf 3 23369 NULL
109141 +iscsi_change_queue_depth_23416 iscsi_change_queue_depth 2 23416 NULL
109142 +vga_mm_r_23419 vga_mm_r 0 23419 NULL
109143 +ocfs2_zero_tail_23447 ocfs2_zero_tail 3 23447 NULL
109144 +hidraw_send_report_23449 hidraw_send_report 3 23449 NULL
109145 +__ata_change_queue_depth_23484 __ata_change_queue_depth 3 23484 NULL
109146 +linear_conf_23485 linear_conf 2 23485 NULL
109147 +event_filter_read_23494 event_filter_read 3 23494 NULL
109148 +lustre_acl_xattr_merge2ext_23502 lustre_acl_xattr_merge2ext 2 23502 NULL
109149 +devm_iio_device_alloc_23511 devm_iio_device_alloc 2 23511 NULL
109150 +__proc_cpt_table_23516 __proc_cpt_table 5 23516 NULL
109151 +ima_show_measurements_count_23536 ima_show_measurements_count 3 23536 NULL
109152 +tcp_current_mss_23552 tcp_current_mss 0 23552 NULL
109153 +btrfs_super_bytenr_23561 btrfs_super_bytenr 0 23561 NULL
109154 +venus_symlink_23570 venus_symlink 6-4 23570 NULL
109155 +iwl_dbgfs_interrupt_read_23574 iwl_dbgfs_interrupt_read 3 23574 NULL
109156 +xfpregs_get_23586 xfpregs_get 4 23586 NULL
109157 +snd_interval_min_23590 snd_interval_min 0 23590 NULL
109158 +islpci_mgt_transaction_23610 islpci_mgt_transaction 5 23610 NULL
109159 +ocfs2_journal_access_23616 ocfs2_journal_access 0 23616 NULL
109160 +__i2400mu_send_barker_23652 __i2400mu_send_barker 3 23652 NULL
109161 +sInW_23663 sInW 0 23663 NULL
109162 +SyS_connect_23669 SyS_connect 3 23669 NULL
109163 +cx18_read_23699 cx18_read 3 23699 NULL
109164 +at_get_23708 at_get 0 23708 NULL
109165 +rx_rx_dropped_frame_read_23748 rx_rx_dropped_frame_read 3 23748 NULL
109166 +__kfifo_max_r_23768 __kfifo_max_r 0-2-1 23768 NULL
109167 +__build_packet_message_23778 __build_packet_message 4-10 23778 NULL
109168 +security_inode_getxattr_23781 security_inode_getxattr 0 23781 NULL
109169 +cfg80211_inform_bss_width_frame_23782 cfg80211_inform_bss_width_frame 5 23782 NULL
109170 +mpt_free_res_23793 mpt_free_res 5 23793 NULL
109171 +map_write_23795 map_write 3 23795 NULL
109172 +rx_path_reset_read_23801 rx_path_reset_read 3 23801 NULL
109173 +ocfs2_replace_cow_23803 ocfs2_replace_cow 0 23803 NULL
109174 +__earlyonly_bootmem_alloc_23824 __earlyonly_bootmem_alloc 2 23824 NULL
109175 +lustre_msg_buflen_23827 lustre_msg_buflen 0 23827 NULL
109176 +ceph_copy_page_vector_to_user_23829 ceph_copy_page_vector_to_user 3-4 23829 NULL
109177 +pgdat_end_pfn_23842 pgdat_end_pfn 0 23842 NULL
109178 +iwl_dbgfs_nvm_read_23845 iwl_dbgfs_nvm_read 3 23845 NULL
109179 +p54_init_common_23850 p54_init_common 1 23850 NULL
109180 +bin_to_hex_dup_23853 bin_to_hex_dup 2 23853 NULL
109181 +ocfs2_xattr_get_clusters_23857 ocfs2_xattr_get_clusters 0 23857 NULL
109182 +ieee80211_if_read_dot11MeshMaxPeerLinks_23878 ieee80211_if_read_dot11MeshMaxPeerLinks 3 23878 NULL
109183 +nouveau_clock_create__23881 nouveau_clock_create_ 5 23881 NULL
109184 +tipc_snprintf_23893 tipc_snprintf 2-0 23893 NULL
109185 +usbg_prepare_w_request_23895 usbg_prepare_w_request 0 23895 NULL
109186 +add_new_gdb_meta_bg_23911 add_new_gdb_meta_bg 3 23911 NULL nohasharray
109187 +ieee80211_if_read_hw_queues_23911 ieee80211_if_read_hw_queues 3 23911 &add_new_gdb_meta_bg_23911
109188 +f2fs_getxattr_23917 f2fs_getxattr 0 23917 NULL
109189 +mpihelp_mul_karatsuba_case_23918 mpihelp_mul_karatsuba_case 5-3 23918 NULL nohasharray
109190 +ipath_reg_phys_mr_23918 ipath_reg_phys_mr 3 23918 &mpihelp_mul_karatsuba_case_23918
109191 +kvm_read_guest_23928 kvm_read_guest 4-2 23928 NULL
109192 +uvc_endpoint_max_bpi_23944 uvc_endpoint_max_bpi 0 23944 NULL
109193 +cifs_setxattr_23957 cifs_setxattr 4 23957 NULL
109194 +size_roundup_power2_23958 size_roundup_power2 0-1 23958 NULL
109195 +sddr55_write_data_23983 sddr55_write_data 4 23983 NULL
109196 +zd_usb_iowrite16v_async_23984 zd_usb_iowrite16v_async 3 23984 NULL
109197 +cxgb_alloc_mem_24007 cxgb_alloc_mem 1 24007 NULL
109198 +give_pages_24021 give_pages 3 24021 NULL
109199 +adis16400_show_serial_number_24037 adis16400_show_serial_number 3 24037 NULL
109200 +hmac_setkey_24043 hmac_setkey 3 24043 NULL
109201 +afs_cell_alloc_24052 afs_cell_alloc 2 24052 NULL
109202 +blkcipher_copy_iv_24075 blkcipher_copy_iv 3 24075 NULL
109203 +vb2_fop_read_24080 vb2_fop_read 3 24080 NULL
109204 +pipeline_post_proc_swi_read_24108 pipeline_post_proc_swi_read 3 24108 NULL
109205 +request_key_auth_read_24109 request_key_auth_read 3 24109 NULL
109206 +lov_brw_24122 lov_brw 4 24122 NULL
109207 +mpu401_read_24126 mpu401_read 3-0 24126 NULL
109208 +_picolcd_flash_write_24134 _picolcd_flash_write 4 24134 NULL
109209 +irnet_ctrl_write_24139 irnet_ctrl_write 3 24139 NULL
109210 +SyS_sethostname_24150 SyS_sethostname 2 24150 NULL
109211 +trim_bitmaps_24158 trim_bitmaps 3 24158 NULL
109212 +adu_read_24177 adu_read 3 24177 NULL
109213 +safe_prepare_write_buffer_24187 safe_prepare_write_buffer 3 24187 NULL
109214 +irq_remapping_setup_msi_irqs_24194 irq_remapping_setup_msi_irqs 2 24194 NULL
109215 +ieee80211_if_read_dot11MeshHWMPpreqMinInterval_24208 ieee80211_if_read_dot11MeshHWMPpreqMinInterval 3 24208 NULL
109216 +tcpprobe_sprint_24222 tcpprobe_sprint 0-2 24222 NULL
109217 +pcpu_embed_first_chunk_24224 pcpu_embed_first_chunk 3-2-1 24224 NULL nohasharray
109218 +mei_amthif_read_24224 mei_amthif_read 4 24224 &pcpu_embed_first_chunk_24224
109219 +pci_num_vf_24235 pci_num_vf 0 24235 NULL
109220 +sel_read_bool_24236 sel_read_bool 3 24236 NULL
109221 +em28xx_alloc_urbs_24260 em28xx_alloc_urbs 4-6 24260 NULL
109222 +calculate_sizes_24273 calculate_sizes 2 24273 NULL
109223 +thin_status_24278 thin_status 5 24278 NULL
109224 +msg_size_24288 msg_size 0 24288 NULL
109225 +gserial_connect_24302 gserial_connect 0 24302 NULL
109226 +btmrvl_pscmd_read_24308 btmrvl_pscmd_read 3 24308 NULL
109227 +ath6kl_add_bss_if_needed_24317 ath6kl_add_bss_if_needed 6 24317 NULL
109228 +si476x_radio_read_acf_blob_24336 si476x_radio_read_acf_blob 3 24336 NULL
109229 +C_SYSC_pwritev_24345 C_SYSC_pwritev 3 24345 NULL
109230 +kzalloc_node_24352 kzalloc_node 1 24352 NULL
109231 +qla2x00_handle_queue_full_24365 qla2x00_handle_queue_full 2 24365 NULL
109232 +cfi_read_pri_24366 cfi_read_pri 3 24366 NULL
109233 +btrfs_item_size_nr_24367 btrfs_item_size_nr 0 24367 NULL
109234 +igetword_24373 igetword 0 24373 NULL
109235 +max_io_len_24384 max_io_len 0-1 24384 NULL
109236 +mpt_alloc_res_24387 mpt_alloc_res 5 24387 NULL
109237 +osc_cur_grant_bytes_seq_write_24396 osc_cur_grant_bytes_seq_write 3 24396 NULL
109238 +getxattr_24398 getxattr 4 24398 NULL nohasharray
109239 +pvr2_v4l2_ioctl_24398 pvr2_v4l2_ioctl 2 24398 &getxattr_24398
109240 +blk_update_bidi_request_24415 blk_update_bidi_request 3-4 24415 NULL
109241 +nvme_trans_log_supp_pages_24418 nvme_trans_log_supp_pages 3 24418 NULL
109242 +b43_debugfs_read_24425 b43_debugfs_read 3 24425 NULL
109243 +xenbus_file_read_24427 xenbus_file_read 3 24427 NULL
109244 +ieee80211_rx_mgmt_beacon_24430 ieee80211_rx_mgmt_beacon 3 24430 NULL
109245 +copy_and_ioctl_24434 copy_and_ioctl 4 24434 NULL
109246 +ixgbe_alloc_q_vector_24439 ixgbe_alloc_q_vector 4-6 24439 NULL
109247 +smk_user_access_24440 smk_user_access 3 24440 NULL nohasharray
109248 +rtw_set_wps_assoc_resp_24440 rtw_set_wps_assoc_resp 3 24440 &smk_user_access_24440
109249 +evdev_do_ioctl_24459 evdev_do_ioctl 2 24459 NULL
109250 +lbs_highsnr_write_24460 lbs_highsnr_write 3 24460 NULL
109251 +skb_copy_and_csum_datagram_iovec_24466 skb_copy_and_csum_datagram_iovec 2 24466 NULL
109252 +dut_mode_read_24489 dut_mode_read 3 24489 NULL
109253 +read_file_spec_scan_ctl_24491 read_file_spec_scan_ctl 3 24491 NULL
109254 +pd_video_read_24510 pd_video_read 3 24510 NULL
109255 +request_key_with_auxdata_24515 request_key_with_auxdata 4 24515 NULL
109256 +xfs_buf_get_map_24522 xfs_buf_get_map 3 24522 NULL
109257 +do_mpage_readpage_24536 do_mpage_readpage 3 24536 NULL
109258 +write_cache_pages_24562 write_cache_pages 0 24562 NULL
109259 +SyS_pselect6_24582 SyS_pselect6 1 24582 NULL
109260 +udf_compute_nr_groups_24594 udf_compute_nr_groups 0 24594 NULL
109261 +sensor_hub_get_physical_device_count_24605 sensor_hub_get_physical_device_count 0 24605 NULL nohasharray
109262 +lov_alloc_memmd_24605 lov_alloc_memmd 2 24605 &sensor_hub_get_physical_device_count_24605
109263 +SyS_poll_24620 SyS_poll 2 24620 NULL
109264 +context_alloc_24645 context_alloc 3 24645 NULL
109265 +blk_rq_err_bytes_24650 blk_rq_err_bytes 0 24650 NULL
109266 +datafab_write_data_24696 datafab_write_data 4 24696 NULL
109267 +intelfbhw_get_p1p2_24703 intelfbhw_get_p1p2 2 24703 NULL
109268 +simple_attr_read_24738 simple_attr_read 3 24738 NULL
109269 +qla2x00_change_queue_depth_24742 qla2x00_change_queue_depth 2 24742 NULL
109270 +get_dma_residue_24749 get_dma_residue 0 24749 NULL
109271 +ocfs2_cow_file_pos_24751 ocfs2_cow_file_pos 3 24751 NULL
109272 +kgdb_hex2mem_24755 kgdb_hex2mem 3 24755 NULL
109273 +ocfs2_read_blocks_24777 ocfs2_read_blocks 0 24777 NULL
109274 +datablob_hmac_verify_24786 datablob_hmac_verify 4 24786 NULL
109275 +cache_read_24790 cache_read 3 24790 NULL
109276 +user_regset_copyout_24796 user_regset_copyout 7 24796 NULL
109277 +kvm_read_guest_virt_helper_24804 kvm_read_guest_virt_helper 3-1 24804 NULL
109278 +ath6kl_fwlog_mask_write_24810 ath6kl_fwlog_mask_write 3 24810 NULL
109279 +net2272_read_24825 net2272_read 0 24825 NULL
109280 +snd_als4k_gcr_read_24840 snd_als4k_gcr_read 0 24840 NULL
109281 +snd_pcm_lib_buffer_bytes_24865 snd_pcm_lib_buffer_bytes 0 24865 NULL
109282 +pnp_alloc_24869 pnp_alloc 1 24869 NULL nohasharray
109283 +l2cap_create_basic_pdu_24869 l2cap_create_basic_pdu 3 24869 &pnp_alloc_24869
109284 +queues_read_24877 queues_read 3 24877 NULL
109285 +__vxge_hw_vp_initialize_24885 __vxge_hw_vp_initialize 2 24885 NULL
109286 +codec_list_read_file_24910 codec_list_read_file 3 24910 NULL
109287 +v4l2_ctrl_new_24927 v4l2_ctrl_new 7 24927 NULL nohasharray
109288 +__btrfs_free_extent_24927 __btrfs_free_extent 7 24927 &v4l2_ctrl_new_24927
109289 +ocfs2_fiemap_24949 ocfs2_fiemap 4-3 24949 NULL
109290 +packet_sendmsg_24954 packet_sendmsg 4 24954 NULL
109291 +ll_layout_fetch_24961 ll_layout_fetch 0 24961 NULL
109292 +twl_i2c_write_u8_24976 twl_i2c_write_u8 3 24976 NULL
109293 +llc_ui_sendmsg_24987 llc_ui_sendmsg 4 24987 NULL
109294 +key_conf_hw_key_idx_read_25003 key_conf_hw_key_idx_read 3 25003 NULL
109295 +il_dbgfs_channels_read_25005 il_dbgfs_channels_read 3 25005 NULL
109296 +ni_660x_num_counters_25031 ni_660x_num_counters 0 25031 NULL
109297 +nfs_dns_resolve_name_25036 nfs_dns_resolve_name 3 25036 NULL
109298 +load_unaligned_zeropad_25050 load_unaligned_zeropad 0 25050 NULL
109299 +btrfs_stack_key_blockptr_25058 btrfs_stack_key_blockptr 0 25058 NULL
109300 +gs_buf_alloc_25067 gs_buf_alloc 2 25067 NULL
109301 +ll_track_pid_seq_write_25068 ll_track_pid_seq_write 3 25068 NULL
109302 +SYSC_listxattr_25072 SYSC_listxattr 3 25072 NULL
109303 +iwl_dbgfs_tx_flush_write_25091 iwl_dbgfs_tx_flush_write 3 25091 NULL
109304 +ima_appraise_measurement_25093 ima_appraise_measurement 6 25093 NULL
109305 +blkg_path_25099 blkg_path 3 25099 NULL
109306 +snd_rawmidi_kernel_write_25106 snd_rawmidi_kernel_write 3 25106 NULL
109307 +ipath_init_qp_table_25167 ipath_init_qp_table 2 25167 NULL
109308 +kvm_mmu_notifier_change_pte_25169 kvm_mmu_notifier_change_pte 3 25169 NULL
109309 +sctp_getsockopt_local_addrs_25178 sctp_getsockopt_local_addrs 2 25178 NULL
109310 +mon_stat_read_25238 mon_stat_read 3 25238 NULL
109311 +stripe_status_25259 stripe_status 5 25259 NULL
109312 +snd_pcm_start_25273 snd_pcm_start 0 25273 NULL
109313 +crypto_alloc_instance2_25277 crypto_alloc_instance2 3 25277 NULL
109314 +vfs_writev_25278 vfs_writev 3 25278 NULL
109315 +l2tp_session_create_25286 l2tp_session_create 1 25286 NULL
109316 +ath9k_debugfs_read_buf_25316 ath9k_debugfs_read_buf 3 25316 NULL
109317 +rng_buffer_size_25348 rng_buffer_size 0 25348 NULL
109318 +SYSC_kexec_load_25361 SYSC_kexec_load 2 25361 NULL
109319 +unix_mkname_25368 unix_mkname 0-2 25368 NULL
109320 +sel_read_mls_25369 sel_read_mls 3 25369 NULL
109321 +vsp1_entity_init_25407 vsp1_entity_init 3 25407 NULL
109322 +dai_list_read_file_25421 dai_list_read_file 3 25421 NULL
109323 +generic_file_buffered_write_25464 generic_file_buffered_write 4 25464 NULL
109324 +ipath_decode_err_25468 ipath_decode_err 3 25468 NULL
109325 +crypto_hash_digestsize_25469 crypto_hash_digestsize 0 25469 NULL
109326 +ivtv_buf_copy_from_user_25502 ivtv_buf_copy_from_user 4-0 25502 NULL
109327 +snd_pcm_plugin_build_25505 snd_pcm_plugin_build 5 25505 NULL
109328 +sb_permission_25523 sb_permission 0 25523 NULL
109329 +ext3_get_inode_loc_25542 ext3_get_inode_loc 0 25542 NULL
109330 +ieee80211_if_read_path_refresh_time_25545 ieee80211_if_read_path_refresh_time 3 25545 NULL
109331 +wimax_addr_scnprint_25548 wimax_addr_scnprint 2 25548 NULL
109332 +ht_print_chan_25556 ht_print_chan 3-4-0 25556 NULL
109333 +skb_tailroom_25567 skb_tailroom 0 25567 NULL
109334 +ping_recvmsg_25597 ping_recvmsg 4 25597 NULL
109335 +copy_user_generic_25611 copy_user_generic 0 25611 NULL
109336 +proc_coredump_filter_write_25625 proc_coredump_filter_write 3 25625 NULL
109337 +befs_utf2nls_25628 befs_utf2nls 3 25628 NULL nohasharray
109338 +__get_user_pages_25628 __get_user_pages 0 25628 &befs_utf2nls_25628
109339 +__direct_map_25647 __direct_map 6-5 25647 NULL
109340 +aircable_prepare_write_buffer_25669 aircable_prepare_write_buffer 3 25669 NULL
109341 +lpfc_idiag_cmd_get_25672 lpfc_idiag_cmd_get 2 25672 NULL
109342 +sta_inactive_ms_read_25690 sta_inactive_ms_read 3 25690 NULL
109343 +rx_filter_mc_filter_read_25712 rx_filter_mc_filter_read 3 25712 NULL
109344 +ibmasm_new_command_25714 ibmasm_new_command 2 25714 NULL
109345 +__alloc_bootmem_low_node_25726 __alloc_bootmem_low_node 2 25726 NULL nohasharray
109346 +sel_write_context_25726 sel_write_context 3 25726 &__alloc_bootmem_low_node_25726
109347 +cxgbi_device_portmap_create_25747 cxgbi_device_portmap_create 3 25747 NULL
109348 +event_rx_pool_read_25792 event_rx_pool_read 3 25792 NULL
109349 +sg_read_25799 sg_read 3 25799 NULL
109350 +system_enable_read_25815 system_enable_read 3 25815 NULL
109351 +realloc_buffer_25816 realloc_buffer 2 25816 NULL
109352 +pwr_missing_bcns_read_25824 pwr_missing_bcns_read 3 25824 NULL
109353 +parport_read_25855 parport_read 0 25855 NULL
109354 +xfs_dir2_sf_hdr_size_25858 xfs_dir2_sf_hdr_size 0 25858 NULL
109355 +key_attr_size_25865 key_attr_size 0 25865 NULL
109356 +ath6kl_regread_read_25884 ath6kl_regread_read 3 25884 NULL
109357 +run_delalloc_nocow_25896 run_delalloc_nocow 3-4 25896 NULL
109358 +sisusbcon_scroll_area_25899 sisusbcon_scroll_area 4-3 25899 NULL
109359 +lpfc_change_queue_depth_25905 lpfc_change_queue_depth 2 25905 NULL
109360 +nvme_trans_mode_page_create_25908 nvme_trans_mode_page_create 7-4 25908 NULL
109361 +do_jffs2_setxattr_25910 do_jffs2_setxattr 5 25910 NULL
109362 +rcname_read_25919 rcname_read 3 25919 NULL
109363 +snd_es1938_capture_copy_25930 snd_es1938_capture_copy 5 25930 NULL
109364 +key_flags_read_25931 key_flags_read 3 25931 NULL
109365 +copy_play_buf_25932 copy_play_buf 3 25932 NULL
109366 +flush_25957 flush 2 25957 NULL
109367 +udp_setsockopt_25985 udp_setsockopt 5 25985 NULL
109368 +lustre_msg_buflen_v2_25997 lustre_msg_buflen_v2 0 25997 NULL
109369 +SyS_process_vm_readv_26019 SyS_process_vm_readv 3-5 26019 NULL
109370 +xfs_xattr_acl_set_26028 xfs_xattr_acl_set 4 26028 NULL
109371 +mptscsih_change_queue_depth_26036 mptscsih_change_queue_depth 2 26036 NULL
109372 +selinux_inode_post_setxattr_26037 selinux_inode_post_setxattr 4 26037 NULL
109373 +tun_do_read_26047 tun_do_read 5 26047 NULL
109374 +keyctl_update_key_26061 keyctl_update_key 3 26061 NULL
109375 +rx_rx_wa_density_dropped_frame_read_26095 rx_rx_wa_density_dropped_frame_read 3 26095 NULL
109376 +read_sb_page_26119 read_sb_page 5 26119 NULL
109377 +ath9k_hw_name_26146 ath9k_hw_name 3 26146 NULL
109378 +copy_oldmem_page_26164 copy_oldmem_page 3 26164 NULL
109379 +gfs2_xattr_acl_get_26166 gfs2_xattr_acl_get 0 26166 NULL nohasharray
109380 +ath6kl_roam_table_read_26166 ath6kl_roam_table_read 3 26166 &gfs2_xattr_acl_get_26166
109381 +disk_devt_26180 disk_devt 0 26180 NULL
109382 +cgroup_setxattr_26188 cgroup_setxattr 4 26188 NULL
109383 +ieee80211_if_fmt_dot11MeshTTL_26198 ieee80211_if_fmt_dot11MeshTTL 3 26198 NULL
109384 +xfs_idata_realloc_26199 xfs_idata_realloc 2 26199 NULL
109385 +mce_write_26201 mce_write 3 26201 NULL
109386 +mwifiex_regrdwr_write_26225 mwifiex_regrdwr_write 3 26225 NULL
109387 +_scsih_change_queue_depth_26230 _scsih_change_queue_depth 2 26230 NULL
109388 +rxrpc_recvmsg_26233 rxrpc_recvmsg 4 26233 NULL
109389 +bio_split_26235 bio_split 2 26235 NULL
109390 +crypto_ctxsize_26278 crypto_ctxsize 0 26278 NULL
109391 +apei_resources_request_26279 apei_resources_request 0 26279 NULL
109392 +wacom_set_device_mode_26280 wacom_set_device_mode 3 26280 NULL
109393 +snd_pcm_plug_client_channels_buf_26309 snd_pcm_plug_client_channels_buf 0-3 26309 NULL nohasharray
109394 +pax_get_random_long_26309 pax_get_random_long 0 26309 &snd_pcm_plug_client_channels_buf_26309
109395 +pwr_wake_on_host_read_26321 pwr_wake_on_host_read 3 26321 NULL
109396 +check_can_nocow_26336 check_can_nocow 2 26336 NULL
109397 +snd_vx_check_reg_bit_26344 snd_vx_check_reg_bit 0 26344 NULL
109398 +ocfs2_duplicate_clusters_by_page_26357 ocfs2_duplicate_clusters_by_page 6-3 26357 NULL
109399 +cifs_readdata_alloc_26360 cifs_readdata_alloc 1 26360 NULL
109400 +invalidate_inode_pages2_range_26403 invalidate_inode_pages2_range 0 26403 NULL
109401 +ntty_write_26404 ntty_write 3 26404 NULL
109402 +firmware_store_26408 firmware_store 4 26408 NULL
109403 +pagemap_read_26441 pagemap_read 3 26441 NULL
109404 +tower_read_26461 tower_read 3 26461 NULL nohasharray
109405 +enc_pools_add_pages_26461 enc_pools_add_pages 1 26461 &tower_read_26461
109406 +ib_alloc_device_26483 ib_alloc_device 1 26483 NULL
109407 +ulong_write_file_26485 ulong_write_file 3 26485 NULL
109408 +dvb_ca_en50221_io_ioctl_26490 dvb_ca_en50221_io_ioctl 2 26490 NULL
109409 +read_vmcore_26501 read_vmcore 3 26501 NULL
109410 +uhid_char_write_26502 uhid_char_write 3 26502 NULL
109411 +vfio_pci_set_msi_trigger_26507 vfio_pci_set_msi_trigger 4-3 26507 NULL
109412 +iwl_dbgfs_rf_reset_read_26512 iwl_dbgfs_rf_reset_read 3 26512 NULL
109413 +SyS_rt_sigpending_26538 SyS_rt_sigpending 2 26538 NULL
109414 +__vhost_add_used_n_26554 __vhost_add_used_n 3 26554 NULL
109415 +dio_new_bio_26562 dio_new_bio 0 26562 NULL
109416 +rts51x_read_mem_26577 rts51x_read_mem 4 26577 NULL
109417 +pwr_fix_tsf_ps_read_26627 pwr_fix_tsf_ps_read 3 26627 NULL
109418 +irq_alloc_generic_chip_26650 irq_alloc_generic_chip 2 26650 NULL nohasharray
109419 +inb_p_26650 inb_p 0 26650 &irq_alloc_generic_chip_26650
109420 +nouveau_volt_create__26654 nouveau_volt_create_ 4 26654 NULL
109421 +cipso_v4_map_cat_rbm_hton_26680 cipso_v4_map_cat_rbm_hton 0 26680 NULL
109422 +nouveau_namedb_create__26732 nouveau_namedb_create_ 7 26732 NULL
109423 +pipeline_tcp_rx_stat_fifo_int_read_26745 pipeline_tcp_rx_stat_fifo_int_read 3 26745 NULL
109424 +bos_desc_26752 bos_desc 0 26752 NULL
109425 +snd_hda_get_raw_connections_26762 snd_hda_get_raw_connections 0 26762 NULL
109426 +dma_map_single_attrs_26779 dma_map_single_attrs 0 26779 NULL
109427 +qlcnic_alloc_sds_rings_26795 qlcnic_alloc_sds_rings 2 26795 NULL
109428 +cipso_v4_genopt_26812 cipso_v4_genopt 0 26812 NULL
109429 +iwl_trans_read_mem32_26825 iwl_trans_read_mem32 0 26825 NULL
109430 +smk_write_load_26829 smk_write_load 3 26829 NULL
109431 +scnprint_id_26842 scnprint_id 3-0 26842 NULL
109432 +ecryptfs_miscdev_write_26847 ecryptfs_miscdev_write 3 26847 NULL
109433 +tipc_conn_sendmsg_26867 tipc_conn_sendmsg 5 26867 NULL
109434 +ath6kl_create_qos_write_26879 ath6kl_create_qos_write 3 26879 NULL
109435 +svc_print_xprts_26881 svc_print_xprts 0 26881 NULL
109436 +cfg80211_process_auth_26916 cfg80211_process_auth 3 26916 NULL
109437 +x25_asy_change_mtu_26928 x25_asy_change_mtu 2 26928 NULL
109438 +scsi_tgt_copy_sense_26933 scsi_tgt_copy_sense 3 26933 NULL
109439 +sctp_setsockopt_adaptation_layer_26935 sctp_setsockopt_adaptation_layer 3 26935 NULL nohasharray
109440 +pwr_ps_enter_read_26935 pwr_ps_enter_read 3 26935 &sctp_setsockopt_adaptation_layer_26935
109441 +hecubafb_write_26942 hecubafb_write 3 26942 NULL
109442 +do_trimming_26952 do_trimming 3 26952 NULL nohasharray
109443 +extract_entropy_user_26952 extract_entropy_user 3 26952 &do_trimming_26952
109444 +do_direct_IO_26979 do_direct_IO 0 26979 NULL
109445 +__videobuf_alloc_vb_27062 __videobuf_alloc_vb 1 27062 NULL
109446 +ext4_convert_unwritten_extents_27064 ext4_convert_unwritten_extents 4-3-0 27064 NULL
109447 +snd_pcm_lib_period_bytes_27071 snd_pcm_lib_period_bytes 0 27071 NULL
109448 +paravirt_read_msr_27077 paravirt_read_msr 0 27077 NULL
109449 +alloc_fdmem_27083 alloc_fdmem 1 27083 NULL
109450 +btmrvl_hscmd_write_27089 btmrvl_hscmd_write 3 27089 NULL nohasharray
109451 +ath9k_hw_4k_dump_eeprom_27089 ath9k_hw_4k_dump_eeprom 5-4 27089 &btmrvl_hscmd_write_27089
109452 +__devcgroup_inode_permission_27108 __devcgroup_inode_permission 0 27108 NULL
109453 +get_kernel_page_27133 get_kernel_page 0 27133 NULL
109454 +drbd_get_capacity_27141 drbd_get_capacity 0 27141 NULL
109455 +pms_capture_27142 pms_capture 4 27142 NULL
109456 +btmrvl_hscfgcmd_write_27143 btmrvl_hscfgcmd_write 3 27143 NULL
109457 +snd_compr_calc_avail_27165 snd_compr_calc_avail 0 27165 NULL
109458 +ieee80211_if_read_rc_rateidx_mask_5ghz_27183 ieee80211_if_read_rc_rateidx_mask_5ghz 3 27183 NULL
109459 +__sg_alloc_table_27198 __sg_alloc_table 0 27198 NULL
109460 +write_kmem_27225 write_kmem 3 27225 NULL
109461 +dbAllocAG_27228 dbAllocAG 0 27228 NULL
109462 +rxrpc_request_key_27235 rxrpc_request_key 3 27235 NULL
109463 +ll_track_gid_seq_write_27267 ll_track_gid_seq_write 3 27267 NULL
109464 +comedi_alloc_devpriv_27272 comedi_alloc_devpriv 2 27272 NULL
109465 +copy_from_buf_27308 copy_from_buf 4-2 27308 NULL
109466 +virtqueue_add_inbuf_27312 virtqueue_add_inbuf 3 27312 NULL
109467 +snd_pcm_oss_write2_27332 snd_pcm_oss_write2 3-0 27332 NULL
109468 +afs_cell_create_27346 afs_cell_create 2 27346 NULL
109469 +iwl_dbgfs_csr_write_27363 iwl_dbgfs_csr_write 3 27363 NULL
109470 +pcbit_stat_27364 pcbit_stat 2 27364 NULL
109471 +seq_read_27411 seq_read 3 27411 NULL
109472 +ib_dma_map_sg_27413 ib_dma_map_sg 0 27413 NULL
109473 +ieee80211_if_read_smps_27416 ieee80211_if_read_smps 3 27416 NULL
109474 +ocfs2_refcount_cal_cow_clusters_27422 ocfs2_refcount_cal_cow_clusters 0-3-4 27422 NULL
109475 +cypress_write_27423 cypress_write 4 27423 NULL
109476 +sddr09_read_data_27447 sddr09_read_data 3 27447 NULL
109477 +v4l2_ctrl_new_std_menu_items_27487 v4l2_ctrl_new_std_menu_items 4 27487 NULL
109478 +hcd_buffer_alloc_27495 hcd_buffer_alloc 2 27495 NULL
109479 +ip_set_get_h32_27498 ip_set_get_h32 0 27498 NULL
109480 +btrfs_get_64_27499 btrfs_get_64 0 27499 NULL
109481 +garmin_read_process_27509 garmin_read_process 3 27509 NULL
109482 +oti_alloc_cookies_27510 oti_alloc_cookies 2 27510 NULL
109483 +ib_copy_to_udata_27525 ib_copy_to_udata 3 27525 NULL
109484 +snd_sonicvibes_getdmaa_27552 snd_sonicvibes_getdmaa 0 27552 NULL
109485 +SyS_fgetxattr_27571 SyS_fgetxattr 4 27571 NULL
109486 +sco_sock_recvmsg_27572 sco_sock_recvmsg 4 27572 NULL
109487 +libipw_alloc_txb_27579 libipw_alloc_txb 1 27579 NULL
109488 +ocfs2_xattr_ibody_get_27642 ocfs2_xattr_ibody_get 0 27642 NULL nohasharray
109489 +nl80211_send_connect_result_27642 nl80211_send_connect_result 5-7 27642 &ocfs2_xattr_ibody_get_27642 nohasharray
109490 +read_flush_procfs_27642 read_flush_procfs 3 27642 &nl80211_send_connect_result_27642 nohasharray
109491 +ocfs2_direct_IO_27642 ocfs2_direct_IO 4 27642 &read_flush_procfs_27642
109492 +add_new_gdb_27643 add_new_gdb 3 27643 NULL
109493 +btrfs_fallocate_27647 btrfs_fallocate 3-4 27647 NULL
109494 +qnx6_readpages_27657 qnx6_readpages 4 27657 NULL
109495 +cdrom_read_cdda_old_27664 cdrom_read_cdda_old 4 27664 NULL
109496 +ocfs2_extend_dir_27695 ocfs2_extend_dir 4 27695 NULL
109497 +fs_path_add_from_extent_buffer_27702 fs_path_add_from_extent_buffer 4 27702 NULL
109498 +evm_write_key_27715 evm_write_key 3 27715 NULL
109499 +ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol_27722 ieee80211_if_fmt_dot11MeshGateAnnouncementProtocol 3 27722 NULL
109500 +xfs_dir2_block_sfsize_27727 xfs_dir2_block_sfsize 0 27727 NULL
109501 +SyS_setsockopt_27759 SyS_setsockopt 5 27759 NULL
109502 +__lov_setstripe_27782 __lov_setstripe 2 27782 NULL
109503 +twl4030_set_gpio_dataout_27792 twl4030_set_gpio_dataout 1 27792 NULL
109504 +SyS_readv_27804 SyS_readv 3 27804 NULL
109505 +mpihelp_mul_27805 mpihelp_mul 5-3 27805 NULL
109506 +fwtty_buffer_rx_27821 fwtty_buffer_rx 3 27821 NULL
109507 +hpt374_read_freq_27828 hpt374_read_freq 0 27828 NULL
109508 +init_header_complete_27833 init_header_complete 0 27833 NULL
109509 +read_profile_27859 read_profile 3 27859 NULL
109510 +sky2_pci_read16_27863 sky2_pci_read16 0 27863 NULL
109511 +ieee80211_if_read_dot11MeshHWMProotInterval_27873 ieee80211_if_read_dot11MeshHWMProotInterval 3 27873 NULL
109512 +unix_seqpacket_sendmsg_27893 unix_seqpacket_sendmsg 4 27893 NULL
109513 +check_mapped_name_27943 check_mapped_name 3 27943 NULL
109514 +tracing_clock_write_27961 tracing_clock_write 3 27961 NULL
109515 +tipc_media_addr_printf_27971 tipc_media_addr_printf 2 27971 NULL
109516 +device_register_27972 device_register 0 27972 NULL nohasharray
109517 +mic_rx_pkts_read_27972 mic_rx_pkts_read 3 27972 &device_register_27972
109518 +pci_enable_device_flags_27977 pci_enable_device_flags 0 27977 NULL
109519 +f2fs_bio_alloc_27983 f2fs_bio_alloc 2 27983 NULL
109520 +edt_ft5x06_debugfs_raw_data_read_28002 edt_ft5x06_debugfs_raw_data_read 3 28002 NULL
109521 +snd_rawmidi_write_28008 snd_rawmidi_write 3 28008 NULL
109522 +powercap_register_zone_28028 powercap_register_zone 6 28028 NULL
109523 +sctp_setsockopt_maxburst_28041 sctp_setsockopt_maxburst 3 28041 NULL
109524 +rts51x_xd_rw_28046 rts51x_xd_rw 3-4 28046 NULL
109525 +cx231xx_init_vbi_isoc_28053 cx231xx_init_vbi_isoc 3-2-4 28053 NULL
109526 +pool_status_28055 pool_status 5 28055 NULL
109527 +init_rs_non_canonical_28059 init_rs_non_canonical 1 28059 NULL
109528 +lpfc_idiag_mbxacc_read_28061 lpfc_idiag_mbxacc_read 3 28061 NULL
109529 +tx_frag_bad_mblk_num_read_28064 tx_frag_bad_mblk_num_read 3 28064 NULL
109530 +mmc_test_alloc_mem_28102 mmc_test_alloc_mem 3-2 28102 NULL
109531 +rx_defrag_need_defrag_read_28117 rx_defrag_need_defrag_read 3 28117 NULL
109532 +vgacon_adjust_height_28124 vgacon_adjust_height 2 28124 NULL
109533 +video_read_28148 video_read 3 28148 NULL
109534 +snd_midi_channel_alloc_set_28153 snd_midi_channel_alloc_set 1 28153 NULL
109535 +stats_dot11FCSErrorCount_read_28154 stats_dot11FCSErrorCount_read 3 28154 NULL
109536 +vread_28173 vread 0-3 28173 NULL
109537 +macvtap_get_user_28185 macvtap_get_user 4 28185 NULL
109538 +counter_free_res_28187 counter_free_res 5 28187 NULL
109539 +read_disk_sb_28188 read_disk_sb 2 28188 NULL
109540 +nouveau_mxm_create__28200 nouveau_mxm_create_ 4 28200 NULL
109541 +__qp_memcpy_from_queue_28220 __qp_memcpy_from_queue 3-4 28220 NULL
109542 +line6_alloc_sysex_buffer_28225 line6_alloc_sysex_buffer 4 28225 NULL
109543 +amd_nb_num_28228 amd_nb_num 0 28228 NULL
109544 +fuse_direct_IO_28275 fuse_direct_IO 4 28275 NULL
109545 +usemap_size_28281 usemap_size 0 28281 NULL
109546 +inline_xattr_size_28285 inline_xattr_size 0 28285 NULL
109547 +dma_map_sg_attrs_28289 dma_map_sg_attrs 0 28289 NULL
109548 +SyS_ppoll_28290 SyS_ppoll 2 28290 NULL
109549 +kstrtos16_from_user_28300 kstrtos16_from_user 2 28300 NULL
109550 +nouveau_compat_ioctl_28305 nouveau_compat_ioctl 2 28305 NULL
109551 +snd_pcm_oss_read_28317 snd_pcm_oss_read 3 28317 NULL
109552 +bm_entry_write_28338 bm_entry_write 3 28338 NULL
109553 +tcp_copy_to_iovec_28344 tcp_copy_to_iovec 3 28344 NULL
109554 +snapshot_write_28351 snapshot_write 3 28351 NULL
109555 +xfs_iomap_write_unwritten_28365 xfs_iomap_write_unwritten 3-2 28365 NULL
109556 +batadv_handle_tt_response_28370 batadv_handle_tt_response 4 28370 NULL
109557 +dlmfs_file_read_28385 dlmfs_file_read 3 28385 NULL
109558 +tx_frag_cache_miss_read_28394 tx_frag_cache_miss_read 3 28394 NULL
109559 +bypass_pwup_write_28416 bypass_pwup_write 3 28416 NULL
109560 +subdev_ioctl_28417 subdev_ioctl 2 28417 NULL
109561 +ksocknal_alloc_tx_28426 ksocknal_alloc_tx 2 28426 NULL
109562 +mpage_readpages_28436 mpage_readpages 3 28436 NULL
109563 +snd_emu10k1_efx_read_28452 snd_emu10k1_efx_read 2 28452 NULL
109564 +key_mic_failures_read_28457 key_mic_failures_read 3 28457 NULL
109565 +alloc_irq_cpu_rmap_28459 alloc_irq_cpu_rmap 1 28459 NULL
109566 +ps_poll_upsd_utilization_read_28519 ps_poll_upsd_utilization_read 3 28519 NULL
109567 +i2400m_tx_stats_read_28527 i2400m_tx_stats_read 3 28527 NULL
109568 +sel_read_policycap_28544 sel_read_policycap 3 28544 NULL
109569 +mptctl_getiocinfo_28545 mptctl_getiocinfo 2 28545 NULL nohasharray
109570 +run_delalloc_range_28545 run_delalloc_range 3-4 28545 &mptctl_getiocinfo_28545 nohasharray
109571 +aio_read_events_28545 aio_read_events 3 28545 &run_delalloc_range_28545
109572 +sysfs_create_bin_file_28551 sysfs_create_bin_file 0 28551 NULL
109573 +b43legacy_debugfs_write_28556 b43legacy_debugfs_write 3 28556 NULL
109574 +asymmetric_verify_28567 asymmetric_verify 3 28567 NULL
109575 +oxygen_read32_28582 oxygen_read32 0 28582 NULL
109576 +extract_entropy_28604 extract_entropy 5-3 28604 NULL
109577 +kfifo_unused_28612 kfifo_unused 0 28612 NULL
109578 +snd_nm256_capture_copy_28622 snd_nm256_capture_copy 5-3 28622 NULL
109579 +setup_usemap_28636 setup_usemap 3-4 28636 NULL
109580 +qib_handle_6120_hwerrors_28642 qib_handle_6120_hwerrors 3 28642 NULL
109581 +p9_fcall_alloc_28652 p9_fcall_alloc 1 28652 NULL
109582 +read_nic_io_byte_28654 read_nic_io_byte 0 28654 NULL
109583 +blk_queue_resize_tags_28670 blk_queue_resize_tags 2 28670 NULL
109584 +SyS_setgroups16_28686 SyS_setgroups16 1 28686 NULL
109585 +kvm_mmu_get_page_28692 kvm_mmu_get_page 2 28692 NULL
109586 +drm_plane_init_28731 drm_plane_init 6 28731 NULL
109587 +spi_execute_28736 spi_execute 5 28736 NULL
109588 +snd_pcm_aio_write_28738 snd_pcm_aio_write 3 28738 NULL
109589 +read_file_btcoex_28743 read_file_btcoex 3 28743 NULL
109590 +max_hw_blocks_28748 max_hw_blocks 0 28748 NULL
109591 +rpc_pipe_generic_upcall_28766 rpc_pipe_generic_upcall 4 28766 NULL
109592 +ath6kl_get_num_reg_28780 ath6kl_get_num_reg 0 28780 NULL
109593 +sel_write_member_28800 sel_write_member 3 28800 NULL
109594 +cgroup_file_read_28804 cgroup_file_read 3 28804 NULL
109595 +iwl_dbgfs_rxon_filter_flags_read_28832 iwl_dbgfs_rxon_filter_flags_read 3 28832 NULL
109596 +vp_request_msix_vectors_28849 vp_request_msix_vectors 2 28849 NULL
109597 +ipv6_renew_options_28867 ipv6_renew_options 5 28867 NULL
109598 +max_io_len_target_boundary_28879 max_io_len_target_boundary 0-1 28879 NULL
109599 +packet_sendmsg_spkt_28885 packet_sendmsg_spkt 4 28885 NULL
109600 +da9055_group_write_28904 da9055_group_write 2-3 28904 NULL
109601 +ps_upsd_timeouts_read_28924 ps_upsd_timeouts_read 3 28924 NULL
109602 +iwl_dbgfs_sleep_level_override_write_28925 iwl_dbgfs_sleep_level_override_write 3 28925 NULL
109603 +push_rx_28939 push_rx 3 28939 NULL
109604 +btrfs_trim_block_group_28963 btrfs_trim_block_group 3-4 28963 NULL
109605 +alloc_sched_domains_28972 alloc_sched_domains 1 28972 NULL
109606 +hash_net6_expire_28979 hash_net6_expire 4 28979 NULL
109607 +hci_sock_setsockopt_28993 hci_sock_setsockopt 5 28993 NULL
109608 +bin_uuid_28999 bin_uuid 3 28999 NULL
109609 +fd_execute_rw_29004 fd_execute_rw 3 29004 NULL
109610 +ieee80211_if_read_ht_opmode_29044 ieee80211_if_read_ht_opmode 3 29044 NULL
109611 +rxrpc_sendmsg_29049 rxrpc_sendmsg 4 29049 NULL
109612 +btrfs_root_bytenr_29058 btrfs_root_bytenr 0 29058 NULL
109613 +iso_packets_buffer_init_29061 iso_packets_buffer_init 3-4 29061 NULL
109614 +roundup_64_29066 roundup_64 2-0-1 29066 NULL
109615 +lpfc_idiag_extacc_drivr_get_29067 lpfc_idiag_extacc_drivr_get 0-3 29067 NULL
109616 +sctp_getsockopt_assoc_stats_29074 sctp_getsockopt_assoc_stats 2 29074 NULL
109617 +iwl_dbgfs_log_event_write_29088 iwl_dbgfs_log_event_write 3 29088 NULL
109618 +i915_error_object_create_sized_29091 i915_error_object_create_sized 3 29091 NULL
109619 +isdn_ppp_write_29109 isdn_ppp_write 4 29109 NULL
109620 +snprintf_29125 snprintf 0 29125 NULL
109621 +iov_shorten_29130 iov_shorten 0 29130 NULL
109622 +proc_scsi_write_29142 proc_scsi_write 3 29142 NULL
109623 +kvm_mmu_notifier_clear_flush_young_29154 kvm_mmu_notifier_clear_flush_young 3 29154 NULL
109624 +drm_property_create_enum_29201 drm_property_create_enum 5 29201 NULL
109625 +wusb_prf_256_29203 wusb_prf_256 7 29203 NULL
109626 +iwl_dbgfs_temperature_read_29224 iwl_dbgfs_temperature_read 3 29224 NULL
109627 +nvme_trans_copy_from_user_29227 nvme_trans_copy_from_user 3 29227 NULL
109628 +irq_domain_add_linear_29236 irq_domain_add_linear 2 29236 NULL
109629 +evdev_handle_get_val_29242 evdev_handle_get_val 5-6 29242 NULL
109630 +security_context_to_sid_core_29248 security_context_to_sid_core 2 29248 NULL
109631 +prism2_set_genericelement_29277 prism2_set_genericelement 3 29277 NULL
109632 +ext4_fiemap_29296 ext4_fiemap 4 29296 NULL
109633 +sn9c102_read_29305 sn9c102_read 3 29305 NULL
109634 +__fuse_get_req_29315 __fuse_get_req 2 29315 NULL
109635 +lprocfs_write_helper_29323 lprocfs_write_helper 2 29323 NULL
109636 +kvm_handle_hva_29326 kvm_handle_hva 2 29326 NULL
109637 +tun_put_user_29337 tun_put_user 5 29337 NULL
109638 +__alloc_ei_netdev_29338 __alloc_ei_netdev 1 29338 NULL
109639 +l2cap_sock_setsockopt_old_29346 l2cap_sock_setsockopt_old 4 29346 NULL
109640 +mwifiex_cfg80211_mgmt_tx_29387 mwifiex_cfg80211_mgmt_tx 7 29387 NULL
109641 +read_file_tx99_power_29405 read_file_tx99_power 3 29405 NULL
109642 +mempool_create_29437 mempool_create 1 29437 NULL
109643 +crypto_ahash_alignmask_29445 crypto_ahash_alignmask 0 29445 NULL
109644 +p9_client_prepare_req_29448 p9_client_prepare_req 3 29448 NULL
109645 +validate_scan_freqs_29462 validate_scan_freqs 0 29462 NULL
109646 +SyS_flistxattr_29474 SyS_flistxattr 3 29474 NULL
109647 +do_register_entry_29478 do_register_entry 4 29478 NULL
109648 +simple_strtoul_29480 simple_strtoul 0 29480 NULL
109649 +btmrvl_pscmd_write_29504 btmrvl_pscmd_write 3 29504 NULL
109650 +btrfs_file_extent_disk_bytenr_29505 btrfs_file_extent_disk_bytenr 0 29505 NULL
109651 +write_file_regidx_29517 write_file_regidx 3 29517 NULL
109652 +atk_debugfs_ggrp_read_29522 atk_debugfs_ggrp_read 3 29522 NULL
109653 +ftrace_write_29551 ftrace_write 3 29551 NULL
109654 +idetape_queue_rw_tail_29562 idetape_queue_rw_tail 3 29562 NULL
109655 +leaf_dealloc_29566 leaf_dealloc 3 29566 NULL
109656 +kvm_read_guest_virt_system_29569 kvm_read_guest_virt_system 4-2 29569 NULL
109657 +lbs_lowsnr_read_29571 lbs_lowsnr_read 3 29571 NULL
109658 +iwl_dbgfs_missed_beacon_write_29586 iwl_dbgfs_missed_beacon_write 3 29586 NULL
109659 +pvr2_hdw_report_unlocked_29589 pvr2_hdw_report_unlocked 4-0 29589 NULL
109660 +dio_set_defer_completion_29599 dio_set_defer_completion 0 29599 NULL
109661 +slots_per_page_29601 slots_per_page 0 29601 NULL
109662 +osc_cached_mb_seq_write_29610 osc_cached_mb_seq_write 3 29610 NULL
109663 +nla_get_u16_29624 nla_get_u16 0 29624 NULL
109664 +tx_frag_cache_hit_read_29639 tx_frag_cache_hit_read 3 29639 NULL
109665 +sctp_make_abort_user_29654 sctp_make_abort_user 3 29654 NULL
109666 +sisusb_write_mem_bulk_29678 sisusb_write_mem_bulk 4 29678 NULL
109667 +lustre_posix_acl_xattr_2ext_29693 lustre_posix_acl_xattr_2ext 2 29693 NULL
109668 +posix_acl_from_xattr_29708 posix_acl_from_xattr 3 29708 NULL
109669 +probes_write_29711 probes_write 3 29711 NULL
109670 +read_cis_cache_29735 read_cis_cache 4 29735 NULL
109671 +xfs_new_eof_29737 xfs_new_eof 2 29737 NULL
109672 +std_nic_write_29752 std_nic_write 3 29752 NULL
109673 +dbAlloc_29794 dbAlloc 0 29794 NULL
109674 +tcp_sendpage_29829 tcp_sendpage 4 29829 NULL
109675 +__probe_kernel_write_29842 __probe_kernel_write 3 29842 NULL
109676 +kvm_read_hva_atomic_29848 kvm_read_hva_atomic 3 29848 NULL
109677 +count_partial_29850 count_partial 0 29850 NULL
109678 +write_file_bool_bmps_29870 write_file_bool_bmps 3 29870 NULL
109679 +ipv6_setsockopt_29871 ipv6_setsockopt 5 29871 NULL
109680 +scsi_end_request_29876 scsi_end_request 3 29876 NULL
109681 +crypto_aead_alignmask_29885 crypto_aead_alignmask 0 29885 NULL
109682 +lov_ost_pool_extend_29914 lov_ost_pool_extend 2 29914 NULL
109683 +write_file_queue_29922 write_file_queue 3 29922 NULL
109684 +ext4_xattr_set_acl_29930 ext4_xattr_set_acl 4 29930 NULL
109685 +__btrfs_getxattr_29947 __btrfs_getxattr 0 29947 NULL nohasharray
109686 +ipv6_recv_error_29947 ipv6_recv_error 3 29947 &__btrfs_getxattr_29947
109687 +dev_mem_write_30028 dev_mem_write 3 30028 NULL
109688 +alloc_netdev_mqs_30030 alloc_netdev_mqs 1 30030 NULL
109689 +scsi_vpd_inquiry_30040 scsi_vpd_inquiry 4 30040 NULL
109690 +drp_wmove_30043 drp_wmove 4 30043 NULL
109691 +__pci_request_selected_regions_30058 __pci_request_selected_regions 0 30058 NULL
109692 +cxgbi_ddp_reserve_30091 cxgbi_ddp_reserve 4 30091 NULL
109693 +snd_midi_channel_init_set_30092 snd_midi_channel_init_set 1 30092 NULL
109694 +rx_filter_data_filter_read_30098 rx_filter_data_filter_read 3 30098 NULL
109695 +defragment_dma_buffer_30113 defragment_dma_buffer 0 30113 NULL
109696 +spi_async_locked_30117 spi_async_locked 0 30117 NULL
109697 +recv_stream_30138 recv_stream 4 30138 NULL
109698 +u_memcpya_30139 u_memcpya 3-2 30139 NULL
109699 +elfcorehdr_read_30159 elfcorehdr_read 2 30159 NULL
109700 +alloc_switch_ctx_30165 alloc_switch_ctx 2 30165 NULL
109701 +expand_inode_data_30169 expand_inode_data 2-3 30169 NULL
109702 +mempool_create_page_pool_30189 mempool_create_page_pool 1 30189 NULL
109703 +drm_property_create_bitmask_30195 drm_property_create_bitmask 5 30195 NULL
109704 +usblp_ioctl_30203 usblp_ioctl 2 30203 NULL
109705 +read_4k_modal_eeprom_30212 read_4k_modal_eeprom 3 30212 NULL
109706 +SyS_semop_30227 SyS_semop 3 30227 NULL
109707 +bitmap_file_set_bit_30228 bitmap_file_set_bit 2 30228 NULL
109708 +ocfs2_calc_bg_discontig_credits_30230 ocfs2_calc_bg_discontig_credits 0 30230 NULL
109709 +rawv6_recvmsg_30265 rawv6_recvmsg 4 30265 NULL
109710 +hfsplus_trusted_setxattr_30270 hfsplus_trusted_setxattr 4 30270 NULL
109711 +isr_pci_pm_read_30271 isr_pci_pm_read 3 30271 NULL
109712 +compat_readv_30273 compat_readv 3 30273 NULL
109713 +skcipher_sendmsg_30290 skcipher_sendmsg 4 30290 NULL
109714 +pipeline_sec_frag_swi_read_30294 pipeline_sec_frag_swi_read 3 30294 NULL
109715 +tcp_sendmsg_30296 tcp_sendmsg 4 30296 NULL
109716 +osc_contention_seconds_seq_write_30305 osc_contention_seconds_seq_write 3 30305 NULL
109717 +ext4_acl_from_disk_30320 ext4_acl_from_disk 2 30320 NULL
109718 +i8254_read_30330 i8254_read 0 30330 NULL
109719 +resource_from_user_30341 resource_from_user 3 30341 NULL
109720 +o2nm_this_node_30342 o2nm_this_node 0 30342 NULL
109721 +kstrtou32_from_user_30361 kstrtou32_from_user 2 30361 NULL
109722 +C_SYSC_readv_30369 C_SYSC_readv 3 30369 NULL
109723 +blkdev_issue_zeroout_30392 blkdev_issue_zeroout 3 30392 NULL
109724 +c4iw_init_resource_30393 c4iw_init_resource 2-3 30393 NULL
109725 +get_kernel_pages_30397 get_kernel_pages 0 30397 NULL
109726 +vb2_fop_write_30420 vb2_fop_write 3 30420 NULL
109727 +tx_tx_template_prepared_read_30424 tx_tx_template_prepared_read 3 30424 NULL
109728 +lstcon_session_info_30425 lstcon_session_info 6 30425 NULL
109729 +enable_write_30456 enable_write 3 30456 NULL
109730 +tx_tx_template_programmed_read_30461 tx_tx_template_programmed_read 3 30461 NULL
109731 +urandom_read_30462 urandom_read 3 30462 NULL
109732 +zoran_ioctl_30465 zoran_ioctl 2 30465 NULL
109733 +i2c_ctrl_read_30467 i2c_ctrl_read 0 30467 NULL
109734 +adu_write_30487 adu_write 3 30487 NULL
109735 +dtim_interval_write_30489 dtim_interval_write 3 30489 NULL
109736 +batadv_send_tt_request_30493 batadv_send_tt_request 5 30493 NULL
109737 +dwc3_testmode_write_30516 dwc3_testmode_write 3 30516 NULL
109738 +set_config_30526 set_config 0 30526 NULL nohasharray
109739 +debug_debug2_read_30526 debug_debug2_read 3 30526 &set_config_30526
109740 +xfs_sb_version_hasftype_30559 xfs_sb_version_hasftype 0 30559 NULL
109741 +disk_expand_part_tbl_30561 disk_expand_part_tbl 2 30561 NULL
109742 +set_le_30581 set_le 4 30581 NULL
109743 +blk_init_tags_30592 blk_init_tags 1 30592 NULL
109744 +i2c_hid_get_report_length_30598 i2c_hid_get_report_length 0 30598 NULL
109745 +sgl_map_user_pages_30610 sgl_map_user_pages 2 30610 NULL nohasharray
109746 +cpufreq_get_global_kobject_30610 cpufreq_get_global_kobject 0 30610 &sgl_map_user_pages_30610
109747 +SyS_msgrcv_30611 SyS_msgrcv 3 30611 NULL
109748 +macvtap_sendmsg_30629 macvtap_sendmsg 4 30629 NULL
109749 +ieee80211_if_read_dot11MeshAwakeWindowDuration_30631 ieee80211_if_read_dot11MeshAwakeWindowDuration 3 30631 NULL
109750 +compat_raw_setsockopt_30634 compat_raw_setsockopt 5 30634 NULL
109751 +mlx5_ib_alloc_fast_reg_page_list_30638 mlx5_ib_alloc_fast_reg_page_list 2 30638 NULL
109752 +SyS_listxattr_30647 SyS_listxattr 3 30647 NULL
109753 +jffs2_flash_read_30667 jffs2_flash_read 0 30667 NULL
109754 +ni_ai_fifo_read_30681 ni_ai_fifo_read 3 30681 NULL
109755 +dccp_setsockopt_ccid_30701 dccp_setsockopt_ccid 4 30701 NULL
109756 +lbs_wrbbp_write_30712 lbs_wrbbp_write 3 30712 NULL
109757 +lbs_debugfs_read_30721 lbs_debugfs_read 3 30721 NULL
109758 +snd_nm256_playback_silence_30727 snd_nm256_playback_silence 4-3 30727 NULL
109759 +snapshot_status_30744 snapshot_status 5 30744 NULL
109760 +fuse_conn_limit_write_30777 fuse_conn_limit_write 3 30777 NULL
109761 +smk_read_doi_30813 smk_read_doi 3 30813 NULL
109762 +get_kobj_path_length_30831 get_kobj_path_length 0 30831 NULL
109763 +sctp_setsockopt_auth_chunk_30843 sctp_setsockopt_auth_chunk 3 30843 NULL
109764 +wd_autoreset_write_30862 wd_autoreset_write 3 30862 NULL
109765 +ieee80211_if_fmt_dropped_frames_no_route_30884 ieee80211_if_fmt_dropped_frames_no_route 3 30884 NULL
109766 +pn_recvmsg_30887 pn_recvmsg 4 30887 NULL
109767 +sctp_setsockopt_rtoinfo_30941 sctp_setsockopt_rtoinfo 3 30941 NULL
109768 +tty_insert_flip_string_flags_30969 tty_insert_flip_string_flags 4 30969 NULL
109769 +huge_page_mask_30981 huge_page_mask 0 30981 NULL
109770 +read_file_bt_ant_diversity_30983 read_file_bt_ant_diversity 3 30983 NULL
109771 +lbs_host_sleep_read_31013 lbs_host_sleep_read 3 31013 NULL
109772 +ima_eventsig_init_31022 ima_eventsig_init 5 31022 NULL
109773 +template_fmt_size_31033 template_fmt_size 0 31033 NULL
109774 +do_setup_msi_irqs_31043 do_setup_msi_irqs 2 31043 NULL
109775 +stride_pg_count_31053 stride_pg_count 0-2-1-4-3-5 31053 NULL
109776 +lbs_failcount_read_31063 lbs_failcount_read 3 31063 NULL
109777 +sctp_setsockopt_context_31091 sctp_setsockopt_context 3 31091 NULL
109778 +proc_gid_map_write_31093 proc_gid_map_write 3 31093 NULL
109779 +compat_sys_get_mempolicy_31109 compat_sys_get_mempolicy 3 31109 NULL
109780 +depth_read_31112 depth_read 3 31112 NULL
109781 +hash_ipportnet6_expire_31118 hash_ipportnet6_expire 4 31118 NULL
109782 +kimage_normal_alloc_31140 kimage_normal_alloc 3 31140 NULL
109783 +size_inside_page_31141 size_inside_page 0 31141 NULL
109784 +w9966_v4l_read_31148 w9966_v4l_read 3 31148 NULL
109785 +ch_do_scsi_31171 ch_do_scsi 4 31171 NULL
109786 +r592_read_fifo_pio_31198 r592_read_fifo_pio 3 31198 NULL
109787 +mtdchar_readoob_31200 mtdchar_readoob 4 31200 NULL
109788 +__btrfs_free_reserved_extent_31207 __btrfs_free_reserved_extent 2 31207 NULL
109789 +cpumask_weight_31215 cpumask_weight 0 31215 NULL
109790 +__read_reg_31216 __read_reg 0 31216 NULL
109791 +atm_get_addr_31221 atm_get_addr 3 31221 NULL
109792 +tcp_recvmsg_31238 tcp_recvmsg 4 31238 NULL
109793 +cyy_readb_31240 cyy_readb 0 31240 NULL
109794 +_create_sg_bios_31244 _create_sg_bios 4 31244 NULL
109795 +ieee80211_if_read_last_beacon_31257 ieee80211_if_read_last_beacon 3 31257 NULL
109796 +hash_netportnet4_expire_31290 hash_netportnet4_expire 4 31290 NULL
109797 +uvc_simplify_fraction_31303 uvc_simplify_fraction 3 31303 NULL
109798 +sisusbcon_scroll_31315 sisusbcon_scroll 5-2-3 31315 NULL
109799 +command_file_write_31318 command_file_write 3 31318 NULL
109800 +hwerr_crcbits_31334 hwerr_crcbits 4 31334 NULL
109801 +em28xx_init_usb_xfer_31337 em28xx_init_usb_xfer 4-6 31337 NULL
109802 +outlen_write_31358 outlen_write 3 31358 NULL
109803 +ieee80211_rx_mgmt_auth_31366 ieee80211_rx_mgmt_auth 3 31366 NULL
109804 +xprt_rdma_allocate_31372 xprt_rdma_allocate 2 31372 NULL
109805 +vb2_vmalloc_get_userptr_31374 vb2_vmalloc_get_userptr 3-2 31374 NULL
109806 +trace_parser_get_init_31379 trace_parser_get_init 2 31379 NULL
109807 +inb_31388 inb 0 31388 NULL
109808 +key_ifindex_read_31411 key_ifindex_read 3 31411 NULL
109809 +_sp2d_max_pg_31422 _sp2d_max_pg 0 31422 NULL
109810 +TSS_checkhmac1_31429 TSS_checkhmac1 5 31429 NULL
109811 +snd_aw2_saa7146_get_hw_ptr_capture_31431 snd_aw2_saa7146_get_hw_ptr_capture 0 31431 NULL
109812 +transport_alloc_session_tags_31449 transport_alloc_session_tags 2-3 31449 NULL
109813 +opera1_xilinx_rw_31453 opera1_xilinx_rw 5 31453 NULL
109814 +xfs_btree_get_numrecs_31477 xfs_btree_get_numrecs 0 31477 NULL
109815 +alg_setkey_31485 alg_setkey 3 31485 NULL
109816 +rds_message_map_pages_31487 rds_message_map_pages 2 31487 NULL
109817 +qsfp_2_read_31491 qsfp_2_read 3 31491 NULL
109818 +__alloc_bootmem_31498 __alloc_bootmem 1 31498 NULL
109819 +hidraw_write_31536 hidraw_write 3 31536 NULL
109820 +usbvision_read_31555 usbvision_read 3 31555 NULL
109821 +tx_frag_tkip_called_read_31575 tx_frag_tkip_called_read 3 31575 NULL
109822 +get_max_inline_xattr_value_size_31578 get_max_inline_xattr_value_size 0 31578 NULL
109823 +osst_write_31581 osst_write 3 31581 NULL
109824 +snd_compr_get_avail_31584 snd_compr_get_avail 0 31584 NULL
109825 +iwl_dbgfs_ucode_tx_stats_read_31611 iwl_dbgfs_ucode_tx_stats_read 3 31611 NULL
109826 +mtd_get_user_prot_info_31616 mtd_get_user_prot_info 0 31616 NULL
109827 +arvo_sysfs_read_31617 arvo_sysfs_read 6 31617 NULL
109828 +videobuf_read_one_31637 videobuf_read_one 3 31637 NULL
109829 +pod_alloc_sysex_buffer_31651 pod_alloc_sysex_buffer 3 31651 NULL
109830 +xfer_secondary_pool_31661 xfer_secondary_pool 2 31661 NULL
109831 +__lgread_31668 __lgread 4 31668 NULL
109832 +copy_from_user_nmi_31672 copy_from_user_nmi 3-0 31672 NULL
109833 +forced_ps_read_31685 forced_ps_read 3 31685 NULL
109834 +fst_recover_rx_error_31687 fst_recover_rx_error 3 31687 NULL
109835 +utf16s_to_utf8s_31735 utf16s_to_utf8s 0 31735 NULL nohasharray
109836 +lu_buf_check_and_grow_31735 lu_buf_check_and_grow 2 31735 &utf16s_to_utf8s_31735
109837 +shmem_pwrite_slow_31741 shmem_pwrite_slow 3-2 31741 NULL
109838 +input_abs_get_max_31742 input_abs_get_max 0 31742 NULL nohasharray
109839 +NCR_700_change_queue_depth_31742 NCR_700_change_queue_depth 2 31742 &input_abs_get_max_31742
109840 +bcm_char_read_31750 bcm_char_read 3 31750 NULL
109841 +snd_seq_device_new_31753 snd_seq_device_new 4 31753 NULL
109842 +SyS_lsetxattr_31766 SyS_lsetxattr 4 31766 NULL
109843 +usblp_cache_device_id_string_31790 usblp_cache_device_id_string 0 31790 NULL
109844 +ecryptfs_send_message_locked_31801 ecryptfs_send_message_locked 2 31801 NULL
109845 +isr_rx_procs_read_31804 isr_rx_procs_read 3 31804 NULL
109846 +data_write_31805 data_write 3 31805 NULL
109847 +SyS_msgsnd_31814 SyS_msgsnd 3 31814 NULL
109848 +strnlen_user_31815 strnlen_user 0-2 31815 NULL
109849 +sta_last_signal_read_31818 sta_last_signal_read 3 31818 NULL
109850 +SyS_ppoll_31855 SyS_ppoll 2 31855 NULL
109851 +iwl_dbgfs_disable_ht40_write_31876 iwl_dbgfs_disable_ht40_write 3 31876 NULL
109852 +drm_mode_crtc_set_gamma_size_31881 drm_mode_crtc_set_gamma_size 2 31881 NULL
109853 +ddb_output_write_31902 ddb_output_write 3-0 31902 NULL
109854 +xattr_permission_31907 xattr_permission 0 31907 NULL
109855 +lu_buf_realloc_31915 lu_buf_realloc 2 31915 NULL
109856 +new_dir_31919 new_dir 3 31919 NULL
109857 +kmem_alloc_31920 kmem_alloc 1 31920 NULL
109858 +SYSC_sethostname_31940 SYSC_sethostname 2 31940 NULL
109859 +read_mem_31942 read_mem 3 31942 NULL nohasharray
109860 +iov_iter_copy_from_user_31942 iov_iter_copy_from_user 4-0 31942 &read_mem_31942
109861 +vb2_write_31948 vb2_write 3 31948 NULL
109862 +pvr2_ctrl_get_valname_31951 pvr2_ctrl_get_valname 4 31951 NULL
109863 +regcache_rbtree_sync_31964 regcache_rbtree_sync 2 31964 NULL
109864 +copy_from_user_toio_31966 copy_from_user_toio 3 31966 NULL
109865 +iblock_execute_rw_31982 iblock_execute_rw 3 31982 NULL nohasharray
109866 +vx_read_status_31982 vx_read_status 0 31982 &iblock_execute_rw_31982
109867 +find_next_zero_bit_31990 find_next_zero_bit 0 31990 NULL
109868 +lustre_acl_xattr_merge2posix_31992 lustre_acl_xattr_merge2posix 2 31992 NULL
109869 +sysfs_create_file_31996 sysfs_create_file 0 31996 NULL
109870 +calc_hmac_32010 calc_hmac 3 32010 NULL
109871 +aead_len_32021 aead_len 0 32021 NULL
109872 +posix_acl_set_32037 posix_acl_set 4 32037 NULL
109873 +stk_read_32038 stk_read 3 32038 NULL
109874 +ocfs2_update_edge_lengths_32046 ocfs2_update_edge_lengths 3 32046 NULL
109875 +SYSC_llistxattr_32061 SYSC_llistxattr 3 32061 NULL
109876 +proc_scsi_devinfo_write_32064 proc_scsi_devinfo_write 3 32064 NULL
109877 +cow_file_range_inline_32091 cow_file_range_inline 3 32091 NULL
109878 +bio_alloc_32095 bio_alloc 2 32095 NULL
109879 +ath6kl_fwlog_read_32101 ath6kl_fwlog_read 3 32101 NULL
109880 +disk_status_32120 disk_status 4 32120 NULL
109881 +kobject_add_internal_32133 kobject_add_internal 0 32133 NULL
109882 +venus_link_32165 venus_link 5 32165 NULL
109883 +do_writepages_32173 do_writepages 0 32173 NULL
109884 +wusb_ccm_mac_32199 wusb_ccm_mac 7 32199 NULL
109885 +riva_get_cmap_len_32218 riva_get_cmap_len 0 32218 NULL
109886 +caif_seqpkt_recvmsg_32241 caif_seqpkt_recvmsg 4 32241 NULL
109887 +lbs_lowrssi_read_32242 lbs_lowrssi_read 3 32242 NULL
109888 +ocfs2_xattr_find_entry_32260 ocfs2_xattr_find_entry 0 32260 NULL
109889 +kvm_set_spte_hva_32312 kvm_set_spte_hva 2 32312 NULL
109890 +cas_calc_tabort_32316 cas_calc_tabort 0 32316 NULL
109891 +SyS_select_32319 SyS_select 1 32319 NULL
109892 +nouveau_bar_create__32332 nouveau_bar_create_ 4 32332 NULL
109893 +nl80211_send_mlme_event_32337 nl80211_send_mlme_event 4 32337 NULL
109894 +t4_alloc_mem_32342 t4_alloc_mem 1 32342 NULL
109895 +dispatch_ioctl_32357 dispatch_ioctl 2 32357 NULL nohasharray
109896 +rx_streaming_always_write_32357 rx_streaming_always_write 3 32357 &dispatch_ioctl_32357
109897 +ReadHDLCPCI_32362 ReadHDLCPCI 0 32362 NULL nohasharray
109898 +sel_read_initcon_32362 sel_read_initcon 3 32362 &ReadHDLCPCI_32362
109899 +ocfs2_cancel_convert_32392 ocfs2_cancel_convert 0 32392 NULL
109900 +ll_setxattr_common_32398 ll_setxattr_common 4 32398 NULL
109901 +xfs_iext_add_indirect_multi_32400 xfs_iext_add_indirect_multi 3 32400 NULL
109902 +vmci_qp_alloc_32405 vmci_qp_alloc 5-3 32405 NULL
109903 +cache_status_32462 cache_status 5 32462 NULL
109904 +fill_readbuf_32464 fill_readbuf 3 32464 NULL
109905 +dgap_usertoboard_32490 dgap_usertoboard 4 32490 NULL
109906 +ide_driver_proc_write_32493 ide_driver_proc_write 3 32493 NULL
109907 +bypass_pwoff_write_32499 bypass_pwoff_write 3 32499 NULL
109908 +mdc_pinger_recov_seq_write_32510 mdc_pinger_recov_seq_write 3 32510 NULL
109909 +ctrl_std_val_to_sym_32516 ctrl_std_val_to_sym 5 32516 NULL
109910 +disconnect_32521 disconnect 4 32521 NULL
109911 +qsfp_read_32522 qsfp_read 0-2-4 32522 NULL
109912 +ocfs2_refresh_qinfo_32524 ocfs2_refresh_qinfo 0 32524 NULL nohasharray
109913 +audio_get_intf_req_32524 audio_get_intf_req 0 32524 &ocfs2_refresh_qinfo_32524
109914 +ilo_read_32531 ilo_read 3 32531 NULL
109915 +ieee80211_if_read_estab_plinks_32533 ieee80211_if_read_estab_plinks 3 32533 NULL
109916 +format_devstat_counter_32550 format_devstat_counter 3 32550 NULL
109917 +aes_encrypt_fail_read_32562 aes_encrypt_fail_read 3 32562 NULL
109918 +osc_iocontrol_32565 osc_iocontrol 3 32565 NULL
109919 +mem_swapout_entry_32586 mem_swapout_entry 3 32586 NULL
109920 +pipeline_tcp_tx_stat_fifo_int_read_32589 pipeline_tcp_tx_stat_fifo_int_read 3 32589 NULL
109921 +read_file_beacon_32595 read_file_beacon 3 32595 NULL
109922 +ieee80211_if_read_dropped_frames_congestion_32603 ieee80211_if_read_dropped_frames_congestion 3 32603 NULL
109923 +irda_recvmsg_dgram_32631 irda_recvmsg_dgram 4 32631 NULL
109924 +cfg80211_roamed_32632 cfg80211_roamed 5-7 32632 NULL
109925 +kvmalloc_32646 kvmalloc 1 32646 NULL
109926 +ib_sg_dma_len_32649 ib_sg_dma_len 0 32649 NULL
109927 +generic_readlink_32654 generic_readlink 3 32654 NULL
109928 +move_addr_to_kernel_32673 move_addr_to_kernel 2 32673 NULL
109929 +apei_res_add_32674 apei_res_add 0 32674 NULL
109930 +compat_SyS_preadv_32679 compat_SyS_preadv 3 32679 NULL
109931 +jfs_readpages_32702 jfs_readpages 4 32702 NULL
109932 +rt2x00debug_read_queue_dump_32712 rt2x00debug_read_queue_dump 3 32712 NULL
109933 +i40e_pci_sriov_enable_32742 i40e_pci_sriov_enable 2 32742 NULL
109934 +megasas_change_queue_depth_32747 megasas_change_queue_depth 2 32747 NULL
109935 +stats_read_ul_32751 stats_read_ul 3 32751 NULL
109936 +vmci_transport_dgram_dequeue_32775 vmci_transport_dgram_dequeue 4 32775 NULL
109937 +sctp_tsnmap_grow_32784 sctp_tsnmap_grow 2 32784 NULL
109938 +rproc_name_read_32805 rproc_name_read 3 32805 NULL
109939 +new_tape_buffer_32866 new_tape_buffer 2 32866 NULL
109940 +cifs_writedata_alloc_32880 cifs_writedata_alloc 1 32880 NULL nohasharray
109941 +ath6kl_usb_submit_ctrl_in_32880 ath6kl_usb_submit_ctrl_in 6 32880 &cifs_writedata_alloc_32880
109942 +vp702x_usb_inout_cmd_32884 vp702x_usb_inout_cmd 6-4 32884 NULL
109943 +il_dbgfs_tx_stats_read_32913 il_dbgfs_tx_stats_read 3 32913 NULL
109944 +zlib_inflate_workspacesize_32927 zlib_inflate_workspacesize 0 32927 NULL
109945 +rmap_recycle_32938 rmap_recycle 3 32938 NULL
109946 +xfs_log_reserve_32959 xfs_log_reserve 2 32959 NULL
109947 +ocfs2_check_dir_trailer_32968 ocfs2_check_dir_trailer 0 32968 NULL
109948 +compat_filldir_32999 compat_filldir 3 32999 NULL
109949 +SyS_syslog_33007 SyS_syslog 3 33007 NULL
109950 +br_multicast_set_hash_max_33012 br_multicast_set_hash_max 2 33012 NULL
109951 +write_file_bt_ant_diversity_33019 write_file_bt_ant_diversity 3 33019 NULL
109952 +mic_virtio_copy_to_user_33048 mic_virtio_copy_to_user 3 33048 NULL
109953 +SYSC_lgetxattr_33049 SYSC_lgetxattr 4 33049 NULL
109954 +pipeline_dec_packet_in_fifo_full_read_33052 pipeline_dec_packet_in_fifo_full_read 3 33052 NULL
109955 +ebt_compat_match_offset_33053 ebt_compat_match_offset 0-2 33053 NULL
109956 +bitmap_resize_33054 bitmap_resize 2 33054 NULL
109957 +stats_dot11RTSSuccessCount_read_33065 stats_dot11RTSSuccessCount_read 3 33065 NULL
109958 +sel_read_checkreqprot_33068 sel_read_checkreqprot 3 33068 NULL
109959 +alloc_tio_33077 alloc_tio 3 33077 NULL
109960 +acl_permission_check_33083 acl_permission_check 0 33083 NULL
109961 +fb_sys_write_33130 fb_sys_write 3 33130 NULL
109962 +__len_within_target_33132 __len_within_target 0 33132 NULL
109963 +SyS_poll_33152 SyS_poll 2 33152 NULL
109964 +debug_debug6_read_33168 debug_debug6_read 3 33168 NULL
109965 +dataflash_read_fact_otp_33204 dataflash_read_fact_otp 3-2 33204 NULL
109966 +pp_read_33210 pp_read 3 33210 NULL
109967 +xfs_file_aio_write_33234 xfs_file_aio_write 4 33234 NULL
109968 +snd_pcm_plug_client_size_33267 snd_pcm_plug_client_size 0-2 33267 NULL
109969 +cachefiles_cook_key_33274 cachefiles_cook_key 2 33274 NULL
109970 +sync_pt_create_33282 sync_pt_create 2 33282 NULL
109971 +mcs7830_get_reg_33308 mcs7830_get_reg 3 33308 NULL
109972 +isku_sysfs_read_keys_easyzone_33318 isku_sysfs_read_keys_easyzone 6 33318 NULL
109973 +vx_send_irq_dsp_33329 vx_send_irq_dsp 0 33329 NULL
109974 +joydev_ioctl_33343 joydev_ioctl 2 33343 NULL
109975 +lov_stripesize_seq_write_33353 lov_stripesize_seq_write 3 33353 NULL
109976 +create_xattr_datum_33356 create_xattr_datum 5 33356 NULL nohasharray
109977 +irq_pkt_threshold_read_33356 irq_pkt_threshold_read 3 33356 &create_xattr_datum_33356
109978 +read_file_regidx_33370 read_file_regidx 3 33370 NULL
109979 +ieee80211_if_read_dropped_frames_no_route_33383 ieee80211_if_read_dropped_frames_no_route 3 33383 NULL
109980 +scsi_varlen_cdb_length_33385 scsi_varlen_cdb_length 0 33385 NULL
109981 +ocfs2_allocate_unwritten_extents_33394 ocfs2_allocate_unwritten_extents 3-2 33394 NULL
109982 +cfs_trace_copyin_string_33396 cfs_trace_copyin_string 4 33396 NULL
109983 +snd_pcm_capture_ioctl1_33408 snd_pcm_capture_ioctl1 0 33408 NULL
109984 +hash_netiface6_expire_33421 hash_netiface6_expire 4 33421 NULL
109985 +dis_tap_write_33426 dis_tap_write 3 33426 NULL
109986 +message_stats_list_33440 message_stats_list 5 33440 NULL
109987 +ovs_vport_alloc_33475 ovs_vport_alloc 1 33475 NULL
109988 +create_entry_33479 create_entry 2 33479 NULL
109989 +ip_setsockopt_33487 ip_setsockopt 5 33487 NULL nohasharray
109990 +elf_map_33487 elf_map 0-2 33487 &ip_setsockopt_33487
109991 +res_counter_read_33499 res_counter_read 4 33499 NULL
109992 +hash_netnet4_expire_33500 hash_netnet4_expire 4 33500 NULL
109993 +fb_read_33506 fb_read 3 33506 NULL
109994 +musb_test_mode_write_33518 musb_test_mode_write 3 33518 NULL
109995 +ahash_setkey_unaligned_33521 ahash_setkey_unaligned 3 33521 NULL
109996 +nes_alloc_fast_reg_page_list_33523 nes_alloc_fast_reg_page_list 2 33523 NULL
109997 +aggr_size_rx_size_read_33526 aggr_size_rx_size_read 3 33526 NULL
109998 +tomoyo_read_self_33539 tomoyo_read_self 3 33539 NULL nohasharray
109999 +osc_max_rpcs_in_flight_seq_write_33539 osc_max_rpcs_in_flight_seq_write 3 33539 &tomoyo_read_self_33539
110000 +count_subheaders_33591 count_subheaders 0 33591 NULL
110001 +scsi_execute_33596 scsi_execute 5 33596 NULL
110002 +comedi_buf_write_n_allocated_33604 comedi_buf_write_n_allocated 0 33604 NULL
110003 +xt_compat_target_offset_33608 xt_compat_target_offset 0 33608 NULL
110004 +usb_gstrings_attach_33615 usb_gstrings_attach 3 33615 NULL nohasharray
110005 +il_dbgfs_qos_read_33615 il_dbgfs_qos_read 3 33615 &usb_gstrings_attach_33615
110006 +stride_page_count_33641 stride_page_count 2 33641 NULL
110007 +irq_blk_threshold_read_33666 irq_blk_threshold_read 3 33666 NULL
110008 +inw_p_33668 inw_p 0 33668 NULL
110009 +arp_hdr_len_33671 arp_hdr_len 0 33671 NULL
110010 +i2c_hid_alloc_buffers_33673 i2c_hid_alloc_buffers 2 33673 NULL
110011 +nv50_disp_dmac_create__33696 nv50_disp_dmac_create_ 6 33696 NULL
110012 +netlink_sendmsg_33708 netlink_sendmsg 4 33708 NULL
110013 +tipc_link_stats_33716 tipc_link_stats 3 33716 NULL
110014 +ext4_wb_update_i_disksize_33717 ext4_wb_update_i_disksize 2 33717 NULL
110015 +pvr2_stream_buffer_count_33719 pvr2_stream_buffer_count 2 33719 NULL
110016 +write_file_spectral_count_33723 write_file_spectral_count 3 33723 NULL
110017 +__mutex_lock_interruptible_slowpath_33735 __mutex_lock_interruptible_slowpath 0 33735 NULL
110018 +vifs_state_read_33762 vifs_state_read 3 33762 NULL
110019 +hashtab_create_33769 hashtab_create 3 33769 NULL
110020 +if_sdio_read_rx_len_33800 if_sdio_read_rx_len 0 33800 NULL
110021 +filter_write_33819 filter_write 3 33819 NULL
110022 +sep_create_msgarea_context_33829 sep_create_msgarea_context 4 33829 NULL
110023 +scrub_setup_recheck_block_33831 scrub_setup_recheck_block 5-4 33831 NULL
110024 +ext4_journal_extend_33835 ext4_journal_extend 2 33835 NULL
110025 +oz_cdev_write_33852 oz_cdev_write 3 33852 NULL
110026 +get_user_pages_33908 get_user_pages 0 33908 NULL
110027 +ath6kl_roam_mode_write_33912 ath6kl_roam_mode_write 3 33912 NULL
110028 +queue_logical_block_size_33918 queue_logical_block_size 0 33918 NULL
110029 +sel_read_avc_cache_threshold_33942 sel_read_avc_cache_threshold 3 33942 NULL
110030 +lpfc_idiag_ctlacc_read_33943 lpfc_idiag_ctlacc_read 3 33943 NULL
110031 +read_file_tgt_rx_stats_33944 read_file_tgt_rx_stats 3 33944 NULL
110032 +hfsplus_osx_setxattr_33952 hfsplus_osx_setxattr 4 33952 NULL
110033 +__proc_dump_kernel_33954 __proc_dump_kernel 5 33954 NULL
110034 +vga_switcheroo_debugfs_write_33984 vga_switcheroo_debugfs_write 3 33984 NULL
110035 +lbs_lowrssi_write_34025 lbs_lowrssi_write 3 34025 NULL
110036 +ppp_write_34034 ppp_write 3 34034 NULL
110037 +tty_insert_flip_string_34042 tty_insert_flip_string 3-0 34042 NULL
110038 +memcg_update_all_caches_34068 memcg_update_all_caches 1 34068 NULL
110039 +pipeline_pipeline_fifo_full_read_34095 pipeline_pipeline_fifo_full_read 3 34095 NULL
110040 +__irq_domain_add_34101 __irq_domain_add 2 34101 NULL
110041 +proc_scsi_host_write_34107 proc_scsi_host_write 3 34107 NULL
110042 +islpci_mgt_transmit_34133 islpci_mgt_transmit 5 34133 NULL
110043 +ttm_dma_page_pool_free_34135 ttm_dma_page_pool_free 2-0 34135 NULL
110044 +ixgbe_dbg_netdev_ops_write_34141 ixgbe_dbg_netdev_ops_write 3 34141 NULL
110045 +shmem_pread_fast_34147 shmem_pread_fast 3 34147 NULL
110046 +ocfs2_xattr_list_entry_34165 ocfs2_xattr_list_entry 0 34165 NULL
110047 +skb_to_sgvec_34171 skb_to_sgvec 0 34171 NULL
110048 +ext4_da_write_begin_34215 ext4_da_write_begin 3-4 34215 NULL
110049 +sysfs_bin_read_34228 sysfs_bin_read 3 34228 NULL
110050 +bl_pipe_downcall_34264 bl_pipe_downcall 3 34264 NULL
110051 +ocfs2_dlm_lock_34265 ocfs2_dlm_lock 0 34265 NULL
110052 +device_private_init_34279 device_private_init 0 34279 NULL
110053 +ext4_get_groups_count_34324 ext4_get_groups_count 0 34324 NULL
110054 +pcpu_need_to_extend_34326 pcpu_need_to_extend 0 34326 NULL nohasharray
110055 +iov_iter_single_seg_count_34326 iov_iter_single_seg_count 0 34326 &pcpu_need_to_extend_34326
110056 +crypto_ablkcipher_ivsize_34363 crypto_ablkcipher_ivsize 0 34363 NULL nohasharray
110057 +sync_page_io_34363 sync_page_io 3 34363 &crypto_ablkcipher_ivsize_34363
110058 +rngapi_reset_34366 rngapi_reset 3 34366 NULL
110059 +ea_read_34378 ea_read 0 34378 NULL
110060 +fuse_send_read_34379 fuse_send_read 4 34379 NULL
110061 +av7110_vbi_write_34384 av7110_vbi_write 3 34384 NULL
110062 +usbvision_v4l2_read_34386 usbvision_v4l2_read 3 34386 NULL
110063 +read_rbu_image_type_34387 read_rbu_image_type 6 34387 NULL
110064 +iwl_calib_set_34400 iwl_calib_set 3 34400 NULL nohasharray
110065 +ivtv_read_pos_34400 ivtv_read_pos 3 34400 &iwl_calib_set_34400
110066 +wd_exp_mode_write_34407 wd_exp_mode_write 3 34407 NULL
110067 +nl80211_send_disassoc_34424 nl80211_send_disassoc 4 34424 NULL
110068 +usbtest_alloc_urb_34446 usbtest_alloc_urb 3-5 34446 NULL
110069 +mwifiex_regrdwr_read_34472 mwifiex_regrdwr_read 3 34472 NULL
110070 +skcipher_sndbuf_34476 skcipher_sndbuf 0 34476 NULL
110071 +i2o_parm_field_get_34477 i2o_parm_field_get 5 34477 NULL
110072 +ocfs2_mv_xattr_buckets_34484 ocfs2_mv_xattr_buckets 6 34484 NULL
110073 +security_inode_permission_34488 security_inode_permission 0 34488 NULL
110074 +SyS_pwritev_34494 SyS_pwritev 3 34494 NULL
110075 +qp_alloc_res_34496 qp_alloc_res 5 34496 NULL
110076 +lu_buf_check_and_alloc_34505 lu_buf_check_and_alloc 2 34505 NULL
110077 +ext4_fallocate_34537 ext4_fallocate 4-3 34537 NULL nohasharray
110078 +tracing_stats_read_34537 tracing_stats_read 3 34537 &ext4_fallocate_34537
110079 +hugetlbfs_read_actor_34547 hugetlbfs_read_actor 2-5-4-0 34547 NULL
110080 +dbBackSplit_34561 dbBackSplit 0 34561 NULL
110081 +alloc_ieee80211_rsl_34564 alloc_ieee80211_rsl 1 34564 NULL
110082 +lov_stripecount_seq_write_34582 lov_stripecount_seq_write 3 34582 NULL
110083 +init_send_hfcd_34586 init_send_hfcd 1 34586 NULL
110084 +inet6_ifla6_size_34591 inet6_ifla6_size 0 34591 NULL
110085 +ceph_msgpool_init_34599 ceph_msgpool_init 4 34599 NULL nohasharray
110086 +cw1200_queue_init_34599 cw1200_queue_init 4 34599 &ceph_msgpool_init_34599
110087 +brcmf_cfg80211_mgmt_tx_34608 brcmf_cfg80211_mgmt_tx 7 34608 NULL
110088 +__jffs2_ref_totlen_34609 __jffs2_ref_totlen 0 34609 NULL
110089 +apei_get_nvs_resources_34616 apei_get_nvs_resources 0 34616 NULL
110090 +__cfg80211_disconnected_34622 __cfg80211_disconnected 3 34622 NULL
110091 +cnic_alloc_dma_34641 cnic_alloc_dma 3 34641 NULL
110092 +kvm_set_spte_hva_34671 kvm_set_spte_hva 2 34671 NULL
110093 +sleep_auth_write_34676 sleep_auth_write 3 34676 NULL
110094 +isr_fiqs_read_34687 isr_fiqs_read 3 34687 NULL
110095 +batadv_tvlv_realloc_packet_buff_34688 batadv_tvlv_realloc_packet_buff 3-4 34688 NULL
110096 +port_print_34704 port_print 3 34704 NULL
110097 +ieee80211_if_read_num_sta_ps_34722 ieee80211_if_read_num_sta_ps 3 34722 NULL
110098 +platform_list_read_file_34734 platform_list_read_file 3 34734 NULL
110099 +reg_w_ixbuf_34736 reg_w_ixbuf 4 34736 NULL
110100 +lsm_alloc_plain_34755 lsm_alloc_plain 1 34755 NULL
110101 +bootmode_store_34762 bootmode_store 4 34762 NULL
110102 +device_add_34766 device_add 0 34766 NULL
110103 +qib_cdev_init_34778 qib_cdev_init 1 34778 NULL
110104 +SYSC_keyctl_34800 SYSC_keyctl 4 34800 NULL
110105 +can_nocow_extent_34801 can_nocow_extent 2 34801 NULL
110106 +drbd_get_max_capacity_34804 drbd_get_max_capacity 0 34804 NULL
110107 +ll_setxattr_34806 ll_setxattr 4 34806 NULL
110108 +file_page_index_34820 file_page_index 0-2 34820 NULL
110109 +b43_debugfs_write_34838 b43_debugfs_write 3 34838 NULL
110110 +nl_portid_hash_zalloc_34843 nl_portid_hash_zalloc 1 34843 NULL
110111 +acpi_system_write_wakeup_device_34853 acpi_system_write_wakeup_device 3 34853 NULL
110112 +usb_serial_generic_prepare_write_buffer_34857 usb_serial_generic_prepare_write_buffer 3 34857 NULL
110113 +ieee80211_if_read_txpower_34871 ieee80211_if_read_txpower 3 34871 NULL
110114 +msg_print_text_34889 msg_print_text 0 34889 NULL
110115 +ieee80211_if_write_34894 ieee80211_if_write 3 34894 NULL
110116 +si476x_radio_read_rsq_primary_blob_34916 si476x_radio_read_rsq_primary_blob 3 34916 NULL
110117 +__inode_permission_34925 __inode_permission 0 34925 NULL nohasharray
110118 +btrfs_super_chunk_root_34925 btrfs_super_chunk_root 0 34925 &__inode_permission_34925
110119 +ceph_aio_write_34930 ceph_aio_write 4 34930 NULL
110120 +sec_flags2str_34933 sec_flags2str 3 34933 NULL
110121 +snd_info_entry_read_34938 snd_info_entry_read 3 34938 NULL
110122 +i2c_transfer_34958 i2c_transfer 0 34958 NULL
110123 +do_add_page_to_bio_34974 do_add_page_to_bio 2-10 34974 NULL
110124 +rx_rx_hdr_overflow_read_35002 rx_rx_hdr_overflow_read 3 35002 NULL
110125 +l2cap_skbuff_fromiovec_35003 l2cap_skbuff_fromiovec 4-3 35003 NULL
110126 +sisusb_copy_memory_35016 sisusb_copy_memory 4 35016 NULL
110127 +coda_psdev_read_35029 coda_psdev_read 3 35029 NULL
110128 +brcmf_sdio_chip_writenvram_35042 brcmf_sdio_chip_writenvram 4 35042 NULL
110129 +pwr_connection_out_of_sync_read_35061 pwr_connection_out_of_sync_read 3 35061 NULL
110130 +__kfifo_uint_must_check_helper_35097 __kfifo_uint_must_check_helper 0-1 35097 NULL
110131 +capi_write_35104 capi_write 3 35104 NULL nohasharray
110132 +tx_tx_done_template_read_35104 tx_tx_done_template_read 3 35104 &capi_write_35104
110133 +ide_settings_proc_write_35110 ide_settings_proc_write 3 35110 NULL
110134 +ceph_osdc_start_request_35122 ceph_osdc_start_request 0 35122 NULL
110135 +message_stats_print_35158 message_stats_print 6 35158 NULL
110136 +iscsi_conn_setup_35159 iscsi_conn_setup 2 35159 NULL
110137 +ieee80211_if_read_bssid_35161 ieee80211_if_read_bssid 3 35161 NULL
110138 +unix_stream_recvmsg_35210 unix_stream_recvmsg 4 35210 NULL
110139 +security_key_getsecurity_35218 security_key_getsecurity 0 35218 NULL nohasharray
110140 +striped_read_35218 striped_read 0-2 35218 &security_key_getsecurity_35218
110141 +rx_rx_cmplt_task_read_35226 rx_rx_cmplt_task_read 3 35226 NULL
110142 +set_fd_set_35249 set_fd_set 1 35249 NULL
110143 +ioapic_setup_resources_35255 ioapic_setup_resources 1 35255 NULL
110144 +jbd2_journal_get_write_access_35263 jbd2_journal_get_write_access 0 35263 NULL
110145 +dis_disc_write_35265 dis_disc_write 3 35265 NULL
110146 +dma_show_regs_35266 dma_show_regs 3 35266 NULL
110147 +irda_recvmsg_stream_35280 irda_recvmsg_stream 4 35280 NULL
110148 +i2o_block_end_request_35282 i2o_block_end_request 3 35282 NULL
110149 +isr_rx_rdys_read_35283 isr_rx_rdys_read 3 35283 NULL
110150 +__btrfs_buffered_write_35311 __btrfs_buffered_write 3 35311 NULL nohasharray
110151 +brcmf_sdio_forensic_read_35311 brcmf_sdio_forensic_read 3 35311 &__btrfs_buffered_write_35311
110152 +tracing_read_pipe_35312 tracing_read_pipe 3 35312 NULL
110153 +ieee80211_if_fmt_ap_power_level_35347 ieee80211_if_fmt_ap_power_level 3 35347 NULL
110154 +nouveau_devinit_create__35348 nouveau_devinit_create_ 4 35348 NULL
110155 +ieee80211_rx_mgmt_deauth_35351 ieee80211_rx_mgmt_deauth 3 35351 NULL
110156 +compat_filldir64_35354 compat_filldir64 3 35354 NULL
110157 +read_kmem_35372 read_kmem 3 35372 NULL
110158 +SyS_getxattr_35408 SyS_getxattr 4 35408 NULL
110159 +rawv6_send_hdrinc_35425 rawv6_send_hdrinc 3 35425 NULL
110160 +buffer_to_user_35439 buffer_to_user 3 35439 NULL
110161 +fiemap_prepare_and_copy_exts_35494 fiemap_prepare_and_copy_exts 5 35494 NULL
110162 +btrfs_prealloc_file_range_trans_35500 btrfs_prealloc_file_range_trans 4 35500 NULL
110163 +async_setkey_35521 async_setkey 3 35521 NULL
110164 +__filemap_fdatawrite_range_35528 __filemap_fdatawrite_range 0 35528 NULL
110165 +iwl_dbgfs_bt_traffic_read_35534 iwl_dbgfs_bt_traffic_read 3 35534 NULL
110166 +pstore_mkfile_35536 pstore_mkfile 7 35536 NULL
110167 +rxpipe_tx_xfr_host_int_trig_rx_data_read_35538 rxpipe_tx_xfr_host_int_trig_rx_data_read 3 35538 NULL
110168 +ibnl_put_attr_35541 ibnl_put_attr 3 35541 NULL
110169 +ieee80211_if_write_smps_35550 ieee80211_if_write_smps 3 35550 NULL
110170 +sysfs_create_subdir_35567 sysfs_create_subdir 0 35567 NULL
110171 +ext4_blocks_for_truncate_35579 ext4_blocks_for_truncate 0 35579 NULL
110172 +ext2_acl_from_disk_35580 ext2_acl_from_disk 2 35580 NULL
110173 +spk_msg_set_35586 spk_msg_set 3 35586 NULL
110174 +kernel_readv_35617 kernel_readv 3 35617 NULL
110175 +reiserfs_readpages_35629 reiserfs_readpages 4 35629 NULL
110176 +pci_request_regions_35635 pci_request_regions 0 35635 NULL
110177 +ptlrpcd_steal_rqset_35637 ptlrpcd_steal_rqset 0 35637 NULL
110178 +spi_register_board_info_35651 spi_register_board_info 2 35651 NULL
110179 +rdmaltWithLock_35669 rdmaltWithLock 0 35669 NULL
110180 +compat_sys_kexec_load_35674 compat_sys_kexec_load 2 35674 NULL
110181 +SYSC_pwritev_35690 SYSC_pwritev 3 35690 NULL
110182 +rds_page_copy_user_35691 rds_page_copy_user 4 35691 NULL
110183 +md_super_write_35703 md_super_write 4 35703 NULL
110184 +ocfs2_extent_recs_per_gd_35710 ocfs2_extent_recs_per_gd 0 35710 NULL
110185 +iwl_dbgfs_disable_ht40_read_35761 iwl_dbgfs_disable_ht40_read 3 35761 NULL
110186 +udf_alloc_i_data_35786 udf_alloc_i_data 2 35786 NULL
110187 +pvr2_hdw_cpufw_get_35824 pvr2_hdw_cpufw_get 0-4-2 35824 NULL
110188 +tx_tx_cmplt_read_35854 tx_tx_cmplt_read 3 35854 NULL
110189 +vx_query_hbuffer_size_35859 vx_query_hbuffer_size 0 35859 NULL
110190 +mthca_buf_alloc_35861 mthca_buf_alloc 2 35861 NULL
110191 +fls64_35862 fls64 0 35862 NULL
110192 +kvm_dirty_bitmap_bytes_35886 kvm_dirty_bitmap_bytes 0 35886 NULL
110193 +ieee80211_if_fmt_dot11MeshRetryTimeout_35890 ieee80211_if_fmt_dot11MeshRetryTimeout 3 35890 NULL
110194 +uwb_rc_cmd_done_35892 uwb_rc_cmd_done 4 35892 NULL
110195 +SyS_set_mempolicy_35909 SyS_set_mempolicy 3 35909 NULL
110196 +kernel_setsockopt_35913 kernel_setsockopt 5 35913 NULL
110197 +rbio_nr_pages_35916 rbio_nr_pages 0-1-2 35916 NULL
110198 +sctp_tsnmap_mark_35929 sctp_tsnmap_mark 2 35929 NULL
110199 +rx_defrag_init_called_read_35935 rx_defrag_init_called_read 3 35935 NULL
110200 +put_cmsg_compat_35937 put_cmsg_compat 4 35937 NULL
110201 +ext_rts51x_sd_execute_write_data_35971 ext_rts51x_sd_execute_write_data 9 35971 NULL
110202 +ceph_buffer_new_35974 ceph_buffer_new 1 35974 NULL nohasharray
110203 +generic_ocp_read_35974 generic_ocp_read 3 35974 &ceph_buffer_new_35974
110204 +acl_alloc_35979 acl_alloc 1 35979 NULL
110205 +device_add_class_symlinks_35985 device_add_class_symlinks 0 35985 NULL
110206 +generic_file_aio_read_35987 generic_file_aio_read 0 35987 NULL
110207 +write_file_antenna_35998 write_file_antenna 3 35998 NULL nohasharray
110208 +kuc_alloc_35998 kuc_alloc 1 35998 &write_file_antenna_35998
110209 +il3945_ucode_tx_stats_read_36016 il3945_ucode_tx_stats_read 3 36016 NULL
110210 +__videobuf_alloc_36031 __videobuf_alloc 1 36031 NULL
110211 +account_shadowed_36048 account_shadowed 2 36048 NULL
110212 +gpio_power_read_36059 gpio_power_read 3 36059 NULL
110213 +write_emulate_36065 write_emulate 2-4 36065 NULL
110214 +stack_max_size_write_36068 stack_max_size_write 3 36068 NULL
110215 +radeon_vm_num_pdes_36070 radeon_vm_num_pdes 0 36070 NULL
110216 +ieee80211_if_fmt_peer_36071 ieee80211_if_fmt_peer 3 36071 NULL
110217 +ieee80211_if_write_tsf_36077 ieee80211_if_write_tsf 3 36077 NULL
110218 +snd_pcm_plug_read_transfer_36080 snd_pcm_plug_read_transfer 0-3 36080 NULL
110219 +mtip_hw_read_device_status_36082 mtip_hw_read_device_status 3 36082 NULL
110220 +vga_arb_write_36112 vga_arb_write 3 36112 NULL
110221 +simple_xattr_alloc_36118 simple_xattr_alloc 2 36118 NULL
110222 +ext3_readpages_36144 ext3_readpages 4 36144 NULL
110223 +twl_set_36154 twl_set 2 36154 NULL
110224 +b1_alloc_card_36155 b1_alloc_card 1 36155 NULL
110225 +btrfs_file_extent_inline_len_36158 btrfs_file_extent_inline_len 0 36158 NULL
110226 +snd_korg1212_copy_from_36169 snd_korg1212_copy_from 6 36169 NULL
110227 +SyS_kexec_load_36176 SyS_kexec_load 2 36176 NULL
110228 +ramoops_init_przs_36199 ramoops_init_przs 4 36199 NULL
110229 +SYSC_sched_getaffinity_36208 SYSC_sched_getaffinity 2 36208 NULL
110230 +SYSC_process_vm_readv_36216 SYSC_process_vm_readv 3-5 36216 NULL
110231 +atomic_stats_read_36228 atomic_stats_read 3 36228 NULL
110232 +viafb_iga1_odev_proc_write_36241 viafb_iga1_odev_proc_write 3 36241 NULL
110233 +SYSC_getxattr_36242 SYSC_getxattr 4 36242 NULL
110234 +rproc_recovery_read_36245 rproc_recovery_read 3 36245 NULL
110235 +scrub_stripe_36248 scrub_stripe 5-4 36248 NULL
110236 +compat_sys_mbind_36256 compat_sys_mbind 5 36256 NULL
110237 +usb_buffer_alloc_36276 usb_buffer_alloc 2 36276 NULL nohasharray
110238 +cfs_hash_buckets_realloc_36276 cfs_hash_buckets_realloc 4 36276 &usb_buffer_alloc_36276
110239 +codec_reg_read_file_36280 codec_reg_read_file 3 36280 NULL
110240 +crypto_shash_digestsize_36284 crypto_shash_digestsize 0 36284 NULL
110241 +nouveau_cli_create_36293 nouveau_cli_create 3 36293 NULL
110242 +lpfc_debugfs_dif_err_read_36303 lpfc_debugfs_dif_err_read 3 36303 NULL
110243 +cfg80211_rx_mlme_mgmt_36306 cfg80211_rx_mlme_mgmt 3 36306 NULL
110244 +ad7879_spi_xfer_36311 ad7879_spi_xfer 3 36311 NULL
110245 +fat_compat_ioctl_filldir_36328 fat_compat_ioctl_filldir 3 36328 NULL
110246 +lc_create_36332 lc_create 4 36332 NULL
110247 +jbd2_journal_init_revoke_table_36336 jbd2_journal_init_revoke_table 1 36336 NULL
110248 +isku_sysfs_read_key_mask_36343 isku_sysfs_read_key_mask 6 36343 NULL
110249 +ath6kl_regwrite_write_36351 ath6kl_regwrite_write 3 36351 NULL
110250 +v9fs_file_readn_36353 v9fs_file_readn 4 36353 NULL
110251 +to_sector_36361 to_sector 0-1 36361 NULL
110252 +tunables_read_36385 tunables_read 3 36385 NULL
110253 +afs_alloc_flat_call_36399 afs_alloc_flat_call 2-3 36399 NULL
110254 +sierra_write_36402 sierra_write 4 36402 NULL
110255 +iwl_dbgfs_d3_sram_write_36403 iwl_dbgfs_d3_sram_write 3 36403 NULL
110256 +SyS_sethostname_36417 SyS_sethostname 2 36417 NULL
110257 +ReadW6692B_36445 ReadW6692B 0 36445 NULL
110258 +sctp_tsnmap_init_36446 sctp_tsnmap_init 2 36446 NULL
110259 +alloc_etherdev_mqs_36450 alloc_etherdev_mqs 1 36450 NULL
110260 +SyS_process_vm_writev_36476 SyS_process_vm_writev 3-5 36476 NULL
110261 +b43_nphy_load_samples_36481 b43_nphy_load_samples 3 36481 NULL
110262 +tx_tx_checksum_result_read_36490 tx_tx_checksum_result_read 3 36490 NULL nohasharray
110263 +ip6_append_data_36490 ip6_append_data 4 36490 &tx_tx_checksum_result_read_36490
110264 +cmd_loop_36491 cmd_loop 0 36491 NULL
110265 +__hwahc_op_set_ptk_36510 __hwahc_op_set_ptk 5 36510 NULL
110266 +mcam_v4l_read_36513 mcam_v4l_read 3 36513 NULL
110267 +get_param_l_36518 get_param_l 0 36518 NULL
110268 +ieee80211_if_read_fwded_frames_36520 ieee80211_if_read_fwded_frames 3 36520 NULL
110269 +crypto_aead_authsize_36537 crypto_aead_authsize 0 36537 NULL
110270 +cpu_type_read_36540 cpu_type_read 3 36540 NULL
110271 +__kfifo_to_user_36555 __kfifo_to_user 3-0 36555 NULL nohasharray
110272 +macvtap_do_read_36555 macvtap_do_read 4 36555 &__kfifo_to_user_36555
110273 +btrfs_get_token_64_36572 btrfs_get_token_64 0 36572 NULL
110274 +__erst_read_36579 __erst_read 0 36579 NULL
110275 +put_cmsg_36589 put_cmsg 4 36589 NULL
110276 +fat_ioctl_filldir_36621 fat_ioctl_filldir 3 36621 NULL
110277 +vxge_config_vpaths_36636 vxge_config_vpaths 0 36636 NULL
110278 +convert_extent_item_v0_36645 convert_extent_item_v0 4 36645 NULL
110279 +ced_ioctl_36647 ced_ioctl 2 36647 NULL
110280 +lpfc_idiag_extacc_alloc_get_36648 lpfc_idiag_extacc_alloc_get 0-3 36648 NULL
110281 +osd_req_list_collection_objects_36664 osd_req_list_collection_objects 5 36664 NULL
110282 +iscsi_host_alloc_36671 iscsi_host_alloc 2 36671 NULL
110283 +xillybus_read_36678 xillybus_read 3 36678 NULL
110284 +gsmtty_write_36702 gsmtty_write 3 36702 NULL
110285 +snd_rawmidi_kernel_read1_36740 snd_rawmidi_kernel_read1 4-0 36740 NULL
110286 +cxgbi_device_register_36746 cxgbi_device_register 1-2 36746 NULL
110287 +ps_poll_upsd_timeouts_read_36755 ps_poll_upsd_timeouts_read 3 36755 NULL
110288 +ptp_filter_init_36780 ptp_filter_init 2 36780 NULL
110289 +i40e_init_lan_hmc_36796 i40e_init_lan_hmc 2-3-4-5 36796 NULL
110290 +proc_fault_inject_read_36802 proc_fault_inject_read 3 36802 NULL
110291 +hiddev_ioctl_36816 hiddev_ioctl 2 36816 NULL
110292 +int_hardware_entry_36833 int_hardware_entry 3 36833 NULL
110293 +fc_change_queue_depth_36841 fc_change_queue_depth 2 36841 NULL
110294 +keyctl_describe_key_36853 keyctl_describe_key 3 36853 NULL
110295 +cm_write_36858 cm_write 3 36858 NULL
110296 +tx_tx_data_programmed_read_36871 tx_tx_data_programmed_read 3 36871 NULL
110297 +svc_setsockopt_36876 svc_setsockopt 5 36876 NULL
110298 +raid56_parity_write_36877 raid56_parity_write 5 36877 NULL
110299 +__btrfs_map_block_36883 __btrfs_map_block 3 36883 NULL
110300 +ib_ucm_alloc_data_36885 ib_ucm_alloc_data 3 36885 NULL
110301 +selinux_inode_notifysecctx_36896 selinux_inode_notifysecctx 3 36896 NULL
110302 +OS_kmalloc_36909 OS_kmalloc 1 36909 NULL
110303 +audio_set_endpoint_req_36918 audio_set_endpoint_req 0 36918 NULL
110304 +crypto_blkcipher_ivsize_36944 crypto_blkcipher_ivsize 0 36944 NULL
110305 +il4965_rs_sta_dbgfs_scale_table_write_36979 il4965_rs_sta_dbgfs_scale_table_write 3 36979 NULL
110306 +drbd_new_dev_size_36998 drbd_new_dev_size 0-3 36998 NULL
110307 +auok190xfb_write_37001 auok190xfb_write 3 37001 NULL
110308 +setxattr_37006 setxattr 4 37006 NULL
110309 +ocfs2_dlm_unlock_37037 ocfs2_dlm_unlock 0 37037 NULL
110310 +command_file_read_37038 command_file_read 3 37038 NULL
110311 +figure_loop_size_37051 figure_loop_size 2-3 37051 NULL
110312 +ieee80211_if_read_drop_unencrypted_37053 ieee80211_if_read_drop_unencrypted 3 37053 NULL nohasharray
110313 +qp_broker_create_37053 qp_broker_create 6-5 37053 &ieee80211_if_read_drop_unencrypted_37053
110314 +SYSC_setxattr_37078 SYSC_setxattr 4 37078 NULL
110315 +parse_command_37079 parse_command 2 37079 NULL
110316 +pipeline_cs_rx_packet_in_read_37089 pipeline_cs_rx_packet_in_read 3 37089 NULL
110317 +tun_get_user_37094 tun_get_user 5 37094 NULL
110318 +has_wrprotected_page_37123 has_wrprotected_page 3-2 37123 NULL
110319 +snd_hda_get_conn_list_37132 snd_hda_get_conn_list 0 37132 NULL
110320 +mtt_free_res_37144 mtt_free_res 5 37144 NULL
110321 +msg_word_37164 msg_word 0 37164 NULL
110322 +f2fs_direct_IO_37167 f2fs_direct_IO 4 37167 NULL
110323 +can_set_xattr_37182 can_set_xattr 4 37182 NULL
110324 +vcc_recvmsg_37198 vcc_recvmsg 4 37198 NULL
110325 +sysfs_add_file_37200 sysfs_add_file 0 37200 NULL
110326 +forced_ps_write_37209 forced_ps_write 3 37209 NULL
110327 +crypto_shash_descsize_37212 crypto_shash_descsize 0 37212 NULL nohasharray
110328 +ext4_ind_direct_IO_37212 ext4_ind_direct_IO 0-4 37212 &crypto_shash_descsize_37212
110329 +bchannel_get_rxbuf_37213 bchannel_get_rxbuf 2-0 37213 NULL
110330 +regmap_access_read_file_37223 regmap_access_read_file 3 37223 NULL
110331 +__do_replace_37227 __do_replace 5 37227 NULL
110332 +iwl_dbgfs_d3_sram_read_37237 iwl_dbgfs_d3_sram_read 3 37237 NULL
110333 +rx_filter_dup_filter_read_37238 rx_filter_dup_filter_read 3 37238 NULL
110334 +exofs_max_io_pages_37263 exofs_max_io_pages 0-2 37263 NULL
110335 +ieee80211_if_read_power_mode_37305 ieee80211_if_read_power_mode 3 37305 NULL
110336 +ext3_direct_IO_37308 ext3_direct_IO 4 37308 NULL
110337 +ocfs2_calc_extend_credits_37310 ocfs2_calc_extend_credits 0 37310 NULL
110338 +jffs2_write_dirent_37311 jffs2_write_dirent 5 37311 NULL
110339 +send_msg_37323 send_msg 4 37323 NULL
110340 +l2cap_create_connless_pdu_37327 l2cap_create_connless_pdu 3 37327 NULL nohasharray
110341 +bnx2x_vf_fill_fw_str_37327 bnx2x_vf_fill_fw_str 3 37327 &l2cap_create_connless_pdu_37327
110342 +scsi_mode_select_37330 scsi_mode_select 6 37330 NULL
110343 +rxrpc_server_sendmsg_37331 rxrpc_server_sendmsg 4 37331 NULL
110344 +security_inode_getsecurity_37354 security_inode_getsecurity 0 37354 NULL
110345 +hci_sock_sendmsg_37420 hci_sock_sendmsg 4 37420 NULL
110346 +acpi_os_allocate_zeroed_37422 acpi_os_allocate_zeroed 1 37422 NULL
110347 +tty_insert_flip_string_fixed_flag_37428 tty_insert_flip_string_fixed_flag 4-0 37428 NULL
110348 +iwl_print_last_event_logs_37433 iwl_print_last_event_logs 7-9-0 37433 NULL
110349 +fru_alloc_37442 fru_alloc 1 37442 NULL
110350 +tcp_established_options_37450 tcp_established_options 0 37450 NULL nohasharray
110351 +tipc_send2port_37450 tipc_send2port 4 37450 &tcp_established_options_37450
110352 +brcmf_sdio_dump_console_37455 brcmf_sdio_dump_console 4 37455 NULL
110353 +get_est_timing_37484 get_est_timing 0 37484 NULL
110354 +kmem_realloc_37489 kmem_realloc 2 37489 NULL
110355 +__hfsplus_setxattr_37499 __hfsplus_setxattr 4 37499 NULL
110356 +bitmap_dirty_bits_37503 bitmap_dirty_bits 2 37503 NULL
110357 +osc_active_seq_write_37514 osc_active_seq_write 3 37514 NULL
110358 +bdev_writeseg_37519 bdev_writeseg 2-3 37519 NULL
110359 +xz_dec_test_write_37527 xz_dec_test_write 3 37527 NULL
110360 +fault_inject_read_37534 fault_inject_read 3 37534 NULL
110361 +hdr_size_37536 hdr_size 0 37536 NULL
110362 +extent_map_end_37550 extent_map_end 0 37550 NULL
110363 +sep_create_dcb_dmatables_context_37551 sep_create_dcb_dmatables_context 6 37551 NULL
110364 +ioat_chansts_37558 ioat_chansts 0 37558 NULL
110365 +xhci_alloc_streams_37586 xhci_alloc_streams 5 37586 NULL
110366 +qla2x00_debounce_register_37597 qla2x00_debounce_register 0 37597 NULL
110367 +kvm_read_guest_page_mmu_37611 kvm_read_guest_page_mmu 6 37611 NULL
110368 +SYSC_mbind_37622 SYSC_mbind 5 37622 NULL
110369 +SyS_mbind_37638 SyS_mbind 5 37638 NULL
110370 +bio_copy_user_iov_37660 bio_copy_user_iov 4 37660 NULL
110371 +rfcomm_sock_sendmsg_37661 rfcomm_sock_sendmsg 4 37661 NULL nohasharray
110372 +vmw_framebuffer_dmabuf_dirty_37661 vmw_framebuffer_dmabuf_dirty 6 37661 &rfcomm_sock_sendmsg_37661
110373 +SYSC_get_mempolicy_37664 SYSC_get_mempolicy 3 37664 NULL
110374 +__wa_seg_calculate_isoc_frame_count_37672 __wa_seg_calculate_isoc_frame_count 0 37672 NULL
110375 +ieee80211_if_read_rc_rateidx_mcs_mask_2ghz_37675 ieee80211_if_read_rc_rateidx_mcs_mask_2ghz 3 37675 NULL
110376 +regmap_map_read_file_37685 regmap_map_read_file 3 37685 NULL
110377 +page_chain_free_37697 page_chain_free 0 37697 NULL
110378 +nametbl_header_37698 nametbl_header 2-0 37698 NULL
110379 +__le32_to_cpup_37702 __le32_to_cpup 0 37702 NULL
110380 +dynamic_ps_timeout_write_37713 dynamic_ps_timeout_write 3 37713 NULL
110381 +read_enabled_file_bool_37744 read_enabled_file_bool 3 37744 NULL
110382 +ocfs2_control_cfu_37750 ocfs2_control_cfu 2 37750 NULL
110383 +ipath_cdev_init_37752 ipath_cdev_init 1 37752 NULL
110384 +dccp_setsockopt_cscov_37766 dccp_setsockopt_cscov 2 37766 NULL
110385 +il4965_rs_sta_dbgfs_rate_scale_data_read_37792 il4965_rs_sta_dbgfs_rate_scale_data_read 3 37792 NULL
110386 +smk_read_logging_37804 smk_read_logging 3 37804 NULL
110387 +ocrdma_alloc_frmr_page_list_37815 ocrdma_alloc_frmr_page_list 2 37815 NULL
110388 +rx_decrypt_key_not_found_read_37820 rx_decrypt_key_not_found_read 3 37820 NULL
110389 +android_get_p2p_addr_37832 android_get_p2p_addr 0 37832 NULL
110390 +jbd2_journal_get_undo_access_37837 jbd2_journal_get_undo_access 0 37837 NULL
110391 +o2hb_debug_read_37851 o2hb_debug_read 3 37851 NULL
110392 +xfs_dir2_block_to_sf_37868 xfs_dir2_block_to_sf 3 37868 NULL
110393 +set_registers_37883 set_registers 4 37883 NULL
110394 +btrfs_stack_file_extent_disk_bytenr_37888 btrfs_stack_file_extent_disk_bytenr 0 37888 NULL
110395 +pkt_alloc_packet_data_37928 pkt_alloc_packet_data 1 37928 NULL nohasharray
110396 +_rtw_malloc_37928 _rtw_malloc 1 37928 &pkt_alloc_packet_data_37928
110397 +read_rbu_packet_size_37939 read_rbu_packet_size 6 37939 NULL
110398 +write_file_bool_37957 write_file_bool 3 37957 NULL
110399 +fifo_alloc_37961 fifo_alloc 1 37961 NULL
110400 +rds_rdma_extra_size_37990 rds_rdma_extra_size 0 37990 NULL
110401 +persistent_ram_old_size_37997 persistent_ram_old_size 0 37997 NULL
110402 +vfs_readv_38011 vfs_readv 3 38011 NULL
110403 +aggr_recv_addba_req_evt_38037 aggr_recv_addba_req_evt 4 38037 NULL
110404 +il_dbgfs_chain_noise_read_38044 il_dbgfs_chain_noise_read 3 38044 NULL nohasharray
110405 +klsi_105_prepare_write_buffer_38044 klsi_105_prepare_write_buffer 3 38044 &il_dbgfs_chain_noise_read_38044
110406 +SyS_llistxattr_38048 SyS_llistxattr 3 38048 NULL
110407 +sysfs_do_create_link_38051 sysfs_do_create_link 0 38051 NULL
110408 +_xfs_buf_alloc_38058 _xfs_buf_alloc 3 38058 NULL
110409 +nsm_create_handle_38060 nsm_create_handle 4 38060 NULL
110410 +alloc_ltalkdev_38071 alloc_ltalkdev 1 38071 NULL
110411 +xfs_buf_readahead_map_38081 xfs_buf_readahead_map 3 38081 NULL nohasharray
110412 +wcn36xx_smd_rsp_process_38081 wcn36xx_smd_rsp_process 3 38081 &xfs_buf_readahead_map_38081
110413 +uwb_mac_addr_print_38085 uwb_mac_addr_print 2 38085 NULL
110414 +request_key_auth_new_38092 request_key_auth_new 3 38092 NULL
110415 +proc_self_readlink_38094 proc_self_readlink 3 38094 NULL
110416 +ep0_read_38095 ep0_read 3 38095 NULL
110417 +sk_wmem_schedule_38096 sk_wmem_schedule 2 38096 NULL nohasharray
110418 +osc_checksum_seq_write_38096 osc_checksum_seq_write 3 38096 &sk_wmem_schedule_38096
110419 +o2hb_read_slots_38105 o2hb_read_slots 2 38105 NULL
110420 +snd_pcm_oss_write_38108 snd_pcm_oss_write 3 38108 NULL
110421 +vmw_kms_present_38130 vmw_kms_present 9 38130 NULL
110422 +__ntfs_copy_from_user_iovec_inatomic_38153 __ntfs_copy_from_user_iovec_inatomic 0-4-3 38153 NULL
110423 +btrfs_extent_same_38163 btrfs_extent_same 3-2 38163 NULL
110424 +kvm_clear_guest_38164 kvm_clear_guest 3-2 38164 NULL
110425 +cdev_add_38176 cdev_add 2-3 38176 NULL
110426 +rt2x00debug_write_rf_38195 rt2x00debug_write_rf 3 38195 NULL
110427 +get_ucode_user_38202 get_ucode_user 3 38202 NULL
110428 +osd_req_list_partition_collections_38223 osd_req_list_partition_collections 5 38223 NULL
110429 +ceph_decode_16_38239 ceph_decode_16 0 38239 NULL
110430 +_ipw_read_reg32_38245 _ipw_read_reg32 0 38245 NULL
110431 +mthca_alloc_icm_table_38268 mthca_alloc_icm_table 4-3 38268 NULL nohasharray
110432 +ieee80211_if_read_auto_open_plinks_38268 ieee80211_if_read_auto_open_plinks 3 38268 &mthca_alloc_icm_table_38268 nohasharray
110433 +SYSC_msgrcv_38268 SYSC_msgrcv 3 38268 &ieee80211_if_read_auto_open_plinks_38268
110434 +xfs_bmbt_to_bmdr_38275 xfs_bmbt_to_bmdr 3 38275 NULL nohasharray
110435 +xfs_bmdr_to_bmbt_38275 xfs_bmdr_to_bmbt 5 38275 &xfs_bmbt_to_bmdr_38275
110436 +ftdi_process_packet_38281 ftdi_process_packet 4 38281 NULL
110437 +ucma_query_path_38305 ucma_query_path 3 38305 NULL
110438 +isr_rx_headers_read_38325 isr_rx_headers_read 3 38325 NULL
110439 +ida_simple_get_38326 ida_simple_get 0 38326 NULL
110440 +__snd_gf1_look8_38333 __snd_gf1_look8 0 38333 NULL
110441 +btrfs_file_extent_disk_num_bytes_38363 btrfs_file_extent_disk_num_bytes 0 38363 NULL
110442 +xfs_free_file_space_38383 xfs_free_file_space 2-3 38383 NULL
110443 +dn_sendmsg_38390 dn_sendmsg 4 38390 NULL
110444 +ieee80211_if_read_dtim_count_38419 ieee80211_if_read_dtim_count 3 38419 NULL
110445 +pmcraid_copy_sglist_38431 pmcraid_copy_sglist 3 38431 NULL
110446 +kvm_write_guest_38454 kvm_write_guest 4-2 38454 NULL
110447 +blk_end_bidi_request_38482 blk_end_bidi_request 3-4 38482 NULL
110448 +dev_names_read_38509 dev_names_read 3 38509 NULL
110449 +iscsi_create_iface_38510 iscsi_create_iface 5 38510 NULL
110450 +event_rx_mismatch_read_38518 event_rx_mismatch_read 3 38518 NULL
110451 +ubifs_idx_node_sz_38546 ubifs_idx_node_sz 0-2 38546 NULL
110452 +btrfs_discard_extent_38547 btrfs_discard_extent 2 38547 NULL
110453 +kuc_len_38557 kuc_len 0-1 38557 NULL
110454 +irda_sendmsg_dgram_38563 irda_sendmsg_dgram 4 38563 NULL
110455 +il4965_rs_sta_dbgfs_scale_table_read_38564 il4965_rs_sta_dbgfs_scale_table_read 3 38564 NULL
110456 +_ipw_read32_38565 _ipw_read32 0 38565 NULL
110457 +snd_nm256_playback_copy_38567 snd_nm256_playback_copy 5-3 38567 NULL
110458 +copy_ctl_value_to_user_38587 copy_ctl_value_to_user 4 38587 NULL
110459 +icn_writecmd_38629 icn_writecmd 2 38629 NULL
110460 +write_enabled_file_bool_38630 write_enabled_file_bool 3 38630 NULL
110461 +ext2_readpages_38640 ext2_readpages 4 38640 NULL
110462 +audit_init_entry_38644 audit_init_entry 1 38644 NULL
110463 +qp_broker_alloc_38646 qp_broker_alloc 6-5 38646 NULL
110464 +mmc_send_cxd_data_38655 mmc_send_cxd_data 5 38655 NULL
110465 +nouveau_instmem_create__38664 nouveau_instmem_create_ 4 38664 NULL
110466 +snd_es1371_wait_src_ready_38673 snd_es1371_wait_src_ready 0 38673 NULL
110467 +iscsit_dump_data_payload_38683 iscsit_dump_data_payload 2 38683 NULL
110468 +rbio_add_io_page_38700 rbio_add_io_page 6 38700 NULL
110469 +alloc_trace_probe_38720 alloc_trace_probe 6 38720 NULL
110470 +w83977af_sir_interrupt_38738 w83977af_sir_interrupt 0 38738 NULL
110471 +udf_readpages_38761 udf_readpages 4 38761 NULL
110472 +iwl_dbgfs_thermal_throttling_read_38779 iwl_dbgfs_thermal_throttling_read 3 38779 NULL
110473 +bcache_device_init_38781 bcache_device_init 3 38781 NULL
110474 +snd_gus_dram_write_38784 snd_gus_dram_write 4 38784 NULL
110475 +slab_order_38794 slab_order 0 38794 NULL
110476 +do_pci_enable_device_38802 do_pci_enable_device 0 38802 NULL
110477 +err_decode_38804 err_decode 2 38804 NULL
110478 +ipv6_renew_option_38813 ipv6_renew_option 3 38813 NULL
110479 +direct_entry_38836 direct_entry 3 38836 NULL
110480 +compat_udp_setsockopt_38840 compat_udp_setsockopt 5 38840 NULL
110481 +read_nic_io_word_38853 read_nic_io_word 0 38853 NULL
110482 +interfaces_38859 interfaces 2 38859 NULL
110483 +pci_msix_table_size_38867 pci_msix_table_size 0 38867 NULL
110484 +dbgfs_state_38894 dbgfs_state 3 38894 NULL
110485 +f2fs_xattr_set_acl_38895 f2fs_xattr_set_acl 4 38895 NULL
110486 +il_dbgfs_sram_write_38942 il_dbgfs_sram_write 3 38942 NULL
110487 +__ath6kl_wmi_send_mgmt_cmd_38971 __ath6kl_wmi_send_mgmt_cmd 7 38971 NULL
110488 +usb_maxpacket_38977 usb_maxpacket 0 38977 NULL nohasharray
110489 +C_SYSC_preadv64_38977 C_SYSC_preadv64 3 38977 &usb_maxpacket_38977
110490 +OSDSetBlock_38986 OSDSetBlock 2-4 38986 NULL
110491 +lpfc_idiag_extacc_write_38998 lpfc_idiag_extacc_write 3 38998 NULL
110492 +get_nodes_39012 get_nodes 3 39012 NULL
110493 +twl6030_interrupt_unmask_39013 twl6030_interrupt_unmask 2 39013 NULL
110494 +__blkdev_issue_zeroout_39020 __blkdev_issue_zeroout 3 39020 NULL
110495 +_zd_iowrite32v_async_locked_39034 _zd_iowrite32v_async_locked 3 39034 NULL
110496 +do_write_kmem_39051 do_write_kmem 0-1-3 39051 NULL
110497 +ReadHFC_39104 ReadHFC 0 39104 NULL
110498 +tomoyo_truncate_39105 tomoyo_truncate 0 39105 NULL
110499 +__kfifo_to_user_r_39123 __kfifo_to_user_r 5-3 39123 NULL
110500 +ea_foreach_39133 ea_foreach 0 39133 NULL
110501 +generic_permission_39150 generic_permission 0 39150 NULL
110502 +proc_coredump_filter_read_39153 proc_coredump_filter_read 3 39153 NULL
110503 +ath9k_hw_ar9003_dump_eeprom_39156 ath9k_hw_ar9003_dump_eeprom 5-4 39156 NULL
110504 +echo_client_kbrw_39170 echo_client_kbrw 6 39170 NULL
110505 +ext3_xattr_check_names_39174 ext3_xattr_check_names 0 39174 NULL
110506 +ubi_more_update_data_39189 ubi_more_update_data 4 39189 NULL
110507 +qcam_read_bytes_39205 qcam_read_bytes 0 39205 NULL
110508 +ivtv_v4l2_write_39226 ivtv_v4l2_write 3 39226 NULL
110509 +posix_acl_to_xattr_39237 posix_acl_to_xattr 0 39237 NULL
110510 +snd_pcm_capture_forward_39248 snd_pcm_capture_forward 2 39248 NULL
110511 +r128_compat_ioctl_39250 r128_compat_ioctl 2 39250 NULL nohasharray
110512 +pwr_cont_miss_bcns_spread_read_39250 pwr_cont_miss_bcns_spread_read 3 39250 &r128_compat_ioctl_39250
110513 +i915_error_state_read_39254 i915_error_state_read 3 39254 NULL
110514 +rx_filter_protection_filter_read_39282 rx_filter_protection_filter_read 3 39282 NULL
110515 +__cfg80211_connect_result_39326 __cfg80211_connect_result 4-6 39326 NULL
110516 +insert_reserved_file_extent_39327 insert_reserved_file_extent 3 39327 NULL
110517 +wimax_msg_alloc_39343 wimax_msg_alloc 4 39343 NULL
110518 +ide_complete_rq_39354 ide_complete_rq 3 39354 NULL
110519 +do_write_log_from_user_39362 do_write_log_from_user 3-0 39362 NULL
110520 +vortex_wtdma_getlinearpos_39371 vortex_wtdma_getlinearpos 0 39371 NULL
110521 +regmap_name_read_file_39379 regmap_name_read_file 3 39379 NULL
110522 +fnic_trace_debugfs_read_39380 fnic_trace_debugfs_read 3 39380 NULL
110523 +ps_poll_ps_poll_utilization_read_39383 ps_poll_ps_poll_utilization_read 3 39383 NULL
110524 +__send_to_port_39386 __send_to_port 3 39386 NULL
110525 +user_power_read_39414 user_power_read 3 39414 NULL
110526 +alloc_agpphysmem_i8xx_39427 alloc_agpphysmem_i8xx 1 39427 NULL
110527 +mic_desc_size_39464 mic_desc_size 0 39464 NULL
110528 +apei_resources_add_39470 apei_resources_add 0 39470 NULL
110529 +setkey_unaligned_39474 setkey_unaligned 3 39474 NULL
110530 +ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries_39499 ieee80211_if_fmt_dot11MeshHWMPmaxPREQretries 3 39499 NULL
110531 +cl_req_alloc_39523 cl_req_alloc 4 39523 NULL
110532 +int_proc_write_39542 int_proc_write 3 39542 NULL
110533 +mdc_unpack_capa_39553 mdc_unpack_capa 0 39553 NULL
110534 +pp_write_39554 pp_write 3 39554 NULL
110535 +datablob_format_39571 datablob_format 2 39571 NULL nohasharray
110536 +ieee80211_if_read_fwded_mcast_39571 ieee80211_if_read_fwded_mcast 3 39571 &datablob_format_39571
110537 +ext_depth_39607 ext_depth 0 39607 NULL
110538 +batadv_tt_tvlv_generate_39615 batadv_tt_tvlv_generate 4 39615 NULL
110539 +nfs_idmap_get_key_39616 nfs_idmap_get_key 2 39616 NULL
110540 +sdio_readb_39618 sdio_readb 0 39618 NULL
110541 +set_dev_class_39645 set_dev_class 4 39645 NULL
110542 +snd_rme32_capture_copy_39653 snd_rme32_capture_copy 5 39653 NULL
110543 +tcp_try_rmem_schedule_39657 tcp_try_rmem_schedule 3 39657 NULL
110544 +kvm_read_guest_cached_39666 kvm_read_guest_cached 4 39666 NULL
110545 +v4l_stk_read_39672 v4l_stk_read 3 39672 NULL
110546 +hsc_msg_len_get_39673 hsc_msg_len_get 0 39673 NULL
110547 +do_surface_dirty_sou_39678 do_surface_dirty_sou 7 39678 NULL
110548 +sd_completed_bytes_39705 sd_completed_bytes 0 39705 NULL
110549 +ftrace_pid_write_39710 ftrace_pid_write 3 39710 NULL
110550 +adt7316_spi_multi_read_39765 adt7316_spi_multi_read 3 39765 NULL
110551 +security_inode_listsecurity_39812 security_inode_listsecurity 0 39812 NULL
110552 +snd_pcm_oss_writev3_39818 snd_pcm_oss_writev3 3 39818 NULL
110553 +get_priv_size_39828 get_priv_size 0-1 39828 NULL
110554 +pkt_add_39897 pkt_add 3 39897 NULL
110555 +read_file_modal_eeprom_39909 read_file_modal_eeprom 3 39909 NULL
110556 +gen_pool_add_virt_39913 gen_pool_add_virt 4 39913 NULL
110557 +dw210x_op_rw_39915 dw210x_op_rw 6 39915 NULL
110558 +aes_encrypt_interrupt_read_39919 aes_encrypt_interrupt_read 3 39919 NULL
110559 +exofs_read_kern_39921 exofs_read_kern 6 39921 NULL nohasharray
110560 +oom_score_adj_read_39921 oom_score_adj_read 3 39921 &exofs_read_kern_39921
110561 +__spi_async_39932 __spi_async 0 39932 NULL
110562 +__get_order_39935 __get_order 0 39935 NULL
110563 +error_error_frame_read_39947 error_error_frame_read 3 39947 NULL
110564 +tty_prepare_flip_string_39955 tty_prepare_flip_string 3-0 39955 NULL
110565 +lstcon_group_list_39958 lstcon_group_list 2 39958 NULL
110566 +dma_push_rx_39973 dma_push_rx 2 39973 NULL
110567 +broadsheetfb_write_39976 broadsheetfb_write 3 39976 NULL
110568 +mthca_array_init_39987 mthca_array_init 2 39987 NULL
110569 +fw_device_op_read_39990 fw_device_op_read 3 39990 NULL
110570 +server_name2svname_39998 server_name2svname 4 39998 NULL
110571 +xen_hvm_config_40018 xen_hvm_config 2 40018 NULL
110572 +ivtvfb_write_40023 ivtvfb_write 3 40023 NULL
110573 +disc_pwup_write_40027 disc_pwup_write 3 40027 NULL
110574 +ea_foreach_i_40028 ea_foreach_i 0 40028 NULL
110575 +datablob_hmac_append_40038 datablob_hmac_append 3 40038 NULL
110576 +l2cap_create_iframe_pdu_40055 l2cap_create_iframe_pdu 3 40055 NULL nohasharray
110577 +add_tty_40055 add_tty 1 40055 &l2cap_create_iframe_pdu_40055
110578 +atomic_xchg_40070 atomic_xchg 0 40070 NULL
110579 +sctp_setsockopt_delayed_ack_40129 sctp_setsockopt_delayed_ack 3 40129 NULL
110580 +dwc2_max_desc_num_40132 dwc2_max_desc_num 0 40132 NULL
110581 +rx_rx_frame_checksum_read_40140 rx_rx_frame_checksum_read 3 40140 NULL
110582 +ath10k_write_simulate_fw_crash_40143 ath10k_write_simulate_fw_crash 3 40143 NULL
110583 +iwch_alloc_fastreg_pbl_40153 iwch_alloc_fastreg_pbl 2 40153 NULL
110584 +pt_write_40159 pt_write 3 40159 NULL
110585 +scsi_sg_count_40182 scsi_sg_count 0 40182 NULL
110586 +ipr_alloc_ucode_buffer_40199 ipr_alloc_ucode_buffer 1 40199 NULL
110587 +allocate_probes_40204 allocate_probes 1 40204 NULL
110588 +au0828_v4l2_read_40220 au0828_v4l2_read 3 40220 NULL
110589 +compress_file_range_40225 compress_file_range 3-4 40225 NULL
110590 +osst_read_40237 osst_read 3 40237 NULL
110591 +lpage_info_slot_40243 lpage_info_slot 3-1 40243 NULL
110592 +ocfs2_zero_extend_get_range_40248 ocfs2_zero_extend_get_range 4-3 40248 NULL
110593 +ptlrpc_queue_wait_40252 ptlrpc_queue_wait 0 40252 NULL
110594 +rs_sta_dbgfs_scale_table_read_40262 rs_sta_dbgfs_scale_table_read 3 40262 NULL
110595 +ext2_fiemap_40271 ext2_fiemap 4 40271 NULL
110596 +usbnet_read_cmd_40275 usbnet_read_cmd 7 40275 NULL
110597 +rx_xfr_hint_trig_read_40283 rx_xfr_hint_trig_read 3 40283 NULL
110598 +SyS_bind_40303 SyS_bind 3 40303 NULL
110599 +ib_get_mad_data_offset_40336 ib_get_mad_data_offset 0 40336 NULL
110600 +mmio_read_40348 mmio_read 4 40348 NULL
110601 +event_rx_mem_empty_read_40363 event_rx_mem_empty_read 3 40363 NULL
110602 +ocfs2_check_range_for_refcount_40365 ocfs2_check_range_for_refcount 3-2 40365 NULL
110603 +get_chars_40373 get_chars 3 40373 NULL
110604 +fb_prepare_extra_logos_40429 fb_prepare_extra_logos 0-2 40429 NULL
110605 +tomoyo_update_policy_40458 tomoyo_update_policy 2 40458 NULL
110606 +zd_usb_scnprint_id_40459 zd_usb_scnprint_id 0-3 40459 NULL
110607 +gp2ap020a00f_write_event_threshold_40461 gp2ap020a00f_write_event_threshold 2 40461 NULL
110608 +SyS_writev_40467 SyS_writev 3 40467 NULL
110609 +SyS_select_40473 SyS_select 1 40473 NULL
110610 +afs_fs_store_data_40484 afs_fs_store_data 3-4-5-6 40484 NULL
110611 +batadv_hash_new_40491 batadv_hash_new 1 40491 NULL
110612 +devcgroup_inode_permission_40492 devcgroup_inode_permission 0 40492 NULL
110613 +__ethtool_get_sset_count_40511 __ethtool_get_sset_count 0 40511 NULL
110614 +TSS_checkhmac2_40520 TSS_checkhmac2 5-7 40520 NULL
110615 +ixgbe_dbg_reg_ops_read_40540 ixgbe_dbg_reg_ops_read 3 40540 NULL
110616 +ima_write_policy_40548 ima_write_policy 3 40548 NULL
110617 +esp_alloc_tmp_40558 esp_alloc_tmp 3-2 40558 NULL
110618 +b1_get_byte_40597 b1_get_byte 0 40597 NULL
110619 +get_priv_descr_and_size_40612 get_priv_descr_and_size 0 40612 NULL
110620 +twl4030_kpwrite_u8_40665 twl4030_kpwrite_u8 3 40665 NULL
110621 +__cfg80211_roamed_40668 __cfg80211_roamed 4-6 40668 NULL
110622 +pipeline_rx_complete_stat_fifo_int_read_40671 pipeline_rx_complete_stat_fifo_int_read 3 40671 NULL
110623 +fops_read_40672 fops_read 3 40672 NULL
110624 +idr_get_empty_slot_40674 idr_get_empty_slot 0 40674 NULL
110625 +alloc_rbio_40676 alloc_rbio 4 40676 NULL
110626 +videobuf_dma_init_user_locked_40678 videobuf_dma_init_user_locked 4-3 40678 NULL
110627 +pci_enable_resources_40680 pci_enable_resources 0 40680 NULL
110628 +nfc_hci_set_param_40697 nfc_hci_set_param 5 40697 NULL
110629 +__seq_open_private_40715 __seq_open_private 3 40715 NULL
110630 +fuse_readpages_40737 fuse_readpages 4 40737 NULL
110631 +xfs_iext_remove_direct_40744 xfs_iext_remove_direct 3 40744 NULL
110632 +security_inode_listxattr_40752 security_inode_listxattr 0 40752 NULL
110633 +card_send_command_40757 card_send_command 3 40757 NULL
110634 +ad1889_readl_40765 ad1889_readl 0 40765 NULL
110635 +pg_write_40766 pg_write 3 40766 NULL
110636 +show_list_40775 show_list 3-0 40775 NULL
110637 +kfifo_out_copy_r_40784 kfifo_out_copy_r 3-0 40784 NULL
110638 +bitmap_weight_40791 bitmap_weight 0-2 40791 NULL
110639 +pyra_sysfs_read_40795 pyra_sysfs_read 6 40795 NULL
110640 +add_action_40811 add_action 4 40811 NULL
110641 +nl80211_send_roamed_40825 nl80211_send_roamed 5-7 40825 NULL
110642 +SyS_mbind_40828 SyS_mbind 5 40828 NULL
110643 +nilfs_mdt_init_40849 nilfs_mdt_init 3 40849 NULL
110644 +v9fs_file_read_40858 v9fs_file_read 3 40858 NULL
110645 +read_file_queue_40895 read_file_queue 3 40895 NULL
110646 +waiters_read_40902 waiters_read 3 40902 NULL
110647 +isdn_add_channels_40905 isdn_add_channels 3 40905 NULL
110648 +gfs2_ea_find_40913 gfs2_ea_find 0 40913 NULL
110649 +vol_cdev_write_40915 vol_cdev_write 3 40915 NULL
110650 +snd_vx_create_40948 snd_vx_create 4 40948 NULL nohasharray
110651 +sg_alloc_table_40948 sg_alloc_table 0 40948 &snd_vx_create_40948
110652 +rds_sendmsg_40976 rds_sendmsg 4 40976 NULL
110653 +il_dbgfs_fh_reg_read_40993 il_dbgfs_fh_reg_read 3 40993 NULL
110654 +iwl_dbgfs_scan_ant_rxchain_read_40999 iwl_dbgfs_scan_ant_rxchain_read 3 40999 NULL
110655 +mac80211_format_buffer_41010 mac80211_format_buffer 2 41010 NULL
110656 +__proc_dobitmasks_41029 __proc_dobitmasks 5 41029 NULL
110657 +_req_append_segment_41031 _req_append_segment 2 41031 NULL
110658 +mISDN_sock_sendmsg_41035 mISDN_sock_sendmsg 4 41035 NULL
110659 +ocfs2_xattr_index_block_find_41040 ocfs2_xattr_index_block_find 0 41040 NULL
110660 +lprocfs_write_frac_helper_41050 lprocfs_write_frac_helper 2 41050 NULL
110661 +calculate_order_41061 calculate_order 0 41061 NULL
110662 +vfs_listxattr_41062 vfs_listxattr 0 41062 NULL nohasharray
110663 +beacon_filtering_write_41062 beacon_filtering_write 3 41062 &vfs_listxattr_41062
110664 +cfg80211_inform_bss_frame_41078 cfg80211_inform_bss_frame 4 41078 NULL
110665 +nvme_map_user_pages_41093 nvme_map_user_pages 4-3 41093 NULL nohasharray
110666 +roccat_read_41093 roccat_read 3 41093 &nvme_map_user_pages_41093
110667 +dma_attach_41094 dma_attach 5-6 41094 NULL
110668 +provide_user_output_41105 provide_user_output 3 41105 NULL
110669 +f_audio_buffer_alloc_41110 f_audio_buffer_alloc 1 41110 NULL
110670 +ath10k_read_wmi_services_41112 ath10k_read_wmi_services 3 41112 NULL
110671 +ocfs2_extend_trans_41116 ocfs2_extend_trans 2 41116 NULL
110672 +v4l2_ctrl_new_int_menu_41151 v4l2_ctrl_new_int_menu 4 41151 NULL
110673 +tx_frag_mpdu_alloc_failed_read_41167 tx_frag_mpdu_alloc_failed_read 3 41167 NULL
110674 +dvb_ca_write_41171 dvb_ca_write 3 41171 NULL
110675 +dgap_driver_kzmalloc_41189 dgap_driver_kzmalloc 1 41189 NULL
110676 +compat_sys_process_vm_writev_41194 compat_sys_process_vm_writev 3-5 41194 NULL
110677 +dfs_file_write_41196 dfs_file_write 3 41196 NULL
110678 +nfs_page_array_len_41219 nfs_page_array_len 0-2-1 41219 NULL
110679 +cfg80211_process_disassoc_41231 cfg80211_process_disassoc 3 41231 NULL
110680 +hiddev_compat_ioctl_41255 hiddev_compat_ioctl 2 41255 NULL
110681 +erst_read_41260 erst_read 0 41260 NULL
110682 +alloc_context_41283 alloc_context 1 41283 NULL
110683 +o2hb_setup_one_bio_41341 o2hb_setup_one_bio 4 41341 NULL
110684 +twl_change_queue_depth_41342 twl_change_queue_depth 2 41342 NULL
110685 +rtw_android_set_block_41347 rtw_android_set_block 0 41347 NULL
110686 +cnic_init_id_tbl_41354 cnic_init_id_tbl 2 41354 NULL
110687 +kmp_init_41373 kmp_init 2 41373 NULL
110688 +isr_commands_read_41398 isr_commands_read 3 41398 NULL
110689 +rx_defrag_decrypt_failed_read_41411 rx_defrag_decrypt_failed_read 3 41411 NULL
110690 +xfs_iext_add_41422 xfs_iext_add 3 41422 NULL
110691 +isdn_ppp_fill_rq_41428 isdn_ppp_fill_rq 2 41428 NULL
110692 +lbs_rdrf_read_41431 lbs_rdrf_read 3 41431 NULL
110693 +iio_device_alloc_41440 iio_device_alloc 1 41440 NULL
110694 +ntfs_file_buffered_write_41442 ntfs_file_buffered_write 6-4 41442 NULL
110695 +pcpu_build_alloc_info_41443 pcpu_build_alloc_info 1-2-3 41443 NULL
110696 +se_io_cb_41461 se_io_cb 3 41461 NULL
110697 +layout_leb_in_gaps_41470 layout_leb_in_gaps 0 41470 NULL
110698 +rt2x00debug_write_rfcsr_41473 rt2x00debug_write_rfcsr 3 41473 NULL
110699 +bl_alloc_init_bio_41478 bl_alloc_init_bio 1 41478 NULL
110700 +kvm_unmap_hva_range_41484 kvm_unmap_hva_range 3-2 41484 NULL
110701 +wep_interrupt_read_41492 wep_interrupt_read 3 41492 NULL
110702 +SyS_get_mempolicy_41495 SyS_get_mempolicy 3 41495 NULL
110703 +hpfs_translate_name_41497 hpfs_translate_name 3 41497 NULL
110704 +xfrm_hash_new_size_41505 xfrm_hash_new_size 0-1 41505 NULL
110705 +SyS_preadv_41523 SyS_preadv 3 41523 NULL
110706 +dm_get_reserved_rq_based_ios_41529 dm_get_reserved_rq_based_ios 0 41529 NULL
110707 +tx_tx_frame_checksum_read_41553 tx_tx_frame_checksum_read 3 41553 NULL
110708 +ath6kl_endpoint_stats_read_41554 ath6kl_endpoint_stats_read 3 41554 NULL
110709 +nr_status_frames_41559 nr_status_frames 0-1 41559 NULL nohasharray
110710 +si476x_radio_fops_read_41559 si476x_radio_fops_read 3 41559 &nr_status_frames_41559
110711 +rng_dev_read_41581 rng_dev_read 3 41581 NULL
110712 +batadv_tvlv_container_ogm_append_41588 batadv_tvlv_container_ogm_append 4 41588 NULL
110713 +vga_io_r_41609 vga_io_r 0 41609 NULL
110714 +tcp_hdrlen_41610 tcp_hdrlen 0 41610 NULL
110715 +lbs_bcnmiss_write_41613 lbs_bcnmiss_write 3 41613 NULL nohasharray
110716 +usb_endpoint_maxp_41613 usb_endpoint_maxp 0 41613 &lbs_bcnmiss_write_41613
110717 +a2mp_send_41615 a2mp_send 4 41615 NULL
110718 +lstcon_batch_list_41627 lstcon_batch_list 2 41627 NULL
110719 +mempool_create_kmalloc_pool_41650 mempool_create_kmalloc_pool 1 41650 NULL
110720 +rx_rx_pre_complt_read_41653 rx_rx_pre_complt_read 3 41653 NULL
110721 +get_std_timing_41654 get_std_timing 0 41654 NULL
110722 +ieee80211_if_fmt_bssid_41677 ieee80211_if_fmt_bssid 3 41677 NULL
110723 +fill_pcm_stream_name_41685 fill_pcm_stream_name 2 41685 NULL
110724 +lov_unpackmd_41701 lov_unpackmd 4 41701 NULL
110725 +apei_exec_for_each_entry_41717 apei_exec_for_each_entry 0 41717 NULL
110726 +fillonedir_41746 fillonedir 3 41746 NULL
110727 +iwl_dbgfs_bt_notif_read_41794 iwl_dbgfs_bt_notif_read 3 41794 NULL
110728 +hsi_alloc_controller_41802 hsi_alloc_controller 1 41802 NULL
110729 +rtw_android_get_macaddr_41812 rtw_android_get_macaddr 0 41812 NULL
110730 +sco_send_frame_41815 sco_send_frame 3 41815 NULL
110731 +ixgbe_dbg_netdev_ops_read_41839 ixgbe_dbg_netdev_ops_read 3 41839 NULL
110732 +do_ip_setsockopt_41852 do_ip_setsockopt 5 41852 NULL
110733 +keyctl_instantiate_key_41855 keyctl_instantiate_key 3 41855 NULL
110734 +pci_map_single_41869 pci_map_single 0 41869 NULL
110735 +usb_gadget_get_string_41871 usb_gadget_get_string 0 41871 NULL
110736 +v_APCI3120_InterruptDmaMoveBlock16bit_41914 v_APCI3120_InterruptDmaMoveBlock16bit 4 41914 NULL
110737 +get_fdb_entries_41916 get_fdb_entries 3 41916 NULL
110738 +nfsd_getxattr_41934 nfsd_getxattr 0 41934 NULL
110739 +ext4_da_write_inline_data_begin_41935 ext4_da_write_inline_data_begin 3-4 41935 NULL
110740 +sci_rxfill_41945 sci_rxfill 0 41945 NULL
110741 +read_gssp_41947 read_gssp 3 41947 NULL
110742 +ocfs2_xattr_bucket_get_name_value_41949 ocfs2_xattr_bucket_get_name_value 0 41949 NULL
110743 +portnames_read_41958 portnames_read 3 41958 NULL
110744 +dst_mtu_41969 dst_mtu 0 41969 NULL
110745 +cx24116_writeregN_41975 cx24116_writeregN 4 41975 NULL
110746 +pool_allocate_42012 pool_allocate 3 42012 NULL
110747 +spidev_sync_read_42014 spidev_sync_read 0 42014 NULL
110748 +rs_sta_dbgfs_scale_table_write_42017 rs_sta_dbgfs_scale_table_write 3 42017 NULL
110749 +create_dir_42025 create_dir 0 42025 NULL
110750 +acpi_ut_create_buffer_object_42030 acpi_ut_create_buffer_object 1 42030 NULL
110751 +__btrfs_drop_extents_42032 __btrfs_drop_extents 5 42032 NULL
110752 +__hwahc_op_set_gtk_42038 __hwahc_op_set_gtk 4 42038 NULL
110753 +irda_sendmsg_ultra_42047 irda_sendmsg_ultra 4 42047 NULL
110754 +jffs2_do_link_42048 jffs2_do_link 6 42048 NULL
110755 +ps_poll_upsd_max_ap_turn_read_42050 ps_poll_upsd_max_ap_turn_read 3 42050 NULL
110756 +InterfaceTransmitPacket_42058 InterfaceTransmitPacket 3 42058 NULL
110757 +scsi_execute_req_42088 scsi_execute_req 5 42088 NULL
110758 +sk_chk_filter_42095 sk_chk_filter 2 42095 NULL
110759 +submit_inquiry_42108 submit_inquiry 3 42108 NULL
110760 +dw_dma_cyclic_prep_42113 dw_dma_cyclic_prep 3-4 42113 NULL
110761 +obd_get_info_42156 obd_get_info 0 42156 NULL
110762 +blk_ioctl_zeroout_42160 blk_ioctl_zeroout 3 42160 NULL
110763 +mmc_align_data_size_42161 mmc_align_data_size 0-2 42161 NULL
110764 +read_file_base_eeprom_42168 read_file_base_eeprom 3 42168 NULL
110765 +oprofilefs_str_to_user_42182 oprofilefs_str_to_user 3 42182 NULL
110766 +write_file_beacon_42185 write_file_beacon 3 42185 NULL
110767 +get_znodes_to_commit_42201 get_znodes_to_commit 0 42201 NULL
110768 +pla_ocp_read_42235 pla_ocp_read 3 42235 NULL
110769 +rx_defrag_need_decrypt_read_42253 rx_defrag_need_decrypt_read 3 42253 NULL
110770 +find_last_bit_42260 find_last_bit 0 42260 NULL
110771 +__pcpu_size_to_slot_42271 __pcpu_size_to_slot 0 42271 NULL
110772 +snd_pcm_hw_param_value_max_42280 snd_pcm_hw_param_value_max 0 42280 NULL
110773 +__cpus_weight_42299 __cpus_weight 2-0 42299 NULL
110774 +sel_read_perm_42302 sel_read_perm 3 42302 NULL
110775 +sctp_setsockopt_del_key_42304 sctp_setsockopt_del_key 3 42304 NULL nohasharray
110776 +ulong_read_file_42304 ulong_read_file 3 42304 &sctp_setsockopt_del_key_42304
110777 +xfs_vm_readpages_42308 xfs_vm_readpages 4 42308 NULL
110778 +hysdn_conf_read_42324 hysdn_conf_read 3 42324 NULL
110779 +tcp_sync_mss_42330 tcp_sync_mss 2-0 42330 NULL
110780 +ide_raw_taskfile_42355 ide_raw_taskfile 4 42355 NULL
110781 +tipc_send_42374 tipc_send 3 42374 NULL
110782 +drbd_md_last_sector_42378 drbd_md_last_sector 0 42378 NULL
110783 +il_dbgfs_disable_ht40_read_42386 il_dbgfs_disable_ht40_read 3 42386 NULL
110784 +msnd_fifo_read_42406 msnd_fifo_read 0-3 42406 NULL
110785 +krng_get_random_42420 krng_get_random 3 42420 NULL
110786 +gsm_data_alloc_42437 gsm_data_alloc 3 42437 NULL
110787 +key_conf_keyidx_read_42443 key_conf_keyidx_read 3 42443 NULL
110788 +alloc_request_42448 alloc_request 0 42448 NULL
110789 +snd_pcm_action_group_42452 snd_pcm_action_group 0 42452 NULL
110790 +tcm_loop_change_queue_depth_42454 tcm_loop_change_queue_depth 2 42454 NULL
110791 +kuc_free_42455 kuc_free 2 42455 NULL
110792 +__simple_xattr_set_42474 __simple_xattr_set 4 42474 NULL
110793 +omfs_readpages_42490 omfs_readpages 4 42490 NULL
110794 +bypass_write_42498 bypass_write 3 42498 NULL
110795 +SyS_mincore_42511 SyS_mincore 1-2 42511 NULL
110796 +kvm_write_wall_clock_42520 kvm_write_wall_clock 2 42520 NULL
110797 +dio_bio_complete_42524 dio_bio_complete 0 42524 NULL
110798 +smk_write_netlbladdr_42525 smk_write_netlbladdr 3 42525 NULL
110799 +dbAllocNear_42546 dbAllocNear 0 42546 NULL
110800 +ath6kl_wmi_proc_events_vif_42549 ath6kl_wmi_proc_events_vif 5 42549 NULL
110801 +udp_recvmsg_42558 udp_recvmsg 4 42558 NULL
110802 +iwl_print_event_log_42566 iwl_print_event_log 7-5-0 42566 NULL
110803 +xfrm_new_hash_mask_42579 xfrm_new_hash_mask 0-1 42579 NULL
110804 +oom_score_adj_write_42594 oom_score_adj_write 3 42594 NULL
110805 +ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout_42635 ieee80211_if_fmt_dot11MeshHWMPactivePathTimeout 3 42635 NULL
110806 +scsi_activate_tcq_42640 scsi_activate_tcq 2 42640 NULL
110807 +br_mdb_rehash_42643 br_mdb_rehash 2 42643 NULL
110808 +parport_pc_compat_write_block_pio_42644 parport_pc_compat_write_block_pio 3 42644 NULL
110809 +_regmap_raw_write_42652 _regmap_raw_write 4-2 42652 NULL
110810 +request_key_and_link_42693 request_key_and_link 4 42693 NULL
110811 +vb2_read_42703 vb2_read 3 42703 NULL
110812 +read_status_42722 read_status 0 42722 NULL
110813 +dvb_demux_ioctl_42733 dvb_demux_ioctl 2 42733 NULL
110814 +set_aoe_iflist_42737 set_aoe_iflist 2 42737 NULL
110815 +ax25_setsockopt_42740 ax25_setsockopt 5 42740 NULL
110816 +dpm_sysfs_add_42756 dpm_sysfs_add 0 42756 NULL
110817 +x25_recvmsg_42777 x25_recvmsg 4 42777 NULL
110818 +snd_midi_event_decode_42780 snd_midi_event_decode 0 42780 NULL
110819 +cryptd_hash_setkey_42781 cryptd_hash_setkey 3 42781 NULL nohasharray
110820 +isku_sysfs_read_info_42781 isku_sysfs_read_info 6 42781 &cryptd_hash_setkey_42781
110821 +elfcorehdr_read_notes_42786 elfcorehdr_read_notes 2 42786 NULL
110822 +koneplus_sysfs_read_42792 koneplus_sysfs_read 6 42792 NULL
110823 +ptlrpc_request_bufs_pack_42793 ptlrpc_request_bufs_pack 0 42793 NULL
110824 +ntfs_attr_extend_allocation_42796 ntfs_attr_extend_allocation 0 42796 NULL
110825 +fw_device_op_compat_ioctl_42804 fw_device_op_compat_ioctl 2 42804 NULL
110826 +drm_ioctl_42813 drm_ioctl 2 42813 NULL
110827 +iwl_dbgfs_ucode_bt_stats_read_42820 iwl_dbgfs_ucode_bt_stats_read 3 42820 NULL
110828 +set_arg_42824 set_arg 3 42824 NULL
110829 +si476x_radio_read_rsq_blob_42827 si476x_radio_read_rsq_blob 3 42827 NULL
110830 +ocfs2_clusters_for_bytes_42872 ocfs2_clusters_for_bytes 0-2 42872 NULL
110831 +nvme_trans_unit_serial_page_42879 nvme_trans_unit_serial_page 4 42879 NULL
110832 +xpc_kmalloc_cacheline_aligned_42895 xpc_kmalloc_cacheline_aligned 1 42895 NULL
110833 +hd_end_request_42904 hd_end_request 2 42904 NULL
110834 +sta_last_rx_rate_read_42909 sta_last_rx_rate_read 3 42909 NULL
110835 +sctp_getsockopt_maxburst_42941 sctp_getsockopt_maxburst 2 42941 NULL nohasharray
110836 +mdc_unpack_acl_42941 mdc_unpack_acl 0 42941 &sctp_getsockopt_maxburst_42941
110837 +vx_reset_chk_42946 vx_reset_chk 0 42946 NULL
110838 +blkdev_direct_IO_42962 blkdev_direct_IO 4 42962 NULL
110839 +read_file_node_stat_42964 read_file_node_stat 3 42964 NULL
110840 +compat_udpv6_setsockopt_42981 compat_udpv6_setsockopt 5 42981 NULL
110841 +nfs_idmap_get_desc_42990 nfs_idmap_get_desc 4-2 42990 NULL nohasharray
110842 +rtw_os_xmit_resource_alloc_42990 rtw_os_xmit_resource_alloc 3 42990 &nfs_idmap_get_desc_42990
110843 +isr_rx_mem_overflow_read_43025 isr_rx_mem_overflow_read 3 43025 NULL
110844 +wep_default_key_count_read_43035 wep_default_key_count_read 3 43035 NULL
110845 +nouveau_gpuobj_create__43072 nouveau_gpuobj_create_ 9 43072 NULL
110846 +nfs_map_group_to_gid_43082 nfs_map_group_to_gid 3 43082 NULL
110847 +_xfer_secondary_pool_43089 _xfer_secondary_pool 2 43089 NULL
110848 +sysfs_create_file_ns_43103 sysfs_create_file_ns 0 43103 NULL
110849 +ieee80211_if_fmt_drop_unencrypted_43107 ieee80211_if_fmt_drop_unencrypted 3 43107 NULL
110850 +calculate_node_totalpages_43118 calculate_node_totalpages 2-3 43118 NULL
110851 +read_file_dfs_43145 read_file_dfs 3 43145 NULL
110852 +cfs_cpt_table_alloc_43159 cfs_cpt_table_alloc 1 43159 NULL
110853 +usb_string_sub_43164 usb_string_sub 0 43164 NULL
110854 +il_dbgfs_power_save_status_read_43165 il_dbgfs_power_save_status_read 3 43165 NULL
110855 +ath6kl_set_assoc_req_ies_43185 ath6kl_set_assoc_req_ies 3 43185 NULL
110856 +ext4_xattr_ibody_get_43200 ext4_xattr_ibody_get 0 43200 NULL
110857 +uio_write_43202 uio_write 3 43202 NULL
110858 +iso_callback_43208 iso_callback 3 43208 NULL
110859 +ath10k_p2p_calc_noa_ie_len_43209 ath10k_p2p_calc_noa_ie_len 0 43209 NULL
110860 +f2fs_acl_from_disk_43210 f2fs_acl_from_disk 2 43210 NULL
110861 +atomic_long_add_return_43217 atomic_long_add_return 1-0 43217 NULL
110862 +batadv_tt_tvlv_unicast_handler_v1_43239 batadv_tt_tvlv_unicast_handler_v1 5 43239 NULL
110863 +vmemmap_alloc_block_43245 vmemmap_alloc_block 1 43245 NULL
110864 +ide_end_rq_43269 ide_end_rq 4 43269 NULL
110865 +nilfs_direct_IO_43271 nilfs_direct_IO 4 43271 NULL
110866 +parport_pc_ecp_write_block_pio_43278 parport_pc_ecp_write_block_pio 3 43278 NULL nohasharray
110867 +evtchn_write_43278 evtchn_write 3 43278 &parport_pc_ecp_write_block_pio_43278
110868 +filemap_write_and_wait_range_43279 filemap_write_and_wait_range 0 43279 NULL
110869 +mpage_alloc_43299 mpage_alloc 3 43299 NULL
110870 +mmu_set_spte_43327 mmu_set_spte 7-6 43327 NULL
110871 +__ext4_get_inode_loc_43332 __ext4_get_inode_loc 0 43332 NULL
110872 +xenfb_write_43412 xenfb_write 3 43412 NULL
110873 +__alloc_bootmem_low_43423 __alloc_bootmem_low 1 43423 NULL
110874 +usb_alloc_urb_43436 usb_alloc_urb 1 43436 NULL
110875 +ath6kl_wmi_roam_tbl_event_rx_43440 ath6kl_wmi_roam_tbl_event_rx 3 43440 NULL
110876 +usb_string_43443 usb_string 0 43443 NULL nohasharray
110877 +usemap_size_43443 usemap_size 0-2-1 43443 &usb_string_43443
110878 +get_vm_area_size_43444 get_vm_area_size 0 43444 NULL
110879 +nvme_trans_device_id_page_43466 nvme_trans_device_id_page 4 43466 NULL
110880 +tx_tx_data_prepared_read_43497 tx_tx_data_prepared_read 3 43497 NULL
110881 +ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime_43505 ieee80211_if_fmt_dot11MeshHWMPnetDiameterTraversalTime 3 43505 NULL
110882 +do_readlink_43518 do_readlink 2 43518 NULL
110883 +dvb_ca_en50221_io_write_43533 dvb_ca_en50221_io_write 3 43533 NULL
110884 +read_events_43534 read_events 3 43534 NULL
110885 +cachefiles_daemon_write_43535 cachefiles_daemon_write 3 43535 NULL
110886 +tx_frag_failed_read_43540 tx_frag_failed_read 3 43540 NULL
110887 +request_resource_43548 request_resource 0 43548 NULL
110888 +rpc_malloc_43573 rpc_malloc 2 43573 NULL
110889 +handle_frequent_errors_43599 handle_frequent_errors 4 43599 NULL
110890 +lpfc_idiag_drbacc_read_reg_43606 lpfc_idiag_drbacc_read_reg 0-3 43606 NULL
110891 +proc_read_43614 proc_read 3 43614 NULL
110892 +disable_dma_on_even_43618 disable_dma_on_even 0 43618 NULL
110893 +alloc_thread_groups_43625 alloc_thread_groups 2 43625 NULL
110894 +random_write_43656 random_write 3 43656 NULL
110895 +bio_integrity_tag_43658 bio_integrity_tag 3 43658 NULL
110896 +ext4_acl_count_43659 ext4_acl_count 0-1 43659 NULL
110897 +write_file_tx99_power_43670 write_file_tx99_power 3 43670 NULL
110898 +dmam_declare_coherent_memory_43679 dmam_declare_coherent_memory 4 43679 NULL
110899 +max77693_bulk_write_43698 max77693_bulk_write 2-3 43698 NULL
110900 +drbd_md_first_sector_43729 drbd_md_first_sector 0 43729 NULL
110901 +snd_rme32_playback_copy_43732 snd_rme32_playback_copy 5 43732 NULL
110902 +fuse_conn_congestion_threshold_write_43736 fuse_conn_congestion_threshold_write 3 43736 NULL
110903 +gigaset_initcs_43753 gigaset_initcs 2 43753 NULL
110904 +sctp_setsockopt_active_key_43755 sctp_setsockopt_active_key 3 43755 NULL
110905 +ocfs2_xattr_get_value_outside_43787 ocfs2_xattr_get_value_outside 0 43787 NULL nohasharray
110906 +byte_pos_43787 byte_pos 0-2 43787 &ocfs2_xattr_get_value_outside_43787
110907 +btrfs_copy_from_user_43806 btrfs_copy_from_user 0-3-1 43806 NULL
110908 +ieee80211_if_fmt_element_ttl_43825 ieee80211_if_fmt_element_ttl 3 43825 NULL
110909 +ieee80211_alloc_hw_43829 ieee80211_alloc_hw 1 43829 NULL
110910 +read_flush_43851 read_flush 3 43851 NULL
110911 +pm860x_bulk_write_43875 pm860x_bulk_write 2-3 43875 NULL
110912 +SendString_43928 SendString 3 43928 NULL
110913 +stats_dot11RTSFailureCount_read_43948 stats_dot11RTSFailureCount_read 3 43948 NULL
110914 +__get_required_blob_size_43980 __get_required_blob_size 0-3-2 43980 NULL
110915 +nla_reserve_43984 nla_reserve 3 43984 NULL
110916 +__clkdev_alloc_43990 __clkdev_alloc 1 43990 NULL
110917 +scsi_command_size_43992 scsi_command_size 0 43992 NULL nohasharray
110918 +kvm_read_guest_virt_43992 kvm_read_guest_virt 4-2 43992 &scsi_command_size_43992 nohasharray
110919 +bcm_recvmsg_43992 bcm_recvmsg 4 43992 &kvm_read_guest_virt_43992
110920 +emit_flags_44006 emit_flags 4-3 44006 NULL
110921 +write_flush_procfs_44011 write_flush_procfs 3 44011 NULL
110922 +fru_strlen_44046 fru_strlen 0 44046 NULL
110923 +ath9k_def_dump_modal_eeprom_44078 ath9k_def_dump_modal_eeprom 3-2-0 44078 NULL
110924 +SYSC_add_key_44079 SYSC_add_key 4 44079 NULL
110925 +__vxge_hw_vpath_tim_configure_44093 __vxge_hw_vpath_tim_configure 2 44093 NULL
110926 +xlog_recover_add_to_cont_trans_44102 xlog_recover_add_to_cont_trans 4 44102 NULL
110927 +skb_frag_dma_map_44112 skb_frag_dma_map 0 44112 NULL
110928 +tracing_set_trace_read_44122 tracing_set_trace_read 3 44122 NULL
110929 +SyS_process_vm_writev_44129 SyS_process_vm_writev 3-5 44129 NULL
110930 +ttm_get_pages_44142 ttm_get_pages 2 44142 NULL
110931 +scsi_get_resid_44147 scsi_get_resid 0 44147 NULL
110932 +ocfs2_xattr_bucket_find_44174 ocfs2_xattr_bucket_find 0 44174 NULL
110933 +SYSC_set_mempolicy_44176 SYSC_set_mempolicy 3 44176 NULL
110934 +readreg_ipac_44186 readreg_ipac 0 44186 NULL
110935 +handle_eviocgbit_44193 handle_eviocgbit 3 44193 NULL
110936 +srp_alloc_iu_44227 srp_alloc_iu 2 44227 NULL
110937 +scsi_track_queue_full_44239 scsi_track_queue_full 2 44239 NULL
110938 +sigma_action_write_regmap_44240 sigma_action_write_regmap 3 44240 NULL
110939 +apei_resources_sub_44252 apei_resources_sub 0 44252 NULL
110940 +device_create_file_44285 device_create_file 0 44285 NULL
110941 +ath6kl_keepalive_read_44303 ath6kl_keepalive_read 3 44303 NULL
110942 +bitmap_scnprintf_44318 bitmap_scnprintf 0-2 44318 NULL
110943 +dispatch_proc_write_44320 dispatch_proc_write 3 44320 NULL
110944 +rs_init_44327 rs_init 1 44327 NULL
110945 +blk_queue_init_tags_44355 blk_queue_init_tags 2 44355 NULL nohasharray
110946 +nfs_fscache_get_super_cookie_44355 nfs_fscache_get_super_cookie 3 44355 &blk_queue_init_tags_44355
110947 +alloc_requests_44372 alloc_requests 0 44372 NULL
110948 +rts_threshold_read_44384 rts_threshold_read 3 44384 NULL
110949 +mtip_hw_read_flags_44396 mtip_hw_read_flags 3 44396 NULL
110950 +aoedev_flush_44398 aoedev_flush 2 44398 NULL
110951 +strlcpy_44400 strlcpy 3 44400 NULL
110952 +drm_buffer_alloc_44405 drm_buffer_alloc 2 44405 NULL
110953 +osst_do_scsi_44410 osst_do_scsi 4 44410 NULL
110954 +ieee80211_if_read_rc_rateidx_mcs_mask_5ghz_44423 ieee80211_if_read_rc_rateidx_mcs_mask_5ghz 3 44423 NULL
110955 +iwl_dbgfs_bf_params_write_44450 iwl_dbgfs_bf_params_write 3 44450 NULL
110956 +write_file_debug_44476 write_file_debug 3 44476 NULL
110957 +btrfs_chunk_item_size_44478 btrfs_chunk_item_size 0-1 44478 NULL
110958 +sdio_align_size_44489 sdio_align_size 0-2 44489 NULL
110959 +bio_advance_44496 bio_advance 2 44496 NULL
110960 +ieee80211_if_read_dropped_frames_ttl_44500 ieee80211_if_read_dropped_frames_ttl 3 44500 NULL
110961 +ac_register_board_44504 ac_register_board 3 44504 NULL
110962 +security_getprocattr_44505 security_getprocattr 0 44505 NULL nohasharray
110963 +iwl_dbgfs_sram_read_44505 iwl_dbgfs_sram_read 3 44505 &security_getprocattr_44505
110964 +spidev_write_44510 spidev_write 3 44510 NULL
110965 +SyS_io_getevents_44519 SyS_io_getevents 3 44519 NULL
110966 +ieee80211_rx_mgmt_assoc_resp_44525 ieee80211_rx_mgmt_assoc_resp 3 44525 NULL
110967 +comm_write_44537 comm_write 3 44537 NULL
110968 +xfs_log_calc_unit_res_44540 xfs_log_calc_unit_res 0-2 44540 NULL
110969 +dgrp_config_proc_write_44571 dgrp_config_proc_write 3 44571 NULL
110970 +nouveau_perfmon_create__44602 nouveau_perfmon_create_ 4 44602 NULL
110971 +alloc_ctrl_packet_44667 alloc_ctrl_packet 1 44667 NULL
110972 +mpi_resize_44674 mpi_resize 2 44674 NULL
110973 +sysfs_create_link_44685 sysfs_create_link 0 44685 NULL
110974 +ts_read_44687 ts_read 3 44687 NULL
110975 +lov_emerg_alloc_44698 lov_emerg_alloc 1 44698 NULL
110976 +__ocfs2_rotate_tree_left_44705 __ocfs2_rotate_tree_left 3 44705 NULL
110977 +xfer_to_user_44713 xfer_to_user 3 44713 NULL nohasharray
110978 +__generic_block_fiemap_44713 __generic_block_fiemap 4 44713 &xfer_to_user_44713
110979 +_zd_iowrite32v_locked_44725 _zd_iowrite32v_locked 3 44725 NULL
110980 +clusterip_proc_write_44729 clusterip_proc_write 3 44729 NULL
110981 +fib_count_nexthops_44730 fib_count_nexthops 0 44730 NULL
110982 +key_tx_rx_count_read_44742 key_tx_rx_count_read 3 44742 NULL
110983 +tnode_new_44757 tnode_new 3 44757 NULL nohasharray
110984 +pty_write_44757 pty_write 3 44757 &tnode_new_44757
110985 +__videobuf_copy_stream_44769 __videobuf_copy_stream 4-0 44769 NULL
110986 +handsfree_ramp_44777 handsfree_ramp 2 44777 NULL
110987 +irq_domain_add_legacy_44781 irq_domain_add_legacy 4-2 44781 NULL
110988 +sctp_setsockopt_44788 sctp_setsockopt 5 44788 NULL
110989 +rx_dropped_read_44799 rx_dropped_read 3 44799 NULL
110990 +qla4xxx_alloc_work_44813 qla4xxx_alloc_work 2 44813 NULL
110991 +mei_cl_read_start_44824 mei_cl_read_start 2 44824 NULL
110992 +rmap_write_protect_44833 rmap_write_protect 2 44833 NULL
110993 +sisusb_write_44834 sisusb_write 3 44834 NULL
110994 +kvm_read_hva_44847 kvm_read_hva 3 44847 NULL
110995 +qib_verbs_send_dma_44850 qib_verbs_send_dma 6 44850 NULL
110996 +copydesc_user_44855 copydesc_user 3 44855 NULL
110997 +set_advertising_44870 set_advertising 4 44870 NULL
110998 +init_rs_44873 init_rs 1 44873 NULL
110999 +skb_availroom_44883 skb_availroom 0 44883 NULL
111000 +ocfs2_wait_for_mask_44893 ocfs2_wait_for_mask 0 44893 NULL
111001 +do_tty_write_44896 do_tty_write 5 44896 NULL
111002 +regmap_spi_read_44921 regmap_spi_read 3-5 44921 NULL
111003 +tx_queue_status_read_44978 tx_queue_status_read 3 44978 NULL
111004 +bytepos_delta_45017 bytepos_delta 0-2 45017 NULL
111005 +ptrace_writedata_45021 ptrace_writedata 4 45021 NULL
111006 +dm_kvzalloc_45025 dm_kvzalloc 1 45025 NULL
111007 +vhci_get_user_45039 vhci_get_user 3 45039 NULL
111008 +sysfs_do_create_link_sd_45057 sysfs_do_create_link_sd 0 45057 NULL
111009 +sel_write_user_45060 sel_write_user 3 45060 NULL
111010 +snd_mixart_BA0_read_45069 snd_mixart_BA0_read 5 45069 NULL
111011 +kvm_mmu_page_get_gfn_45110 kvm_mmu_page_get_gfn 0-2 45110 NULL
111012 +pwr_missing_bcns_cnt_read_45113 pwr_missing_bcns_cnt_read 3 45113 NULL
111013 +usbdev_read_45114 usbdev_read 3 45114 NULL
111014 +send_to_tty_45141 send_to_tty 3 45141 NULL
111015 +cfs_trace_daemon_command_usrstr_45147 cfs_trace_daemon_command_usrstr 2 45147 NULL
111016 +gen_bitmask_string_45149 gen_bitmask_string 6 45149 NULL
111017 +device_write_45156 device_write 3 45156 NULL nohasharray
111018 +ocfs2_remove_inode_range_45156 ocfs2_remove_inode_range 3-4 45156 &device_write_45156
111019 +tomoyo_write_self_45161 tomoyo_write_self 3 45161 NULL
111020 +sta_agg_status_write_45164 sta_agg_status_write 3 45164 NULL
111021 +snd_sb_csp_load_user_45190 snd_sb_csp_load_user 3 45190 NULL nohasharray
111022 +sctp_pack_cookie_45190 sctp_pack_cookie 6 45190 &snd_sb_csp_load_user_45190
111023 +iso_alloc_urb_45206 iso_alloc_urb 4-5 45206 NULL
111024 +spi_alloc_master_45223 spi_alloc_master 2 45223 NULL
111025 +ieee80211_if_read_peer_45233 ieee80211_if_read_peer 3 45233 NULL
111026 +event_enable_write_45238 event_enable_write 3 45238 NULL
111027 +prism2_pda_proc_read_45246 prism2_pda_proc_read 3 45246 NULL
111028 +input_mt_init_slots_45279 input_mt_init_slots 2 45279 NULL
111029 +gfs2_fiemap_45282 gfs2_fiemap 4 45282 NULL
111030 +snd_pcm_oss_sync1_45298 snd_pcm_oss_sync1 2 45298 NULL
111031 +e1000_tx_map_45309 e1000_tx_map 5 45309 NULL
111032 +copy_vm86_regs_from_user_45340 copy_vm86_regs_from_user 3 45340 NULL
111033 +null_alloc_repbuf_45375 null_alloc_repbuf 3 45375 NULL
111034 +sock_recv_errqueue_45412 sock_recv_errqueue 3 45412 NULL
111035 +ieee80211_if_fmt_dot11MeshHWMProotInterval_45421 ieee80211_if_fmt_dot11MeshHWMProotInterval 3 45421 NULL
111036 +ll_iocontrol_register_45430 ll_iocontrol_register 2 45430 NULL
111037 +tty_buffer_alloc_45437 tty_buffer_alloc 2 45437 NULL
111038 +__node_remap_45458 __node_remap 4 45458 NULL
111039 +rds_ib_set_wr_signal_state_45463 rds_ib_set_wr_signal_state 0 45463 NULL
111040 +tracing_read_dyn_info_45468 tracing_read_dyn_info 3 45468 NULL
111041 +rds_message_copy_from_user_45510 rds_message_copy_from_user 3 45510 NULL
111042 +i40e_alloc_vfs_45511 i40e_alloc_vfs 2 45511 NULL
111043 +cgroup_read_u64_45532 cgroup_read_u64 5 45532 NULL
111044 +copy_macs_45534 copy_macs 4 45534 NULL
111045 +nla_attr_size_45545 nla_attr_size 0-1 45545 NULL
111046 +v9fs_direct_read_45546 v9fs_direct_read 3 45546 NULL
111047 +cx18_copy_mdl_to_user_45549 cx18_copy_mdl_to_user 4 45549 NULL
111048 +stats_dot11ACKFailureCount_read_45558 stats_dot11ACKFailureCount_read 3 45558 NULL
111049 +_regmap_bus_raw_write_45559 _regmap_bus_raw_write 2 45559 NULL
111050 +posix_acl_xattr_size_45561 posix_acl_xattr_size 0-1 45561 NULL
111051 +venus_rmdir_45564 venus_rmdir 4 45564 NULL
111052 +ath6kl_keepalive_write_45600 ath6kl_keepalive_write 3 45600 NULL
111053 +hidraw_get_report_45609 hidraw_get_report 3 45609 NULL
111054 +compat_mpctl_ioctl_45671 compat_mpctl_ioctl 2 45671 NULL
111055 +dgram_sendmsg_45679 dgram_sendmsg 4 45679 NULL
111056 +smk_write_ambient_45691 smk_write_ambient 3 45691 NULL
111057 +unix_dgram_sendmsg_45699 unix_dgram_sendmsg 4 45699 NULL nohasharray
111058 +bscnl_emit_45699 bscnl_emit 2-5-0 45699 &unix_dgram_sendmsg_45699
111059 +sg_proc_write_adio_45704 sg_proc_write_adio 3 45704 NULL
111060 +snd_cs46xx_io_read_45734 snd_cs46xx_io_read 5 45734 NULL nohasharray
111061 +task_cgroup_path_45734 task_cgroup_path 3 45734 &snd_cs46xx_io_read_45734
111062 +rw_copy_check_uvector_45748 rw_copy_check_uvector 3-0 45748 NULL nohasharray
111063 +v4l2_ctrl_new_std_45748 v4l2_ctrl_new_std 5 45748 &rw_copy_check_uvector_45748
111064 +lkdtm_debugfs_read_45752 lkdtm_debugfs_read 3 45752 NULL
111065 +alloc_ts_config_45775 alloc_ts_config 1 45775 NULL
111066 +osc_checksum_type_seq_write_45785 osc_checksum_type_seq_write 3 45785 NULL
111067 +raw_setsockopt_45800 raw_setsockopt 5 45800 NULL
111068 +rds_tcp_inc_copy_to_user_45804 rds_tcp_inc_copy_to_user 3 45804 NULL
111069 +lbs_rdbbp_read_45805 lbs_rdbbp_read 3 45805 NULL
111070 +pcpu_alloc_alloc_info_45813 pcpu_alloc_alloc_info 1-2 45813 NULL
111071 +ll_max_readahead_mb_seq_write_45815 ll_max_readahead_mb_seq_write 3 45815 NULL
111072 +memcg_update_cache_size_45828 memcg_update_cache_size 2 45828 NULL
111073 +ipv6_recv_rxpmtu_45830 ipv6_recv_rxpmtu 3 45830 NULL
111074 +x509_process_extension_45854 x509_process_extension 5 45854 NULL
111075 +efx_tx_queue_insert_45859 efx_tx_queue_insert 2 45859 NULL
111076 +isdn_write_45863 isdn_write 3 45863 NULL
111077 +tpm_config_in_45880 tpm_config_in 0 45880 NULL
111078 +get_rdac_req_45882 get_rdac_req 3 45882 NULL
111079 +ima_eventdigest_init_common_45889 ima_eventdigest_init_common 2 45889 NULL
111080 +ocfs2_xattr_block_find_45891 ocfs2_xattr_block_find 0 45891 NULL
111081 +cfs_cpt_weight_45903 cfs_cpt_weight 0 45903 NULL
111082 +wm_adsp_region_to_reg_45915 wm_adsp_region_to_reg 0-2 45915 NULL
111083 +dbgfs_frame_45917 dbgfs_frame 3 45917 NULL
111084 +alloc_mr_45935 alloc_mr 1 45935 NULL
111085 +copy_to_45969 copy_to 3 45969 NULL
111086 +rb_simple_read_45972 rb_simple_read 3 45972 NULL
111087 +ioat2_dca_count_dca_slots_45984 ioat2_dca_count_dca_slots 0 45984 NULL
111088 +kobject_init_and_add_46003 kobject_init_and_add 0 46003 NULL
111089 +sierra_setup_urb_46029 sierra_setup_urb 5 46029 NULL
111090 +fnic_reset_stats_read_46030 fnic_reset_stats_read 3 46030 NULL nohasharray
111091 +get_free_entries_46030 get_free_entries 1 46030 &fnic_reset_stats_read_46030
111092 +__access_remote_vm_46031 __access_remote_vm 0 46031 NULL
111093 +snd_emu10k1x_ptr_read_46049 snd_emu10k1x_ptr_read 0 46049 NULL
111094 +__ocfs2_move_extent_46060 __ocfs2_move_extent 3-4 46060 NULL nohasharray
111095 +dma_tx_errors_read_46060 dma_tx_errors_read 3 46060 &__ocfs2_move_extent_46060
111096 +sel_commit_bools_write_46077 sel_commit_bools_write 3 46077 NULL
111097 +il3945_ucode_general_stats_read_46111 il3945_ucode_general_stats_read 3 46111 NULL nohasharray
111098 +memcg_update_array_size_46111 memcg_update_array_size 1 46111 &il3945_ucode_general_stats_read_46111
111099 +C_SYSC_writev_46113 C_SYSC_writev 3 46113 NULL
111100 +mlx4_ib_alloc_fast_reg_page_list_46119 mlx4_ib_alloc_fast_reg_page_list 2 46119 NULL
111101 +rtw_buf_update_46138 rtw_buf_update 4 46138 NULL
111102 +vb2_dma_sg_get_userptr_46146 vb2_dma_sg_get_userptr 3-2 46146 NULL
111103 +__netlink_change_ngroups_46156 __netlink_change_ngroups 2 46156 NULL
111104 +twl_direction_out_46182 twl_direction_out 2 46182 NULL
111105 +vxge_os_dma_malloc_46184 vxge_os_dma_malloc 2 46184 NULL
111106 +fq_resize_46195 fq_resize 2 46195 NULL
111107 +add_conn_list_46197 add_conn_list 3-0 46197 NULL
111108 +i2400m_op_msg_from_user_46213 i2400m_op_msg_from_user 4 46213 NULL
111109 +tm6000_i2c_recv_regs_46215 tm6000_i2c_recv_regs 5 46215 NULL
111110 +dsp_write_46218 dsp_write 2 46218 NULL
111111 +hash_netiface4_expire_46226 hash_netiface4_expire 4 46226 NULL
111112 +xen_setup_msi_irqs_46245 xen_setup_msi_irqs 2 46245 NULL
111113 +mpi_read_raw_data_46248 mpi_read_raw_data 2 46248 NULL
111114 +ReadReg_46277 ReadReg 0 46277 NULL
111115 +sptlrpc_req_get_ctx_46303 sptlrpc_req_get_ctx 0 46303 NULL
111116 +sg_proc_write_dressz_46316 sg_proc_write_dressz 3 46316 NULL
111117 +__hwahc_dev_set_key_46328 __hwahc_dev_set_key 5 46328 NULL nohasharray
111118 +compat_SyS_readv_46328 compat_SyS_readv 3 46328 &__hwahc_dev_set_key_46328
111119 +iwl_dbgfs_chain_noise_read_46355 iwl_dbgfs_chain_noise_read 3 46355 NULL
111120 +smk_write_direct_46363 smk_write_direct 3 46363 NULL
111121 +fuse_file_aio_write_46399 fuse_file_aio_write 4 46399 NULL
111122 +crypto_ablkcipher_reqsize_46411 crypto_ablkcipher_reqsize 0 46411 NULL
111123 +ttm_page_pool_get_pages_46431 ttm_page_pool_get_pages 0-5 46431 NULL
111124 +cfs_power2_roundup_46433 cfs_power2_roundup 0-1 46433 NULL
111125 +cp210x_set_config_46447 cp210x_set_config 4 46447 NULL
111126 +parport_pc_fifo_write_block_46455 parport_pc_fifo_write_block 3 46455 NULL
111127 +il_dbgfs_clear_traffic_stats_write_46458 il_dbgfs_clear_traffic_stats_write 3 46458 NULL
111128 +filldir64_46469 filldir64 3 46469 NULL
111129 +fill_in_write_vector_46498 fill_in_write_vector 0 46498 NULL
111130 +pin_code_reply_46510 pin_code_reply 4 46510 NULL
111131 +mthca_alloc_cq_buf_46512 mthca_alloc_cq_buf 3 46512 NULL
111132 +kmsg_read_46514 kmsg_read 3 46514 NULL nohasharray
111133 +nouveau_drm_ioctl_46514 nouveau_drm_ioctl 2 46514 &kmsg_read_46514
111134 +nl80211_send_rx_assoc_46538 nl80211_send_rx_assoc 4 46538 NULL
111135 +dn_current_mss_46574 dn_current_mss 0 46574 NULL
111136 +serverworks_create_gatt_pages_46582 serverworks_create_gatt_pages 1 46582 NULL
111137 +snd_compr_write_data_46592 snd_compr_write_data 3 46592 NULL
111138 +il3945_stats_flag_46606 il3945_stats_flag 3-0 46606 NULL
111139 +vscnprintf_46617 vscnprintf 0-2 46617 NULL
111140 +__kfifo_out_r_46623 __kfifo_out_r 3-0 46623 NULL
111141 +request_key_async_with_auxdata_46624 request_key_async_with_auxdata 4 46624 NULL
111142 +pci_enable_device_46642 pci_enable_device 0 46642 NULL
111143 +vfs_getxattr_alloc_46649 vfs_getxattr_alloc 0 46649 NULL
111144 +e1000_tx_map_46672 e1000_tx_map 4 46672 NULL
111145 +alloc_data_packet_46698 alloc_data_packet 1 46698 NULL
111146 +__ilog2_u32_46706 __ilog2_u32 0 46706 NULL
111147 +erst_dbg_write_46715 erst_dbg_write 3 46715 NULL
111148 +wl1271_rx_filter_alloc_field_46721 wl1271_rx_filter_alloc_field 5 46721 NULL
111149 +irq_domain_add_simple_46734 irq_domain_add_simple 2 46734 NULL
111150 +read_file_tx99_46741 read_file_tx99 3 46741 NULL
111151 +ext4_count_free_46754 ext4_count_free 2 46754 NULL
111152 +hest_ghes_dev_register_46766 hest_ghes_dev_register 1 46766 NULL
111153 +int_hw_irq_en_46776 int_hw_irq_en 3 46776 NULL
111154 +_xfs_buf_get_pages_46811 _xfs_buf_get_pages 2 46811 NULL
111155 +xfs_iroot_realloc_46826 xfs_iroot_realloc 2 46826 NULL
111156 +readreg_46845 readreg 0 46845 NULL
111157 +spi_async_46857 spi_async 0 46857 NULL
111158 +SyS_move_pages_46863 SyS_move_pages 2 46863 NULL nohasharray
111159 +vsnprintf_46863 vsnprintf 0 46863 &SyS_move_pages_46863
111160 +nvme_alloc_queue_46865 nvme_alloc_queue 3 46865 NULL
111161 +qp_memcpy_from_queue_iov_46874 qp_memcpy_from_queue_iov 5-4 46874 NULL
111162 +lov_iocontrol_46876 lov_iocontrol 3 46876 NULL
111163 +ixgbe_dbg_reg_ops_write_46895 ixgbe_dbg_reg_ops_write 3 46895 NULL
111164 +sk_mem_pages_46896 sk_mem_pages 0-1 46896 NULL
111165 +ieee80211_if_fmt_power_mode_46906 ieee80211_if_fmt_power_mode 3 46906 NULL
111166 +wlcore_alloc_hw_46917 wlcore_alloc_hw 1-3 46917 NULL
111167 +fb_write_46924 fb_write 3 46924 NULL
111168 +__sctp_setsockopt_connectx_46949 __sctp_setsockopt_connectx 3 46949 NULL
111169 +qla4xxx_post_aen_work_46953 qla4xxx_post_aen_work 3 46953 NULL
111170 +SYSC_poll_46965 SYSC_poll 2 46965 NULL
111171 +crypto_tfm_alg_alignmask_46971 crypto_tfm_alg_alignmask 0 46971 NULL
111172 +mgmt_pending_add_46976 mgmt_pending_add 5 46976 NULL
111173 +strlcat_46985 strlcat 3 46985 NULL
111174 +bitmap_file_clear_bit_46990 bitmap_file_clear_bit 2 46990 NULL
111175 +sel_write_bool_46996 sel_write_bool 3 46996 NULL nohasharray
111176 +gfs2_xattr_system_set_46996 gfs2_xattr_system_set 4 46996 &sel_write_bool_46996
111177 +blk_rq_map_kern_47004 blk_rq_map_kern 4 47004 NULL
111178 +cx231xx_init_bulk_47024 cx231xx_init_bulk 3-2-4 47024 NULL
111179 +fs_path_len_47060 fs_path_len 0 47060 NULL
111180 +ext4_xattr_list_entries_47070 ext4_xattr_list_entries 0 47070 NULL
111181 +pipeline_dec_packet_in_read_47076 pipeline_dec_packet_in_read 3 47076 NULL
111182 +scsi_deactivate_tcq_47086 scsi_deactivate_tcq 2 47086 NULL
111183 +iwl_dump_nic_event_log_47089 iwl_dump_nic_event_log 0 47089 NULL
111184 +ptlrpc_lprocfs_threads_max_seq_write_47104 ptlrpc_lprocfs_threads_max_seq_write 3 47104 NULL
111185 +mousedev_read_47123 mousedev_read 3 47123 NULL
111186 +acpi_ut_initialize_buffer_47143 acpi_ut_initialize_buffer 2 47143 NULL nohasharray
111187 +ses_recv_diag_47143 ses_recv_diag 4 47143 &acpi_ut_initialize_buffer_47143
111188 +mxms_headerlen_47161 mxms_headerlen 0 47161 NULL
111189 +rs_sta_dbgfs_rate_scale_data_read_47165 rs_sta_dbgfs_rate_scale_data_read 3 47165 NULL
111190 +rts51x_ms_rw_47171 rts51x_ms_rw 3-4 47171 NULL
111191 +can_set_system_xattr_47182 can_set_system_xattr 4 47182 NULL
111192 +options_write_47243 options_write 3 47243 NULL
111193 +portcntrs_1_read_47253 portcntrs_1_read 3 47253 NULL
111194 +ablkcipher_next_slow_47274 ablkcipher_next_slow 4-3 47274 NULL
111195 +gfs2_readpages_47285 gfs2_readpages 4 47285 NULL
111196 +vsnprintf_47291 vsnprintf 0 47291 NULL
111197 +SYSC_semop_47292 SYSC_semop 3 47292 NULL
111198 +tx_internal_desc_overflow_read_47300 tx_internal_desc_overflow_read 3 47300 NULL
111199 +nouveau_fb_create__47316 nouveau_fb_create_ 4 47316 NULL
111200 +ieee80211_if_read_dot11MeshHoldingTimeout_47356 ieee80211_if_read_dot11MeshHoldingTimeout 3 47356 NULL
111201 +avc_get_hash_stats_47359 avc_get_hash_stats 0 47359 NULL
111202 +kvm_arch_create_memslot_47364 kvm_arch_create_memslot 3 47364 NULL nohasharray
111203 +__output_copy_user_47364 __output_copy_user 3 47364 &kvm_arch_create_memslot_47364
111204 +__bio_map_kern_47379 __bio_map_kern 3 47379 NULL
111205 +trace_options_core_read_47390 trace_options_core_read 3 47390 NULL nohasharray
111206 +nv_rd32_47390 nv_rd32 0 47390 &trace_options_core_read_47390
111207 +nametbl_list_47391 nametbl_list 2 47391 NULL
111208 +dgrp_net_write_47392 dgrp_net_write 3 47392 NULL
111209 +pfkey_sendmsg_47394 pfkey_sendmsg 4 47394 NULL
111210 +lbs_wrmac_write_47400 lbs_wrmac_write 3 47400 NULL
111211 +sta_vht_capa_read_47409 sta_vht_capa_read 3 47409 NULL
111212 +crypto_ablkcipher_alignmask_47410 crypto_ablkcipher_alignmask 0 47410 NULL
111213 +lbs_wrrf_write_47418 lbs_wrrf_write 3 47418 NULL
111214 +posix_acl_from_disk_47445 posix_acl_from_disk 2 47445 NULL
111215 +nvme_trans_send_fw_cmd_47479 nvme_trans_send_fw_cmd 4 47479 NULL
111216 +newpart_47485 newpart 6-4 47485 NULL
111217 +mcp23s17_read_regs_47491 mcp23s17_read_regs 4 47491 NULL
111218 +core_sys_select_47494 core_sys_select 1 47494 NULL
111219 +alloc_arraycache_47505 alloc_arraycache 2 47505 NULL
111220 +unlink_simple_47506 unlink_simple 3 47506 NULL
111221 +pstore_decompress_47510 pstore_decompress 0 47510 NULL
111222 +__proc_lnet_portal_rotor_47529 __proc_lnet_portal_rotor 5 47529 NULL
111223 +process_vm_rw_47533 process_vm_rw 3-5 47533 NULL nohasharray
111224 +vscnprintf_47533 vscnprintf 0-2 47533 &process_vm_rw_47533
111225 +einj_check_trigger_header_47534 einj_check_trigger_header 0 47534 NULL
111226 +ieee80211_if_fmt_min_discovery_timeout_47539 ieee80211_if_fmt_min_discovery_timeout 3 47539 NULL
111227 +read_ldt_47570 read_ldt 2 47570 NULL
111228 +isku_sysfs_read_last_set_47572 isku_sysfs_read_last_set 6 47572 NULL
111229 +btrfs_stack_header_bytenr_47589 btrfs_stack_header_bytenr 0 47589 NULL
111230 +ext4_kvzalloc_47605 ext4_kvzalloc 1 47605 NULL
111231 +sctp_ssnmap_new_47608 sctp_ssnmap_new 2-1 47608 NULL
111232 +cache_read_pipefs_47615 cache_read_pipefs 3 47615 NULL
111233 +twl4030_clear_set_47624 twl4030_clear_set 4 47624 NULL
111234 +get_size_47644 get_size 1-2 47644 NULL
111235 +packet_recvmsg_47700 packet_recvmsg 4 47700 NULL nohasharray
111236 +ipath_format_hwmsg_47700 ipath_format_hwmsg 2 47700 &packet_recvmsg_47700
111237 +save_microcode_47717 save_microcode 3 47717 NULL
111238 +bits_to_user_47733 bits_to_user 2-3 47733 NULL
111239 +carl9170_debugfs_read_47738 carl9170_debugfs_read 3 47738 NULL
111240 +ir_prepare_write_buffer_47747 ir_prepare_write_buffer 3 47747 NULL
111241 +mvumi_alloc_mem_resource_47750 mvumi_alloc_mem_resource 3 47750 NULL
111242 +alloc_sched_domains_47756 alloc_sched_domains 1 47756 NULL
111243 +uwb_ie_dump_hex_47774 uwb_ie_dump_hex 4 47774 NULL
111244 +SyS_setgroups16_47780 SyS_setgroups16 1 47780 NULL
111245 +error_error_numll_frame_cts_start_read_47781 error_error_numll_frame_cts_start_read 3 47781 NULL
111246 +posix_acl_fix_xattr_from_user_47793 posix_acl_fix_xattr_from_user 2 47793 NULL
111247 +W6692_empty_Bfifo_47804 W6692_empty_Bfifo 2 47804 NULL
111248 +lov_packmd_47810 lov_packmd 0 47810 NULL
111249 +pinconf_dbg_config_write_47835 pinconf_dbg_config_write 3 47835 NULL
111250 +KEY_SIZE_47855 KEY_SIZE 0 47855 NULL
111251 +vhci_read_47878 vhci_read 3 47878 NULL
111252 +keyctl_instantiate_key_common_47889 keyctl_instantiate_key_common 4 47889 NULL
111253 +cfs_percpt_alloc_47918 cfs_percpt_alloc 2 47918 NULL
111254 +comedi_write_47926 comedi_write 3 47926 NULL
111255 +nvme_trans_get_blk_desc_len_47946 nvme_trans_get_blk_desc_len 0-2 47946 NULL
111256 +gether_get_ifname_47972 gether_get_ifname 3 47972 NULL
111257 +mempool_resize_47983 mempool_resize 2 47983 NULL nohasharray
111258 +iwl_dbgfs_ucode_tracing_read_47983 iwl_dbgfs_ucode_tracing_read 3 47983 &mempool_resize_47983
111259 +dbg_port_buf_47990 dbg_port_buf 2 47990 NULL
111260 +ib_umad_write_47993 ib_umad_write 3 47993 NULL
111261 +lustre_cfg_len_48002 lustre_cfg_len 0 48002 NULL
111262 +gdm_tty_recv_complete_48011 gdm_tty_recv_complete 2 48011 NULL
111263 +ffs_epfile_write_48014 ffs_epfile_write 3 48014 NULL
111264 +bio_integrity_set_tag_48035 bio_integrity_set_tag 3 48035 NULL
111265 +pppoe_sendmsg_48039 pppoe_sendmsg 4 48039 NULL
111266 +SYSC_writev_48040 SYSC_writev 3 48040 NULL
111267 +wpan_phy_alloc_48056 wpan_phy_alloc 1 48056 NULL
111268 +posix_acl_alloc_48063 posix_acl_alloc 1 48063 NULL
111269 +palmas_bulk_write_48068 palmas_bulk_write 2-3-5 48068 NULL
111270 +disc_write_48070 disc_write 3 48070 NULL
111271 +mmc_alloc_host_48097 mmc_alloc_host 1 48097 NULL
111272 +skb_copy_datagram_const_iovec_48102 skb_copy_datagram_const_iovec 4-2-5 48102 NULL
111273 +vmw_framebuffer_surface_dirty_48132 vmw_framebuffer_surface_dirty 6 48132 NULL
111274 +set_discoverable_48141 set_discoverable 4 48141 NULL
111275 +dn_fib_count_nhs_48145 dn_fib_count_nhs 0 48145 NULL
111276 +_add_to_r4w_48152 _add_to_r4w 4 48152 NULL
111277 +isr_dma1_done_read_48159 isr_dma1_done_read 3 48159 NULL
111278 +c4iw_id_table_alloc_48163 c4iw_id_table_alloc 3 48163 NULL
111279 +rbd_obj_method_sync_48170 rbd_obj_method_sync 8 48170 NULL
111280 +alloc_cc770dev_48186 alloc_cc770dev 1 48186 NULL
111281 +brcmf_sdio_chip_cm3_exitdl_48192 brcmf_sdio_chip_cm3_exitdl 4 48192 NULL
111282 +cfg80211_process_deauth_48200 cfg80211_process_deauth 3 48200 NULL
111283 +ext4_index_trans_blocks_48205 ext4_index_trans_blocks 0-2 48205 NULL
111284 +snd_seq_dump_var_event_48209 snd_seq_dump_var_event 0 48209 NULL
111285 +ll_direct_IO_26_48216 ll_direct_IO_26 4 48216 NULL
111286 +uv_blade_nr_possible_cpus_48226 uv_blade_nr_possible_cpus 0 48226 NULL
111287 +nilfs_readpages_48229 nilfs_readpages 4 48229 NULL
111288 +read_file_recv_48232 read_file_recv 3 48232 NULL
111289 +unaccount_shadowed_48233 unaccount_shadowed 2 48233 NULL
111290 +nouveau_i2c_port_create__48240 nouveau_i2c_port_create_ 7 48240 NULL
111291 +nfsctl_transaction_read_48250 nfsctl_transaction_read 3 48250 NULL
111292 +batadv_socket_read_48257 batadv_socket_read 3 48257 NULL
111293 +cache_write_pipefs_48270 cache_write_pipefs 3 48270 NULL
111294 +trace_options_write_48275 trace_options_write 3 48275 NULL
111295 +send_set_info_48288 send_set_info 7 48288 NULL
111296 +lpfc_idiag_extacc_read_48301 lpfc_idiag_extacc_read 3 48301 NULL
111297 +timblogiw_read_48305 timblogiw_read 3 48305 NULL
111298 +hash_setkey_48310 hash_setkey 3 48310 NULL
111299 +audio_set_intf_req_48319 audio_set_intf_req 0 48319 NULL
111300 +kvm_mmu_pte_write_48340 kvm_mmu_pte_write 2 48340 NULL
111301 +skb_add_data_48363 skb_add_data 3 48363 NULL
111302 +tx_frag_init_called_read_48377 tx_frag_init_called_read 3 48377 NULL
111303 +lbs_debugfs_write_48413 lbs_debugfs_write 3 48413 NULL
111304 +uhid_event_from_user_48417 uhid_event_from_user 2 48417 NULL
111305 +div64_u64_rem_48418 div64_u64_rem 0-1-2 48418 NULL
111306 +pwr_tx_without_ps_read_48423 pwr_tx_without_ps_read 3 48423 NULL
111307 +print_filtered_48442 print_filtered 2-0 48442 NULL
111308 +tun_recvmsg_48463 tun_recvmsg 4 48463 NULL
111309 +compat_SyS_preadv64_48469 compat_SyS_preadv64 3 48469 NULL
111310 +ipath_format_hwerrors_48487 ipath_format_hwerrors 5 48487 NULL
111311 +r8712_usbctrl_vendorreq_48489 r8712_usbctrl_vendorreq 6 48489 NULL
111312 +ocfs2_refcount_cow_48495 ocfs2_refcount_cow 3 48495 NULL
111313 +send_control_msg_48498 send_control_msg 6 48498 NULL
111314 +count_masked_bytes_48507 count_masked_bytes 0-1 48507 NULL
111315 +diva_os_copy_to_user_48508 diva_os_copy_to_user 4 48508 NULL
111316 +brcmf_sdio_trap_info_48510 brcmf_sdio_trap_info 4 48510 NULL
111317 +phantom_get_free_48514 phantom_get_free 0 48514 NULL
111318 +drbd_bm_capacity_48530 drbd_bm_capacity 0 48530 NULL
111319 +raid10_size_48571 raid10_size 0-2-3 48571 NULL
111320 +llog_data_len_48607 llog_data_len 1 48607 NULL
111321 +do_ip_vs_set_ctl_48641 do_ip_vs_set_ctl 4 48641 NULL
111322 +ll_rw_extents_stats_pp_seq_write_48651 ll_rw_extents_stats_pp_seq_write 3 48651 NULL
111323 +mtd_read_48655 mtd_read 0 48655 NULL
111324 +aes_encrypt_packets_read_48666 aes_encrypt_packets_read 3 48666 NULL
111325 +sm501_create_subdev_48668 sm501_create_subdev 3-4 48668 NULL
111326 +hysdn_log_write_48694 hysdn_log_write 3 48694 NULL
111327 +altera_drscan_48698 altera_drscan 2 48698 NULL
111328 +kvm_set_irq_routing_48704 kvm_set_irq_routing 3 48704 NULL
111329 +recv_msg_48709 recv_msg 4 48709 NULL
111330 +lpfc_idiag_drbacc_write_48712 lpfc_idiag_drbacc_write 3 48712 NULL
111331 +SyS_lgetxattr_48719 SyS_lgetxattr 4 48719 NULL
111332 +ath6kl_usb_bmi_read_48745 ath6kl_usb_bmi_read 3 48745 NULL
111333 +ath6kl_regwrite_read_48747 ath6kl_regwrite_read 3 48747 NULL
111334 +l2cap_segment_sdu_48772 l2cap_segment_sdu 4 48772 NULL
111335 +gfs2_direct_IO_48774 gfs2_direct_IO 4 48774 NULL
111336 +il3945_sta_dbgfs_stats_table_read_48802 il3945_sta_dbgfs_stats_table_read 3 48802 NULL
111337 +twa_change_queue_depth_48808 twa_change_queue_depth 2 48808 NULL
111338 +atomic_counters_read_48827 atomic_counters_read 3 48827 NULL
111339 +azx_get_position_48841 azx_get_position 0 48841 NULL
111340 +vc_do_resize_48842 vc_do_resize 3-4 48842 NULL
111341 +comedi_buf_write_alloc_48846 comedi_buf_write_alloc 0-2 48846 NULL
111342 +suspend_dtim_interval_write_48854 suspend_dtim_interval_write 3 48854 NULL
111343 +sptlrpc_cli_alloc_reqbuf_48855 sptlrpc_cli_alloc_reqbuf 0 48855 NULL
111344 +C_SYSC_pwritev64_48864 C_SYSC_pwritev64 3 48864 NULL nohasharray
111345 +viafb_dvp1_proc_write_48864 viafb_dvp1_proc_write 3 48864 &C_SYSC_pwritev64_48864
111346 +__ffs_ep0_read_events_48868 __ffs_ep0_read_events 3 48868 NULL
111347 +crypto_cipher_ctxsize_48890 crypto_cipher_ctxsize 0 48890 NULL
111348 +joydev_handle_JSIOCSAXMAP_48898 joydev_handle_JSIOCSAXMAP 3 48898 NULL
111349 +xdi_copy_to_user_48900 xdi_copy_to_user 4 48900 NULL
111350 +msg_hdr_sz_48908 msg_hdr_sz 0 48908 NULL
111351 +sep_crypto_dma_48937 sep_crypto_dma 0 48937 NULL
111352 +si5351_write_parameters_48940 si5351_write_parameters 2 48940 NULL
111353 +event_heart_beat_read_48961 event_heart_beat_read 3 48961 NULL
111354 +nand_ecc_test_run_48966 nand_ecc_test_run 1 48966 NULL
111355 +vmci_handle_arr_create_48971 vmci_handle_arr_create 1 48971 NULL
111356 +rds_rm_size_48996 rds_rm_size 0-2 48996 NULL
111357 +sel_write_enforce_48998 sel_write_enforce 3 48998 NULL
111358 +null_alloc_rs_49019 null_alloc_rs 2 49019 NULL
111359 +filemap_check_errors_49022 filemap_check_errors 0 49022 NULL
111360 +aic_inb_49023 aic_inb 0 49023 NULL
111361 +transient_status_49027 transient_status 4 49027 NULL
111362 +iwl_mvm_power_legacy_dbgfs_read_49038 iwl_mvm_power_legacy_dbgfs_read 4 49038 NULL
111363 +aic7xxx_rem_scb_from_disc_list_49041 aic7xxx_rem_scb_from_disc_list 0 49041 NULL
111364 +scsi_register_49094 scsi_register 2 49094 NULL
111365 +compat_do_readv_writev_49102 compat_do_readv_writev 4 49102 NULL
111366 +xfrm_replay_state_esn_len_49119 xfrm_replay_state_esn_len 0 49119 NULL
111367 +ll_max_cached_mb_seq_write_49122 ll_max_cached_mb_seq_write 3 49122 NULL
111368 +pt_read_49136 pt_read 3 49136 NULL
111369 +ipwireless_tty_received_49154 ipwireless_tty_received 3 49154 NULL
111370 +f2fs_acl_count_49155 f2fs_acl_count 0-1 49155 NULL
111371 +ipw_queue_tx_init_49161 ipw_queue_tx_init 3 49161 NULL
111372 +__jfs_setxattr_49175 __jfs_setxattr 5 49175 NULL
111373 +ath6kl_bgscan_int_write_49178 ath6kl_bgscan_int_write 3 49178 NULL
111374 +dvb_dvr_ioctl_49182 dvb_dvr_ioctl 2 49182 NULL
111375 +print_queue_49191 print_queue 4-0 49191 NULL
111376 +root_nfs_cat_49192 root_nfs_cat 3 49192 NULL
111377 +iwl_dbgfs_ucode_general_stats_read_49199 iwl_dbgfs_ucode_general_stats_read 3 49199 NULL
111378 +il4965_rs_sta_dbgfs_stats_table_read_49206 il4965_rs_sta_dbgfs_stats_table_read 3 49206 NULL
111379 +do_jffs2_getxattr_49210 do_jffs2_getxattr 0 49210 NULL
111380 +nouveau_therm_create__49228 nouveau_therm_create_ 4 49228 NULL
111381 +hugetlb_cgroup_read_49259 hugetlb_cgroup_read 5 49259 NULL
111382 +ieee80211_if_read_rssi_threshold_49260 ieee80211_if_read_rssi_threshold 3 49260 NULL
111383 +isku_sysfs_read_keys_media_49268 isku_sysfs_read_keys_media 6 49268 NULL
111384 +ptlrpc_check_set_49277 ptlrpc_check_set 0 49277 NULL
111385 +rx_filter_beacon_filter_read_49279 rx_filter_beacon_filter_read 3 49279 NULL
111386 +viafb_dfph_proc_write_49288 viafb_dfph_proc_write 3 49288 NULL
111387 +uio_read_49300 uio_read 3 49300 NULL
111388 +isku_sysfs_read_keys_macro_49312 isku_sysfs_read_keys_macro 6 49312 NULL
111389 +SYSC_mincore_49319 SYSC_mincore 2-1 49319 NULL
111390 +fwtty_port_handler_49327 fwtty_port_handler 9 49327 NULL
111391 +srpt_alloc_ioctx_ring_49330 srpt_alloc_ioctx_ring 2-4-3 49330 NULL
111392 +joydev_ioctl_common_49359 joydev_ioctl_common 2 49359 NULL
111393 +iscsi_alloc_session_49390 iscsi_alloc_session 3 49390 NULL
111394 +ext4_ext_index_trans_blocks_49396 ext4_ext_index_trans_blocks 0 49396 NULL
111395 +rx_streaming_always_read_49401 rx_streaming_always_read 3 49401 NULL
111396 +tnode_alloc_49407 tnode_alloc 1 49407 NULL
111397 +samples_to_bytes_49426 samples_to_bytes 0-2 49426 NULL
111398 +compat_do_msg_fill_49440 compat_do_msg_fill 3 49440 NULL
111399 +__hfsplus_getxattr_49460 __hfsplus_getxattr 0 49460 NULL
111400 +agp_3_5_isochronous_node_enable_49465 agp_3_5_isochronous_node_enable 3 49465 NULL
111401 +xfs_iformat_local_49472 xfs_iformat_local 4 49472 NULL
111402 +isr_decrypt_done_read_49490 isr_decrypt_done_read 3 49490 NULL
111403 +iwl_dbgfs_disable_power_off_read_49517 iwl_dbgfs_disable_power_off_read 3 49517 NULL
111404 +SyS_listxattr_49519 SyS_listxattr 3 49519 NULL
111405 +emulator_write_phys_49520 emulator_write_phys 2-4 49520 NULL
111406 +smk_write_access_49561 smk_write_access 3 49561 NULL
111407 +alloc_chunk_49575 alloc_chunk 1 49575 NULL
111408 +sctp_setsockopt_default_send_param_49578 sctp_setsockopt_default_send_param 3 49578 NULL
111409 +ptlrpc_request_pack_49581 ptlrpc_request_pack 0 49581 NULL
111410 +readfifo_49583 readfifo 1 49583 NULL
111411 +tap_write_49595 tap_write 3 49595 NULL
111412 +isr_wakeups_read_49607 isr_wakeups_read 3 49607 NULL
111413 +btrfs_mksubvol_49616 btrfs_mksubvol 3 49616 NULL
111414 +heap_init_49617 heap_init 2 49617 NULL
111415 +smk_write_doi_49621 smk_write_doi 3 49621 NULL
111416 +port_fops_read_49626 port_fops_read 3 49626 NULL
111417 +btrfsic_cmp_log_and_dev_bytenr_49628 btrfsic_cmp_log_and_dev_bytenr 2 49628 NULL
111418 +aa_simple_write_to_buffer_49683 aa_simple_write_to_buffer 4-3 49683 NULL
111419 +SyS_pwritev_49688 SyS_pwritev 3 49688 NULL
111420 +__copy_from_user_nocheck_49699 __copy_from_user_nocheck 0-3 49699 NULL
111421 +cx2341x_ctrl_new_menu_49700 cx2341x_ctrl_new_menu 3 49700 NULL
111422 +write_pool_49718 write_pool 3 49718 NULL
111423 +kvm_mmu_notifier_invalidate_page_49723 kvm_mmu_notifier_invalidate_page 3 49723 NULL
111424 +sep_create_dcb_dmatables_context_kernel_49728 sep_create_dcb_dmatables_context_kernel 6 49728 NULL
111425 +zd_usb_iowrite16v_49744 zd_usb_iowrite16v 3 49744 NULL
111426 +btrfs_chunk_num_stripes_49751 btrfs_chunk_num_stripes 0 49751 NULL
111427 +fuse_wr_pages_49753 fuse_wr_pages 0-1-2 49753 NULL
111428 +key_conf_keylen_read_49758 key_conf_keylen_read 3 49758 NULL
111429 +fuse_conn_waiting_read_49762 fuse_conn_waiting_read 3 49762 NULL
111430 +w83977af_fir_interrupt_49775 w83977af_fir_interrupt 0 49775 NULL
111431 +ceph_osdc_readpages_49789 ceph_osdc_readpages 0 49789 NULL
111432 +nfs4_acl_new_49806 nfs4_acl_new 1 49806 NULL
111433 +ntfs_copy_from_user_iovec_49829 ntfs_copy_from_user_iovec 3-6-0 49829 NULL
111434 +add_uuid_49831 add_uuid 4 49831 NULL
111435 +iraw_loop_49842 iraw_loop 0-1 49842 NULL
111436 +twl4030_write_49846 twl4030_write 2 49846 NULL
111437 +scsi_dispatch_cmd_entry_49848 scsi_dispatch_cmd_entry 3 49848 NULL
111438 +timeradd_entry_49850 timeradd_entry 3 49850 NULL
111439 +fiemap_count_to_size_49869 fiemap_count_to_size 0-1 49869 NULL
111440 +sctp_setsockopt_bindx_49870 sctp_setsockopt_bindx 3 49870 NULL
111441 +ceph_get_caps_49890 ceph_get_caps 0 49890 NULL
111442 +osc_brw_49896 osc_brw 4 49896 NULL
111443 +config_ep_by_speed_49939 config_ep_by_speed 0 49939 NULL
111444 +ieee80211_if_fmt_dtim_count_49987 ieee80211_if_fmt_dtim_count 3 49987 NULL
111445 +drm_buffer_copy_from_user_49990 drm_buffer_copy_from_user 3 49990 NULL
111446 +l2cap_chan_send_49995 l2cap_chan_send 3 49995 NULL
111447 +dn_mss_from_pmtu_50011 dn_mss_from_pmtu 0-2 50011 NULL
111448 +isdn_read_50021 isdn_read 3 50021 NULL
111449 +mdc_rename_pack_50023 mdc_rename_pack 4-6 50023 NULL
111450 +ioread8_50049 ioread8 0 50049 NULL
111451 +fuse_conn_max_background_write_50061 fuse_conn_max_background_write 3 50061 NULL
111452 +__kfifo_dma_in_prepare_50081 __kfifo_dma_in_prepare 4 50081 NULL
111453 +dev_set_alias_50084 dev_set_alias 3 50084 NULL
111454 +libcfs_ioctl_popdata_50087 libcfs_ioctl_popdata 3 50087 NULL
111455 +sock_setsockopt_50088 sock_setsockopt 5 50088 NULL
111456 +altera_swap_dr_50090 altera_swap_dr 2 50090 NULL
111457 +android_set_cntry_50100 android_set_cntry 0 50100 NULL
111458 +read_file_slot_50111 read_file_slot 3 50111 NULL
111459 +rx_streaming_interval_write_50120 rx_streaming_interval_write 3 50120 NULL
111460 +jfs_direct_IO_50125 jfs_direct_IO 4 50125 NULL
111461 +SYSC_preadv_50134 SYSC_preadv 3 50134 NULL
111462 +copy_items_50140 copy_items 6 50140 NULL
111463 +tx_frag_need_fragmentation_read_50153 tx_frag_need_fragmentation_read 3 50153 NULL
111464 +kmalloc_node_50163 kmalloc_node 1 50163 NULL
111465 +rx_filter_ibss_filter_read_50167 rx_filter_ibss_filter_read 3 50167 NULL
111466 +ahd_probe_stack_size_50168 ahd_probe_stack_size 0 50168 NULL
111467 +odev_update_50169 odev_update 2 50169 NULL
111468 +ubi_resize_volume_50172 ubi_resize_volume 2 50172 NULL nohasharray
111469 +ieee80211_if_fmt_dot11MeshHWMPRannInterval_50172 ieee80211_if_fmt_dot11MeshHWMPRannInterval 3 50172 &ubi_resize_volume_50172
111470 +cfg80211_roamed_bss_50198 cfg80211_roamed_bss 4-6 50198 NULL
111471 +cyttsp4_probe_50201 cyttsp4_probe 4 50201 NULL
111472 +rx_rx_timeout_wa_read_50204 rx_rx_timeout_wa_read 3 50204 NULL
111473 +mthca_buddy_init_50206 mthca_buddy_init 2 50206 NULL
111474 +l2cap_sock_setsockopt_50207 l2cap_sock_setsockopt 5 50207 NULL
111475 +mon_bin_compat_ioctl_50234 mon_bin_compat_ioctl 3 50234 NULL
111476 +sg_kmalloc_50240 sg_kmalloc 1 50240 NULL
111477 +rxrpc_setsockopt_50286 rxrpc_setsockopt 5 50286 NULL
111478 +soc_codec_reg_show_50302 soc_codec_reg_show 0-3 50302 NULL
111479 +SYSC_flistxattr_50307 SYSC_flistxattr 3 50307 NULL
111480 +SYSC_sched_setaffinity_50310 SYSC_sched_setaffinity 2 50310 NULL
111481 +soc_camera_read_50319 soc_camera_read 3 50319 NULL
111482 +do_launder_page_50329 do_launder_page 0 50329 NULL
111483 +nouveau_engine_create__50331 nouveau_engine_create_ 7 50331 NULL
111484 +lpfc_idiag_pcicfg_read_50334 lpfc_idiag_pcicfg_read 3 50334 NULL
111485 +snd_pcm_lib_writev_50337 snd_pcm_lib_writev 0-3 50337 NULL
111486 +tpm_read_50344 tpm_read 3 50344 NULL
111487 +isdn_ppp_read_50356 isdn_ppp_read 4 50356 NULL
111488 +iwl_dbgfs_echo_test_write_50362 iwl_dbgfs_echo_test_write 3 50362 NULL
111489 +xfrm_send_migrate_50365 xfrm_send_migrate 5 50365 NULL
111490 +roccat_common2_receive_50369 roccat_common2_receive 4 50369 NULL
111491 +sl_alloc_bufs_50380 sl_alloc_bufs 2 50380 NULL
111492 +l2tp_ip_sendmsg_50411 l2tp_ip_sendmsg 4 50411 NULL
111493 +iscsi_create_conn_50425 iscsi_create_conn 2 50425 NULL
111494 +validate_acl_mac_addrs_50429 validate_acl_mac_addrs 0 50429 NULL
111495 +btrfs_error_discard_extent_50444 btrfs_error_discard_extent 2 50444 NULL
111496 +pgctrl_write_50453 pgctrl_write 3 50453 NULL
111497 +device_create_sys_dev_entry_50458 device_create_sys_dev_entry 0 50458 NULL
111498 +cfs_size_round_50472 cfs_size_round 0-1 50472 NULL
111499 +cdrom_read_cdda_50478 cdrom_read_cdda 4 50478 NULL
111500 +mei_io_cb_alloc_req_buf_50493 mei_io_cb_alloc_req_buf 2 50493 NULL
111501 +pwr_rcvd_awake_beacons_read_50505 pwr_rcvd_awake_beacons_read 3 50505 NULL
111502 +ath6kl_set_ap_probe_resp_ies_50539 ath6kl_set_ap_probe_resp_ies 3 50539 NULL
111503 +usbat_flash_write_data_50553 usbat_flash_write_data 4 50553 NULL
111504 +fat_readpages_50582 fat_readpages 4 50582 NULL
111505 +iwl_dbgfs_missed_beacon_read_50584 iwl_dbgfs_missed_beacon_read 3 50584 NULL
111506 +xillybus_write_50605 xillybus_write 3 50605 NULL
111507 +rx_rx_checksum_result_read_50617 rx_rx_checksum_result_read 3 50617 NULL
111508 +sparse_early_usemaps_alloc_node_50623 sparse_early_usemaps_alloc_node 4 50623 NULL
111509 +simple_transaction_get_50633 simple_transaction_get 3 50633 NULL
111510 +ath6kl_tm_rx_event_50664 ath6kl_tm_rx_event 3 50664 NULL
111511 +bnad_debugfs_read_50665 bnad_debugfs_read 3 50665 NULL
111512 +prism2_read_fid_reg_50689 prism2_read_fid_reg 0 50689 NULL
111513 +xfs_growfs_get_hdr_buf_50697 xfs_growfs_get_hdr_buf 3 50697 NULL
111514 +dev_mem_read_50706 dev_mem_read 3 50706 NULL
111515 +blk_check_plugged_50736 blk_check_plugged 3 50736 NULL
111516 +__ext3_get_inode_loc_50744 __ext3_get_inode_loc 0 50744 NULL
111517 +ocfs2_xattr_block_get_50773 ocfs2_xattr_block_get 0 50773 NULL
111518 +tm6000_read_write_usb_50774 tm6000_read_write_usb 7 50774 NULL
111519 +bio_alloc_map_data_50782 bio_alloc_map_data 1-2 50782 NULL
111520 +tpm_write_50798 tpm_write 3 50798 NULL
111521 +write_flush_50803 write_flush 3 50803 NULL
111522 +dvb_play_50814 dvb_play 3 50814 NULL
111523 +dpcm_show_state_50827 dpcm_show_state 0 50827 NULL
111524 +SetArea_50835 SetArea 4 50835 NULL
111525 +videobuf_dma_init_user_50839 videobuf_dma_init_user 4-3 50839 NULL
111526 +carl9170_debugfs_write_50857 carl9170_debugfs_write 3 50857 NULL
111527 +SyS_lgetxattr_50889 SyS_lgetxattr 4 50889 NULL
111528 +netlbl_secattr_catmap_walk_rng_50894 netlbl_secattr_catmap_walk_rng 0-2 50894 NULL
111529 +__bdev_writeseg_50903 __bdev_writeseg 4 50903 NULL
111530 +xfs_iext_remove_50909 xfs_iext_remove 3 50909 NULL
111531 +blk_rq_cur_sectors_50910 blk_rq_cur_sectors 0 50910 NULL
111532 +hash_recvmsg_50924 hash_recvmsg 4 50924 NULL
111533 +chd_dec_fetch_cdata_50926 chd_dec_fetch_cdata 3 50926 NULL
111534 +show_device_status_50947 show_device_status 0 50947 NULL
111535 +irq_timeout_write_50950 irq_timeout_write 3 50950 NULL
111536 +virtio_cread16_50951 virtio_cread16 0 50951 NULL
111537 +sdio_uart_write_50954 sdio_uart_write 3 50954 NULL
111538 +SyS_setxattr_50957 SyS_setxattr 4 50957 NULL
111539 +iwl_statistics_flag_50981 iwl_statistics_flag 3-0 50981 NULL
111540 +timeout_write_50991 timeout_write 3 50991 NULL
111541 +proc_write_51003 proc_write 3 51003 NULL
111542 +jbd2_journal_extend_51012 jbd2_journal_extend 2 51012 NULL
111543 +lbs_dev_info_51023 lbs_dev_info 3 51023 NULL
111544 +fuse_conn_congestion_threshold_read_51028 fuse_conn_congestion_threshold_read 3 51028 NULL
111545 +BcmGetSectionValEndOffset_51039 BcmGetSectionValEndOffset 0 51039 NULL
111546 +dump_midi_51040 dump_midi 3 51040 NULL
111547 +usb_get_descriptor_51041 usb_get_descriptor 0 51041 NULL
111548 +srpt_alloc_ioctx_51042 srpt_alloc_ioctx 2-3 51042 NULL
111549 +do_arpt_set_ctl_51053 do_arpt_set_ctl 4 51053 NULL
111550 +wusb_prf_64_51065 wusb_prf_64 7 51065 NULL
111551 +jbd2_journal_init_revoke_51088 jbd2_journal_init_revoke 2 51088 NULL
111552 +__ocfs2_find_path_51096 __ocfs2_find_path 0 51096 NULL
111553 +ti_recv_51110 ti_recv 3 51110 NULL
111554 +uasp_prepare_r_request_51124 uasp_prepare_r_request 0 51124 NULL
111555 +nfs_map_name_to_uid_51132 nfs_map_name_to_uid 3 51132 NULL
111556 +alloc_rtllib_51136 alloc_rtllib 1 51136 NULL
111557 +simple_xattr_set_51140 simple_xattr_set 4 51140 NULL
111558 +xfs_trans_get_efd_51148 xfs_trans_get_efd 3 51148 NULL
111559 +nf_ct_ext_create_51232 nf_ct_ext_create 3 51232 NULL
111560 +snd_pcm_write_51235 snd_pcm_write 3 51235 NULL
111561 +drm_property_create_51239 drm_property_create 4 51239 NULL
111562 +__mxt_read_reg_51249 __mxt_read_reg 0 51249 NULL
111563 +st_read_51251 st_read 3 51251 NULL
111564 +compat_dccp_setsockopt_51263 compat_dccp_setsockopt 5 51263 NULL
111565 +target_alloc_sgl_51264 target_alloc_sgl 3 51264 NULL
111566 +dvb_audio_write_51275 dvb_audio_write 3 51275 NULL
111567 +ipwireless_network_packet_received_51277 ipwireless_network_packet_received 4 51277 NULL
111568 +pvr2_std_id_to_str_51288 pvr2_std_id_to_str 2 51288 NULL
111569 +bnad_debugfs_read_regrd_51308 bnad_debugfs_read_regrd 3 51308 NULL
111570 +init_map_ipmac_51317 init_map_ipmac 5 51317 NULL
111571 +alloc_hippi_dev_51320 alloc_hippi_dev 1 51320 NULL
111572 +ext2_xattr_get_51327 ext2_xattr_get 0 51327 NULL
111573 +alloc_smp_req_51337 alloc_smp_req 1 51337 NULL
111574 +ipw_get_event_log_len_51341 ipw_get_event_log_len 0 51341 NULL
111575 +ieee80211_if_fmt_estab_plinks_51370 ieee80211_if_fmt_estab_plinks 3 51370 NULL
111576 +radeon_kms_compat_ioctl_51371 radeon_kms_compat_ioctl 2 51371 NULL
111577 +ceph_sync_read_51410 ceph_sync_read 3-0 51410 NULL
111578 +blk_register_region_51424 blk_register_region 1-2 51424 NULL
111579 +mwifiex_rdeeprom_read_51429 mwifiex_rdeeprom_read 3 51429 NULL
111580 +hfsplus_brec_read_51436 hfsplus_brec_read 0 51436 NULL
111581 +ieee80211_if_read_dot11MeshHWMPRootMode_51441 ieee80211_if_read_dot11MeshHWMPRootMode 3 51441 NULL
111582 +print_devstats_dot11ACKFailureCount_51443 print_devstats_dot11ACKFailureCount 3 51443 NULL
111583 +____alloc_ei_netdev_51475 ____alloc_ei_netdev 1 51475 NULL
111584 +xfs_buf_get_uncached_51477 xfs_buf_get_uncached 2 51477 NULL
111585 +kvm_fetch_guest_virt_51493 kvm_fetch_guest_virt 4-2 51493 NULL
111586 +ieee80211_if_write_uapsd_queues_51526 ieee80211_if_write_uapsd_queues 3 51526 NULL
111587 +__alloc_eip_netdev_51549 __alloc_eip_netdev 1 51549 NULL
111588 +batadv_tt_prepare_tvlv_local_data_51568 batadv_tt_prepare_tvlv_local_data 0 51568 NULL
111589 +ixgb_get_eeprom_len_51586 ixgb_get_eeprom_len 0 51586 NULL
111590 +aac_convert_sgraw2_51598 aac_convert_sgraw2 4 51598 NULL
111591 +table_size_to_number_of_entries_51613 table_size_to_number_of_entries 0-1 51613 NULL
111592 +extent_fiemap_51621 extent_fiemap 3 51621 NULL
111593 +sctp_auth_create_key_51641 sctp_auth_create_key 1 51641 NULL
111594 +iscsi_create_session_51647 iscsi_create_session 3 51647 NULL
111595 +ps_upsd_utilization_read_51669 ps_upsd_utilization_read 3 51669 NULL
111596 +sctp_setsockopt_associnfo_51684 sctp_setsockopt_associnfo 3 51684 NULL
111597 +host_mapping_level_51696 host_mapping_level 0 51696 NULL
111598 +sel_write_access_51704 sel_write_access 3 51704 NULL
111599 +tty_cdev_add_51714 tty_cdev_add 2-4 51714 NULL
111600 +v9fs_alloc_rdir_buf_51716 v9fs_alloc_rdir_buf 2 51716 NULL
111601 +drm_compat_ioctl_51717 drm_compat_ioctl 2 51717 NULL
111602 +sg_read_oxfer_51724 sg_read_oxfer 3 51724 NULL
111603 +cm4040_read_51732 cm4040_read 3 51732 NULL
111604 +get_user_pages_fast_51751 get_user_pages_fast 0 51751 NULL
111605 +ifx_spi_insert_flip_string_51752 ifx_spi_insert_flip_string 3 51752 NULL
111606 +if_write_51756 if_write 3 51756 NULL
111607 +qib_alloc_devdata_51819 qib_alloc_devdata 2 51819 NULL
111608 +buffer_from_user_51826 buffer_from_user 3 51826 NULL
111609 +ioread32_51847 ioread32 0 51847 NULL nohasharray
111610 +read_file_tgt_tx_stats_51847 read_file_tgt_tx_stats 3 51847 &ioread32_51847
111611 +do_readv_writev_51849 do_readv_writev 4 51849 NULL
111612 +SYSC_sendto_51852 SYSC_sendto 6 51852 NULL
111613 +bm_page_io_async_51858 bm_page_io_async 2 51858 NULL
111614 +pointer_size_read_51863 pointer_size_read 3 51863 NULL
111615 +get_indirect_ea_51869 get_indirect_ea 4 51869 NULL
111616 +user_read_51881 user_read 3 51881 NULL
111617 +dbAdjCtl_51888 dbAdjCtl 0 51888 NULL
111618 +SyS_mq_timedsend_51896 SyS_mq_timedsend 3 51896 NULL
111619 +wmi_set_ie_51919 wmi_set_ie 3 51919 NULL
111620 +dbg_status_buf_51930 dbg_status_buf 2 51930 NULL
111621 +__tcp_mtu_to_mss_51938 __tcp_mtu_to_mss 0-2 51938 NULL
111622 +xfrm_alg_len_51940 xfrm_alg_len 0 51940 NULL
111623 +scsi_get_vpd_page_51951 scsi_get_vpd_page 4 51951 NULL
111624 +snd_mask_min_51969 snd_mask_min 0 51969 NULL
111625 +__blkdev_get_51972 __blkdev_get 0 51972 NULL
111626 +get_zone_51981 get_zone 0-1 51981 NULL
111627 +ath6kl_sdio_alloc_prep_scat_req_51986 ath6kl_sdio_alloc_prep_scat_req 2 51986 NULL
111628 +_c4iw_write_mem_dma_51991 _c4iw_write_mem_dma 3 51991 NULL
111629 +dwc3_mode_write_51997 dwc3_mode_write 3 51997 NULL
111630 +skb_copy_datagram_from_iovec_52014 skb_copy_datagram_from_iovec 4-2-5 52014 NULL
111631 +rdmalt_52022 rdmalt 0 52022 NULL
111632 +override_release_52032 override_release 2 52032 NULL
111633 +end_port_52042 end_port 0 52042 NULL
111634 +dma_rx_errors_read_52045 dma_rx_errors_read 3 52045 NULL
111635 +msnd_fifo_write_52052 msnd_fifo_write 0-3 52052 NULL
111636 +dvb_ringbuffer_avail_52057 dvb_ringbuffer_avail 0 52057 NULL
111637 +__fuse_request_alloc_52060 __fuse_request_alloc 1 52060 NULL
111638 +isofs_readpages_52067 isofs_readpages 4 52067 NULL
111639 +nsm_get_handle_52089 nsm_get_handle 4 52089 NULL
111640 +o2net_debug_read_52105 o2net_debug_read 3 52105 NULL
111641 +split_scan_timeout_write_52128 split_scan_timeout_write 3 52128 NULL
111642 +retry_count_read_52129 retry_count_read 3 52129 NULL
111643 +gdm_usb_hci_send_52138 gdm_usb_hci_send 3 52138 NULL
111644 +sub_alloc_52140 sub_alloc 0 52140 NULL
111645 +hysdn_conf_write_52145 hysdn_conf_write 3 52145 NULL
111646 +htable_size_52148 htable_size 0-1 52148 NULL
111647 +smk_write_load2_52155 smk_write_load2 3 52155 NULL
111648 +ieee80211_if_read_dot11MeshRetryTimeout_52168 ieee80211_if_read_dot11MeshRetryTimeout 3 52168 NULL
111649 +mga_compat_ioctl_52170 mga_compat_ioctl 2 52170 NULL
111650 +print_prefix_52176 print_prefix 0 52176 NULL
111651 +proc_pid_readlink_52186 proc_pid_readlink 3 52186 NULL
111652 +vmci_qp_broker_alloc_52216 vmci_qp_broker_alloc 6-5 52216 NULL
111653 +fuse_request_alloc_52243 fuse_request_alloc 1 52243 NULL nohasharray
111654 +xfs_iomap_eof_align_last_fsb_52243 xfs_iomap_eof_align_last_fsb 3 52243 &fuse_request_alloc_52243
111655 +mdiobus_alloc_size_52259 mdiobus_alloc_size 1 52259 NULL
111656 +shrink_slab_52261 shrink_slab 2 52261 NULL
111657 +sisusbcon_do_font_op_52271 sisusbcon_do_font_op 9 52271 NULL
111658 +handle_supp_msgs_52284 handle_supp_msgs 4 52284 NULL
111659 +kobject_set_name_vargs_52309 kobject_set_name_vargs 0 52309 NULL
111660 +read_file_reset_52310 read_file_reset 3 52310 NULL
111661 +request_asymmetric_key_52317 request_asymmetric_key 2-4 52317 NULL
111662 +hwflags_read_52318 hwflags_read 3 52318 NULL
111663 +test_unaligned_bulk_52333 test_unaligned_bulk 3 52333 NULL
111664 +hur_len_52339 hur_len 0 52339 NULL
111665 +bytes_to_frames_52362 bytes_to_frames 0-2 52362 NULL
111666 +copy_entries_to_user_52367 copy_entries_to_user 1 52367 NULL
111667 +iwl_dump_fh_52371 iwl_dump_fh 0 52371 NULL
111668 +hfsplus_find_attr_52374 hfsplus_find_attr 0 52374 NULL
111669 +mq_emit_config_values_52378 mq_emit_config_values 3 52378 NULL
111670 +isdn_writebuf_stub_52383 isdn_writebuf_stub 4 52383 NULL
111671 +jfs_setxattr_52389 jfs_setxattr 4 52389 NULL
111672 +aer_inject_write_52399 aer_inject_write 3 52399 NULL
111673 +cgroup_file_write_52417 cgroup_file_write 3 52417 NULL
111674 +line6_midibuf_init_52425 line6_midibuf_init 2 52425 NULL
111675 +hso_serial_common_create_52428 hso_serial_common_create 4 52428 NULL
111676 +delay_status_52431 delay_status 5 52431 NULL
111677 +ath6kl_delete_qos_write_52435 ath6kl_delete_qos_write 3 52435 NULL
111678 +ieee80211_if_fmt_num_sta_ps_52438 ieee80211_if_fmt_num_sta_ps 3 52438 NULL
111679 +acpi_nvs_for_each_region_52448 acpi_nvs_for_each_region 0 52448 NULL
111680 +alauda_read_data_52452 alauda_read_data 3 52452 NULL
111681 +ieee80211_alloc_txb_52477 ieee80211_alloc_txb 1 52477 NULL
111682 +usb_tranzport_write_52479 usb_tranzport_write 3 52479 NULL
111683 +ocfs2_extend_no_holes_52483 ocfs2_extend_no_holes 3-4 52483 NULL
111684 +fd_do_rw_52495 fd_do_rw 3 52495 NULL
111685 +int_tasklet_entry_52500 int_tasklet_entry 3 52500 NULL
111686 +lmv_get_easize_52504 lmv_get_easize 0 52504 NULL
111687 +pm_qos_power_write_52513 pm_qos_power_write 3 52513 NULL
111688 +bt_sock_stream_recvmsg_52518 bt_sock_stream_recvmsg 4 52518 NULL
111689 +dup_variable_bug_52525 dup_variable_bug 3 52525 NULL
111690 +raw_recvmsg_52529 raw_recvmsg 4 52529 NULL
111691 +dccpprobe_read_52549 dccpprobe_read 3 52549 NULL
111692 +debug_level_proc_write_52572 debug_level_proc_write 3 52572 NULL
111693 +isku_sysfs_read_macro_52587 isku_sysfs_read_macro 6 52587 NULL
111694 +SyS_setsockopt_52610 SyS_setsockopt 5 52610 NULL
111695 +ll_sa_entry_alloc_52611 ll_sa_entry_alloc 4 52611 NULL
111696 +tps80031_writes_52638 tps80031_writes 3-4 52638 NULL
111697 +brcmf_sdio_assert_info_52653 brcmf_sdio_assert_info 4 52653 NULL
111698 +nvme_queue_extra_52661 nvme_queue_extra 0-1 52661 NULL
111699 +SYSC_gethostname_52677 SYSC_gethostname 2 52677 NULL
111700 +nvd0_disp_pioc_create__52693 nvd0_disp_pioc_create_ 5 52693 NULL
111701 +nouveau_client_create__52715 nouveau_client_create_ 5 52715 NULL
111702 +__dm_stat_bio_52722 __dm_stat_bio 3 52722 NULL
111703 +cx25840_ir_rx_read_52724 cx25840_ir_rx_read 3 52724 NULL
111704 +blkcipher_next_slow_52733 blkcipher_next_slow 3-4 52733 NULL
111705 +relay_alloc_page_array_52735 relay_alloc_page_array 1 52735 NULL
111706 +hfcsusb_rx_frame_52745 hfcsusb_rx_frame 3 52745 NULL
111707 +carl9170_debugfs_vif_dump_read_52755 carl9170_debugfs_vif_dump_read 3 52755 NULL
111708 +ieee80211_if_read_beacon_timeout_52756 ieee80211_if_read_beacon_timeout 3 52756 NULL
111709 +nvme_trans_ext_inq_page_52776 nvme_trans_ext_inq_page 3 52776 NULL
111710 +pwr_rcvd_beacons_read_52836 pwr_rcvd_beacons_read 3 52836 NULL
111711 +ext2_xattr_set_acl_52857 ext2_xattr_set_acl 4 52857 NULL
111712 +mon_bin_get_event_52863 mon_bin_get_event 4-6 52863 NULL
111713 +twl6030_gpadc_write_52867 twl6030_gpadc_write 1 52867 NULL
111714 +qib_decode_6120_err_52876 qib_decode_6120_err 3 52876 NULL
111715 +twlreg_write_52880 twlreg_write 3 52880 NULL
111716 +pvr2_ctrl_value_to_sym_internal_52881 pvr2_ctrl_value_to_sym_internal 5 52881 NULL
111717 +cache_read_procfs_52882 cache_read_procfs 3 52882 NULL
111718 +kvm_kvzalloc_52894 kvm_kvzalloc 1 52894 NULL
111719 +dio_bio_reap_52913 dio_bio_reap 0 52913 NULL
111720 +__kfifo_out_peek_r_52919 __kfifo_out_peek_r 3 52919 NULL
111721 +iblock_get_bio_52936 iblock_get_bio 3 52936 NULL
111722 +__nodes_remap_52951 __nodes_remap 5 52951 NULL
111723 +send_packet_52960 send_packet 4 52960 NULL
111724 +ieee80211_if_fmt_fwded_mcast_52961 ieee80211_if_fmt_fwded_mcast 3 52961 NULL
111725 +tx_tx_exch_read_52986 tx_tx_exch_read 3 52986 NULL
111726 +num_node_state_52989 num_node_state 0 52989 NULL
111727 +efivarfs_file_write_53000 efivarfs_file_write 3 53000 NULL
111728 +uasp_alloc_stream_res_53015 uasp_alloc_stream_res 0 53015 NULL
111729 +btrfs_free_and_pin_reserved_extent_53016 btrfs_free_and_pin_reserved_extent 2 53016 NULL
111730 +tx_tx_exch_pending_read_53018 tx_tx_exch_pending_read 3 53018 NULL
111731 +bio_cur_bytes_53037 bio_cur_bytes 0 53037 NULL
111732 +regcache_lzo_block_count_53056 regcache_lzo_block_count 0 53056 NULL
111733 +cfi_read_query_53066 cfi_read_query 0 53066 NULL
111734 +iwl_dbgfs_interrupt_write_53069 iwl_dbgfs_interrupt_write 3 53069 NULL
111735 +mwifiex_debug_read_53074 mwifiex_debug_read 3 53074 NULL
111736 +mic_virtio_copy_from_user_53107 mic_virtio_copy_from_user 3 53107 NULL
111737 +verity_status_53120 verity_status 5 53120 NULL
111738 +brcmf_usb_dl_cmd_53130 brcmf_usb_dl_cmd 4 53130 NULL
111739 +ps_poll_ps_poll_max_ap_turn_read_53140 ps_poll_ps_poll_max_ap_turn_read 3 53140 NULL
111740 +ieee80211_bss_info_update_53170 ieee80211_bss_info_update 4 53170 NULL
111741 +btrfs_io_bio_alloc_53179 btrfs_io_bio_alloc 2 53179 NULL
111742 +clear_capture_buf_53192 clear_capture_buf 2 53192 NULL
111743 +tx_tx_start_data_read_53219 tx_tx_start_data_read 3 53219 NULL
111744 +ptlrpc_lprocfs_req_history_max_seq_write_53243 ptlrpc_lprocfs_req_history_max_seq_write 3 53243 NULL
111745 +hfsplus_xattr_set_posix_acl_53249 hfsplus_xattr_set_posix_acl 4 53249 NULL
111746 +xfs_trans_read_buf_map_53258 xfs_trans_read_buf_map 5 53258 NULL
111747 +wil_write_file_ssid_53266 wil_write_file_ssid 3 53266 NULL
111748 +btrfs_file_extent_num_bytes_53269 btrfs_file_extent_num_bytes 0 53269 NULL
111749 +ftrace_profile_write_53327 ftrace_profile_write 3 53327 NULL
111750 +find_nr_power_limit_53330 find_nr_power_limit 0 53330 NULL
111751 +gsm_control_reply_53333 gsm_control_reply 4 53333 NULL
111752 +vm_mmap_53339 vm_mmap 0 53339 NULL
111753 +read_6120_creg32_53363 read_6120_creg32 0 53363 NULL
111754 +sock_setbindtodevice_53369 sock_setbindtodevice 3 53369 NULL
111755 +get_random_bytes_arch_53370 get_random_bytes_arch 2 53370 NULL
111756 +isr_cmd_cmplt_read_53439 isr_cmd_cmplt_read 3 53439 NULL
111757 +mwifiex_info_read_53447 mwifiex_info_read 3 53447 NULL
111758 +apei_exec_run_optional_53452 apei_exec_run_optional 0 53452 NULL
111759 +paging64_prefetch_gpte_53468 paging64_prefetch_gpte 4 53468 NULL
111760 +ima_write_template_field_data_53475 ima_write_template_field_data 2 53475 NULL
111761 +iowarrior_read_53483 iowarrior_read 3 53483 NULL
111762 +osd_req_write_kern_53486 osd_req_write_kern 5 53486 NULL
111763 +do_verify_xattr_datum_53499 do_verify_xattr_datum 0 53499 NULL
111764 +snd_pcm_format_physical_width_53505 snd_pcm_format_physical_width 0 53505 NULL
111765 +dbAllocNext_53506 dbAllocNext 0 53506 NULL
111766 +ocfs2_xattr_set_acl_53508 ocfs2_xattr_set_acl 4 53508 NULL
111767 +check_acl_53512 check_acl 0 53512 NULL
111768 +nft_data_dump_53549 nft_data_dump 5 53549 NULL
111769 +SYSC_bind_53582 SYSC_bind 3 53582 NULL
111770 +cifs_utf16_bytes_53593 cifs_utf16_bytes 0 53593 NULL
111771 +proc_uid_map_write_53596 proc_uid_map_write 3 53596 NULL
111772 +pfkey_recvmsg_53604 pfkey_recvmsg 4 53604 NULL
111773 +___alloc_bootmem_nopanic_53626 ___alloc_bootmem_nopanic 1 53626 NULL
111774 +xd_write_multiple_pages_53633 xd_write_multiple_pages 6-5 53633 NULL
111775 +ccid_getsockopt_builtin_ccids_53634 ccid_getsockopt_builtin_ccids 2 53634 NULL
111776 +nr_sendmsg_53656 nr_sendmsg 4 53656 NULL
111777 +fuse_fill_write_pages_53682 fuse_fill_write_pages 0-4 53682 NULL
111778 +v4l2_event_subscribe_53687 v4l2_event_subscribe 3 53687 NULL
111779 +bdev_logical_block_size_53690 bdev_logical_block_size 0 53690 NULL nohasharray
111780 +igb_alloc_q_vector_53690 igb_alloc_q_vector 4-6 53690 &bdev_logical_block_size_53690
111781 +find_overflow_devnum_53711 find_overflow_devnum 0 53711 NULL
111782 +bio_integrity_split_53714 bio_integrity_split 3 53714 NULL
111783 +__proc_debug_mb_53732 __proc_debug_mb 5 53732 NULL
111784 +wdm_write_53735 wdm_write 3 53735 NULL
111785 +amdtp_out_stream_get_max_payload_53755 amdtp_out_stream_get_max_payload 0 53755 NULL nohasharray
111786 +lpfc_idiag_queacc_read_qe_53755 lpfc_idiag_queacc_read_qe 0-2 53755 &amdtp_out_stream_get_max_payload_53755
111787 +ext2_acl_count_53773 ext2_acl_count 0-1 53773 NULL
111788 +__kfifo_dma_in_prepare_r_53792 __kfifo_dma_in_prepare_r 4-5 53792 NULL
111789 +qp_alloc_host_work_53798 qp_alloc_host_work 5-3 53798 NULL
111790 +regmap_raw_write_53803 regmap_raw_write 2-4 53803 NULL
111791 +lpfc_idiag_ctlacc_read_reg_53809 lpfc_idiag_ctlacc_read_reg 0-3 53809 NULL
111792 +nls_nullsize_53815 nls_nullsize 0 53815 NULL
111793 +setup_data_read_53822 setup_data_read 3 53822 NULL
111794 +pms_read_53873 pms_read 3 53873 NULL
111795 +ieee80211_if_fmt_dropped_frames_congestion_53883 ieee80211_if_fmt_dropped_frames_congestion 3 53883 NULL
111796 +SyS_setgroups_53900 SyS_setgroups 1 53900 NULL
111797 +batadv_tt_tvlv_ogm_handler_v1_53909 batadv_tt_tvlv_ogm_handler_v1 5 53909 NULL
111798 +usb_serial_generic_write_53927 usb_serial_generic_write 4 53927 NULL
111799 +ocfs2_make_clusters_writable_53938 ocfs2_make_clusters_writable 0 53938 NULL
111800 +idetape_chrdev_write_53976 idetape_chrdev_write 3 53976 NULL
111801 +__ocfs2_xattr_set_value_outside_53981 __ocfs2_xattr_set_value_outside 5 53981 NULL
111802 +ieee80211_if_fmt_dot11MeshHWMPperrMinInterval_53998 ieee80211_if_fmt_dot11MeshHWMPperrMinInterval 3 53998 NULL
111803 +hfsplus_attr_build_key_54013 hfsplus_attr_build_key 0 54013 NULL
111804 +snd_pcm_lib_write_transfer_54018 snd_pcm_lib_write_transfer 5-2-4 54018 NULL
111805 +mdc_kuc_write_54019 mdc_kuc_write 3 54019 NULL
111806 +ipxrtr_route_packet_54036 ipxrtr_route_packet 4 54036 NULL
111807 +batadv_tt_update_orig_54049 batadv_tt_update_orig 6-4 54049 NULL
111808 +pipeline_dec_packet_out_read_54052 pipeline_dec_packet_out_read 3 54052 NULL
111809 +nl80211_send_disconnected_54056 nl80211_send_disconnected 5 54056 NULL
111810 +rproc_state_read_54057 rproc_state_read 3 54057 NULL
111811 +_malloc_54077 _malloc 1 54077 NULL
111812 +bitmap_bitremap_54096 bitmap_bitremap 4 54096 NULL
111813 +altera_set_ir_pre_54103 altera_set_ir_pre 2 54103 NULL nohasharray
111814 +lustre_posix_acl_xattr_filter_54103 lustre_posix_acl_xattr_filter 2 54103 &altera_set_ir_pre_54103
111815 +__comedi_buf_write_alloc_54112 __comedi_buf_write_alloc 0-2 54112 NULL
111816 +strn_len_54122 strn_len 0 54122 NULL
111817 +isku_receive_54130 isku_receive 4 54130 NULL
111818 +isr_host_acknowledges_read_54136 isr_host_acknowledges_read 3 54136 NULL
111819 +irq_blk_threshold_write_54138 irq_blk_threshold_write 3 54138 NULL
111820 +memcpy_toiovec_54166 memcpy_toiovec 3 54166 NULL
111821 +nouveau_falcon_create__54169 nouveau_falcon_create_ 8 54169 NULL
111822 +p9_client_prepare_req_54175 p9_client_prepare_req 3 54175 NULL
111823 +do_sys_poll_54221 do_sys_poll 2 54221 NULL
111824 +__register_chrdev_54223 __register_chrdev 2-3 54223 NULL
111825 +pi_read_regr_54231 pi_read_regr 0 54231 NULL
111826 +mcp23s08_read_regs_54246 mcp23s08_read_regs 4 54246 NULL
111827 +reada_add_block_54247 reada_add_block 2 54247 NULL
111828 +xfs_dir2_sf_addname_hard_54254 xfs_dir2_sf_addname_hard 3 54254 NULL
111829 +ceph_msgpool_get_54258 ceph_msgpool_get 2 54258 NULL
111830 +audio_write_54261 audio_write 4 54261 NULL nohasharray
111831 +wusb_prf_54261 wusb_prf 7 54261 &audio_write_54261
111832 +mwifiex_getlog_read_54269 mwifiex_getlog_read 3 54269 NULL
111833 +kstrtou16_from_user_54274 kstrtou16_from_user 2 54274 NULL
111834 +tipc_multicast_54285 tipc_multicast 4 54285 NULL
111835 +altera_set_dr_post_54291 altera_set_dr_post 2 54291 NULL
111836 +dlm_alloc_pagevec_54296 dlm_alloc_pagevec 1 54296 NULL
111837 +reclaim_pages_54301 reclaim_pages 3 54301 NULL
111838 +sprintf_54306 sprintf 0 54306 NULL
111839 +bio_add_pc_page_54319 bio_add_pc_page 4 54319 NULL
111840 +br_fdb_fillbuf_54339 br_fdb_fillbuf 0 54339 NULL
111841 +__alloc_dev_table_54343 __alloc_dev_table 2 54343 NULL
111842 +__get_free_pages_54352 __get_free_pages 0 54352 NULL
111843 +tcf_hash_create_54360 tcf_hash_create 4 54360 NULL
111844 +read_file_credit_dist_stats_54367 read_file_credit_dist_stats 3 54367 NULL
111845 +vfs_readlink_54368 vfs_readlink 3 54368 NULL
111846 +do_dccp_setsockopt_54377 do_dccp_setsockopt 5 54377 NULL nohasharray
111847 +intel_sdvo_write_cmd_54377 intel_sdvo_write_cmd 4 54377 &do_dccp_setsockopt_54377
111848 +ah_alloc_tmp_54378 ah_alloc_tmp 3-2 54378 NULL
111849 +snd_pcm_oss_read2_54387 snd_pcm_oss_read2 3-0 54387 NULL
111850 +iwl_dbgfs_power_save_status_read_54392 iwl_dbgfs_power_save_status_read 3 54392 NULL
111851 +ll_ra_count_get_54410 ll_ra_count_get 3 54410 NULL
111852 +copy_gadget_strings_54417 copy_gadget_strings 2-3 54417 NULL
111853 +sparse_early_mem_maps_alloc_node_54485 sparse_early_mem_maps_alloc_node 4 54485 NULL
111854 +simple_strtoull_54493 simple_strtoull 0 54493 NULL
111855 +btrfs_ordered_sum_size_54509 btrfs_ordered_sum_size 0-2 54509 NULL
111856 +cgroup_write_X64_54514 cgroup_write_X64 5 54514 NULL
111857 +rfc4106_set_key_54519 rfc4106_set_key 3 54519 NULL
111858 +vmci_transport_dgram_enqueue_54525 vmci_transport_dgram_enqueue 4 54525 NULL
111859 +viacam_read_54526 viacam_read 3 54526 NULL
111860 +unix_dgram_connect_54535 unix_dgram_connect 3 54535 NULL
111861 +setsockopt_54539 setsockopt 5 54539 NULL
111862 +lbs_lowsnr_write_54549 lbs_lowsnr_write 3 54549 NULL
111863 +SYSC_setsockopt_54561 SYSC_setsockopt 5 54561 NULL
111864 +nfsd_vfs_write_54577 nfsd_vfs_write 6 54577 NULL
111865 +fw_iso_buffer_init_54582 fw_iso_buffer_init 3 54582 NULL
111866 +nvme_npages_54601 nvme_npages 0-1 54601 NULL
111867 +irq_pkt_threshold_write_54605 irq_pkt_threshold_write 3 54605 NULL
111868 +port_fops_write_54627 port_fops_write 3 54627 NULL
111869 +irq_timeout_read_54653 irq_timeout_read 3 54653 NULL
111870 +dns_resolver_read_54658 dns_resolver_read 3 54658 NULL
111871 +twl6030_interrupt_mask_54659 twl6030_interrupt_mask 2 54659 NULL
111872 +tdp_page_fault_54663 tdp_page_fault 2 54663 NULL
111873 +bus_add_device_54665 bus_add_device 0 54665 NULL
111874 +cw1200_queue_stats_init_54670 cw1200_queue_stats_init 2 54670 NULL
111875 +bio_kmalloc_54672 bio_kmalloc 2 54672 NULL
111876 +evm_read_key_54674 evm_read_key 3 54674 NULL
111877 +tipc_link_send_sections_fast_54689 tipc_link_send_sections_fast 3 54689 NULL
111878 +__btrfs_inc_extent_ref_54706 __btrfs_inc_extent_ref 7 54706 NULL
111879 +rfkill_fop_read_54711 rfkill_fop_read 3 54711 NULL
111880 +ocfs2_control_write_54737 ocfs2_control_write 3 54737 NULL
111881 +kzalloc_54740 kzalloc 1 54740 NULL
111882 +wep_iv_read_54744 wep_iv_read 3 54744 NULL
111883 +lpfc_idiag_pcicfg_write_54749 lpfc_idiag_pcicfg_write 3 54749 NULL
111884 +iio_event_chrdev_read_54757 iio_event_chrdev_read 3 54757 NULL
111885 +adis16480_show_firmware_date_54762 adis16480_show_firmware_date 3 54762 NULL
111886 +ldsem_atomic_update_54774 ldsem_atomic_update 1 54774 NULL
111887 +flexcop_device_kmalloc_54793 flexcop_device_kmalloc 1 54793 NULL
111888 +nfsd_write_54809 nfsd_write 6 54809 NULL
111889 +ar9287_dump_modal_eeprom_54814 ar9287_dump_modal_eeprom 3-2 54814 NULL
111890 +crypto_tfm_ctx_alignment_54815 crypto_tfm_ctx_alignment 0 54815 NULL nohasharray
111891 +kvzalloc_54815 kvzalloc 1 54815 &crypto_tfm_ctx_alignment_54815 nohasharray
111892 +aes_decrypt_fail_read_54815 aes_decrypt_fail_read 3 54815 &kvzalloc_54815
111893 +generic_perform_write_54832 generic_perform_write 3 54832 NULL
111894 +write_rio_54837 write_rio 3 54837 NULL
111895 +ext3_acl_from_disk_54839 ext3_acl_from_disk 2 54839 NULL nohasharray
111896 +nouveau_engctx_create__54839 nouveau_engctx_create_ 8 54839 &ext3_acl_from_disk_54839
111897 +ll_layout_conf_54841 ll_layout_conf 0 54841 NULL
111898 +ufx_ops_write_54848 ufx_ops_write 3 54848 NULL
111899 +printer_read_54851 printer_read 3 54851 NULL
111900 +alloc_ep_req_54860 alloc_ep_req 2 54860 NULL
111901 +broadsheet_spiflash_rewrite_sector_54864 broadsheet_spiflash_rewrite_sector 2 54864 NULL
111902 +prism_build_supp_rates_54865 prism_build_supp_rates 0 54865 NULL
111903 +iscsi_pool_init_54913 iscsi_pool_init 2-4 54913 NULL nohasharray
111904 +kobject_set_name_vargs_54913 kobject_set_name_vargs 0 54913 &iscsi_pool_init_54913
111905 +btrfs_stack_chunk_num_stripes_54923 btrfs_stack_chunk_num_stripes 0 54923 NULL
111906 +bio_add_page_54933 bio_add_page 0-3 54933 NULL
111907 +mxms_structlen_54939 mxms_structlen 0 54939 NULL
111908 +add_port_54941 add_port 2 54941 NULL
111909 +ath9k_dump_btcoex_54949 ath9k_dump_btcoex 3-0 54949 NULL
111910 +alauda_write_data_54967 alauda_write_data 3 54967 NULL
111911 +c4_add_card_54968 c4_add_card 3 54968 NULL
111912 +ext3_xattr_get_54989 ext3_xattr_get 0 54989 NULL
111913 +cx231xx_v4l2_read_55014 cx231xx_v4l2_read 3 55014 NULL
111914 +error_error_null_Frame_tx_start_read_55024 error_error_null_Frame_tx_start_read 3 55024 NULL
111915 +dgap_do_bios_load_55025 dgap_do_bios_load 3 55025 NULL
111916 +apei_exec_run_55075 apei_exec_run 0 55075 NULL
111917 +bitmap_storage_alloc_55077 bitmap_storage_alloc 2 55077 NULL
111918 +read_dma_55086 read_dma 3 55086 NULL
111919 +rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read_55106 rxpipe_beacon_buffer_thres_host_int_trig_rx_data_read 3 55106 NULL
111920 +crypto_ahash_setkey_55134 crypto_ahash_setkey 3 55134 NULL
111921 +filldir_55137 filldir 3 55137 NULL
111922 +ocfs2_truncate_file_55148 ocfs2_truncate_file 3 55148 NULL
111923 +npages_to_npools_55149 npages_to_npools 0-1 55149 NULL
111924 +ieee80211_if_read_uapsd_queues_55150 ieee80211_if_read_uapsd_queues 3 55150 NULL
111925 +mtd_get_fact_prot_info_55186 mtd_get_fact_prot_info 0 55186 NULL
111926 +sel_write_relabel_55195 sel_write_relabel 3 55195 NULL
111927 +sched_feat_write_55202 sched_feat_write 3 55202 NULL
111928 +ht40allow_map_read_55209 ht40allow_map_read 3 55209 NULL
111929 +__kfifo_dma_out_prepare_r_55211 __kfifo_dma_out_prepare_r 4-5 55211 NULL
111930 +do_raw_setsockopt_55215 do_raw_setsockopt 5 55215 NULL
111931 +qxl_alloc_client_monitors_config_55216 qxl_alloc_client_monitors_config 2 55216 NULL
111932 +nouveau_mc_create__55217 nouveau_mc_create_ 4 55217 NULL
111933 +dbAllocDmap_55227 dbAllocDmap 0 55227 NULL
111934 +memcpy_fromiovec_55247 memcpy_fromiovec 3 55247 NULL
111935 +lbs_failcount_write_55276 lbs_failcount_write 3 55276 NULL
111936 +persistent_ram_new_55286 persistent_ram_new 2-1 55286 NULL
111937 +rx_streaming_interval_read_55291 rx_streaming_interval_read 3 55291 NULL
111938 +lov_get_stripecnt_55297 lov_get_stripecnt 0-3 55297 NULL
111939 +gsm_control_modem_55303 gsm_control_modem 3 55303 NULL
111940 +wimax_msg_len_55304 wimax_msg_len 0 55304 NULL
111941 +qp_alloc_guest_work_55305 qp_alloc_guest_work 5-3 55305 NULL
111942 +__vxge_hw_vpath_initialize_55328 __vxge_hw_vpath_initialize 2 55328 NULL
111943 +vme_user_read_55338 vme_user_read 3 55338 NULL
111944 +__wa_xfer_setup_sizes_55342 __wa_xfer_setup_sizes 0 55342 NULL nohasharray
111945 +sctp_datamsg_from_user_55342 sctp_datamsg_from_user 4 55342 &__wa_xfer_setup_sizes_55342
111946 +tipc_send2name_55373 tipc_send2name 5 55373 NULL
111947 +cw1200_sdio_align_size_55391 cw1200_sdio_align_size 2 55391 NULL
111948 +iwl_dbgfs_plcp_delta_read_55407 iwl_dbgfs_plcp_delta_read 3 55407 NULL
111949 +sysfs_chmod_file_55408 sysfs_chmod_file 0 55408 NULL
111950 +si476x_radio_read_rds_blckcnt_blob_55427 si476x_radio_read_rds_blckcnt_blob 3 55427 NULL
111951 +sysfs_sd_setattr_55437 sysfs_sd_setattr 0 55437 NULL
111952 +__vxge_hw_channel_allocate_55462 __vxge_hw_channel_allocate 3 55462 NULL
111953 +cx23888_ir_rx_read_55473 cx23888_ir_rx_read 3 55473 NULL
111954 +snd_pcm_lib_write_55483 snd_pcm_lib_write 0-3 55483 NULL
111955 +i2o_pool_alloc_55485 i2o_pool_alloc 4 55485 NULL
111956 +batadv_tt_entries_55487 batadv_tt_entries 0-1 55487 NULL
111957 +ras_stride_increase_window_55501 ras_stride_increase_window 3 55501 NULL
111958 +tx_tx_done_int_template_read_55511 tx_tx_done_int_template_read 3 55511 NULL
111959 +ea_get_55522 ea_get 3-0 55522 NULL
111960 +buffer_size_55534 buffer_size 0 55534 NULL
111961 +set_msr_interception_55538 set_msr_interception 2 55538 NULL
111962 +tty_port_register_device_55543 tty_port_register_device 3 55543 NULL
111963 +dgap_do_config_load_55548 dgap_do_config_load 2 55548 NULL
111964 +hash_ipport6_expire_55549 hash_ipport6_expire 4 55549 NULL
111965 +dm_stats_list_55551 dm_stats_list 4 55551 NULL
111966 +__vdev_disk_physio_55568 __vdev_disk_physio 4 55568 NULL
111967 +add_partition_55588 add_partition 2 55588 NULL
111968 +kstrtou8_from_user_55599 kstrtou8_from_user 2 55599 NULL
111969 +SyS_keyctl_55602 SyS_keyctl 4 55602 NULL nohasharray
111970 +config_buf_55602 config_buf 0 55602 &SyS_keyctl_55602
111971 +macvtap_put_user_55609 macvtap_put_user 4 55609 NULL
111972 +selinux_setprocattr_55611 selinux_setprocattr 4 55611 NULL
111973 +edge_tty_recv_55622 edge_tty_recv 3 55622 NULL
111974 +pktgen_if_write_55628 pktgen_if_write 3 55628 NULL nohasharray
111975 +reiserfs_xattr_get_55628 reiserfs_xattr_get 0 55628 &pktgen_if_write_55628
111976 +osc_obd_max_pages_per_rpc_seq_write_55636 osc_obd_max_pages_per_rpc_seq_write 3 55636 NULL
111977 +xfs_bmbt_maxrecs_55649 xfs_bmbt_maxrecs 0-2 55649 NULL
111978 +lpfc_idiag_queinfo_read_55662 lpfc_idiag_queinfo_read 3 55662 NULL
111979 +il_dbgfs_tx_queue_read_55668 il_dbgfs_tx_queue_read 3 55668 NULL
111980 +get_info_55681 get_info 3 55681 NULL
111981 +iwl_dbgfs_plcp_delta_write_55682 iwl_dbgfs_plcp_delta_write 3 55682 NULL
111982 +echo_big_lmm_get_55690 echo_big_lmm_get 0 55690 NULL
111983 +genl_allocate_reserve_groups_55705 genl_allocate_reserve_groups 1 55705 NULL
111984 +pm8001_store_update_fw_55716 pm8001_store_update_fw 4 55716 NULL
111985 +ocfs2_lock_refcount_tree_55719 ocfs2_lock_refcount_tree 0 55719 NULL
111986 +tap_pwup_write_55723 tap_pwup_write 3 55723 NULL
111987 +__iio_allocate_kfifo_55738 __iio_allocate_kfifo 2 55738 NULL
111988 +set_local_name_55757 set_local_name 4 55757 NULL
111989 +strlen_55778 strlen 0 55778 NULL
111990 +set_spte_55783 set_spte 4-5 55783 NULL
111991 +req_bio_endio_55786 req_bio_endio 3 55786 NULL nohasharray
111992 +conf_read_55786 conf_read 3 55786 &req_bio_endio_55786
111993 +uwb_rc_neh_grok_event_55799 uwb_rc_neh_grok_event 3 55799 NULL
111994 +sb16_copy_from_user_55836 sb16_copy_from_user 10-6-7 55836 NULL
111995 +ip_hdrlen_55849 ip_hdrlen 0 55849 NULL
111996 +hcd_alloc_coherent_55862 hcd_alloc_coherent 5 55862 NULL
111997 +shmem_setxattr_55867 shmem_setxattr 4 55867 NULL
111998 +hsc_write_55875 hsc_write 3 55875 NULL
111999 +ramdisk_store_55885 ramdisk_store 4 55885 NULL
112000 +pm_qos_power_read_55891 pm_qos_power_read 3 55891 NULL
112001 +hash_ip4_expire_55911 hash_ip4_expire 4 55911 NULL
112002 +snd_pcm_hw_param_value_min_55917 snd_pcm_hw_param_value_min 0 55917 NULL
112003 +ext2_direct_IO_55932 ext2_direct_IO 4 55932 NULL
112004 +kvm_write_guest_virt_system_55944 kvm_write_guest_virt_system 4-2 55944 NULL
112005 +sel_read_policy_55947 sel_read_policy 3 55947 NULL
112006 +ceph_get_direct_page_vector_55956 ceph_get_direct_page_vector 2 55956 NULL
112007 +simple_read_from_buffer_55957 simple_read_from_buffer 2-5 55957 NULL
112008 +tx_tx_imm_resp_read_55964 tx_tx_imm_resp_read 3 55964 NULL
112009 +btrfs_clone_55977 btrfs_clone 5-3 55977 NULL
112010 +wa_xfer_create_subset_sg_55992 wa_xfer_create_subset_sg 3-2 55992 NULL
112011 +nvme_alloc_iod_56027 nvme_alloc_iod 1-2 56027 NULL
112012 +dccp_sendmsg_56058 dccp_sendmsg 4 56058 NULL
112013 +pscsi_get_bio_56103 pscsi_get_bio 1 56103 NULL
112014 +add_sysfs_param_56108 add_sysfs_param 0 56108 NULL
112015 +usb_alloc_stream_buffers_56123 usb_alloc_stream_buffers 3 56123 NULL
112016 +sel_read_handle_status_56139 sel_read_handle_status 3 56139 NULL
112017 +write_file_frameerrors_56145 write_file_frameerrors 3 56145 NULL
112018 +__i2c_transfer_56162 __i2c_transfer 0 56162 NULL
112019 +rawv6_setsockopt_56165 rawv6_setsockopt 5 56165 NULL
112020 +ath9k_dump_legacy_btcoex_56194 ath9k_dump_legacy_btcoex 3-0 56194 NULL
112021 +vring_add_indirect_56222 vring_add_indirect 4 56222 NULL
112022 +ocfs2_find_xe_in_bucket_56224 ocfs2_find_xe_in_bucket 0 56224 NULL
112023 +do_ipt_set_ctl_56238 do_ipt_set_ctl 4 56238 NULL
112024 +fd_copyin_56247 fd_copyin 3 56247 NULL
112025 +sk_rmem_schedule_56255 sk_rmem_schedule 3 56255 NULL
112026 +il4965_ucode_general_stats_read_56277 il4965_ucode_general_stats_read 3 56277 NULL
112027 +ieee80211_if_fmt_user_power_level_56283 ieee80211_if_fmt_user_power_level 3 56283 NULL
112028 +RESIZE_IF_NEEDED_56286 RESIZE_IF_NEEDED 2 56286 NULL
112029 +dvb_aplay_56296 dvb_aplay 3 56296 NULL
112030 +btmrvl_hscfgcmd_read_56303 btmrvl_hscfgcmd_read 3 56303 NULL
112031 +speakup_file_write_56310 speakup_file_write 3 56310 NULL
112032 +pipeline_pre_to_defrag_swi_read_56321 pipeline_pre_to_defrag_swi_read 3 56321 NULL
112033 +journal_init_revoke_table_56331 journal_init_revoke_table 1 56331 NULL
112034 +snd_rawmidi_read_56337 snd_rawmidi_read 3 56337 NULL
112035 +vxge_os_dma_malloc_async_56348 vxge_os_dma_malloc_async 3 56348 NULL
112036 +mite_device_bytes_transferred_56355 mite_device_bytes_transferred 0 56355 NULL
112037 +iov_iter_copy_from_user_atomic_56368 iov_iter_copy_from_user_atomic 4-0 56368 NULL
112038 +dev_read_56369 dev_read 3 56369 NULL
112039 +ath10k_read_simulate_fw_crash_56371 ath10k_read_simulate_fw_crash 3 56371 NULL
112040 +write_gssp_56404 write_gssp 3 56404 NULL
112041 +ocfs2_control_read_56405 ocfs2_control_read 3 56405 NULL
112042 +do_get_write_access_56410 do_get_write_access 0 56410 NULL
112043 +store_msg_56417 store_msg 3 56417 NULL
112044 +pppol2tp_sendmsg_56420 pppol2tp_sendmsg 4 56420 NULL
112045 +fl_create_56435 fl_create 5 56435 NULL
112046 +gnttab_map_56439 gnttab_map 2 56439 NULL
112047 +cx231xx_init_isoc_56453 cx231xx_init_isoc 3-2-4 56453 NULL
112048 +set_connectable_56458 set_connectable 4 56458 NULL
112049 +osd_req_list_partition_objects_56464 osd_req_list_partition_objects 5 56464 NULL
112050 +putused_user_56467 putused_user 3 56467 NULL
112051 +lbs_rdmac_write_56471 lbs_rdmac_write 3 56471 NULL
112052 +calc_linear_pos_56472 calc_linear_pos 0-3 56472 NULL
112053 +crypto_shash_alignmask_56486 crypto_shash_alignmask 0 56486 NULL
112054 +ieee80211_rx_mgmt_probe_beacon_56491 ieee80211_rx_mgmt_probe_beacon 3 56491 NULL
112055 +init_map_ip_56508 init_map_ip 5 56508 NULL
112056 +lustre_posix_acl_xattr_reduce_space_56512 lustre_posix_acl_xattr_reduce_space 3 56512 NULL
112057 +cfg80211_connect_result_56515 cfg80211_connect_result 4-6 56515 NULL
112058 +ip_options_get_56538 ip_options_get 4 56538 NULL
112059 +ll_wr_track_id_56544 ll_wr_track_id 2 56544 NULL
112060 +alloc_apertures_56561 alloc_apertures 1 56561 NULL
112061 +rs_sta_dbgfs_stats_table_read_56573 rs_sta_dbgfs_stats_table_read 3 56573 NULL
112062 +portcntrs_2_read_56586 portcntrs_2_read 3 56586 NULL
112063 +event_filter_write_56609 event_filter_write 3 56609 NULL
112064 +nvme_trans_log_temperature_56613 nvme_trans_log_temperature 3 56613 NULL
112065 +edac_device_create_block_56619 edac_device_create_block 0 56619 NULL
112066 +gather_array_56641 gather_array 3 56641 NULL
112067 +lookup_extent_backref_56644 lookup_extent_backref 9 56644 NULL
112068 +uvc_debugfs_stats_read_56651 uvc_debugfs_stats_read 3 56651 NULL
112069 +tg3_nvram_write_block_56666 tg3_nvram_write_block 3 56666 NULL
112070 +snd_gus_dram_read_56686 snd_gus_dram_read 4 56686 NULL
112071 +dvb_ringbuffer_read_user_56702 dvb_ringbuffer_read_user 3-0 56702 NULL
112072 +sta_flags_read_56710 sta_flags_read 3 56710 NULL
112073 +ipv6_getsockopt_sticky_56711 ipv6_getsockopt_sticky 5 56711 NULL
112074 +__wa_xfer_setup_segs_56725 __wa_xfer_setup_segs 2 56725 NULL
112075 +__copy_from_user_ll_56738 __copy_from_user_ll 0-3 56738 NULL
112076 +drm_agp_bind_pages_56748 drm_agp_bind_pages 3 56748 NULL
112077 +btrfsic_map_block_56751 btrfsic_map_block 2 56751 NULL
112078 +ttm_alloc_new_pages_56792 ttm_alloc_new_pages 5 56792 NULL
112079 +do_syslog_56807 do_syslog 3 56807 NULL
112080 +mtdchar_write_56831 mtdchar_write 3 56831 NULL
112081 +snd_rawmidi_kernel_write1_56847 snd_rawmidi_kernel_write1 4-0 56847 NULL
112082 +si476x_radio_read_agc_blob_56849 si476x_radio_read_agc_blob 3 56849 NULL
112083 +ext3_xattr_ibody_get_56880 ext3_xattr_ibody_get 0 56880 NULL
112084 +pvr2_debugifc_print_status_56890 pvr2_debugifc_print_status 3 56890 NULL
112085 +debug_debug3_read_56894 debug_debug3_read 3 56894 NULL
112086 +batadv_tt_update_changes_56895 batadv_tt_update_changes 3 56895 NULL
112087 +hfsplus_find_cat_56899 hfsplus_find_cat 0 56899 NULL
112088 +hfsplus_setxattr_56902 hfsplus_setxattr 4 56902 NULL
112089 +strcspn_56913 strcspn 0 56913 NULL
112090 +__kfifo_out_56927 __kfifo_out 0-3 56927 NULL
112091 +journal_init_revoke_56933 journal_init_revoke 2 56933 NULL
112092 +nouveau_xtensa_create__56952 nouveau_xtensa_create_ 8 56952 NULL
112093 +diva_get_driver_info_56967 diva_get_driver_info 0 56967 NULL
112094 +nouveau_device_create__56984 nouveau_device_create_ 6 56984 NULL
112095 +sptlrpc_secflags2str_56995 sptlrpc_secflags2str 3 56995 NULL
112096 +vlsi_alloc_ring_57003 vlsi_alloc_ring 3-4 57003 NULL
112097 +btrfs_super_csum_size_57004 btrfs_super_csum_size 0 57004 NULL
112098 +aircable_process_packet_57027 aircable_process_packet 4 57027 NULL
112099 +ieee80211_if_fmt_state_57043 ieee80211_if_fmt_state 3 57043 NULL nohasharray
112100 +skb_network_offset_57043 skb_network_offset 0 57043 &ieee80211_if_fmt_state_57043
112101 +bytes_to_samples_57049 bytes_to_samples 0-2 57049 NULL
112102 +xfs_buf_read_map_57053 xfs_buf_read_map 3 57053 NULL
112103 +cx2341x_ctrl_new_std_57061 cx2341x_ctrl_new_std 4 57061 NULL
112104 +sca3000_read_data_57064 sca3000_read_data 4 57064 NULL
112105 +pcmcia_replace_cis_57066 pcmcia_replace_cis 3 57066 NULL
112106 +tracing_set_trace_write_57096 tracing_set_trace_write 3 57096 NULL
112107 +altera_get_note_57099 altera_get_note 6 57099 NULL
112108 +hpfs_readpages_57106 hpfs_readpages 4 57106 NULL
112109 +crypto_compress_ctxsize_57109 crypto_compress_ctxsize 0 57109 NULL
112110 +sysfs_write_file_57116 sysfs_write_file 3 57116 NULL
112111 +cipso_v4_gentag_loc_57119 cipso_v4_gentag_loc 0 57119 NULL
112112 +rds_ib_sub_signaled_57136 rds_ib_sub_signaled 2 57136 NULL nohasharray
112113 +nl80211_send_deauth_57136 nl80211_send_deauth 4 57136 &rds_ib_sub_signaled_57136 nohasharray
112114 +ima_show_htable_value_57136 ima_show_htable_value 2 57136 &nl80211_send_deauth_57136
112115 +snd_sonicvibes_getdmac_57140 snd_sonicvibes_getdmac 0 57140 NULL
112116 +udl_prime_create_57159 udl_prime_create 2 57159 NULL
112117 +stk_prepare_sio_buffers_57168 stk_prepare_sio_buffers 2 57168 NULL
112118 +rx_hw_stuck_read_57179 rx_hw_stuck_read 3 57179 NULL
112119 +hash_netnet6_expire_57191 hash_netnet6_expire 4 57191 NULL
112120 +tt3650_ci_msg_57219 tt3650_ci_msg 4 57219 NULL
112121 +dma_fifo_alloc_57236 dma_fifo_alloc 5-3-2 57236 NULL
112122 +rsxx_cram_write_57244 rsxx_cram_write 3 57244 NULL
112123 +ieee80211_if_fmt_tsf_57249 ieee80211_if_fmt_tsf 3 57249 NULL
112124 +oprofilefs_ulong_from_user_57251 oprofilefs_ulong_from_user 3 57251 NULL
112125 +alloc_flex_gd_57259 alloc_flex_gd 1 57259 NULL
112126 +lbs_sleepparams_write_57283 lbs_sleepparams_write 3 57283 NULL
112127 +pstore_file_read_57288 pstore_file_read 3 57288 NULL
112128 +snd_pcm_read_57289 snd_pcm_read 3 57289 NULL
112129 +ftdi_elan_write_57309 ftdi_elan_write 3 57309 NULL
112130 +write_file_regval_57313 write_file_regval 3 57313 NULL
112131 +__mxt_write_reg_57326 __mxt_write_reg 3 57326 NULL
112132 +usblp_read_57342 usblp_read 3 57342 NULL
112133 +print_devstats_dot11RTSFailureCount_57347 print_devstats_dot11RTSFailureCount 3 57347 NULL
112134 +dio_send_cur_page_57348 dio_send_cur_page 0 57348 NULL
112135 +tipc_bclink_stats_57372 tipc_bclink_stats 2 57372 NULL
112136 +tty_register_device_attr_57381 tty_register_device_attr 2 57381 NULL
112137 +read_file_blob_57406 read_file_blob 3 57406 NULL
112138 +enclosure_register_57412 enclosure_register 3 57412 NULL
112139 +compat_keyctl_instantiate_key_iov_57431 compat_keyctl_instantiate_key_iov 3 57431 NULL
112140 +copy_to_user_fromio_57432 copy_to_user_fromio 3 57432 NULL
112141 +__roundup_pow_of_two_57461 __roundup_pow_of_two 0 57461 NULL
112142 +sisusb_clear_vram_57466 sisusb_clear_vram 2-3 57466 NULL
112143 +ieee80211_if_read_flags_57470 ieee80211_if_read_flags 3 57470 NULL
112144 +tipc_port_reject_sections_57478 tipc_port_reject_sections 4 57478 NULL
112145 +bnad_debugfs_write_regwr_57500 bnad_debugfs_write_regwr 3 57500 NULL
112146 +skb_headlen_57501 skb_headlen 0 57501 NULL
112147 +copy_in_user_57502 copy_in_user 3 57502 NULL
112148 +ckhdid_printf_57505 ckhdid_printf 2 57505 NULL
112149 +init_tag_map_57515 init_tag_map 3 57515 NULL
112150 +il_dbgfs_force_reset_read_57517 il_dbgfs_force_reset_read 3 57517 NULL nohasharray
112151 +wil_read_file_ssid_57517 wil_read_file_ssid 3 57517 &il_dbgfs_force_reset_read_57517
112152 +cmm_read_57520 cmm_read 3 57520 NULL
112153 +inode_permission_57531 inode_permission 0 57531 NULL
112154 +acpi_dev_get_resources_57534 acpi_dev_get_resources 0 57534 NULL
112155 +ptlrpc_lprocfs_hp_ratio_seq_write_57537 ptlrpc_lprocfs_hp_ratio_seq_write 3 57537 NULL
112156 +ReadHDLCPnP_57559 ReadHDLCPnP 0 57559 NULL
112157 +obd_unpackmd_57563 obd_unpackmd 0 57563 NULL
112158 +snd_pcm_playback_ioctl1_57569 snd_pcm_playback_ioctl1 0 57569 NULL
112159 +get_bridge_ifindices_57579 get_bridge_ifindices 0 57579 NULL
112160 +ldlm_cli_enqueue_local_57582 ldlm_cli_enqueue_local 11 57582 NULL
112161 +il_dbgfs_interrupt_write_57591 il_dbgfs_interrupt_write 3 57591 NULL
112162 +read_file_spectral_fft_period_57593 read_file_spectral_fft_period 3 57593 NULL
112163 +tx_tx_retry_template_read_57623 tx_tx_retry_template_read 3 57623 NULL
112164 +sisusbcon_putcs_57630 sisusbcon_putcs 3 57630 NULL
112165 +mem_read_57631 mem_read 3 57631 NULL
112166 +r3964_write_57662 r3964_write 4 57662 NULL
112167 +proc_ns_readlink_57664 proc_ns_readlink 3 57664 NULL
112168 +__lgwrite_57669 __lgwrite 4 57669 NULL
112169 +f1x_match_to_this_node_57695 f1x_match_to_this_node 3 57695 NULL
112170 +i2400m_rx_stats_read_57706 i2400m_rx_stats_read 3 57706 NULL
112171 +ieee80211_if_read_dot11MeshHWMPconfirmationInterval_57722 ieee80211_if_read_dot11MeshHWMPconfirmationInterval 3 57722 NULL
112172 +nouveau_gpio_create__57735 nouveau_gpio_create_ 4-5 57735 NULL
112173 +pppol2tp_recvmsg_57742 pppol2tp_recvmsg 4 57742 NULL nohasharray
112174 +compat_sys_set_mempolicy_57742 compat_sys_set_mempolicy 3 57742 &pppol2tp_recvmsg_57742
112175 +ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval_57762 ieee80211_if_fmt_dot11MeshHWMPpreqMinInterval 3 57762 NULL
112176 +SYSC_process_vm_writev_57776 SYSC_process_vm_writev 3-5 57776 NULL
112177 +apei_exec_collect_resources_57788 apei_exec_collect_resources 0 57788 NULL
112178 +ld2_57794 ld2 0 57794 NULL
112179 +ivtv_read_57796 ivtv_read 3 57796 NULL
112180 +bfad_debugfs_read_regrd_57830 bfad_debugfs_read_regrd 3 57830 NULL
112181 +copy_to_user_57835 copy_to_user 3-0 57835 NULL
112182 +flash_read_57843 flash_read 3 57843 NULL
112183 +kiblnd_create_tx_pool_57846 kiblnd_create_tx_pool 2 57846 NULL
112184 +xt_alloc_table_info_57903 xt_alloc_table_info 1 57903 NULL
112185 +iio_read_first_n_kfifo_57910 iio_read_first_n_kfifo 2 57910 NULL
112186 +memcg_caches_array_size_57918 memcg_caches_array_size 0-1 57918 NULL
112187 +twl_i2c_write_57923 twl_i2c_write 3-4 57923 NULL
112188 +__snd_gf1_look16_57925 __snd_gf1_look16 0 57925 NULL
112189 +sel_read_handle_unknown_57933 sel_read_handle_unknown 3 57933 NULL
112190 +xfs_mru_cache_create_57943 xfs_mru_cache_create 3 57943 NULL
112191 +key_algorithm_read_57946 key_algorithm_read 3 57946 NULL
112192 +ip_set_alloc_57953 ip_set_alloc 1 57953 NULL nohasharray
112193 +ioat3_dca_count_dca_slots_57953 ioat3_dca_count_dca_slots 0 57953 &ip_set_alloc_57953
112194 +do_rx_dma_57996 do_rx_dma 5 57996 NULL
112195 +rx_reset_counter_read_58001 rx_reset_counter_read 3 58001 NULL
112196 +iwl_dbgfs_ucode_rx_stats_read_58023 iwl_dbgfs_ucode_rx_stats_read 3 58023 NULL
112197 +io_playback_transfer_58030 io_playback_transfer 4 58030 NULL
112198 +mce_async_out_58056 mce_async_out 3 58056 NULL
112199 +ocfs2_find_leaf_58065 ocfs2_find_leaf 0 58065 NULL
112200 +dt3155_alloc_coherent_58073 dt3155_alloc_coherent 2 58073 NULL
112201 +cm4040_write_58079 cm4040_write 3 58079 NULL
112202 +ipv6_flowlabel_opt_58135 ipv6_flowlabel_opt 3 58135 NULL nohasharray
112203 +slhc_init_58135 slhc_init 1-2 58135 &ipv6_flowlabel_opt_58135
112204 +garmin_write_bulk_58191 garmin_write_bulk 3 58191 NULL
112205 +ieee80211_if_fmt_flags_58205 ieee80211_if_fmt_flags 3 58205 NULL
112206 +btrfsic_create_link_to_next_block_58246 btrfsic_create_link_to_next_block 4 58246 NULL
112207 +read_file_debug_58256 read_file_debug 3 58256 NULL
112208 +osc_max_dirty_mb_seq_write_58263 osc_max_dirty_mb_seq_write 3 58263 NULL
112209 +cfg80211_mgmt_tx_status_58266 cfg80211_mgmt_tx_status 4 58266 NULL
112210 +profile_load_58267 profile_load 3 58267 NULL
112211 +kstrtos8_from_user_58268 kstrtos8_from_user 2 58268 NULL
112212 +acpi_ds_build_internal_package_obj_58271 acpi_ds_build_internal_package_obj 3 58271 NULL
112213 +iscsi_decode_text_input_58292 iscsi_decode_text_input 4 58292 NULL
112214 +ieee80211_if_read_dot11MeshTTL_58307 ieee80211_if_read_dot11MeshTTL 3 58307 NULL
112215 +tx_tx_start_int_templates_read_58324 tx_tx_start_int_templates_read 3 58324 NULL
112216 +ext4_ext_truncate_extend_restart_58331 ext4_ext_truncate_extend_restart 3 58331 NULL
112217 +__copy_from_user_swizzled_58337 __copy_from_user_swizzled 2-4 58337 NULL
112218 +SyS_migrate_pages_58348 SyS_migrate_pages 2 58348 NULL
112219 +brcmf_debugfs_sdio_counter_read_58369 brcmf_debugfs_sdio_counter_read 3 58369 NULL
112220 +il_dbgfs_status_read_58388 il_dbgfs_status_read 3 58388 NULL
112221 +_drbd_md_sync_page_io_58403 _drbd_md_sync_page_io 6 58403 NULL
112222 +kvm_mmu_write_protect_pt_masked_58406 kvm_mmu_write_protect_pt_masked 3 58406 NULL nohasharray
112223 +idetape_pad_zeros_58406 idetape_pad_zeros 2 58406 &kvm_mmu_write_protect_pt_masked_58406
112224 +i2400m_pld_size_58415 i2400m_pld_size 0 58415 NULL
112225 +capabilities_read_58457 capabilities_read 3 58457 NULL
112226 +lpfc_idiag_baracc_read_58466 lpfc_idiag_baracc_read 3 58466 NULL nohasharray
112227 +compat_do_ipt_set_ctl_58466 compat_do_ipt_set_ctl 4 58466 &lpfc_idiag_baracc_read_58466
112228 +nv_rd08_58472 nv_rd08 0 58472 NULL
112229 +acpi_tables_sysfs_init_58477 acpi_tables_sysfs_init 0 58477 NULL
112230 +snd_gf1_read_addr_58483 snd_gf1_read_addr 0 58483 NULL
112231 +snd_rme96_capture_copy_58484 snd_rme96_capture_copy 5 58484 NULL
112232 +btrfs_cont_expand_58498 btrfs_cont_expand 2-3 58498 NULL
112233 +rndis_add_response_58544 rndis_add_response 2 58544 NULL
112234 +ldlm_srv_pool_shrink_58554 ldlm_srv_pool_shrink 0 58554 NULL
112235 +wep_decrypt_fail_read_58567 wep_decrypt_fail_read 3 58567 NULL
112236 +scnprint_mac_oui_58578 scnprint_mac_oui 3-0 58578 NULL
112237 +get_rhf_errstring_58582 get_rhf_errstring 3 58582 NULL
112238 +ea_read_inline_58589 ea_read_inline 0 58589 NULL
112239 +isku_sysfs_read_keys_thumbster_58590 isku_sysfs_read_keys_thumbster 6 58590 NULL
112240 +xip_file_read_58592 xip_file_read 3 58592 NULL
112241 +ecryptfs_write_end_58594 ecryptfs_write_end 5-3 58594 NULL
112242 +radeon_bo_size_58606 radeon_bo_size 0 58606 NULL
112243 +skb_copy_to_page_nocache_58624 skb_copy_to_page_nocache 6 58624 NULL
112244 +tx_tx_start_fw_gen_read_58648 tx_tx_start_fw_gen_read 3 58648 NULL
112245 +iwl_dbgfs_rx_handlers_write_58655 iwl_dbgfs_rx_handlers_write 3 58655 NULL
112246 +find_zero_58685 find_zero 0-1 58685 NULL
112247 +uwb_bce_print_IEs_58686 uwb_bce_print_IEs 4 58686 NULL
112248 +tps6586x_writes_58689 tps6586x_writes 2-3 58689 NULL
112249 +vx_send_msg_58711 vx_send_msg 0 58711 NULL
112250 +csum_exist_in_range_58730 csum_exist_in_range 2-3 58730 NULL
112251 +frames_to_bytes_58741 frames_to_bytes 0-2 58741 NULL
112252 +ieee80211_if_write_tkip_mic_test_58748 ieee80211_if_write_tkip_mic_test 3 58748 NULL
112253 +agp_allocate_memory_58761 agp_allocate_memory 2 58761 NULL
112254 +regmap_calc_reg_len_58795 regmap_calc_reg_len 0 58795 NULL
112255 +raw_send_hdrinc_58803 raw_send_hdrinc 4 58803 NULL
112256 +isku_sysfs_read_58806 isku_sysfs_read 5 58806 NULL
112257 +ep_read_58813 ep_read 3 58813 NULL
112258 +command_write_58841 command_write 3 58841 NULL
112259 +ath6kl_wmi_send_action_cmd_58860 ath6kl_wmi_send_action_cmd 7 58860 NULL
112260 +gs_alloc_req_58883 gs_alloc_req 2 58883 NULL
112261 +esas2r_change_queue_depth_58886 esas2r_change_queue_depth 2 58886 NULL
112262 +lprocfs_wr_pinger_recov_58914 lprocfs_wr_pinger_recov 3 58914 NULL
112263 +print_devstats_dot11FCSErrorCount_58919 print_devstats_dot11FCSErrorCount 3 58919 NULL
112264 +pipeline_cs_rx_packet_out_read_58926 pipeline_cs_rx_packet_out_read 3 58926 NULL
112265 +sptlrpc_import_sec_adapt_58948 sptlrpc_import_sec_adapt 0 58948 NULL
112266 +wait_table_hash_nr_entries_58962 wait_table_hash_nr_entries 0 58962 NULL
112267 +ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout_58965 ieee80211_if_fmt_dot11MeshHWMPactivePathToRootTimeout 3 58965 NULL
112268 +crypto_aead_ivsize_58970 crypto_aead_ivsize 0 58970 NULL
112269 +init_list_set_59005 init_list_set 3 59005 NULL
112270 +ep_write_59008 ep_write 3 59008 NULL
112271 +lpfc_idiag_baracc_write_59014 lpfc_idiag_baracc_write 3 59014 NULL
112272 +SyS_preadv_59029 SyS_preadv 3 59029 NULL
112273 +init_pci_cap_msi_perm_59033 init_pci_cap_msi_perm 2 59033 NULL
112274 +selinux_transaction_write_59038 selinux_transaction_write 3 59038 NULL
112275 +crypto_aead_reqsize_59039 crypto_aead_reqsize 0 59039 NULL
112276 +regmap_bulk_write_59049 regmap_bulk_write 2-4 59049 NULL
112277 +sysfs_link_sibling_59078 sysfs_link_sibling 0 59078 NULL
112278 +mmc_sd_num_wr_blocks_59112 mmc_sd_num_wr_blocks 0 59112 NULL
112279 +scsi_io_completion_59122 scsi_io_completion 2 59122 NULL
112280 +nfc_llcp_send_i_frame_59130 nfc_llcp_send_i_frame 3 59130 NULL
112281 +print_devstats_dot11RTSSuccessCount_59145 print_devstats_dot11RTSSuccessCount 3 59145 NULL nohasharray
112282 +framebuffer_alloc_59145 framebuffer_alloc 1 59145 &print_devstats_dot11RTSSuccessCount_59145
112283 +radeon_compat_ioctl_59150 radeon_compat_ioctl 2 59150 NULL
112284 +pvr2_hdw_report_clients_59152 pvr2_hdw_report_clients 3 59152 NULL
112285 +md_getxattr_59161 md_getxattr 0 59161 NULL
112286 +ksize_59176 ksize 0 59176 NULL
112287 +setup_window_59178 setup_window 4-2-5-7 59178 NULL
112288 +ocfs2_move_extent_59187 ocfs2_move_extent 2-5 59187 NULL
112289 +xfs_iext_realloc_indirect_59211 xfs_iext_realloc_indirect 2 59211 NULL
112290 +check_mapped_selector_name_59216 check_mapped_selector_name 5 59216 NULL
112291 +dt3155_read_59226 dt3155_read 3 59226 NULL
112292 +paging64_gpte_to_gfn_lvl_59229 paging64_gpte_to_gfn_lvl 0-1-2 59229 NULL
112293 +tty_prepare_flip_string_flags_59240 tty_prepare_flip_string_flags 4 59240 NULL
112294 +nla_len_59258 nla_len 0 59258 NULL
112295 +drbd_bm_write_page_59290 drbd_bm_write_page 2 59290 NULL
112296 +btrfs_insert_dir_item_59304 btrfs_insert_dir_item 4 59304 NULL
112297 +fd_copyout_59323 fd_copyout 3 59323 NULL
112298 +read_9287_modal_eeprom_59327 read_9287_modal_eeprom 3 59327 NULL
112299 +rx_defrag_in_process_called_read_59338 rx_defrag_in_process_called_read 3 59338 NULL
112300 +xfs_attrmulti_attr_set_59346 xfs_attrmulti_attr_set 4 59346 NULL
112301 +__map_request_59350 __map_request 0 59350 NULL
112302 +f2fs_fallocate_59377 f2fs_fallocate 3-4 59377 NULL
112303 +pvr2_debugifc_print_info_59380 pvr2_debugifc_print_info 3 59380 NULL
112304 +journal_init_dev_59384 journal_init_dev 5 59384 NULL
112305 +__net_get_random_once_59389 __net_get_random_once 2 59389 NULL
112306 +isku_sysfs_read_keys_function_59412 isku_sysfs_read_keys_function 6 59412 NULL
112307 +pci_ctrl_read_59424 pci_ctrl_read 0 59424 NULL
112308 +vxge_hw_ring_rxds_per_block_get_59425 vxge_hw_ring_rxds_per_block_get 0 59425 NULL
112309 +SyS_sched_setaffinity_59442 SyS_sched_setaffinity 2 59442 NULL
112310 +fs_path_ensure_buf_59445 fs_path_ensure_buf 2 59445 NULL
112311 +ib_copy_from_udata_59502 ib_copy_from_udata 3 59502 NULL
112312 +mic_vringh_copy_59523 mic_vringh_copy 4 59523 NULL
112313 +mpi_get_nbits_59551 mpi_get_nbits 0 59551 NULL
112314 +tunables_write_59563 tunables_write 3 59563 NULL
112315 +__copy_from_user_ll_nozero_59571 __copy_from_user_ll_nozero 0-3 59571 NULL
112316 +write_pbl_59583 write_pbl 4 59583 NULL
112317 +memdup_user_59590 memdup_user 2 59590 NULL
112318 +xrcdn_free_res_59616 xrcdn_free_res 5 59616 NULL nohasharray
112319 +mem_fwlog_free_mem_blks_read_59616 mem_fwlog_free_mem_blks_read 3 59616 &xrcdn_free_res_59616
112320 +ath6kl_endpoint_stats_write_59621 ath6kl_endpoint_stats_write 3 59621 NULL
112321 +mtrr_write_59622 mtrr_write 3 59622 NULL
112322 +find_first_zero_bit_59636 find_first_zero_bit 0 59636 NULL
112323 +SyS_setdomainname_59646 SyS_setdomainname 2 59646 NULL
112324 +hidraw_read_59650 hidraw_read 3 59650 NULL
112325 +v9fs_xattr_set_acl_59651 v9fs_xattr_set_acl 4 59651 NULL
112326 +__devcgroup_check_permission_59665 __devcgroup_check_permission 0 59665 NULL
112327 +iwl_dbgfs_mac_params_read_59666 iwl_dbgfs_mac_params_read 3 59666 NULL
112328 +alloc_dca_provider_59670 alloc_dca_provider 2 59670 NULL
112329 +mic_calc_failure_read_59700 mic_calc_failure_read 3 59700 NULL
112330 +ioperm_get_59701 ioperm_get 4-3 59701 NULL
112331 +prism2_info_scanresults_59729 prism2_info_scanresults 3 59729 NULL
112332 +ieee80211_if_read_fwded_unicast_59740 ieee80211_if_read_fwded_unicast 3 59740 NULL
112333 +fat_direct_IO_59741 fat_direct_IO 4 59741 NULL
112334 +qib_decode_7220_sdma_errs_59745 qib_decode_7220_sdma_errs 4 59745 NULL
112335 +strnlen_59746 strnlen 0 59746 NULL
112336 +ext3_acl_count_59754 ext3_acl_count 0-1 59754 NULL
112337 +long_retry_limit_read_59766 long_retry_limit_read 3 59766 NULL
112338 +venus_remove_59781 venus_remove 4 59781 NULL
112339 +mei_nfc_recv_59784 mei_nfc_recv 3 59784 NULL
112340 +C_SYSC_preadv_59801 C_SYSC_preadv 3 59801 NULL
112341 +ipw_write_59807 ipw_write 3 59807 NULL
112342 +scsi_init_shared_tag_map_59812 scsi_init_shared_tag_map 2 59812 NULL
112343 +ieee80211_if_read_dot11MeshHWMPmaxPREQretries_59829 ieee80211_if_read_dot11MeshHWMPmaxPREQretries 3 59829 NULL
112344 +gspca_dev_probe2_59833 gspca_dev_probe2 4 59833 NULL
112345 +regmap_raw_write_async_59849 regmap_raw_write_async 2-4 59849 NULL
112346 +pvr2_ioread_set_sync_key_59882 pvr2_ioread_set_sync_key 3 59882 NULL
112347 +l2cap_sock_recvmsg_59886 l2cap_sock_recvmsg 4 59886 NULL
112348 +ffs_prepare_buffer_59892 ffs_prepare_buffer 2 59892 NULL
112349 +ocfs2_extend_rotate_transaction_59894 ocfs2_extend_rotate_transaction 2-3 59894 NULL
112350 +aic7xxx_abort_waiting_scb_59932 aic7xxx_abort_waiting_scb 0 59932 NULL
112351 +kvm_mmu_notifier_invalidate_range_start_59944 kvm_mmu_notifier_invalidate_range_start 3-4 59944 NULL
112352 +dapm_widget_power_read_file_59950 dapm_widget_power_read_file 3 59950 NULL nohasharray
112353 +il_dbgfs_rxon_flags_read_59950 il_dbgfs_rxon_flags_read 3 59950 &dapm_widget_power_read_file_59950
112354 +il_dbgfs_missed_beacon_read_59956 il_dbgfs_missed_beacon_read 3 59956 NULL
112355 +__arch_hweight16_59975 __arch_hweight16 0 59975 NULL
112356 +osd_req_read_kern_59990 osd_req_read_kern 5 59990 NULL
112357 +ghash_async_setkey_60001 ghash_async_setkey 3 60001 NULL
112358 +ieee80211_if_fmt_dot11MeshAwakeWindowDuration_60006 ieee80211_if_fmt_dot11MeshAwakeWindowDuration 3 60006 NULL
112359 +rawsock_sendmsg_60010 rawsock_sendmsg 4 60010 NULL
112360 +mthca_init_cq_60011 mthca_init_cq 2 60011 NULL
112361 +osd_req_list_dev_partitions_60027 osd_req_list_dev_partitions 4 60027 NULL
112362 +xlog_bread_offset_60030 xlog_bread_offset 3 60030 NULL
112363 +bio_integrity_hw_sectors_60039 bio_integrity_hw_sectors 0-2 60039 NULL
112364 +do_ip6t_set_ctl_60040 do_ip6t_set_ctl 4 60040 NULL
112365 +vcs_size_60050 vcs_size 0 60050 NULL
112366 +gru_alloc_gts_60056 gru_alloc_gts 3-2 60056 NULL
112367 +compat_writev_60063 compat_writev 3 60063 NULL
112368 +ath6kl_listen_int_write_60066 ath6kl_listen_int_write 3 60066 NULL
112369 +c4iw_num_stags_60073 c4iw_num_stags 0 60073 NULL
112370 +rxrpc_kernel_send_data_60083 rxrpc_kernel_send_data 3 60083 NULL
112371 +ieee80211_if_fmt_fwded_frames_60103 ieee80211_if_fmt_fwded_frames 3 60103 NULL
112372 +SYSC_msgsnd_60113 SYSC_msgsnd 3 60113 NULL
112373 +nfs_idmap_request_key_60124 nfs_idmap_request_key 2 60124 NULL
112374 +__mutex_lock_common_60134 __mutex_lock_common 0 60134 NULL
112375 +ld_usb_read_60156 ld_usb_read 3 60156 NULL
112376 +jmb38x_ms_count_slots_60164 jmb38x_ms_count_slots 0 60164 NULL
112377 +init_state_60165 init_state 2 60165 NULL
112378 +jffs2_alloc_full_dirent_60179 jffs2_alloc_full_dirent 1 60179 NULL nohasharray
112379 +sg_build_sgat_60179 sg_build_sgat 3 60179 &jffs2_alloc_full_dirent_60179
112380 +fuse_async_req_send_60183 fuse_async_req_send 0-3 60183 NULL
112381 +rx_rx_tkip_replays_read_60193 rx_rx_tkip_replays_read 3 60193 NULL
112382 +qib_reg_phys_mr_60202 qib_reg_phys_mr 3 60202 NULL
112383 +btrfs_get_token_16_60220 btrfs_get_token_16 0 60220 NULL
112384 +irq_alloc_domain_generic_chips_60264 irq_alloc_domain_generic_chips 2-3 60264 NULL
112385 +display_crc_ctl_write_60273 display_crc_ctl_write 3 60273 NULL
112386 +printer_write_60276 printer_write 3 60276 NULL
112387 +do_xip_mapping_read_60297 do_xip_mapping_read 5 60297 NULL
112388 +getDataLength_60301 getDataLength 0 60301 NULL
112389 +usb_alphatrack_write_60341 usb_alphatrack_write 3 60341 NULL
112390 +__kfifo_from_user_r_60345 __kfifo_from_user_r 5-3 60345 NULL
112391 +dccp_setsockopt_60367 dccp_setsockopt 5 60367 NULL
112392 +mthca_alloc_resize_buf_60394 mthca_alloc_resize_buf 3 60394 NULL
112393 +ocfs2_zero_extend_60396 ocfs2_zero_extend 3 60396 NULL
112394 +driver_names_read_60399 driver_names_read 3 60399 NULL
112395 +simple_alloc_urb_60420 simple_alloc_urb 3 60420 NULL
112396 +excessive_retries_read_60425 excessive_retries_read 3 60425 NULL
112397 +kmalloc_60432 kmalloc 1 60432 NULL nohasharray
112398 +tstats_write_60432 tstats_write 3 60432 &kmalloc_60432
112399 +snd_hda_get_num_raw_conns_60462 snd_hda_get_num_raw_conns 0 60462 NULL
112400 +crypto_shash_setkey_60483 crypto_shash_setkey 3 60483 NULL
112401 +lustre_msg_early_size_60496 lustre_msg_early_size 0 60496 NULL
112402 +v9fs_fid_readn_60544 v9fs_fid_readn 4 60544 NULL
112403 +nonpaging_map_60551 nonpaging_map 4 60551 NULL
112404 +osc_lockless_truncate_seq_write_60553 osc_lockless_truncate_seq_write 3 60553 NULL
112405 +tracing_entries_write_60563 tracing_entries_write 3 60563 NULL
112406 +skb_transport_offset_60619 skb_transport_offset 0 60619 NULL
112407 +wl1273_fm_fops_write_60621 wl1273_fm_fops_write 3 60621 NULL
112408 +acl_alloc_stack_init_60630 acl_alloc_stack_init 1 60630 NULL
112409 +__proc_lnet_stats_60647 __proc_lnet_stats 5 60647 NULL
112410 +if_sdio_host_to_card_60666 if_sdio_host_to_card 4 60666 NULL
112411 +ieee80211_if_read_dot11MeshConfirmTimeout_60670 ieee80211_if_read_dot11MeshConfirmTimeout 3 60670 NULL
112412 +vga_rcrt_60731 vga_rcrt 0 60731 NULL
112413 +snd_ice1712_ds_read_60754 snd_ice1712_ds_read 0 60754 NULL
112414 +raid_status_60755 raid_status 5 60755 NULL
112415 +sel_write_checkreqprot_60774 sel_write_checkreqprot 3 60774 NULL
112416 +opticon_write_60775 opticon_write 4 60775 NULL
112417 +acl_alloc_num_60778 acl_alloc_num 1-2 60778 NULL
112418 +snd_pcm_oss_readv3_60792 snd_pcm_oss_readv3 3 60792 NULL
112419 +pwr_tx_with_ps_read_60851 pwr_tx_with_ps_read 3 60851 NULL
112420 +alloc_buf_60864 alloc_buf 3-2 60864 NULL
112421 +generic_writepages_60871 generic_writepages 0 60871 NULL
112422 +ext4_update_inline_data_60888 ext4_update_inline_data 3 60888 NULL
112423 +iio_debugfs_read_reg_60908 iio_debugfs_read_reg 3 60908 NULL
112424 +libcfs_sock_ioctl_60915 libcfs_sock_ioctl 0 60915 NULL
112425 +mgt_set_varlen_60916 mgt_set_varlen 4 60916 NULL
112426 +scrub_chunk_60926 scrub_chunk 5 60926 NULL
112427 +submit_extent_page_60928 submit_extent_page 5 60928 NULL
112428 +pti_char_write_60960 pti_char_write 3 60960 NULL
112429 +mwifiex_alloc_sdio_mpa_buffers_60961 mwifiex_alloc_sdio_mpa_buffers 2-3 60961 NULL
112430 +__a2mp_build_60987 __a2mp_build 3 60987 NULL
112431 +hsc_msg_alloc_60990 hsc_msg_alloc 1 60990 NULL
112432 +ath6kl_lrssi_roam_read_61022 ath6kl_lrssi_roam_read 3 61022 NULL
112433 +graph_depth_write_61024 graph_depth_write 3 61024 NULL
112434 +sdhci_pltfm_register_61031 sdhci_pltfm_register 3 61031 NULL
112435 +lpfc_idiag_queacc_write_61043 lpfc_idiag_queacc_write 3 61043 NULL
112436 +symtab_init_61050 symtab_init 2 61050 NULL
112437 +fuse_send_write_61053 fuse_send_write 0-4 61053 NULL
112438 +bitmap_scnlistprintf_61062 bitmap_scnlistprintf 0-2 61062 NULL
112439 +ahash_align_buffer_size_61070 ahash_align_buffer_size 0-1-2 61070 NULL
112440 +get_derived_key_61100 get_derived_key 4 61100 NULL
112441 +i40e_calculate_l2fpm_size_61104 i40e_calculate_l2fpm_size 0-1-2-3-4 61104 NULL
112442 +alloc_chrdev_region_61112 alloc_chrdev_region 0 61112 NULL
112443 +__probe_kernel_read_61119 __probe_kernel_read 3 61119 NULL
112444 +vmemmap_alloc_block_buf_61126 vmemmap_alloc_block_buf 1 61126 NULL
112445 +afs_proc_cells_write_61139 afs_proc_cells_write 3 61139 NULL
112446 +brcmf_sdio_chip_cr4_exitdl_61143 brcmf_sdio_chip_cr4_exitdl 4 61143 NULL
112447 +osl_malloc_61156 osl_malloc 2 61156 NULL
112448 +pair_device_61175 pair_device 4 61175 NULL nohasharray
112449 +event_oom_late_read_61175 event_oom_late_read 3 61175 &pair_device_61175
112450 +dio_bio_add_page_61178 dio_bio_add_page 0 61178 NULL
112451 +SyS_prctl_61202 SyS_prctl 4 61202 NULL
112452 +arch_hibernation_header_save_61212 arch_hibernation_header_save 0 61212 NULL
112453 +smk_read_ambient_61220 smk_read_ambient 3 61220 NULL
112454 +btrfs_bio_alloc_61270 btrfs_bio_alloc 3 61270 NULL nohasharray
112455 +find_get_pages_tag_61270 find_get_pages_tag 0 61270 &btrfs_bio_alloc_61270 nohasharray
112456 +ifalias_store_61270 ifalias_store 4 61270 &find_get_pages_tag_61270
112457 +vortex_adbdma_getlinearpos_61283 vortex_adbdma_getlinearpos 0 61283 NULL nohasharray
112458 +hfsplus_getxattr_finder_info_61283 hfsplus_getxattr_finder_info 0 61283 &vortex_adbdma_getlinearpos_61283
112459 +nvme_trans_copy_to_user_61288 nvme_trans_copy_to_user 3 61288 NULL
112460 +xfer_from_user_61307 xfer_from_user 3 61307 NULL
112461 +xfrm_user_sec_ctx_size_61320 xfrm_user_sec_ctx_size 0 61320 NULL
112462 +C_SYSC_msgsnd_61330 C_SYSC_msgsnd 3 61330 NULL
112463 +write_file_spectral_short_repeat_61335 write_file_spectral_short_repeat 3 61335 NULL
112464 +st5481_setup_isocpipes_61340 st5481_setup_isocpipes 6-4 61340 NULL
112465 +rx_rx_wa_ba_not_expected_read_61341 rx_rx_wa_ba_not_expected_read 3 61341 NULL
112466 +__dm_get_reserved_ios_61342 __dm_get_reserved_ios 0-3-2 61342 NULL
112467 +f1x_map_sysaddr_to_csrow_61344 f1x_map_sysaddr_to_csrow 2 61344 NULL
112468 +debug_debug4_read_61367 debug_debug4_read 3 61367 NULL
112469 +system_enable_write_61396 system_enable_write 3 61396 NULL
112470 +xfs_zero_remaining_bytes_61423 xfs_zero_remaining_bytes 3 61423 NULL
112471 +unix_stream_sendmsg_61455 unix_stream_sendmsg 4 61455 NULL
112472 +snd_pcm_lib_writev_transfer_61483 snd_pcm_lib_writev_transfer 5-4-2 61483 NULL
112473 +btrfs_item_size_61485 btrfs_item_size 0 61485 NULL
112474 +ocfs2_get_refcount_rec_61514 ocfs2_get_refcount_rec 0 61514 NULL
112475 +erst_errno_61526 erst_errno 0 61526 NULL
112476 +trace_options_core_write_61551 trace_options_core_write 3 61551 NULL
112477 +dvb_net_ioctl_61559 dvb_net_ioctl 2 61559 NULL
112478 +parport_pc_fifo_write_block_dma_61568 parport_pc_fifo_write_block_dma 3 61568 NULL
112479 +fan_proc_write_61569 fan_proc_write 3 61569 NULL
112480 +ieee80211_if_read_rc_rateidx_mask_2ghz_61570 ieee80211_if_read_rc_rateidx_mask_2ghz 3 61570 NULL
112481 +ldlm_pool_rw_atomic_seq_write_61572 ldlm_pool_rw_atomic_seq_write 3 61572 NULL
112482 +seq_open_private_61589 seq_open_private 3 61589 NULL
112483 +ept_gpte_to_gfn_lvl_61591 ept_gpte_to_gfn_lvl 0-1-2 61591 NULL
112484 +netlink_recvmsg_61600 netlink_recvmsg 4 61600 NULL
112485 +nfs4_init_uniform_client_string_61601 nfs4_init_uniform_client_string 3 61601 NULL
112486 +configfs_write_file_61621 configfs_write_file 3 61621 NULL
112487 +ieee80211_if_fmt_hw_queues_61629 ieee80211_if_fmt_hw_queues 3 61629 NULL
112488 +i2o_parm_table_get_61635 i2o_parm_table_get 6 61635 NULL
112489 +snd_pcm_oss_read3_61643 snd_pcm_oss_read3 0-3 61643 NULL
112490 +resize_stripes_61650 resize_stripes 2 61650 NULL
112491 +ttm_page_pool_free_61661 ttm_page_pool_free 2-0 61661 NULL
112492 +insert_one_name_61668 insert_one_name 7 61668 NULL
112493 +qib_format_hwmsg_61679 qib_format_hwmsg 2 61679 NULL
112494 +lock_loop_61681 lock_loop 1 61681 NULL
112495 +__do_tune_cpucache_61684 __do_tune_cpucache 2 61684 NULL
112496 +filter_read_61692 filter_read 3 61692 NULL
112497 +iov_length_61716 iov_length 0 61716 NULL
112498 +fragmentation_threshold_read_61718 fragmentation_threshold_read 3 61718 NULL
112499 +null_alloc_reqbuf_61719 null_alloc_reqbuf 3 61719 NULL
112500 +read_file_interrupt_61742 read_file_interrupt 3 61742 NULL nohasharray
112501 +read_file_regval_61742 read_file_regval 3 61742 &read_file_interrupt_61742
112502 +SyS_sendto_61763 SyS_sendto 6 61763 NULL
112503 +mls_compute_context_len_61812 mls_compute_context_len 0 61812 NULL
112504 +bfad_debugfs_write_regwr_61841 bfad_debugfs_write_regwr 3 61841 NULL
112505 +regcache_sync_block_61846 regcache_sync_block 5-4 61846 NULL
112506 +ath9k_hw_def_dump_eeprom_61853 ath9k_hw_def_dump_eeprom 5-4 61853 NULL
112507 +fs_path_prepare_for_add_61854 fs_path_prepare_for_add 2 61854 NULL
112508 +evdev_compute_buffer_size_61863 evdev_compute_buffer_size 0 61863 NULL
112509 +SYSC_lsetxattr_61869 SYSC_lsetxattr 4 61869 NULL
112510 +get_fw_name_61874 get_fw_name 3 61874 NULL
112511 +btrfs_ioctl_clone_61886 btrfs_ioctl_clone 3-4-5 61886 NULL
112512 +lprocfs_write_frac_u64_helper_61897 lprocfs_write_frac_u64_helper 2 61897 NULL
112513 +lov_mds_md_stripecnt_61899 lov_mds_md_stripecnt 0-1 61899 NULL
112514 +clear_refs_write_61904 clear_refs_write 3 61904 NULL nohasharray
112515 +import_sec_check_expire_61904 import_sec_check_expire 0 61904 &clear_refs_write_61904
112516 +rx_filter_arp_filter_read_61914 rx_filter_arp_filter_read 3 61914 NULL
112517 +au0828_init_isoc_61917 au0828_init_isoc 3-2-4 61917 NULL
112518 +sctp_sendmsg_61919 sctp_sendmsg 4 61919 NULL
112519 +edac_device_create_instance_61940 edac_device_create_instance 0 61940 NULL
112520 +SyS_kexec_load_61946 SyS_kexec_load 2 61946 NULL
112521 +il4965_ucode_rx_stats_read_61948 il4965_ucode_rx_stats_read 3 61948 NULL
112522 +squashfs_read_id_index_table_61961 squashfs_read_id_index_table 4 61961 NULL
112523 +fix_read_error_61965 fix_read_error 4 61965 NULL
112524 +ocfs2_quota_write_61972 ocfs2_quota_write 4-5 61972 NULL
112525 +fd_locked_ioctl_61978 fd_locked_ioctl 3 61978 NULL
112526 +cow_file_range_61979 cow_file_range 3 61979 NULL
112527 +dequeue_event_62000 dequeue_event 3 62000 NULL
112528 +xt_compat_match_offset_62011 xt_compat_match_offset 0 62011 NULL
112529 +SyS_setxattr_62019 SyS_setxattr 4 62019 NULL
112530 +jffs2_do_unlink_62020 jffs2_do_unlink 4 62020 NULL
112531 +SYSC_select_62024 SYSC_select 1 62024 NULL
112532 +pmcraid_build_passthrough_ioadls_62034 pmcraid_build_passthrough_ioadls 2 62034 NULL
112533 +sctp_user_addto_chunk_62047 sctp_user_addto_chunk 2-3 62047 NULL
112534 +do_pselect_62061 do_pselect 1 62061 NULL
112535 +pcpu_alloc_bootmem_62074 pcpu_alloc_bootmem 2 62074 NULL
112536 +jffs2_security_setxattr_62107 jffs2_security_setxattr 4 62107 NULL
112537 +btrfs_direct_IO_62114 btrfs_direct_IO 4 62114 NULL
112538 +ip_recv_error_62117 ip_recv_error 3 62117 NULL
112539 +generic_block_fiemap_62122 generic_block_fiemap 4 62122 NULL
112540 +llc_ui_header_len_62131 llc_ui_header_len 0 62131 NULL
112541 +kobject_add_varg_62133 kobject_add_varg 0 62133 NULL nohasharray
112542 +qib_diag_write_62133 qib_diag_write 3 62133 &kobject_add_varg_62133
112543 +device_add_attrs_62135 device_add_attrs 0 62135 NULL nohasharray
112544 +ql_status_62135 ql_status 5 62135 &device_add_attrs_62135
112545 +video_usercopy_62151 video_usercopy 2 62151 NULL
112546 +SyS_getxattr_62166 SyS_getxattr 4 62166 NULL
112547 +prism54_wpa_bss_ie_get_62173 prism54_wpa_bss_ie_get 0 62173 NULL
112548 +write_file_dfs_62180 write_file_dfs 3 62180 NULL
112549 +alloc_upcall_62186 alloc_upcall 2 62186 NULL
112550 +btrfs_xattr_acl_set_62203 btrfs_xattr_acl_set 4 62203 NULL
112551 +sock_kmalloc_62205 sock_kmalloc 2 62205 NULL
112552 +SYSC_setgroups16_62232 SYSC_setgroups16 1 62232 NULL
112553 +nfsd_read_file_62241 nfsd_read_file 6 62241 NULL
112554 +subtract_dirty_62242 subtract_dirty 2-3 62242 NULL
112555 +get_random_int_62279 get_random_int 0 62279 NULL
112556 +il_dbgfs_sram_read_62296 il_dbgfs_sram_read 3 62296 NULL
112557 +sparse_early_usemaps_alloc_pgdat_section_62304 sparse_early_usemaps_alloc_pgdat_section 2 62304 NULL
112558 +subsystem_filter_read_62310 subsystem_filter_read 3 62310 NULL
112559 +Wb35Reg_BurstWrite_62327 Wb35Reg_BurstWrite 4 62327 NULL
112560 +ocfs2_xattr_buckets_per_cluster_62330 ocfs2_xattr_buckets_per_cluster 0 62330 NULL
112561 +subseq_list_62332 subseq_list 3-0 62332 NULL
112562 +ll_statahead_max_seq_write_62333 ll_statahead_max_seq_write 3 62333 NULL
112563 +flash_write_62354 flash_write 3 62354 NULL
112564 +xfpregs_set_62363 xfpregs_set 4 62363 NULL
112565 +rx_rx_timeout_read_62389 rx_rx_timeout_read 3 62389 NULL
112566 +altera_irscan_62396 altera_irscan 2 62396 NULL
112567 +set_ssp_62411 set_ssp 4 62411 NULL
112568 +ext_rts51x_sd_execute_read_data_62501 ext_rts51x_sd_execute_read_data 9 62501 NULL
112569 +pep_sendmsg_62524 pep_sendmsg 4 62524 NULL
112570 +test_iso_queue_62534 test_iso_queue 5 62534 NULL
112571 +debugfs_read_62535 debugfs_read 3 62535 NULL
112572 +sco_sock_sendmsg_62542 sco_sock_sendmsg 4 62542 NULL
112573 +qib_refresh_qsfp_cache_62547 qib_refresh_qsfp_cache 0 62547 NULL
112574 +link_send_sections_long_62557 link_send_sections_long 3 62557 NULL
112575 +xfrm_user_policy_62573 xfrm_user_policy 4 62573 NULL
112576 +compat_SyS_rt_sigpending_62580 compat_SyS_rt_sigpending 2 62580 NULL
112577 +get_subdir_62581 get_subdir 3 62581 NULL
112578 +nfsd_vfs_read_62605 nfsd_vfs_read 6 62605 NULL
112579 +tipc_port_recv_sections_62609 tipc_port_recv_sections 3 62609 NULL
112580 +dut_mode_write_62630 dut_mode_write 3 62630 NULL
112581 +vfs_fsync_range_62635 vfs_fsync_range 0 62635 NULL
112582 +lpfc_sli4_queue_alloc_62646 lpfc_sli4_queue_alloc 3 62646 NULL
112583 +ocfs2_wait_for_mask_interruptible_62675 ocfs2_wait_for_mask_interruptible 0 62675 NULL
112584 +printer_req_alloc_62687 printer_req_alloc 2 62687 NULL
112585 +bioset_integrity_create_62708 bioset_integrity_create 2 62708 NULL
112586 +gfs2_log_write_62717 gfs2_log_write 3 62717 NULL
112587 +rdm_62719 rdm 0 62719 NULL
112588 +obd_ioctl_popdata_62741 obd_ioctl_popdata 3 62741 NULL
112589 +key_replays_read_62746 key_replays_read 3 62746 NULL
112590 +lov_verify_lmm_62747 lov_verify_lmm 2 62747 NULL
112591 +mwifiex_rdeeprom_write_62754 mwifiex_rdeeprom_write 3 62754 NULL
112592 +ax25_sendmsg_62770 ax25_sendmsg 4 62770 NULL
112593 +C_SYSC_ipc_62776 C_SYSC_ipc 3 62776 NULL
112594 +SyS_sched_getaffinity_62786 SyS_sched_getaffinity 2 62786 NULL
112595 +dm_stats_account_io_62787 dm_stats_account_io 3 62787 NULL
112596 +tracing_total_entries_read_62817 tracing_total_entries_read 3 62817 NULL
112597 +__rounddown_pow_of_two_62836 __rounddown_pow_of_two 0 62836 NULL
112598 +bio_get_nr_vecs_62838 bio_get_nr_vecs 0 62838 NULL
112599 +xlog_recover_add_to_trans_62839 xlog_recover_add_to_trans 4 62839 NULL
112600 +rx_fcs_err_read_62844 rx_fcs_err_read 3 62844 NULL
112601 +read_nic_io_dword_62859 read_nic_io_dword 0 62859 NULL
112602 +l2tp_ip6_recvmsg_62874 l2tp_ip6_recvmsg 4 62874 NULL
112603 +aoechr_write_62883 aoechr_write 3 62883 NULL
112604 +if_spi_host_to_card_62890 if_spi_host_to_card 4 62890 NULL
112605 +ocfs2_validate_gd_parent_62905 ocfs2_validate_gd_parent 0 62905 NULL
112606 +mempool_create_slab_pool_62907 mempool_create_slab_pool 1 62907 NULL
112607 +getdqbuf_62908 getdqbuf 1 62908 NULL
112608 +ll_statahead_agl_seq_write_62928 ll_statahead_agl_seq_write 3 62928 NULL
112609 +agp_create_user_memory_62955 agp_create_user_memory 1 62955 NULL
112610 +kstrtoull_from_user_63026 kstrtoull_from_user 2 63026 NULL
112611 +__vb2_perform_fileio_63033 __vb2_perform_fileio 3 63033 NULL
112612 +pipeline_defrag_to_csum_swi_read_63037 pipeline_defrag_to_csum_swi_read 3 63037 NULL
112613 +scsi_host_alloc_63041 scsi_host_alloc 2 63041 NULL
112614 +unlink1_63059 unlink1 3 63059 NULL
112615 +xen_set_nslabs_63066 xen_set_nslabs 0 63066 NULL
112616 +iwl_dbgfs_fw_rx_stats_read_63070 iwl_dbgfs_fw_rx_stats_read 3 63070 NULL
112617 +sep_prepare_input_output_dma_table_in_dcb_63087 sep_prepare_input_output_dma_table_in_dcb 4-5 63087 NULL
112618 +iwl_dbgfs_sensitivity_read_63116 iwl_dbgfs_sensitivity_read 3 63116 NULL
112619 +ext4_chunk_trans_blocks_63123 ext4_chunk_trans_blocks 0-2 63123 NULL
112620 +smk_write_revoke_subj_63173 smk_write_revoke_subj 3 63173 NULL
112621 +SyS_syslog_63178 SyS_syslog 3 63178 NULL
112622 +vme_master_read_63221 vme_master_read 0 63221 NULL
112623 +SyS_gethostname_63227 SyS_gethostname 2 63227 NULL
112624 +ptp_read_63251 ptp_read 4 63251 NULL
112625 +xfs_dir2_leaf_getdents_63262 xfs_dir2_leaf_getdents 3 63262 NULL
112626 +raid5_resize_63306 raid5_resize 2 63306 NULL
112627 +proc_info_read_63344 proc_info_read 3 63344 NULL
112628 +ps_upsd_max_sptime_read_63362 ps_upsd_max_sptime_read 3 63362 NULL
112629 +idmouse_read_63374 idmouse_read 3 63374 NULL
112630 +usbnet_read_cmd_nopm_63388 usbnet_read_cmd_nopm 7 63388 NULL nohasharray
112631 +edac_pci_alloc_ctl_info_63388 edac_pci_alloc_ctl_info 1 63388 &usbnet_read_cmd_nopm_63388
112632 +rxpipe_missed_beacon_host_int_trig_rx_data_read_63405 rxpipe_missed_beacon_host_int_trig_rx_data_read 3 63405 NULL
112633 +nouveau_event_create_63411 nouveau_event_create 1 63411 NULL
112634 +l2cap_sock_sendmsg_63427 l2cap_sock_sendmsg 4 63427 NULL
112635 +nfsd_symlink_63442 nfsd_symlink 6 63442 NULL
112636 +si5351_bulk_write_63468 si5351_bulk_write 2-3 63468 NULL
112637 +snd_info_entry_write_63474 snd_info_entry_write 3 63474 NULL
112638 +reada_find_extent_63486 reada_find_extent 2 63486 NULL
112639 +read_kcore_63488 read_kcore 3 63488 NULL
112640 +snd_pcm_plug_write_transfer_63503 snd_pcm_plug_write_transfer 0-3 63503 NULL
112641 +efx_mcdi_rpc_async_63529 efx_mcdi_rpc_async 4-5 63529 NULL
112642 +ubi_more_leb_change_data_63534 ubi_more_leb_change_data 4 63534 NULL
112643 +write_file_spectral_period_63536 write_file_spectral_period 3 63536 NULL
112644 +if_sdio_read_scratch_63540 if_sdio_read_scratch 0 63540 NULL
112645 +append_to_buffer_63550 append_to_buffer 3 63550 NULL
112646 +kvm_write_guest_page_63555 kvm_write_guest_page 5 63555 NULL
112647 +rproc_alloc_63577 rproc_alloc 5 63577 NULL
112648 +write_debug_level_63613 write_debug_level 3 63613 NULL
112649 +symbol_build_supp_rates_63634 symbol_build_supp_rates 0 63634 NULL
112650 +proc_loginuid_write_63648 proc_loginuid_write 3 63648 NULL
112651 +ValidateDSDParamsChecksum_63654 ValidateDSDParamsChecksum 3 63654 NULL
112652 +ldlm_cli_enqueue_63657 ldlm_cli_enqueue 8 63657 NULL
112653 +hidraw_ioctl_63658 hidraw_ioctl 2 63658 NULL
112654 +vbi_read_63673 vbi_read 3 63673 NULL
112655 +write_file_spectral_fft_period_63696 write_file_spectral_fft_period 3 63696 NULL
112656 +nouveau_object_create__63715 nouveau_object_create_ 5 63715 NULL
112657 +btrfs_insert_delayed_dir_index_63720 btrfs_insert_delayed_dir_index 4 63720 NULL
112658 +selinux_secctx_to_secid_63744 selinux_secctx_to_secid 2 63744 NULL
112659 +snd_pcm_oss_read1_63771 snd_pcm_oss_read1 3 63771 NULL
112660 +snd_opl4_mem_proc_read_63774 snd_opl4_mem_proc_read 5 63774 NULL
112661 +spidev_compat_ioctl_63778 spidev_compat_ioctl 2 63778 NULL
112662 +mwifiex_11n_create_rx_reorder_tbl_63806 mwifiex_11n_create_rx_reorder_tbl 4 63806 NULL
112663 +copy_nodes_to_user_63807 copy_nodes_to_user 2 63807 NULL
112664 +prepare_copy_63826 prepare_copy 2 63826 NULL
112665 +sel_write_load_63830 sel_write_load 3 63830 NULL
112666 +ll_readlink_63836 ll_readlink 3 63836 NULL
112667 +proc_pid_attr_write_63845 proc_pid_attr_write 3 63845 NULL
112668 +xhci_alloc_stream_info_63902 xhci_alloc_stream_info 3 63902 NULL
112669 +uvc_alloc_urb_buffers_63922 uvc_alloc_urb_buffers 0-2-3 63922 NULL
112670 +snd_compr_write_63923 snd_compr_write 3 63923 NULL
112671 +afs_send_simple_reply_63940 afs_send_simple_reply 3 63940 NULL
112672 +__team_options_register_63941 __team_options_register 3 63941 NULL
112673 +macvtap_recvmsg_63949 macvtap_recvmsg 4 63949 NULL
112674 +sysfs_add_one_63969 sysfs_add_one 0 63969 NULL
112675 +set_bredr_63975 set_bredr 4 63975 NULL
112676 +construct_key_and_link_63985 construct_key_and_link 3 63985 NULL
112677 +rs_extent_to_bm_page_63996 rs_extent_to_bm_page 0-1 63996 NULL
112678 +read_file_frameerrors_64001 read_file_frameerrors 3 64001 NULL
112679 +hfsplus_security_setxattr_64009 hfsplus_security_setxattr 4 64009 NULL
112680 +SyS_rt_sigpending_64018 SyS_rt_sigpending 2 64018 NULL
112681 +dbAllocDmapLev_64030 dbAllocDmapLev 0 64030 NULL
112682 +SyS_fsetxattr_64039 SyS_fsetxattr 4 64039 NULL
112683 +get_u8_64076 get_u8 0 64076 NULL
112684 +xilly_malloc_64077 xilly_malloc 2 64077 NULL
112685 +sl_realloc_bufs_64086 sl_realloc_bufs 2 64086 NULL
112686 +vmci_handle_arr_get_size_64088 vmci_handle_arr_get_size 0 64088 NULL
112687 +lbs_highrssi_read_64089 lbs_highrssi_read 3 64089 NULL
112688 +SyS_set_mempolicy_64096 SyS_set_mempolicy 3 64096 NULL
112689 +SyS_mq_timedsend_64107 SyS_mq_timedsend 3 64107 NULL
112690 +rdma_addr_size_64116 rdma_addr_size 0 64116 NULL
112691 +do_load_xattr_datum_64118 do_load_xattr_datum 0 64118 NULL
112692 +bypass_wd_write_64120 bypass_wd_write 3 64120 NULL
112693 +ext4_prepare_inline_data_64124 ext4_prepare_inline_data 3 64124 NULL
112694 +init_bch_64130 init_bch 1-2 64130 NULL
112695 +ablkcipher_copy_iv_64140 ablkcipher_copy_iv 3 64140 NULL
112696 +read_div_64147 read_div 0 64147 NULL
112697 +dlfb_ops_write_64150 dlfb_ops_write 3 64150 NULL
112698 +cpumask_scnprintf_64170 cpumask_scnprintf 0-2 64170 NULL
112699 +xfs_vm_direct_IO_64223 xfs_vm_direct_IO 4 64223 NULL
112700 +read_pulse_64227 read_pulse 0-3 64227 NULL
112701 +ea_len_64229 ea_len 0 64229 NULL
112702 +io_capture_transfer_64276 io_capture_transfer 4 64276 NULL
112703 +btrfs_file_extent_offset_64278 btrfs_file_extent_offset 0 64278 NULL
112704 +sta_current_tx_rate_read_64286 sta_current_tx_rate_read 3 64286 NULL
112705 +xfs_dir_cilookup_result_64288 xfs_dir_cilookup_result 3 64288 NULL nohasharray
112706 +event_id_read_64288 event_id_read 3 64288 &xfs_dir_cilookup_result_64288
112707 +ocfs2_block_check_validate_bhs_64302 ocfs2_block_check_validate_bhs 0 64302 NULL
112708 +snd_hda_get_sub_nodes_64304 snd_hda_get_sub_nodes 0 64304 NULL
112709 +error_error_bar_retry_read_64305 error_error_bar_retry_read 3 64305 NULL
112710 +sisusbcon_clear_64329 sisusbcon_clear 4-3-5 64329 NULL
112711 +ts_write_64336 ts_write 3 64336 NULL
112712 +usbtmc_write_64340 usbtmc_write 3 64340 NULL
112713 +bnx2x_vfop_mcast_cmd_64354 bnx2x_vfop_mcast_cmd 5 64354 NULL
112714 +user_regset_copyin_64360 user_regset_copyin 7 64360 NULL
112715 +wlc_phy_loadsampletable_nphy_64367 wlc_phy_loadsampletable_nphy 3 64367 NULL
112716 +reg_create_64372 reg_create 5 64372 NULL
112717 +ilo_write_64378 ilo_write 3 64378 NULL
112718 +btrfs_map_block_64379 btrfs_map_block 3 64379 NULL
112719 +vmcs_readl_64381 vmcs_readl 0 64381 NULL
112720 +nilfs_alloc_seg_bio_64383 nilfs_alloc_seg_bio 3 64383 NULL
112721 +ir_lirc_transmit_ir_64403 ir_lirc_transmit_ir 3 64403 NULL
112722 +pidlist_allocate_64404 pidlist_allocate 1 64404 NULL
112723 +rx_hdr_overflow_read_64407 rx_hdr_overflow_read 3 64407 NULL
112724 +snd_card_create_64418 snd_card_create 4 64418 NULL nohasharray
112725 +keyctl_get_security_64418 keyctl_get_security 3 64418 &snd_card_create_64418
112726 +oom_adj_write_64428 oom_adj_write 3 64428 NULL
112727 +read_file_spectral_short_repeat_64431 read_file_spectral_short_repeat 3 64431 NULL
112728 +ax25_recvmsg_64441 ax25_recvmsg 4 64441 NULL
112729 +single_open_size_64483 single_open_size 4 64483 NULL
112730 +p54_parse_rssical_64493 p54_parse_rssical 3 64493 NULL
112731 +msg_data_sz_64503 msg_data_sz 0 64503 NULL
112732 +remove_uuid_64505 remove_uuid 4 64505 NULL
112733 +crypto_blkcipher_alignmask_64520 crypto_blkcipher_alignmask 0 64520 NULL
112734 +opera1_usb_i2c_msgxfer_64521 opera1_usb_i2c_msgxfer 4 64521 NULL
112735 +iwl_dbgfs_ucode_tracing_write_64524 iwl_dbgfs_ucode_tracing_write 3 64524 NULL
112736 +ses_send_diag_64527 ses_send_diag 4 64527 NULL
112737 +prctl_set_mm_64538 prctl_set_mm 3 64538 NULL
112738 +SyS_bind_64544 SyS_bind 3 64544 NULL
112739 +rbd_obj_read_sync_64554 rbd_obj_read_sync 4-3 64554 NULL
112740 +__btrfs_prealloc_file_range_64557 __btrfs_prealloc_file_range 3 64557 NULL
112741 +__spi_sync_64561 __spi_sync 0 64561 NULL nohasharray
112742 +ll_max_rw_chunk_seq_write_64561 ll_max_rw_chunk_seq_write 3 64561 &__spi_sync_64561
112743 +__apei_exec_run_64563 __apei_exec_run 0 64563 NULL
112744 +kstrtoul_from_user_64569 kstrtoul_from_user 2 64569 NULL
112745 +do_erase_64574 do_erase 4 64574 NULL
112746 +fanotify_write_64623 fanotify_write 3 64623 NULL
112747 +regmap_read_debugfs_64658 regmap_read_debugfs 5 64658 NULL
112748 +ocfs2_read_xattr_block_64661 ocfs2_read_xattr_block 0 64661 NULL nohasharray
112749 +tlbflush_read_file_64661 tlbflush_read_file 3 64661 &ocfs2_read_xattr_block_64661
112750 +efx_tsoh_get_buffer_64664 efx_tsoh_get_buffer 3 64664 NULL
112751 +rx_rx_out_of_mpdu_nodes_read_64668 rx_rx_out_of_mpdu_nodes_read 3 64668 NULL
112752 +nr_free_zone_pages_64680 nr_free_zone_pages 0 64680 NULL
112753 +sec_bulk_write_64691 sec_bulk_write 2-3 64691 NULL
112754 +snd_pcm_oss_capture_position_fixup_64713 snd_pcm_oss_capture_position_fixup 0 64713 NULL
112755 +dapm_bias_read_file_64715 dapm_bias_read_file 3 64715 NULL
112756 +atomic_add_return_64720 atomic_add_return 0-1 64720 NULL
112757 +i2400m_msg_to_dev_64722 i2400m_msg_to_dev 3 64722 NULL
112758 +AscGetChipVersion_64737 AscGetChipVersion 0 64737 NULL
112759 +squashfs_read_inode_lookup_table_64739 squashfs_read_inode_lookup_table 4 64739 NULL
112760 +bio_map_kern_64751 bio_map_kern 3 64751 NULL
112761 +rt2x00debug_write_csr_64753 rt2x00debug_write_csr 3 64753 NULL
112762 +message_for_md_64777 message_for_md 5 64777 NULL
112763 +isr_low_rssi_read_64789 isr_low_rssi_read 3 64789 NULL
112764 +regmap_reg_ranges_read_file_64798 regmap_reg_ranges_read_file 3 64798 NULL
112765 +nfsctl_transaction_write_64800 nfsctl_transaction_write 3 64800 NULL
112766 +rfkill_fop_write_64808 rfkill_fop_write 3 64808 NULL
112767 +proc_projid_map_write_64810 proc_projid_map_write 3 64810 NULL
112768 +megaraid_change_queue_depth_64815 megaraid_change_queue_depth 2 64815 NULL
112769 +ecryptfs_send_miscdev_64816 ecryptfs_send_miscdev 2 64816 NULL
112770 +do_kimage_alloc_64827 do_kimage_alloc 3 64827 NULL
112771 +altera_set_dr_pre_64862 altera_set_dr_pre 2 64862 NULL
112772 +lprocfs_write_u64_helper_64880 lprocfs_write_u64_helper 2 64880 NULL
112773 +ffs_epfile_io_64886 ffs_epfile_io 3 64886 NULL
112774 +ieee80211_if_read_ave_beacon_64924 ieee80211_if_read_ave_beacon 3 64924 NULL
112775 +ip_options_get_from_user_64958 ip_options_get_from_user 4 64958 NULL
112776 +traceprobe_probes_write_64969 traceprobe_probes_write 3 64969 NULL
112777 +suspend_dtim_interval_read_64971 suspend_dtim_interval_read 3 64971 NULL
112778 +crypto_ahash_digestsize_65014 crypto_ahash_digestsize 0 65014 NULL
112779 +insert_dent_65034 insert_dent 7 65034 NULL
112780 +snd_hda_get_pin_label_65035 snd_hda_get_pin_label 5 65035 NULL
112781 +ext4_ind_trans_blocks_65053 ext4_ind_trans_blocks 0-2 65053 NULL
112782 +pcibios_enable_device_65059 pcibios_enable_device 0 65059 NULL
112783 +__alloc_bootmem_node_high_65076 __alloc_bootmem_node_high 2 65076 NULL
112784 +batadv_socket_write_65083 batadv_socket_write 3 65083 NULL
112785 +ocfs2_truncate_cluster_pages_65086 ocfs2_truncate_cluster_pages 2 65086 NULL
112786 +ath9k_dump_mci_btcoex_65090 ath9k_dump_mci_btcoex 3-0 65090 NULL
112787 +uasp_alloc_cmd_65097 uasp_alloc_cmd 0 65097 NULL
112788 +generic_ocp_write_65107 generic_ocp_write 4 65107 NULL
112789 +rx_rx_done_read_65217 rx_rx_done_read 3 65217 NULL
112790 +print_endpoint_stat_65232 print_endpoint_stat 3-4-0 65232 NULL
112791 +whci_n_caps_65247 whci_n_caps 0 65247 NULL
112792 +kmalloc_parameter_65279 kmalloc_parameter 1 65279 NULL
112793 +compat_core_sys_select_65285 compat_core_sys_select 1 65285 NULL
112794 +mpi_set_buffer_65294 mpi_set_buffer 3 65294 NULL
112795 +redirected_tty_write_65297 redirected_tty_write 3 65297 NULL
112796 +get_var_len_65304 get_var_len 0 65304 NULL
112797 +unpack_array_65318 unpack_array 0 65318 NULL
112798 +pci_vpd_find_tag_65325 pci_vpd_find_tag 0-2 65325 NULL
112799 +dccp_setsockopt_service_65336 dccp_setsockopt_service 4 65336 NULL
112800 +dma_rx_requested_read_65354 dma_rx_requested_read 3 65354 NULL
112801 +alloc_cpu_rmap_65363 alloc_cpu_rmap 1 65363 NULL
112802 +SyS_writev_65372 SyS_writev 3 65372 NULL
112803 +__alloc_bootmem_nopanic_65397 __alloc_bootmem_nopanic 1 65397 NULL
112804 +trace_seq_to_user_65398 trace_seq_to_user 3 65398 NULL
112805 +__read_vmcore_65402 __read_vmcore 2 65402 NULL
112806 +usb_ep_enable_65405 usb_ep_enable 0 65405 NULL
112807 +ocfs2_write_begin_nolock_65410 ocfs2_write_begin_nolock 3-4 65410 NULL
112808 +device_add_groups_65423 device_add_groups 0 65423 NULL
112809 +xpc_kzalloc_cacheline_aligned_65433 xpc_kzalloc_cacheline_aligned 1 65433 NULL
112810 +usb_alloc_coherent_65444 usb_alloc_coherent 2 65444 NULL
112811 +il_dbgfs_wd_timeout_write_65464 il_dbgfs_wd_timeout_write 3 65464 NULL
112812 +clear_user_65470 clear_user 2 65470 NULL
112813 +dpcm_state_read_file_65489 dpcm_state_read_file 3 65489 NULL
112814 +lookup_inline_extent_backref_65493 lookup_inline_extent_backref 9 65493 NULL
112815 +nvme_trans_standard_inquiry_page_65526 nvme_trans_standard_inquiry_page 4 65526 NULL
112816 diff --git a/tools/gcc/size_overflow_plugin.c b/tools/gcc/size_overflow_plugin.c
112817 new file mode 100644
112818 index 0000000..4aab36f
112819 --- /dev/null
112820 +++ b/tools/gcc/size_overflow_plugin.c
112821 @@ -0,0 +1,4051 @@
112822 +/*
112823 + * Copyright 2011-2014 by Emese Revfy <re.emese@gmail.com>
112824 + * Licensed under the GPL v2, or (at your option) v3
112825 + *
112826 + * Homepage:
112827 + * http://www.grsecurity.net/~ephox/overflow_plugin/
112828 + *
112829 + * Documentation:
112830 + * http://forums.grsecurity.net/viewtopic.php?f=7&t=3043
112831 + *
112832 + * This plugin recomputes expressions of function arguments marked by a size_overflow attribute
112833 + * with double integer precision (DImode/TImode for 32/64 bit integer types).
112834 + * The recomputed argument is checked against TYPE_MAX and an event is logged on overflow and the triggering process is killed.
112835 + *
112836 + * Usage:
112837 + * $ gcc -I`gcc -print-file-name=plugin`/include/c-family -I`gcc -print-file-name=plugin`/include -fPIC -shared -O2 -ggdb -Wall -W -o size_overflow_plugin.so size_overflow_plugin.c
112838 + * $ gcc -fplugin=size_overflow_plugin.so test.c -O2
112839 + */
112840 +
112841 +#include "gcc-common.h"
112842 +
112843 +int plugin_is_GPL_compatible;
112844 +
112845 +static struct plugin_info size_overflow_plugin_info = {
112846 + .version = "20140213",
112847 + .help = "no-size-overflow\tturn off size overflow checking\n",
112848 +};
112849 +
112850 +#define BEFORE_STMT true
112851 +#define AFTER_STMT false
112852 +#define CREATE_NEW_VAR NULL_TREE
112853 +#define CODES_LIMIT 32
112854 +#define MAX_PARAM 31
112855 +#define VEC_LEN 128
112856 +#define MY_STMT GF_PLF_1
112857 +#define NO_CAST_CHECK GF_PLF_2
112858 +#define RET_CHECK NULL_TREE
112859 +#define CANNOT_FIND_ARG 32
112860 +#define WRONG_NODE 32
112861 +#define NOT_INTENTIONAL_ASM NULL
112862 +#define MIN_CHECK true
112863 +#define MAX_CHECK false
112864 +
112865 +#define TURN_OFF_ASM_STR "# size_overflow MARK_TURN_OFF "
112866 +#define YES_ASM_STR "# size_overflow MARK_YES "
112867 +#define OK_ASM_STR "# size_overflow "
112868 +
112869 +struct size_overflow_hash {
112870 + const struct size_overflow_hash * const next;
112871 + const char * const name;
112872 + const unsigned int param;
112873 +};
112874 +
112875 +#include "size_overflow_hash.h"
112876 +
112877 +enum mark {
112878 + MARK_NO, MARK_YES, MARK_NOT_INTENTIONAL, MARK_TURN_OFF
112879 +};
112880 +
112881 +static unsigned int call_count;
112882 +
112883 +struct visited {
112884 + struct visited *next;
112885 + const_tree fndecl;
112886 + unsigned int num;
112887 + const_tree rhs;
112888 +};
112889 +
112890 +struct next_cgraph_node {
112891 + struct next_cgraph_node *next;
112892 + struct cgraph_node *current_function;
112893 + tree callee_fndecl;
112894 + unsigned int num;
112895 +};
112896 +
112897 +struct interesting_node {
112898 + struct interesting_node *next;
112899 + gimple first_stmt;
112900 + const_tree fndecl;
112901 + tree node;
112902 +#if BUILDING_GCC_VERSION <= 4007
112903 + VEC(tree, gc) *last_nodes;
112904 +#else
112905 + vec<tree, va_gc> *last_nodes;
112906 +#endif
112907 + unsigned int num;
112908 + enum mark intentional_attr_decl;
112909 + enum mark intentional_attr_cur_fndecl;
112910 + gimple intentional_mark_from_gimple;
112911 +};
112912 +
112913 +static tree report_size_overflow_decl;
112914 +
112915 +static tree expand(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs);
112916 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs);
112917 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs);
112918 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs);
112919 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs);
112920 +
112921 +static void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before);
112922 +static tree get_size_overflow_type(gimple stmt, const_tree node);
112923 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3);
112924 +
112925 +static tree handle_size_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
112926 +{
112927 + unsigned int arg_count;
112928 + enum tree_code code = TREE_CODE(*node);
112929 +
112930 + switch (code) {
112931 + case FUNCTION_DECL:
112932 + arg_count = type_num_arguments(TREE_TYPE(*node));
112933 + break;
112934 + case FUNCTION_TYPE:
112935 + case METHOD_TYPE:
112936 + arg_count = type_num_arguments(*node);
112937 + break;
112938 + default:
112939 + *no_add_attrs = true;
112940 + error("%s: %qE attribute only applies to functions", __func__, name);
112941 + return NULL_TREE;
112942 + }
112943 +
112944 + for (; args; args = TREE_CHAIN(args)) {
112945 + tree position = TREE_VALUE(args);
112946 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
112947 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
112948 + *no_add_attrs = true;
112949 + }
112950 + }
112951 + return NULL_TREE;
112952 +}
112953 +
112954 +static tree handle_intentional_overflow_attribute(tree *node, tree __unused name, tree args, int __unused flags, bool *no_add_attrs)
112955 +{
112956 + unsigned int arg_count;
112957 + enum tree_code code = TREE_CODE(*node);
112958 +
112959 + switch (code) {
112960 + case FUNCTION_DECL:
112961 + arg_count = type_num_arguments(TREE_TYPE(*node));
112962 + break;
112963 + case FUNCTION_TYPE:
112964 + case METHOD_TYPE:
112965 + arg_count = type_num_arguments(*node);
112966 + break;
112967 + case FIELD_DECL:
112968 + return NULL_TREE;
112969 + default:
112970 + *no_add_attrs = true;
112971 + error("%qE attribute only applies to functions", name);
112972 + return NULL_TREE;
112973 + }
112974 +
112975 + if (TREE_INT_CST_HIGH(TREE_VALUE(args)) != 0)
112976 + return NULL_TREE;
112977 +
112978 + for (; args; args = TREE_CHAIN(args)) {
112979 + tree position = TREE_VALUE(args);
112980 + if (TREE_CODE(position) != INTEGER_CST || TREE_INT_CST_LOW(position) > arg_count ) {
112981 + error("%s: parameter %u is outside range.", __func__, (unsigned int)TREE_INT_CST_LOW(position));
112982 + *no_add_attrs = true;
112983 + }
112984 + }
112985 + return NULL_TREE;
112986 +}
112987 +
112988 +static struct attribute_spec size_overflow_attr = {
112989 + .name = "size_overflow",
112990 + .min_length = 1,
112991 + .max_length = -1,
112992 + .decl_required = true,
112993 + .type_required = false,
112994 + .function_type_required = false,
112995 + .handler = handle_size_overflow_attribute,
112996 +#if BUILDING_GCC_VERSION >= 4007
112997 + .affects_type_identity = false
112998 +#endif
112999 +};
113000 +
113001 +static struct attribute_spec intentional_overflow_attr = {
113002 + .name = "intentional_overflow",
113003 + .min_length = 1,
113004 + .max_length = -1,
113005 + .decl_required = true,
113006 + .type_required = false,
113007 + .function_type_required = false,
113008 + .handler = handle_intentional_overflow_attribute,
113009 +#if BUILDING_GCC_VERSION >= 4007
113010 + .affects_type_identity = false
113011 +#endif
113012 +};
113013 +
113014 +static void register_attributes(void __unused *event_data, void __unused *data)
113015 +{
113016 + register_attribute(&size_overflow_attr);
113017 + register_attribute(&intentional_overflow_attr);
113018 +}
113019 +
113020 +static bool is_bool(const_tree node)
113021 +{
113022 + const_tree type;
113023 +
113024 + if (node == NULL_TREE)
113025 + return false;
113026 +
113027 + type = TREE_TYPE(node);
113028 + if (!INTEGRAL_TYPE_P(type))
113029 + return false;
113030 + if (TREE_CODE(type) == BOOLEAN_TYPE)
113031 + return true;
113032 + if (TYPE_PRECISION(type) == 1)
113033 + return true;
113034 + return false;
113035 +}
113036 +
113037 +static bool skip_types(const_tree var)
113038 +{
113039 + tree type;
113040 + enum tree_code code;
113041 +
113042 + if (is_gimple_constant(var))
113043 + return true;
113044 +
113045 + switch (TREE_CODE(var)) {
113046 + case ADDR_EXPR:
113047 +#if BUILDING_GCC_VERSION >= 4006
113048 + case MEM_REF:
113049 +#endif
113050 + case ARRAY_REF:
113051 + case BIT_FIELD_REF:
113052 + case INDIRECT_REF:
113053 + case TARGET_MEM_REF:
113054 + case COMPONENT_REF:
113055 + case VAR_DECL:
113056 + case VIEW_CONVERT_EXPR:
113057 + return true;
113058 + default:
113059 + break;
113060 + }
113061 +
113062 + code = TREE_CODE(var);
113063 + gcc_assert(code == SSA_NAME || code == PARM_DECL);
113064 +
113065 + type = TREE_TYPE(var);
113066 + switch (TREE_CODE(type)) {
113067 + case INTEGER_TYPE:
113068 + case ENUMERAL_TYPE:
113069 + return false;
113070 + case BOOLEAN_TYPE:
113071 + return is_bool(var);
113072 + default:
113073 + return true;
113074 + }
113075 +}
113076 +
113077 +static inline gimple get_def_stmt(const_tree node)
113078 +{
113079 + gcc_assert(node != NULL_TREE);
113080 +
113081 + if (skip_types(node))
113082 + return NULL;
113083 +
113084 + if (TREE_CODE(node) != SSA_NAME)
113085 + return NULL;
113086 + return SSA_NAME_DEF_STMT(node);
113087 +}
113088 +
113089 +static unsigned char get_tree_code(const_tree type)
113090 +{
113091 + switch (TREE_CODE(type)) {
113092 + case ARRAY_TYPE:
113093 + return 0;
113094 + case BOOLEAN_TYPE:
113095 + return 1;
113096 + case ENUMERAL_TYPE:
113097 + return 2;
113098 + case FUNCTION_TYPE:
113099 + return 3;
113100 + case INTEGER_TYPE:
113101 + return 4;
113102 + case POINTER_TYPE:
113103 + return 5;
113104 + case RECORD_TYPE:
113105 + return 6;
113106 + case UNION_TYPE:
113107 + return 7;
113108 + case VOID_TYPE:
113109 + return 8;
113110 + case REAL_TYPE:
113111 + return 9;
113112 + case VECTOR_TYPE:
113113 + return 10;
113114 + case REFERENCE_TYPE:
113115 + return 11;
113116 + case OFFSET_TYPE:
113117 + return 12;
113118 + case COMPLEX_TYPE:
113119 + return 13;
113120 + default:
113121 + debug_tree((tree)type);
113122 + gcc_unreachable();
113123 + }
113124 +}
113125 +
113126 +struct function_hash {
113127 + size_t tree_codes_len;
113128 + unsigned char tree_codes[CODES_LIMIT];
113129 + const_tree fndecl;
113130 + unsigned int hash;
113131 +};
113132 +
113133 +// http://www.team5150.com/~andrew/noncryptohashzoo2~/CrapWow.html
113134 +static unsigned int CrapWow(const char *key, unsigned int len, unsigned int seed)
113135 +{
113136 +#define cwfold( a, b, lo, hi ) { p = (unsigned int)(a) * (unsigned long long)(b); lo ^= (unsigned int)p; hi ^= (unsigned int)(p >> 32); }
113137 +#define cwmixa( in ) { cwfold( in, m, k, h ); }
113138 +#define cwmixb( in ) { cwfold( in, n, h, k ); }
113139 +
113140 + unsigned int m = 0x57559429;
113141 + unsigned int n = 0x5052acdb;
113142 + const unsigned int *key4 = (const unsigned int *)key;
113143 + unsigned int h = len;
113144 + unsigned int k = len + seed + n;
113145 + unsigned long long p;
113146 +
113147 + while (len >= 8) {
113148 + cwmixb(key4[0]) cwmixa(key4[1]) key4 += 2;
113149 + len -= 8;
113150 + }
113151 + if (len >= 4) {
113152 + cwmixb(key4[0]) key4 += 1;
113153 + len -= 4;
113154 + }
113155 + if (len)
113156 + cwmixa(key4[0] & ((1 << (len * 8)) - 1 ));
113157 + cwmixb(h ^ (k + n));
113158 + return k ^ h;
113159 +
113160 +#undef cwfold
113161 +#undef cwmixa
113162 +#undef cwmixb
113163 +}
113164 +
113165 +static void set_hash(const char *fn_name, struct function_hash *fn_hash_data)
113166 +{
113167 + unsigned int fn, codes, seed = 0;
113168 +
113169 + fn = CrapWow(fn_name, strlen(fn_name), seed) & 0xffff;
113170 + codes = CrapWow((const char*)fn_hash_data->tree_codes, fn_hash_data->tree_codes_len, seed) & 0xffff;
113171 +
113172 + fn_hash_data->hash = fn ^ codes;
113173 +}
113174 +
113175 +static void set_node_codes(const_tree type, struct function_hash *fn_hash_data)
113176 +{
113177 + gcc_assert(type != NULL_TREE);
113178 + gcc_assert(TREE_CODE_CLASS(TREE_CODE(type)) == tcc_type);
113179 +
113180 + while (type && fn_hash_data->tree_codes_len < CODES_LIMIT) {
113181 + fn_hash_data->tree_codes[fn_hash_data->tree_codes_len] = get_tree_code(type);
113182 + fn_hash_data->tree_codes_len++;
113183 + type = TREE_TYPE(type);
113184 + }
113185 +}
113186 +
113187 +static void set_result_codes(const_tree node, struct function_hash *fn_hash_data)
113188 +{
113189 + const_tree result;
113190 +
113191 + gcc_assert(node != NULL_TREE);
113192 +
113193 + if (DECL_P(node)) {
113194 + result = DECL_RESULT(node);
113195 + if (result != NULL_TREE)
113196 + return set_node_codes(TREE_TYPE(result), fn_hash_data);
113197 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
113198 + }
113199 +
113200 + gcc_assert(TYPE_P(node));
113201 +
113202 + if (TREE_CODE(node) == FUNCTION_TYPE)
113203 + return set_result_codes(TREE_TYPE(node), fn_hash_data);
113204 +
113205 + return set_node_codes(node, fn_hash_data);
113206 +}
113207 +
113208 +static void set_function_codes(struct function_hash *fn_hash_data)
113209 +{
113210 + const_tree arg, type = TREE_TYPE(fn_hash_data->fndecl);
113211 + enum tree_code code = TREE_CODE(type);
113212 +
113213 + gcc_assert(code == FUNCTION_TYPE || code == METHOD_TYPE);
113214 +
113215 + set_result_codes(fn_hash_data->fndecl, fn_hash_data);
113216 +
113217 + for (arg = TYPE_ARG_TYPES(type); arg != NULL_TREE && fn_hash_data->tree_codes_len < CODES_LIMIT; arg = TREE_CHAIN(arg))
113218 + set_node_codes(TREE_VALUE(arg), fn_hash_data);
113219 +}
113220 +
113221 +static const struct size_overflow_hash *get_function_hash(const_tree fndecl)
113222 +{
113223 + const struct size_overflow_hash *entry;
113224 + struct function_hash fn_hash_data;
113225 + const char *func_name;
113226 +
113227 + // skip builtins __builtin_constant_p
113228 + if (DECL_BUILT_IN(fndecl))
113229 + return NULL;
113230 +
113231 + fn_hash_data.fndecl = fndecl;
113232 + fn_hash_data.tree_codes_len = 0;
113233 +
113234 + set_function_codes(&fn_hash_data);
113235 + gcc_assert(fn_hash_data.tree_codes_len != 0);
113236 +
113237 + func_name = DECL_NAME_POINTER(fn_hash_data.fndecl);
113238 + set_hash(func_name, &fn_hash_data);
113239 +
113240 + entry = size_overflow_hash[fn_hash_data.hash];
113241 +
113242 + while (entry) {
113243 + if (!strcmp(entry->name, func_name))
113244 + return entry;
113245 + entry = entry->next;
113246 + }
113247 + return NULL;
113248 +}
113249 +
113250 +static void print_missing_msg(const_tree func, unsigned int argnum)
113251 +{
113252 + location_t loc;
113253 + const char *curfunc;
113254 + struct function_hash fn_hash_data;
113255 +
113256 + fn_hash_data.fndecl = DECL_ORIGIN(func);
113257 + fn_hash_data.tree_codes_len = 0;
113258 +
113259 + loc = DECL_SOURCE_LOCATION(fn_hash_data.fndecl);
113260 + curfunc = DECL_NAME_POINTER(fn_hash_data.fndecl);
113261 +
113262 + set_function_codes(&fn_hash_data);
113263 + set_hash(curfunc, &fn_hash_data);
113264 +
113265 + inform(loc, "Function %s is missing from the size_overflow hash table +%s+%u+%u+", curfunc, curfunc, argnum, fn_hash_data.hash);
113266 +}
113267 +
113268 +static unsigned int find_arg_number_tree(const_tree arg, const_tree func)
113269 +{
113270 + tree var;
113271 + unsigned int argnum = 1;
113272 +
113273 + if (TREE_CODE(arg) == SSA_NAME)
113274 + arg = SSA_NAME_VAR(arg);
113275 +
113276 + for (var = DECL_ARGUMENTS(func); var; var = TREE_CHAIN(var), argnum++) {
113277 + if (!operand_equal_p(arg, var, 0) && strcmp(DECL_NAME_POINTER(var), DECL_NAME_POINTER(arg)))
113278 + continue;
113279 + if (!skip_types(var))
113280 + return argnum;
113281 + }
113282 +
113283 + return CANNOT_FIND_ARG;
113284 +}
113285 +
113286 +static tree create_new_var(tree type)
113287 +{
113288 + tree new_var = create_tmp_var(type, "cicus");
113289 +
113290 + add_referenced_var(new_var);
113291 + return new_var;
113292 +}
113293 +
113294 +static gimple create_binary_assign(enum tree_code code, gimple stmt, tree rhs1, tree rhs2)
113295 +{
113296 + gimple assign;
113297 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
113298 + tree type = TREE_TYPE(rhs1);
113299 + tree lhs = create_new_var(type);
113300 +
113301 + gcc_assert(types_compatible_p(type, TREE_TYPE(rhs2)));
113302 + assign = gimple_build_assign_with_ops(code, lhs, rhs1, rhs2);
113303 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
113304 +
113305 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
113306 + update_stmt(assign);
113307 + gimple_set_plf(assign, MY_STMT, true);
113308 + return assign;
113309 +}
113310 +
113311 +static tree cast_a_tree(tree type, tree var)
113312 +{
113313 + gcc_assert(type != NULL_TREE);
113314 + gcc_assert(var != NULL_TREE);
113315 + gcc_assert(fold_convertible_p(type, var));
113316 +
113317 + return fold_convert(type, var);
113318 +}
113319 +
113320 +static tree get_lhs(const_gimple stmt)
113321 +{
113322 + switch (gimple_code(stmt)) {
113323 + case GIMPLE_ASSIGN:
113324 + case GIMPLE_CALL:
113325 + return gimple_get_lhs(stmt);
113326 + case GIMPLE_PHI:
113327 + return gimple_phi_result(stmt);
113328 + default:
113329 + return NULL_TREE;
113330 + }
113331 +}
113332 +
113333 +static bool skip_cast(tree dst_type, const_tree rhs, bool force)
113334 +{
113335 + const_gimple def_stmt = get_def_stmt(rhs);
113336 +
113337 + if (force)
113338 + return false;
113339 +
113340 + if (is_gimple_constant(rhs))
113341 + return false;
113342 +
113343 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
113344 + return false;
113345 +
113346 + if (!types_compatible_p(dst_type, TREE_TYPE(rhs)))
113347 + return false;
113348 +
113349 + // DI type can be on 32 bit (from create_assign) but overflow type stays DI
113350 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
113351 + return false;
113352 +
113353 + return true;
113354 +}
113355 +
113356 +static gimple build_cast_stmt(tree dst_type, tree rhs, tree lhs, gimple_stmt_iterator *gsi, bool before, bool force)
113357 +{
113358 + gimple assign, def_stmt;
113359 +
113360 + gcc_assert(dst_type != NULL_TREE && rhs != NULL_TREE);
113361 + if (gsi_end_p(*gsi) && before == AFTER_STMT)
113362 + gcc_unreachable();
113363 +
113364 + def_stmt = get_def_stmt(rhs);
113365 + if (def_stmt && gimple_code(def_stmt) != GIMPLE_NOP && skip_cast(dst_type, rhs, force) && gimple_plf(def_stmt, MY_STMT))
113366 + return def_stmt;
113367 +
113368 + if (lhs == CREATE_NEW_VAR)
113369 + lhs = create_new_var(dst_type);
113370 +
113371 + assign = gimple_build_assign(lhs, cast_a_tree(dst_type, rhs));
113372 +
113373 + if (!gsi_end_p(*gsi)) {
113374 + location_t loc = gimple_location(gsi_stmt(*gsi));
113375 + gimple_set_location(assign, loc);
113376 + }
113377 +
113378 + gimple_assign_set_lhs(assign, make_ssa_name(lhs, assign));
113379 +
113380 + if (before)
113381 + gsi_insert_before(gsi, assign, GSI_NEW_STMT);
113382 + else
113383 + gsi_insert_after(gsi, assign, GSI_NEW_STMT);
113384 + update_stmt(assign);
113385 + return assign;
113386 +}
113387 +
113388 +static tree cast_to_new_size_overflow_type(gimple stmt, tree rhs, tree size_overflow_type, bool before)
113389 +{
113390 + gimple_stmt_iterator gsi;
113391 + tree lhs;
113392 + gimple new_stmt;
113393 +
113394 + if (rhs == NULL_TREE)
113395 + return NULL_TREE;
113396 +
113397 + gsi = gsi_for_stmt(stmt);
113398 + new_stmt = build_cast_stmt(size_overflow_type, rhs, CREATE_NEW_VAR, &gsi, before, false);
113399 + gimple_set_plf(new_stmt, MY_STMT, true);
113400 +
113401 + lhs = get_lhs(new_stmt);
113402 + gcc_assert(lhs != NULL_TREE);
113403 + return lhs;
113404 +}
113405 +
113406 +static tree cast_to_TI_type(gimple stmt, tree node)
113407 +{
113408 + gimple_stmt_iterator gsi;
113409 + gimple cast_stmt;
113410 + tree type = TREE_TYPE(node);
113411 +
113412 + if (types_compatible_p(type, intTI_type_node))
113413 + return node;
113414 +
113415 + gsi = gsi_for_stmt(stmt);
113416 + cast_stmt = build_cast_stmt(intTI_type_node, node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
113417 + gimple_set_plf(cast_stmt, MY_STMT, true);
113418 + return gimple_assign_lhs(cast_stmt);
113419 +}
113420 +
113421 +static tree create_assign(struct pointer_set_t *visited, gimple oldstmt, tree rhs1, bool before)
113422 +{
113423 + tree lhs, new_lhs;
113424 + gimple_stmt_iterator gsi;
113425 +
113426 + if (rhs1 == NULL_TREE) {
113427 + debug_gimple_stmt(oldstmt);
113428 + error("%s: rhs1 is NULL_TREE", __func__);
113429 + gcc_unreachable();
113430 + }
113431 +
113432 + switch (gimple_code(oldstmt)) {
113433 + case GIMPLE_ASM:
113434 + lhs = rhs1;
113435 + break;
113436 + case GIMPLE_CALL:
113437 + case GIMPLE_ASSIGN:
113438 + lhs = gimple_get_lhs(oldstmt);
113439 + break;
113440 + default:
113441 + debug_gimple_stmt(oldstmt);
113442 + gcc_unreachable();
113443 + }
113444 +
113445 + gsi = gsi_for_stmt(oldstmt);
113446 + pointer_set_insert(visited, oldstmt);
113447 + if (lookup_stmt_eh_lp(oldstmt) != 0) {
113448 + basic_block next_bb, cur_bb;
113449 + const_edge e;
113450 +
113451 + gcc_assert(before == false);
113452 + gcc_assert(stmt_can_throw_internal(oldstmt));
113453 + gcc_assert(gimple_code(oldstmt) == GIMPLE_CALL);
113454 + gcc_assert(!gsi_end_p(gsi));
113455 +
113456 + cur_bb = gimple_bb(oldstmt);
113457 + next_bb = cur_bb->next_bb;
113458 + e = find_edge(cur_bb, next_bb);
113459 + gcc_assert(e != NULL);
113460 + gcc_assert(e->flags & EDGE_FALLTHRU);
113461 +
113462 + gsi = gsi_after_labels(next_bb);
113463 + gcc_assert(!gsi_end_p(gsi));
113464 +
113465 + before = true;
113466 + oldstmt = gsi_stmt(gsi);
113467 + }
113468 +
113469 + new_lhs = cast_to_new_size_overflow_type(oldstmt, rhs1, get_size_overflow_type(oldstmt, lhs), before);
113470 + return new_lhs;
113471 +}
113472 +
113473 +static tree dup_assign(struct pointer_set_t *visited, gimple oldstmt, const_tree node, tree rhs1, tree rhs2, tree __unused rhs3)
113474 +{
113475 + gimple stmt;
113476 + gimple_stmt_iterator gsi;
113477 + tree size_overflow_type, new_var, lhs = gimple_assign_lhs(oldstmt);
113478 +
113479 + if (gimple_plf(oldstmt, MY_STMT))
113480 + return lhs;
113481 +
113482 + if (gimple_num_ops(oldstmt) != 4 && rhs1 == NULL_TREE) {
113483 + rhs1 = gimple_assign_rhs1(oldstmt);
113484 + rhs1 = create_assign(visited, oldstmt, rhs1, BEFORE_STMT);
113485 + }
113486 + if (gimple_num_ops(oldstmt) == 3 && rhs2 == NULL_TREE) {
113487 + rhs2 = gimple_assign_rhs2(oldstmt);
113488 + rhs2 = create_assign(visited, oldstmt, rhs2, BEFORE_STMT);
113489 + }
113490 +
113491 + stmt = gimple_copy(oldstmt);
113492 + gimple_set_location(stmt, gimple_location(oldstmt));
113493 + gimple_set_plf(stmt, MY_STMT, true);
113494 +
113495 + if (gimple_assign_rhs_code(oldstmt) == WIDEN_MULT_EXPR)
113496 + gimple_assign_set_rhs_code(stmt, MULT_EXPR);
113497 +
113498 + size_overflow_type = get_size_overflow_type(oldstmt, node);
113499 +
113500 + new_var = create_new_var(size_overflow_type);
113501 + new_var = make_ssa_name(new_var, stmt);
113502 + gimple_assign_set_lhs(stmt, new_var);
113503 +
113504 + if (rhs1 != NULL_TREE)
113505 + gimple_assign_set_rhs1(stmt, rhs1);
113506 +
113507 + if (rhs2 != NULL_TREE)
113508 + gimple_assign_set_rhs2(stmt, rhs2);
113509 +#if BUILDING_GCC_VERSION >= 4006
113510 + if (rhs3 != NULL_TREE)
113511 + gimple_assign_set_rhs3(stmt, rhs3);
113512 +#endif
113513 + gimple_set_vuse(stmt, gimple_vuse(oldstmt));
113514 + gimple_set_vdef(stmt, gimple_vdef(oldstmt));
113515 +
113516 + gsi = gsi_for_stmt(oldstmt);
113517 + gsi_insert_after(&gsi, stmt, GSI_SAME_STMT);
113518 + update_stmt(stmt);
113519 + pointer_set_insert(visited, oldstmt);
113520 + return gimple_assign_lhs(stmt);
113521 +}
113522 +
113523 +static tree cast_parm_decl(tree phi_ssa_name, tree arg, tree size_overflow_type, basic_block bb)
113524 +{
113525 + gimple assign;
113526 + gimple_stmt_iterator gsi;
113527 + basic_block first_bb;
113528 +
113529 + gcc_assert(SSA_NAME_IS_DEFAULT_DEF(arg));
113530 +
113531 + if (bb->index == 0) {
113532 + first_bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
113533 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
113534 + set_immediate_dominator(CDI_DOMINATORS, first_bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
113535 + bb = first_bb;
113536 + }
113537 +
113538 + gsi = gsi_after_labels(bb);
113539 + assign = build_cast_stmt(size_overflow_type, arg, phi_ssa_name, &gsi, BEFORE_STMT, false);
113540 + gimple_set_plf(assign, MY_STMT, true);
113541 +
113542 + return gimple_assign_lhs(assign);
113543 +}
113544 +
113545 +static tree use_phi_ssa_name(tree ssa_name_var, tree new_arg)
113546 +{
113547 + gimple_stmt_iterator gsi;
113548 + gimple assign, def_stmt = get_def_stmt(new_arg);
113549 +
113550 + if (gimple_code(def_stmt) == GIMPLE_PHI) {
113551 + gsi = gsi_after_labels(gimple_bb(def_stmt));
113552 + assign = build_cast_stmt(TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, BEFORE_STMT, true);
113553 + } else {
113554 + gsi = gsi_for_stmt(def_stmt);
113555 + assign = build_cast_stmt(TREE_TYPE(new_arg), new_arg, ssa_name_var, &gsi, AFTER_STMT, true);
113556 + }
113557 +
113558 + gimple_set_plf(assign, MY_STMT, true);
113559 + return gimple_assign_lhs(assign);
113560 +}
113561 +
113562 +static tree cast_visited_phi_arg(tree ssa_name_var, tree arg, tree size_overflow_type)
113563 +{
113564 + basic_block bb;
113565 + gimple_stmt_iterator gsi;
113566 + const_gimple def_stmt;
113567 + gimple assign;
113568 +
113569 + def_stmt = get_def_stmt(arg);
113570 + bb = gimple_bb(def_stmt);
113571 + gcc_assert(bb->index != 0);
113572 + gsi = gsi_after_labels(bb);
113573 +
113574 + assign = build_cast_stmt(size_overflow_type, arg, ssa_name_var, &gsi, BEFORE_STMT, false);
113575 + gimple_set_plf(assign, MY_STMT, true);
113576 + return gimple_assign_lhs(assign);
113577 +}
113578 +
113579 +static tree create_new_phi_arg(tree ssa_name_var, tree new_arg, gimple oldstmt, unsigned int i)
113580 +{
113581 + tree size_overflow_type;
113582 + tree arg;
113583 + const_gimple def_stmt;
113584 +
113585 + if (new_arg != NULL_TREE && is_gimple_constant(new_arg))
113586 + return new_arg;
113587 +
113588 + arg = gimple_phi_arg_def(oldstmt, i);
113589 + def_stmt = get_def_stmt(arg);
113590 + gcc_assert(def_stmt != NULL);
113591 + size_overflow_type = get_size_overflow_type(oldstmt, arg);
113592 +
113593 + switch (gimple_code(def_stmt)) {
113594 + case GIMPLE_PHI:
113595 + return cast_visited_phi_arg(ssa_name_var, arg, size_overflow_type);
113596 + case GIMPLE_NOP: {
113597 + basic_block bb;
113598 +
113599 + bb = gimple_phi_arg_edge(oldstmt, i)->src;
113600 + return cast_parm_decl(ssa_name_var, arg, size_overflow_type, bb);
113601 + }
113602 + case GIMPLE_ASM: {
113603 + gimple_stmt_iterator gsi;
113604 + gimple assign, stmt = get_def_stmt(arg);
113605 +
113606 + gsi = gsi_for_stmt(stmt);
113607 + assign = build_cast_stmt(size_overflow_type, arg, ssa_name_var, &gsi, AFTER_STMT, false);
113608 + gimple_set_plf(assign, MY_STMT, true);
113609 + return gimple_assign_lhs(assign);
113610 + }
113611 + default:
113612 + gcc_assert(new_arg != NULL_TREE);
113613 + gcc_assert(types_compatible_p(TREE_TYPE(new_arg), size_overflow_type));
113614 + return use_phi_ssa_name(ssa_name_var, new_arg);
113615 + }
113616 +}
113617 +
113618 +static gimple overflow_create_phi_node(gimple oldstmt, tree result)
113619 +{
113620 + basic_block bb;
113621 + gimple phi;
113622 + gimple_seq seq;
113623 + gimple_stmt_iterator gsi = gsi_for_stmt(oldstmt);
113624 +
113625 + bb = gsi_bb(gsi);
113626 +
113627 + if (result == NULL_TREE) {
113628 + tree old_result = gimple_phi_result(oldstmt);
113629 + tree size_overflow_type = get_size_overflow_type(oldstmt, old_result);
113630 +
113631 + result = create_new_var(size_overflow_type);
113632 + }
113633 +
113634 + phi = create_phi_node(result, bb);
113635 + gimple_phi_set_result(phi, make_ssa_name(result, phi));
113636 + seq = phi_nodes(bb);
113637 + gsi = gsi_last(seq);
113638 + gsi_remove(&gsi, false);
113639 +
113640 + gsi = gsi_for_stmt(oldstmt);
113641 + gsi_insert_after(&gsi, phi, GSI_NEW_STMT);
113642 + gimple_set_bb(phi, bb);
113643 + gimple_set_plf(phi, MY_STMT, true);
113644 + return phi;
113645 +}
113646 +
113647 +#if BUILDING_GCC_VERSION <= 4007
113648 +static tree create_new_phi_node(VEC(tree, heap) **args, tree ssa_name_var, gimple oldstmt)
113649 +#else
113650 +static tree create_new_phi_node(vec<tree, va_heap, vl_embed> *&args, tree ssa_name_var, gimple oldstmt)
113651 +#endif
113652 +{
113653 + gimple new_phi;
113654 + unsigned int i;
113655 + tree arg, result;
113656 + location_t loc = gimple_location(oldstmt);
113657 +
113658 +#if BUILDING_GCC_VERSION <= 4007
113659 + gcc_assert(!VEC_empty(tree, *args));
113660 +#else
113661 + gcc_assert(!args->is_empty());
113662 +#endif
113663 +
113664 + new_phi = overflow_create_phi_node(oldstmt, ssa_name_var);
113665 + result = gimple_phi_result(new_phi);
113666 + ssa_name_var = SSA_NAME_VAR(result);
113667 +
113668 +#if BUILDING_GCC_VERSION <= 4007
113669 + FOR_EACH_VEC_ELT(tree, *args, i, arg) {
113670 +#else
113671 + FOR_EACH_VEC_SAFE_ELT(args, i, arg) {
113672 +#endif
113673 + arg = create_new_phi_arg(ssa_name_var, arg, oldstmt, i);
113674 + add_phi_arg(new_phi, arg, gimple_phi_arg_edge(oldstmt, i), loc);
113675 + }
113676 +
113677 +#if BUILDING_GCC_VERSION <= 4007
113678 + VEC_free(tree, heap, *args);
113679 +#else
113680 + vec_free(args);
113681 +#endif
113682 + update_stmt(new_phi);
113683 + return result;
113684 +}
113685 +
113686 +static tree handle_phi(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree orig_result)
113687 +{
113688 + tree ssa_name_var = NULL_TREE;
113689 +#if BUILDING_GCC_VERSION <= 4007
113690 + VEC(tree, heap) *args = NULL;
113691 +#else
113692 + vec<tree, va_heap, vl_embed> *args = NULL;
113693 +#endif
113694 + gimple oldstmt = get_def_stmt(orig_result);
113695 + unsigned int i, len = gimple_phi_num_args(oldstmt);
113696 +
113697 + pointer_set_insert(visited, oldstmt);
113698 + for (i = 0; i < len; i++) {
113699 + tree arg, new_arg;
113700 +
113701 + arg = gimple_phi_arg_def(oldstmt, i);
113702 + new_arg = expand(visited, caller_node, arg);
113703 +
113704 + if (ssa_name_var == NULL_TREE && new_arg != NULL_TREE)
113705 + ssa_name_var = SSA_NAME_VAR(new_arg);
113706 +
113707 + if (is_gimple_constant(arg)) {
113708 + tree size_overflow_type = get_size_overflow_type(oldstmt, arg);
113709 +
113710 + new_arg = cast_a_tree(size_overflow_type, arg);
113711 + }
113712 +
113713 +#if BUILDING_GCC_VERSION <= 4007
113714 + VEC_safe_push(tree, heap, args, new_arg);
113715 +#else
113716 + vec_safe_push(args, new_arg);
113717 +#endif
113718 + }
113719 +
113720 +#if BUILDING_GCC_VERSION <= 4007
113721 + return create_new_phi_node(&args, ssa_name_var, oldstmt);
113722 +#else
113723 + return create_new_phi_node(args, ssa_name_var, oldstmt);
113724 +#endif
113725 +}
113726 +
113727 +static tree change_assign_rhs(gimple stmt, const_tree orig_rhs, tree new_rhs)
113728 +{
113729 + gimple assign;
113730 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
113731 + tree origtype = TREE_TYPE(orig_rhs);
113732 +
113733 + gcc_assert(is_gimple_assign(stmt));
113734 +
113735 + assign = build_cast_stmt(origtype, new_rhs, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
113736 + gimple_set_plf(assign, MY_STMT, true);
113737 + return gimple_assign_lhs(assign);
113738 +}
113739 +
113740 +static bool is_a_cast_and_const_overflow(const_tree no_const_rhs)
113741 +{
113742 + const_tree rhs1, lhs, rhs1_type, lhs_type;
113743 + enum machine_mode lhs_mode, rhs_mode;
113744 + gimple def_stmt = get_def_stmt(no_const_rhs);
113745 +
113746 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
113747 + return false;
113748 +
113749 + rhs1 = gimple_assign_rhs1(def_stmt);
113750 + lhs = gimple_assign_lhs(def_stmt);
113751 + rhs1_type = TREE_TYPE(rhs1);
113752 + lhs_type = TREE_TYPE(lhs);
113753 + rhs_mode = TYPE_MODE(rhs1_type);
113754 + lhs_mode = TYPE_MODE(lhs_type);
113755 + if (TYPE_UNSIGNED(lhs_type) == TYPE_UNSIGNED(rhs1_type) || lhs_mode != rhs_mode)
113756 + return false;
113757 +
113758 + return true;
113759 +}
113760 +
113761 +static tree create_cast_assign(struct pointer_set_t *visited, gimple stmt)
113762 +{
113763 + tree rhs1 = gimple_assign_rhs1(stmt);
113764 + tree lhs = gimple_assign_lhs(stmt);
113765 + const_tree rhs1_type = TREE_TYPE(rhs1);
113766 + const_tree lhs_type = TREE_TYPE(lhs);
113767 +
113768 + if (TYPE_UNSIGNED(rhs1_type) == TYPE_UNSIGNED(lhs_type))
113769 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113770 +
113771 + return create_assign(visited, stmt, rhs1, AFTER_STMT);
113772 +}
113773 +
113774 +static bool no_uses(tree node)
113775 +{
113776 + imm_use_iterator imm_iter;
113777 + use_operand_p use_p;
113778 +
113779 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
113780 + const_gimple use_stmt = USE_STMT(use_p);
113781 +
113782 + if (use_stmt == NULL)
113783 + return true;
113784 + if (is_gimple_debug(use_stmt))
113785 + continue;
113786 + return false;
113787 + }
113788 + return true;
113789 +}
113790 +
113791 +// 3.8.5 mm/page-writeback.c __ilog2_u64(): ret, uint + uintmax; uint -> int; int max
113792 +static bool is_const_plus_unsigned_signed_truncation(const_tree lhs)
113793 +{
113794 + tree rhs1, lhs_type, rhs_type, rhs2, not_const_rhs;
113795 + gimple def_stmt = get_def_stmt(lhs);
113796 +
113797 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
113798 + return false;
113799 +
113800 + rhs1 = gimple_assign_rhs1(def_stmt);
113801 + rhs_type = TREE_TYPE(rhs1);
113802 + lhs_type = TREE_TYPE(lhs);
113803 + if (TYPE_UNSIGNED(lhs_type) || !TYPE_UNSIGNED(rhs_type))
113804 + return false;
113805 + if (TYPE_MODE(lhs_type) != TYPE_MODE(rhs_type))
113806 + return false;
113807 +
113808 + def_stmt = get_def_stmt(rhs1);
113809 + if (!def_stmt || !is_gimple_assign(def_stmt) || gimple_num_ops(def_stmt) != 3)
113810 + return false;
113811 +
113812 + if (gimple_assign_rhs_code(def_stmt) != PLUS_EXPR)
113813 + return false;
113814 +
113815 + rhs1 = gimple_assign_rhs1(def_stmt);
113816 + rhs2 = gimple_assign_rhs2(def_stmt);
113817 + if (!is_gimple_constant(rhs1) && !is_gimple_constant(rhs2))
113818 + return false;
113819 +
113820 + if (is_gimple_constant(rhs2))
113821 + not_const_rhs = rhs1;
113822 + else
113823 + not_const_rhs = rhs2;
113824 +
113825 + return no_uses(not_const_rhs);
113826 +}
113827 +
113828 +static bool skip_lhs_cast_check(const_gimple stmt)
113829 +{
113830 + const_tree rhs = gimple_assign_rhs1(stmt);
113831 + const_gimple def_stmt = get_def_stmt(rhs);
113832 +
113833 + // 3.8.2 kernel/futex_compat.c compat_exit_robust_list(): get_user() 64 ulong -> int (compat_long_t), int max
113834 + if (gimple_code(def_stmt) == GIMPLE_ASM)
113835 + return true;
113836 +
113837 + if (is_const_plus_unsigned_signed_truncation(rhs))
113838 + return true;
113839 +
113840 + return false;
113841 +}
113842 +
113843 +static tree create_cast_overflow_check(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree new_rhs1, gimple stmt)
113844 +{
113845 + bool cast_lhs, cast_rhs;
113846 + tree lhs = gimple_assign_lhs(stmt);
113847 + tree rhs = gimple_assign_rhs1(stmt);
113848 + const_tree lhs_type = TREE_TYPE(lhs);
113849 + const_tree rhs_type = TREE_TYPE(rhs);
113850 + enum machine_mode lhs_mode = TYPE_MODE(lhs_type);
113851 + enum machine_mode rhs_mode = TYPE_MODE(rhs_type);
113852 + unsigned int lhs_size = GET_MODE_BITSIZE(lhs_mode);
113853 + unsigned int rhs_size = GET_MODE_BITSIZE(rhs_mode);
113854 +
113855 + static bool check_lhs[3][4] = {
113856 + // ss su us uu
113857 + { false, true, true, false }, // lhs > rhs
113858 + { false, false, false, false }, // lhs = rhs
113859 + { true, true, true, true }, // lhs < rhs
113860 + };
113861 +
113862 + static bool check_rhs[3][4] = {
113863 + // ss su us uu
113864 + { true, false, true, true }, // lhs > rhs
113865 + { true, false, true, true }, // lhs = rhs
113866 + { true, false, true, true }, // lhs < rhs
113867 + };
113868 +
113869 + // skip lhs check on signed SI -> HI cast or signed SI -> QI cast !!!!
113870 + if (rhs_mode == SImode && !TYPE_UNSIGNED(rhs_type) && (lhs_mode == HImode || lhs_mode == QImode))
113871 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113872 +
113873 + if (lhs_size > rhs_size) {
113874 + cast_lhs = check_lhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
113875 + cast_rhs = check_rhs[0][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
113876 + } else if (lhs_size == rhs_size) {
113877 + cast_lhs = check_lhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
113878 + cast_rhs = check_rhs[1][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
113879 + } else {
113880 + cast_lhs = check_lhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
113881 + cast_rhs = check_rhs[2][TYPE_UNSIGNED(rhs_type) + 2 * TYPE_UNSIGNED(lhs_type)];
113882 + }
113883 +
113884 + if (!cast_lhs && !cast_rhs)
113885 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
113886 +
113887 + if (cast_lhs && !skip_lhs_cast_check(stmt))
113888 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, lhs, BEFORE_STMT);
113889 +
113890 + if (cast_rhs)
113891 + check_size_overflow(caller_node, stmt, TREE_TYPE(new_rhs1), new_rhs1, rhs, BEFORE_STMT);
113892 +
113893 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
113894 +}
113895 +
113896 +static tree handle_unary_rhs(struct pointer_set_t *visited, struct cgraph_node *caller_node, gimple stmt)
113897 +{
113898 + tree rhs1, new_rhs1, lhs = gimple_assign_lhs(stmt);
113899 +
113900 + if (gimple_plf(stmt, MY_STMT))
113901 + return lhs;
113902 +
113903 + rhs1 = gimple_assign_rhs1(stmt);
113904 + if (TREE_CODE(TREE_TYPE(rhs1)) == POINTER_TYPE)
113905 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113906 +
113907 + new_rhs1 = expand(visited, caller_node, rhs1);
113908 +
113909 + if (new_rhs1 == NULL_TREE)
113910 + return create_cast_assign(visited, stmt);
113911 +
113912 + if (gimple_plf(stmt, NO_CAST_CHECK))
113913 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
113914 +
113915 + if (gimple_assign_rhs_code(stmt) == BIT_NOT_EXPR) {
113916 + tree size_overflow_type = get_size_overflow_type(stmt, rhs1);
113917 +
113918 + new_rhs1 = cast_to_new_size_overflow_type(stmt, new_rhs1, size_overflow_type, BEFORE_STMT);
113919 + check_size_overflow(caller_node, stmt, size_overflow_type, new_rhs1, rhs1, BEFORE_STMT);
113920 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113921 + }
113922 +
113923 + if (!gimple_assign_cast_p(stmt))
113924 + return dup_assign(visited, stmt, lhs, new_rhs1, NULL_TREE, NULL_TREE);
113925 +
113926 + return create_cast_overflow_check(visited, caller_node, new_rhs1, stmt);
113927 +}
113928 +
113929 +static tree handle_unary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, gimple stmt)
113930 +{
113931 + tree rhs1, lhs = gimple_assign_lhs(stmt);
113932 + gimple def_stmt = get_def_stmt(lhs);
113933 +
113934 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP);
113935 + rhs1 = gimple_assign_rhs1(def_stmt);
113936 +
113937 + if (is_gimple_constant(rhs1))
113938 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
113939 +
113940 + switch (TREE_CODE(rhs1)) {
113941 + case SSA_NAME:
113942 + return handle_unary_rhs(visited, caller_node, def_stmt);
113943 + case ARRAY_REF:
113944 + case BIT_FIELD_REF:
113945 + case ADDR_EXPR:
113946 + case COMPONENT_REF:
113947 + case INDIRECT_REF:
113948 +#if BUILDING_GCC_VERSION >= 4006
113949 + case MEM_REF:
113950 +#endif
113951 + case TARGET_MEM_REF:
113952 + case VIEW_CONVERT_EXPR:
113953 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
113954 + case PARM_DECL:
113955 + case VAR_DECL:
113956 + return create_assign(visited, stmt, lhs, AFTER_STMT);
113957 +
113958 + default:
113959 + debug_gimple_stmt(def_stmt);
113960 + debug_tree(rhs1);
113961 + gcc_unreachable();
113962 + }
113963 +}
113964 +
113965 +static void insert_cond(basic_block cond_bb, tree arg, enum tree_code cond_code, tree type_value)
113966 +{
113967 + gimple cond_stmt;
113968 + gimple_stmt_iterator gsi = gsi_last_bb(cond_bb);
113969 +
113970 + cond_stmt = gimple_build_cond(cond_code, arg, type_value, NULL_TREE, NULL_TREE);
113971 + gsi_insert_after(&gsi, cond_stmt, GSI_CONTINUE_LINKING);
113972 + update_stmt(cond_stmt);
113973 +}
113974 +
113975 +static tree create_string_param(tree string)
113976 +{
113977 + tree i_type, a_type;
113978 + const int length = TREE_STRING_LENGTH(string);
113979 +
113980 + gcc_assert(length > 0);
113981 +
113982 + i_type = build_index_type(build_int_cst(NULL_TREE, length - 1));
113983 + a_type = build_array_type(char_type_node, i_type);
113984 +
113985 + TREE_TYPE(string) = a_type;
113986 + TREE_CONSTANT(string) = 1;
113987 + TREE_READONLY(string) = 1;
113988 +
113989 + return build1(ADDR_EXPR, ptr_type_node, string);
113990 +}
113991 +
113992 +static void insert_cond_result(struct cgraph_node *caller_node, basic_block bb_true, const_gimple stmt, const_tree arg, bool min)
113993 +{
113994 + gimple func_stmt;
113995 + const_gimple def_stmt;
113996 + const_tree loc_line;
113997 + tree loc_file, ssa_name, current_func;
113998 + expanded_location xloc;
113999 + char *ssa_name_buf;
114000 + int len;
114001 + struct cgraph_edge *edge;
114002 + struct cgraph_node *callee_node;
114003 + int frequency;
114004 + gimple_stmt_iterator gsi = gsi_start_bb(bb_true);
114005 +
114006 + def_stmt = get_def_stmt(arg);
114007 + xloc = expand_location(gimple_location(def_stmt));
114008 +
114009 + if (!gimple_has_location(def_stmt)) {
114010 + xloc = expand_location(gimple_location(stmt));
114011 + if (!gimple_has_location(stmt))
114012 + xloc = expand_location(DECL_SOURCE_LOCATION(current_function_decl));
114013 + }
114014 +
114015 + loc_line = build_int_cstu(unsigned_type_node, xloc.line);
114016 +
114017 + loc_file = build_string(strlen(xloc.file) + 1, xloc.file);
114018 + loc_file = create_string_param(loc_file);
114019 +
114020 + current_func = build_string(DECL_NAME_LENGTH(current_function_decl) + 1, DECL_NAME_POINTER(current_function_decl));
114021 + current_func = create_string_param(current_func);
114022 +
114023 + gcc_assert(DECL_NAME(SSA_NAME_VAR(arg)) != NULL);
114024 + call_count++;
114025 + 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);
114026 + gcc_assert(len > 0);
114027 + ssa_name = build_string(len + 1, ssa_name_buf);
114028 + free(ssa_name_buf);
114029 + ssa_name = create_string_param(ssa_name);
114030 +
114031 + // void report_size_overflow(const char *file, unsigned int line, const char *func, const char *ssa_name)
114032 + func_stmt = gimple_build_call(report_size_overflow_decl, 4, loc_file, loc_line, current_func, ssa_name);
114033 + gsi_insert_after(&gsi, func_stmt, GSI_CONTINUE_LINKING);
114034 +
114035 + callee_node = cgraph_get_create_node(report_size_overflow_decl);
114036 + frequency = compute_call_stmt_bb_frequency(current_function_decl, bb_true);
114037 +
114038 + edge = cgraph_create_edge(caller_node, callee_node, func_stmt, bb_true->count, frequency, bb_true->loop_depth);
114039 + gcc_assert(edge != NULL);
114040 +}
114041 +
114042 +static void __unused print_the_code_insertions(const_gimple stmt)
114043 +{
114044 + location_t loc = gimple_location(stmt);
114045 +
114046 + inform(loc, "Integer size_overflow check applied here.");
114047 +}
114048 +
114049 +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)
114050 +{
114051 + basic_block cond_bb, join_bb, bb_true;
114052 + edge e;
114053 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
114054 +
114055 + cond_bb = gimple_bb(stmt);
114056 + if (before)
114057 + gsi_prev(&gsi);
114058 + if (gsi_end_p(gsi))
114059 + e = split_block_after_labels(cond_bb);
114060 + else
114061 + e = split_block(cond_bb, gsi_stmt(gsi));
114062 + cond_bb = e->src;
114063 + join_bb = e->dest;
114064 + e->flags = EDGE_FALSE_VALUE;
114065 + e->probability = REG_BR_PROB_BASE;
114066 +
114067 + bb_true = create_empty_bb(cond_bb);
114068 + make_edge(cond_bb, bb_true, EDGE_TRUE_VALUE);
114069 + make_edge(cond_bb, join_bb, EDGE_FALSE_VALUE);
114070 + make_edge(bb_true, join_bb, EDGE_FALLTHRU);
114071 +
114072 + gcc_assert(dom_info_available_p(CDI_DOMINATORS));
114073 + set_immediate_dominator(CDI_DOMINATORS, bb_true, cond_bb);
114074 + set_immediate_dominator(CDI_DOMINATORS, join_bb, cond_bb);
114075 +
114076 + if (current_loops != NULL) {
114077 + gcc_assert(cond_bb->loop_father == join_bb->loop_father);
114078 + add_bb_to_loop(bb_true, cond_bb->loop_father);
114079 + }
114080 +
114081 + insert_cond(cond_bb, arg, cond_code, type_value);
114082 + insert_cond_result(caller_node, bb_true, stmt, arg, min);
114083 +
114084 +// print_the_code_insertions(stmt);
114085 +}
114086 +
114087 +static void check_size_overflow(struct cgraph_node *caller_node, gimple stmt, tree size_overflow_type, tree cast_rhs, tree rhs, bool before)
114088 +{
114089 + const_tree rhs_type = TREE_TYPE(rhs);
114090 + tree cast_rhs_type, type_max_type, type_min_type, type_max, type_min;
114091 +
114092 + gcc_assert(rhs_type != NULL_TREE);
114093 + if (TREE_CODE(rhs_type) == POINTER_TYPE)
114094 + return;
114095 +
114096 + gcc_assert(TREE_CODE(rhs_type) == INTEGER_TYPE || TREE_CODE(rhs_type) == ENUMERAL_TYPE);
114097 +
114098 + if (is_const_plus_unsigned_signed_truncation(rhs))
114099 + return;
114100 +
114101 + type_max = cast_a_tree(size_overflow_type, TYPE_MAX_VALUE(rhs_type));
114102 + // typemax (-1) < typemin (0)
114103 + if (TREE_OVERFLOW(type_max))
114104 + return;
114105 +
114106 + type_min = cast_a_tree(size_overflow_type, TYPE_MIN_VALUE(rhs_type));
114107 +
114108 + cast_rhs_type = TREE_TYPE(cast_rhs);
114109 + type_max_type = TREE_TYPE(type_max);
114110 + gcc_assert(types_compatible_p(cast_rhs_type, type_max_type));
114111 +
114112 + insert_check_size_overflow(caller_node, stmt, GT_EXPR, cast_rhs, type_max, before, MAX_CHECK);
114113 +
114114 + // special case: get_size_overflow_type(), 32, u64->s
114115 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode) && TYPE_UNSIGNED(size_overflow_type) && !TYPE_UNSIGNED(rhs_type))
114116 + return;
114117 +
114118 + type_min_type = TREE_TYPE(type_min);
114119 + gcc_assert(types_compatible_p(type_max_type, type_min_type));
114120 + insert_check_size_overflow(caller_node, stmt, LT_EXPR, cast_rhs, type_min, before, MIN_CHECK);
114121 +}
114122 +
114123 +static bool is_a_constant_overflow(const_gimple stmt, const_tree rhs)
114124 +{
114125 + if (gimple_assign_rhs_code(stmt) == MIN_EXPR)
114126 + return false;
114127 + if (!is_gimple_constant(rhs))
114128 + return false;
114129 + return true;
114130 +}
114131 +
114132 +static tree get_def_stmt_rhs(const_tree var)
114133 +{
114134 + tree rhs1, def_stmt_rhs1;
114135 + gimple rhs1_def_stmt, def_stmt_rhs1_def_stmt, def_stmt;
114136 +
114137 + def_stmt = get_def_stmt(var);
114138 + if (!gimple_assign_cast_p(def_stmt))
114139 + return NULL_TREE;
114140 + gcc_assert(gimple_code(def_stmt) != GIMPLE_NOP && gimple_plf(def_stmt, MY_STMT) && gimple_assign_cast_p(def_stmt));
114141 +
114142 + rhs1 = gimple_assign_rhs1(def_stmt);
114143 + rhs1_def_stmt = get_def_stmt(rhs1);
114144 + if (!gimple_assign_cast_p(rhs1_def_stmt))
114145 + return rhs1;
114146 +
114147 + def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
114148 + def_stmt_rhs1_def_stmt = get_def_stmt(def_stmt_rhs1);
114149 +
114150 + switch (gimple_code(def_stmt_rhs1_def_stmt)) {
114151 + case GIMPLE_CALL:
114152 + case GIMPLE_NOP:
114153 + case GIMPLE_ASM:
114154 + case GIMPLE_PHI:
114155 + return def_stmt_rhs1;
114156 + case GIMPLE_ASSIGN:
114157 + return rhs1;
114158 + default:
114159 + debug_gimple_stmt(def_stmt_rhs1_def_stmt);
114160 + gcc_unreachable();
114161 + }
114162 +}
114163 +
114164 +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)
114165 +{
114166 + tree new_rhs, orig_rhs;
114167 + void (*gimple_assign_set_rhs)(gimple, tree);
114168 + tree rhs1 = gimple_assign_rhs1(stmt);
114169 + tree rhs2 = gimple_assign_rhs2(stmt);
114170 + tree lhs = gimple_assign_lhs(stmt);
114171 +
114172 + if (!check_overflow)
114173 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114174 +
114175 + if (change_rhs == NULL_TREE)
114176 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114177 +
114178 + if (new_rhs2 == NULL_TREE) {
114179 + orig_rhs = rhs1;
114180 + gimple_assign_set_rhs = &gimple_assign_set_rhs1;
114181 + } else {
114182 + orig_rhs = rhs2;
114183 + gimple_assign_set_rhs = &gimple_assign_set_rhs2;
114184 + }
114185 +
114186 + check_size_overflow(caller_node, stmt, TREE_TYPE(change_rhs), change_rhs, orig_rhs, BEFORE_STMT);
114187 +
114188 + new_rhs = change_assign_rhs(stmt, orig_rhs, change_rhs);
114189 + gimple_assign_set_rhs(stmt, new_rhs);
114190 + update_stmt(stmt);
114191 +
114192 + return create_assign(visited, stmt, lhs, AFTER_STMT);
114193 +}
114194 +
114195 +static bool is_subtraction_special(const_gimple stmt)
114196 +{
114197 + gimple rhs1_def_stmt, rhs2_def_stmt;
114198 + const_tree rhs1_def_stmt_rhs1, rhs2_def_stmt_rhs1, rhs1_def_stmt_lhs, rhs2_def_stmt_lhs;
114199 + enum machine_mode rhs1_def_stmt_rhs1_mode, rhs2_def_stmt_rhs1_mode, rhs1_def_stmt_lhs_mode, rhs2_def_stmt_lhs_mode;
114200 + const_tree rhs1 = gimple_assign_rhs1(stmt);
114201 + const_tree rhs2 = gimple_assign_rhs2(stmt);
114202 +
114203 + if (is_gimple_constant(rhs1) || is_gimple_constant(rhs2))
114204 + return false;
114205 +
114206 + gcc_assert(TREE_CODE(rhs1) == SSA_NAME && TREE_CODE(rhs2) == SSA_NAME);
114207 +
114208 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
114209 + return false;
114210 +
114211 + rhs1_def_stmt = get_def_stmt(rhs1);
114212 + rhs2_def_stmt = get_def_stmt(rhs2);
114213 + if (!gimple_assign_cast_p(rhs1_def_stmt) || !gimple_assign_cast_p(rhs2_def_stmt))
114214 + return false;
114215 +
114216 + rhs1_def_stmt_rhs1 = gimple_assign_rhs1(rhs1_def_stmt);
114217 + rhs2_def_stmt_rhs1 = gimple_assign_rhs1(rhs2_def_stmt);
114218 + rhs1_def_stmt_lhs = gimple_assign_lhs(rhs1_def_stmt);
114219 + rhs2_def_stmt_lhs = gimple_assign_lhs(rhs2_def_stmt);
114220 + rhs1_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_rhs1));
114221 + rhs2_def_stmt_rhs1_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_rhs1));
114222 + rhs1_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs1_def_stmt_lhs));
114223 + rhs2_def_stmt_lhs_mode = TYPE_MODE(TREE_TYPE(rhs2_def_stmt_lhs));
114224 + if (GET_MODE_BITSIZE(rhs1_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs1_def_stmt_lhs_mode))
114225 + return false;
114226 + if (GET_MODE_BITSIZE(rhs2_def_stmt_rhs1_mode) <= GET_MODE_BITSIZE(rhs2_def_stmt_lhs_mode))
114227 + return false;
114228 +
114229 + gimple_set_plf(rhs1_def_stmt, NO_CAST_CHECK, true);
114230 + gimple_set_plf(rhs2_def_stmt, NO_CAST_CHECK, true);
114231 + return true;
114232 +}
114233 +
114234 +static tree handle_integer_truncation(struct pointer_set_t *visited, struct cgraph_node *caller_node, const_tree lhs)
114235 +{
114236 + tree new_rhs1, new_rhs2;
114237 + tree new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1, new_lhs;
114238 + gimple assign, stmt = get_def_stmt(lhs);
114239 + tree rhs1 = gimple_assign_rhs1(stmt);
114240 + tree rhs2 = gimple_assign_rhs2(stmt);
114241 +
114242 + if (!is_subtraction_special(stmt))
114243 + return NULL_TREE;
114244 +
114245 + new_rhs1 = expand(visited, caller_node, rhs1);
114246 + new_rhs2 = expand(visited, caller_node, rhs2);
114247 +
114248 + new_rhs1_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs1);
114249 + new_rhs2_def_stmt_rhs1 = get_def_stmt_rhs(new_rhs2);
114250 +
114251 + if (new_rhs1_def_stmt_rhs1 == NULL_TREE || new_rhs2_def_stmt_rhs1 == NULL_TREE)
114252 + return NULL_TREE;
114253 +
114254 + if (!types_compatible_p(TREE_TYPE(new_rhs1_def_stmt_rhs1), TREE_TYPE(new_rhs2_def_stmt_rhs1))) {
114255 + new_rhs1_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs1_def_stmt_rhs1);
114256 + new_rhs2_def_stmt_rhs1 = cast_to_TI_type(stmt, new_rhs2_def_stmt_rhs1);
114257 + }
114258 +
114259 + assign = create_binary_assign(MINUS_EXPR, stmt, new_rhs1_def_stmt_rhs1, new_rhs2_def_stmt_rhs1);
114260 + new_lhs = gimple_assign_lhs(assign);
114261 + check_size_overflow(caller_node, assign, TREE_TYPE(new_lhs), new_lhs, rhs1, AFTER_STMT);
114262 +
114263 + return dup_assign(visited, stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
114264 +}
114265 +
114266 +static bool is_a_neg_overflow(const_gimple stmt, const_tree rhs)
114267 +{
114268 + const_gimple def_stmt;
114269 +
114270 + if (TREE_CODE(rhs) != SSA_NAME)
114271 + return false;
114272 +
114273 + if (gimple_assign_rhs_code(stmt) != PLUS_EXPR)
114274 + return false;
114275 +
114276 + def_stmt = get_def_stmt(rhs);
114277 + if (!is_gimple_assign(def_stmt) || gimple_assign_rhs_code(def_stmt) != BIT_NOT_EXPR)
114278 + return false;
114279 +
114280 + return true;
114281 +}
114282 +
114283 +static tree handle_binary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
114284 +{
114285 + tree rhs1, rhs2, new_lhs;
114286 + gimple def_stmt = get_def_stmt(lhs);
114287 + tree new_rhs1 = NULL_TREE;
114288 + tree new_rhs2 = NULL_TREE;
114289 +
114290 + rhs1 = gimple_assign_rhs1(def_stmt);
114291 + rhs2 = gimple_assign_rhs2(def_stmt);
114292 +
114293 + /* no DImode/TImode division in the 32/64 bit kernel */
114294 + switch (gimple_assign_rhs_code(def_stmt)) {
114295 + case RDIV_EXPR:
114296 + case TRUNC_DIV_EXPR:
114297 + case CEIL_DIV_EXPR:
114298 + case FLOOR_DIV_EXPR:
114299 + case ROUND_DIV_EXPR:
114300 + case TRUNC_MOD_EXPR:
114301 + case CEIL_MOD_EXPR:
114302 + case FLOOR_MOD_EXPR:
114303 + case ROUND_MOD_EXPR:
114304 + case EXACT_DIV_EXPR:
114305 + case POINTER_PLUS_EXPR:
114306 + case BIT_AND_EXPR:
114307 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
114308 + default:
114309 + break;
114310 + }
114311 +
114312 + new_lhs = handle_integer_truncation(visited, caller_node, lhs);
114313 + if (new_lhs != NULL_TREE)
114314 + return new_lhs;
114315 +
114316 + if (TREE_CODE(rhs1) == SSA_NAME)
114317 + new_rhs1 = expand(visited, caller_node, rhs1);
114318 + if (TREE_CODE(rhs2) == SSA_NAME)
114319 + new_rhs2 = expand(visited, caller_node, rhs2);
114320 +
114321 + if (is_a_neg_overflow(def_stmt, rhs2))
114322 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs1, NULL_TREE);
114323 + if (is_a_neg_overflow(def_stmt, rhs1))
114324 + return handle_intentional_overflow(visited, caller_node, true, def_stmt, new_rhs2, new_rhs2);
114325 +
114326 +
114327 + if (is_a_constant_overflow(def_stmt, rhs2))
114328 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs1), def_stmt, new_rhs1, NULL_TREE);
114329 + if (is_a_constant_overflow(def_stmt, rhs1))
114330 + return handle_intentional_overflow(visited, caller_node, !is_a_cast_and_const_overflow(rhs2), def_stmt, new_rhs2, new_rhs2);
114331 +
114332 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, NULL_TREE);
114333 +}
114334 +
114335 +#if BUILDING_GCC_VERSION >= 4006
114336 +static tree get_new_rhs(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree size_overflow_type, tree rhs)
114337 +{
114338 + if (is_gimple_constant(rhs))
114339 + return cast_a_tree(size_overflow_type, rhs);
114340 + if (TREE_CODE(rhs) != SSA_NAME)
114341 + return NULL_TREE;
114342 + return expand(visited, caller_node, rhs);
114343 +}
114344 +
114345 +static tree handle_ternary_ops(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
114346 +{
114347 + tree rhs1, rhs2, rhs3, new_rhs1, new_rhs2, new_rhs3, size_overflow_type;
114348 + gimple def_stmt = get_def_stmt(lhs);
114349 +
114350 + size_overflow_type = get_size_overflow_type(def_stmt, lhs);
114351 +
114352 + rhs1 = gimple_assign_rhs1(def_stmt);
114353 + rhs2 = gimple_assign_rhs2(def_stmt);
114354 + rhs3 = gimple_assign_rhs3(def_stmt);
114355 + new_rhs1 = get_new_rhs(visited, caller_node, size_overflow_type, rhs1);
114356 + new_rhs2 = get_new_rhs(visited, caller_node, size_overflow_type, rhs2);
114357 + new_rhs3 = get_new_rhs(visited, caller_node, size_overflow_type, rhs3);
114358 +
114359 + return dup_assign(visited, def_stmt, lhs, new_rhs1, new_rhs2, new_rhs3);
114360 +}
114361 +#endif
114362 +
114363 +static tree get_size_overflow_type(gimple stmt, const_tree node)
114364 +{
114365 + const_tree type;
114366 + tree new_type;
114367 +
114368 + gcc_assert(node != NULL_TREE);
114369 +
114370 + type = TREE_TYPE(node);
114371 +
114372 + if (gimple_plf(stmt, MY_STMT))
114373 + return TREE_TYPE(node);
114374 +
114375 + switch (TYPE_MODE(type)) {
114376 + case QImode:
114377 + new_type = intHI_type_node;
114378 + break;
114379 + case HImode:
114380 + new_type = intSI_type_node;
114381 + break;
114382 + case SImode:
114383 + new_type = intDI_type_node;
114384 + break;
114385 + case DImode:
114386 + if (LONG_TYPE_SIZE == GET_MODE_BITSIZE(SImode))
114387 + new_type = TYPE_UNSIGNED(type) ? unsigned_intDI_type_node : intDI_type_node;
114388 + else
114389 + new_type = intTI_type_node;
114390 + break;
114391 + case TImode:
114392 + gcc_assert(!TYPE_UNSIGNED(type));
114393 + new_type = intTI_type_node;
114394 + break;
114395 + default:
114396 + debug_tree((tree)node);
114397 + error("%s: unsupported gcc configuration (%qE).", __func__, current_function_decl);
114398 + gcc_unreachable();
114399 + }
114400 +
114401 + if (TYPE_QUALS(type) != 0)
114402 + return build_qualified_type(new_type, TYPE_QUALS(type));
114403 + return new_type;
114404 +}
114405 +
114406 +static tree expand_visited(gimple def_stmt)
114407 +{
114408 + const_gimple next_stmt;
114409 + gimple_stmt_iterator gsi;
114410 + enum gimple_code code = gimple_code(def_stmt);
114411 +
114412 + if (code == GIMPLE_ASM)
114413 + return NULL_TREE;
114414 +
114415 + gsi = gsi_for_stmt(def_stmt);
114416 + gsi_next(&gsi);
114417 +
114418 + if (gimple_code(def_stmt) == GIMPLE_PHI && gsi_end_p(gsi))
114419 + return NULL_TREE;
114420 + gcc_assert(!gsi_end_p(gsi));
114421 + next_stmt = gsi_stmt(gsi);
114422 +
114423 + if (gimple_code(def_stmt) == GIMPLE_PHI && !gimple_plf((gimple)next_stmt, MY_STMT))
114424 + return NULL_TREE;
114425 + gcc_assert(gimple_plf((gimple)next_stmt, MY_STMT));
114426 +
114427 + return get_lhs(next_stmt);
114428 +}
114429 +
114430 +static tree expand(struct pointer_set_t *visited, struct cgraph_node *caller_node, tree lhs)
114431 +{
114432 + gimple def_stmt;
114433 +
114434 + def_stmt = get_def_stmt(lhs);
114435 +
114436 + if (!def_stmt || gimple_code(def_stmt) == GIMPLE_NOP)
114437 + return NULL_TREE;
114438 +
114439 + if (gimple_plf(def_stmt, MY_STMT))
114440 + return lhs;
114441 +
114442 + if (pointer_set_contains(visited, def_stmt))
114443 + return expand_visited(def_stmt);
114444 +
114445 + switch (gimple_code(def_stmt)) {
114446 + case GIMPLE_PHI:
114447 + return handle_phi(visited, caller_node, lhs);
114448 + case GIMPLE_CALL:
114449 + case GIMPLE_ASM:
114450 + return create_assign(visited, def_stmt, lhs, AFTER_STMT);
114451 + case GIMPLE_ASSIGN:
114452 + switch (gimple_num_ops(def_stmt)) {
114453 + case 2:
114454 + return handle_unary_ops(visited, caller_node, def_stmt);
114455 + case 3:
114456 + return handle_binary_ops(visited, caller_node, lhs);
114457 +#if BUILDING_GCC_VERSION >= 4006
114458 + case 4:
114459 + return handle_ternary_ops(visited, caller_node, lhs);
114460 +#endif
114461 + }
114462 + default:
114463 + debug_gimple_stmt(def_stmt);
114464 + error("%s: unknown gimple code", __func__);
114465 + gcc_unreachable();
114466 + }
114467 +}
114468 +
114469 +static tree cast_to_orig_type(gimple stmt, const_tree orig_node, tree new_node)
114470 +{
114471 + const_gimple assign;
114472 + tree orig_type = TREE_TYPE(orig_node);
114473 + gimple_stmt_iterator gsi = gsi_for_stmt(stmt);
114474 +
114475 + assign = build_cast_stmt(orig_type, new_node, CREATE_NEW_VAR, &gsi, BEFORE_STMT, false);
114476 + return gimple_assign_lhs(assign);
114477 +}
114478 +
114479 +static void change_orig_node(struct interesting_node *cur_node, tree new_node)
114480 +{
114481 + void (*set_rhs)(gimple, tree);
114482 + gimple stmt = cur_node->first_stmt;
114483 + const_tree orig_node = cur_node->node;
114484 +
114485 + switch (gimple_code(stmt)) {
114486 + case GIMPLE_RETURN:
114487 + gimple_return_set_retval(stmt, cast_to_orig_type(stmt, orig_node, new_node));
114488 + break;
114489 + case GIMPLE_CALL:
114490 + gimple_call_set_arg(stmt, cur_node->num - 1, cast_to_orig_type(stmt, orig_node, new_node));
114491 + break;
114492 + case GIMPLE_ASSIGN:
114493 + switch (cur_node->num) {
114494 + case 1:
114495 + set_rhs = &gimple_assign_set_rhs1;
114496 + break;
114497 + case 2:
114498 + set_rhs = &gimple_assign_set_rhs2;
114499 + break;
114500 +#if BUILDING_GCC_VERSION >= 4006
114501 + case 3:
114502 + set_rhs = &gimple_assign_set_rhs3;
114503 + break;
114504 +#endif
114505 + default:
114506 + gcc_unreachable();
114507 + }
114508 +
114509 + set_rhs(stmt, cast_to_orig_type(stmt, orig_node, new_node));
114510 + break;
114511 + default:
114512 + debug_gimple_stmt(stmt);
114513 + gcc_unreachable();
114514 + }
114515 +
114516 + update_stmt(stmt);
114517 +}
114518 +
114519 +static unsigned int get_correct_arg_count(unsigned int argnum, const_tree fndecl)
114520 +{
114521 + const struct size_overflow_hash *hash;
114522 + unsigned int new_argnum;
114523 + tree arg;
114524 + const_tree origarg;
114525 +
114526 + if (argnum == 0)
114527 + return argnum;
114528 +
114529 + hash = get_function_hash(fndecl);
114530 + if (hash && hash->param & (1U << argnum))
114531 + return argnum;
114532 +
114533 + if (DECL_EXTERNAL(fndecl))
114534 + return argnum;
114535 +
114536 + origarg = DECL_ARGUMENTS(DECL_ORIGIN(fndecl));
114537 + argnum--;
114538 + while (origarg && argnum) {
114539 + origarg = TREE_CHAIN(origarg);
114540 + argnum--;
114541 + }
114542 + gcc_assert(argnum == 0);
114543 + gcc_assert(origarg != NULL_TREE);
114544 +
114545 + for (arg = DECL_ARGUMENTS(fndecl), new_argnum = 1; arg; arg = TREE_CHAIN(arg), new_argnum++)
114546 + if (operand_equal_p(origarg, arg, 0) || !strcmp(DECL_NAME_POINTER(origarg), DECL_NAME_POINTER(arg)))
114547 + return new_argnum;
114548 +
114549 + return CANNOT_FIND_ARG;
114550 +}
114551 +
114552 +// Don't want to duplicate entries in next_cgraph_node
114553 +static bool is_in_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, const_tree fndecl, unsigned int num)
114554 +{
114555 + const_tree new_callee_fndecl;
114556 + struct next_cgraph_node *cur_node;
114557 +
114558 + if (fndecl == RET_CHECK)
114559 + new_callee_fndecl = NODE_DECL(node);
114560 + else
114561 + new_callee_fndecl = fndecl;
114562 +
114563 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
114564 + if (!operand_equal_p(NODE_DECL(cur_node->current_function), NODE_DECL(node), 0))
114565 + continue;
114566 + if (!operand_equal_p(cur_node->callee_fndecl, new_callee_fndecl, 0))
114567 + continue;
114568 + if (num == cur_node->num)
114569 + return true;
114570 + }
114571 + return false;
114572 +}
114573 +
114574 +/* Add a next_cgraph_node into the list for handle_function().
114575 + * handle_function() iterates over all the next cgraph nodes and
114576 + * starts the overflow check insertion process.
114577 + */
114578 +static struct next_cgraph_node *create_new_next_cgraph_node(struct next_cgraph_node *head, struct cgraph_node *node, tree fndecl, unsigned int num)
114579 +{
114580 + struct next_cgraph_node *new_node;
114581 +
114582 + if (is_in_next_cgraph_node(head, node, fndecl, num))
114583 + return head;
114584 +
114585 + new_node = (struct next_cgraph_node *)xmalloc(sizeof(*new_node));
114586 + new_node->current_function = node;
114587 + new_node->next = NULL;
114588 + new_node->num = num;
114589 + if (fndecl == RET_CHECK)
114590 + new_node->callee_fndecl = NODE_DECL(node);
114591 + else
114592 + new_node->callee_fndecl = fndecl;
114593 +
114594 + if (!head)
114595 + return new_node;
114596 +
114597 + new_node->next = head;
114598 + return new_node;
114599 +}
114600 +
114601 +static struct next_cgraph_node *create_new_next_cgraph_nodes(struct next_cgraph_node *head, struct cgraph_node *node, unsigned int num)
114602 +{
114603 + struct cgraph_edge *e;
114604 +
114605 + if (num == 0)
114606 + return create_new_next_cgraph_node(head, node, RET_CHECK, num);
114607 +
114608 + for (e = node->callers; e; e = e->next_caller) {
114609 + tree fndecl = gimple_call_fndecl(e->call_stmt);
114610 +
114611 + gcc_assert(fndecl != NULL_TREE);
114612 + head = create_new_next_cgraph_node(head, e->caller, fndecl, num);
114613 + }
114614 +
114615 + return head;
114616 +}
114617 +
114618 +static bool is_a_return_check(const_tree node)
114619 +{
114620 + if (TREE_CODE(node) == FUNCTION_DECL)
114621 + return true;
114622 +
114623 + gcc_assert(TREE_CODE(node) == PARM_DECL);
114624 + return false;
114625 +}
114626 +
114627 +static bool is_in_hash_table(const_tree fndecl, unsigned int num)
114628 +{
114629 + const struct size_overflow_hash *hash;
114630 +
114631 + hash = get_function_hash(fndecl);
114632 + if (hash && (hash->param & (1U << num)))
114633 + return true;
114634 + return false;
114635 +}
114636 +
114637 +struct missing_functions {
114638 + struct missing_functions *next;
114639 + const_tree node;
114640 + tree fndecl;
114641 +};
114642 +
114643 +static struct missing_functions *create_new_missing_function(struct missing_functions *missing_fn_head, tree node)
114644 +{
114645 + struct missing_functions *new_function;
114646 +
114647 + new_function = (struct missing_functions *)xmalloc(sizeof(*new_function));
114648 + new_function->node = node;
114649 + new_function->next = NULL;
114650 +
114651 + if (TREE_CODE(node) == FUNCTION_DECL)
114652 + new_function->fndecl = node;
114653 + else
114654 + new_function->fndecl = current_function_decl;
114655 + gcc_assert(new_function->fndecl);
114656 +
114657 + if (!missing_fn_head)
114658 + return new_function;
114659 +
114660 + new_function->next = missing_fn_head;
114661 + return new_function;
114662 +}
114663 +
114664 +/* Check if the function has a size_overflow attribute or it is in the size_overflow hash table.
114665 + * If the function is missing everywhere then print the missing message into stderr.
114666 + */
114667 +static bool is_missing_function(const_tree orig_fndecl, unsigned int num)
114668 +{
114669 + switch (DECL_FUNCTION_CODE(orig_fndecl)) {
114670 +#if BUILDING_GCC_VERSION >= 4008
114671 + case BUILT_IN_BSWAP16:
114672 +#endif
114673 + case BUILT_IN_BSWAP32:
114674 + case BUILT_IN_BSWAP64:
114675 + case BUILT_IN_EXPECT:
114676 + case BUILT_IN_MEMCMP:
114677 + return false;
114678 + default:
114679 + break;
114680 + }
114681 +
114682 + // skip test.c
114683 + if (strcmp(DECL_NAME_POINTER(current_function_decl), "coolmalloc")) {
114684 + if (lookup_attribute("size_overflow", DECL_ATTRIBUTES(orig_fndecl)))
114685 + warning(0, "unnecessary size_overflow attribute on: %s\n", DECL_NAME_POINTER(orig_fndecl));
114686 + }
114687 +
114688 + if (is_in_hash_table(orig_fndecl, num))
114689 + return false;
114690 +
114691 + print_missing_msg(orig_fndecl, num);
114692 + return true;
114693 +}
114694 +
114695 +// Get the argnum of a function decl, if node is a return then the argnum is 0
114696 +static unsigned int get_function_num(const_tree node, const_tree orig_fndecl)
114697 +{
114698 + if (is_a_return_check(node))
114699 + return 0;
114700 + else
114701 + return find_arg_number_tree(node, orig_fndecl);
114702 +}
114703 +
114704 +/* If the function is missing from the hash table and it is a static function
114705 + * then create a next_cgraph_node from it for handle_function()
114706 + */
114707 +static struct next_cgraph_node *check_missing_overflow_attribute_and_create_next_node(struct next_cgraph_node *cnodes, struct missing_functions *missing_fn_head)
114708 +{
114709 + unsigned int num;
114710 + const_tree orig_fndecl;
114711 + struct cgraph_node *next_node = NULL;
114712 +
114713 + orig_fndecl = DECL_ORIGIN(missing_fn_head->fndecl);
114714 +
114715 + num = get_function_num(missing_fn_head->node, orig_fndecl);
114716 + if (num == CANNOT_FIND_ARG)
114717 + return cnodes;
114718 +
114719 + if (!is_missing_function(orig_fndecl, num))
114720 + return cnodes;
114721 +
114722 + next_node = cgraph_get_node(missing_fn_head->fndecl);
114723 + if (next_node && next_node->local.local)
114724 + cnodes = create_new_next_cgraph_nodes(cnodes, next_node, num);
114725 + return cnodes;
114726 +}
114727 +
114728 +/* Search for missing size_overflow attributes on the last nodes in ipa and collect them
114729 + * into the next_cgraph_node list. They will be the next interesting returns or callees.
114730 + */
114731 +static struct next_cgraph_node *search_overflow_attribute(struct next_cgraph_node *cnodes, struct interesting_node *cur_node)
114732 +{
114733 + unsigned int i;
114734 + tree node;
114735 + struct missing_functions *cur, *missing_fn_head = NULL;
114736 +
114737 +#if BUILDING_GCC_VERSION <= 4007
114738 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, node) {
114739 +#else
114740 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, node) {
114741 +#endif
114742 + switch (TREE_CODE(node)) {
114743 + case PARM_DECL:
114744 + if (TREE_CODE(TREE_TYPE(node)) != INTEGER_TYPE)
114745 + break;
114746 + case FUNCTION_DECL:
114747 + missing_fn_head = create_new_missing_function(missing_fn_head, node);
114748 + break;
114749 + default:
114750 + break;
114751 + }
114752 + }
114753 +
114754 + while (missing_fn_head) {
114755 + cnodes = check_missing_overflow_attribute_and_create_next_node(cnodes, missing_fn_head);
114756 +
114757 + cur = missing_fn_head->next;
114758 + free(missing_fn_head);
114759 + missing_fn_head = cur;
114760 + }
114761 +
114762 + return cnodes;
114763 +}
114764 +
114765 +static void walk_phi_set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree result)
114766 +{
114767 + gimple phi = get_def_stmt(result);
114768 + unsigned int i, n = gimple_phi_num_args(phi);
114769 +
114770 + pointer_set_insert(visited, phi);
114771 + for (i = 0; i < n; i++) {
114772 + const_tree arg = gimple_phi_arg_def(phi, i);
114773 +
114774 + set_conditions(visited, interesting_conditions, arg);
114775 + }
114776 +}
114777 +
114778 +enum conditions {
114779 + FROM_CONST, NOT_UNARY, CAST
114780 +};
114781 +
114782 +// Search for constants, cast assignments and binary/ternary assignments
114783 +static void set_conditions(struct pointer_set_t *visited, bool *interesting_conditions, const_tree lhs)
114784 +{
114785 + gimple def_stmt = get_def_stmt(lhs);
114786 +
114787 + if (is_gimple_constant(lhs)) {
114788 + interesting_conditions[FROM_CONST] = true;
114789 + return;
114790 + }
114791 +
114792 + if (!def_stmt)
114793 + return;
114794 +
114795 + if (pointer_set_contains(visited, def_stmt))
114796 + return;
114797 +
114798 + switch (gimple_code(def_stmt)) {
114799 + case GIMPLE_NOP:
114800 + case GIMPLE_CALL:
114801 + case GIMPLE_ASM:
114802 + return;
114803 + case GIMPLE_PHI:
114804 + return walk_phi_set_conditions(visited, interesting_conditions, lhs);
114805 + case GIMPLE_ASSIGN:
114806 + if (gimple_num_ops(def_stmt) == 2) {
114807 + const_tree rhs = gimple_assign_rhs1(def_stmt);
114808 +
114809 + if (gimple_assign_cast_p(def_stmt))
114810 + interesting_conditions[CAST] = true;
114811 +
114812 + return set_conditions(visited, interesting_conditions, rhs);
114813 + } else {
114814 + interesting_conditions[NOT_UNARY] = true;
114815 + return;
114816 + }
114817 + default:
114818 + debug_gimple_stmt(def_stmt);
114819 + gcc_unreachable();
114820 + }
114821 +}
114822 +
114823 +// determine whether duplication will be necessary or not.
114824 +static void search_interesting_conditions(struct interesting_node *cur_node, bool *interesting_conditions)
114825 +{
114826 + struct pointer_set_t *visited;
114827 +
114828 + if (gimple_assign_cast_p(cur_node->first_stmt))
114829 + interesting_conditions[CAST] = true;
114830 + else if (is_gimple_assign(cur_node->first_stmt) && gimple_num_ops(cur_node->first_stmt) > 2)
114831 + interesting_conditions[NOT_UNARY] = true;
114832 +
114833 + visited = pointer_set_create();
114834 + set_conditions(visited, interesting_conditions, cur_node->node);
114835 + pointer_set_destroy(visited);
114836 +}
114837 +
114838 +// Remove the size_overflow asm stmt and create an assignment from the input and output of the asm
114839 +static void replace_size_overflow_asm_with_assign(gimple asm_stmt, tree lhs, tree rhs)
114840 +{
114841 + gimple assign;
114842 + gimple_stmt_iterator gsi;
114843 +
114844 + // already removed
114845 + if (gimple_bb(asm_stmt) == NULL)
114846 + return;
114847 + gsi = gsi_for_stmt(asm_stmt);
114848 +
114849 + assign = gimple_build_assign(lhs, rhs);
114850 + gsi_insert_before(&gsi, assign, GSI_SAME_STMT);
114851 + SSA_NAME_DEF_STMT(lhs) = assign;
114852 +
114853 + gsi_remove(&gsi, true);
114854 +}
114855 +
114856 +// Get the field decl of a component ref for intentional_overflow checking
114857 +static const_tree search_field_decl(const_tree comp_ref)
114858 +{
114859 + const_tree field = NULL_TREE;
114860 + unsigned int i, len = TREE_OPERAND_LENGTH(comp_ref);
114861 +
114862 + for (i = 0; i < len; i++) {
114863 + field = TREE_OPERAND(comp_ref, i);
114864 + if (TREE_CODE(field) == FIELD_DECL)
114865 + break;
114866 + }
114867 + gcc_assert(TREE_CODE(field) == FIELD_DECL);
114868 + return field;
114869 +}
114870 +
114871 +/* Get the fndecl of an interesting stmt, the fndecl is the caller function if the interesting
114872 + * stmt is a return otherwise it is the callee function.
114873 + */
114874 +static const_tree get_interesting_orig_fndecl(const_gimple stmt, unsigned int argnum)
114875 +{
114876 + const_tree fndecl;
114877 +
114878 + if (argnum == 0)
114879 + fndecl = current_function_decl;
114880 + else
114881 + fndecl = gimple_call_fndecl(stmt);
114882 +
114883 + if (fndecl == NULL_TREE)
114884 + return NULL_TREE;
114885 +
114886 + return DECL_ORIGIN(fndecl);
114887 +}
114888 +
114889 +/* Get the param of the intentional_overflow attribute.
114890 + * * 0: MARK_NOT_INTENTIONAL
114891 + * * 1..MAX_PARAM: MARK_YES
114892 + * * -1: MARK_TURN_OFF
114893 + */
114894 +static tree get_attribute_param(const_tree decl)
114895 +{
114896 + const_tree attr;
114897 +
114898 + if (decl == NULL_TREE)
114899 + return NULL_TREE;
114900 +
114901 + attr = lookup_attribute("intentional_overflow", DECL_ATTRIBUTES(decl));
114902 + if (!attr || !TREE_VALUE(attr))
114903 + return NULL_TREE;
114904 +
114905 + return TREE_VALUE(attr);
114906 +}
114907 +
114908 +// MARK_TURN_OFF
114909 +static bool is_turn_off_intentional_attr(const_tree decl)
114910 +{
114911 + const_tree param_head;
114912 +
114913 + param_head = get_attribute_param(decl);
114914 + if (param_head == NULL_TREE)
114915 + return false;
114916 +
114917 + if (TREE_INT_CST_HIGH(TREE_VALUE(param_head)) == -1)
114918 + return true;
114919 + return false;
114920 +}
114921 +
114922 +// MARK_NOT_INTENTIONAL
114923 +static bool is_end_intentional_intentional_attr(const_tree decl, unsigned int argnum)
114924 +{
114925 + const_tree param_head;
114926 +
114927 + if (argnum == 0)
114928 + return false;
114929 +
114930 + param_head = get_attribute_param(decl);
114931 + if (param_head == NULL_TREE)
114932 + return false;
114933 +
114934 + if (!TREE_INT_CST_LOW(TREE_VALUE(param_head)))
114935 + return true;
114936 + return false;
114937 +}
114938 +
114939 +// MARK_YES
114940 +static bool is_yes_intentional_attr(const_tree decl, unsigned int argnum)
114941 +{
114942 + tree param, param_head;
114943 +
114944 + if (argnum == 0)
114945 + return false;
114946 +
114947 + param_head = get_attribute_param(decl);
114948 + for (param = param_head; param; param = TREE_CHAIN(param))
114949 + if (argnum == TREE_INT_CST_LOW(TREE_VALUE(param)))
114950 + return true;
114951 + return false;
114952 +}
114953 +
114954 +static const char *get_asm_string(const_gimple stmt)
114955 +{
114956 + if (!stmt)
114957 + return NULL;
114958 + if (gimple_code(stmt) != GIMPLE_ASM)
114959 + return NULL;
114960 +
114961 + return gimple_asm_string(stmt);
114962 +}
114963 +
114964 +static bool is_size_overflow_intentional_asm_turn_off(const_gimple stmt)
114965 +{
114966 + const char *str;
114967 +
114968 + str = get_asm_string(stmt);
114969 + if (!str)
114970 + return false;
114971 + return !strncmp(str, TURN_OFF_ASM_STR, sizeof(TURN_OFF_ASM_STR) - 1);
114972 +}
114973 +
114974 +static bool is_size_overflow_intentional_asm_yes(const_gimple stmt)
114975 +{
114976 + const char *str;
114977 +
114978 + str = get_asm_string(stmt);
114979 + if (!str)
114980 + return false;
114981 + return !strncmp(str, YES_ASM_STR, sizeof(YES_ASM_STR) - 1);
114982 +}
114983 +
114984 +static bool is_size_overflow_asm(const_gimple stmt)
114985 +{
114986 + const char *str;
114987 +
114988 + str = get_asm_string(stmt);
114989 + if (!str)
114990 + return false;
114991 + return !strncmp(str, OK_ASM_STR, sizeof(OK_ASM_STR) - 1);
114992 +}
114993 +
114994 +static void print_missing_intentional(enum mark callee_attr, enum mark caller_attr, const_tree decl, unsigned int argnum)
114995 +{
114996 + location_t loc;
114997 +
114998 + if (caller_attr == MARK_NO || caller_attr == MARK_NOT_INTENTIONAL || caller_attr == MARK_TURN_OFF)
114999 + return;
115000 +
115001 + if (callee_attr == MARK_NOT_INTENTIONAL || callee_attr == MARK_YES)
115002 + return;
115003 +
115004 + loc = DECL_SOURCE_LOCATION(decl);
115005 + inform(loc, "The intentional_overflow attribute is missing from +%s+%u+", DECL_NAME_POINTER(decl), argnum);
115006 +}
115007 +
115008 +/* Get the type of the intentional_overflow attribute of a node
115009 + * * MARK_TURN_OFF
115010 + * * MARK_YES
115011 + * * MARK_NO
115012 + * * MARK_NOT_INTENTIONAL
115013 + */
115014 +static enum mark get_intentional_attr_type(const_tree node)
115015 +{
115016 + const_tree cur_decl;
115017 +
115018 + if (node == NULL_TREE)
115019 + return MARK_NO;
115020 +
115021 + switch (TREE_CODE(node)) {
115022 + case COMPONENT_REF:
115023 + cur_decl = search_field_decl(node);
115024 + if (is_turn_off_intentional_attr(cur_decl))
115025 + return MARK_TURN_OFF;
115026 + if (is_end_intentional_intentional_attr(cur_decl, 1))
115027 + return MARK_YES;
115028 + break;
115029 + case PARM_DECL: {
115030 + unsigned int argnum;
115031 +
115032 + cur_decl = DECL_ORIGIN(current_function_decl);
115033 + argnum = find_arg_number_tree(node, cur_decl);
115034 + if (argnum == CANNOT_FIND_ARG)
115035 + return MARK_NO;
115036 + if (is_yes_intentional_attr(cur_decl, argnum))
115037 + return MARK_YES;
115038 + if (is_end_intentional_intentional_attr(cur_decl, argnum))
115039 + return MARK_NOT_INTENTIONAL;
115040 + break;
115041 + }
115042 + case FUNCTION_DECL:
115043 + if (is_turn_off_intentional_attr(DECL_ORIGIN(node)))
115044 + return MARK_TURN_OFF;
115045 + break;
115046 + default:
115047 + break;
115048 + }
115049 + return MARK_NO;
115050 +}
115051 +
115052 +// Search for the intentional_overflow attribute on the last nodes
115053 +static enum mark search_last_nodes_intentional(struct interesting_node *cur_node)
115054 +{
115055 + unsigned int i;
115056 + tree last_node;
115057 + enum mark mark = MARK_NO;
115058 +
115059 +#if BUILDING_GCC_VERSION <= 4007
115060 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, last_node) {
115061 +#else
115062 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, last_node) {
115063 +#endif
115064 + mark = get_intentional_attr_type(last_node);
115065 + if (mark != MARK_NO)
115066 + break;
115067 + }
115068 + return mark;
115069 +}
115070 +
115071 +/* Check the intentional kind of size_overflow asm stmt (created by the gimple pass) and
115072 + * set the appropriate intentional_overflow type. Delete the asm stmt in the end.
115073 + */
115074 +static bool is_intentional_attribute_from_gimple(struct interesting_node *cur_node)
115075 +{
115076 + if (!cur_node->intentional_mark_from_gimple)
115077 + return false;
115078 +
115079 + if (is_size_overflow_intentional_asm_yes(cur_node->intentional_mark_from_gimple))
115080 + cur_node->intentional_attr_cur_fndecl = MARK_YES;
115081 + else
115082 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
115083 +
115084 + // skip param decls
115085 + if (gimple_asm_noutputs(cur_node->intentional_mark_from_gimple) == 0)
115086 + return true;
115087 + return true;
115088 +}
115089 +
115090 +/* Search intentional_overflow attribute on caller and on callee too.
115091 + * 0</MARK_YES: no dup, search size_overflow and intentional_overflow attributes
115092 + * 0/MARK_NOT_INTENTIONAL: no dup, search size_overflow attribute (int)
115093 + * -1/MARK_TURN_OFF: no dup, no search, current_function_decl -> no dup
115094 +*/
115095 +static void check_intentional_attribute_ipa(struct interesting_node *cur_node)
115096 +{
115097 + const_tree fndecl;
115098 +
115099 + if (is_intentional_attribute_from_gimple(cur_node))
115100 + return;
115101 +
115102 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
115103 + cur_node->intentional_attr_cur_fndecl = MARK_TURN_OFF;
115104 + return;
115105 + }
115106 +
115107 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASM) {
115108 + cur_node->intentional_attr_cur_fndecl = MARK_NOT_INTENTIONAL;
115109 + return;
115110 + }
115111 +
115112 + if (gimple_code(cur_node->first_stmt) == GIMPLE_ASSIGN)
115113 + return;
115114 +
115115 + fndecl = get_interesting_orig_fndecl(cur_node->first_stmt, cur_node->num);
115116 + if (is_turn_off_intentional_attr(fndecl)) {
115117 + cur_node->intentional_attr_decl = MARK_TURN_OFF;
115118 + return;
115119 + }
115120 +
115121 + if (is_end_intentional_intentional_attr(fndecl, cur_node->num))
115122 + cur_node->intentional_attr_decl = MARK_NOT_INTENTIONAL;
115123 + else if (is_yes_intentional_attr(fndecl, cur_node->num))
115124 + cur_node->intentional_attr_decl = MARK_YES;
115125 +
115126 + cur_node->intentional_attr_cur_fndecl = search_last_nodes_intentional(cur_node);
115127 + print_missing_intentional(cur_node->intentional_attr_decl, cur_node->intentional_attr_cur_fndecl, cur_node->fndecl, cur_node->num);
115128 +}
115129 +
115130 +// e.g., 3.8.2, 64, arch/x86/ia32/ia32_signal.c copy_siginfo_from_user32(): compat_ptr() u32 max
115131 +static bool skip_asm(const_tree arg)
115132 +{
115133 + gimple def_stmt = get_def_stmt(arg);
115134 +
115135 + if (!def_stmt || !gimple_assign_cast_p(def_stmt))
115136 + return false;
115137 +
115138 + def_stmt = get_def_stmt(gimple_assign_rhs1(def_stmt));
115139 + return def_stmt && gimple_code(def_stmt) == GIMPLE_ASM;
115140 +}
115141 +
115142 +static void walk_use_def_phi(struct pointer_set_t *visited, struct interesting_node *cur_node, tree result)
115143 +{
115144 + gimple phi = get_def_stmt(result);
115145 + unsigned int i, n = gimple_phi_num_args(phi);
115146 +
115147 + pointer_set_insert(visited, phi);
115148 + for (i = 0; i < n; i++) {
115149 + tree arg = gimple_phi_arg_def(phi, i);
115150 +
115151 + walk_use_def(visited, cur_node, arg);
115152 + }
115153 +}
115154 +
115155 +static void walk_use_def_binary(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
115156 +{
115157 + gimple def_stmt = get_def_stmt(lhs);
115158 + tree rhs1, rhs2;
115159 +
115160 + rhs1 = gimple_assign_rhs1(def_stmt);
115161 + rhs2 = gimple_assign_rhs2(def_stmt);
115162 +
115163 + walk_use_def(visited, cur_node, rhs1);
115164 + walk_use_def(visited, cur_node, rhs2);
115165 +}
115166 +
115167 +static void insert_last_node(struct interesting_node *cur_node, tree node)
115168 +{
115169 + unsigned int i;
115170 + tree element;
115171 + enum tree_code code;
115172 +
115173 + gcc_assert(node != NULL_TREE);
115174 +
115175 + if (is_gimple_constant(node))
115176 + return;
115177 +
115178 + code = TREE_CODE(node);
115179 + if (code == VAR_DECL) {
115180 + node = DECL_ORIGIN(node);
115181 + code = TREE_CODE(node);
115182 + }
115183 +
115184 + if (code != PARM_DECL && code != FUNCTION_DECL && code != COMPONENT_REF)
115185 + return;
115186 +
115187 +#if BUILDING_GCC_VERSION <= 4007
115188 + FOR_EACH_VEC_ELT(tree, cur_node->last_nodes, i, element) {
115189 +#else
115190 + FOR_EACH_VEC_ELT(*cur_node->last_nodes, i, element) {
115191 +#endif
115192 + if (operand_equal_p(node, element, 0))
115193 + return;
115194 + }
115195 +
115196 +#if BUILDING_GCC_VERSION <= 4007
115197 + gcc_assert(VEC_length(tree, cur_node->last_nodes) < VEC_LEN);
115198 + VEC_safe_push(tree, gc, cur_node->last_nodes, node);
115199 +#else
115200 + gcc_assert(cur_node->last_nodes->length() < VEC_LEN);
115201 + vec_safe_push(cur_node->last_nodes, node);
115202 +#endif
115203 +}
115204 +
115205 +// a size_overflow asm stmt in the control flow doesn't stop the recursion
115206 +static void handle_asm_stmt(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs, const_gimple stmt)
115207 +{
115208 + if (!is_size_overflow_asm(stmt))
115209 + walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
115210 +}
115211 +
115212 +/* collect the parm_decls and fndecls (for checking a missing size_overflow attribute (ret or arg) or intentional_overflow)
115213 + * and component refs (for checking the intentional_overflow attribute).
115214 + */
115215 +static void walk_use_def(struct pointer_set_t *visited, struct interesting_node *cur_node, tree lhs)
115216 +{
115217 + const_gimple def_stmt;
115218 +
115219 + if (TREE_CODE(lhs) != SSA_NAME) {
115220 + insert_last_node(cur_node, lhs);
115221 + return;
115222 + }
115223 +
115224 + def_stmt = get_def_stmt(lhs);
115225 + if (!def_stmt)
115226 + return;
115227 +
115228 + if (pointer_set_insert(visited, def_stmt))
115229 + return;
115230 +
115231 + switch (gimple_code(def_stmt)) {
115232 + case GIMPLE_NOP:
115233 + return walk_use_def(visited, cur_node, SSA_NAME_VAR(lhs));
115234 + case GIMPLE_ASM:
115235 + return handle_asm_stmt(visited, cur_node, lhs, def_stmt);
115236 + case GIMPLE_CALL: {
115237 + tree fndecl = gimple_call_fndecl(def_stmt);
115238 +
115239 + if (fndecl == NULL_TREE)
115240 + return;
115241 + insert_last_node(cur_node, fndecl);
115242 + return;
115243 + }
115244 + case GIMPLE_PHI:
115245 + return walk_use_def_phi(visited, cur_node, lhs);
115246 + case GIMPLE_ASSIGN:
115247 + switch (gimple_num_ops(def_stmt)) {
115248 + case 2:
115249 + return walk_use_def(visited, cur_node, gimple_assign_rhs1(def_stmt));
115250 + case 3:
115251 + return walk_use_def_binary(visited, cur_node, lhs);
115252 + }
115253 + default:
115254 + debug_gimple_stmt((gimple)def_stmt);
115255 + error("%s: unknown gimple code", __func__);
115256 + gcc_unreachable();
115257 + }
115258 +}
115259 +
115260 +// Collect all the last nodes for checking the intentional_overflow and size_overflow attributes
115261 +static void set_last_nodes(struct interesting_node *cur_node)
115262 +{
115263 + struct pointer_set_t *visited;
115264 +
115265 + visited = pointer_set_create();
115266 + walk_use_def(visited, cur_node, cur_node->node);
115267 + pointer_set_destroy(visited);
115268 +}
115269 +
115270 +enum precond {
115271 + NO_ATTRIBUTE_SEARCH, NO_CHECK_INSERT, NONE
115272 +};
115273 +
115274 +/* 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.
115275 + * There is only missing size_overflow attribute checking if the intentional_overflow attribute is the mark_no type.
115276 + * Stmt duplication is unnecessary if there are no binary/ternary assignements or if the unary assignment isn't a cast.
115277 + * 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.
115278 + */
115279 +static enum precond check_preconditions(struct interesting_node *cur_node)
115280 +{
115281 + bool interesting_conditions[3] = {false, false, false};
115282 +
115283 + set_last_nodes(cur_node);
115284 +
115285 + check_intentional_attribute_ipa(cur_node);
115286 + if (cur_node->intentional_attr_decl == MARK_TURN_OFF || cur_node->intentional_attr_cur_fndecl == MARK_TURN_OFF)
115287 + return NO_ATTRIBUTE_SEARCH;
115288 +
115289 + search_interesting_conditions(cur_node, interesting_conditions);
115290 +
115291 + // error code
115292 + if (interesting_conditions[CAST] && interesting_conditions[FROM_CONST] && !interesting_conditions[NOT_UNARY])
115293 + return NO_ATTRIBUTE_SEARCH;
115294 +
115295 + // unnecessary overflow check
115296 + if (!interesting_conditions[CAST] && !interesting_conditions[NOT_UNARY])
115297 + return NO_CHECK_INSERT;
115298 +
115299 + if (cur_node->intentional_attr_cur_fndecl != MARK_NO)
115300 + return NO_CHECK_INSERT;
115301 +
115302 + return NONE;
115303 +}
115304 +
115305 +/* This function calls the main recursion function (expand) that duplicates the stmts. Before that it checks the intentional_overflow attribute and asm stmts,
115306 + * 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
115307 + * in the original stmt (first stmt) and it inserts the overflow check for the arg of the callee or for the return value.
115308 + */
115309 +static struct next_cgraph_node *handle_interesting_stmt(struct next_cgraph_node *cnodes, struct interesting_node *cur_node, struct cgraph_node *caller_node)
115310 +{
115311 + enum precond ret;
115312 + struct pointer_set_t *visited;
115313 + tree new_node, orig_node = cur_node->node;
115314 +
115315 + ret = check_preconditions(cur_node);
115316 + if (ret == NO_ATTRIBUTE_SEARCH)
115317 + return cnodes;
115318 +
115319 + cnodes = search_overflow_attribute(cnodes, cur_node);
115320 +
115321 + if (ret == NO_CHECK_INSERT)
115322 + return cnodes;
115323 +
115324 + visited = pointer_set_create();
115325 + new_node = expand(visited, caller_node, orig_node);
115326 + pointer_set_destroy(visited);
115327 +
115328 + if (new_node == NULL_TREE)
115329 + return cnodes;
115330 +
115331 + change_orig_node(cur_node, new_node);
115332 + check_size_overflow(caller_node, cur_node->first_stmt, TREE_TYPE(new_node), new_node, orig_node, BEFORE_STMT);
115333 +
115334 + return cnodes;
115335 +}
115336 +
115337 +// Check visited interesting nodes.
115338 +static bool is_in_interesting_node(struct interesting_node *head, const_gimple first_stmt, const_tree node, unsigned int num)
115339 +{
115340 + struct interesting_node *cur;
115341 +
115342 + for (cur = head; cur; cur = cur->next) {
115343 + if (!operand_equal_p(node, cur->node, 0))
115344 + continue;
115345 + if (num != cur->num)
115346 + continue;
115347 + if (first_stmt == cur->first_stmt)
115348 + return true;
115349 + }
115350 + return false;
115351 +}
115352 +
115353 +/* Create an interesting node. The ipa pass starts to duplicate from these stmts.
115354 + 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
115355 + 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
115356 + the intentional_overflow attribute check. They are collected by set_last_nodes().
115357 + num: arg count of a call stmt or 0 when it is a ret
115358 + node: the recursion starts from here, it is a call arg or a return value
115359 + 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.
115360 + intentional_attr_decl: intentional_overflow attribute of the callee function
115361 + intentional_attr_cur_fndecl: intentional_overflow attribute of the caller function
115362 + intentional_mark_from_gimple: the intentional overflow type of size_overflow asm stmt from gimple if it exists
115363 + */
115364 +static struct interesting_node *create_new_interesting_node(struct interesting_node *head, gimple first_stmt, tree node, unsigned int num, gimple asm_stmt)
115365 +{
115366 + struct interesting_node *new_node;
115367 + tree fndecl;
115368 + enum gimple_code code;
115369 +
115370 + gcc_assert(node != NULL_TREE);
115371 + code = gimple_code(first_stmt);
115372 + gcc_assert(code == GIMPLE_CALL || code == GIMPLE_ASM || code == GIMPLE_ASSIGN || code == GIMPLE_RETURN);
115373 +
115374 + if (num == CANNOT_FIND_ARG)
115375 + return head;
115376 +
115377 + if (skip_types(node))
115378 + return head;
115379 +
115380 + if (skip_asm(node))
115381 + return head;
115382 +
115383 + if (is_gimple_call(first_stmt))
115384 + fndecl = gimple_call_fndecl(first_stmt);
115385 + else
115386 + fndecl = current_function_decl;
115387 +
115388 + if (fndecl == NULL_TREE)
115389 + return head;
115390 +
115391 + if (is_in_interesting_node(head, first_stmt, node, num))
115392 + return head;
115393 +
115394 + new_node = (struct interesting_node *)xmalloc(sizeof(*new_node));
115395 +
115396 + new_node->next = NULL;
115397 + new_node->first_stmt = first_stmt;
115398 +#if BUILDING_GCC_VERSION <= 4007
115399 + new_node->last_nodes = VEC_alloc(tree, gc, VEC_LEN);
115400 +#else
115401 + vec_alloc(new_node->last_nodes, VEC_LEN);
115402 +#endif
115403 + new_node->num = num;
115404 + new_node->node = node;
115405 + new_node->fndecl = fndecl;
115406 + new_node->intentional_attr_decl = MARK_NO;
115407 + new_node->intentional_attr_cur_fndecl = MARK_NO;
115408 + new_node->intentional_mark_from_gimple = asm_stmt;
115409 +
115410 + if (!head)
115411 + return new_node;
115412 +
115413 + new_node->next = head;
115414 + return new_node;
115415 +}
115416 +
115417 +/* 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).
115418 + * If the ret stmt is in the next cgraph node list then it's an interesting ret.
115419 + */
115420 +static struct interesting_node *handle_stmt_by_cgraph_nodes_ret(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
115421 +{
115422 + struct next_cgraph_node *cur_node;
115423 + tree ret = gimple_return_retval(stmt);
115424 +
115425 + if (ret == NULL_TREE)
115426 + return head;
115427 +
115428 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
115429 + if (!operand_equal_p(cur_node->callee_fndecl, DECL_ORIGIN(current_function_decl), 0))
115430 + continue;
115431 + if (cur_node->num == 0)
115432 + head = create_new_interesting_node(head, stmt, ret, 0, NOT_INTENTIONAL_ASM);
115433 + }
115434 +
115435 + return head;
115436 +}
115437 +
115438 +/* 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).
115439 + * If the call stmt is in the next cgraph node list then it's an interesting call.
115440 + */
115441 +static struct interesting_node *handle_stmt_by_cgraph_nodes_call(struct interesting_node *head, gimple stmt, struct next_cgraph_node *next_node)
115442 +{
115443 + unsigned int argnum;
115444 + tree arg;
115445 + const_tree fndecl;
115446 + struct next_cgraph_node *cur_node;
115447 +
115448 + fndecl = gimple_call_fndecl(stmt);
115449 + if (fndecl == NULL_TREE)
115450 + return head;
115451 +
115452 + for (cur_node = next_node; cur_node; cur_node = cur_node->next) {
115453 + if (!operand_equal_p(cur_node->callee_fndecl, fndecl, 0))
115454 + continue;
115455 + argnum = get_correct_arg_count(cur_node->num, fndecl);
115456 + gcc_assert(argnum != CANNOT_FIND_ARG);
115457 + if (argnum == 0)
115458 + continue;
115459 +
115460 + arg = gimple_call_arg(stmt, argnum - 1);
115461 + head = create_new_interesting_node(head, stmt, arg, argnum, NOT_INTENTIONAL_ASM);
115462 + }
115463 +
115464 + return head;
115465 +}
115466 +
115467 +static unsigned int check_ops(const_tree orig_node, const_tree node, unsigned int ret_count)
115468 +{
115469 + if (!operand_equal_p(orig_node, node, 0))
115470 + return WRONG_NODE;
115471 + if (skip_types(node))
115472 + return WRONG_NODE;
115473 + return ret_count;
115474 +}
115475 +
115476 +// Get the index of the rhs node in an assignment
115477 +static unsigned int get_assign_ops_count(const_gimple stmt, tree node)
115478 +{
115479 + const_tree rhs1, rhs2;
115480 + unsigned int ret;
115481 +
115482 + gcc_assert(stmt);
115483 + gcc_assert(is_gimple_assign(stmt));
115484 +
115485 + rhs1 = gimple_assign_rhs1(stmt);
115486 + gcc_assert(rhs1 != NULL_TREE);
115487 +
115488 + switch (gimple_num_ops(stmt)) {
115489 + case 2:
115490 + return check_ops(node, rhs1, 1);
115491 + case 3:
115492 + ret = check_ops(node, rhs1, 1);
115493 + if (ret != WRONG_NODE)
115494 + return ret;
115495 +
115496 + rhs2 = gimple_assign_rhs2(stmt);
115497 + gcc_assert(rhs2 != NULL_TREE);
115498 + return check_ops(node, rhs2, 2);
115499 + default:
115500 + gcc_unreachable();
115501 + }
115502 +}
115503 +
115504 +// Find the correct arg number of a call stmt. It is needed when the interesting function is a cloned function.
115505 +static unsigned int find_arg_number_gimple(const_tree arg, const_gimple stmt)
115506 +{
115507 + unsigned int i;
115508 +
115509 + if (gimple_call_fndecl(stmt) == NULL_TREE)
115510 + return CANNOT_FIND_ARG;
115511 +
115512 + for (i = 0; i < gimple_call_num_args(stmt); i++) {
115513 + tree node;
115514 +
115515 + node = gimple_call_arg(stmt, i);
115516 + if (!operand_equal_p(arg, node, 0))
115517 + continue;
115518 + if (!skip_types(node))
115519 + return i + 1;
115520 + }
115521 +
115522 + return CANNOT_FIND_ARG;
115523 +}
115524 +
115525 +/* starting from the size_overflow asm stmt collect interesting stmts. They can be
115526 + * any of return, call or assignment stmts (because of inlining).
115527 + */
115528 +static struct interesting_node *get_interesting_ret_or_call(struct pointer_set_t *visited, struct interesting_node *head, tree node, gimple intentional_asm)
115529 +{
115530 + use_operand_p use_p;
115531 + imm_use_iterator imm_iter;
115532 + unsigned int argnum;
115533 +
115534 + gcc_assert(TREE_CODE(node) == SSA_NAME);
115535 +
115536 + if (pointer_set_insert(visited, node))
115537 + return head;
115538 +
115539 + FOR_EACH_IMM_USE_FAST(use_p, imm_iter, node) {
115540 + gimple stmt = USE_STMT(use_p);
115541 +
115542 + if (stmt == NULL)
115543 + return head;
115544 + if (is_gimple_debug(stmt))
115545 + continue;
115546 +
115547 + switch (gimple_code(stmt)) {
115548 + case GIMPLE_CALL:
115549 + argnum = find_arg_number_gimple(node, stmt);
115550 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
115551 + break;
115552 + case GIMPLE_RETURN:
115553 + head = create_new_interesting_node(head, stmt, node, 0, intentional_asm);
115554 + break;
115555 + case GIMPLE_ASSIGN:
115556 + argnum = get_assign_ops_count(stmt, node);
115557 + head = create_new_interesting_node(head, stmt, node, argnum, intentional_asm);
115558 + break;
115559 + case GIMPLE_PHI: {
115560 + tree result = gimple_phi_result(stmt);
115561 + head = get_interesting_ret_or_call(visited, head, result, intentional_asm);
115562 + break;
115563 + }
115564 + case GIMPLE_ASM:
115565 + if (gimple_asm_noutputs(stmt) != 0)
115566 + break;
115567 + if (!is_size_overflow_asm(stmt))
115568 + break;
115569 + head = create_new_interesting_node(head, stmt, node, 1, intentional_asm);
115570 + break;
115571 + case GIMPLE_COND:
115572 + case GIMPLE_SWITCH:
115573 + break;
115574 + default:
115575 + debug_gimple_stmt(stmt);
115576 + gcc_unreachable();
115577 + break;
115578 + }
115579 + }
115580 + return head;
115581 +}
115582 +
115583 +static void remove_size_overflow_asm(gimple stmt)
115584 +{
115585 + gimple_stmt_iterator gsi;
115586 + tree input, output;
115587 +
115588 + if (!is_size_overflow_asm(stmt))
115589 + return;
115590 +
115591 + if (gimple_asm_noutputs(stmt) == 0) {
115592 + gsi = gsi_for_stmt(stmt);
115593 + ipa_remove_stmt_references(cgraph_get_create_node(current_function_decl), stmt);
115594 + gsi_remove(&gsi, true);
115595 + return;
115596 + }
115597 +
115598 + input = gimple_asm_input_op(stmt, 0);
115599 + output = gimple_asm_output_op(stmt, 0);
115600 + replace_size_overflow_asm_with_assign(stmt, TREE_VALUE(output), TREE_VALUE(input));
115601 +}
115602 +
115603 +/* handle the size_overflow asm stmts from the gimple pass and collect the interesting stmts.
115604 + * If the asm stmt is a parm_decl kind (noutputs == 0) then remove it.
115605 + * If it is a simple asm stmt then replace it with an assignment from the asm input to the asm output.
115606 + */
115607 +static struct interesting_node *handle_stmt_by_size_overflow_asm(gimple stmt, struct interesting_node *head)
115608 +{
115609 + const_tree output;
115610 + struct pointer_set_t *visited;
115611 + gimple intentional_asm = NOT_INTENTIONAL_ASM;
115612 +
115613 + if (!is_size_overflow_asm(stmt))
115614 + return head;
115615 +
115616 + if (is_size_overflow_intentional_asm_yes(stmt) || is_size_overflow_intentional_asm_turn_off(stmt))
115617 + intentional_asm = stmt;
115618 +
115619 + gcc_assert(gimple_asm_ninputs(stmt) == 1);
115620 +
115621 + if (gimple_asm_noutputs(stmt) == 0 && is_size_overflow_intentional_asm_turn_off(stmt))
115622 + return head;
115623 +
115624 + if (gimple_asm_noutputs(stmt) == 0) {
115625 + const_tree input;
115626 +
115627 + if (!is_size_overflow_intentional_asm_turn_off(stmt))
115628 + return head;
115629 +
115630 + input = gimple_asm_input_op(stmt, 0);
115631 + remove_size_overflow_asm(stmt);
115632 + if (is_gimple_constant(TREE_VALUE(input)))
115633 + return head;
115634 + visited = pointer_set_create();
115635 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(input), intentional_asm);
115636 + pointer_set_destroy(visited);
115637 + return head;
115638 + }
115639 +
115640 + if (!is_size_overflow_intentional_asm_yes(stmt) && !is_size_overflow_intentional_asm_turn_off(stmt))
115641 + remove_size_overflow_asm(stmt);
115642 +
115643 + visited = pointer_set_create();
115644 + output = gimple_asm_output_op(stmt, 0);
115645 + head = get_interesting_ret_or_call(visited, head, TREE_VALUE(output), intentional_asm);
115646 + pointer_set_destroy(visited);
115647 + return head;
115648 +}
115649 +
115650 +/* Iterate over all the stmts of a function and look for the size_overflow asm stmts (they were created in the gimple pass)
115651 + * or a call stmt or a return stmt and store them in the interesting_node list
115652 + */
115653 +static struct interesting_node *collect_interesting_stmts(struct next_cgraph_node *next_node)
115654 +{
115655 + basic_block bb;
115656 + struct interesting_node *head = NULL;
115657 +
115658 + FOR_ALL_BB_FN(bb, cfun) {
115659 + gimple_stmt_iterator gsi;
115660 +
115661 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
115662 + enum gimple_code code;
115663 + gimple stmt = gsi_stmt(gsi);
115664 +
115665 + code = gimple_code(stmt);
115666 +
115667 + if (code == GIMPLE_ASM)
115668 + head = handle_stmt_by_size_overflow_asm(stmt, head);
115669 +
115670 + if (!next_node)
115671 + continue;
115672 + if (code == GIMPLE_CALL)
115673 + head = handle_stmt_by_cgraph_nodes_call(head, stmt, next_node);
115674 + if (code == GIMPLE_RETURN)
115675 + head = handle_stmt_by_cgraph_nodes_ret(head, stmt, next_node);
115676 + }
115677 + }
115678 + return head;
115679 +}
115680 +
115681 +static void set_current_function_decl(tree fndecl)
115682 +{
115683 + gcc_assert(fndecl != NULL_TREE);
115684 +
115685 + push_cfun(DECL_STRUCT_FUNCTION(fndecl));
115686 + calculate_dominance_info(CDI_DOMINATORS);
115687 + current_function_decl = fndecl;
115688 +}
115689 +
115690 +static void unset_current_function_decl(void)
115691 +{
115692 + free_dominance_info(CDI_DOMINATORS);
115693 + pop_cfun();
115694 + current_function_decl = NULL_TREE;
115695 +}
115696 +
115697 +static void free_interesting_node(struct interesting_node *head)
115698 +{
115699 + struct interesting_node *cur;
115700 +
115701 + while (head) {
115702 + cur = head->next;
115703 +#if BUILDING_GCC_VERSION <= 4007
115704 + VEC_free(tree, gc, head->last_nodes);
115705 +#else
115706 + vec_free(head->last_nodes);
115707 +#endif
115708 + free(head);
115709 + head = cur;
115710 + }
115711 +}
115712 +
115713 +static struct visited *insert_visited_function(struct visited *head, struct interesting_node *cur_node)
115714 +{
115715 + struct visited *new_visited;
115716 +
115717 + new_visited = (struct visited *)xmalloc(sizeof(*new_visited));
115718 + new_visited->fndecl = cur_node->fndecl;
115719 + new_visited->num = cur_node->num;
115720 + new_visited->rhs = cur_node->node;
115721 + new_visited->next = NULL;
115722 +
115723 + if (!head)
115724 + return new_visited;
115725 +
115726 + new_visited->next = head;
115727 + return new_visited;
115728 +}
115729 +
115730 +/* 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
115731 + * it is a visited function.
115732 + */
115733 +static bool is_visited_function(struct visited *head, struct interesting_node *cur_node)
115734 +{
115735 + struct visited *cur;
115736 +
115737 + if (!head)
115738 + return false;
115739 +
115740 + for (cur = head; cur; cur = cur->next) {
115741 + if (!operand_equal_p(cur_node->fndecl, cur->fndecl, 0))
115742 + continue;
115743 + if (cur_node->num != cur->num)
115744 + continue;
115745 + if (cur_node->node == cur->rhs)
115746 + return true;
115747 + }
115748 + return false;
115749 +}
115750 +
115751 +static void free_next_cgraph_node(struct next_cgraph_node *head)
115752 +{
115753 + struct next_cgraph_node *cur;
115754 +
115755 + while (head) {
115756 + cur = head->next;
115757 + free(head);
115758 + head = cur;
115759 + }
115760 +}
115761 +
115762 +static void remove_all_size_overflow_asm(void)
115763 +{
115764 + basic_block bb;
115765 +
115766 + FOR_ALL_BB_FN(bb, cfun) {
115767 + gimple_stmt_iterator si;
115768 +
115769 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
115770 + remove_size_overflow_asm(gsi_stmt(si));
115771 + }
115772 +}
115773 +
115774 +/* Main recursive walk of the ipa pass: iterate over the collected interesting stmts in a function
115775 + * (they are interesting if they have an associated size_overflow asm stmt) and recursively walk
115776 + * the newly collected interesting functions (they are interesting if there is control flow between
115777 + * the interesting stmts and them).
115778 + */
115779 +static struct visited *handle_function(struct cgraph_node *node, struct next_cgraph_node *next_node, struct visited *visited)
115780 +{
115781 + struct interesting_node *head, *cur_node;
115782 + struct next_cgraph_node *cur_cnodes, *cnodes_head = NULL;
115783 +
115784 + set_current_function_decl(NODE_DECL(node));
115785 + call_count = 0;
115786 +
115787 + head = collect_interesting_stmts(next_node);
115788 + for (cur_node = head; cur_node; cur_node = cur_node->next) {
115789 + if (is_visited_function(visited, cur_node))
115790 + continue;
115791 + cnodes_head = handle_interesting_stmt(cnodes_head, cur_node, node);
115792 + visited = insert_visited_function(visited, cur_node);
115793 + }
115794 +
115795 + free_interesting_node(head);
115796 + remove_all_size_overflow_asm();
115797 + unset_current_function_decl();
115798 +
115799 + for (cur_cnodes = cnodes_head; cur_cnodes; cur_cnodes = cur_cnodes->next)
115800 + visited = handle_function(cur_cnodes->current_function, cur_cnodes, visited);
115801 +
115802 + free_next_cgraph_node(cnodes_head);
115803 + return visited;
115804 +}
115805 +
115806 +static void free_visited(struct visited *head)
115807 +{
115808 + struct visited *cur;
115809 +
115810 + while (head) {
115811 + cur = head->next;
115812 + free(head);
115813 + head = cur;
115814 + }
115815 +}
115816 +
115817 +// erase the local flag
115818 +static void set_plf_false(void)
115819 +{
115820 + basic_block bb;
115821 +
115822 + FOR_ALL_BB_FN(bb, cfun) {
115823 + gimple_stmt_iterator si;
115824 +
115825 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
115826 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
115827 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
115828 + gimple_set_plf(gsi_stmt(si), MY_STMT, false);
115829 + }
115830 +}
115831 +
115832 +// Main entry point of the ipa pass: erases the plf flag of all stmts and iterates over all the functions
115833 +static unsigned int search_function(void)
115834 +{
115835 + struct cgraph_node *node;
115836 + struct visited *visited = NULL;
115837 +
115838 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
115839 + set_current_function_decl(NODE_DECL(node));
115840 + set_plf_false();
115841 + unset_current_function_decl();
115842 + }
115843 +
115844 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
115845 + gcc_assert(cgraph_function_flags_ready);
115846 +#if BUILDING_GCC_VERSION <= 4007
115847 + gcc_assert(node->reachable);
115848 +#endif
115849 +
115850 + visited = handle_function(node, NULL, visited);
115851 + }
115852 +
115853 + free_visited(visited);
115854 + return 0;
115855 +}
115856 +
115857 +#if BUILDING_GCC_VERSION >= 4009
115858 +static const struct pass_data ipa_pass_data = {
115859 +#else
115860 +static struct ipa_opt_pass_d ipa_pass = {
115861 + .pass = {
115862 +#endif
115863 + .type = SIMPLE_IPA_PASS,
115864 + .name = "size_overflow",
115865 +#if BUILDING_GCC_VERSION >= 4008
115866 + .optinfo_flags = OPTGROUP_NONE,
115867 +#endif
115868 +#if BUILDING_GCC_VERSION >= 4009
115869 + .has_gate = false,
115870 + .has_execute = true,
115871 +#else
115872 + .gate = NULL,
115873 + .execute = search_function,
115874 + .sub = NULL,
115875 + .next = NULL,
115876 + .static_pass_number = 0,
115877 +#endif
115878 + .tv_id = TV_NONE,
115879 + .properties_required = 0,
115880 + .properties_provided = 0,
115881 + .properties_destroyed = 0,
115882 + .todo_flags_start = 0,
115883 + .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,
115884 +#if BUILDING_GCC_VERSION < 4009
115885 + },
115886 + .generate_summary = NULL,
115887 + .write_summary = NULL,
115888 + .read_summary = NULL,
115889 +#if BUILDING_GCC_VERSION >= 4006
115890 + .write_optimization_summary = NULL,
115891 + .read_optimization_summary = NULL,
115892 +#endif
115893 + .stmt_fixup = NULL,
115894 + .function_transform_todo_flags_start = 0,
115895 + .function_transform = NULL,
115896 + .variable_transform = NULL,
115897 +#endif
115898 +};
115899 +
115900 +#if BUILDING_GCC_VERSION >= 4009
115901 +namespace {
115902 +class ipa_pass : public ipa_opt_pass_d {
115903 +public:
115904 + ipa_pass() : ipa_opt_pass_d(ipa_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
115905 + unsigned int execute() { return search_function(); }
115906 +};
115907 +}
115908 +#endif
115909 +
115910 +static struct opt_pass *make_ipa_pass(void)
115911 +{
115912 +#if BUILDING_GCC_VERSION >= 4009
115913 + return new ipa_pass();
115914 +#else
115915 + return &ipa_pass.pass;
115916 +#endif
115917 +}
115918 +
115919 +// data for the size_overflow asm stmt
115920 +struct asm_data {
115921 + gimple def_stmt;
115922 + tree input;
115923 + tree output;
115924 +};
115925 +
115926 +#if BUILDING_GCC_VERSION <= 4007
115927 +static VEC(tree, gc) *create_asm_io_list(tree string, tree io)
115928 +#else
115929 +static vec<tree, va_gc> *create_asm_io_list(tree string, tree io)
115930 +#endif
115931 +{
115932 + tree list;
115933 +#if BUILDING_GCC_VERSION <= 4007
115934 + VEC(tree, gc) *vec_list = NULL;
115935 +#else
115936 + vec<tree, va_gc> *vec_list = NULL;
115937 +#endif
115938 +
115939 + list = build_tree_list(NULL_TREE, string);
115940 + list = chainon(NULL_TREE, build_tree_list(list, io));
115941 +#if BUILDING_GCC_VERSION <= 4007
115942 + VEC_safe_push(tree, gc, vec_list, list);
115943 +#else
115944 + vec_safe_push(vec_list, list);
115945 +#endif
115946 + return vec_list;
115947 +}
115948 +
115949 +static void create_asm_stmt(const char *str, tree str_input, tree str_output, struct asm_data *asm_data)
115950 +{
115951 + gimple asm_stmt;
115952 + gimple_stmt_iterator gsi;
115953 +#if BUILDING_GCC_VERSION <= 4007
115954 + VEC(tree, gc) *input, *output = NULL;
115955 +#else
115956 + vec<tree, va_gc> *input, *output = NULL;
115957 +#endif
115958 +
115959 + input = create_asm_io_list(str_input, asm_data->input);
115960 +
115961 + if (asm_data->output)
115962 + output = create_asm_io_list(str_output, asm_data->output);
115963 +
115964 + asm_stmt = gimple_build_asm_vec(str, input, output, NULL, NULL);
115965 + gsi = gsi_for_stmt(asm_data->def_stmt);
115966 + gsi_insert_after(&gsi, asm_stmt, GSI_NEW_STMT);
115967 +
115968 + if (asm_data->output)
115969 + SSA_NAME_DEF_STMT(asm_data->output) = asm_stmt;
115970 +}
115971 +
115972 +static void replace_call_lhs(const struct asm_data *asm_data)
115973 +{
115974 + gimple_set_lhs(asm_data->def_stmt, asm_data->input);
115975 + update_stmt(asm_data->def_stmt);
115976 + SSA_NAME_DEF_STMT(asm_data->input) = asm_data->def_stmt;
115977 +}
115978 +
115979 +static enum mark search_intentional_phi(struct pointer_set_t *visited, const_tree result)
115980 +{
115981 + enum mark cur_fndecl_attr;
115982 + gimple phi = get_def_stmt(result);
115983 + unsigned int i, n = gimple_phi_num_args(phi);
115984 +
115985 + pointer_set_insert(visited, phi);
115986 + for (i = 0; i < n; i++) {
115987 + tree arg = gimple_phi_arg_def(phi, i);
115988 +
115989 + cur_fndecl_attr = search_intentional(visited, arg);
115990 + if (cur_fndecl_attr != MARK_NO)
115991 + return cur_fndecl_attr;
115992 + }
115993 + return MARK_NO;
115994 +}
115995 +
115996 +static enum mark search_intentional_binary(struct pointer_set_t *visited, const_tree lhs)
115997 +{
115998 + enum mark cur_fndecl_attr;
115999 + const_tree rhs1, rhs2;
116000 + gimple def_stmt = get_def_stmt(lhs);
116001 +
116002 + rhs1 = gimple_assign_rhs1(def_stmt);
116003 + rhs2 = gimple_assign_rhs2(def_stmt);
116004 +
116005 + cur_fndecl_attr = search_intentional(visited, rhs1);
116006 + if (cur_fndecl_attr != MARK_NO)
116007 + return cur_fndecl_attr;
116008 + return search_intentional(visited, rhs2);
116009 +}
116010 +
116011 +// Look up the intentional_overflow attribute on the caller and the callee functions.
116012 +static enum mark search_intentional(struct pointer_set_t *visited, const_tree lhs)
116013 +{
116014 + const_gimple def_stmt;
116015 +
116016 + if (TREE_CODE(lhs) != SSA_NAME)
116017 + return get_intentional_attr_type(lhs);
116018 +
116019 + def_stmt = get_def_stmt(lhs);
116020 + if (!def_stmt)
116021 + return MARK_NO;
116022 +
116023 + if (pointer_set_contains(visited, def_stmt))
116024 + return MARK_NO;
116025 +
116026 + switch (gimple_code(def_stmt)) {
116027 + case GIMPLE_NOP:
116028 + return search_intentional(visited, SSA_NAME_VAR(lhs));
116029 + case GIMPLE_ASM:
116030 + if (is_size_overflow_intentional_asm_turn_off(def_stmt))
116031 + return MARK_TURN_OFF;
116032 + return MARK_NO;
116033 + case GIMPLE_CALL:
116034 + return MARK_NO;
116035 + case GIMPLE_PHI:
116036 + return search_intentional_phi(visited, lhs);
116037 + case GIMPLE_ASSIGN:
116038 + switch (gimple_num_ops(def_stmt)) {
116039 + case 2:
116040 + return search_intentional(visited, gimple_assign_rhs1(def_stmt));
116041 + case 3:
116042 + return search_intentional_binary(visited, lhs);
116043 + }
116044 + case GIMPLE_RETURN:
116045 + return MARK_NO;
116046 + default:
116047 + debug_gimple_stmt((gimple)def_stmt);
116048 + error("%s: unknown gimple code", __func__);
116049 + gcc_unreachable();
116050 + }
116051 +}
116052 +
116053 +// Check the intentional_overflow attribute and create the asm comment string for the size_overflow asm stmt.
116054 +static enum mark check_intentional_attribute_gimple(const_tree arg, const_gimple stmt, unsigned int argnum)
116055 +{
116056 + const_tree fndecl;
116057 + struct pointer_set_t *visited;
116058 + enum mark cur_fndecl_attr, decl_attr = MARK_NO;
116059 +
116060 + fndecl = get_interesting_orig_fndecl(stmt, argnum);
116061 + if (is_end_intentional_intentional_attr(fndecl, argnum))
116062 + decl_attr = MARK_NOT_INTENTIONAL;
116063 + else if (is_yes_intentional_attr(fndecl, argnum))
116064 + decl_attr = MARK_YES;
116065 + else if (is_turn_off_intentional_attr(fndecl) || is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl))) {
116066 + return MARK_TURN_OFF;
116067 + }
116068 +
116069 + visited = pointer_set_create();
116070 + cur_fndecl_attr = search_intentional(visited, arg);
116071 + pointer_set_destroy(visited);
116072 +
116073 + switch (cur_fndecl_attr) {
116074 + case MARK_NO:
116075 + case MARK_TURN_OFF:
116076 + return cur_fndecl_attr;
116077 + default:
116078 + print_missing_intentional(decl_attr, cur_fndecl_attr, fndecl, argnum);
116079 + return MARK_YES;
116080 + }
116081 +}
116082 +
116083 +static void check_missing_size_overflow_attribute(tree var)
116084 +{
116085 + tree orig_fndecl;
116086 + unsigned int num;
116087 +
116088 + if (is_a_return_check(var))
116089 + orig_fndecl = DECL_ORIGIN(var);
116090 + else
116091 + orig_fndecl = DECL_ORIGIN(current_function_decl);
116092 +
116093 + num = get_function_num(var, orig_fndecl);
116094 + if (num == CANNOT_FIND_ARG)
116095 + return;
116096 +
116097 + is_missing_function(orig_fndecl, num);
116098 +}
116099 +
116100 +static void search_size_overflow_attribute_phi(struct pointer_set_t *visited, const_tree result)
116101 +{
116102 + gimple phi = get_def_stmt(result);
116103 + unsigned int i, n = gimple_phi_num_args(phi);
116104 +
116105 + pointer_set_insert(visited, phi);
116106 + for (i = 0; i < n; i++) {
116107 + tree arg = gimple_phi_arg_def(phi, i);
116108 +
116109 + search_size_overflow_attribute(visited, arg);
116110 + }
116111 +}
116112 +
116113 +static void search_size_overflow_attribute_binary(struct pointer_set_t *visited, const_tree lhs)
116114 +{
116115 + const_gimple def_stmt = get_def_stmt(lhs);
116116 + tree rhs1, rhs2;
116117 +
116118 + rhs1 = gimple_assign_rhs1(def_stmt);
116119 + rhs2 = gimple_assign_rhs2(def_stmt);
116120 +
116121 + search_size_overflow_attribute(visited, rhs1);
116122 + search_size_overflow_attribute(visited, rhs2);
116123 +}
116124 +
116125 +static void search_size_overflow_attribute(struct pointer_set_t *visited, tree lhs)
116126 +{
116127 + const_gimple def_stmt;
116128 +
116129 + if (TREE_CODE(lhs) == PARM_DECL) {
116130 + check_missing_size_overflow_attribute(lhs);
116131 + return;
116132 + }
116133 +
116134 + def_stmt = get_def_stmt(lhs);
116135 + if (!def_stmt)
116136 + return;
116137 +
116138 + if (pointer_set_insert(visited, def_stmt))
116139 + return;
116140 +
116141 + switch (gimple_code(def_stmt)) {
116142 + case GIMPLE_NOP:
116143 + return search_size_overflow_attribute(visited, SSA_NAME_VAR(lhs));
116144 + case GIMPLE_ASM:
116145 + return;
116146 + case GIMPLE_CALL: {
116147 + tree fndecl = gimple_call_fndecl(def_stmt);
116148 +
116149 + if (fndecl == NULL_TREE)
116150 + return;
116151 + check_missing_size_overflow_attribute(fndecl);
116152 + return;
116153 + }
116154 + case GIMPLE_PHI:
116155 + return search_size_overflow_attribute_phi(visited, lhs);
116156 + case GIMPLE_ASSIGN:
116157 + switch (gimple_num_ops(def_stmt)) {
116158 + case 2:
116159 + return search_size_overflow_attribute(visited, gimple_assign_rhs1(def_stmt));
116160 + case 3:
116161 + return search_size_overflow_attribute_binary(visited, lhs);
116162 + }
116163 + default:
116164 + debug_gimple_stmt((gimple)def_stmt);
116165 + error("%s: unknown gimple code", __func__);
116166 + gcc_unreachable();
116167 + }
116168 +}
116169 +
116170 +// Search missing entries in the hash table (invoked from the gimple pass)
116171 +static void search_missing_size_overflow_attribute_gimple(const_gimple stmt, unsigned int num)
116172 +{
116173 + tree fndecl = NULL_TREE;
116174 + tree lhs;
116175 + struct pointer_set_t *visited;
116176 +
116177 + if (is_turn_off_intentional_attr(DECL_ORIGIN(current_function_decl)))
116178 + return;
116179 +
116180 + if (num == 0) {
116181 + gcc_assert(gimple_code(stmt) == GIMPLE_RETURN);
116182 + lhs = gimple_return_retval(stmt);
116183 + } else {
116184 + gcc_assert(is_gimple_call(stmt));
116185 + lhs = gimple_call_arg(stmt, num - 1);
116186 + fndecl = gimple_call_fndecl(stmt);
116187 + }
116188 +
116189 + if (fndecl != NULL_TREE && is_turn_off_intentional_attr(DECL_ORIGIN(fndecl)))
116190 + return;
116191 +
116192 + visited = pointer_set_create();
116193 + search_size_overflow_attribute(visited, lhs);
116194 + pointer_set_destroy(visited);
116195 +}
116196 +
116197 +static void create_output_from_phi(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
116198 +{
116199 + gimple_stmt_iterator gsi;
116200 + gimple assign;
116201 +
116202 + assign = gimple_build_assign(asm_data->input, asm_data->output);
116203 + gsi = gsi_for_stmt(stmt);
116204 + gsi_insert_before(&gsi, assign, GSI_NEW_STMT);
116205 + asm_data->def_stmt = assign;
116206 +
116207 + asm_data->output = create_new_var(TREE_TYPE(asm_data->output));
116208 + asm_data->output = make_ssa_name(asm_data->output, stmt);
116209 + if (gimple_code(stmt) == GIMPLE_RETURN)
116210 + gimple_return_set_retval(stmt, asm_data->output);
116211 + else
116212 + gimple_call_set_arg(stmt, argnum - 1, asm_data->output);
116213 + update_stmt(stmt);
116214 +}
116215 +
116216 +static char *create_asm_comment(unsigned int argnum, const_gimple stmt , const char *mark_str)
116217 +{
116218 + const char *fn_name;
116219 + char *asm_comment;
116220 + unsigned int len;
116221 +
116222 + if (argnum == 0)
116223 + fn_name = DECL_NAME_POINTER(current_function_decl);
116224 + else
116225 + fn_name = DECL_NAME_POINTER(gimple_call_fndecl(stmt));
116226 +
116227 + len = asprintf(&asm_comment, "%s %s %u", mark_str, fn_name, argnum);
116228 + gcc_assert(len > 0);
116229 +
116230 + return asm_comment;
116231 +}
116232 +
116233 +static const char *convert_mark_to_str(enum mark mark)
116234 +{
116235 + switch (mark) {
116236 + case MARK_NO:
116237 + return OK_ASM_STR;
116238 + case MARK_YES:
116239 + case MARK_NOT_INTENTIONAL:
116240 + return YES_ASM_STR;
116241 + case MARK_TURN_OFF:
116242 + return TURN_OFF_ASM_STR;
116243 + }
116244 +
116245 + gcc_unreachable();
116246 +}
116247 +
116248 +/* Create the input of the size_overflow asm stmt.
116249 + * When the arg of the callee function is a parm_decl it creates this kind of size_overflow asm stmt:
116250 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
116251 + * The input field in asm_data will be empty if there is no need for further size_overflow asm stmt insertion.
116252 + * otherwise create the input (for a phi stmt the output too) of the asm stmt.
116253 + */
116254 +static void create_asm_input(gimple stmt, unsigned int argnum, struct asm_data *asm_data)
116255 +{
116256 + if (!asm_data->def_stmt) {
116257 + asm_data->input = NULL_TREE;
116258 + return;
116259 + }
116260 +
116261 + asm_data->input = create_new_var(TREE_TYPE(asm_data->output));
116262 + asm_data->input = make_ssa_name(asm_data->input, asm_data->def_stmt);
116263 +
116264 + switch (gimple_code(asm_data->def_stmt)) {
116265 + case GIMPLE_ASSIGN:
116266 + case GIMPLE_CALL:
116267 + replace_call_lhs(asm_data);
116268 + break;
116269 + case GIMPLE_PHI:
116270 + create_output_from_phi(stmt, argnum, asm_data);
116271 + break;
116272 + case GIMPLE_NOP: {
116273 + enum mark mark;
116274 + const char *mark_str;
116275 + char *asm_comment;
116276 +
116277 + mark = check_intentional_attribute_gimple(asm_data->output, stmt, argnum);
116278 +
116279 + asm_data->input = asm_data->output;
116280 + asm_data->output = NULL;
116281 + asm_data->def_stmt = stmt;
116282 +
116283 + mark_str = convert_mark_to_str(mark);
116284 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
116285 +
116286 + create_asm_stmt(asm_comment, build_string(2, "rm"), NULL, asm_data);
116287 + free(asm_comment);
116288 + asm_data->input = NULL_TREE;
116289 + break;
116290 + }
116291 + case GIMPLE_ASM:
116292 + if (is_size_overflow_asm(asm_data->def_stmt)) {
116293 + asm_data->input = NULL_TREE;
116294 + break;
116295 + }
116296 + default:
116297 + debug_gimple_stmt(asm_data->def_stmt);
116298 + gcc_unreachable();
116299 + }
116300 +}
116301 +
116302 +/* This is the gimple part of searching for a missing size_overflow attribute. If the intentional_overflow attribute type
116303 + * is of the right kind create the appropriate size_overflow asm stmts:
116304 + * __asm__("# size_overflow" : =rm" D.3344_8 : "0" cicus.4_16);
116305 + * __asm__("# size_overflow MARK_YES" : : "rm" size_1(D));
116306 + */
116307 +static void create_size_overflow_asm(gimple stmt, tree output_node, unsigned int argnum)
116308 +{
116309 + struct asm_data asm_data;
116310 + const char *mark_str;
116311 + char *asm_comment;
116312 + enum mark mark;
116313 +
116314 + if (is_gimple_constant(output_node))
116315 + return;
116316 +
116317 + asm_data.output = output_node;
116318 + mark = check_intentional_attribute_gimple(asm_data.output, stmt, argnum);
116319 + if (mark != MARK_TURN_OFF)
116320 + search_missing_size_overflow_attribute_gimple(stmt, argnum);
116321 +
116322 + asm_data.def_stmt = get_def_stmt(asm_data.output);
116323 + if (is_size_overflow_intentional_asm_turn_off(asm_data.def_stmt))
116324 + return;
116325 +
116326 + create_asm_input(stmt, argnum, &asm_data);
116327 + if (asm_data.input == NULL_TREE)
116328 + return;
116329 +
116330 + mark_str = convert_mark_to_str(mark);
116331 + asm_comment = create_asm_comment(argnum, stmt, mark_str);
116332 + create_asm_stmt(asm_comment, build_string(1, "0"), build_string(3, "=rm"), &asm_data);
116333 + free(asm_comment);
116334 +}
116335 +
116336 +// Insert an asm stmt with "MARK_TURN_OFF", "MARK_YES" or "MARK_NOT_INTENTIONAL".
116337 +static bool create_mark_asm(gimple stmt, enum mark mark)
116338 +{
116339 + struct asm_data asm_data;
116340 + const char *asm_str;
116341 +
116342 + switch (mark) {
116343 + case MARK_TURN_OFF:
116344 + asm_str = TURN_OFF_ASM_STR;
116345 + break;
116346 + case MARK_NOT_INTENTIONAL:
116347 + case MARK_YES:
116348 + asm_str = YES_ASM_STR;
116349 + break;
116350 + default:
116351 + gcc_unreachable();
116352 + }
116353 +
116354 + asm_data.def_stmt = stmt;
116355 + asm_data.output = gimple_call_lhs(stmt);
116356 +
116357 + if (asm_data.output == NULL_TREE) {
116358 + asm_data.input = gimple_call_arg(stmt, 0);
116359 + if (is_gimple_constant(asm_data.input))
116360 + return false;
116361 + asm_data.output = NULL;
116362 + create_asm_stmt(asm_str, build_string(2, "rm"), NULL, &asm_data);
116363 + return true;
116364 + }
116365 +
116366 + create_asm_input(stmt, 0, &asm_data);
116367 + gcc_assert(asm_data.input != NULL_TREE);
116368 +
116369 + create_asm_stmt(asm_str, build_string(1, "0"), build_string(3, "=rm"), &asm_data);
116370 + return true;
116371 +}
116372 +
116373 +static bool is_from_cast(const_tree node)
116374 +{
116375 + gimple def_stmt = get_def_stmt(node);
116376 +
116377 + if (!def_stmt)
116378 + return false;
116379 +
116380 + if (gimple_assign_cast_p(def_stmt))
116381 + return true;
116382 +
116383 + return false;
116384 +}
116385 +
116386 +// Skip duplication when there is a minus expr and the type of rhs1 or rhs2 is a pointer_type.
116387 +static bool skip_ptr_minus(gimple stmt)
116388 +{
116389 + const_tree rhs1, rhs2, ptr1_rhs, ptr2_rhs;
116390 +
116391 + if (gimple_assign_rhs_code(stmt) != MINUS_EXPR)
116392 + return false;
116393 +
116394 + rhs1 = gimple_assign_rhs1(stmt);
116395 + if (!is_from_cast(rhs1))
116396 + return false;
116397 +
116398 + rhs2 = gimple_assign_rhs2(stmt);
116399 + if (!is_from_cast(rhs2))
116400 + return false;
116401 +
116402 + ptr1_rhs = gimple_assign_rhs1(get_def_stmt(rhs1));
116403 + ptr2_rhs = gimple_assign_rhs1(get_def_stmt(rhs2));
116404 +
116405 + if (TREE_CODE(TREE_TYPE(ptr1_rhs)) != POINTER_TYPE && TREE_CODE(TREE_TYPE(ptr2_rhs)) != POINTER_TYPE)
116406 + return false;
116407 +
116408 + create_mark_asm(stmt, MARK_YES);
116409 + return true;
116410 +}
116411 +
116412 +static void walk_use_def_ptr(struct pointer_set_t *visited, const_tree lhs)
116413 +{
116414 + gimple def_stmt;
116415 +
116416 + def_stmt = get_def_stmt(lhs);
116417 + if (!def_stmt)
116418 + return;
116419 +
116420 + if (pointer_set_insert(visited, def_stmt))
116421 + return;
116422 +
116423 + switch (gimple_code(def_stmt)) {
116424 + case GIMPLE_NOP:
116425 + case GIMPLE_ASM:
116426 + case GIMPLE_CALL:
116427 + break;
116428 + case GIMPLE_PHI: {
116429 + unsigned int i, n = gimple_phi_num_args(def_stmt);
116430 +
116431 + pointer_set_insert(visited, def_stmt);
116432 +
116433 + for (i = 0; i < n; i++) {
116434 + tree arg = gimple_phi_arg_def(def_stmt, i);
116435 +
116436 + walk_use_def_ptr(visited, arg);
116437 + }
116438 + }
116439 + case GIMPLE_ASSIGN:
116440 + switch (gimple_num_ops(def_stmt)) {
116441 + case 2:
116442 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
116443 + return;
116444 + case 3:
116445 + if (skip_ptr_minus(def_stmt))
116446 + return;
116447 +
116448 + walk_use_def_ptr(visited, gimple_assign_rhs1(def_stmt));
116449 + walk_use_def_ptr(visited, gimple_assign_rhs2(def_stmt));
116450 + return;
116451 + default:
116452 + return;
116453 + }
116454 + default:
116455 + debug_gimple_stmt((gimple)def_stmt);
116456 + error("%s: unknown gimple code", __func__);
116457 + gcc_unreachable();
116458 + }
116459 +}
116460 +
116461 +// Look for a ptr - ptr expression (e.g., cpuset_common_file_read() s - page)
116462 +static void insert_mark_not_intentional_asm_at_ptr(const_tree arg)
116463 +{
116464 + struct pointer_set_t *visited;
116465 +
116466 + visited = pointer_set_create();
116467 + walk_use_def_ptr(visited, arg);
116468 + pointer_set_destroy(visited);
116469 +}
116470 +
116471 +// Determine the return value and insert the asm stmt to mark the return stmt.
116472 +static void insert_asm_ret(gimple stmt)
116473 +{
116474 + tree ret;
116475 +
116476 + ret = gimple_return_retval(stmt);
116477 + create_size_overflow_asm(stmt, ret, 0);
116478 +}
116479 +
116480 +// Determine the correct arg index and arg and insert the asm stmt to mark the stmt.
116481 +static void insert_asm_arg(gimple stmt, unsigned int orig_argnum)
116482 +{
116483 + tree arg;
116484 + unsigned int argnum;
116485 +
116486 + argnum = get_correct_arg_count(orig_argnum, gimple_call_fndecl(stmt));
116487 + gcc_assert(argnum != 0);
116488 + if (argnum == CANNOT_FIND_ARG)
116489 + return;
116490 +
116491 + arg = gimple_call_arg(stmt, argnum - 1);
116492 + gcc_assert(arg != NULL_TREE);
116493 +
116494 + // skip all ptr - ptr expressions
116495 + insert_mark_not_intentional_asm_at_ptr(arg);
116496 +
116497 + create_size_overflow_asm(stmt, arg, argnum);
116498 +}
116499 +
116500 +// If a function arg or the return value is marked by the size_overflow attribute then set its index in the array.
116501 +static void set_argnum_attribute(const_tree attr, bool *argnums)
116502 +{
116503 + unsigned int argnum;
116504 + tree attr_value;
116505 +
116506 + for (attr_value = TREE_VALUE(attr); attr_value; attr_value = TREE_CHAIN(attr_value)) {
116507 + argnum = TREE_INT_CST_LOW(TREE_VALUE(attr_value));
116508 + argnums[argnum] = true;
116509 + }
116510 +}
116511 +
116512 +// If a function arg or the return value is in the hash table then set its index in the array.
116513 +static void set_argnum_hash(tree fndecl, bool *argnums)
116514 +{
116515 + unsigned int num;
116516 + const struct size_overflow_hash *hash;
116517 +
116518 + hash = get_function_hash(DECL_ORIGIN(fndecl));
116519 + if (!hash)
116520 + return;
116521 +
116522 + for (num = 0; num <= MAX_PARAM; num++) {
116523 + if (!(hash->param & (1U << num)))
116524 + continue;
116525 +
116526 + argnums[num] = true;
116527 + }
116528 +}
116529 +
116530 +static bool is_all_the_argnums_empty(bool *argnums)
116531 +{
116532 + unsigned int i;
116533 +
116534 + for (i = 0; i <= MAX_PARAM; i++)
116535 + if (argnums[i])
116536 + return false;
116537 + return true;
116538 +}
116539 +
116540 +// Check whether the arguments or the return value of the function are in the hash table or are marked by the size_overflow attribute.
116541 +static void search_interesting_args(tree fndecl, bool *argnums)
116542 +{
116543 + const_tree attr;
116544 +
116545 + set_argnum_hash(fndecl, argnums);
116546 + if (!is_all_the_argnums_empty(argnums))
116547 + return;
116548 +
116549 + attr = lookup_attribute("size_overflow", DECL_ATTRIBUTES(fndecl));
116550 + if (attr && TREE_VALUE(attr))
116551 + set_argnum_attribute(attr, argnums);
116552 +}
116553 +
116554 +/*
116555 + * Look up the intentional_overflow attribute that turns off ipa based duplication
116556 + * on the callee function.
116557 + */
116558 +static bool is_mark_turn_off_attribute(gimple stmt)
116559 +{
116560 + enum mark mark;
116561 + const_tree fndecl = gimple_call_fndecl(stmt);
116562 +
116563 + mark = get_intentional_attr_type(DECL_ORIGIN(fndecl));
116564 + if (mark == MARK_TURN_OFF)
116565 + return true;
116566 + return false;
116567 +}
116568 +
116569 +// 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
116570 +static void handle_interesting_function(gimple stmt)
116571 +{
116572 + unsigned int argnum;
116573 + tree fndecl;
116574 + bool orig_argnums[MAX_PARAM + 1] = {false};
116575 +
116576 + if (gimple_call_num_args(stmt) == 0)
116577 + return;
116578 + fndecl = gimple_call_fndecl(stmt);
116579 + if (fndecl == NULL_TREE)
116580 + return;
116581 + fndecl = DECL_ORIGIN(fndecl);
116582 +
116583 + if (is_mark_turn_off_attribute(stmt)) {
116584 + create_mark_asm(stmt, MARK_TURN_OFF);
116585 + return;
116586 + }
116587 +
116588 + search_interesting_args(fndecl, orig_argnums);
116589 +
116590 + for (argnum = 1; argnum < MAX_PARAM; argnum++)
116591 + if (orig_argnums[argnum])
116592 + insert_asm_arg(stmt, argnum);
116593 +}
116594 +
116595 +// 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
116596 +static void handle_interesting_ret(gimple stmt)
116597 +{
116598 + bool orig_argnums[MAX_PARAM + 1] = {false};
116599 +
116600 + search_interesting_args(current_function_decl, orig_argnums);
116601 +
116602 + if (orig_argnums[0])
116603 + insert_asm_ret(stmt);
116604 +}
116605 +
116606 +// Iterate over all the stmts and search for call and return stmts and mark them if they're in the hash table
116607 +static unsigned int search_interesting_functions(void)
116608 +{
116609 + basic_block bb;
116610 +
116611 + FOR_ALL_BB_FN(bb, cfun) {
116612 + gimple_stmt_iterator gsi;
116613 +
116614 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
116615 + gimple stmt = gsi_stmt(gsi);
116616 +
116617 + if (is_size_overflow_asm(stmt))
116618 + continue;
116619 +
116620 + if (is_gimple_call(stmt))
116621 + handle_interesting_function(stmt);
116622 + else if (gimple_code(stmt) == GIMPLE_RETURN)
116623 + handle_interesting_ret(stmt);
116624 + }
116625 + }
116626 + return 0;
116627 +}
116628 +
116629 +/*
116630 + * A lot of functions get inlined before the ipa passes so after the build_ssa gimple pass
116631 + * this pass inserts asm stmts to mark the interesting args
116632 + * that the ipa pass will detect and insert the size overflow checks for.
116633 + */
116634 +#if BUILDING_GCC_VERSION >= 4009
116635 +static const struct pass_data insert_size_overflow_asm_pass_data = {
116636 +#else
116637 +static struct gimple_opt_pass insert_size_overflow_asm_pass = {
116638 + .pass = {
116639 +#endif
116640 + .type = GIMPLE_PASS,
116641 + .name = "insert_size_overflow_asm",
116642 +#if BUILDING_GCC_VERSION >= 4008
116643 + .optinfo_flags = OPTGROUP_NONE,
116644 +#endif
116645 +#if BUILDING_GCC_VERSION >= 4009
116646 + .has_gate = false,
116647 + .has_execute = true,
116648 +#else
116649 + .gate = NULL,
116650 + .execute = search_interesting_functions,
116651 + .sub = NULL,
116652 + .next = NULL,
116653 + .static_pass_number = 0,
116654 +#endif
116655 + .tv_id = TV_NONE,
116656 + .properties_required = PROP_cfg,
116657 + .properties_provided = 0,
116658 + .properties_destroyed = 0,
116659 + .todo_flags_start = 0,
116660 + .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
116661 +#if BUILDING_GCC_VERSION < 4009
116662 + }
116663 +#endif
116664 +};
116665 +
116666 +#if BUILDING_GCC_VERSION >= 4009
116667 +namespace {
116668 +class insert_size_overflow_asm_pass : public gimple_opt_pass {
116669 +public:
116670 + insert_size_overflow_asm_pass() : gimple_opt_pass(insert_size_overflow_asm_pass_data, g) {}
116671 + unsigned int execute() { return search_interesting_functions(); }
116672 +};
116673 +}
116674 +#endif
116675 +
116676 +static struct opt_pass *make_insert_size_overflow_asm_pass(void)
116677 +{
116678 +#if BUILDING_GCC_VERSION >= 4009
116679 + return new insert_size_overflow_asm_pass();
116680 +#else
116681 + return &insert_size_overflow_asm_pass.pass;
116682 +#endif
116683 +}
116684 +
116685 +// Create the noreturn report_size_overflow() function decl.
116686 +static void size_overflow_start_unit(void __unused *gcc_data, void __unused *user_data)
116687 +{
116688 + tree const_char_ptr_type_node;
116689 + tree fntype;
116690 +
116691 + const_char_ptr_type_node = build_pointer_type(build_type_variant(char_type_node, 1, 0));
116692 +
116693 + // void report_size_overflow(const char *loc_file, unsigned int loc_line, const char *current_func, const char *ssa_var)
116694 + fntype = build_function_type_list(void_type_node,
116695 + const_char_ptr_type_node,
116696 + unsigned_type_node,
116697 + const_char_ptr_type_node,
116698 + const_char_ptr_type_node,
116699 + NULL_TREE);
116700 + report_size_overflow_decl = build_fn_decl("report_size_overflow", fntype);
116701 +
116702 + DECL_ASSEMBLER_NAME(report_size_overflow_decl);
116703 + TREE_PUBLIC(report_size_overflow_decl) = 1;
116704 + DECL_EXTERNAL(report_size_overflow_decl) = 1;
116705 + DECL_ARTIFICIAL(report_size_overflow_decl) = 1;
116706 + TREE_THIS_VOLATILE(report_size_overflow_decl) = 1;
116707 +}
116708 +
116709 +static unsigned int dump_functions(void)
116710 +{
116711 + struct cgraph_node *node;
116712 +
116713 + FOR_EACH_FUNCTION_WITH_GIMPLE_BODY(node) {
116714 + basic_block bb;
116715 +
116716 + push_cfun(DECL_STRUCT_FUNCTION(NODE_DECL(node)));
116717 + current_function_decl = NODE_DECL(node);
116718 +
116719 + fprintf(stderr, "-----------------------------------------\n%s\n-----------------------------------------\n", DECL_NAME_POINTER(current_function_decl));
116720 +
116721 + FOR_ALL_BB_FN(bb, cfun) {
116722 + gimple_stmt_iterator si;
116723 +
116724 + fprintf(stderr, "<bb %u>:\n", bb->index);
116725 + for (si = gsi_start_phis(bb); !gsi_end_p(si); gsi_next(&si))
116726 + debug_gimple_stmt(gsi_stmt(si));
116727 + for (si = gsi_start_bb(bb); !gsi_end_p(si); gsi_next(&si))
116728 + debug_gimple_stmt(gsi_stmt(si));
116729 + fprintf(stderr, "\n");
116730 + }
116731 +
116732 + fprintf(stderr, "-------------------------------------------------------------------------\n");
116733 +
116734 + pop_cfun();
116735 + current_function_decl = NULL_TREE;
116736 + }
116737 +
116738 + fprintf(stderr, "###############################################################################\n");
116739 +
116740 + return 0;
116741 +}
116742 +
116743 +#if BUILDING_GCC_VERSION >= 4009
116744 +static const struct pass_data dump_pass_data = {
116745 +#else
116746 +static struct ipa_opt_pass_d dump_pass = {
116747 + .pass = {
116748 +#endif
116749 + .type = SIMPLE_IPA_PASS,
116750 + .name = "dump",
116751 +#if BUILDING_GCC_VERSION >= 4008
116752 + .optinfo_flags = OPTGROUP_NONE,
116753 +#endif
116754 +#if BUILDING_GCC_VERSION >= 4009
116755 + .has_gate = false,
116756 + .has_execute = true,
116757 +#else
116758 + .gate = NULL,
116759 + .execute = dump_functions,
116760 + .sub = NULL,
116761 + .next = NULL,
116762 + .static_pass_number = 0,
116763 +#endif
116764 + .tv_id = TV_NONE,
116765 + .properties_required = 0,
116766 + .properties_provided = 0,
116767 + .properties_destroyed = 0,
116768 + .todo_flags_start = 0,
116769 + .todo_flags_finish = 0,
116770 +#if BUILDING_GCC_VERSION < 4009
116771 + },
116772 + .generate_summary = NULL,
116773 + .write_summary = NULL,
116774 + .read_summary = NULL,
116775 +#if BUILDING_GCC_VERSION >= 4006
116776 + .write_optimization_summary = NULL,
116777 + .read_optimization_summary = NULL,
116778 +#endif
116779 + .stmt_fixup = NULL,
116780 + .function_transform_todo_flags_start = 0,
116781 + .function_transform = NULL,
116782 + .variable_transform = NULL,
116783 +#endif
116784 +};
116785 +
116786 +#if BUILDING_GCC_VERSION >= 4009
116787 +namespace {
116788 +class dump_pass : public ipa_opt_pass_d {
116789 +public:
116790 + dump_pass() : ipa_opt_pass_d(dump_pass_data, g, NULL, NULL, NULL, NULL, NULL, NULL, 0, NULL, NULL) {}
116791 + unsigned int execute() { return dump_functions(); }
116792 +};
116793 +}
116794 +#endif
116795 +
116796 +static struct opt_pass *make_dump_pass(void)
116797 +{
116798 +#if BUILDING_GCC_VERSION >= 4009
116799 + return new dump_pass();
116800 +#else
116801 + return &dump_pass.pass;
116802 +#endif
116803 +}
116804 +
116805 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
116806 +{
116807 + int i;
116808 + const char * const plugin_name = plugin_info->base_name;
116809 + const int argc = plugin_info->argc;
116810 + const struct plugin_argument * const argv = plugin_info->argv;
116811 + bool enable = true;
116812 + struct register_pass_info insert_size_overflow_asm_pass_info;
116813 + struct register_pass_info __unused dump_before_pass_info;
116814 + struct register_pass_info __unused dump_after_pass_info;
116815 + struct register_pass_info ipa_pass_info;
116816 + static const struct ggc_root_tab gt_ggc_r_gt_size_overflow[] = {
116817 + {
116818 + .base = &report_size_overflow_decl,
116819 + .nelt = 1,
116820 + .stride = sizeof(report_size_overflow_decl),
116821 + .cb = &gt_ggc_mx_tree_node,
116822 + .pchw = &gt_pch_nx_tree_node
116823 + },
116824 + LAST_GGC_ROOT_TAB
116825 + };
116826 +
116827 + insert_size_overflow_asm_pass_info.pass = make_insert_size_overflow_asm_pass();
116828 + insert_size_overflow_asm_pass_info.reference_pass_name = "ssa";
116829 + insert_size_overflow_asm_pass_info.ref_pass_instance_number = 1;
116830 + insert_size_overflow_asm_pass_info.pos_op = PASS_POS_INSERT_AFTER;
116831 +
116832 + dump_before_pass_info.pass = make_dump_pass();
116833 + dump_before_pass_info.reference_pass_name = "increase_alignment";
116834 + dump_before_pass_info.ref_pass_instance_number = 1;
116835 + dump_before_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
116836 +
116837 + ipa_pass_info.pass = make_ipa_pass();
116838 + ipa_pass_info.reference_pass_name = "increase_alignment";
116839 + ipa_pass_info.ref_pass_instance_number = 1;
116840 + ipa_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
116841 +
116842 + dump_after_pass_info.pass = make_dump_pass();
116843 + dump_after_pass_info.reference_pass_name = "increase_alignment";
116844 + dump_after_pass_info.ref_pass_instance_number = 1;
116845 + dump_after_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
116846 +
116847 + if (!plugin_default_version_check(version, &gcc_version)) {
116848 + error(G_("incompatible gcc/plugin versions"));
116849 + return 1;
116850 + }
116851 +
116852 + for (i = 0; i < argc; ++i) {
116853 + if (!strcmp(argv[i].key, "no-size-overflow")) {
116854 + enable = false;
116855 + continue;
116856 + }
116857 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
116858 + }
116859 +
116860 + register_callback(plugin_name, PLUGIN_INFO, NULL, &size_overflow_plugin_info);
116861 + if (enable) {
116862 + register_callback(plugin_name, PLUGIN_START_UNIT, &size_overflow_start_unit, NULL);
116863 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_size_overflow);
116864 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &insert_size_overflow_asm_pass_info);
116865 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_before_pass_info);
116866 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &ipa_pass_info);
116867 +// register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &dump_after_pass_info);
116868 + }
116869 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
116870 +
116871 + return 0;
116872 +}
116873 diff --git a/tools/gcc/stackleak_plugin.c b/tools/gcc/stackleak_plugin.c
116874 new file mode 100644
116875 index 0000000..e684c74
116876 --- /dev/null
116877 +++ b/tools/gcc/stackleak_plugin.c
116878 @@ -0,0 +1,373 @@
116879 +/*
116880 + * Copyright 2011-2014 by the PaX Team <pageexec@freemail.hu>
116881 + * Licensed under the GPL v2
116882 + *
116883 + * Note: the choice of the license means that the compilation process is
116884 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
116885 + * but for the kernel it doesn't matter since it doesn't link against
116886 + * any of the gcc libraries
116887 + *
116888 + * gcc plugin to help implement various PaX features
116889 + *
116890 + * - track lowest stack pointer
116891 + *
116892 + * TODO:
116893 + * - initialize all local variables
116894 + *
116895 + * BUGS:
116896 + * - none known
116897 + */
116898 +
116899 +#include "gcc-common.h"
116900 +
116901 +int plugin_is_GPL_compatible;
116902 +
116903 +static int track_frame_size = -1;
116904 +static const char track_function[] = "pax_track_stack";
116905 +static const char check_function[] = "pax_check_alloca";
116906 +static tree track_function_decl, check_function_decl;
116907 +static bool init_locals;
116908 +
116909 +static struct plugin_info stackleak_plugin_info = {
116910 + .version = "201402131920",
116911 + .help = "track-lowest-sp=nn\ttrack sp in functions whose frame size is at least nn bytes\n"
116912 +// "initialize-locals\t\tforcibly initialize all stack frames\n"
116913 +};
116914 +
116915 +static void stackleak_check_alloca(gimple_stmt_iterator *gsi)
116916 +{
116917 + gimple check_alloca;
116918 + tree alloca_size;
116919 +
116920 + // insert call to void pax_check_alloca(unsigned long size)
116921 + alloca_size = gimple_call_arg(gsi_stmt(*gsi), 0);
116922 + check_alloca = gimple_build_call(check_function_decl, 1, alloca_size);
116923 + gsi_insert_before(gsi, check_alloca, GSI_SAME_STMT);
116924 +}
116925 +
116926 +static void stackleak_add_instrumentation(gimple_stmt_iterator *gsi)
116927 +{
116928 + gimple track_stack;
116929 +
116930 + // insert call to void pax_track_stack(void)
116931 + track_stack = gimple_build_call(track_function_decl, 0);
116932 + gsi_insert_after(gsi, track_stack, GSI_CONTINUE_LINKING);
116933 +}
116934 +
116935 +static bool is_alloca(gimple stmt)
116936 +{
116937 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA))
116938 + return true;
116939 +
116940 +#if BUILDING_GCC_VERSION >= 4007
116941 + if (gimple_call_builtin_p(stmt, BUILT_IN_ALLOCA_WITH_ALIGN))
116942 + return true;
116943 +#endif
116944 +
116945 + return false;
116946 +}
116947 +
116948 +static unsigned int execute_stackleak_tree_instrument(void)
116949 +{
116950 + basic_block bb, entry_bb;
116951 + bool prologue_instrumented = false, is_leaf = true;
116952 +
116953 + entry_bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb;
116954 +
116955 + // 1. loop through BBs and GIMPLE statements
116956 + FOR_EACH_BB_FN(bb, cfun) {
116957 + gimple_stmt_iterator gsi;
116958 +
116959 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
116960 + gimple stmt;
116961 +
116962 + stmt = gsi_stmt(gsi);
116963 +
116964 + if (is_gimple_call(stmt))
116965 + is_leaf = false;
116966 +
116967 + // gimple match: align 8 built-in BUILT_IN_NORMAL:BUILT_IN_ALLOCA attributes <tree_list 0xb7576450>
116968 + if (!is_alloca(stmt))
116969 + continue;
116970 +
116971 + // 2. insert stack overflow check before each __builtin_alloca call
116972 + stackleak_check_alloca(&gsi);
116973 +
116974 + // 3. insert track call after each __builtin_alloca call
116975 + stackleak_add_instrumentation(&gsi);
116976 + if (bb == entry_bb)
116977 + prologue_instrumented = true;
116978 + }
116979 + }
116980 +
116981 + // special cases for some bad linux code: taking the address of static inline functions will materialize them
116982 + // but we mustn't instrument some of them as the resulting stack alignment required by the function call ABI
116983 + // will break other assumptions regarding the expected (but not otherwise enforced) register clobbering ABI.
116984 + // case in point: native_save_fl on amd64 when optimized for size clobbers rdx if it were instrumented here.
116985 + if (is_leaf && !TREE_PUBLIC(current_function_decl) && DECL_DECLARED_INLINE_P(current_function_decl))
116986 + return 0;
116987 + if (is_leaf && !strncmp(IDENTIFIER_POINTER(DECL_NAME(current_function_decl)), "_paravirt_", 10))
116988 + return 0;
116989 +
116990 + // 4. insert track call at the beginning
116991 + if (!prologue_instrumented) {
116992 + gimple_stmt_iterator gsi;
116993 +
116994 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
116995 + if (dom_info_available_p(CDI_DOMINATORS))
116996 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
116997 + gsi = gsi_start_bb(bb);
116998 + stackleak_add_instrumentation(&gsi);
116999 + }
117000 +
117001 + return 0;
117002 +}
117003 +
117004 +static unsigned int execute_stackleak_final(void)
117005 +{
117006 + rtx insn, next;
117007 +
117008 + if (cfun->calls_alloca)
117009 + return 0;
117010 +
117011 + // keep calls only if function frame is big enough
117012 + if (get_frame_size() >= track_frame_size)
117013 + return 0;
117014 +
117015 + // 1. find pax_track_stack calls
117016 + for (insn = get_insns(); insn; insn = next) {
117017 + // 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))
117018 + rtx body;
117019 +
117020 + next = NEXT_INSN(insn);
117021 + if (!CALL_P(insn))
117022 + continue;
117023 + body = PATTERN(insn);
117024 + if (GET_CODE(body) != CALL)
117025 + continue;
117026 + body = XEXP(body, 0);
117027 + if (GET_CODE(body) != MEM)
117028 + continue;
117029 + body = XEXP(body, 0);
117030 + if (GET_CODE(body) != SYMBOL_REF)
117031 + continue;
117032 + if (strcmp(XSTR(body, 0), track_function))
117033 + continue;
117034 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
117035 + // 2. delete call
117036 + delete_insn_and_edges(insn);
117037 +#if BUILDING_GCC_VERSION >= 4007
117038 + if (GET_CODE(next) == NOTE && NOTE_KIND(next) == NOTE_INSN_CALL_ARG_LOCATION) {
117039 + insn = next;
117040 + next = NEXT_INSN(insn);
117041 + delete_insn_and_edges(insn);
117042 + }
117043 +#endif
117044 + }
117045 +
117046 +// print_simple_rtl(stderr, get_insns());
117047 +// print_rtl(stderr, get_insns());
117048 +// warning(0, "track_frame_size: %d %ld %d", cfun->calls_alloca, get_frame_size(), track_frame_size);
117049 +
117050 + return 0;
117051 +}
117052 +
117053 +static bool gate_stackleak_track_stack(void)
117054 +{
117055 + return track_frame_size >= 0;
117056 +}
117057 +
117058 +static void stackleak_start_unit(void *gcc_data, void *user_data)
117059 +{
117060 + tree fntype;
117061 +
117062 + // void pax_track_stack(void)
117063 + fntype = build_function_type_list(void_type_node, NULL_TREE);
117064 + track_function_decl = build_fn_decl(track_function, fntype);
117065 + DECL_ASSEMBLER_NAME(track_function_decl); // for LTO
117066 + TREE_PUBLIC(track_function_decl) = 1;
117067 + DECL_EXTERNAL(track_function_decl) = 1;
117068 + DECL_ARTIFICIAL(track_function_decl) = 1;
117069 +
117070 + // void pax_check_alloca(unsigned long)
117071 + fntype = build_function_type_list(void_type_node, long_unsigned_type_node, NULL_TREE);
117072 + check_function_decl = build_fn_decl(check_function, fntype);
117073 + DECL_ASSEMBLER_NAME(check_function_decl); // for LTO
117074 + TREE_PUBLIC(check_function_decl) = 1;
117075 + DECL_EXTERNAL(check_function_decl) = 1;
117076 + DECL_ARTIFICIAL(check_function_decl) = 1;
117077 +}
117078 +
117079 +#if BUILDING_GCC_VERSION >= 4009
117080 +static const struct pass_data stackleak_tree_instrument_pass_data = {
117081 +#else
117082 +static struct gimple_opt_pass stackleak_tree_instrument_pass = {
117083 + .pass = {
117084 +#endif
117085 + .type = GIMPLE_PASS,
117086 + .name = "stackleak_tree_instrument",
117087 +#if BUILDING_GCC_VERSION >= 4008
117088 + .optinfo_flags = OPTGROUP_NONE,
117089 +#endif
117090 +#if BUILDING_GCC_VERSION >= 4009
117091 + .has_gate = true,
117092 + .has_execute = true,
117093 +#else
117094 + .gate = gate_stackleak_track_stack,
117095 + .execute = execute_stackleak_tree_instrument,
117096 + .sub = NULL,
117097 + .next = NULL,
117098 + .static_pass_number = 0,
117099 +#endif
117100 + .tv_id = TV_NONE,
117101 + .properties_required = PROP_gimple_leh | PROP_cfg,
117102 + .properties_provided = 0,
117103 + .properties_destroyed = 0,
117104 + .todo_flags_start = 0, //TODO_verify_ssa | TODO_verify_flow | TODO_verify_stmts,
117105 + .todo_flags_finish = TODO_verify_ssa | TODO_verify_stmts | TODO_dump_func | TODO_update_ssa
117106 +#if BUILDING_GCC_VERSION < 4009
117107 + }
117108 +#endif
117109 +};
117110 +
117111 +#if BUILDING_GCC_VERSION >= 4009
117112 +static const struct pass_data stackleak_final_rtl_opt_pass_data = {
117113 +#else
117114 +static struct rtl_opt_pass stackleak_final_rtl_opt_pass = {
117115 + .pass = {
117116 +#endif
117117 + .type = RTL_PASS,
117118 + .name = "stackleak_final",
117119 +#if BUILDING_GCC_VERSION >= 4008
117120 + .optinfo_flags = OPTGROUP_NONE,
117121 +#endif
117122 +#if BUILDING_GCC_VERSION >= 4009
117123 + .has_gate = true,
117124 + .has_execute = true,
117125 +#else
117126 + .gate = gate_stackleak_track_stack,
117127 + .execute = execute_stackleak_final,
117128 + .sub = NULL,
117129 + .next = NULL,
117130 + .static_pass_number = 0,
117131 +#endif
117132 + .tv_id = TV_NONE,
117133 + .properties_required = 0,
117134 + .properties_provided = 0,
117135 + .properties_destroyed = 0,
117136 + .todo_flags_start = 0,
117137 + .todo_flags_finish = TODO_dump_func
117138 +#if BUILDING_GCC_VERSION < 4009
117139 + }
117140 +#endif
117141 +};
117142 +
117143 +#if BUILDING_GCC_VERSION >= 4009
117144 +namespace {
117145 +class stackleak_tree_instrument_pass : public gimple_opt_pass {
117146 +public:
117147 + stackleak_tree_instrument_pass() : gimple_opt_pass(stackleak_tree_instrument_pass_data, g) {}
117148 + bool gate() { return gate_stackleak_track_stack(); }
117149 + unsigned int execute() { return execute_stackleak_tree_instrument(); }
117150 +};
117151 +
117152 +class stackleak_final_rtl_opt_pass : public rtl_opt_pass {
117153 +public:
117154 + stackleak_final_rtl_opt_pass() : rtl_opt_pass(stackleak_final_rtl_opt_pass_data, g) {}
117155 + bool gate() { return gate_stackleak_track_stack(); }
117156 + unsigned int execute() { return execute_stackleak_final(); }
117157 +};
117158 +}
117159 +#endif
117160 +
117161 +static struct opt_pass *make_stackleak_tree_instrument_pass(void)
117162 +{
117163 +#if BUILDING_GCC_VERSION >= 4009
117164 + return new stackleak_tree_instrument_pass();
117165 +#else
117166 + return &stackleak_tree_instrument_pass.pass;
117167 +#endif
117168 +}
117169 +
117170 +static struct opt_pass *make_stackleak_final_rtl_opt_pass(void)
117171 +{
117172 +#if BUILDING_GCC_VERSION >= 4009
117173 + return new stackleak_final_rtl_opt_pass();
117174 +#else
117175 + return &stackleak_final_rtl_opt_pass.pass;
117176 +#endif
117177 +}
117178 +
117179 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
117180 +{
117181 + const char * const plugin_name = plugin_info->base_name;
117182 + const int argc = plugin_info->argc;
117183 + const struct plugin_argument * const argv = plugin_info->argv;
117184 + int i;
117185 + struct register_pass_info stackleak_tree_instrument_pass_info;
117186 + struct register_pass_info stackleak_final_pass_info;
117187 + static const struct ggc_root_tab gt_ggc_r_gt_stackleak[] = {
117188 + {
117189 + .base = &track_function_decl,
117190 + .nelt = 1,
117191 + .stride = sizeof(track_function_decl),
117192 + .cb = &gt_ggc_mx_tree_node,
117193 + .pchw = &gt_pch_nx_tree_node
117194 + },
117195 + {
117196 + .base = &check_function_decl,
117197 + .nelt = 1,
117198 + .stride = sizeof(check_function_decl),
117199 + .cb = &gt_ggc_mx_tree_node,
117200 + .pchw = &gt_pch_nx_tree_node
117201 + },
117202 + LAST_GGC_ROOT_TAB
117203 + };
117204 +
117205 + stackleak_tree_instrument_pass_info.pass = make_stackleak_tree_instrument_pass();
117206 +// stackleak_tree_instrument_pass_info.reference_pass_name = "tree_profile";
117207 + stackleak_tree_instrument_pass_info.reference_pass_name = "optimized";
117208 + stackleak_tree_instrument_pass_info.ref_pass_instance_number = 1;
117209 + stackleak_tree_instrument_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
117210 +
117211 + stackleak_final_pass_info.pass = make_stackleak_final_rtl_opt_pass();
117212 + stackleak_final_pass_info.reference_pass_name = "final";
117213 + stackleak_final_pass_info.ref_pass_instance_number = 1;
117214 + stackleak_final_pass_info.pos_op = PASS_POS_INSERT_BEFORE;
117215 +
117216 + if (!plugin_default_version_check(version, &gcc_version)) {
117217 + error(G_("incompatible gcc/plugin versions"));
117218 + return 1;
117219 + }
117220 +
117221 + register_callback(plugin_name, PLUGIN_INFO, NULL, &stackleak_plugin_info);
117222 +
117223 + for (i = 0; i < argc; ++i) {
117224 + if (!strcmp(argv[i].key, "track-lowest-sp")) {
117225 + if (!argv[i].value) {
117226 + error(G_("no value supplied for option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
117227 + continue;
117228 + }
117229 + track_frame_size = atoi(argv[i].value);
117230 + if (argv[i].value[0] < '0' || argv[i].value[0] > '9' || track_frame_size < 0)
117231 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
117232 + continue;
117233 + }
117234 + if (!strcmp(argv[i].key, "initialize-locals")) {
117235 + if (argv[i].value) {
117236 + error(G_("invalid option argument '-fplugin-arg-%s-%s=%s'"), plugin_name, argv[i].key, argv[i].value);
117237 + continue;
117238 + }
117239 + init_locals = true;
117240 + continue;
117241 + }
117242 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
117243 + }
117244 +
117245 + register_callback(plugin_name, PLUGIN_START_UNIT, &stackleak_start_unit, NULL);
117246 + register_callback(plugin_name, PLUGIN_REGISTER_GGC_ROOTS, NULL, (void *)&gt_ggc_r_gt_stackleak);
117247 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_tree_instrument_pass_info);
117248 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &stackleak_final_pass_info);
117249 +
117250 + return 0;
117251 +}
117252 diff --git a/tools/gcc/structleak_plugin.c b/tools/gcc/structleak_plugin.c
117253 new file mode 100644
117254 index 0000000..796569a
117255 --- /dev/null
117256 +++ b/tools/gcc/structleak_plugin.c
117257 @@ -0,0 +1,273 @@
117258 +/*
117259 + * Copyright 2013-2014 by PaX Team <pageexec@freemail.hu>
117260 + * Licensed under the GPL v2
117261 + *
117262 + * Note: the choice of the license means that the compilation process is
117263 + * NOT 'eligible' as defined by gcc's library exception to the GPL v3,
117264 + * but for the kernel it doesn't matter since it doesn't link against
117265 + * any of the gcc libraries
117266 + *
117267 + * gcc plugin to forcibly initialize certain local variables that could
117268 + * otherwise leak kernel stack to userland if they aren't properly initialized
117269 + * by later code
117270 + *
117271 + * Homepage: http://pax.grsecurity.net/
117272 + *
117273 + * Usage:
117274 + * $ # for 4.5/4.6/C based 4.7
117275 + * $ 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
117276 + * $ # for C++ based 4.7/4.8+
117277 + * $ 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
117278 + * $ gcc -fplugin=./structleak_plugin.so test.c -O2
117279 + *
117280 + * TODO: eliminate redundant initializers
117281 + * increase type coverage
117282 + */
117283 +
117284 +#include "gcc-common.h"
117285 +
117286 +// unused C type flag in all versions 4.5-4.9
117287 +#define TYPE_USERSPACE(TYPE) TYPE_LANG_FLAG_3(TYPE)
117288 +
117289 +int plugin_is_GPL_compatible;
117290 +
117291 +static struct plugin_info structleak_plugin_info = {
117292 + .version = "201401260140",
117293 + .help = "disable\tdo not activate plugin\n",
117294 +};
117295 +
117296 +static tree handle_user_attribute(tree *node, tree name, tree args, int flags, bool *no_add_attrs)
117297 +{
117298 + *no_add_attrs = true;
117299 +
117300 + // check for types? for now accept everything linux has to offer
117301 + if (TREE_CODE(*node) != FIELD_DECL)
117302 + return NULL_TREE;
117303 +
117304 + *no_add_attrs = false;
117305 + return NULL_TREE;
117306 +}
117307 +
117308 +static struct attribute_spec user_attr = {
117309 + .name = "user",
117310 + .min_length = 0,
117311 + .max_length = 0,
117312 + .decl_required = false,
117313 + .type_required = false,
117314 + .function_type_required = false,
117315 + .handler = handle_user_attribute,
117316 +#if BUILDING_GCC_VERSION >= 4007
117317 + .affects_type_identity = true
117318 +#endif
117319 +};
117320 +
117321 +static void register_attributes(void *event_data, void *data)
117322 +{
117323 + register_attribute(&user_attr);
117324 +// register_attribute(&force_attr);
117325 +}
117326 +
117327 +static tree get_field_type(tree field)
117328 +{
117329 + return strip_array_types(TREE_TYPE(field));
117330 +}
117331 +
117332 +static bool is_userspace_type(tree type)
117333 +{
117334 + tree field;
117335 +
117336 + for (field = TYPE_FIELDS(type); field; field = TREE_CHAIN(field)) {
117337 + tree fieldtype = get_field_type(field);
117338 + enum tree_code code = TREE_CODE(fieldtype);
117339 +
117340 + if (code == RECORD_TYPE || code == UNION_TYPE)
117341 + if (is_userspace_type(fieldtype))
117342 + return true;
117343 +
117344 + if (lookup_attribute("user", DECL_ATTRIBUTES(field)))
117345 + return true;
117346 + }
117347 + return false;
117348 +}
117349 +
117350 +static void finish_type(void *event_data, void *data)
117351 +{
117352 + tree type = (tree)event_data;
117353 +
117354 + if (TYPE_USERSPACE(type))
117355 + return;
117356 +
117357 + if (is_userspace_type(type))
117358 + TYPE_USERSPACE(type) = 1;
117359 +}
117360 +
117361 +static void initialize(tree var)
117362 +{
117363 + basic_block bb;
117364 + gimple_stmt_iterator gsi;
117365 + tree initializer;
117366 + gimple init_stmt;
117367 +
117368 + // this is the original entry bb before the forced split
117369 + // TODO: check further BBs in case more splits occured before us
117370 + bb = ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb->next_bb;
117371 +
117372 + // first check if the variable is already initialized, warn otherwise
117373 + for (gsi = gsi_start_bb(bb); !gsi_end_p(gsi); gsi_next(&gsi)) {
117374 + gimple stmt = gsi_stmt(gsi);
117375 + tree rhs1;
117376 +
117377 + // we're looking for an assignment of a single rhs...
117378 + if (!gimple_assign_single_p(stmt))
117379 + continue;
117380 + rhs1 = gimple_assign_rhs1(stmt);
117381 +#if BUILDING_GCC_VERSION >= 4007
117382 + // ... of a non-clobbering expression...
117383 + if (TREE_CLOBBER_P(rhs1))
117384 + continue;
117385 +#endif
117386 + // ... to our variable...
117387 + if (gimple_get_lhs(stmt) != var)
117388 + continue;
117389 + // if it's an initializer then we're good
117390 + if (TREE_CODE(rhs1) == CONSTRUCTOR)
117391 + return;
117392 + }
117393 +
117394 + // these aren't the 0days you're looking for
117395 +// inform(DECL_SOURCE_LOCATION(var), "userspace variable will be forcibly initialized");
117396 +
117397 + // build the initializer expression
117398 + initializer = build_constructor(TREE_TYPE(var), NULL);
117399 +
117400 + // build the initializer stmt
117401 + init_stmt = gimple_build_assign(var, initializer);
117402 + gsi = gsi_start_bb(ENTRY_BLOCK_PTR_FOR_FN(cfun)->next_bb);
117403 + gsi_insert_before(&gsi, init_stmt, GSI_NEW_STMT);
117404 + update_stmt(init_stmt);
117405 +}
117406 +
117407 +static unsigned int handle_function(void)
117408 +{
117409 + basic_block bb;
117410 + unsigned int ret = 0;
117411 + tree var;
117412 + unsigned int i;
117413 +
117414 + // split the first bb where we can put the forced initializers
117415 + bb = split_block_after_labels(ENTRY_BLOCK_PTR_FOR_FN(cfun))->dest;
117416 + if (dom_info_available_p(CDI_DOMINATORS))
117417 + set_immediate_dominator(CDI_DOMINATORS, bb, ENTRY_BLOCK_PTR_FOR_FN(cfun));
117418 +
117419 + // enumarate all local variables and forcibly initialize our targets
117420 + FOR_EACH_LOCAL_DECL(cfun, i, var) {
117421 + tree type = TREE_TYPE(var);
117422 +
117423 + gcc_assert(DECL_P(var));
117424 + if (!auto_var_in_fn_p(var, current_function_decl))
117425 + continue;
117426 +
117427 + // only care about structure types
117428 + if (TREE_CODE(type) != RECORD_TYPE && TREE_CODE(type) != UNION_TYPE)
117429 + continue;
117430 +
117431 + // if the type is of interest, examine the variable
117432 + if (TYPE_USERSPACE(type))
117433 + initialize(var);
117434 + }
117435 +
117436 + return ret;
117437 +}
117438 +
117439 +#if BUILDING_GCC_VERSION >= 4009
117440 +static const struct pass_data structleak_pass_data = {
117441 +#else
117442 +static struct gimple_opt_pass structleak_pass = {
117443 + .pass = {
117444 +#endif
117445 + .type = GIMPLE_PASS,
117446 + .name = "structleak",
117447 +#if BUILDING_GCC_VERSION >= 4008
117448 + .optinfo_flags = OPTGROUP_NONE,
117449 +#endif
117450 +#if BUILDING_GCC_VERSION >= 4009
117451 + .has_gate = false,
117452 + .has_execute = true,
117453 +#else
117454 + .gate = NULL,
117455 + .execute = handle_function,
117456 + .sub = NULL,
117457 + .next = NULL,
117458 + .static_pass_number = 0,
117459 +#endif
117460 + .tv_id = TV_NONE,
117461 + .properties_required = PROP_cfg,
117462 + .properties_provided = 0,
117463 + .properties_destroyed = 0,
117464 + .todo_flags_start = 0,
117465 + .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
117466 +#if BUILDING_GCC_VERSION < 4009
117467 + }
117468 +#endif
117469 +};
117470 +
117471 +#if BUILDING_GCC_VERSION >= 4009
117472 +namespace {
117473 +class structleak_pass : public gimple_opt_pass {
117474 +public:
117475 + structleak_pass() : gimple_opt_pass(structleak_pass_data, g) {}
117476 + unsigned int execute() { return handle_function(); }
117477 +};
117478 +}
117479 +#endif
117480 +
117481 +static struct opt_pass *make_structleak_pass(void)
117482 +{
117483 +#if BUILDING_GCC_VERSION >= 4009
117484 + return new structleak_pass();
117485 +#else
117486 + return &structleak_pass.pass;
117487 +#endif
117488 +}
117489 +
117490 +int plugin_init(struct plugin_name_args *plugin_info, struct plugin_gcc_version *version)
117491 +{
117492 + int i;
117493 + const char * const plugin_name = plugin_info->base_name;
117494 + const int argc = plugin_info->argc;
117495 + const struct plugin_argument * const argv = plugin_info->argv;
117496 + bool enable = true;
117497 + struct register_pass_info structleak_pass_info;
117498 +
117499 + structleak_pass_info.pass = make_structleak_pass();
117500 + structleak_pass_info.reference_pass_name = "ssa";
117501 + structleak_pass_info.ref_pass_instance_number = 1;
117502 + structleak_pass_info.pos_op = PASS_POS_INSERT_AFTER;
117503 +
117504 + if (!plugin_default_version_check(version, &gcc_version)) {
117505 + error(G_("incompatible gcc/plugin versions"));
117506 + return 1;
117507 + }
117508 +
117509 + if (strcmp(lang_hooks.name, "GNU C")) {
117510 + inform(UNKNOWN_LOCATION, G_("%s supports C only"), plugin_name);
117511 + enable = false;
117512 + }
117513 +
117514 + for (i = 0; i < argc; ++i) {
117515 + if (!strcmp(argv[i].key, "disable")) {
117516 + enable = false;
117517 + continue;
117518 + }
117519 + error(G_("unkown option '-fplugin-arg-%s-%s'"), plugin_name, argv[i].key);
117520 + }
117521 +
117522 + register_callback(plugin_name, PLUGIN_INFO, NULL, &structleak_plugin_info);
117523 + if (enable) {
117524 + register_callback(plugin_name, PLUGIN_PASS_MANAGER_SETUP, NULL, &structleak_pass_info);
117525 + register_callback(plugin_name, PLUGIN_FINISH_TYPE, finish_type, NULL);
117526 + }
117527 + register_callback(plugin_name, PLUGIN_ATTRIBUTES, register_attributes, NULL);
117528 +
117529 + return 0;
117530 +}
117531 diff --git a/tools/lib/lk/Makefile b/tools/lib/lk/Makefile
117532 index 3dba0a4..97175dc 100644
117533 --- a/tools/lib/lk/Makefile
117534 +++ b/tools/lib/lk/Makefile
117535 @@ -13,7 +13,7 @@ LIB_OBJS += $(OUTPUT)debugfs.o
117536
117537 LIBFILE = liblk.a
117538
117539 -CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
117540 +CFLAGS = -ggdb3 -Wall -Wextra -std=gnu99 -Werror -O6 -U_FORTIFY_SOURCE -D_FORTIFY_SOURCE=2 $(EXTRA_WARNINGS) $(EXTRA_CFLAGS) -fPIC
117541 EXTLIBS = -lelf -lpthread -lrt -lm
117542 ALL_CFLAGS = $(CFLAGS) $(BASIC_CFLAGS) -D_LARGEFILE64_SOURCE -D_FILE_OFFSET_BITS=64
117543 ALL_LDFLAGS = $(LDFLAGS)
117544 diff --git a/tools/perf/util/include/asm/alternative-asm.h b/tools/perf/util/include/asm/alternative-asm.h
117545 index 6789d78..4afd019e 100644
117546 --- a/tools/perf/util/include/asm/alternative-asm.h
117547 +++ b/tools/perf/util/include/asm/alternative-asm.h
117548 @@ -5,4 +5,7 @@
117549
117550 #define altinstruction_entry #
117551
117552 + .macro pax_force_retaddr rip=0, reload=0
117553 + .endm
117554 +
117555 #endif
117556 diff --git a/tools/perf/util/include/linux/compiler.h b/tools/perf/util/include/linux/compiler.h
117557 index b003ad7..c0a02f8 100644
117558 --- a/tools/perf/util/include/linux/compiler.h
117559 +++ b/tools/perf/util/include/linux/compiler.h
117560 @@ -27,4 +27,12 @@
117561 # define __weak __attribute__((weak))
117562 #endif
117563
117564 +#ifndef __size_overflow
117565 +# define __size_overflow(...)
117566 +#endif
117567 +
117568 +#ifndef __intentional_overflow
117569 +# define __intentional_overflow(...)
117570 +#endif
117571 +
117572 #endif
117573 diff --git a/virt/kvm/kvm_main.c b/virt/kvm/kvm_main.c
117574 index 4f588bc..d3cfc5c 100644
117575 --- a/virt/kvm/kvm_main.c
117576 +++ b/virt/kvm/kvm_main.c
117577 @@ -76,12 +76,17 @@ LIST_HEAD(vm_list);
117578
117579 static cpumask_var_t cpus_hardware_enabled;
117580 static int kvm_usage_count = 0;
117581 -static atomic_t hardware_enable_failed;
117582 +static atomic_unchecked_t hardware_enable_failed;
117583
117584 struct kmem_cache *kvm_vcpu_cache;
117585 EXPORT_SYMBOL_GPL(kvm_vcpu_cache);
117586
117587 -static __read_mostly struct preempt_ops kvm_preempt_ops;
117588 +static void kvm_sched_in(struct preempt_notifier *pn, int cpu);
117589 +static void kvm_sched_out(struct preempt_notifier *pn, struct task_struct *next);
117590 +static struct preempt_ops kvm_preempt_ops = {
117591 + .sched_in = kvm_sched_in,
117592 + .sched_out = kvm_sched_out,
117593 +};
117594
117595 struct dentry *kvm_debugfs_dir;
117596
117597 @@ -751,7 +756,7 @@ int __kvm_set_memory_region(struct kvm *kvm,
117598 /* We can read the guest memory with __xxx_user() later on. */
117599 if ((mem->slot < KVM_USER_MEM_SLOTS) &&
117600 ((mem->userspace_addr & (PAGE_SIZE - 1)) ||
117601 - !access_ok(VERIFY_WRITE,
117602 + !__access_ok(VERIFY_WRITE,
117603 (void __user *)(unsigned long)mem->userspace_addr,
117604 mem->memory_size)))
117605 goto out;
117606 @@ -1615,9 +1620,17 @@ EXPORT_SYMBOL_GPL(kvm_read_guest_cached);
117607
117608 int kvm_clear_guest_page(struct kvm *kvm, gfn_t gfn, int offset, int len)
117609 {
117610 - const void *zero_page = (const void *) __va(page_to_phys(ZERO_PAGE(0)));
117611 + int r;
117612 + unsigned long addr;
117613
117614 - return kvm_write_guest_page(kvm, gfn, zero_page, offset, len);
117615 + addr = gfn_to_hva(kvm, gfn);
117616 + if (kvm_is_error_hva(addr))
117617 + return -EFAULT;
117618 + r = __clear_user((void __user *)addr + offset, len);
117619 + if (r)
117620 + return -EFAULT;
117621 + mark_page_dirty(kvm, gfn);
117622 + return 0;
117623 }
117624 EXPORT_SYMBOL_GPL(kvm_clear_guest_page);
117625
117626 @@ -1872,7 +1885,7 @@ static int kvm_vcpu_release(struct inode *inode, struct file *filp)
117627 return 0;
117628 }
117629
117630 -static struct file_operations kvm_vcpu_fops = {
117631 +static file_operations_no_const kvm_vcpu_fops __read_only = {
117632 .release = kvm_vcpu_release,
117633 .unlocked_ioctl = kvm_vcpu_ioctl,
117634 #ifdef CONFIG_COMPAT
117635 @@ -2532,7 +2545,7 @@ out:
117636 }
117637 #endif
117638
117639 -static struct file_operations kvm_vm_fops = {
117640 +static file_operations_no_const kvm_vm_fops __read_only = {
117641 .release = kvm_vm_release,
117642 .unlocked_ioctl = kvm_vm_ioctl,
117643 #ifdef CONFIG_COMPAT
117644 @@ -2632,7 +2645,7 @@ out:
117645 return r;
117646 }
117647
117648 -static struct file_operations kvm_chardev_ops = {
117649 +static file_operations_no_const kvm_chardev_ops __read_only = {
117650 .unlocked_ioctl = kvm_dev_ioctl,
117651 .compat_ioctl = kvm_dev_ioctl,
117652 .llseek = noop_llseek,
117653 @@ -2658,7 +2671,7 @@ static void hardware_enable_nolock(void *junk)
117654
117655 if (r) {
117656 cpumask_clear_cpu(cpu, cpus_hardware_enabled);
117657 - atomic_inc(&hardware_enable_failed);
117658 + atomic_inc_unchecked(&hardware_enable_failed);
117659 printk(KERN_INFO "kvm: enabling virtualization on "
117660 "CPU%d failed\n", cpu);
117661 }
117662 @@ -2714,10 +2727,10 @@ static int hardware_enable_all(void)
117663
117664 kvm_usage_count++;
117665 if (kvm_usage_count == 1) {
117666 - atomic_set(&hardware_enable_failed, 0);
117667 + atomic_set_unchecked(&hardware_enable_failed, 0);
117668 on_each_cpu(hardware_enable_nolock, NULL, 1);
117669
117670 - if (atomic_read(&hardware_enable_failed)) {
117671 + if (atomic_read_unchecked(&hardware_enable_failed)) {
117672 hardware_disable_all_nolock();
117673 r = -EBUSY;
117674 }
117675 @@ -3148,7 +3161,7 @@ static void kvm_sched_out(struct preempt_notifier *pn,
117676 kvm_arch_vcpu_put(vcpu);
117677 }
117678
117679 -int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
117680 +int kvm_init(const void *opaque, unsigned vcpu_size, unsigned vcpu_align,
117681 struct module *module)
117682 {
117683 int r;
117684 @@ -3195,7 +3208,7 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
117685 if (!vcpu_align)
117686 vcpu_align = __alignof__(struct kvm_vcpu);
117687 kvm_vcpu_cache = kmem_cache_create("kvm_vcpu", vcpu_size, vcpu_align,
117688 - 0, NULL);
117689 + SLAB_USERCOPY, NULL);
117690 if (!kvm_vcpu_cache) {
117691 r = -ENOMEM;
117692 goto out_free_3;
117693 @@ -3205,9 +3218,11 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
117694 if (r)
117695 goto out_free;
117696
117697 + pax_open_kernel();
117698 kvm_chardev_ops.owner = module;
117699 kvm_vm_fops.owner = module;
117700 kvm_vcpu_fops.owner = module;
117701 + pax_close_kernel();
117702
117703 r = misc_register(&kvm_dev);
117704 if (r) {
117705 @@ -3217,9 +3232,6 @@ int kvm_init(void *opaque, unsigned vcpu_size, unsigned vcpu_align,
117706
117707 register_syscore_ops(&kvm_syscore_ops);
117708
117709 - kvm_preempt_ops.sched_in = kvm_sched_in;
117710 - kvm_preempt_ops.sched_out = kvm_sched_out;
117711 -
117712 r = kvm_init_debug();
117713 if (r) {
117714 printk(KERN_ERR "kvm: create debugfs files failed\n");